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