PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.38
Strong Testimonials v2.38
3.3.3 3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / views-validate.php
strong-testimonials / admin Last commit date
about 7 years ago css 7 years ago img 7 years ago js 7 years ago menu 7 years ago partials 7 years ago scss 7 years ago settings 7 years ago admin-notices.php 7 years ago admin.php 7 years ago class-strong-testimonials-addons.php 7 years ago class-strong-testimonials-admin-category-list.php 7 years ago class-strong-testimonials-admin-list.php 7 years ago class-strong-testimonials-admin-scripts.php 7 years ago class-strong-testimonials-defaults.php 7 years ago class-strong-testimonials-exporter.php 7 years ago class-strong-testimonials-help.php 7 years ago class-strong-testimonials-list-table.php 7 years ago class-strong-testimonials-page-shortcodes.php 7 years ago class-strong-testimonials-post-editor.php 7 years ago class-strong-testimonials-updater.php 7 years ago class-strong-testimonials-upsell.php 7 years ago class-strong-views-list-table.php 7 years ago class-walker-strong-category-checklist.php 7 years ago class-walker-strong-form-category-checklist.php 7 years ago compat.php 7 years ago custom-fields-ajax.php 7 years ago custom-fields.php 7 years ago form-preview.php 7 years ago view-list-order.php 7 years ago views-ajax.php 7 years ago views-validate.php 7 years ago views.php 7 years ago
views-validate.php
547 lines
1 <?php
2
3 /**
4 * Validate a View's name.
5 *
6 * @since 2.11.14
7 *
8 * @param $name
9 * @param $view_id
10 *
11 * @return string
12 */
13 function wpmtst_validate_view_name( $name, $view_id ){
14 if ( '' == $name ) {
15 $name = "Testimonial View $view_id";
16 }else {
17 $name = sanitize_text_field( stripslashes( $name ) );
18 }
19
20 return $name;
21 }
22
23
24 /**
25 * Sanitize and validate a View.
26 * TODO break down into separate validators
27 *
28 * @since 1.21.0
29 * @since 2.5.7 Strip CSS from CSS Class Names field.
30 * @since 2.10.0 Provide both more_post and more_page.
31 * @since 2.11.0 More slideshow options: effect, slideshow_nav, stretch
32 * @since 2.11.4 more_full_post for manual excerpts
33 * @since 2.11.5 more_page_hook
34 *
35 * @param $input
36 *
37 * @return array
38 */
39 function wpmtst_sanitize_view( $input ) {
40 ksort( $input );
41
42 $default_view = wpmtst_get_view_default();
43
44 $data = array();
45 $data['mode'] = sanitize_text_field( $input['mode'] );
46
47 $data['form_ajax'] = isset( $input['form_ajax'] ) ? 1 : 0;
48
49 $data = wpmtst_sanitize_view_post_id( $data, $input );
50
51 $data = wpmtst_sanitize_view_template( $data, $input );
52
53 // Category
54 if ( 'form' == $data['mode'] ) {
55 if ( isset( $input['category-form'] ) ) {
56 $data['category'] = sanitize_text_field( implode( ',', $input['category-form'] ) );
57 } else {
58 $data['category'] = '';
59 }
60 } else {
61 if ( 'allcats' == $input['category_all'] ) {
62 $data['category'] = 'all';
63 } elseif ( ! isset( $input['category'] ) ) {
64 $data['category'] = 'all';
65 } elseif ( 'somecats' == $input['category_all'] && ! isset( $input['category'] ) ) {
66 $data['category'] = 'all';
67 } else {
68 $data['category'] = sanitize_text_field( implode( ',', $input['category'] ) );
69 }
70 }
71
72 $data['order'] = sanitize_text_field( $input['order'] );
73
74 // Limit
75 if ( isset( $input['all'] ) && $input['all'] ) {
76 $data['count'] = -1;
77 }
78 else {
79 $data['count'] = (int) sanitize_text_field( $input['count'] );
80 }
81
82 // Pagination
83 $data['pagination'] = isset( $input['pagination'] ) ? 1 : 0;
84 $data['pagination_settings'] = wpmtst_sanitize_view_pagination( $input['pagination_settings'] );
85
86 $data['title'] = isset( $input['title'] ) ? 1 : 0;
87 $data['title_link'] = isset( $input['title_link'] ) ? 1 : 0;
88
89 $data['content'] = sanitize_text_field( $input['content'] );
90 $data['excerpt_length'] = (int) sanitize_text_field( $input['excerpt_length'] );
91 $data['use_default_length'] = sanitize_text_field( $input['use_default_length'] );
92
93 $data = wpmtst_sanitize_view_readmore( $data, $input, $default_view );
94
95 // Thumbnail
96 $data['thumbnail'] = isset( $input['thumbnail'] ) ? 1 : 0;
97 $data['thumbnail_size'] = sanitize_text_field( $input['thumbnail_size'] );
98 $data['thumbnail_width'] = max( 0, sanitize_text_field( $input['thumbnail_width'] ) );
99 $data['thumbnail_height'] = max( 0, sanitize_text_field( $input['thumbnail_height'] ) );
100 $data['lightbox'] = isset( $input['lightbox'] ) ? 1 : 0;
101 $data['lightbox_class'] = sanitize_text_field( $input['lightbox_class'] );
102 $data['gravatar'] = sanitize_text_field( $input['gravatar'] );
103
104 /**
105 * CSS Class Names
106 * This field is being confused with custom CSS rules like `.testimonial { border: none; }`
107 * so strip periods and declarations.
108 */
109 $data['class'] = sanitize_text_field( trim( preg_replace( '/\{.*?\}|\./', '', $input['class'] ) ) );
110
111 // Background
112 $data['background'] = wpmtst_get_background_defaults();
113 if ( ! isset( $input['background']['type'] ) ) {
114 $data['background']['type'] = '';
115 }
116 else {
117 $data['background']['type'] = sanitize_text_field( $input['background']['type'] );
118 }
119 $data['background']['color'] = sanitize_hex_color( $input['background']['color'] );
120 $data['background']['gradient1'] = sanitize_hex_color( $input['background']['gradient1'] );
121 $data['background']['gradient2'] = sanitize_hex_color( $input['background']['gradient2'] );
122 $data['background']['preset'] = sanitize_text_field( $input['background']['preset'] );
123
124 // Font color
125 if ( ! isset( $input['font-color']['type'] ) ) {
126 $data['font-color']['type'] = '';
127 }
128 else {
129 $data['font-color']['type'] = sanitize_text_field( $input['font-color']['type'] );
130 }
131 $data['font-color']['color'] = sanitize_hex_color( $input['font-color']['color'] );
132
133 // Layout input may have been disabled by selecting the widget template so no value is posted.
134 if ( ! isset( $input['layout'] ) ) {
135 $data['layout'] = '';
136 }
137 else {
138 // pagination and Masonry are incompatible
139 $data['layout'] = sanitize_text_field( $input['layout'] );
140 if ( isset( $input['pagination'] ) && 'masonry' == $data['layout'] ) {
141 $data['layout'] = '';
142 }
143 }
144
145 $data['column_count'] = sanitize_text_field( $input['column_count'] );
146
147 $data['slideshow_settings'] = wpmtst_sanitize_view_slideshow( $input['slideshow_settings'] );
148
149 if ( isset( $input['client_section'] ) ) {
150 $data['client_section'] = wpmtst_sanitize_view_client_section( $input['client_section'] );
151 } else {
152 $data['client_section'] = null;
153 }
154
155 // Multiple Forms add-on
156 if ( isset( $input['form_id'] ) ) {
157 $data['form_id'] = $input['form_id'];
158 }
159 else {
160 // hidden
161 $data['form_id'] = $input['_form_id'];
162 }
163
164 // Divi Builder
165 $data['divi_builder'] = isset( $input['divi_builder'] ) ? 1 : 0;
166
167 $data = apply_filters( 'wpmtst_sanitized_view', $data, $input );
168 ksort( $data );
169
170 return $data;
171 }
172
173 /**
174 * Read-more options.
175 *
176 * @param $data
177 * @param $input
178 * @param $default_view
179 *
180 * @since 2.33.0 As separate function.
181 *
182 * @return array
183 */
184 function wpmtst_sanitize_view_readmore( $data, $input, $default_view ) {
185 if ( 'truncated' == $data['content'] || 'excerpt' == $data['content'] ) {
186 $data['more_post'] = 1;
187 } else {
188 $data['more_post'] = 0;
189 }
190 $data['more_post_ellipsis'] = sanitize_text_field( $input['more_post_ellipsis'] );
191 $data['use_default_more'] = $input['use_default_more'];
192 $data['more_post_text'] = sanitize_text_field( $input['more_post_text'] );
193 $data['less_post_text'] = sanitize_text_field( $input['less_post_text'] );
194
195 /**
196 * Read more in place
197 *
198 * @since 2.33.0
199 */
200 $data['more_post_in_place'] = isset( $input['more_post_in_place'] ) ? $input['more_post_in_place'] : 0;
201
202 /**
203 * Read more --> post (dependent on more-post-in-place)
204 */
205 $data['more_full_post'] = sanitize_text_field( $input['more_full_post'] );
206
207 /**
208 * Read more --> page
209 */
210 if ( isset( $input['more_page'] ) && $input['more_page'] ) {
211
212 // Check the "ID or slug" field first
213 if ( $input['more_page_id2'] ) {
214
215 // is post ID?
216 $id = sanitize_text_field( $input['more_page_id2'] );
217 if ( is_numeric( $id ) ) {
218 if ( ! get_posts( array( 'p' => $id, 'post_type' => array( 'page', 'post' ), 'post_status' => 'publish' ) ) ) {
219 $id = null;
220 }
221 } else {
222 // is post slug?
223 $target = get_posts( array( 'name' => $id, 'post_type' => array( 'page', 'post' ), 'post_status' => 'publish' ) );
224 if ( $target ) {
225 $id = $target[0]->ID;
226 }
227 }
228
229 if ( $id ) {
230 $data['more_page_id'] = $id;
231 unset( $data['more_page_id2'] );
232 }
233
234 } else {
235
236 if ( $input['more_page_id'] ) {
237 if ( is_numeric( $input['more_page_id'] ) ) {
238 $data['more_page_id'] = (int) sanitize_text_field( $input['more_page_id'] );
239 } else {
240 $data['more_page_id'] = sanitize_text_field( $input['more_page_id'] );
241 }
242 }
243
244 }
245
246 // Only enable more_page if a page was selected by either method.
247 if ( isset( $data['more_page_id'] ) && $data['more_page_id'] ) {
248 $data['more_page'] = 1;
249 }
250 }
251
252 if ( ! $input['more_page_text'] ) {
253 $data['more_page_text'] = $default_view['more_page_text'];
254 } else {
255 $data['more_page_text'] = sanitize_text_field( $input['more_page_text'] );
256 }
257 $data['more_page_hook'] = sanitize_text_field( $input['more_page_hook'] );
258
259 return $data;
260 }
261
262 /**
263 * Single testimonial
264 *
265 * @since 2.30.0 As separate function.
266 *
267 * @param $data array
268 * @param $input array
269 *
270 * @return array
271 */
272 function wpmtst_sanitize_view_post_id( $data, $input ) {
273 // Clear single ID if "multiple" selected
274 if ( 'multiple' == $input['select'] ) {
275 $data['id'] = 0; // must be zero not empty or false
276 return $data;
277 }
278
279 // Clear single ID if mode:slideshow selected
280 if ( 'slideshow' == $input['mode'] ) {
281 $data['id'] = 0; // must be zero not empty or false
282 return $data;
283 }
284
285 // Check the "ID or slug" field first
286 if ( ! $input['post_id'] ) {
287 $data['id'] = (int) sanitize_text_field( $input['id'] );
288 return $data;
289 }
290
291 // Is post ID?
292 $id = (int) $input['post_id'];
293 if ( $id ) {
294 $args = array(
295 'p' => $id,
296 'post_type' => 'wpm-testimonial',
297 'post_status' => 'publish',
298 );
299 if ( ! get_posts( $args ) ) {
300 $id = null;
301 }
302 }
303 else {
304 // Is post slug?
305 $args = array(
306 'name' => $input['post_id'],
307 'post_type' => 'wpm-testimonial',
308 'post_status' => 'publish',
309 );
310 $target = get_posts( $args );
311 if ( $target ) {
312 $id = $target[0]->ID;
313 }
314 }
315
316 $data['id'] = $id;
317 $data['post_id'] = '';
318
319 return $data;
320 }
321
322 /**
323 * Sanitize slideshow settings.
324 *
325 * @since 2.28.0
326 *
327 * @param $in
328 *
329 * @return array
330 */
331 function wpmtst_sanitize_view_pagination( $in ) {
332 $out['type'] = sanitize_text_field( $in['type'] );
333 $out['nav'] = str_replace( ' ', '', sanitize_text_field( $in['nav'] ) );
334 $out['show_all'] = $in['show_all'] === 'on';
335 $out['prev_next'] = wpmtst_sanitize_checkbox( $in, 'prev_next' );
336 $out['prev_text'] = sanitize_text_field( $in['prev_text'] );
337 $out['next_text'] = sanitize_text_field( $in['next_text'] );
338 $out['before_page_number'] = sanitize_text_field( $in['before_page_number'] );
339 $out['after_page_number'] = sanitize_text_field( $in['after_page_number'] );
340
341 /**
342 * Attempt to repair bug from 2.28.2
343 */
344 if ( isset( $in['end_size'] ) && intval( $in['end_size'] ) ) {
345 $out['end_size'] = (int) sanitize_text_field( $in['end_size'] );
346 }
347 else {
348 $out['end_size'] = 1;
349 }
350
351 if ( isset( $in['mid_size'] ) && intval( $in['mid_size'] ) ) {
352 $out['mid_size'] = (int) sanitize_text_field( $in['mid_size'] );
353 }
354 else {
355 $out['mid_size'] = 2;
356 }
357
358 if ( isset( $in['per_page'] ) && intval( $in['per_page'] ) ) {
359 $out['per_page'] = (int) sanitize_text_field( $in['per_page'] );
360 }
361 else {
362 $out['per_page'] = 5;
363 }
364
365 return $out;
366 }
367
368 /**
369 * Sanitize slideshow settings.
370 *
371 * @param $in
372 * @since 2.15.0
373 *
374 * @return array
375 */
376 function wpmtst_sanitize_view_slideshow( $in ) {
377 $out = array();
378
379 $out['type'] = sanitize_text_field( $in['type'] );
380
381 // Insert unused defaults.
382 $out['show_single'] = array(
383 'max_slides' => 1,
384 'move_slides' => 1,
385 'margin' => 1,
386 );
387
388 // Save carousel breakpoints.
389 $breakpoints = $in['breakpoints'];
390
391 foreach ( $breakpoints as $key => $breakpoint ) {
392
393 $out['breakpoints'][ $key ]['width'] = intval( sanitize_text_field( $breakpoint['width'] ) );
394
395 $out['breakpoints'][ $key ]['max_slides'] = intval( sanitize_text_field( $breakpoint['max_slides'] ) );
396
397 $out['breakpoints'][ $key ]['move_slides'] = intval( sanitize_text_field( $breakpoint['move_slides'] ) );
398
399 if ( $out['breakpoints'][ $key ]['move_slides'] > $out['breakpoints'][ $key ]['max_slides'] ) {
400 $out['breakpoints'][ $key ]['move_slides'] = $out['breakpoints'][ $key ]['max_slides'];
401 }
402
403 $out['breakpoints'][ $key ]['margin'] = intval( sanitize_text_field( $breakpoint['margin'] ) );
404
405 }
406
407 // Carousel requires horizontal scroll.
408 if ( 'show_multiple' == $out['type'] ) {
409 $out['effect'] = 'horizontal';
410 } else {
411 $out['effect'] = sanitize_text_field( $in['effect'] );
412 }
413
414 $out['pause'] = floatval( sanitize_text_field( $in['pause'] ) );
415 $out['speed'] = floatval( sanitize_text_field( $in['speed'] ) );
416 $out['auto_hover'] = isset( $in['auto_hover'] ) ? 1 : 0;
417 $out['stop_auto_on_click'] = isset( $in['stop_auto_on_click'] ) ? 1 : 0;
418
419 if ( 'dynamic' == $in['height'] ) {
420 $out['adapt_height'] = 1;
421 } else {
422 $out['adapt_height'] = 0;
423 }
424 $out['adapt_height_speed'] = floatval( sanitize_text_field( $in['adapt_height_speed'] ) );
425 $out['stretch'] = isset( $in['stretch'] ) ? 1 : 0;
426
427 // If no navigation, must start automatically.
428 if ( 'none' == $in['pager_type'] && 'none' == $in['controls_type'] ) {
429 $out['auto_start'] = 1;
430 } else {
431 $out['auto_start'] = isset( $in['auto_start'] ) ? 1 : 0;
432 }
433
434 // Controls
435 $out['controls_type'] = sanitize_text_field( $in['controls_type'] );
436 $out['controls_style'] = sanitize_text_field( $in['controls_style'] );
437
438 // Pagination
439 $out['pager_type'] = sanitize_text_field( $in['pager_type'] );
440 $out['pager_style'] = sanitize_text_field( $in['pager_style'] );
441
442 // Position is shared by Controls and Pagination
443 if ( $out['controls_type'] || $out['pager_type'] ) {
444 if ( 'show_multiple' == $out['type'] ) {
445 $out['nav_position'] = 'outside';
446 } else {
447 $out['nav_position'] = sanitize_text_field( $in['nav_position'] );
448 }
449 }
450
451 ksort( $out );
452
453 return $out;
454 }
455
456
457 /**
458 * Sanitize client section (custom fields).
459 *
460 * @param $in
461 * @since 2.17.0
462 *
463 * @return array
464 */
465 function wpmtst_sanitize_view_client_section( $in ) {
466 $out = array();
467
468 foreach ( $in as $key => $field ) {
469 if ( empty( $field['field'] ) ) {
470 continue;
471 }
472
473 $out[ $key ]['field'] = sanitize_text_field( $field['field'] );
474
475 if ( isset( $field['type'] ) ) {
476 $type = sanitize_text_field( $field['type'] );
477 } else {
478 $type = sanitize_text_field( $field['save-type'] );
479 }
480 $out[ $key ]['type'] = $type;
481
482 $out[ $key ]['before'] = sanitize_text_field( $field['before'] );
483
484 $out[ $key ]['class'] = sanitize_text_field( $field['class'] );
485
486 switch ( $type ) {
487 case 'link':
488 case 'link2':
489 /**
490 * If no URL, change field type to 'text'. This happens when a URL field
491 * (e.g. company_name) is removed from Custom Fields.
492 * @since 2.10.0
493 */
494 if ( ! isset( $field['url'] ) ) {
495 $out[ $key ]['type'] = 'text';
496 unset( $out[ $key ]['link_text'] );
497 unset( $out[ $key ]['link_text_custom'] );
498 unset( $out[ $key ]['new_tab'] );
499 }
500 else {
501 $out[ $key ]['url'] = sanitize_text_field( $field['url'] );
502
503 $out[ $key ]['link_text'] = isset( $field['link_text'] ) ? sanitize_text_field( $field['link_text'] ) : '';
504
505 $out[ $key ]['link_text_custom'] = isset( $field['link_text_custom'] ) ? sanitize_text_field( $field['link_text_custom'] ) : '';
506
507 $out[ $key ]['new_tab'] = isset( $field['new_tab'] ) ? 1 : 0;
508 }
509 break;
510 case 'date':
511 $format = isset( $field['format'] ) ? sanitize_text_field( $field['format'] ) : '';
512 $out[ $key ]['format'] = $format;
513 break;
514 default:
515 }
516
517 }
518
519 return $out;
520 }
521
522 /**
523 * Template settings.
524 *
525 * @param $data
526 * @param $input
527 *
528 * @return array
529 */
530 function wpmtst_sanitize_view_template( $data, $input ) {
531 if ( 'form' == $data['mode'] ) {
532 $data['template'] = isset( $input['form-template'] ) ? sanitize_text_field( $input['form-template'] ) : '';
533 } else {
534 $data['template'] = isset( $input['template'] ) ? sanitize_text_field( $input['template'] ) : '';
535 }
536
537 // To save all template settings:
538 foreach ( $input['template_settings'] as $template => $settings ) {
539 foreach ( $settings as $key => $setting ) {
540 // This does not work for checkboxes yet.
541 $data['template_settings'][ $template ][ $key ] = sanitize_text_field( $setting );
542 }
543 }
544
545 return $data;
546 }
547