Instagram Slider Widget - Version 1.2.1

Version Description

Download this release

Release Info

Developer jetonr
Plugin Icon 128x128 Instagram Slider Widget
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.2.0 to 1.2.1

assets/css/instag-slider.css CHANGED
@@ -8,7 +8,7 @@
8
  .pllexislider, .pllexislider .slides li:hover, .pllexislider .slides > li:hover > a { border: none; }
9
 
10
  /* no list style */
11
- .jr-insta-thumb .no-bullet, .pllexislider .no-bullet { list-style:none; padding: 0; margin:0; }
12
 
13
  /* Flexi Slider Template */
14
  .pllexislider { margin: 0; position: relative; }
@@ -45,12 +45,12 @@
45
  /* Direction Nav */
46
  .pllexislider .pllex-direction-nav { z-index:2; position: absolute; list-style:none; padding: 0; top: 7px; right: 7px; margin: 0; background-color: rgba(0,0,0, 0.6); -webkit-border-radius: 15%; -moz-border-radius: 15%; -o-border-radius: 15%; border-radius: 15%; }
47
  .pllexislider-overlay .pllex-direction-nav { display:none; }
48
- .pllexislider .pllex-direction-nav li a { line-height: normal; overflow: hidden; display: block; }
49
  .pllexislider .pllex-direction-nav li a:focus { outline: 0 }
50
  .pllexislider .pllex-direction-nav li:first-child { float: left; margin-right: 0; border-left: 0; border-right: 1px solid gray; }
51
- .pllexislider .pllex-direction-nav li { float: right; margin-top: 0; border-right: 0; border-left: 1px solid #1e1e1e; }
52
  .pllexislider .pllex-direction-nav .pllex-next:before,
53
- .pllexislider .pllex-direction-nav .pllex-prev:before { display: inline-block; padding: 0 4px 1px; speak: none; color: #fff; font-size: 18px; text-shadow: 0 2px 0 rgba(0, 0, 0, 1); }
54
  .pllexislider .pllex-direction-nav .pllex-next:before { content: '\25BA'; }
55
  .pllexislider .pllex-direction-nav .pllex-prev:before { content: '\25C4'; }
56
 
8
  .pllexislider, .pllexislider .slides li:hover, .pllexislider .slides > li:hover > a { border: none; }
9
 
10
  /* no list style */
11
+ .jr-insta-thumb .no-bullet, .pllexislider .no-bullet { list-style: none; margin: 0 0 0 0; padding: 0 0 0 0; clear: both; }
12
 
13
  /* Flexi Slider Template */
14
  .pllexislider { margin: 0; position: relative; }
45
  /* Direction Nav */
46
  .pllexislider .pllex-direction-nav { z-index:2; position: absolute; list-style:none; padding: 0; top: 7px; right: 7px; margin: 0; background-color: rgba(0,0,0, 0.6); -webkit-border-radius: 15%; -moz-border-radius: 15%; -o-border-radius: 15%; border-radius: 15%; }
47
  .pllexislider-overlay .pllex-direction-nav { display:none; }
48
+ .pllexislider .pllex-direction-nav li a { line-height: normal; overflow: hidden; display: block; border: 0 }
49
  .pllexislider .pllex-direction-nav li a:focus { outline: 0 }
50
  .pllexislider .pllex-direction-nav li:first-child { float: left; margin-right: 0; border-left: 0; border-right: 1px solid gray; }
51
+ .pllexislider .pllex-direction-nav li { list-style:none; float: right; margin: 0; border-right: 0; border-left: 1px solid #1e1e1e; }
52
  .pllexislider .pllex-direction-nav .pllex-next:before,
53
+ .pllexislider .pllex-direction-nav .pllex-prev:before { font-family: Arial,Helvetica,sans-serif; display: inline-block; padding: 0 4px 1px; speak: none; color: #fff; font-size: 18px; text-shadow: 0 2px 0 rgba(0, 0, 0, 1); }
54
  .pllexislider .pllex-direction-nav .pllex-next:before { content: '\25BA'; }
55
  .pllexislider .pllex-direction-nav .pllex-prev:before { content: '\25C4'; }
56
 
assets/css/jr-insta-admin.css CHANGED
@@ -8,5 +8,16 @@
8
  .jr-container .jr-advanced { text-decoration: none; border: none }
9
  .jr-container .jr-advanced:focus { outline: 0; border: none; box-shadow:none }
10
 
11
- .jr-container .jr-advanced-input div { border: 1px solid #cfcfcf; padding: 10px; margin: 20px 0; }
12
- .jr-container .jr-advanced-input .jr-advanced-title{ margin: -22px 0 0 0; background-color: white; width: 160px; padding: 3px 10px; border: 1px solid #cfcfcf; }
 
 
 
 
 
 
 
 
 
 
 
8
  .jr-container .jr-advanced { text-decoration: none; border: none }
9
  .jr-container .jr-advanced:focus { outline: 0; border: none; box-shadow:none }
10
 
11
+ .jr-container .jr-advanced-input div { border: 1px solid #cfcfcf; padding: 10px; margin: 25px 0 0; }
12
+ .jr-container .jr-advanced-input .jr-advanced-title{ margin: -22px 0 0 0; background-color: white; width: 160px; padding: 3px 10px; border: 1px solid #cfcfcf; }
13
+ .jr-container .jr-description { color: #777; font-size: smaller; clear:both; display:block }
14
+
15
+ .jr-container .blocked-images { margin: 0 0 0 0; padding: 0 0 0 0; }
16
+ .jr-container .blocked-images:after { content: ""; display: table; clear: both; }
17
+ .jr-container .blocked-images-toggle { padding-left: 7px; }
18
+ .jr-container .blocked-images-toggle:focus { outline: 0; border: none; box-shadow:none }
19
+ .jr-container .blocked-column { width: 60px; max-height: 60px; margin: 3px; display:inline-block; position:relative; float:left; }
20
+ .jr-container .blocked-column .blocked-imgcontainer img{ max-width:100%; background:#ccc; display:block; cursor: pointer }
21
+ .jr-container .blocked-column .blocked-imgcontainer .jr-allow-yes { z-index: 5; padding: 0 0 0 0; font-size: 18px; top: 5px; right: -5px; line-height:0; color: #ffffff; position: absolute; cursor: pointer; text-shadow: 2px 2px 4px #000000; visibility:hidden; opacity:0; transition: visibility 0s linear 0.3s,opacity 0.3s linear; -webkit-transition-delay: visibility 0s linear 0.3s,opacity 0.3s linear; -moz-transition-delay: visibility 0s linear 0.3s,opacity 0.3s linear; -o-transition-delay: visibility 0s linear 0.3s,opacity 0.3s linear; }
22
+ .jr-container .blocked-column .blocked-imgcontainer .jr-allow-yes:before { width:20px; background-color: #1e8cbe; -webkit-box-shadow: 0 0 0 1px #fff,0 0 0 2px #1e8cbe; -moz-box-shadow: 0 0 0 1px #fff,0 0 0 2px #1e8cbe; box-shadow: 0 0 0 1px #fff,0 0 0 2px #1e8cbe; }
23
+ .jr-container .blocked-column:hover .blocked-imgcontainer .jr-allow-yes { visibility:visible; opacity:1; transition-delay:0s; -webkit-transition-delay:0s; -moz-transition-delay:0s; -o-transition-delay:0s; }
assets/js/jr-insta-admin.js CHANGED
@@ -24,15 +24,30 @@
24
  }
25
  });
26
 
 
27
  // Hide Refresh hour if source is wp media library
28
  $('body').on('change', '.jr-container input:radio[id$="source"]', function(e){
29
  var source = $(this);
30
  if ( source.val() != 'instagram' ) {
31
  source.closest('.jr-container').find('input[id$="refresh_hour"]').closest('p').animate({opacity: 'hide' , height: 'hide'}, 200);
 
 
32
  } else {
33
  source.closest('.jr-container').find('input[id$="refresh_hour"]').closest('p').animate({opacity: 'show' , height: 'show'}, 200);
 
 
34
  }
35
  });
 
 
 
 
 
 
 
 
 
 
36
 
37
  // Toggle advanced options
38
  $('body').on('click', '.jr-advanced', function(e){
@@ -46,7 +61,51 @@
46
  }
47
  advanced_container.toggle();
48
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  })(jQuery);
24
  }
25
  });
26
 
27
+
28
  // Hide Refresh hour if source is wp media library
29
  $('body').on('change', '.jr-container input:radio[id$="source"]', function(e){
30
  var source = $(this);
31
  if ( source.val() != 'instagram' ) {
32
  source.closest('.jr-container').find('input[id$="refresh_hour"]').closest('p').animate({opacity: 'hide' , height: 'hide'}, 200);
33
+ source.closest('.jr-container').find('input[id$="attachment"]').closest('p').animate({opacity: 'hide' , height: 'hide'}, 200);
34
+ source.closest('.jr-container').find('.blocked-wrap').animate({opacity: 'hide' , height: 'hide'}, 200);
35
  } else {
36
  source.closest('.jr-container').find('input[id$="refresh_hour"]').closest('p').animate({opacity: 'show' , height: 'show'}, 200);
37
+ source.closest('.jr-container').find('input[id$="attachment"]').closest('p').animate({opacity: 'show' , height: 'show'}, 200);
38
+ source.closest('.jr-container').find('.blocked-wrap').animate({opacity: 'show' , height: 'show'}, 200);
39
  }
40
  });
41
+
42
+ // Hide blocked images if not checked attachments
43
+ $('body').on('change', '.jr-container [id$="attachment"]:checkbox', function(e){
44
+ var attachment = $(this);
45
+ if ( this.checked ) {
46
+ attachment.closest('.jr-container').find('.blocked-wrap').animate({opacity: 'show' , height: 'show'}, 200);
47
+ } else {
48
+ attachment.closest('.jr-container').find('.blocked-wrap').animate({opacity: 'hide' , height: 'hide'}, 200);
49
+ }
50
+ });
51
 
52
  // Toggle advanced options
53
  $('body').on('click', '.jr-advanced', function(e){
61
  }
62
  advanced_container.toggle();
63
  });
64
+
65
+ // Toggle blocked images
66
+ $('body').on('click', '.blocked-images-toggle', function(e){
67
+ e.preventDefault();
68
+ var blocked_container = $(this).next();
69
+
70
+ if ( blocked_container.is(':hidden') ) {
71
+ $(this).html('[ - Close ]');
72
+ } else {
73
+ $(this).html('[ + Open ]');
74
+ }
75
+ blocked_container.toggle();
76
+ });
77
 
78
+ // Remove blocked images with ajax
79
+ $('body').on('click', '.jr-container .blocked-images .blocked-column', function(e){
80
+ var li = $(this),
81
+ id = li.data('id'),
82
+ username = li.closest('.jr-container').find('input[id$="username"]').val(),
83
+ counter = li.closest('.jr-container').find('.blocked-count-nr'),
84
+ ajaxNonce = li.closest('.jr-container').find('input[name=unblock_images_nonce]').val();
85
+
86
+ $.ajax({
87
+ type: 'POST',
88
+ url: ajaxurl,
89
+ data: {
90
+ action: 'jr_unblock_images',
91
+ username : username,
92
+ id : id,
93
+ _ajax_nonce: ajaxNonce
94
+ },
95
+ success: function(data, textStatus, XMLHttpRequest) {
96
+ if ( data == 'success' ) {
97
+ li.fadeOut( "slow", function() {
98
+ $(this).remove();
99
+ counter.html(parseInt(counter.html(), 10) - 1);
100
+ });
101
+ }
102
+ },
103
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
104
+ //console.log(XMLHttpRequest.responseText);
105
+ }
106
+ });
107
+ });
108
+
109
+ }); // Document Ready
110
 
111
  })(jQuery);
