PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.4.0
Responsive Lightbox & Gallery v2.4.0
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 1.4.11 1.4.12 1.4.13 1.4.14 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7
responsive-lightbox / includes / class-widgets.php
responsive-lightbox / includes Last commit date
providers 4 years ago class-fast-image.php 8 years ago class-folders-walker.php 7 years ago class-folders.php 4 years ago class-frontend.php 4 years ago class-galleries.php 4 years ago class-multilang.php 4 years ago class-remote-library-api.php 4 years ago class-remote-library.php 4 years ago class-settings.php 4 years ago class-tour.php 4 years ago class-welcome.php 4 years ago class-widgets.php 4 years ago functions.php 4 years ago
class-widgets.php
587 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 new Responsive_Lightbox_Widgets();
7
8 /**
9 * Responsive Lightbox Widgets class.
10 *
11 * @class Responsive_Lightbox_Widgets
12 */
13 class Responsive_Lightbox_Widgets {
14
15 /**
16 * Class constructor.
17 *
18 * @return void
19 */
20 public function __construct() {
21 // actions
22 add_action( 'widgets_init', array( $this, 'register_widgets' ) );
23 }
24
25 /**
26 * Register widgets.
27 *
28 * @return void
29 */
30 public function register_widgets() {
31 register_widget( 'Responsive_Lightbox_Gallery_Widget' );
32 register_widget( 'Responsive_Lightbox_Image_Widget' );
33 }
34 }
35
36 /**
37 * Responsive Lightbox Gallery Widget class.
38 *
39 * @class Responsive_Lightbox_Gallery_Widget
40 */
41 class Responsive_Lightbox_Gallery_Widget extends WP_Widget {
42
43 private $rlg_defaults = array();
44 private $rlg_orders = array();
45 private $rlg_order_types = array();
46 private $rlg_image_sizes = array();
47 private $rlg_gallery_types = array();
48
49 /**
50 * Class constructor.
51 *
52 * @return void
53 */
54 public function __construct() {
55 parent::__construct(
56 'Responsive_Lightbox_Gallery_Widget',
57 __( 'Gallery', 'responsive-lightbox' ),
58 array(
59 'description' => __( 'Displays an image gallery.', 'responsive-lightbox' ),
60 'classname' => 'rl-gallery-widget'
61 )
62 );
63
64 $this->rlg_defaults = array(
65 'title' => __( 'Gallery', 'responsive-lightbox' ),
66 'orderby' => 'menu_order',
67 'order' => 'asc',
68 'columns' => 3,
69 'size' => 'thumbnail',
70 'type' => 'none',
71 'atts' => '',
72 'ids' => ''
73 );
74
75 $this->rlg_orders = array(
76 'menu_order' => __( 'Menu order', 'responsive-lightbox' ),
77 'title' => __( 'Title', 'responsive-lightbox' ),
78 'post_date' => __( 'Image date', 'responsive-lightbox' ),
79 'ID' => __( 'ID', 'responsive-lightbox' ),
80 'rand' => __( 'Random', 'responsive-lightbox' )
81 );
82
83 $this->rlg_order_types = array(
84 'asc' => __( 'Ascending', 'responsive-lightbox' ),
85 'desc' => __( 'Descending', 'responsive-lightbox' )
86 );
87
88 $gallery_types = apply_filters( 'rl_gallery_types', Responsive_Lightbox()->gallery_types );
89
90 if ( ! empty( $gallery_types ) ) {
91 $this->rlg_gallery_types = array_merge(
92 array(
93 'none' => __( 'None', 'responsive-lightbox' ),
94 'default' => __( 'Default', 'responsive-lightbox' )
95 ),
96 $gallery_types
97 );
98 }
99
100 $this->rlg_image_sizes = array_merge( array( 'full' ), get_intermediate_image_sizes() );
101
102 sort( $this->rlg_image_sizes, SORT_STRING );
103 }
104
105 /**
106 * Display widget.
107 *
108 * @param array $args
109 * @param object $instance
110 * @return void
111 */
112 public function widget( $args, $instance ) {
113 $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
114
115 $html = $args['before_widget'] . $args['before_title'] . ( $instance['title'] !== '' ? $instance['title'] : '' ) . $args['after_title'];
116 $html .= do_shortcode( '[gallery link="file" columns="' . $instance['columns'] . '" size="' . $instance['size'] . '" ' . ( $instance['type'] !== 'none' ? 'type="' . $instance['type'] . '"' : '' ) . ' ids="' . ( ! empty( $instance['ids'] ) ? esc_attr( $instance['ids'] ) : '' ) . '" orderby="' . $instance['orderby'] . '" order="' . $instance['order'] . '"' . ( $instance['atts'] !== '' ? ' ' . $instance['atts'] : '' ) . ']' );
117 $html .= $args['after_widget'];
118
119 echo apply_filters( 'rl_gallery_widget_html', $html, $instance );
120 }
121
122 /** Render widget form.
123 *
124 * @param object $instance
125 * @return void
126 */
127 public function form( $instance ) {
128 $attachments = ! empty( $instance['ids'] ) ? array_filter( explode( ',', $instance['ids'] ) ) : array();
129
130 $html = '
131 <div class="rl-gallery-widget-container">
132 <p>
133 <label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'responsive-lightbox' ) . ':</label>
134 <input id="' . $this->get_field_id( 'title' ) . '" class="widefat" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( isset( $instance['title'] ) ? $instance['title'] : $this->rlg_defaults['title'] ) . '" />
135 </p>
136 <div id="' . $this->get_field_id( 'gallery' ) . '" class="rl-gallery-widget' . ( ! empty( $attachments ) ? ' has-image' : '' ) . '">
137 <input type="hidden" class="rl-gallery-ids" id="' . $this->get_field_id( 'ids' ) . '" name="' . $this->get_field_name( 'ids' ) . '" value="' . ( ! empty( $instance['ids'] ) ? esc_attr( $instance['ids'] ) : '' ) . '">';
138
139 $html .= '
140 <a href="#" class="rl-gallery-widget-select button button-secondary">' . __( 'Select images', 'responsive-lightbox' ) . '</a>
141 <div class="rl-gallery-widget-content">
142 <ul id="' . $this->get_field_id( 'gallery-images' ) . '" class="rl-gallery-images">';
143
144 if ( $attachments ) {
145 foreach ( $attachments as $attachment_id ) {
146 if ( ! $attachment_id || ! wp_attachment_is_image( $attachment_id ) )
147 continue;
148
149 $html .= '
150 <li class="rl-gallery-image" data-attachment_id="' . absint( $attachment_id ) . '">
151 <div class="rl-gallery-inner">' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . '</div>
152 <div class="rl-gallery-actions"><a href="#" class="rl-gallery-image-remove dashicons dashicons-no" title="' . __( 'Delete image', 'responsive-lightbox' ) . '"></a></div>
153 </li>';
154 }
155 }
156
157 $html .= '
158 </ul>
159 </div>
160 </div>
161 <p>';
162
163 if ( ! empty( $this->rlg_gallery_types ) ) {
164 $html .= '
165 <label for="' . $this->get_field_id( 'type' ) . '">' . __( 'Gallery type', 'responsive-lightbox' ) . ':</label>
166 <select id="' . $this->get_field_id( 'type' ) . '" class="widefat" name="' . $this->get_field_name( 'type' ) . '">';
167
168 foreach ( $this->rlg_gallery_types as $id => $type ) {
169 $html .= '
170 <option value="' . esc_attr( $id ) . '" ' . selected( $id, ( isset( $instance['type'] ) ? $instance['type'] : $this->rlg_defaults['type'] ), false ) . '>' . esc_html( $type ) . '</option>';
171 }
172
173 $html .= '
174 </select>
175 </p>
176 <p>';
177 }
178
179 $html .= '
180 <label for="' . $this->get_field_id( 'orderby' ) . '">' . __( 'Order by', 'responsive-lightbox' ) . ':</label>
181 <select id="' . $this->get_field_id( 'orderby' ) . '" class="widefat" name="' . $this->get_field_name( 'orderby' ) . '">';
182
183 foreach ( $this->rlg_orders as $id => $orderby ) {
184 $html .= '
185 <option value="' . esc_attr( $id ) . '" ' . selected( $id, ( isset( $instance['orderby'] ) ? $instance['orderby'] : $this->rlg_defaults['orderby'] ), false ) . '>' . esc_html( $orderby ) . '</option>';
186 }
187
188 $html .= '
189 </select>
190 </p>
191 <p>
192 <label for="' . $this->get_field_id( 'order' ) . '">' . __( 'Order', 'responsive-lightbox' ) . ':</label>
193 <select id="' . $this->get_field_id( 'order' ) . '" class="widefat" name="' . $this->get_field_name( 'order' ) . '">';
194
195 foreach ( $this->rlg_order_types as $id => $order ) {
196 $html .= '
197 <option value="' . esc_attr( $id ) . '" ' . selected( $id, ( isset( $instance['order'] ) ? $instance['order'] : $this->rlg_defaults['order'] ), false ) . '>' . esc_html( $order ) . '</option>';
198 }
199
200 $html .= '
201 </select>
202 </p>
203 <p>
204 <label for="' . $this->get_field_id( 'size' ) . '">' . __( 'Image size', 'responsive-lightbox' ) . ':</label>
205 <select id="' . $this->get_field_id( 'size' ) . '" class="widefat" name="' . $this->get_field_name( 'size' ) . '">';
206
207 foreach ( $this->rlg_image_sizes as $size ) {
208 $html .= '
209 <option value="' . esc_attr( $size ) . '" ' . selected( $size, ( isset( $instance['size'] ) ? $instance['size'] : $this->rlg_defaults['size'] ), false ) . '>' . esc_html( $size ) . '</option>';
210 }
211
212 $html .= '
213 </select>
214 </p>
215 <p>
216 <label for="' . $this->get_field_id( 'columns' ) . '">' . __( 'Number of columns', 'responsive-lightbox' ) . ':</label>
217 <input id="' . $this->get_field_id( 'columns' ) . '" class="small-text" name="' . $this->get_field_name( 'columns' ) . '" type="number" min="0" value="' . esc_attr( isset( $instance['columns'] ) ? $instance['columns'] : $this->rlg_defaults['columns'] ) . '" />
218 </p>
219 <p>
220 <label for="' . $this->get_field_id( 'atts' ) . '">' . __( 'Custom attributes', 'responsive-lightbox' ) . ':</label>
221 <br />
222 <textarea id="' . $this->get_field_id( 'atts' ) . '" class="widefat" name="' . $this->get_field_name( 'atts' ) . '">' . esc_textarea( isset( $instance['atts'] ) ? $instance['atts'] : $this->rlg_defaults['atts'] ) . '</textarea><span class="description">' . __( 'Custom gallery shortcode attributes (optional).', 'responsive-lightbox' ) . '</span>
223 </p>
224 </div>';
225
226 echo $html;
227 }
228
229 /**
230 * Save widget form.
231 *
232 * @param array $new_instance
233 * @param array $old_instance
234 * @return array
235 */
236 public function update( $new_instance, $old_instance ) {
237 // title
238 $old_instance['title'] = array_key_exists( 'title', $new_instance ) ? trim( $new_instance['title'] ) : $this->rlg_defaults['title'];
239
240 // order by
241 $old_instance['orderby'] = array_key_exists( 'orderby', $new_instance ) && array_key_exists( $new_instance['orderby'], $this->rlg_orders ) ? $new_instance['orderby'] : $this->rlg_defaults['orderby'];
242
243 // order
244 $old_instance['order'] = array_key_exists( 'order', $new_instance ) && array_key_exists( $new_instance['order'], $this->rlg_order_types ) ? $new_instance['order'] : $this->rlg_defaults['order'];
245
246 // image size
247 $old_instance['size'] = array_key_exists( 'size', $new_instance ) && in_array( $new_instance['size'], $this->rlg_image_sizes, true ) ? $new_instance['size'] : $this->rlg_defaults['size'];
248
249 // gallery type
250 $old_instance['type'] = array_key_exists( 'type', $new_instance ) && array_key_exists( $new_instance['type'], $this->rlg_gallery_types ) ? $new_instance['type'] : $this->rlg_defaults['type'];
251
252 // number of columns
253 $old_instance['columns'] = array_key_exists( 'columns', $new_instance ) ? ( ( $columns = (int) $new_instance['columns'] ) > 0 ? $columns : $this->rlg_defaults['columns'] ) : $this->rlg_defaults['columns'];
254
255 // image ids
256 if ( array_key_exists( 'ids', $new_instance ) && ! empty( $new_instance['ids'] ) ) {
257 // get unique and non empty attachment ids only
258 $attachment_ids = array_unique( array_filter( array_map( 'intval', explode( ',', $new_instance['ids'] ) ) ) );
259
260 $old_instance['ids'] = implode( ',', $attachment_ids );
261 } else
262 $old_instance['ids'] = $this->rlg_defaults['ids'];
263
264 // custom attributes
265 $atts = preg_replace( '/\s+/', ' ', trim( str_replace( array( "\r\n", "\n\r", "\n", "\r" ), '', array_key_exists( 'atts', $new_instance ) ? $new_instance['atts'] : $this->rlg_defaults['atts'] ) ) );
266
267 $new_atts = array();
268
269 if ( $atts !== '' ) {
270 $atts_exp = explode( '" ', $atts );
271
272 if ( ! empty( $atts_exp ) ) {
273 end( $atts_exp );
274
275 $last = key( $atts_exp );
276
277 reset( $atts_exp );
278
279 foreach ( $atts_exp as $id => $attribute ) {
280 $check = $attribute . ( $last === $id ? '' : '"' );
281
282 if ( preg_match( '/^[a-z0-9_-]+=\"(.+)\"$/', $check ) === 1 )
283 $new_atts[] = $check;
284 }
285 }
286 }
287
288 if ( ! empty( $new_atts ) )
289 $old_instance['atts'] = implode( ' ', $new_atts );
290 else
291 $old_instance['atts'] = '';
292
293 return $old_instance;
294 }
295 }
296
297 /**
298 * Responsive Lightbox Gallery Widget class.
299 *
300 * @class Responsive_Lightbox_Gallery_Widget
301 */
302 class Responsive_Lightbox_Image_Widget extends WP_Widget {
303
304 private $rli_defaults = array();
305 private $rli_text_positions = array();
306 private $rli_link_to = array();
307 private $rli_aligns = array();
308 private $rli_image_sizes = array();
309
310 /**
311 * Class constructor.
312 *
313 * @return void
314 */
315 public function __construct() {
316 parent::__construct(
317 'Responsive_Lightbox_Image_Widget',
318 __( 'Image', 'responsive-lightbox' ),
319 array(
320 'description' => __( 'Displays a single image.', 'responsive-lightbox' ),
321 'classname' => 'rl-image-widget'
322 )
323 );
324
325 $this->rli_defaults = array(
326 'title' => __( 'Image', 'responsive-lightbox' ),
327 'image_id' => 0,
328 'responsive' => true,
329 'size' => 'thumbnail',
330 'link_to' => 'file',
331 'link_custom_url' => '',
332 'image_align' => 'none',
333 'text' => '',
334 'autobr' => false,
335 'text_position' => 'below_image',
336 'text_align' => 'none',
337 );
338
339 $this->rli_text_positions = array(
340 'below_image' => __( 'Below the image', 'responsive-lightbox' ),
341 'above_image' => __( 'Above the image', 'responsive-lightbox' )
342 );
343
344 $this->rli_link_to = array(
345 'none' => __( 'None', 'responsive-lightbox' ),
346 'file' => __( 'Media File', 'responsive-lightbox' ),
347 'post' => __( 'Attachment Page', 'responsive-lightbox' ),
348 'custom' => __( 'Custom URL', 'responsive-lightbox' )
349 );
350
351 $this->rli_aligns = array(
352 'none' => __( 'None', 'responsive-lightbox' ),
353 'left' => __( 'Left', 'responsive-lightbox' ),
354 'center' => __( 'Center', 'responsive-lightbox' ),
355 'right' => __( 'Right', 'responsive-lightbox' ),
356 'justify' => __( 'Justify', 'responsive-lightbox' )
357 );
358
359 $this->rli_image_sizes = array_merge( array( 'full' ), get_intermediate_image_sizes() );
360 sort( $this->rli_image_sizes, SORT_STRING );
361 }
362
363 /**
364 * Display widget.
365 *
366 * @param array $args
367 * @param array $instance
368 * @return void
369 */
370 public function widget( $args, $instance ) {
371 $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
372 $title = $args['before_widget'] . $args['before_title'] . ( $instance['title'] !== '' ? $instance['title'] : '' ) . $args['after_title'];
373
374 if ( $instance['autobr'] === true ) {
375 $text = wpautop( $instance['text'] );
376 } else {
377 $text = html_entity_decode( $instance['text'], ENT_QUOTES, 'UTF-8' );
378 }
379
380 $image = wp_get_attachment_image_src( $instance['image_id'], $instance['size'], false );
381
382 switch ( $instance['link_to'] ) {
383 case 'file':
384 $file = wp_get_attachment_image_src( $instance['image_id'], 'full', false );
385 $href = $file[0];
386 break;
387
388 case 'post':
389 $href = get_permalink( $instance['image_id'] );
390 break;
391
392 case 'custom':
393 $href = $instance['link_custom_url'];
394 break;
395
396 case 'none':
397 default:
398 $href = '';
399 break;
400 }
401
402 if ( $instance['image_align'] === 'left' )
403 $image_align = ' style="float: left;"';
404 elseif ( $instance['image_align'] === 'center' )
405 $image_align = ' style="margin-left: auto; margin-right: auto; display: block;"';
406 elseif ( $instance['image_align'] === 'right' )
407 $image_align = ' style="float: right;"';
408 else
409 $image_align = '';
410
411 if ( $instance['text_align'] === 'left' )
412 $text_align = ' style="text-align: left; display: block;"';
413 elseif ( $instance['text_align'] === 'center' )
414 $text_align = ' style="text-align: center; display: block;"';
415 elseif ( $instance['text_align'] === 'right' )
416 $text_align = ' style="text-align: right; display: block;"';
417 elseif ( $instance['text_align'] === 'justify' )
418 $text_align = ' style="text-align: justify; display: block;"';
419 else
420 $text_align = '';
421
422
423 $text_position = $instance['text_position'];
424 $width = $instance['responsive'] === false ? $image[1] : '100%';
425 $height = $instance['responsive'] === false ? $image[2] : 'auto';
426 $post = get_post( $instance['image_id'] );
427 $image_title = isset( $post->post_title ) ? $post->post_title : '';
428 $alt = (string) get_post_meta( $instance['image_id'], '_wp_attachment_image_alt', true );
429
430 $html = $title;
431
432 if ( $text_position === 'below_image' ) {
433 $html .= ($href !== '' ? '<a href="' . $href . '" class="rl-image-widget-link">' : '') . '<img class="rl-image-widget-image" src="' . $image[0] . '" width="' . $width . '" height="' . $height . '" title="' . $image_title . '" alt="' . $alt . '"' . $image_align . ' />' . ($href !== '' ? '</a>' : '');
434 $html .= '<div class="rl-image-widget-text"' . $text_align . '>' . $text . '</div>';
435 } else {
436 $html .= '<div class="rl-image-widget-text"' . $text_align . '>' . $text . '</div>';
437 $html .= ($href !== '' ? '<a href="' . $href . '" class="rl-image-widget-link">' : '') . '<img class="rl-image-widget-image" src="' . $image[0] . '" width="' . $width . '" height="' . $height . '" title="' . $image_title . '" alt="' . $alt . '"' . $image_align . ' />' . ($href !== '' ? '</a>' : '');
438 }
439 $html .= $args['after_widget'];
440
441 echo apply_filters( 'rl_image_widget_html', $html, $instance );
442 }
443
444 /** Render widget form.
445 *
446 * @param array $instance
447 * @return void
448 */
449 public function form( $instance ) {
450 $image_id = (int) (isset( $instance['image_id'] ) ? $instance['image_id'] : $this->rli_defaults['image_id']);
451 $image = '';
452
453 if ( ! empty( $image_id ) )
454 $image = wp_get_attachment_image( $image_id, 'medium', false );
455
456 if ( ! $image )
457 $image = wp_get_attachment_image( $image_id, 'full', false );
458
459 $html = '
460 <div class="rl-image-widget-container">
461 <p>
462 <label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'responsive-lightbox' ) . '</label>
463 <input id="' . $this->get_field_id( 'title' ) . '" class="widefat" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( isset( $instance['title'] ) ? $instance['title'] : $this->rli_defaults['title'] ) . '" />
464 </p>
465 <div class="rl-image-widget' . ( ! empty( $image_id ) ? ' has-image' : '' ) . '">
466 <input class="rl-image-widget-image-id" type="hidden" name="' . $this->get_field_name( 'image_id' ) . '" value="' . $image_id . '" />
467 <a href="#" class="rl-image-widget-select button button-secondary">' . __( 'Select image', 'responsive-lightbox' ) . '</a>
468 <div class="rl-image-widget-content">';
469 if ( ! empty( $image ) ) {
470 $html .= $image;
471 }
472 $html .= '
473 </div>
474 </div>
475 <p>
476 <input id="' . $this->get_field_id( 'responsive' ) . '" type="checkbox" name="' . $this->get_field_name( 'responsive' ) . '" value="" ' . checked( true, (isset( $instance['responsive'] ) ? $instance['responsive'] : $this->rli_defaults['responsive'] ), false ) . ' /> <label for="' . $this->get_field_id( 'responsive' ) . '">' . __( 'Force responsive', 'responsive-lightbox' ) . '</label>
477 </p>';
478
479 $html .= '
480 <p>
481 <label for="' . $this->get_field_id( 'size' ) . '">' . __( 'Size', 'responsive-lightbox' ) . '</label>
482 <select class="rl-image-size-select widefat" id="' . $this->get_field_id( 'size' ) . '" name="' . $this->get_field_name( 'size' ) . '">';
483
484 $size_type = (isset( $instance['size'] ) ? $instance['size'] : $this->rli_defaults['size']);
485
486 foreach ( $this->rli_image_sizes as $size ) {
487 $html .= '
488 <option value="' . esc_attr( $size ) . '" ' . selected( $size, $size_type, false ) . '>' . $size . '</option>';
489 }
490
491 $html .= '
492 </select>
493 </p>
494 <p>
495 <label for="' . $this->get_field_id( 'link_to' ) . '">' . __( 'Link to', 'responsive-lightbox' ) . '</label>
496 <select class="rl-image-link-to widefat" id="' . $this->get_field_id( 'link_to' ) . '" name="' . $this->get_field_name( 'link_to' ) . '">';
497
498 $link_type = (isset( $instance['link_to'] ) ? $instance['link_to'] : $this->rli_defaults['link_to']);
499
500 foreach ( $this->rli_link_to as $id => $type ) {
501 $html .= '
502 <option value="' . esc_attr( $id ) . '" ' . selected( $id, $link_type, false ) . '>' . $type . '</option>';
503 }
504
505 $html .= '
506 </select>
507 </p>
508 <p class="rl-image-link-url"' . ($link_type === 'custom' ? '' : ' style="display: none;"') . '>
509 <label for="' . $this->get_field_id( 'link_custom_url' ) . '">' . __( 'URL', 'responsive-lightbox' ) . '</label>
510 <input id="' . $this->get_field_id( 'link_custom_url' ) . '" class="widefat" name="' . $this->get_field_name( 'link_custom_url' ) . '" type="text" value="' . esc_attr( isset( $instance['link_custom_url'] ) ? $instance['link_custom_url'] : $this->rli_defaults['link_custom_url'] ) . '" />
511 </p>';
512
513 $html .= '
514 <p>
515 <label for="' . $this->get_field_id( 'image_align' ) . '">' . __( 'Image align', 'responsive-lightbox' ) . '</label>
516 <select id="' . $this->get_field_id( 'image_align' ) . '" class="widefat" name="' . $this->get_field_name( 'image_align' ) . '">';
517
518 foreach ( $this->rli_aligns as $id => $image_align ) {
519 if ( $id != 'justify' )
520 $html .= '
521 <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['image_align'] ) ? $instance['image_align'] : $this->rli_defaults['image_align'] ), false ) . '>' . $image_align . '</option>';
522 }
523
524 $html .= '
525 </select>
526 </p>
527 <p>
528 <label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'responsive-lightbox' ) . '</label>
529 <textarea id="' . $this->get_field_id( 'text' ) . '" class="widefat" name="' . $this->get_field_name( 'text' ) . '" rows="4">' . (isset( $instance['text'] ) ? $instance['text'] : $this->rli_defaults['text']) . '</textarea>
530 </p>
531 <p>
532 <input id="' . $this->get_field_id( 'autobr' ) . '" type="checkbox" name="' . $this->get_field_name( 'autobr' ) . '" value="" ' . checked( true, (isset( $instance['autobr'] ) ? $instance['autobr'] : $this->rli_defaults['autobr'] ), false ) . ' /> <label for="' . $this->get_field_id( 'autobr' ) . '">' . __( 'Automatically add paragraphs', 'responsive-lightbox' ) . '</label>
533 </p>';
534
535 $html .= '
536 <p>
537 <label for="' . $this->get_field_id( 'text_position' ) . '">' . __( 'Text position', 'responsive-lightbox' ) . '</label>
538 <select id="' . $this->get_field_id( 'text_position' ) . '" class="widefat" name="' . $this->get_field_name( 'text_position' ) . '">';
539
540 foreach ( $this->rli_text_positions as $id => $text_position ) {
541 $html .= '
542 <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['text_position'] ) ? $instance['text_position'] : $this->rli_defaults['text_position'] ), false ) . '>' . $text_position . '</option>';
543 }
544
545 $html .= '
546 </select>
547 </p>
548 <label for="' . $this->get_field_id( 'text_align' ) . '">' . __( 'Text align', 'responsive-lightbox' ) . '</label>
549 <select id="' . $this->get_field_id( 'text_align' ) . '" class="widefat" name="' . $this->get_field_name( 'text_align' ) . '">';
550
551 foreach ( $this->rli_aligns as $id => $text_align ) {
552 $html .= '
553 <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['text_align'] ) ? $instance['text_align'] : $this->rli_defaults['text_align'] ), false ) . '>' . $text_align . '</option>';
554 }
555
556 $html .= '
557 </select>
558
559 </div>';
560
561 echo $html;
562 }
563
564 /**
565 * Save widget form.
566 *
567 * @param array $new_instance
568 * @param array $old_instance
569 * @return array
570 */
571 public function update( $new_instance, $old_instance ) {
572 $old_instance['title'] = sanitize_text_field( isset( $new_instance['title'] ) ? $new_instance['title'] : $this->rli_defaults['title'] );
573 $old_instance['image_id'] = (int) (isset( $new_instance['image_id'] ) ? $new_instance['image_id'] : $this->rli_defaults['image_id']);
574 $old_instance['responsive'] = isset( $new_instance['responsive'] ) ? true : false;
575 $old_instance['size'] = (isset( $new_instance['size'] ) && in_array( $new_instance['size'], $this->rli_image_sizes, true ) ? $new_instance['size'] : $this->rli_defaults['size']);
576 $old_instance['link_to'] = (isset( $new_instance['link_to'] ) && in_array( $new_instance['link_to'], array_keys( $this->rli_link_to ), true ) ? $new_instance['link_to'] : $this->rli_defaults['link_to']);
577 $old_instance['link_custom_url'] = esc_url( isset( $new_instance['link_custom_url'] ) ? $new_instance['link_custom_url'] : $this->rli_defaults['link_custom_url'] );
578 $old_instance['image_align'] = (isset( $new_instance['image_align'] ) && in_array( $new_instance['image_align'], array_keys( $this->rli_aligns ), true ) ? $new_instance['image_align'] : $this->rli_defaults['image_align']);
579 $old_instance['text'] = wp_kses_post( isset( $new_instance['text'] ) ? $new_instance['text'] : $this->rli_defaults['text'] );
580 $old_instance['autobr'] = isset( $new_instance['autobr'] ) ? true : false;
581 $old_instance['text_position'] = (isset( $new_instance['text_position'] ) && in_array( $new_instance['text_position'], array_keys( $this->rli_text_positions ), true ) ? $new_instance['text_position'] : $this->rli_defaults['text_position']);
582 $old_instance['text_align'] = (isset( $new_instance['text_align'] ) && in_array( $new_instance['text_align'], array_keys( $this->rli_aligns ), true ) ? $new_instance['text_align'] : $this->rli_defaults['text_align']);
583
584 return $old_instance;
585 }
586
587 }