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