instaram_slider.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Instagram Slider Widget
4
  Plugin URI: http://jrwebstudio.com/instagram-slider/
5
- Version: 1.2.0
6
  Description: Instagram Slider Widget is a responsive slider widget that shows 20 latest images from a public instagram user.
7
  Author: jetonr
8
  Author URI: http://jrwebstudio.com/
@@ -24,7 +24,7 @@ class JR_InstagramSlider extends WP_Widget {
24
  *
25
  * @var string
26
  */
27
- const VERSION = '1.2.0';
28
 
29
  /**
30
  * Initialize the plugin by registering widget and loading public scripts
@@ -38,22 +38,40 @@ class JR_InstagramSlider extends WP_Widget {
38
  'description' => __( 'A widget that displays a slider with instagram images ', 'jrinstaslider' )
39
  )
40
  );
41
-
 
 
 
 
 
 
42
  // Enqueue Plugin Styles and scripts
43
  add_action( 'wp_enqueue_scripts', array( $this, 'public_enqueue' ) );
44
 
45
  // Enqueue Plugin Styles and scripts for admin pages
46
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
47
 
48
- // Instgram Action to display images
49
- add_action( 'jr_instagram', array( $this, 'instagram_images' ) );
 
 
 
 
 
 
50
  }
51
-
52
  /**
53
  * Register widget on windgets init
54
  */
55
  public static function register_widget() {
56
  register_widget( __CLASS__ );
 
 
 
 
 
 
57
  }
58
 
59
  /**
@@ -120,6 +138,7 @@ class JR_InstagramSlider extends WP_Widget {
120
  $instance['title'] = strip_tags( $new_instance['title'] );
121
  $instance['username'] = $new_instance['username'];
122
  $instance['source'] = $new_instance['source'];
 
123
  $instance['template'] = $new_instance['template'];
124
  $instance['images_link'] = $new_instance['images_link'];
125
  $instance['custom_url'] = $new_instance['custom_url'];
@@ -133,11 +152,7 @@ class JR_InstagramSlider extends WP_Widget {
133
  $instance['controls'] = $new_instance['controls'];
134
  $instance['animation'] = $new_instance['animation'];
135
  $instance['description'] = $new_instance['description'];
136
-
137
- if ( $instance['source'] == 'instagram' ) {
138
- $this->instagram_data( $instance['username'], $instance['refresh_hour'], $instance['images_number'] );
139
- }
140
-
141
  return $instance;
142
  }
143
 
@@ -153,6 +168,7 @@ class JR_InstagramSlider extends WP_Widget {
153
  'title' => __('Instagram Slider', 'jrinstaslider'),
154
  'username' => '',
155
  'source' => 'instagram',
 
156
  'template' => 'slider',
157
  'images_link' => 'image_url',
158
  'custom_url' => '',
@@ -169,7 +185,7 @@ class JR_InstagramSlider extends WP_Widget {
169
  );
170
 
171
  $instance = wp_parse_args( (array) $instance, $defaults );
172
-
173
  ?>
174
  <div class="jr-container">
175
  <p>
@@ -184,8 +200,32 @@ class JR_InstagramSlider extends WP_Widget {
184
  <?php _e( 'Source:', 'jrinstaslider' ); ?><br>
185
  <label class="jr-radio"><input type="radio" id="<?php echo $this->get_field_id( 'source' ); ?>" name="<?php echo $this->get_field_name( 'source' ); ?>" value="instagram" <?php checked( 'instagram', $instance['source'] ); ?> /> <?php _e( 'Instagram', 'jrinstaslider' ); ?></label>
186
  <label class="jr-radio"><input type="radio" id="<?php echo $this->get_field_id( 'source' ); ?>" name="<?php echo $this->get_field_name( 'source' ); ?>" value="media_library" <?php checked( 'media_library', $instance['source'] ); ?> /> <?php _e( 'WP Media Library', 'jrinstaslider' ); ?></label>
187
- <br><small class="description"><?php _e( 'WP Media Library option will display previously saved instagram images for the user in the field above!', 'jrinstaslider') ?></small>
188
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  <p>
190
  <label for="<?php echo $this->get_field_id( 'template' ); ?>"><?php _e( 'Template', 'jrinstaslider' ); ?>
191
  <select class="widefat" name="<?php echo $this->get_field_name( 'template' ); ?>" id="<?php echo $this->get_field_id( 'template' ); ?>">
@@ -195,6 +235,31 @@ class JR_InstagramSlider extends WP_Widget {
195
  </select>
196
  </label>
197
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  <p>
199
  <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Order by', 'jrinstaslider' ); ?>
200
  <select class="widefat" name="<?php echo $this->get_field_name( 'orderby' ); ?>" id="<?php echo $this->get_field_id( 'orderby' ); ?>">
@@ -211,8 +276,10 @@ class JR_InstagramSlider extends WP_Widget {
211
  <select class="widefat" name="<?php echo $this->get_field_name( 'images_link' ); ?>" id="<?php echo $this->get_field_id( 'images_link' ); ?>">
212
  <option value="image_url" <?php selected( $instance['images_link'], 'image_url', true); ?>><?php _e( 'Instagram Image', 'jrinstaslider' ); ?></option>
213
  <option value="user_url" <?php selected( $instance['images_link'], 'user_url', true); ?>><?php _e( 'Instagram Profile', 'jrinstaslider' ); ?></option>
 
214
  <option value="local_image_url" <?php selected( $instance['images_link'], 'local_image_url', true); ?>><?php _e( 'Locally Saved Image', 'jrinstaslider' ); ?></option>
215
  <option value="attachment" <?php selected( $instance['images_link'], 'attachment', true); ?>><?php _e( 'Attachment Page', 'jrinstaslider' ); ?></option>
 
216
  <option value="custom_url" <?php selected( $instance['images_link'], 'custom_url', true ); ?>><?php _e( 'Custom Link', 'jrinstaslider' ); ?></option>
217
  <option value="none" <?php selected( $instance['images_link'], 'none', true); ?>><?php _e( 'None', 'jrinstaslider' ); ?></option>
218
  </select>
@@ -221,24 +288,24 @@ class JR_InstagramSlider extends WP_Widget {
221
  <p class="<?php if ( 'custom_url' != $instance['images_link'] ) echo 'hidden'; ?>">
222
  <label for="<?php echo $this->get_field_id( 'custom_url' ); ?>"><?php _e( 'Custom link:', 'jrinstaslider'); ?></label>
223
  <input class="widefat" id="<?php echo $this->get_field_id( 'custom_url' ); ?>" name="<?php echo $this->get_field_name( 'custom_url' ); ?>" value="<?php echo $instance['custom_url']; ?>" />
224
- <small><?php _e('* use this field only if the above option is set to <strong>Custom Link</strong>', 'jrinstaslider'); ?></small>
225
  </p>
226
  <p>
227
  <label for="<?php echo $this->get_field_id( 'images_number' ); ?>"><?php _e( 'Number of images to show:', 'jrinstaslider' ); ?>
228
  <input class="small-text" id="<?php echo $this->get_field_id( 'images_number' ); ?>" name="<?php echo $this->get_field_name( 'images_number' ); ?>" value="<?php echo $instance['images_number']; ?>" />
229
- <small><?php _e( 'limit is 20 if <strong>Source</strong> is Instagram', 'jrinstaslider' ); ?></small>
230
  </label>
231
  </p>
232
  <p class="<?php if ( 'thumbs' != $instance['template'] ) echo 'hidden'; ?>">
233
  <label for="<?php echo $this->get_field_id( 'columns' ); ?>"><?php _e( 'Number of Columns:', 'jrinstaslider' ); ?>
234
  <input class="small-text" id="<?php echo $this->get_field_id( 'columns' ); ?>" name="<?php echo $this->get_field_name( 'columns' ); ?>" value="<?php echo $instance['columns']; ?>" />
235
- <small><?php _e('max is 10 ( only for thumbnails template )', 'jrinstaslider'); ?></small>
236
  </label>
237
  </p>
238
  <p class="<?php if ( 'instagram' != $instance['source'] ) echo 'hidden'; ?>">
239
  <label for="<?php echo $this->get_field_id( 'refresh_hour' ); ?>"><?php _e( 'Check for new images every:', 'jrinstaslider' ); ?>
240
  <input class="small-text" id="<?php echo $this->get_field_id( 'refresh_hour' ); ?>" name="<?php echo $this->get_field_name( 'refresh_hour' ); ?>" value="<?php echo $instance['refresh_hour']; ?>" />
241
- <small><?php _e('hours', 'jrinstaslider'); ?></small>
242
  </label>
243
  </p>
244
  <p>
@@ -256,37 +323,15 @@ class JR_InstagramSlider extends WP_Widget {
256
  <div class="jr-advanced-input <?php echo $advanced_class; ?>">
257
  <div class="jr-image-options">
258
  <h4 class="jr-advanced-title"><?php _e( 'Advanced Image Options', 'jrinstaslider'); ?></h4>
259
- <?php
260
- $image_size_options = get_intermediate_image_sizes();
261
- $image_sizes = array( 'thumbnail', 'medium', 'large' );
262
- if ( is_array( $image_size_options ) && !empty( $image_size_options ) ) {
263
- $image_sizes = $image_size_options;
264
- }
265
- ?>
266
- <p>
267
- <label for="<?php echo $this->get_field_id( 'image_size' ); ?>"><?php _e( 'Image size', 'jrinstaslider' ); ?></label>
268
- <select class="widefat" id="<?php echo $this->get_field_id( 'image_size' ); ?>" name="<?php echo $this->get_field_name( 'image_size' ); ?>">
269
- <option value=""><?php _e('Select Image Size', 'jrinstaslider') ?></option>
270
- <?php
271
- foreach ( $image_sizes as $image_size_option ) {
272
- echo '
273
- <option value="' . esc_attr( $image_size_option ) . '"'
274
- . selected( $image_size_option, $instance['image_size'], false )
275
- . '>' . ucfirst( $image_size_option ) . '</option>';
276
- }
277
- ?>
278
- </select>
279
- <small class="description"><?php _e( 'Image Sizes are defined using add_image_size() function', 'jrinstaslider' ); ?></small>
280
- </p>
281
  <p>
282
  <label for="<?php echo $this->get_field_id( 'image_link_rel' ); ?>"><?php _e( 'Image Link rel attribute', 'jrinstaslider' ); ?>:</label>
283
  <input class="widefat" id="<?php echo $this->get_field_id( 'image_link_rel' ); ?>" name="<?php echo $this->get_field_name( 'image_link_rel' ); ?>" value="<?php echo $instance['image_link_rel']; ?>" />
284
- <small class="description"><?php _e( 'Specifies the relationship between the current page and the linked website', 'jrinstaslider' ); ?></small>
285
  </p>
286
  <p>
287
  <label for="<?php echo $this->get_field_id( 'image_link_class' ); ?>"><?php _e( 'Image Link class', 'jrinstaslider' ); ?>:</label>
288
  <input class="widefat" id="<?php echo $this->get_field_id( 'image_link_class' ); ?>" name="<?php echo $this->get_field_name( 'image_link_class' ); ?>" value="<?php echo $instance['image_link_class']; ?>" />
289
- <small class="description"><?php _e( 'Usefull if you are using jQuery lightbox plugins to open links', 'jrinstaslider' ); ?></small>
290
 
291
  </p>
292
  </div>
@@ -310,10 +355,17 @@ class JR_InstagramSlider extends WP_Widget {
310
  <option value='time'<?php $this->selected( $instance['description'], 'time' ); ?>><?php _e( 'Time', 'jrinstaslider'); ?></option>
311
  <option value='caption'<?php $this->selected( $instance['description'], 'caption' ); ?>><?php _e( 'Caption', 'jrinstaslider'); ?></option>
312
  </select>
313
- <small class="description"><?php _e( 'Hold ctrl and click the fields you want to show/hide on your slider. Leave all unselected to hide them all. Default all selected.', 'jrinstaslider') ?></small>
314
  </p>
315
  </div>
316
  </div>
 
 
 
 
 
 
 
317
  <p class="pressthis"><a target="_blank" title="Donate To Keep This Plugin Alive!" href="http://goo.gl/RZiu34"><span>Donate To Keep This Plugin Alive!</span></a></p>
318
  </div>
319
  <?php
@@ -327,14 +379,27 @@ class JR_InstagramSlider extends WP_Widget {
327
  *
328
  * @return string
329
  */
330
- private function selected( $haystack, $current ) {
331
 
332
  if( is_array( $haystack ) && in_array( $current, $haystack ) ) {
333
- $current = $haystack = 1;
334
  }
335
- selected( $haystack, $current, true );
336
  }
337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  /**
339
  * Echoes the Display Instagram Images method
340
  *
@@ -357,6 +422,7 @@ class JR_InstagramSlider extends WP_Widget {
357
 
358
  $username = isset( $args['username'] ) && !empty( $args['username'] ) ? $args['username'] : false;
359
  $source = isset( $args['source'] ) && !empty( $args['source'] ) ? $args['source'] : 'instagram';
 
360
  $template = isset( $args['template'] ) ? $args['template'] : 'slider';
361
  $orderby = isset( $args['orderby'] ) ? $args['orderby'] : 'rand';
362
  $images_link = isset( $args['images_link'] ) ? $args['images_link'] : 'local_image_url';
@@ -384,106 +450,122 @@ class JR_InstagramSlider extends WP_Widget {
384
  }
385
 
386
  $template_args = array(
387
- 'image_size' => $image_size,
 
 
388
  'link_rel' => $image_link_rel,
389
  'link_class' => $image_link_class
390
  );
391
 
392
- $query_args = array(
393
- 'post_type' => 'attachment',
394
- 'post_status' => 'inherit',
395
- 'post_mime_type' => 'image',
396
- 'posts_per_page' => -1,
397
- 'orderby' => 'rand',
398
- 'no_found_rows' => true
399
- );
400
-
401
- if ( $orderby != 'rand' ) {
402
-
403
- $orderby = explode( '-', $orderby );
404
- $meta_key = $orderby[0] == 'date' ? 'jr_insta_timestamp' : 'jr_insta_popularity';
405
 
406
- $query_args['meta_key'] = $meta_key;
407
- $query_args['orderby'] = 'meta_value_num';
408
- $query_args['order'] = $orderby[1];
409
- }
410
-
411
- if ( $source != 'instagram' ) {
412
- $query_args['posts_per_page'] = $images_number;
413
- $query_args['meta_query'] = array(
414
- array(
415
- 'key' => 'jr_insta_username',
416
- 'value' => $username,
417
- 'compare' => '='
418
- )
419
- );
420
- } else {
421
- $query_args['post__in'] = $this->instagram_data( $username, $refresh_hour, $images_number );
422
- }
423
-
424
- $instagram_images = new WP_Query( $query_args );
425
 
426
- $output = __( 'No Images Yet', 'jrinstaslider' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
 
428
- if ( $instagram_images->have_posts() ) {
429
 
430
- $images_div_class = 'jr-insta-thumb';
431
- $ul_class = 'thumbnails jr_col_' . $columns;
432
- $slider_script = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
433
 
434
- if ( $template != 'thumbs' ) {
 
 
 
 
 
 
 
 
 
 
435
 
436
- $template_args['description'] = $description;
437
- $direction_nav = ( $controls == 'prev_next' ) ? 'true' : 'false';
438
- $control_nav = ( $controls == 'numberless' ) ? 'true': 'false';
439
- $ul_class = 'slides';
440
-
441
- if ( $template == 'slider' ) {
442
- $images_div_class = 'pllexislider pllexislider-normal';
443
- $slider_script =
444
- "<script type='text/javascript'>" . "\n" .
445
- " jQuery(document).ready(function($) {" . "\n" .
446
- " $('.pllexislider-normal').pllexislider({" . "\n" .
447
- " animation: '{$animation}'," . "\n" .
448
- " directionNav: {$direction_nav}," . "\n" .
449
- " controlNav: {$control_nav}," . "\n" .
450
- " prevText: ''," . "\n" .
451
- " nextText: ''," . "\n" .
452
- " });" . "\n" .
453
- " });" . "\n" .
454
- "</script>" . "\n";
455
  } else {
456
- $images_div_class = 'pllexislider pllexislider-overlay';
457
- $slider_script =
458
- "<script type='text/javascript'>" . "\n" .
459
- " jQuery(document).ready(function($) {" . "\n" .
460
- " $('.pllexislider-overlay').pllexislider({" . "\n" .
461
- " animation: '{$animation}'," . "\n" .
462
- " directionNav: {$direction_nav}," . "\n" .
463
- " controlNav: {$control_nav}," . "\n" .
464
- " prevText: ''," . "\n" .
465
- " nextText: ''," . "\n" .
466
- " start: function(slider){" . "\n" .
467
- " slider.hover(" . "\n" .
468
- " function () {" . "\n" .
469
- " slider.find('.jr-insta-datacontainer, .pllex-control-nav, .pllex-direction-nav').stop(true,true).fadeIn();" . "\n" .
470
- " }," . "\n" .
471
- " function () {" . "\n" .
472
- " slider.find('.jr-insta-datacontainer, .pllex-control-nav, .pllex-direction-nav').stop(true,true).fadeOut();" . "\n" .
473
- " }" . "\n" .
474
- " );" . "\n" .
475
- " }" . "\n" .
476
- " });" . "\n" .
477
- " });" . "\n" .
478
- "</script>" . "\n";
479
  }
480
- }
481
-
482
- $images_div = "<div class='{$images_div_class}'>\n";
483
- $images_ul = "<ul class='no-bullet {$ul_class}'>\n";
484
 
485
- $output = $slider_script . $images_div . $images_ul;
486
 
 
 
 
 
487
  while ( $instagram_images->have_posts() ) : $instagram_images->the_post();
488
 
489
  $id = get_the_id();
@@ -503,15 +585,65 @@ class JR_InstagramSlider extends WP_Widget {
503
  $output .= $this->get_template( $template, $template_args );
504
 
505
  endwhile;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
 
507
- $output .= "</ul>";
508
- $output .= "</div>";
509
 
510
- }
511
-
512
- wp_reset_postdata();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
 
514
  return $output;
 
515
  }
516
 
517
  /**
@@ -524,13 +656,25 @@ class JR_InstagramSlider extends WP_Widget {
524
  */
525
  private function get_template( $template, $args ) {
526
 
527
- $image_url = wp_get_attachment_image_src( get_the_id(), $args['image_size'] );
528
- $all_metas = get_post_custom( get_the_id() );
529
  $link_to = isset( $args['link_to'] ) ? $args['link_to'] : false;
530
- $caption = get_the_excerpt();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
  $short_caption = wp_trim_words( $caption, 10 );
532
 
533
- $image_src = '<img src="' . $image_url[0] . '" alt="' . $short_caption . '" title="' . $short_caption . '" />';
534
  $image_output = $image_src;
535
 
536
  if ( $link_to ) {
@@ -555,16 +699,16 @@ class JR_InstagramSlider extends WP_Widget {
555
 
556
  $output .= $image_output;
557
 
558
- if ( count( $args['description'] ) >= 1 ) {
559
 
560
  $output .= "<div class='jr-insta-datacontainer'>\n";
561
 
562
- if ( $all_metas['jr_insta_timestamp'][0] && in_array( 'time', $args['description'] ) ) {
563
- $time = human_time_diff( $all_metas['jr_insta_timestamp'][0] );
564
  $output .= "<span class='jr-insta-time'>{$time} ago</span>\n";
565
  }
566
  if ( in_array( 'username', $args['description'] ) ) {
567
- $output .= "<span class='jr-insta-username'>by <a rel='nofollow' href='http://instagram.com/{$all_metas['jr_insta_username'][0]}' target='_blank'>{$all_metas['jr_insta_username'][0]}</a></span>\n";
568
  }
569
 
570
  if ( $caption != '' && in_array( 'caption', $args['description'] ) ) {
@@ -584,19 +728,19 @@ class JR_InstagramSlider extends WP_Widget {
584
 
585
  $output .= $image_output;
586
 
587
- if ( count( $args['description'] ) >= 1 ) {
588
 
589
  $output .= "<div class='jr-insta-wrap'>\n";
590
 
591
  $output .= "<div class='jr-insta-datacontainer'>\n";
592
 
593
- if ( $all_metas['jr_insta_timestamp'][0] && in_array( 'time', $args['description'] ) ) {
594
- $time = human_time_diff( $all_metas['jr_insta_timestamp'][0] );
595
  $output .= "<span class='jr-insta-time'>{$time} ago</span>\n";
596
  }
597
 
598
  if ( in_array( 'username', $args['description'] ) ) {
599
- $output .= "<span class='jr-insta-username'>by <a rel='nofollow' target='_blank' href='http://instagram.com/{$all_metas['jr_insta_username'][0]}'>{$all_metas['jr_insta_username'][0]}</a></span>\n";
600
  }
601
 
602
  if ( $caption != '' && in_array( 'caption', $args['description'] ) ) {
@@ -635,30 +779,37 @@ class JR_InstagramSlider extends WP_Widget {
635
  *
636
  * @return array of localy saved instagram data
637
  */
638
- private function instagram_data( $username, $cache_hours, $nr_images ) {
639
 
640
  $opt_name = 'jr_insta_' . md5( $username );
641
  $instaData = get_transient( $opt_name );
642
  $user_opt = (array) get_option( $opt_name );
643
 
644
- if ( false === $instaData || $user_opt['username'] != $username || $user_opt['cache_hours'] != $cache_hours || $user_opt['nr_images'] != $nr_images ) {
645
-
646
- $instaData = array();
647
- $user_options = compact( 'username', 'cache_hours', 'nr_images' );
648
 
649
- $json = wp_remote_get( 'http://instagram.com/' . $username, array( 'sslverify' => false, 'timeout' => 60 ) );
 
 
 
 
 
 
 
 
 
 
 
 
650
 
651
- if ( $json['response']['code'] == 200 ) {
652
 
653
- $json = $json['body'];
654
- $json = strstr( $json, 'window._sharedData = ' );
655
- $json = str_replace( 'window._sharedData = ', '', $json );
656
 
657
  // Compatibility for version of php where strstr() doesnt accept third parameter
658
- if ( version_compare( PHP_VERSION, '5.3.10', '>=' ) ) {
659
- $json = substr( $json, 0, strpos( $json, '</script>' ) );
660
- } else {
661
  $json = strstr( $json, '</script>', true );
 
 
662
  }
663
 
664
  $json = rtrim( $json, ';' );
@@ -673,9 +824,15 @@ class JR_InstagramSlider extends WP_Widget {
673
  $results = json_decode( $json, true );
674
  }
675
 
676
- if ( ( $results ) && is_array( $results ) ) {
 
 
677
 
678
- foreach ( $results['entry_data']['UserProfile'][0]['userMedia'] as $current => $result ) {
 
 
 
 
679
 
680
  if ( $result['type'] != 'image' ) {
681
  $nr_images++;
@@ -686,49 +843,68 @@ class JR_InstagramSlider extends WP_Widget {
686
  break;
687
  }
688
 
689
- $image_data['username'] = $result['user']['username'];
690
- $image_data['url'] = $result['images']['standard_resolution']['url'];
691
- $image_data['caption'] = $this->sanitize( $result['caption']['text'] );
692
- $image_data['id'] = $result['id'];
693
- $image_data['link'] = $result['link'];
694
- $image_data['popularity'] = (int) ( $result['comments']['count'] ) + ( $result['likes']['count'] );
695
- $image_data['timestamp'] = $result['created_time'];
696
-
697
- if ( isset( $user_opt['saved_images'][$image_data['id']] ) ) {
 
 
698
 
699
- if ( is_string( get_post_status( $user_opt['saved_images'][$image_data['id']] ) ) ) {
 
 
 
 
700
 
701
- $this->update_wp_attachment( $user_opt['saved_images'][$image_data['id']], $image_data );
 
 
 
 
702
 
703
- $instaData[$image_data['id']] = $user_opt['saved_images'][$image_data['id']];
 
 
 
704
 
705
  } else {
706
 
707
- $user_opt['deleted_images'][$image_data['id']] = $image_data['url'];
708
- }
709
-
710
- } else {
711
-
712
- $id = $this->save_wp_attachment( $image_data );
713
-
714
- if ( $id ) {
715
 
716
- $user_opt['saved_images'][$image_data['id']] = $id;
 
 
 
 
717
 
718
- $instaData[$image_data['id']] = $id;
719
- }
720
-
721
- } // end isset $saved_images
 
 
 
 
722
 
723
  } // end -> foreach
724
 
725
  } // end -> ( $results ) && is_array( $results ) )
726
 
727
- } // end -> $json['response']['code'] === 200 )
728
-
729
- update_option( $opt_name, array_merge( $user_options, $user_opt ) );
 
 
 
 
730
 
731
- if ( $instaData ) {
 
732
  set_transient( $opt_name, $instaData, $cache_hours * 60 * 60 );
733
  }
734
 
@@ -766,7 +942,7 @@ class JR_InstagramSlider extends WP_Widget {
766
  }
767
 
768
  // These files need to be included as dependencies when on the front end.
769
- if ( !is_admin() ) {
770
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
771
  require_once( ABSPATH . 'wp-admin/includes/file.php' );
772
  require_once( ABSPATH . 'wp-admin/includes/media.php' );
@@ -780,18 +956,23 @@ class JR_InstagramSlider extends WP_Widget {
780
 
781
  // If error storing temporarily, unlink
782
  if ( is_wp_error( $tmp ) ) {
 
783
  @unlink( $file_array['tmp_name'] );
784
  $file_array['tmp_name'] = '';
 
 
785
  }
786
 
787
  $id = media_handle_sideload( $file_array, 0, NULL, array(
788
- 'post_excerpt' => $image_data['caption']
789
  ) );
790
 
791
  // If error storing permanently, unlink
792
  if ( is_wp_error( $id ) ) {
 
793
  @unlink( $file_array['tmp_name'] );
794
- return $id;
 
795
  }
796
 
797
  unset( $image_data['caption'] );
@@ -803,7 +984,114 @@ class JR_InstagramSlider extends WP_Widget {
803
  return $id;
804
  }
805
 
806
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
807
  /**
808
  * Sanitize 4-byte UTF8 chars; no full utf8mb4 support in drupal7+mysql stack.
809
  * This solution runs in O(n) time BUT assumes that all incoming input is
@@ -814,9 +1102,7 @@ class JR_InstagramSlider extends WP_Widget {
814
  * @return the sanitized input
815
  */
816
  private function sanitize( $input ) {
817
-
818
- $input = trim( str_replace( '#', '', $input ) );
819
-
820
  if ( !empty( $input ) ) {
821
  $utf8_2byte = 0xC0 /*1100 0000*/ ;
822
  $utf8_2byte_bmask = 0xE0 /*1110 0000*/ ;
2
  /*
3
  Plugin Name: Instagram Slider Widget
4
  Plugin URI: http://jrwebstudio.com/instagram-slider/
5
+ Version: 1.2.1
6
  Description: Instagram Slider Widget is a responsive slider widget that shows 20 latest images from a public instagram user.
7
  Author: jetonr
8
  Author URI: http://jrwebstudio.com/
24
  *
25
  * @var string
26
  */
27
+ const VERSION = '1.2.1';
28
 
29
  /**
30
  * Initialize the plugin by registering widget and loading public scripts
38
  'description' => __( 'A widget that displays a slider with instagram images ', 'jrinstaslider' )
39
  )
40
  );
41
+
42
+ // Shortcode
43
+ add_shortcode( 'jr_instagram', array( $this, 'shortcode' ) );
44
+
45
+ // Instgram Action to display images
46
+ add_action( 'jr_instagram', array( $this, 'instagram_images' ) );
47
+
48
  // Enqueue Plugin Styles and scripts
49
  add_action( 'wp_enqueue_scripts', array( $this, 'public_enqueue' ) );
50
 
51
  // Enqueue Plugin Styles and scripts for admin pages
52
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
53
 
54
+ // Action when attachments are deleted
55
+ add_action( 'delete_attachment', array( $this, 'delete_wp_attachment' ) );
56
+
57
+ // Ajax action to unblock images from widget
58
+ add_action( 'wp_ajax_jr_unblock_images', array( $this, 'unblock_images' ) );
59
+
60
+ // Add new attachment field desctiptions
61
+ add_filter( 'attachment_fields_to_edit', array( $this, 'insta_attachment_fields' ) , 10, 2 );
62
  }
63
+
64
  /**
65
  * Register widget on windgets init
66
  */
67
  public static function register_widget() {
68
  register_widget( __CLASS__ );
69
+ register_sidebar( array(
70
+ 'name' => __( 'Instagram Slider - Shortcode Generator', 'jrinstaslider' ),
71
+ 'id' => 'jr-insta-shortcodes',
72
+ 'description' => __( "1. Drag Instagram Slider widget here. 2. Fill in the fields and hit save. 3. Copy the shortocde generated at the bottom of the widget form and use it on posts or pages.", 'jrinstaslider' )
73
+ )
74
+ );
75
  }
76
 
77
  /**
138
  $instance['title'] = strip_tags( $new_instance['title'] );
139
  $instance['username'] = $new_instance['username'];
140
  $instance['source'] = $new_instance['source'];
141
+ $instance['attachment'] = $new_instance['attachment'];
142
  $instance['template'] = $new_instance['template'];
143
  $instance['images_link'] = $new_instance['images_link'];
144
  $instance['custom_url'] = $new_instance['custom_url'];
152
  $instance['controls'] = $new_instance['controls'];
153
  $instance['animation'] = $new_instance['animation'];
154
  $instance['description'] = $new_instance['description'];
155
+
 
 
 
 
156
  return $instance;
157
  }
158
 
168
  'title' => __('Instagram Slider', 'jrinstaslider'),
169
  'username' => '',
170
  'source' => 'instagram',
171
+ 'attachment' => 1,
172
  'template' => 'slider',
173
  'images_link' => 'image_url',
174
  'custom_url' => '',
185
  );
186
 
187
  $instance = wp_parse_args( (array) $instance, $defaults );
188
+
189
  ?>
190
  <div class="jr-container">
191
  <p>
200
  <?php _e( 'Source:', 'jrinstaslider' ); ?><br>
201
  <label class="jr-radio"><input type="radio" id="<?php echo $this->get_field_id( 'source' ); ?>" name="<?php echo $this->get_field_name( 'source' ); ?>" value="instagram" <?php checked( 'instagram', $instance['source'] ); ?> /> <?php _e( 'Instagram', 'jrinstaslider' ); ?></label>
202
  <label class="jr-radio"><input type="radio" id="<?php echo $this->get_field_id( 'source' ); ?>" name="<?php echo $this->get_field_name( 'source' ); ?>" value="media_library" <?php checked( 'media_library', $instance['source'] ); ?> /> <?php _e( 'WP Media Library', 'jrinstaslider' ); ?></label>
203
+ <br><span class="jr-description"><?php _e( 'WP Media Library option will display previously saved instagram images for the user in the field above!', 'jrinstaslider') ?></span>
204
+ </p>
205
+ <p class="<?php if ( 'instagram' != $instance['source'] ) echo 'hidden'; ?>">
206
+ <label for="<?php echo $this->get_field_id( 'attachment' ); ?>"><?php _e( 'Insert images into Media Library:', 'jrinstaslider' ); ?></label>
207
+ <input class="widefat" id="<?php echo $this->get_field_id( 'attachment' ); ?>" name="<?php echo $this->get_field_name( 'attachment' ); ?>" type="checkbox" value="1" <?php checked( '1', $instance['attachment'] ); ?> />
208
+ <br><span class="jr-description"><?php _e( 'It is recommended you check the field above because images displayed directly from Instagram server will affect your site loading time!', 'jrinstaslider') ?></span>
209
+ </p>
210
+ <?php
211
+ $user_opt = get_option( 'jr_insta_'. md5( $instance['username'] ) );
212
+ if ( isset( $user_opt['deleted_images'] ) && ( !empty( $user_opt['deleted_images'] ) && ( $instance['source'] == 'instagram' ) && ( $instance['attachment'] ) ) ) {
213
+ $deleted_count = count( $user_opt['deleted_images'] );
214
+ echo '<div class="blocked-wrap">';
215
+ wp_nonce_field( 'jr_unblock_instagram_image', 'unblock_images_nonce' );
216
+ echo "<strong>{$instance['username']}</strong> has <strong class='blocked-count-nr'>{$deleted_count}</strong> blocked images! ";
217
+ echo "<a href='#' class='blocked-images-toggle'>[ + Open ]</a>";
218
+ echo '<div class="blocked-images hidden">';
219
+ echo '<ul>';
220
+ foreach ( $user_opt['deleted_images'] as $id => $image ) {
221
+ echo "<li class='blocked-column' data-id='{$id}'><span class='blocked-imgcontainer'><span class='jr-allow-yes dashicons dashicons-yes'></span><img src='{$image}'></span></li>";
222
+ }
223
+ echo '</ul>';
224
+ echo '</div>';
225
+ echo "<span class='jr-description'>You can unblock instagram images by clicking the ones you want to have on the media library.</span>";
226
+ echo '</div>';
227
+ }
228
+ ?>
229
  <p>
230
  <label for="<?php echo $this->get_field_id( 'template' ); ?>"><?php _e( 'Template', 'jrinstaslider' ); ?>
231
  <select class="widefat" name="<?php echo $this->get_field_name( 'template' ); ?>" id="<?php echo $this->get_field_id( 'template' ); ?>">
235
  </select>
236
  </label>
237
  </p>
238
+ <p>
239
+ <?php
240
+ $image_sizes = array( 'thumbnail', 'medium', 'large' );
241
+ /*
242
+ $image_size_options = get_intermediate_image_sizes();
243
+ if ( is_array( $image_size_options ) && !empty( $image_size_options ) && !$instance['attachment'] ) {
244
+ $image_sizes = $image_size_options;
245
+ }
246
+ */
247
+ ?>
248
+ <label for="<?php echo $this->get_field_id( 'image_size' ); ?>"><?php _e( 'Image size', 'jrinstaslider' ); ?></label>
249
+ <select class="widefat" id="<?php echo $this->get_field_id( 'image_size' ); ?>" name="<?php echo $this->get_field_name( 'image_size' ); ?>">
250
+ <option value=""><?php _e('Select Image Size', 'jrinstaslider') ?></option>
251
+ <?php
252
+ foreach ( $image_sizes as $image_size_option ) {
253
+ printf(
254
+ '<option value="%1$s" %2$s>%3$s</option>',
255
+ esc_attr( $image_size_option ),
256
+ selected( $image_size_option, $instance['image_size'], false ),
257
+ ucfirst( $image_size_option )
258
+ );
259
+ }
260
+ ?>
261
+ </select>
262
+ </p>
263
  <p>
264
  <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Order by', 'jrinstaslider' ); ?>
265
  <select class="widefat" name="<?php echo $this->get_field_name( 'orderby' ); ?>" id="<?php echo $this->get_field_id( 'orderby' ); ?>">
276
  <select class="widefat" name="<?php echo $this->get_field_name( 'images_link' ); ?>" id="<?php echo $this->get_field_id( 'images_link' ); ?>">
277
  <option value="image_url" <?php selected( $instance['images_link'], 'image_url', true); ?>><?php _e( 'Instagram Image', 'jrinstaslider' ); ?></option>
278
  <option value="user_url" <?php selected( $instance['images_link'], 'user_url', true); ?>><?php _e( 'Instagram Profile', 'jrinstaslider' ); ?></option>
279
+ <?php if ( $instance['attachment'] ) : ?>
280
  <option value="local_image_url" <?php selected( $instance['images_link'], 'local_image_url', true); ?>><?php _e( 'Locally Saved Image', 'jrinstaslider' ); ?></option>
281
  <option value="attachment" <?php selected( $instance['images_link'], 'attachment', true); ?>><?php _e( 'Attachment Page', 'jrinstaslider' ); ?></option>
282
+ <?php endif; ?>
283
  <option value="custom_url" <?php selected( $instance['images_link'], 'custom_url', true ); ?>><?php _e( 'Custom Link', 'jrinstaslider' ); ?></option>
284
  <option value="none" <?php selected( $instance['images_link'], 'none', true); ?>><?php _e( 'None', 'jrinstaslider' ); ?></option>
285
  </select>
288
  <p class="<?php if ( 'custom_url' != $instance['images_link'] ) echo 'hidden'; ?>">
289
  <label for="<?php echo $this->get_field_id( 'custom_url' ); ?>"><?php _e( 'Custom link:', 'jrinstaslider'); ?></label>
290
  <input class="widefat" id="<?php echo $this->get_field_id( 'custom_url' ); ?>" name="<?php echo $this->get_field_name( 'custom_url' ); ?>" value="<?php echo $instance['custom_url']; ?>" />
291
+ <span><?php _e('* use this field only if the above option is set to <strong>Custom Link</strong>', 'jrinstaslider'); ?></span>
292
  </p>
293
  <p>
294
  <label for="<?php echo $this->get_field_id( 'images_number' ); ?>"><?php _e( 'Number of images to show:', 'jrinstaslider' ); ?>
295
  <input class="small-text" id="<?php echo $this->get_field_id( 'images_number' ); ?>" name="<?php echo $this->get_field_name( 'images_number' ); ?>" value="<?php echo $instance['images_number']; ?>" />
296
+ <span><?php _e( 'limit is 20 if <strong>Source</strong> is Instagram', 'jrinstaslider' ); ?></span>
297
  </label>
298
  </p>
299
  <p class="<?php if ( 'thumbs' != $instance['template'] ) echo 'hidden'; ?>">
300
  <label for="<?php echo $this->get_field_id( 'columns' ); ?>"><?php _e( 'Number of Columns:', 'jrinstaslider' ); ?>
301
  <input class="small-text" id="<?php echo $this->get_field_id( 'columns' ); ?>" name="<?php echo $this->get_field_name( 'columns' ); ?>" value="<?php echo $instance['columns']; ?>" />
302
+ <span><?php _e('max is 10 ( only for thumbnails template )', 'jrinstaslider'); ?></span>
303
  </label>
304
  </p>
305
  <p class="<?php if ( 'instagram' != $instance['source'] ) echo 'hidden'; ?>">
306
  <label for="<?php echo $this->get_field_id( 'refresh_hour' ); ?>"><?php _e( 'Check for new images every:', 'jrinstaslider' ); ?>
307
  <input class="small-text" id="<?php echo $this->get_field_id( 'refresh_hour' ); ?>" name="<?php echo $this->get_field_name( 'refresh_hour' ); ?>" value="<?php echo $instance['refresh_hour']; ?>" />
308
+ <span><?php _e('hours', 'jrinstaslider'); ?></span>
309
  </label>
310
  </p>
311
  <p>
323
  <div class="jr-advanced-input <?php echo $advanced_class; ?>">
324
  <div class="jr-image-options">
325
  <h4 class="jr-advanced-title"><?php _e( 'Advanced Image Options', 'jrinstaslider'); ?></h4>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  <p>
327
  <label for="<?php echo $this->get_field_id( 'image_link_rel' ); ?>"><?php _e( 'Image Link rel attribute', 'jrinstaslider' ); ?>:</label>
328
  <input class="widefat" id="<?php echo $this->get_field_id( 'image_link_rel' ); ?>" name="<?php echo $this->get_field_name( 'image_link_rel' ); ?>" value="<?php echo $instance['image_link_rel']; ?>" />
329
+ <span class="jr-description"><?php _e( 'Specifies the relationship between the current page and the linked website', 'jrinstaslider' ); ?></span>
330
  </p>
331
  <p>
332
  <label for="<?php echo $this->get_field_id( 'image_link_class' ); ?>"><?php _e( 'Image Link class', 'jrinstaslider' ); ?>:</label>
333
  <input class="widefat" id="<?php echo $this->get_field_id( 'image_link_class' ); ?>" name="<?php echo $this->get_field_name( 'image_link_class' ); ?>" value="<?php echo $instance['image_link_class']; ?>" />
334
+ <span class="jr-description"><?php _e( 'Usefull if you are using jQuery lightbox plugins to open links', 'jrinstaslider' ); ?></span>
335
 
336
  </p>
337
  </div>
355
  <option value='time'<?php $this->selected( $instance['description'], 'time' ); ?>><?php _e( 'Time', 'jrinstaslider'); ?></option>
356
  <option value='caption'<?php $this->selected( $instance['description'], 'caption' ); ?>><?php _e( 'Caption', 'jrinstaslider'); ?></option>
357
  </select>
358
+ <span class="jr-description"><?php _e( 'Hold ctrl and click the fields you want to show/hide on your slider. Leave all unselected to hide them all. Default all selected.', 'jrinstaslider') ?></span>
359
  </p>
360
  </div>
361
  </div>
362
+ <?php $widget_id = preg_replace( '/[^0-9]/', '', $this->id ); if ( $widget_id != '' ) : ?>
363
+ <p>
364
+ <label for="jr_insta_shortcode"><?php _e('Shortcode of this Widget:', 'jrinstaslider'); ?></label>
365
+ <input id="jr_insta_shortcode" onclick="this.setSelectionRange(0, this.value.length)" type="text" class="widefat" value="[jr_instagram id=&quot;<?php echo $widget_id ?>&quot;]" readonly="readonly" style="border:none; color:black; font-family:monospace;">
366
+ <span class="jr-description"><?php _e( 'Use this shortcode in any page or post to display images with this widget configuration!', 'jrinstaslider') ?></span>
367
+ </p>
368
+ <?php endif; ?>
369
  <p class="pressthis"><a target="_blank" title="Donate To Keep This Plugin Alive!" href="http://goo.gl/RZiu34"><span>Donate To Keep This Plugin Alive!</span></a></p>
370
  </div>
371
  <?php
379
  *
380
  * @return string
381
  */
382
+ public function selected( $haystack, $current ) {
383
 
384
  if( is_array( $haystack ) && in_array( $current, $haystack ) ) {
385
+ selected( 1, 1, true );
386
  }
 
387
  }
388
 
389
+ /**
390
+ * Add shorcode function
391
+ * @param array $atts shortcode attributes
392
+ * @return mixed
393
+ */
394
+ public function shortcode( $atts ) {
395
+
396
+ $atts = shortcode_atts( array( 'id' => '' ), $atts, 'jr_instagram' );
397
+ $args = get_option( 'widget_jr_insta_slider' );
398
+ if ( isset($args[$atts['id']] ) ) {
399
+ return $this->display_images( $args[$atts['id']] );
400
+ }
401
+ }
402
+
403
  /**
404
  * Echoes the Display Instagram Images method
405
  *
422
 
423
  $username = isset( $args['username'] ) && !empty( $args['username'] ) ? $args['username'] : false;
424
  $source = isset( $args['source'] ) && !empty( $args['source'] ) ? $args['source'] : 'instagram';
425
+ $attachment = isset( $args['attachment'] ) ? true : false;
426
  $template = isset( $args['template'] ) ? $args['template'] : 'slider';
427
  $orderby = isset( $args['orderby'] ) ? $args['orderby'] : 'rand';
428
  $images_link = isset( $args['images_link'] ) ? $args['images_link'] : 'local_image_url';
450
  }
451
 
452
  $template_args = array(
453
+ 'source' => $source,
454
+ 'attachment' => $attachment,
455
+ 'image_size' => $image_size,
456
  'link_rel' => $image_link_rel,
457
  'link_class' => $image_link_class
458
  );
459
 
460
+ $images_div_class = 'jr-insta-thumb';
461
+ $ul_class = 'thumbnails jr_col_' . $columns;
462
+ $slider_script = '';
463
+
464
+ if ( $template != 'thumbs' ) {
 
 
 
 
 
 
 
 
465
 
466
+ $template_args['description'] = $description;
467
+ $direction_nav = ( $controls == 'prev_next' ) ? 'true' : 'false';
468
+ $control_nav = ( $controls == 'numberless' ) ? 'true': 'false';
469
+ $ul_class = 'slides';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
 
471
+ if ( $template == 'slider' ) {
472
+ $images_div_class = 'pllexislider pllexislider-normal';
473
+ $slider_script =
474
+ "<script type='text/javascript'>" . "\n" .
475
+ " jQuery(document).ready(function($) {" . "\n" .
476
+ " $('.pllexislider-normal').pllexislider({" . "\n" .
477
+ " animation: '{$animation}'," . "\n" .
478
+ " directionNav: {$direction_nav}," . "\n" .
479
+ " controlNav: {$control_nav}," . "\n" .
480
+ " prevText: ''," . "\n" .
481
+ " nextText: ''," . "\n" .
482
+ " });" . "\n" .
483
+ " });" . "\n" .
484
+ "</script>" . "\n";
485
+ } else {
486
+ $images_div_class = 'pllexislider pllexislider-overlay';
487
+ $slider_script =
488
+ "<script type='text/javascript'>" . "\n" .
489
+ " jQuery(document).ready(function($) {" . "\n" .
490
+ " $('.pllexislider-overlay').pllexislider({" . "\n" .
491
+ " animation: '{$animation}'," . "\n" .
492
+ " directionNav: {$direction_nav}," . "\n" .
493
+ " controlNav: {$control_nav}," . "\n" .
494
+ " prevText: ''," . "\n" .
495
+ " nextText: ''," . "\n" .
496
+ " start: function(slider){" . "\n" .
497
+ " slider.hover(" . "\n" .
498
+ " function () {" . "\n" .
499
+ " slider.find('.jr-insta-datacontainer, .pllex-control-nav, .pllex-direction-nav').stop(true,true).fadeIn();" . "\n" .
500
+ " }," . "\n" .
501
+ " function () {" . "\n" .
502
+ " slider.find('.jr-insta-datacontainer, .pllex-control-nav, .pllex-direction-nav').stop(true,true).fadeOut();" . "\n" .
503
+ " }" . "\n" .
504
+ " );" . "\n" .
505
+ " }" . "\n" .
506
+ " });" . "\n" .
507
+ " });" . "\n" .
508
+ "</script>" . "\n";
509
+ }
510
+ }
511
+
512
+ $images_div = "<div class='{$images_div_class}'>\n";
513
+ $images_ul = "<ul class='no-bullet {$ul_class}'>\n";
514
+
515
+ $output = __( 'No saved images for ' . $username, 'jrinstaslider' );
516
 
517
+ if ( ( $attachment && $source == 'instagram' ) || ( $source == 'media_library') ) {
518
 
519
+ $query_args = array(
520
+ 'post_type' => 'attachment',
521
+ 'post_status' => 'inherit',
522
+ 'post_mime_type' => 'image',
523
+ 'posts_per_page' => -1,
524
+ 'orderby' => 'rand',
525
+ 'no_found_rows' => true
526
+ );
527
+
528
+ if ( $orderby != 'rand' ) {
529
+
530
+ $orderby = explode( '-', $orderby );
531
+ $meta_key = $orderby[0] == 'date' ? 'jr_insta_timestamp' : 'jr_insta_popularity';
532
+
533
+ $query_args['meta_key'] = $meta_key;
534
+ $query_args['orderby'] = 'meta_value_num';
535
+ $query_args['order'] = $orderby[1];
536
+ }
537
 
538
+ if ( $source != 'instagram' ) {
539
+ $query_args['posts_per_page'] = $images_number;
540
+ $query_args['meta_query'] = array(
541
+ array(
542
+ 'key' => 'jr_insta_username',
543
+ 'value' => $username,
544
+ 'compare' => '='
545
+ )
546
+ );
547
+
548
+ } else {
549
 
550
+ $attachment_ids = $this->instagram_data( $username, $refresh_hour, $images_number, true );
551
+
552
+ if ( is_array( $attachment_ids ) && !empty( $attachment_ids ) ) {
553
+ $query_args['post__in'] = $attachment_ids;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  } else {
555
+ if ( is_array( $attachment_ids ) ) {
556
+ return __( 'No Images found for this user. This account may not be public!', 'jrinstaslider' );
557
+ } else {
558
+ return $attachment_ids;
559
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
  }
561
+ }
 
 
 
562
 
563
+ $instagram_images = new WP_Query( $query_args );
564
 
565
+ if ( $instagram_images->have_posts() ) {
566
+
567
+ $output = $slider_script . $images_div . $images_ul;
568
+
569
  while ( $instagram_images->have_posts() ) : $instagram_images->the_post();
570
 
571
  $id = get_the_id();
585
  $output .= $this->get_template( $template, $template_args );
586
 
587
  endwhile;
588
+
589
+ $output .= "</ul>\n</div>";
590
+ }
591
+
592
+ wp_reset_postdata();
593
+
594
+ } else {
595
+
596
+ $images_data = $this->instagram_data( $username, $refresh_hour, $images_number, false );
597
+
598
+ if ( is_array( $images_data ) && !empty( $images_data ) ) {
599
+
600
+ if ( $orderby != 'rand' ) {
601
+
602
+ $orderby = explode( '-', $orderby );
603
+ $func = $orderby[0] == 'date' ? 'sort_timestamp_' . $orderby[1] : 'sort_popularity_' . $orderby[1];
604
+
605
+ usort( $images_data, array( $this, $func ) );
606
+
607
+ } else {
608
+
609
+ shuffle( $images_data );
610
+ }
611
 
612
+ $output = $slider_script . $images_div . $images_ul;
 
613
 
614
+ foreach ( $images_data as $image_data ) {
615
+
616
+ if ( 'image_url' == $images_link ) {
617
+ $template_args['link_to'] = $image_data['link'];
618
+ } elseif ( 'user_url' == $images_link ) {
619
+ $template_args['link_to'] = 'http://instagram.com/' . $username;
620
+ } elseif ( 'custom_url' == $images_link ) {
621
+ $template_args['link_to'] = $custom_url;
622
+ }
623
+
624
+ if ( $image_size == 'thumbnail' ) {
625
+ $template_args['image'] = $image_data['url_thumbnail'];
626
+ } elseif ( $image_size == 'medium' ) {
627
+ $template_args['image'] = $image_data['url_medium'];
628
+ } elseif( $image_size == 'large' ) {
629
+ $template_args['image'] = $image_data['url'];
630
+ } else {
631
+ $template_args['image'] = $image_data['url'];
632
+ }
633
+
634
+ $template_args['caption'] = $image_data['caption'];
635
+ $template_args['timestamp'] = $image_data['timestamp'];
636
+ $template_args['username'] = $image_data['username'];
637
+
638
+ $output .= $this->get_template( $template, $template_args );
639
+ }
640
+
641
+ $output .= "</ul>\n</div>";
642
+ }
643
+ }
644
 
645
  return $output;
646
+
647
  }
648
 
649
  /**
656
  */
657
  private function get_template( $template, $args ) {
658
 
 
 
659
  $link_to = isset( $args['link_to'] ) ? $args['link_to'] : false;
660
+
661
+ if ( $args['attachment'] !== true && $args['source'] == 'instagram' ) {
662
+ $caption = $args['caption'];
663
+ $time = $args['timestamp'];
664
+ $username = $args['username'];
665
+ $image_url = $args['image'];
666
+ } else {
667
+ $attach_id = get_the_id();
668
+ $caption = get_the_excerpt();
669
+ $time = get_post_meta( $attach_id, 'jr_insta_timestamp', true );
670
+ $username = get_post_meta( $attach_id, 'jr_insta_username', true );
671
+ $image_url = wp_get_attachment_image_src( $attach_id, $args['image_size'] );
672
+ $image_url = $image_url[0];
673
+ }
674
+
675
  $short_caption = wp_trim_words( $caption, 10 );
676
 
677
+ $image_src = '<img src="' . $image_url . '" alt="' . $short_caption . '" title="' . $short_caption . '" />';
678
  $image_output = $image_src;
679
 
680
  if ( $link_to ) {
699
 
700
  $output .= $image_output;
701
 
702
+ if ( is_array( $args['description'] ) && count( $args['description'] ) >= 1 ) {
703
 
704
  $output .= "<div class='jr-insta-datacontainer'>\n";
705
 
706
+ if ( $time && in_array( 'time', $args['description'] ) ) {
707
+ $time = human_time_diff( $time );
708
  $output .= "<span class='jr-insta-time'>{$time} ago</span>\n";
709
  }
710
  if ( in_array( 'username', $args['description'] ) ) {
711
+ $output .= "<span class='jr-insta-username'>by <a rel='nofollow' href='http://instagram.com/{$username}' target='_blank'>{$username}</a></span>\n";
712
  }
713
 
714
  if ( $caption != '' && in_array( 'caption', $args['description'] ) ) {
728
 
729
  $output .= $image_output;
730
 
731
+ if ( is_array( $args['description'] ) && count( $args['description'] ) >= 1 ) {
732
 
733
  $output .= "<div class='jr-insta-wrap'>\n";
734
 
735
  $output .= "<div class='jr-insta-datacontainer'>\n";
736
 
737
+ if ( $time && in_array( 'time', $args['description'] ) ) {
738
+ $time = human_time_diff( $time );
739
  $output .= "<span class='jr-insta-time'>{$time} ago</span>\n";
740
  }
741
 
742
  if ( in_array( 'username', $args['description'] ) ) {
743
+ $output .= "<span class='jr-insta-username'>by <a rel='nofollow' target='_blank' href='http://instagram.com/{$username}'>{$username}</a></span>\n";
744
  }
745
 
746
  if ( $caption != '' && in_array( 'caption', $args['description'] ) ) {
779
  *
780
  * @return array of localy saved instagram data
781
  */
782
+ private function instagram_data( $username, $cache_hours, $nr_images, $attachment ) {
783
 
784
  $opt_name = 'jr_insta_' . md5( $username );
785
  $instaData = get_transient( $opt_name );
786
  $user_opt = (array) get_option( $opt_name );
787
 
788
+ if ( false === $instaData || $user_opt['username'] != $username || $user_opt['cache_hours'] != $cache_hours || $user_opt['nr_images'] != $nr_images || $user_opt['attachment'] != $attachment ) {
 
 
 
789
 
790
+ $instaData = array();
791
+
792
+ $user_opt['username'] = $username;
793
+ $user_opt['cache_hours'] = $cache_hours;
794
+ $user_opt['nr_images'] = $nr_images;
795
+ $user_opt['attachment'] = $attachment;
796
+
797
+ $response = wp_remote_get( 'http://instagram.com/' . trim( $username ), array( 'sslverify' => false, 'timeout' => 60 ) );
798
+
799
+ if ( is_wp_error( $response ) ) {
800
+
801
+ return $response->get_error_message();
802
+ }
803
 
804
+ if ( $response['response']['code'] == 200 ) {
805
 
806
+ $json = str_replace( 'window._sharedData = ', '', strstr( $response['body'], 'window._sharedData = ' ) );
 
 
807
 
808
  // Compatibility for version of php where strstr() doesnt accept third parameter
809
+ if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
 
 
810
  $json = strstr( $json, '</script>', true );
811
+ } else {
812
+ $json = substr( $json, 0, strpos( $json, '</script>' ) );
813
  }
814
 
815
  $json = rtrim( $json, ';' );
824
  $results = json_decode( $json, true );
825
  }
826
 
827
+ if ( $results && is_array( $results ) ) {
828
+
829
+ $userMedia = isset( $results['entry_data']['UserProfile'][0]['userMedia'] ) ? $results['entry_data']['UserProfile'][0]['userMedia'] : array();
830
 
831
+ if ( empty( $userMedia ) ) {
832
+ return __( 'No images found', 'jrinstaslider');
833
+ }
834
+
835
+ foreach ( $userMedia as $current => $result ) {
836
 
837
  if ( $result['type'] != 'image' ) {
838
  $nr_images++;
843
  break;
844
  }
845
 
846
+ $image_data['username'] = $result['user']['username'];
847
+ $image_data['caption'] = $this->sanitize( $result['caption']['text'] );
848
+ $image_data['id'] = $result['id'];
849
+ $image_data['link'] = $result['link'];
850
+ $image_data['popularity'] = (int) ( $result['comments']['count'] ) + ( $result['likes']['count'] );
851
+ $image_data['timestamp'] = (int) $result['created_time'];
852
+ $image_data['url'] = $result['images']['standard_resolution']['url'];
853
+ $image_data['url_thumbnail'] = $result['images']['thumbnail']['url'];
854
+ $image_data['url_medium'] = $result['images']['low_resolution']['url'];
855
+
856
+ if ( !$attachment ) {
857
 
858
+ $instaData[] = $image_data;
859
+
860
+ } else {
861
+
862
+ if ( isset( $user_opt['saved_images'][$image_data['id']] ) ) {
863
 
864
+ if ( is_string( get_post_status( $user_opt['saved_images'][$image_data['id']] ) ) ) {
865
+
866
+ $this->update_wp_attachment( $user_opt['saved_images'][$image_data['id']], $image_data );
867
+
868
+ $instaData[$image_data['id']] = $user_opt['saved_images'][$image_data['id']];
869
 
870
+ } else {
871
+
872
+ $user_opt['deleted_images'][$image_data['id']] = $image_data['url_thumbnail'];
873
+ }
874
 
875
  } else {
876
 
877
+ $id = $this->save_wp_attachment( $image_data );
 
 
 
 
 
 
 
878
 
879
+ if ( $id && is_numeric( $id ) ) {
880
+
881
+ $user_opt['saved_images'][$image_data['id']] = $id;
882
+
883
+ $instaData[$image_data['id']] = $id;
884
 
885
+ } else {
886
+
887
+ return $id;
888
+ }
889
+
890
+ } // end isset $saved_images
891
+
892
+ } // false to save attachments
893
 
894
  } // end -> foreach
895
 
896
  } // end -> ( $results ) && is_array( $results ) )
897
 
898
+ } else {
899
+
900
+ return $response['response']['message'];
901
+
902
+ } // end -> $response['response']['code'] === 200 )
903
+
904
+ update_option( $opt_name, $user_opt );
905
 
906
+ if ( is_array( $instaData ) && !empty( $instaData ) ) {
907
+
908
  set_transient( $opt_name, $instaData, $cache_hours * 60 * 60 );
909
  }
910
 
942
  }
943
 
944
  // These files need to be included as dependencies when on the front end.
945
+ if( !function_exists( 'download_url' ) || !function_exists( 'media_handle_sideload' ) ) {
946
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
947
  require_once( ABSPATH . 'wp-admin/includes/file.php' );
948
  require_once( ABSPATH . 'wp-admin/includes/media.php' );
956
 
957
  // If error storing temporarily, unlink
958
  if ( is_wp_error( $tmp ) ) {
959
+
960
  @unlink( $file_array['tmp_name'] );
961
  $file_array['tmp_name'] = '';
962
+
963
+ return $tmp->get_error_message();
964
  }
965
 
966
  $id = media_handle_sideload( $file_array, 0, NULL, array(
967
+ 'post_excerpt' => $image_data['caption']
968
  ) );
969
 
970
  // If error storing permanently, unlink
971
  if ( is_wp_error( $id ) ) {
972
+
973
  @unlink( $file_array['tmp_name'] );
974
+
975
+ return $id->get_error_message();
976
  }
977
 
978
  unset( $image_data['caption'] );
984
  return $id;
985
  }
986
 
987
+ /**
988
+ * Add new attachment Description only for instgram images
989
+ *
990
+ * @param array $form_fields
991
+ * @param object $post
992
+ *
993
+ * @return array
994
+ */
995
+ public function insta_attachment_fields( $form_fields, $post ) {
996
+
997
+ $instagram_username = get_post_meta( $post->ID, 'jr_insta_username', true );
998
+
999
+ if ( !empty( $instagram_username ) ) {
1000
+
1001
+ $form_fields["jr_insta_username"] = array(
1002
+ "label" => __( "Instagram Username" ),
1003
+ "input" => "html",
1004
+ "html" => "<span style='line-height:31px'><a target='_blank' href='http://instagram.com/{$instagram_username}'>{$instagram_username}</a></span>"
1005
+ );
1006
+
1007
+ $instagram_link = get_post_meta( $post->ID, 'jr_insta_link', true );
1008
+ if ( !empty( $instagram_link ) ) {
1009
+ $form_fields["jr_insta_link"] = array(
1010
+ "label" => __( "Instagram Image" ),
1011
+ "input" => "html",
1012
+ "html" => "<span style='line-height:31px'><a target='_blank' href='{$instagram_link}'>{$instagram_link}</a></span>"
1013
+ );
1014
+ }
1015
+
1016
+ $instagram_date = get_post_meta( $post->ID, 'jr_insta_timestamp', true );
1017
+ if ( !empty( $instagram_date ) ) {
1018
+ $instagram_date = date( "F j, Y, g:i a", $instagram_date );
1019
+ $form_fields["jr_insta_time"] = array(
1020
+ "label" => __( "Posted on Instagram" ),
1021
+ "input" => "html",
1022
+ "html" => "<span style='line-height:31px'>{$instagram_date}</span>"
1023
+ );
1024
+ }
1025
+ }
1026
+
1027
+ return $form_fields;
1028
+ }
1029
+
1030
+ /**
1031
+ * Sort Function for timestamp Ascending
1032
+ */
1033
+ public function sort_timestamp_ASC( $a, $b ) {
1034
+ return $a['timestamp'] > $b['timestamp'];
1035
+ }
1036
+
1037
+ /**
1038
+ * Sort Function for timestamp Descending
1039
+ */
1040
+ public function sort_timestamp_DESC( $a, $b ) {
1041
+ return $a['timestamp'] < $b['timestamp'];
1042
+ }
1043
+
1044
+ /**
1045
+ * Sort Function for popularity Ascending
1046
+ */
1047
+ public function sort_popularity_ASC( $a, $b ) {
1048
+ return $a['popularity'] > $b['popularity'];
1049
+ }
1050
+
1051
+ /**
1052
+ * Sort Function for popularity Descending
1053
+ */
1054
+ public function sort_popularity_DESC( $a, $b ) {
1055
+ return $a['popularity'] < $b['popularity'];
1056
+ }
1057
+
1058
+ /**
1059
+ * Action function when user deletes an attachment
1060
+ * @param int $post_id
1061
+ * @return void
1062
+ */
1063
+ public function delete_wp_attachment( $post_id ) {
1064
+
1065
+ $username = get_post_meta( $post_id, 'jr_insta_username', true );
1066
+
1067
+ if ( !empty( $username ) ) {
1068
+ delete_transient( 'jr_insta_' . md5( $username ) );
1069
+ }
1070
+ }
1071
+
1072
+ /**
1073
+ * Ajax Call to unblock images
1074
+ * @return void
1075
+ */
1076
+ public function unblock_images() {
1077
+
1078
+ if (function_exists('check_ajax_referer')) {
1079
+ check_ajax_referer( 'jr_unblock_instagram_image' );
1080
+ }
1081
+
1082
+ $post = $_POST;
1083
+ $option_id = 'jr_insta_' . md5( $post['username'] );
1084
+ $user_options = get_option( $option_id );
1085
+
1086
+ unset( $user_options['deleted_images'][$post['id']] );
1087
+ unset( $user_options['saved_images'][$post['id']] );
1088
+
1089
+ update_option( $option_id, $user_options );
1090
+ delete_transient( $option_id );
1091
+
1092
+ die('success');
1093
+ }
1094
+
1095
  /**
1096
  * Sanitize 4-byte UTF8 chars; no full utf8mb4 support in drupal7+mysql stack.
1097
  * This solution runs in O(n) time BUT assumes that all incoming input is
1102
  * @return the sanitized input
1103
  */
1104
  private function sanitize( $input ) {
1105
+
 
 
1106
  if ( !empty( $input ) ) {
1107
  $utf8_2byte = 0xC0 /*1100 0000*/ ;
1108
  $utf8_2byte_bmask = 0xE0 /*1110 0000*/ ;
readme.txt CHANGED
@@ -19,6 +19,10 @@ Instagram Slider Widget is a responsive slider widget that shows 20 latest image
19
  * Sort images Randomily, Popularity, Date
20
  * For more info visit http://instagram.jrwebstudio.com
21
 
 
 
 
 
22
  = If you liked this plugin. Please rate it =
23
 
24
  == Installation ==
@@ -33,18 +37,17 @@ Instagram Slider Widget is a responsive slider widget that shows 20 latest image
33
  * PHP 5.2.0 or later
34
  * Wordpress 3.5 or later
35
 
36
- == Frequently asked questions ==
37
-
38
- = Where can I get support =
39
- I will try to respond on wordpress.org asap but for faster reposnse use the link bellow
40
- * http://support.jrwebstudio.com/product/instagram-slider-widget/
41
-
42
  == Screenshots ==
43
  1. Frontend Widget Slider
44
  2. Frontend Widget Thumbs
45
  3. Backend Configuration
46
 
47
  == Changelog ==
 
 
 
 
 
48
  = 1.2.0 =
49
  * Full Rewritte of the plugin
50
 
19
  * Sort images Randomily, Popularity, Date
20
  * For more info visit http://instagram.jrwebstudio.com
21
 
22
+ = Where can I get support =
23
+ I will try to respond on wordpress.org asap but for faster reposnse use the link bellow
24
+ * http://support.jrwebstudio.com/product/instagram-slider-widget/
25
+
26
  = If you liked this plugin. Please rate it =
27
 
28
  == Installation ==
37
  * PHP 5.2.0 or later
38
  * Wordpress 3.5 or later
39
 
 
 
 
 
 
 
40
  == Screenshots ==
41
  1. Frontend Widget Slider
42
  2. Frontend Widget Thumbs
43
  3. Backend Configuration
44
 
45
  == Changelog ==
46
+ = 1.2.0 =
47
+ * Bug fixes
48
+ * Shortcode for widgets
49
+ * Option not to insert images into media library
50
+
51
  = 1.2.0 =
52
  * Full Rewritte of the plugin
53