PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.2.1
Responsive Lightbox & Gallery v2.2.1
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 6 years ago class-fast-image.php 8 years ago class-folders-walker.php 7 years ago class-folders.php 6 years ago class-frontend.php 6 years ago class-galleries.php 6 years ago class-remote-library-api.php 6 years ago class-remote-library.php 6 years ago class-settings.php 6 years ago class-tour.php 6 years ago class-welcome.php 6 years ago class-widgets.php 6 years ago functions.php 6 years ago
class-widgets.php
582 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 * 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 * 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 public function __construct() {
311 parent::__construct(
312 'Responsive_Lightbox_Image_Widget',
313 __( 'Image', 'responsive-lightbox' ),
314 array(
315 'description' => __( 'Displays a single image.', 'responsive-lightbox' ),
316 'classname' => 'rl-image-widget'
317 )
318 );
319
320 $this->rli_defaults = array(
321 'title' => __( 'Image', 'responsive-lightbox' ),
322 'image_id' => 0,
323 'responsive' => true,
324 'size' => 'thumbnail',
325 'link_to' => 'file',
326 'link_custom_url' => '',
327 'image_align' => 'none',
328 'text' => '',
329 'autobr' => false,
330 'text_position' => 'below_image',
331 'text_align' => 'none',
332 );
333
334 $this->rli_text_positions = array(
335 'below_image' => __( 'Below the image', 'responsive-lightbox' ),
336 'above_image' => __( 'Above the image', 'responsive-lightbox' )
337 );
338
339 $this->rli_link_to = array(
340 'none' => __( 'None', 'responsive-lightbox' ),
341 'file' => __( 'Media File', 'responsive-lightbox' ),
342 'post' => __( 'Attachment Page', 'responsive-lightbox' ),
343 'custom' => __( 'Custom URL', 'responsive-lightbox' )
344 );
345
346 $this->rli_aligns = array(
347 'none' => __( 'None', 'responsive-lightbox' ),
348 'left' => __( 'Left', 'responsive-lightbox' ),
349 'center' => __( 'Center', 'responsive-lightbox' ),
350 'right' => __( 'Right', 'responsive-lightbox' ),
351 'justify' => __( 'Justify', 'responsive-lightbox' )
352 );
353
354 $this->rli_image_sizes = array_merge( array( 'full' ), get_intermediate_image_sizes() );
355 sort( $this->rli_image_sizes, SORT_STRING );
356 }
357
358 /**
359 * Display widget.
360 *
361 * @param array $args
362 * @param object $instance
363 * @return void
364 */
365 public function widget( $args, $instance ) {
366 $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
367 $title = $args['before_widget'] . $args['before_title'] . ( $instance['title'] !== '' ? $instance['title'] : '' ) . $args['after_title'];
368
369 if ( $instance['autobr'] === true ) {
370 $text = wpautop( $instance['text'] );
371 } else {
372 $text = html_entity_decode( $instance['text'], ENT_QUOTES, 'UTF-8' );
373 }
374
375 $image = wp_get_attachment_image_src( $instance['image_id'], $instance['size'], false );
376
377 switch ( $instance['link_to'] ) {
378 case 'file' :
379 $file = wp_get_attachment_image_src( $instance['image_id'], 'full', false );
380 $href = $file[0];
381 break;
382
383 case 'post' :
384 $href = get_permalink( $instance['image_id'] );
385 break;
386
387 case 'custom' :
388 $href = $instance['link_custom_url'];
389 break;
390
391 case 'none' :
392 default :
393 $href = '';
394 break;
395 }
396
397 if ( $instance['image_align'] === 'left' )
398 $image_align = ' style="float: left;"';
399 elseif ( $instance['image_align'] === 'center' )
400 $image_align = ' style="margin-left: auto; margin-right: auto; display: block;"';
401 elseif ( $instance['image_align'] === 'right' )
402 $image_align = ' style="float: right;"';
403 else
404 $image_align = '';
405
406 if ( $instance['text_align'] === 'left' )
407 $text_align = ' style="text-align: left; display: block;"';
408 elseif ( $instance['text_align'] === 'center' )
409 $text_align = ' style="text-align: center; display: block;"';
410 elseif ( $instance['text_align'] === 'right' )
411 $text_align = ' style="text-align: right; display: block;"';
412 elseif ( $instance['text_align'] === 'justify' )
413 $text_align = ' style="text-align: justify; display: block;"';
414 else
415 $text_align = '';
416
417
418 $text_position = $instance['text_position'];
419 $width = $instance['responsive'] === false ? $image[1] : '100%';
420 $height = $instance['responsive'] === false ? $image[2] : 'auto';
421 $post = get_post( $instance['image_id'] );
422 $image_title = isset( $post->post_title ) ? $post->post_title : '';
423 $alt = (string) get_post_meta( $instance['image_id'], '_wp_attachment_image_alt', true );
424
425 $html = $title;
426
427 if ( $text_position === 'below_image' ) {
428 $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>' : '');
429 $html .= '<div class="rl-image-widget-text"' . $text_align . '>' . $text . '</div>';
430 } else {
431 $html .= '<div class="rl-image-widget-text"' . $text_align . '>' . $text . '</div>';
432 $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>' : '');
433 }
434 $html .= $args['after_widget'];
435
436 echo apply_filters( 'rl_image_widget_html', $html, $instance );
437 }
438
439 /** Render widget form.
440 *
441 * @param object $instance
442 * @return void
443 */
444 public function form( $instance ) {
445 $image_id = (int) (isset( $instance['image_id'] ) ? $instance['image_id'] : $this->rli_defaults['image_id']);
446 $image = '';
447
448 if ( ! empty( $image_id ) )
449 $image = wp_get_attachment_image( $image_id, 'medium', false );
450
451 if ( ! $image )
452 $image = wp_get_attachment_image( $image_id, 'full', false );
453
454 $html = '
455 <div class="rl-image-widget-container">
456 <p>
457 <label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title', 'responsive-lightbox' ) . '</label>
458 <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'] ) . '" />
459 </p>
460 <div class="rl-image-widget' . ( ! empty( $image_id ) ? ' has-image' : '' ) . '">
461 <input class="rl-image-widget-image-id" type="hidden" name="' . $this->get_field_name( 'image_id' ) . '" value="' . $image_id . '" />
462 <a href="#" class="rl-image-widget-select button button-secondary">' . __( 'Select image', 'responsive-lightbox' ) . '</a>
463 <div class="rl-image-widget-content">';
464 if ( ! empty( $image ) ) {
465 $html .= $image;
466 }
467 $html .= '
468 </div>
469 </div>
470 <p>
471 <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>
472 </p>';
473
474 $html .= '
475 <p>
476 <label for="' . $this->get_field_id( 'size' ) . '">' . __( 'Size', 'responsive-lightbox' ) . '</label>
477 <select class="rl-image-size-select widefat" id="' . $this->get_field_id( 'size' ) . '" name="' . $this->get_field_name( 'size' ) . '">';
478
479 $size_type = (isset( $instance['size'] ) ? $instance['size'] : $this->rli_defaults['size']);
480
481 foreach ( $this->rli_image_sizes as $size ) {
482 $html .= '
483 <option value="' . esc_attr( $size ) . '" ' . selected( $size, $size_type, false ) . '>' . $size . '</option>';
484 }
485
486 $html .= '
487 </select>
488 </p>
489 <p>
490 <label for="' . $this->get_field_id( 'link_to' ) . '">' . __( 'Link to', 'responsive-lightbox' ) . '</label>
491 <select class="rl-image-link-to widefat" id="' . $this->get_field_id( 'link_to' ) . '" name="' . $this->get_field_name( 'link_to' ) . '">';
492
493 $link_type = (isset( $instance['link_to'] ) ? $instance['link_to'] : $this->rli_defaults['link_to']);
494
495 foreach ( $this->rli_link_to as $id => $type ) {
496 $html .= '
497 <option value="' . esc_attr( $id ) . '" ' . selected( $id, $link_type, false ) . '>' . $type . '</option>';
498 }
499
500 $html .= '
501 </select>
502 </p>
503 <p class="rl-image-link-url"' . ($link_type === 'custom' ? '' : ' style="display: none;"') . '>
504 <label for="' . $this->get_field_id( 'link_custom_url' ) . '">' . __( 'URL', 'responsive-lightbox' ) . '</label>
505 <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'] ) . '" />
506 </p>';
507
508 $html .= '
509 <p>
510 <label for="' . $this->get_field_id( 'image_align' ) . '">' . __( 'Image align', 'responsive-lightbox' ) . '</label>
511 <select id="' . $this->get_field_id( 'image_align' ) . '" class="widefat" name="' . $this->get_field_name( 'image_align' ) . '">';
512
513 foreach ( $this->rli_aligns as $id => $image_align ) {
514 if ( $id != 'justify' )
515 $html .= '
516 <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['image_align'] ) ? $instance['image_align'] : $this->rli_defaults['image_align'] ), false ) . '>' . $image_align . '</option>';
517 }
518
519 $html .= '
520 </select>
521 </p>
522 <p>
523 <label for="' . $this->get_field_id( 'text' ) . '">' . __( 'Text', 'responsive-lightbox' ) . '</label>
524 <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>
525 </p>
526 <p>
527 <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>
528 </p>';
529
530 $html .= '
531 <p>
532 <label for="' . $this->get_field_id( 'text_position' ) . '">' . __( 'Text position', 'responsive-lightbox' ) . '</label>
533 <select id="' . $this->get_field_id( 'text_position' ) . '" class="widefat" name="' . $this->get_field_name( 'text_position' ) . '">';
534
535 foreach ( $this->rli_text_positions as $id => $text_position ) {
536 $html .= '
537 <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['text_position'] ) ? $instance['text_position'] : $this->rli_defaults['text_position'] ), false ) . '>' . $text_position . '</option>';
538 }
539
540 $html .= '
541 </select>
542 </p>
543 <label for="' . $this->get_field_id( 'text_align' ) . '">' . __( 'Text align', 'responsive-lightbox' ) . '</label>
544 <select id="' . $this->get_field_id( 'text_align' ) . '" class="widefat" name="' . $this->get_field_name( 'text_align' ) . '">';
545
546 foreach ( $this->rli_aligns as $id => $text_align ) {
547 $html .= '
548 <option value="' . esc_attr( $id ) . '" ' . selected( $id, (isset( $instance['text_align'] ) ? $instance['text_align'] : $this->rli_defaults['text_align'] ), false ) . '>' . $text_align . '</option>';
549 }
550
551 $html .= '
552 </select>
553
554 </div>';
555
556 echo $html;
557 }
558
559 /**
560 * Save widget form.
561 *
562 * @param array $new_instance
563 * @param array $old_instance
564 * @return array
565 */
566 public function update( $new_instance, $old_instance ) {
567 $old_instance['title'] = sanitize_text_field( isset( $new_instance['title'] ) ? $new_instance['title'] : $this->rli_defaults['title'] );
568 $old_instance['image_id'] = (int) (isset( $new_instance['image_id'] ) ? $new_instance['image_id'] : $this->rli_defaults['image_id']);
569 $old_instance['responsive'] = isset( $new_instance['responsive'] ) ? true : false;
570 $old_instance['size'] = (isset( $new_instance['size'] ) && in_array( $new_instance['size'], $this->rli_image_sizes, true ) ? $new_instance['size'] : $this->rli_defaults['size']);
571 $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']);
572 $old_instance['link_custom_url'] = esc_url( isset( $new_instance['link_custom_url'] ) ? $new_instance['link_custom_url'] : $this->rli_defaults['link_custom_url'] );
573 $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']);
574 $old_instance['text'] = wp_kses_post( isset( $new_instance['text'] ) ? $new_instance['text'] : $this->rli_defaults['text'] );
575 $old_instance['autobr'] = isset( $new_instance['autobr'] ) ? true : false;
576 $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']);
577 $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']);
578
579 return $old_instance;
580 }
581
582 }