Guest User

Untitled

a guest
Jun 3rd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Custom Instagram Widget
  4. Description: Custom Instagram Widget is very simple widget to showcase your latest instagram images.
  5. Version: 1.0
  6. Author: priyanshu.mittal,a.ankit,abhipathak
  7. Author URI: http://webriti.com
  8. License: GPLv2 or later
  9. Text Domain: ciw
  10. */
  11.  
  12.  
  13.  
  14. // Creating the widget
  15. class custom_instagram_widget extends WP_Widget {
  16.  
  17. function __construct() {
  18. parent::__construct(
  19. 'custom_instagram_widget',
  20. __('Custom Instagram', 'ciw'),
  21. array( 'description' => __( 'Custom Instagram Widget', 'ciw' ), )
  22. );
  23. }
  24.  
  25. // Creating widget front-end
  26. public function widget( $args, $instance ) {
  27. $ciw_title = apply_filters( 'widget_title', $instance['ciw_title'] );
  28. $username = $instance['ciw_username'] ;
  29. $ciw_image_padding = $instance['ciw_image_padding'] ;
  30. $ciw_image_padding_unit = $instance['ciw_image_padding_unit'] ;
  31. $ciw_follow_button_text = $instance['ciw_follow_button_text'] ;
  32.  
  33. // before and after widget arguments are defined by themes
  34. //echo $args['before_widget'];
  35. //if ( ! empty( $userid ) )
  36. echo $args['before_title'] . $ciw_title . $args['after_title'];
  37.  
  38. function cwi_instagram($url){
  39. $ch = curl_init();
  40. curl_setopt_array($ch, array(
  41. CURLOPT_URL => $url,
  42. CURLOPT_RETURNTRANSFER => true,
  43. CURLOPT_SSL_VERIFYPEER => false,
  44. CURLOPT_SSL_VERIFYHOST => 2
  45. ));
  46.  
  47. $feed_data = curl_exec($ch);
  48. curl_close($ch);
  49. return $feed_data;
  50. }
  51.  
  52. $user_data = cwi_instagram("https://api.instagram.com/v1/users/search?q=".$username."&access_token=1631861081.3a81a9f.9d7b2e2bc94f42df935055677efb2c4d");
  53. $user_data = json_decode($user_data);
  54. $userid = $user_data->data[0]->id;
  55.  
  56.  
  57.  
  58.  
  59. $feed_data = cwi_instagram("https://api.instagram.com/v1/users/".$userid."/media/recent/?access_token=1631861081.3a81a9f.9d7b2e2bc94f42df935055677efb2c4d");
  60. $feed_data = json_decode($feed_data);
  61. $usernameshow = $feed_data->data[0]->user->username;
  62.  
  63. echo "<div class='ciw_feed'>";
  64. foreach ($feed_data->data as $post) { ?>
  65. <a class="custom_instagram_widget" target="blank" href="<?php echo $post->link; ?>">
  66. <img src="<?php echo $post->images->standard_resolution->url; ?>" alt="<?php $post->caption->text ;?> " style="margin-bottom: <?php echo $ciw_image_padding.''.$ciw_image_padding_unit; ?>; max-width:100%; height:auto;"/>
  67. </a>
  68.  
  69. <?php }
  70. echo "</div>";
  71. ?>
  72. <input type="button" class="flowbutton" onClick="window.open('https://instagram.com/<?php echo $usernameshow?>','_blank');" value='<?php echo $ciw_follow_button_text; ?>'>
  73.  
  74. <style type="text/css">
  75. .flowbutton {
  76. font-family:'Helvetica Neue',sans-serif!important;
  77. font-size:18px;
  78. line-height:12px;
  79. border-radius:20px;
  80. -webkit-border-radius:9px;
  81. -moz-border-radius:20px;
  82. font-weight: lighter!important;
  83. border:0;
  84. text-shadow:#C17C3A 0 -1px 0;
  85. height:32px;
  86. text-transform: none!important;
  87. }
  88.  
  89. </style>
  90.  
  91. <?php
  92. }
  93.  
  94. // Widget Backend
  95. public function form( $instance ) {
  96. // show default values
  97. $instance = wp_parse_args((array) $instance,array( 'ciw_title' => __( 'Custom Instagram Widget', 'ciw' ), 'ciw_username' => '', 'ciw_follow_button_text' => __( 'Follow Us', 'ciw' ), 'ciw_image_padding' => 3, 'ciw_image_padding_unit' => __( 'px', 'ciw' ) ));
  98. $ciw_username = $instance[ 'ciw_username' ];
  99. $ciw_title = $instance[ 'ciw_title' ];
  100. $ciw_image_padding = $instance[ 'ciw_image_padding' ];
  101. $ciw_image_padding_unit = $instance[ 'ciw_image_padding_unit' ];
  102. $ciw_follow_button_text = $instance[ 'ciw_follow_button_text' ];
  103.  
  104. // Widget admin form
  105. ?>
  106. <p>
  107. <label for="<?php echo $this->get_field_id( 'ciw_title' ); ?>"><?php _e( 'Title:','ciw' ); ?></label>
  108. <input class="widefat" id="<?php echo $this->get_field_id( 'ciw_title' ); ?>" name="<?php echo $this->get_field_name( 'ciw_title' ); ?>" type="text" value="<?php echo esc_attr( $ciw_title ); ?>" />
  109. </p>
  110.  
  111. <p>
  112. <label for="<?php echo $this->get_field_id( 'ciw_username' ); ?>"><?php _e( 'User Name:','ciw' ); ?></label>
  113. <input class="widefat" id="<?php echo $this->get_field_id( 'ciw_username' ); ?>" name="<?php echo $this->get_field_name( 'ciw_username' ); ?>" type="text" value="<?php echo esc_attr( $ciw_username ); ?>" />
  114. </p>
  115.  
  116. <p>
  117. <label for="<?php echo $this->get_field_id('ciw_image_padding') ?>"><?php _e('Space between Images:','ciw');?></label>
  118. <input style="width:82%" id="<?php echo $this->get_field_id('ciw_image_padding')?>" name ="<?php echo $this->get_field_name('ciw_image_padding');?>" type="text" value="<?php echo esc_attr($ciw_image_padding); ?>"/>
  119. <select class="ciw_padding_unit" id="<?php echo $this->get_field_id( 'ciw_image_padding_unit' ); ?>" name="<?php echo $this->get_field_name( 'ciw_image_padding_unit' ); ?>">
  120. <option <?php if ( 'px' == $ciw_image_padding_unit ) echo 'selected="selected"'; ?> value="px">PX</option>
  121. <option <?php if ( '%' == $ciw_image_padding_unit ) echo 'selected="selected"'; ?> value="%">%</option>
  122.  
  123. </select>
  124. </p>
  125.  
  126.  
  127. <p>
  128. <label for="<?php echo $this->get_field_id( 'ciw_follow_button_text' ); ?>"><?php _e( 'Follw Button Text:','ciw' ); ?></label>
  129. <input class="widefat" id="<?php echo $this->get_field_id( 'ciw_follow_button_text' ); ?>" name="<?php echo $this->get_field_name( 'ciw_follow_button_text' ); ?>" type="text" value="<?php echo esc_attr( $ciw_follow_button_text ); ?>" />
  130. </p>
  131.  
  132.  
  133. <style type="text/css">
  134. .ciw_padding_unit {
  135.  
  136. vertical-align: baseline!important;
  137. }
  138. </style>
  139. <?php
  140. }
  141.  
  142. // Updating widget replacing old instances with new
  143. public function update( $new_instance, $old_instance ) {
  144. $instance = array();
  145. $instance['ciw_username'] = ( ! empty( $new_instance['ciw_username'] ) ) ? strip_tags( $new_instance['ciw_username'] ) : '';
  146. $instance['ciw_title'] = ( ! empty( $new_instance['ciw_title'] ) ) ? strip_tags( $new_instance['ciw_title'] ) : '';
  147. $instance['ciw_image_padding'] = ( ! empty( $new_instance['ciw_image_padding'] ) ) ? strip_tags( $new_instance['ciw_image_padding'] ) : '';
  148. $instance['ciw_image_padding_unit'] = ( ! empty( $new_instance['ciw_image_padding_unit'] ) ) ? strip_tags( $new_instance['ciw_image_padding_unit'] ) : '';
  149. $instance['ciw_follow_button_text'] = ( ! empty( $new_instance['ciw_follow_button_text'] ) ) ? strip_tags( $new_instance['ciw_follow_button_text'] ) : '';
  150.  
  151. return $instance;
  152. }
  153. } // Class custom_instagram_widget ends here
  154.  
  155. // Register and load the widget
  156. function custom_instagram_load_widget() {
  157. register_widget( 'custom_instagram_widget' );
  158. }
  159. add_action( 'widgets_init', 'custom_instagram_load_widget' );
  160. ?>
Add Comment
Please, Sign In to add comment