PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 2.34
Strong Testimonials v2.34
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.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-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-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-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.php
887 lines
1 <?php
2 /**
3 * View admin functions.
4 *
5 * @since 1.21.0
6 */
7
8
9 /**
10 * View list page.
11 *
12 * @since 1.21.0
13 */
14 function wpmtst_views_admin() {
15 if ( ! current_user_can( 'strong_testimonials_views' ) ) {
16 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
17 }
18
19 $tags = array(
20 'a' => array(
21 'href' => array(),
22 'target' => array(),
23 ),
24 );
25
26 ?>
27 <div class="wrap wpmtst2">
28
29 <?php
30 if ( isset( $_REQUEST['result'] ) ) {
31
32 $result = filter_input( INPUT_GET, 'result', FILTER_SANITIZE_STRING );
33
34 $result_messages = array(
35 'cancelled' => __( 'Changes cancelled.', 'strong-testimonials' ),
36 'defaults-restored' => __( 'Defaults restored.', 'strong-testimonials' ),
37 'view-saved' => __( 'View saved.', 'strong-testimonials' ),
38 'view-deleted' => __( 'View deleted.', 'strong-testimonials' ),
39 );
40
41 if ( in_array( $result, array_keys( $result_messages ) ) ) {
42 printf( '<div class="notice notice-success is-dismissible"><p>%s</p></div>', wp_kses_post( $result_messages[ $result ] ) );
43 }
44 }
45
46 if ( isset( $_REQUEST['error'] ) ) {
47
48 echo '<h1>' . esc_html__( 'Edit View', 'strong-testimonials' ) . '</h1>';
49
50 $message = esc_html__( 'An error occurred.', 'strong-testimonials' );
51
52 wp_die( sprintf( '<div class="notice notice-error"><p>%s</p></div>', wp_kses_post( $message ) ) );
53
54 }
55
56 if ( isset( $_REQUEST['action'] ) ) {
57
58 $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
59 $id = abs( filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ) );
60
61 wpmtst_view_settings( $action, $id );
62
63 } else {
64
65 /**
66 * View list
67 */
68 ?>
69 <h1>
70 <?php esc_html_e( 'Views', 'strong-testimonials' ); ?>
71 <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=wpm-testimonial&page=testimonial-views&action=add' ) ); ?>" class="add-new-h2"><?php esc_html_e( 'Add New' ); ?></a>
72 <a href="#tab-panel-wpmtst-help-views" class="add-new-h2 open-help-tab"><?php esc_html_e( 'Help' ); ?></a>
73 </h1>
74
75 <?php
76 // Fetch views after heading and before intro in case we need to display any database errors.
77 $views = wpmtst_get_views();
78
79 // Add button to clear sort value.
80 if ( isset( $_GET['orderby'] ) ) {
81 ?>
82 <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" style="margin-bottom: 4px;">
83 <input type="hidden" name="action" value="clear-view-sort">
84 <input type="submit" value="clear sort" class="button">
85 </form>
86 <?php
87 }
88
89 // Display the table
90 $views_table = new Strong_Views_List_Table();
91 $views_table->prepare_list( wpmtst_unserialize_views( $views ) );
92 $views_table->display();
93
94 }
95 ?>
96 </div><!-- .wrap -->
97 <?php
98 }
99
100
101 /**
102 * An individual view settings page.
103 *
104 * @since 1.21.0
105 *
106 * @param string $action
107 * @param null $view_id
108 */
109 function wpmtst_view_settings( $action = '', $view_id = null ) {
110
111 $actions = array( 'edit', 'duplicate', 'add' );
112 if ( ! in_array( $action, $actions ) ) {
113 wp_die( esc_html__( 'Invalid request. Please try again.', 'strong-testimonials' ) );
114 }
115
116 if ( ( 'edit' == $action || 'duplicate' == $action ) && ! $view_id ) {
117 return;
118 }
119
120 global $view;
121 add_thickbox();
122
123 $fields = wpmtst_get_custom_fields();
124 $all_fields = wpmtst_get_all_fields();
125
126 $testimonials_list = get_posts(
127 array(
128 'orderby' => 'post_date',
129 'order' => 'ASC',
130 'post_type' => 'wpm-testimonial',
131 'post_status' => 'publish',
132 'posts_per_page' => -1,
133 'suppress_filters' => true,
134 )
135 );
136
137 $cat_count = wpmtst_get_cat_count();
138
139 /**
140 * Show category filter if necessary.
141 *
142 * @since 2.2.0
143 */
144 if ( $cat_count > 5 ) {
145 wp_enqueue_script( 'wpmtst-view-category-filter-script' );
146 }
147
148 $default_view = wpmtst_get_view_default();
149
150 if ( 'edit' == $action ) {
151 $view_array = wpmtst_get_view( $view_id );
152 $view = unserialize( $view_array['value'] );
153 $view_name = $view_array['name'];
154 } elseif ( 'duplicate' == $action ) {
155 $view_array = wpmtst_get_view( $view_id );
156 $view = unserialize( $view_array['value'] );
157 $view_id = 0;
158 $view_name = $view_array['name'] . ' - COPY';
159 } else {
160 $view_id = 1;
161 $view = $default_view;
162 $view_name = 'new';
163 }
164
165 /**
166 * Attempt to repair bug from 2.28.2
167 */
168 if ( ! isset( $view['pagination_settings']['end_size'] ) || ! $view['pagination_settings']['end_size'] ) {
169 $view['pagination_settings']['end_size'] = 1;
170 }
171 if ( ! isset( $view['pagination_settings']['mid_size'] ) || ! $view['pagination_settings']['mid_size'] ) {
172 $view['pagination_settings']['mid_size'] = 2;
173 }
174 if ( ! isset( $view['pagination_settings']['per_page'] ) || ! $view['pagination_settings']['per_page'] ) {
175 $view['pagination_settings']['per_page'] = 5;
176 }
177
178 $custom_list = apply_filters( 'wpmtst_custom_pages_list', array(), $view );
179 $pages_list = apply_filters( 'wpmtst_pages_list', wpmtst_get_pages() );
180 $posts_list = apply_filters( 'wpmtst_posts_list', wpmtst_get_posts() );
181
182 $view_options = apply_filters( 'wpmtst_view_options', get_option( 'wpmtst_view_options' ) );
183
184 // Select default template if necessary
185 if ( ! $view['template'] ) {
186 if ( 'form' == $view['mode'] ) {
187 $view['template'] = 'default-form';
188 } else {
189 $view['template'] = 'default';
190 }
191 }
192
193 $view_cats_array = apply_filters( 'wpmtst_l10n_cats', explode( ',', $view['category'] ) );
194
195 // Assemble list of templates
196 $templates = array(
197 'display' => WPMST()->templates->get_templates( 'display' ),
198 'form' => WPMST()->templates->get_templates( 'form' ),
199 );
200 $template_keys = WPMST()->templates->get_template_keys();
201 $template_found = in_array( $view['template'], $template_keys );
202
203 // Get list of image sizes
204 $image_sizes = wpmtst_get_image_sizes();
205
206 $url = admin_url( 'edit.php?post_type=wpm-testimonial&page=testimonial-views' );
207 $url1 = $url . '&action=add';
208 $url2 = $url . '&action=duplicate&id=' . $view_id;
209 ?>
210 <h1>
211 <?php 'edit' == $action ? esc_html_e( 'Edit View', 'strong-testimonials' ) : esc_html_e( 'Add View', 'strong-testimonials' ); ?>
212 <a href="<?php echo esc_url( $url1 ); ?>" class="add-new-h2"><?php esc_html_e( 'Add New' ); ?></a>
213 <a href="<?php echo esc_url( $url ); ?>" class="add-new-h2"><?php esc_html_e( 'Return To List', 'strong-testimonials' ); ?></a>
214 <?php if ( 'edit' == $action ) : ?>
215 <a href="<?php echo esc_url( $url2 ); ?>" class="add-new-h2"><?php esc_html_e( 'Duplicate This View', 'strong-testimonials' ); ?></a>
216 <?php endif; ?>
217 </h1>
218
219 <form id="wpmtst-views-form" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" autocomplete="off">
220
221 <?php wp_nonce_field( 'view_form_submit', 'view_form_nonce', true, true ); ?>
222
223 <input type="hidden" name="action" value="view_<?php echo esc_attr( $action ); ?>_form">
224 <input type="hidden" name="view[id]" value="<?php echo esc_attr( $view_id ); ?>">
225 <input type="hidden" name="view_original_mode" value="<?php echo esc_attr( $view['mode'] ); ?>">
226 <input type="hidden" name="view[data][_form_id]" value="<?php echo esc_attr( $view['form_id'] ); ?>">
227
228 <div class="table view-info">
229 <?php include 'partials/views/view-name.php'; ?>
230 <?php include 'partials/views/view-shortcode.php'; ?>
231 <?php include 'partials/views/view-mode.php'; ?>
232 </div>
233
234 <?php
235 // TODO Generify both hook and include
236 do_action( 'wpmtst_view_editor_before_group_select' );
237 include 'partials/views/group-query.php';
238
239 do_action( 'wpmtst_view_editor_before_group_slideshow' );
240 include 'partials/views/group-slideshow.php';
241
242 do_action( 'wpmtst_view_editor_before_group_fields' );
243 include 'partials/views/group-fields.php';
244
245 do_action( 'wpmtst_view_editor_before_group_form' );
246 include 'partials/views/group-form.php';
247
248 do_action( 'wpmtst_view_editor_before_group_extra' );
249 include 'partials/views/group-extra.php';
250
251 do_action( 'wpmtst_view_editor_before_group_style' );
252 include 'partials/views/group-style.php';
253
254 do_action( 'wpmtst_view_editor_before_group_compat' );
255 include 'partials/views/group-compat.php';
256
257 // For back-compat. General group no longer used.
258 do_action( 'wpmtst_view_editor_before_group_general' );
259
260 do_action( 'wpmtst_view_editor_after_groups' );
261 ?>
262
263 <p class="wpmtst-submit">
264 <?php submit_button( '', 'primary', 'submit-form', false ); ?>
265 <?php submit_button( __( 'Cancel Changes', 'strong-testimonials' ), 'secondary', 'reset', false ); ?>
266 <?php submit_button( __( 'Restore Defaults', 'strong-testimonials' ), 'secondary', 'restore-defaults', false ); ?>
267 </p>
268
269 </form>
270 <?php
271 }
272
273
274 /**
275 * Process form POST after editing.
276 *
277 * Thanks http://stackoverflow.com/a/20003981/51600
278 *
279 * @since 1.21.0
280 */
281 function wpmtst_view_edit_form() {
282
283 $goback = wp_get_referer();
284
285 if ( empty( $_POST ) || ! check_admin_referer( 'view_form_submit', 'view_form_nonce' ) ) {
286 $goback = add_query_arg( 'result', 'error', $goback );
287 wp_redirect( $goback );
288 exit;
289 }
290
291 $view_id = abs( filter_var( $_POST['view']['id'], FILTER_SANITIZE_NUMBER_INT ) );
292 $view_name = wpmtst_validate_view_name( $_POST['view']['name'], $view_id );
293
294 if ( isset( $_POST['reset'] ) ) {
295
296 // Undo changes
297 $goback = add_query_arg( 'result', 'cancelled', $goback );
298
299 } elseif ( isset( $_POST['restore-defaults'] ) ) {
300
301 // Restore defaults
302 $default_view = wpmtst_get_view_default();
303
304 $view = array(
305 'id' => $view_id,
306 'name' => $view_name,
307 'data' => $default_view,
308 );
309 $success = wpmtst_save_view( $view ); // num_rows
310
311 if ( $success ) {
312 $goback = add_query_arg( 'result', 'defaults-restored', $goback );
313 } else {
314 $goback = add_query_arg( 'result', 'error', $goback );
315 }
316 } elseif ( isset( $_POST['submit-form'] ) ) {
317
318 // Sanitize & validate
319 $view = array(
320 'id' => $view_id,
321 'name' => $view_name,
322 'data' => wpmtst_sanitize_view( stripslashes_deep( $_POST['view']['data'] ) ),
323 );
324 $success = wpmtst_save_view( $view ); // num_rows
325
326 if ( $success ) {
327 $goback = add_query_arg( 'result', 'view-saved', $goback );
328 } else {
329 $goback = add_query_arg( 'result', 'error', $goback );
330 }
331 } else {
332
333 $goback = add_query_arg( 'result', 'error', $goback );
334
335 }
336
337 wp_redirect( $goback );
338 exit;
339
340 }
341 add_action( 'admin_post_view_edit_form', 'wpmtst_view_edit_form' );
342
343
344 /**
345 * Process form POST after adding.
346 *
347 * @since 1.21.0
348 */
349 function wpmtst_view_add_form() {
350
351 $goback = wp_get_referer();
352
353 if ( empty( $_POST ) || ! check_admin_referer( 'view_form_submit', 'view_form_nonce' ) ) {
354 $goback = add_query_arg( 'result', 'error', $goback );
355 wp_redirect( $goback );
356 exit;
357 }
358
359 $view_id = 0;
360 $view_name = wpmtst_validate_view_name( $_POST['view']['name'], $view_id );
361
362 if ( isset( $_POST['restore-defaults'] ) ) {
363
364 // Restore defaults
365 $default_view = wpmtst_get_view_default();
366
367 $view = array(
368 'id' => $view_id,
369 'name' => $view_name,
370 'data' => $default_view,
371 );
372 $success = wpmtst_save_view( $view, 'add' ); // view ID
373
374 $query_arg = 'defaults-restored';
375
376 } elseif ( isset( $_POST['submit-form'] ) ) {
377
378 // Sanitize & validate
379 $view = array(
380 'id' => 0,
381 'name' => $view_name,
382 'data' => wpmtst_sanitize_view( stripslashes_deep( $_POST['view']['data'] ) ),
383 );
384 $success = wpmtst_save_view( $view, 'add' ); // view ID
385
386 $query_arg = 'view-saved';
387
388 } else {
389
390 $success = false;
391 $query_arg = 'error';
392
393 }
394
395 if ( $success ) {
396 $goback = add_query_arg(
397 array(
398 'action' => 'edit',
399 'id' => $success,
400 'result' => $query_arg,
401 ),
402 $goback
403 );
404 } else {
405 $goback = add_query_arg( 'result', 'error', $goback );
406 }
407
408 wp_redirect( $goback );
409 exit;
410
411 }
412 add_action( 'admin_post_view_add_form', 'wpmtst_view_add_form' );
413 add_action( 'admin_post_view_duplicate_form', 'wpmtst_view_add_form' );
414
415
416 /**
417 * --------------
418 * VIEW FUNCTIONS
419 * --------------
420 */
421
422 /**
423 * Fetch pages, bypass filters.
424 *
425 * @since 2.10.0
426 *
427 * @return array|null|object
428 */
429 function wpmtst_get_pages() {
430 global $wpdb;
431 $query = "SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY post_title ASC";
432
433 $pages = $wpdb->get_results( $query );
434
435 return $pages;
436 }
437
438
439 /**
440 * Fetch pages, bypass filters.
441 *
442 * @since 2.10.0
443 *
444 * @return array|null|object
445 */
446 function wpmtst_get_posts() {
447 global $wpdb;
448 $query = "SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_title ASC";
449
450 $posts = $wpdb->get_results( $query );
451
452 return $posts;
453 }
454
455 /**
456 * Filter the custom fields.
457 * Until WordPress abandons PHP 5.2
458 *
459 * @since 2.17.0 Remove [category] from custom because it's included in [optional].
460 * @since 2.23.0 Remove checkboxes.
461 *
462 * @param $field
463 *
464 * @return bool
465 */
466 function wpmtst_array_filter__custom_fields( $field ) {
467 if ( 'category' == strtok( $field['input_type'], '-' ) ) {
468 return false;
469 }
470 if ( 'checkbox' == $field['input_type'] ) {
471 return false;
472 }
473
474 return true;
475 }
476
477
478 /**
479 * Show a single client field's inputs.
480 *
481 * @since 1.21.0
482 *
483 * @param $key
484 * @param $field
485 * @param bool $adding
486 */
487 function wpmtst_view_field_inputs( $key, $field, $adding = false ) {
488 $custom_fields = array_filter( wpmtst_get_custom_fields(), 'wpmtst_array_filter__custom_fields' );
489
490 $builtin_fields = wpmtst_get_builtin_fields();
491
492 $all_fields = array(
493 __( 'custom', 'strong-testimonials' ) => $custom_fields,
494 __( 'built-in', 'strong-testimonials' ) => $builtin_fields,
495 );
496
497 $allowed = array( 'custom', 'optional', 'builtin' );
498
499 // TODO Move this to view defaults option.
500 $types = array(
501 'text' => __( 'text', 'strong-testimonials' ),
502 'link' => __( 'link with another field', 'strong-testimonials' ), // the original link type
503 'link2' => __( 'link (must be URL type)', 'strong-testimonials' ), // @since 1.24.0
504 'date' => __( 'date', 'strong-testimonials' ),
505 'category' => __( 'category', 'strong-testimonials' ),
506 'rating' => __( 'rating', 'strong-testimonials' ),
507 'shortcode' => __( 'shortcode', 'strong-testimonials' ),
508 );
509
510 if ( isset( $custom_fields[ $field['field'] ] ) ) {
511 $field_label = $custom_fields[ $field['field'] ]['label'];
512 } else {
513 $field_label = ucwords( str_replace( '_', ' ', $field['field'] ) );
514 }
515
516 /**
517 * Catch and highlight fields not found in custom fields; i.e. it has been deleted.
518 *
519 * @since 2.17.0
520 */
521 $all_field_names = array_merge( array_keys( $custom_fields ), array( 'post_date', 'submit_date', 'category' ) );
522 $label_class = '';
523 if ( ! $adding && ! in_array( $field['field'], $all_field_names ) ) {
524 $field_label .= ' < ERROR - not found >';
525 $label_class = 'error';
526 }
527 ?>
528 <div id="field-<?php echo esc_attr( $key ); ?>" class="field2">
529
530 <div class="field3" data-key="<?php echo esc_attr( $key ); ?>">
531
532 <div class="link" title="<?php esc_attr_e( 'click to open or close', 'strong-testimonials' ); ?>">
533
534 <a href="#" class="field-description <?php echo esc_attr( $label_class ); ?>"><?php echo esc_html( $field_label ); ?></a>
535
536 <div class="controls2 left">
537 <span class="handle ui-sortable-handle icon-wrap" title="<?php esc_attr_e( 'drag and drop to reorder', 'strong-testimonials' ); ?>"></span>
538 <span class="delete icon-wrap" title="<?php esc_attr_e( 'remove this field', 'strong-testimonials' ); ?>"></span>
539 </div>
540
541 <div class="controls2 right">
542 <span class="toggle icon-wrap" title="<?php esc_attr_e( 'click to open or close', 'strong-testimonials' ); ?>"></span>
543 </div>
544
545 </div>
546
547 <div class="field-properties" style="display: none;">
548
549 <!-- FIELD NAME -->
550 <div class="field-property field-name">
551 <label for="client_section_<?php echo esc_attr( $key ); ?>_field">
552 <?php esc_html_e( 'Name', 'strong-testimonials' ); ?>
553 </label>
554 <select id="client_section_<?php echo esc_attr( $key ); ?>_field" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][field]" class="first-field">
555 <option value="">&mdash; select a field &mdash;</option>
556
557 <?php foreach ( $all_fields as $group_name => $group ) : ?>
558 <optgroup label="<?php echo esc_attr( $group_name ); ?>">
559
560 <?php foreach ( $group as $key2 => $field2 ) : ?>
561 <?php if ( in_array( $field2['record_type'], $allowed ) && 'email' != $field2['input_type'] ) : ?>
562 <option value="<?php echo esc_attr( $field2['name'] ); ?>" data-type="<?php echo esc_attr( $field2['input_type'] ); ?>"
563 <?php selected( $field2['name'], $field['field'] ); ?>><?php echo esc_html( $field2['name'] ); ?></option>
564 <?php endif; ?>
565 <?php endforeach; ?>
566
567 </optgroup>
568 <?php endforeach; ?>
569 </select>
570 </div>
571
572 <!-- FIELD TYPE -->
573 <div class="field-property field-type field-dep"
574 <?php
575 if ( $adding ) {
576 echo ' style="display: none;"';}
577 ?>
578 >
579 <label for="client_section_<?php echo esc_attr( $key ); ?>_type">
580 <?php esc_html_e( 'Display Type', 'strong-testimonials' ); ?>
581 </label>
582 <select id="client_section_<?php echo esc_attr( $key ); ?>_type" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][type]">
583 <?php foreach ( $types as $type => $type_label ) : ?>
584 <option value="<?php echo esc_attr( $type ); ?>" <?php selected( $type, $field['type'] ); ?>><?php echo esc_html( $type_label ); ?></option>
585 <?php endforeach; ?>
586 </select>
587 </div>
588
589 <!-- FIELD META -->
590 <div class="field-property-box field-meta field-dep"
591 <?php
592 if ( $adding ) {
593 echo ' style="display: none;"';}
594 ?>
595 >
596 <?php
597 if ( 'link' == $field['type'] || 'link2' == $field['type'] ) {
598 wpmtst_view_field_link( $key, $field['field'], $field['type'], $field );
599 }
600
601 if ( 'date' == $field['type'] ) {
602 wpmtst_view_field_date( $key, $field );
603 }
604 ?>
605 </div>
606
607 <!-- FIELD BEFORE -->
608 <div class="field-property field-before field-dep"
609 <?php
610 if ( $adding ) {
611 echo ' style="display: none;"';}
612 ?>
613 >
614 <label for="client_section_<?php echo esc_attr( $key ); ?>_before">
615 <?php esc_html_e( 'Before', 'strong-testimonials' ); ?>
616 </label>
617 <input id="client_section_<?php echo esc_attr( $key ); ?>_before" type="text" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][before]" value="<?php echo isset( $field['before'] ) ? esc_attr( $field['before'] ) : ''; ?>">
618 </div>
619
620 <!-- FIELD CSS CLASS -->
621 <div class="field-property field-css field-dep"
622 <?php
623 if ( $adding ) {
624 echo ' style="display: none;"';}
625 ?>
626 >
627 <label for="client_section_<?php echo esc_attr( $key ); ?>_class">
628 <?php esc_html_e( 'CSS Class', 'strong-testimonials' ); ?>
629 </label>
630 <input id="client_section_<?php echo esc_attr( $key ); ?>_class" type="text" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][class]" value="<?php echo esc_attr( $field['class'] ); ?>">
631 </div>
632
633 </div>
634
635 </div>
636
637 </div>
638 <?php
639 }
640
641
642 /**
643 * Show a single client link field inputs.
644 *
645 * @since 1.21.0
646 *
647 * @param $key
648 * @param $field_name
649 * @param $type
650 * @param $field
651 * @param bool|false $adding
652 */
653 function wpmtst_view_field_link( $key, $field_name, $type, $field, $adding = false ) {
654 if ( $field_name ) {
655 $current_field = wpmtst_get_field_by_name( $field_name );
656 if ( is_array( $current_field ) ) {
657 $field = array_merge( $current_field, $field );
658 }
659 }
660
661 $custom_fields = wpmtst_get_custom_fields();
662
663 // Add placeholder link_text and label to field in case we need to populate link_text
664 if ( ! isset( $field['link_text'] ) ) {
665 $field['link_text'] = 'field';
666 }
667 if ( ! isset( $field['link_text_custom'] ) ) {
668 $field['link_text_custom'] = '';
669 }
670 $field['label'] = wpmtst_get_field_label( $field );
671 ?>
672
673 <?php // the link text ?>
674 <div class="flex">
675 <label for="view-fieldtext<?php echo esc_attr( $key ); ?>"><?php esc_html_e( 'Link Text', 'strong-testimonials' ); ?></label>
676 <select id="view-fieldtext<?php echo esc_attr( $key ); ?>" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][link_text]" class="if selectgroup">
677 <option value="value" <?php selected( $field['link_text'], 'value' ); ?>><?php esc_html_e( "this field's value", 'strong-testimonials' ); ?></option>
678 <option value="label" <?php selected( $field['link_text'], 'label' ); ?>><?php esc_html_e( "this field's label", 'strong-testimonials' ); ?></option>
679 <option value="custom" <?php selected( $field['link_text'], 'custom' ); ?>><?php esc_html_e( 'custom text', 'strong-testimonials' ); ?></option>
680 </select>
681 </div>
682
683 <?php // the link text options ?>
684 <?php // use the field label ?>
685 <div class="flex then_fieldtext<?php echo esc_attr( $key ); ?> then_label then_not_value then_not_custom" style="display: none;">
686 <div class="nolabel">&nbsp;</div>
687 <input type="text" id="view-fieldtext<?php echo esc_attr( $key ); ?>-label" value="<?php echo esc_attr( $field['label'] ); ?>" readonly>
688 </div>
689 <?php // use custom text ?>
690 <div class="flex then_fieldtext<?php echo esc_attr( $key ); ?> then_custom then_not_value then_not_label" style="display: none;">
691 <div class="nolabel">&nbsp;</div>
692 <input type="text" id="view-fieldtext<?php echo esc_attr( $key ); ?>-custom" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][link_text_custom]" value="<?php echo esc_attr( $field['link_text_custom'] ); ?>">
693 </div>
694
695 <?php // the URL ?>
696 <?php if ( 'link' == $type ) : // URL = another field ?>
697 <div class="flex">
698 <label for="view-fieldurl<?php echo esc_attr( $key ); ?>"><?php esc_html_e( 'URL Field', 'strong-testimonials' ); ?></label>
699 <select id="view-fieldurl<?php echo esc_attr( $key ); ?>" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][url]" class="field-type-select">
700 <?php foreach ( $custom_fields as $key2 => $field2 ) : ?>
701 <?php if ( 'url' == $field2['input_type'] ) : ?>
702 <option value="<?php echo esc_attr( $field2['name'] ); ?>" <?php selected( $field2['name'], $field['url'] ); ?>><?php echo esc_html( $field2['name'] ); ?></option>
703 <?php endif; ?>
704 <?php endforeach; ?>
705 </select>
706 </div>
707 <div class="flex">
708 <?php // the URL options ?>
709 <div class="nolabel"></div>
710 <div class="new_tab">
711 <input type="checkbox" id="view-fieldurl<?php echo esc_attr( $key ); ?>-newtab" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][new_tab]" value="1" <?php checked( $field['new_tab'] ); ?>>
712 <label for="view-fieldurl<?php echo esc_attr( $key ); ?>-newtab">
713 <?php esc_html_e( 'new tab', 'strong-testimonials' ); ?>
714 </label>
715 </div>
716
717 </div>
718 <?php else : // URL = this field ?>
719 <input type="hidden" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][url]" value="<?php echo esc_attr( $field['name'] ); ?>">
720 <?php endif; ?>
721
722 <?php
723 }
724
725
726 /**
727 * Show a single client date field inputs.
728 *
729 * @since 1.21.0
730 *
731 * @param $key
732 * @param $field
733 * @param bool $adding
734 */
735 function wpmtst_view_field_date( $key, $field, $adding = false ) {
736 ?>
737 <div class="flex">
738 <label for="view-<?php echo esc_attr( $key ); ?>-client-date-format"><span><?php esc_html_e( 'Format', 'strong-testimonials' ); ?></span></label>
739 <input id="view-<?php echo esc_attr( $key ); ?>-client-date-format" type="text" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][format]" class="field-type-date" value="<?php echo isset( $field['format'] ) ? esc_attr( $field['format'] ) : ''; ?>">
740 </div>
741 <div class="flex">
742 <div class="nolabel">&nbsp;</div>
743 <div class="help minor">
744 <?php
745 printf(
746 '<a href="%s" target="_blank">%s</a>',
747 esc_url( 'https://codex.wordpress.org/Formatting_Date_and_Time' ),
748 esc_html__( 'more about date formats', 'strong-testimonials' )
749 );
750 ?>
751 </div>
752 </div>
753 <?php
754 }
755
756
757 /**
758 * Delete a view.
759 *
760 * @since 1.21.0
761 * @param $id
762 * @return false|int
763 */
764 function wpmtst_delete_view( $id ) {
765 global $wpdb;
766 $num_rows_deleted = $wpdb->delete( $wpdb->prefix . 'strong_views', array( 'id' => $id ) );
767 return $num_rows_deleted;
768 }
769
770
771 /**
772 * Admin action hook to delete a view.
773 *
774 * @since 1.21.0
775 */
776 function wpmtst_action_delete_view() {
777 if ( isset( $_REQUEST['action'] ) && 'delete-strong-view' == $_REQUEST['action'] && isset( $_REQUEST['id'] ) ) {
778 $id = abs( (int) filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ) );
779 check_admin_referer( 'delete-strong-view_' . $id );
780 wpmtst_delete_view( $id );
781 $goback = add_query_arg( 'result', 'view-deleted', wp_get_referer() );
782 wp_redirect( $goback );
783 exit;
784 }
785 }
786 add_action( 'admin_action_delete-strong-view', 'wpmtst_action_delete_view' );
787
788
789 /**
790 * Category selector in Display mode in view editor.
791 *
792 * @param $view_cats_array
793 */
794 function wpmtst_category_checklist( $view_cats_array ) {
795 ?>
796 <div class="view-category-list-panel short-panel">
797 <div class="fc-search-wrap">
798 <input type="search" class="fc-search-field" placeholder="<?php esc_attr_e( 'filter categories', 'strong-testimonials' ); ?>"/>
799 </div>
800 <ul class="view-category-list">
801 <?php
802 $args = array(
803 'descendants_and_self' => 0,
804 'selected_cats' => $view_cats_array,
805 'popular_cats' => false,
806 'walker' => new Walker_Strong_Category_Checklist(),
807 'taxonomy' => 'wpm-testimonial-category',
808 'checked_ontop' => true,
809 );
810 ?>
811 <?php wp_terms_checklist( 0, $args ); ?>
812 </ul>
813 </div>
814 <?php
815 }
816
817
818 /**
819 * Category selector in Form mode in view editor.
820 *
821 * @param $view_cats_array
822 */
823 function wpmtst_form_category_checklist( $view_cats_array ) {
824 ?>
825 <div class="view-category-list-panel short-panel">
826 <div class="fc-search-wrap">
827 <input type="search" class="fc-search-field" placeholder="<?php esc_attr_e( 'filter categories', 'strong-testimonials' ); ?>"/>
828 </div>
829 <ul class="view-category-list">
830 <?php
831 $args = array(
832 'descendants_and_self' => 0,
833 'selected_cats' => $view_cats_array,
834 'popular_cats' => false,
835 'walker' => new Walker_Strong_Form_Category_Checklist(),
836 'taxonomy' => 'wpm-testimonial-category',
837 'checked_ontop' => true,
838 );
839 ?>
840 <?php wp_terms_checklist( 0, $args ); ?>
841 </ul>
842 </div>
843 <?php
844 }
845
846
847 /**
848 * Save sticky view
849 *
850 * @since 2.22.0
851 */
852 function wpmtst_save_view_sticky() {
853 $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
854 $stickies = get_option( 'wpmtst_sticky_views', array() );
855 if ( in_array( $id, $stickies ) ) {
856 $stickies = array_diff( $stickies, array( $id ) );
857 $is_sticky = false;
858 } else {
859 $stickies[] = $id;
860 $is_sticky = true;
861 }
862 update_option( 'wpmtst_sticky_views', $stickies );
863 echo json_encode( $is_sticky );
864 wp_die();
865 }
866 add_action( 'wp_ajax_wpmtst_save_view_sticky', 'wpmtst_save_view_sticky' );
867
868
869 /**
870 * Return classes for toggling sections.
871 *
872 * @param $classes
873 * @param $section
874 *
875 * @since 2.22.0
876 *
877 * @return string
878 */
879 function wpmtst_view_section_filter( $classes, $section ) {
880 if ( 'compat' == $section && wpmtst_divi_builder_active() ) {
881 $classes = 'then_display then_form then_slideshow then_not_single_template';
882 }
883
884 return $classes;
885 }
886 add_filter( 'wpmtst_view_section', 'wpmtst_view_section_filter', 10, 2 );
887