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