PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / classes / PodsUI.php
pods / classes Last commit date
cli 3 days ago fields 3 days ago widgets 3 days ago Pods.php 3 days ago PodsAPI.php 3 days ago PodsAdmin.php 3 days ago PodsArray.php 3 days ago PodsComponent.php 3 days ago PodsComponents.php 3 days ago PodsData.php 3 days ago PodsField.php 3 days ago PodsForm.php 3 days ago PodsI18n.php 3 days ago PodsInit.php 3 days ago PodsMeta.php 3 days ago PodsMigrate.php 3 days ago PodsRESTFields.php 3 days ago PodsRESTHandlers.php 3 days ago PodsTermSplitting.php 3 days ago PodsUI.php 3 days ago PodsView.php 3 days ago
PodsUI.php
5832 lines
1 <?php
2
3 /**
4 * @package Pods
5 */
6 class PodsUI {
7
8 /**
9 * @var null Nonce for security
10 */
11 private $_nonce = null;
12
13 // internal
14 /**
15 * @var bool|PodsData
16 */
17 private $pods_data = false;
18
19 /**
20 * @var array
21 */
22 private $actions = array(
23 'manage',
24 'add',
25 'edit',
26 'duplicate',
27 'save',
28 // 'view',
29 'delete',
30 'reorder',
31 'export',
32 );
33
34 /**
35 * @var array
36 */
37 private $ui_page = array();
38
39 /**
40 * @var bool
41 */
42 private $unique_identifier = false;
43
44 // base
45 public $x = array();
46
47 /**
48 * @var array|bool|mixed|null|Pods
49 */
50 public $pod = false;
51
52 /**
53 * @var int
54 */
55 public $id = 0;
56
57 /**
58 * The prefix used for all URL parameters used by PodsUI.
59 *
60 * @since 2.7.28
61 *
62 * @var string
63 */
64 public $num_prefix = '';
65
66 /**
67 * Allows multiple co-existing PodsUI instances with separate functionality in URL.
68 *
69 * @var string
70 */
71 public $num = '';
72
73 /**
74 * @var array
75 */
76 public static $excluded = array(
77 'do',
78 'id',
79 'pg',
80 'search',
81 'filter_*',
82 'orderby',
83 'orderby_dir',
84 'limit',
85 'action',
86 'action_bulk',
87 'action_bulk_ids',
88 '_wpnonce',
89 'view',
90 'export',
91 'export_type',
92 'export_delimiter',
93 'remove_export',
94 'updated',
95 'duplicate',
96 'message',
97 );
98 // used in var_update
99 public static $allowed = array(
100 'page',
101 'post_type',
102 );
103
104 // ui
105 /**
106 * @var bool
107 */
108 public $item = false;
109 // to be set with localized string
110 /**
111 * @var bool
112 */
113 public $items = false;
114 // to be set with localized string
115 /**
116 * @var bool
117 */
118 public $heading = false;
119 // to be set with localized string array
120 /**
121 * @var bool
122 */
123 public $header = false;
124 // to be set with localized string array
125 /**
126 * @var bool
127 */
128 public $label = false;
129 // to be set with localized string array
130 /**
131 * @var bool
132 */
133 public $icon = false;
134
135 /**
136 * @var bool
137 */
138 public $css = false;
139 // set to a URL of stylesheet to include
140 /**
141 * @var bool
142 */
143 public $wpcss = false;
144 // set to true to include WP Admin stylesheets
145 /**
146 * @var array
147 */
148 public $fields = array(
149 'manage' => array(),
150 'search' => array(),
151 'sort' => array(),
152 'form' => array(),
153 'add' => array(),
154 'edit' => array(),
155 'duplicate' => array(),
156 'view' => array(),
157 'reorder' => array(),
158 'export' => array(),
159 );
160
161 /**
162 * Which field sets haven set up.
163 *
164 * @since 2.7.28
165 *
166 * @var array
167 */
168 public $fields_setup = array();
169
170 /**
171 * @var bool
172 */
173 public $searchable = true;
174
175 /**
176 * @var bool
177 */
178 public $sortable = true;
179
180 /**
181 * @var bool
182 */
183 public $pagination = true;
184
185 /**
186 * The type of pagination to use.
187 *
188 * @since 2.7.28
189 *
190 * @var string
191 */
192 public $pagination_type = 'table';
193
194 /**
195 * The location of where to show pagination.
196 *
197 * @since 2.7.28
198 *
199 * @var string
200 */
201 public $pagination_location = 'both';
202
203 /**
204 * @var bool
205 */
206 public $pagination_total = true;
207
208 /**
209 * @var array
210 */
211 public $export = array(
212 'on' => false,
213 'formats' => array(
214 'csv' => ',',
215 'tsv' => "\t",
216 'xml' => false,
217 'json' => false,
218 ),
219 'url' => false,
220 'type' => false,
221 );
222
223 /**
224 * @var array
225 */
226 public $reorder = array(
227 'on' => false,
228 'limit' => 250,
229 'orderby' => false,
230 'orderby_dir' => 'ASC',
231 'sql' => null,
232 );
233
234 /**
235 * @var array
236 */
237 public $screen_options = array();
238 // set to 'page' => 'Text'; false hides link
239 /**
240 * @var array
241 */
242 public $help = array();
243 // set to 'page' => 'Text'; 'page' => array('link' => 'yourhelplink'); false hides link
244 // data
245 /**
246 * @var bool
247 */
248 public $search = false;
249
250 /**
251 * @var bool
252 */
253 public $filters_enhanced = false;
254
255 /**
256 * @var array
257 */
258 public $filters = array();
259
260 /**
261 * @var string
262 */
263 public $view = false;
264
265 /**
266 * @var array
267 */
268 public $views = array();
269
270 /**
271 * @var bool
272 */
273 public $search_across = true;
274
275 /**
276 * @var bool
277 */
278 public $search_across_picks = false;
279
280 /**
281 * @var bool
282 */
283 public $default_none = false;
284
285 /**
286 * @var array
287 */
288 public $where = array(
289 'manage' => null,
290 /*
291 'edit' => null,
292 'duplicate' => null,
293 'delete' => null,*/
294 'reorder' => null,
295 );
296
297 /**
298 * @var bool
299 */
300 public $orderby = false;
301
302 /**
303 * @var string
304 */
305 public $orderby_dir = 'DESC';
306
307 /**
308 * @var int
309 */
310 public $limit = 25;
311
312 /**
313 * @var int
314 */
315 public $page = 1;
316
317 /**
318 * @var int
319 */
320 public $total = 0;
321
322 /**
323 * @var int
324 */
325 public $total_found = 0;
326
327 /**
328 * @var array
329 */
330 public $session = array(
331 'search',
332 'filters',
333 );
334 // allowed: search, filters, show_per_page, orderby (priority over usermeta)
335 /**
336 * @var array
337 */
338 public $user = array(
339 'show_per_page',
340 'orderby',
341 );
342 // allowed: search, filters, show_per_page, orderby (priority under session)
343 // advanced data
344 /**
345 * @var array
346 */
347 public $sql = array(
348 'table' => null,
349 'field_id' => 'id',
350 'field_index' => 'name',
351 'select' => null,
352 'sql' => null,
353 );
354
355 /**
356 * @var array
357 */
358 public $params = array();
359
360 /**
361 * @var bool|array
362 */
363 public $data = false;
364
365 /**
366 * @var bool|array
367 */
368 public $data_full = false;
369
370 /**
371 * @var array
372 */
373 public $data_keys = array();
374
375 /**
376 * @var array
377 */
378 public $row = array();
379
380 // actions
381 /**
382 * @var string
383 */
384 public $action = 'manage';
385
386 /**
387 * @var string
388 */
389 public $action_bulk = false;
390
391 /**
392 * @var array
393 */
394 public $bulk = array();
395
396 /**
397 * @var array
398 */
399 public $action_after = array(
400 'add' => 'edit',
401 'edit' => 'edit',
402 'duplicate' => 'edit',
403 );
404 // set action to 'manage'
405 /**
406 * @var bool
407 */
408 public $do = false;
409
410 /**
411 * @var array
412 */
413 public $action_links = array(
414 'manage' => null,
415 'add' => null,
416 'edit' => null,
417 'duplicate' => null,
418 'view' => null,
419 'delete' => null,
420 'reorder' => null,
421 );
422 // custom links (ex. /my-link/{@id}/
423 /**
424 * @var array
425 */
426 public $actions_disabled = array(
427 'view',
428 'export',
429 );
430 // disable actions
431 /**
432 * @var array
433 */
434 public $actions_hidden = array();
435 // hide actions to not show them but allow them
436 /**
437 * @var array
438 */
439 public $actions_custom = array();
440 // overwrite existing actions or add your own
441 /**
442 * @var array
443 */
444 public $actions_bulk = array();
445 // enabled bulk actions
446 /**
447 * @var array
448 */
449 public $restrict = array(
450 'manage' => null,
451 'edit' => null,
452 'duplicate' => null,
453 'delete' => null,
454 'reorder' => null,
455 'author_restrict' => null,
456 );
457
458 /**
459 * @var array
460 */
461 public $extra = array(
462 'total' => null,
463 );
464
465 /**
466 * @var string
467 */
468 public $style = 'post_type';
469
470 /**
471 * @var bool
472 */
473 public $save = false;
474 // Allow custom save handling for tables that aren't Pod-based
475
476 /**
477 * Generate UI for Data Management
478 *
479 * @param mixed $options Object, Array, or String containing Pod or Options to be used
480 * @param bool $deprecated Set to true to support old options array from Pods UI plugin
481 *
482 * @return \PodsUI
483 *
484 * @license http://www.gnu.org/licenses/gpl-2.0.html
485 * @since 2.0.0
486 */
487 public function __construct( $options, $deprecated = false ) {
488
489 $this->_nonce = pods_v( $this->num_prefix . '_wpnonce' . $this->num, 'request' );
490
491 $object = null;
492
493 if ( is_object( $options ) ) {
494 $object = $options;
495 $options = array();
496
497 if ( isset( $object->ui ) ) {
498 $options = (array) $object->ui;
499
500 unset( $object->ui );
501 }
502
503 if ( is_object( $object ) && ( 'Pods' == get_class( $object ) || 'Pod' == get_class( $object ) ) ) {
504 $this->pod =& $object;
505 }
506 }
507
508 if ( ! is_array( $options ) ) {
509 // @todo need to come back to this and allow for multi-dimensional strings
510 // like: option=value&option2=value2&option3=key[val],key2[val2]&option4=this,that,another
511 if ( false !== strpos( $options, '=' ) || false !== strpos( $options, '&' ) ) {
512 parse_str( $options, $options );
513 } else {
514 $options = array( 'pod' => $options );
515 }
516 }
517
518 if ( ! is_object( $object ) && isset( $options['pod'] ) ) {
519 if ( is_object( $options['pod'] ) ) {
520 $this->pod = $options['pod'];
521 } elseif ( isset( $options['id'] ) ) {
522 $this->pod = pods( $options['pod'], $options['id'] );
523 } else {
524 $this->pod = pods( $options['pod'] );
525 }
526
527 unset( $options['pod'] );
528 } elseif ( is_object( $object ) ) {
529 $this->pod = $object;
530 }
531
532 if ( false !== $deprecated || ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) ) ) {
533 $options = $this->setup_deprecated( $options );
534 }
535
536 if ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) && is_object( $this->pod->_data ) ) {
537 $this->pods_data =& $this->pod->_data;
538 } elseif ( is_object( $this->pod ) && 'Pods' == get_class( $this->pod ) && is_object( $this->pod->data ) ) {
539 $this->pods_data =& $this->pod->data;
540 } elseif ( is_object( $this->pod ) ) {
541 $this->pods_data = pods_data( $this->pod->pod );
542 } elseif ( ! is_object( $this->pod ) ) {
543 $this->pods_data = pods_data( $this->pod );
544 }
545
546 $options = $this->do_hook( 'pre_init', $options );
547
548 $this->setup( $options );
549
550 if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id ) {
551 if ( $this->id != $this->pods_data->id ) {
552 $this->row = $this->pods_data->fetch( $this->id );
553 } else {
554 $this->row = $this->pods_data->row;
555 }
556 }
557
558 if ( ( ! is_object( $this->pod ) || 'Pods' != get_class( $this->pod ) ) && false === $this->sql['table'] && false === $this->data ) {
559 echo $this->error( __( '<strong>Error:</strong> Pods UI needs a Pods object or a Table definition to run from, see the User Guide for more information.', 'pods' ) );
560
561 return null;
562 }
563
564 // Assign pod labels
565 // @todo This is also done in setup(), maybe a better / more central way?
566 if ( is_object( $this->pod ) && ! empty( $this->pod->pod_data['options'] ) ) {
567 $pod_options = $this->pod->pod_data['options'];
568 $pod_name = $this->pod->pod_data['name'];
569 $pod_options = apply_filters( "pods_advanced_content_type_pod_data_{$pod_name}", $pod_options, $this->pod->pod_data['name'] );
570 $pod_options = apply_filters( 'pods_advanced_content_type_pod_data', $pod_options, $this->pod->pod_data['name'] );
571
572 $this->label = array_merge( $this->label, $pod_options );
573 }
574
575 $this->go();
576 }
577
578 /**
579 * @param $deprecated_options
580 *
581 * @return array
582 */
583 public function setup_deprecated( $deprecated_options ) {
584
585 $options = array();
586
587 if ( isset( $deprecated_options['id'] ) ) {
588 $options['id'] = $deprecated_options['id'];
589 }
590 if ( isset( $deprecated_options['action'] ) ) {
591 $options['action'] = $deprecated_options['action'];
592 }
593 if ( isset( $deprecated_options['num'] ) ) {
594 $options['num'] = $deprecated_options['num'];
595 }
596
597 if ( isset( $deprecated_options['title'] ) ) {
598 $options['items'] = $deprecated_options['title'];
599 }
600 if ( isset( $deprecated_options['item'] ) ) {
601 $options['item'] = $deprecated_options['item'];
602 }
603
604 if ( isset( $deprecated_options['label'] ) ) {
605 $options['label'] = array(
606 'add' => $deprecated_options['label'],
607 'edit' => $deprecated_options['label'],
608 'duplicate' => $deprecated_options['label'],
609 );
610 }
611 if ( isset( $deprecated_options['label_add'] ) ) {
612 if ( isset( $options['label'] ) ) {
613 $options['label']['add'] = $deprecated_options['label_add'];
614 } else {
615 $options['label'] = array( 'add' => $deprecated_options['label_add'] );
616 }
617 }
618 if ( isset( $deprecated_options['label_edit'] ) ) {
619 if ( isset( $options['label'] ) ) {
620 $options['label']['edit'] = $deprecated_options['label_edit'];
621 } else {
622 $options['label'] = array( 'edit' => $deprecated_options['label_edit'] );
623 }
624 }
625 if ( isset( $deprecated_options['label_duplicate'] ) ) {
626 if ( isset( $options['label'] ) ) {
627 $options['label']['duplicate'] = $deprecated_options['label_duplicate'];
628 } else {
629 $options['label'] = array( 'duplicate' => $deprecated_options['label_duplicate'] );
630 }
631 }
632
633 if ( isset( $deprecated_options['icon'] ) ) {
634 $options['icon'] = $deprecated_options['icon'];
635 }
636
637 if ( isset( $deprecated_options['columns'] ) ) {
638 $options['fields'] = array( 'manage' => $deprecated_options['columns'] );
639 }
640 if ( isset( $deprecated_options['reorder_columns'] ) ) {
641 if ( isset( $options['fields'] ) ) {
642 $options['fields']['reorder'] = $deprecated_options['reorder_columns'];
643 } else {
644 $options['fields'] = array( 'reorder' => $deprecated_options['reorder_columns'] );
645 }
646 }
647 if ( isset( $deprecated_options['add_fields'] ) ) {
648 if ( isset( $options['fields'] ) ) {
649 if ( ! isset( $options['fields']['add'] ) ) {
650 $options['fields']['add'] = $deprecated_options['add_fields'];
651 }
652 if ( ! isset( $options['fields']['edit'] ) ) {
653 $options['fields']['edit'] = $deprecated_options['add_fields'];
654 }
655 if ( ! isset( $options['fields']['duplicate'] ) ) {
656 $options['fields']['duplicate'] = $deprecated_options['add_fields'];
657 }
658 } else {
659 $options['fields'] = array(
660 'add' => $deprecated_options['add_fields'],
661 'edit' => $deprecated_options['add_fields'],
662 'duplicate' => $deprecated_options['add_fields'],
663 );
664 }
665 }
666 if ( isset( $deprecated_options['edit_fields'] ) ) {
667 if ( isset( $options['fields'] ) ) {
668 if ( ! isset( $options['fields']['add'] ) ) {
669 $options['fields']['add'] = $deprecated_options['edit_fields'];
670 }
671 if ( ! isset( $options['fields']['edit'] ) ) {
672 $options['fields']['edit'] = $deprecated_options['edit_fields'];
673 }
674 if ( ! isset( $options['fields']['duplicate'] ) ) {
675 $options['fields']['duplicate'] = $deprecated_options['edit_fields'];
676 }
677 } else {
678 $options['fields'] = array(
679 'add' => $deprecated_options['edit_fields'],
680 'edit' => $deprecated_options['edit_fields'],
681 'duplicate' => $deprecated_options['edit_fields'],
682 );
683 }
684 }
685 if ( isset( $deprecated_options['duplicate_fields'] ) ) {
686 if ( isset( $options['fields'] ) ) {
687 $options['fields']['duplicate'] = $deprecated_options['duplicate_fields'];
688 } else {
689 $options['fields'] = array( 'duplicate' => $deprecated_options['duplicate_fields'] );
690 }
691 }
692
693 if ( isset( $deprecated_options['session_filters'] ) && false === $deprecated_options['session_filters'] ) {
694 $options['session'] = false;
695 }
696 if ( isset( $deprecated_options['user_per_page'] ) ) {
697 if ( isset( $options['user'] ) && ! empty( $options['user'] ) ) {
698 $options['user'] = array( 'orderby' );
699 } else {
700 $options['user'] = false;
701 }
702 }
703 if ( isset( $deprecated_options['user_sort'] ) ) {
704 if ( isset( $options['user'] ) && ! empty( $options['user'] ) ) {
705 $options['user'] = array( 'show_per_page' );
706 } else {
707 $options['user'] = false;
708 }
709 }
710
711 if ( isset( $deprecated_options['custom_list'] ) ) {
712 if ( isset( $options['actions_custom'] ) ) {
713 $options['actions_custom']['manage'] = $deprecated_options['custom_list'];
714 } else {
715 $options['actions_custom'] = array( 'manage' => $deprecated_options['custom_list'] );
716 }
717 }
718 if ( isset( $deprecated_options['custom_reorder'] ) ) {
719 if ( isset( $options['actions_custom'] ) ) {
720 $options['actions_custom']['reorder'] = $deprecated_options['custom_reorder'];
721 } else {
722 $options['actions_custom'] = array( 'reorder' => $deprecated_options['custom_reorder'] );
723 }
724 }
725 if ( isset( $deprecated_options['custom_add'] ) ) {
726 if ( isset( $options['actions_custom'] ) ) {
727 $options['actions_custom']['add'] = $deprecated_options['custom_add'];
728 } else {
729 $options['actions_custom'] = array( 'add' => $deprecated_options['custom_add'] );
730 }
731 }
732 if ( isset( $deprecated_options['custom_edit'] ) ) {
733 if ( isset( $options['actions_custom'] ) ) {
734 $options['actions_custom']['edit'] = $deprecated_options['custom_edit'];
735 } else {
736 $options['actions_custom'] = array( 'edit' => $deprecated_options['custom_edit'] );
737 }
738 }
739 if ( isset( $deprecated_options['custom_duplicate'] ) ) {
740 if ( isset( $options['actions_custom'] ) ) {
741 $options['actions_custom']['duplicate'] = $deprecated_options['custom_duplicate'];
742 } else {
743 $options['actions_custom'] = array( 'duplicate' => $deprecated_options['custom_duplicate'] );
744 }
745 }
746 if ( isset( $deprecated_options['custom_delete'] ) ) {
747 if ( isset( $options['actions_custom'] ) ) {
748 $options['actions_custom']['delete'] = $deprecated_options['custom_delete'];
749 } else {
750 $options['actions_custom'] = array( 'delete' => $deprecated_options['custom_delete'] );
751 }
752 }
753 if ( isset( $deprecated_options['custom_save'] ) ) {
754 if ( isset( $options['actions_custom'] ) ) {
755 $options['actions_custom']['save'] = $deprecated_options['custom_save'];
756 } else {
757 $options['actions_custom'] = array( 'save' => $deprecated_options['custom_save'] );
758 }
759 }
760
761 if ( isset( $deprecated_options['custom_actions'] ) ) {
762 $options['actions_custom'] = $deprecated_options['custom_actions'];
763 }
764 if ( isset( $deprecated_options['action_after_save'] ) ) {
765 $options['action_after'] = array(
766 'add' => $deprecated_options['action_after_save'],
767 'edit' => $deprecated_options['action_after_save'],
768 'duplicate' => $deprecated_options['action_after_save'],
769 );
770 }
771 if ( isset( $deprecated_options['edit_link'] ) ) {
772 if ( isset( $options['action_links'] ) ) {
773 $options['action_links']['edit'] = $deprecated_options['edit_link'];
774 } else {
775 $options['action_links'] = array( 'edit' => $deprecated_options['edit_link'] );
776 }
777 }
778 if ( isset( $deprecated_options['view_link'] ) ) {
779 if ( isset( $options['action_links'] ) ) {
780 $options['action_links']['view'] = $deprecated_options['view_link'];
781 } else {
782 $options['action_links'] = array( 'view' => $deprecated_options['view_link'] );
783 }
784 }
785 if ( isset( $deprecated_options['duplicate_link'] ) ) {
786 if ( isset( $options['action_links'] ) ) {
787 $options['action_links']['duplicate'] = $deprecated_options['duplicate_link'];
788 } else {
789 $options['action_links'] = array( 'duplicate' => $deprecated_options['duplicate_link'] );
790 }
791 }
792
793 if ( isset( $deprecated_options['reorder'] ) ) {
794 $options['reorder'] = array(
795 'on' => $deprecated_options['reorder'],
796 'orderby' => $deprecated_options['reorder'],
797 );
798 }
799 if ( isset( $deprecated_options['reorder_sort'] ) && isset( $options['reorder'] ) ) {
800 $options['reorder']['orderby'] = $deprecated_options['reorder_sort'];
801 }
802 if ( isset( $deprecated_options['reorder_limit'] ) && isset( $options['reorder'] ) ) {
803 $options['reorder']['limit'] = $deprecated_options['reorder_limit'];
804 }
805 if ( isset( $deprecated_options['reorder_sql'] ) && isset( $options['reorder'] ) ) {
806 $options['reorder']['sql'] = $deprecated_options['reorder_sql'];
807 }
808
809 if ( isset( $deprecated_options['sort'] ) ) {
810 $options['orderby'] = $deprecated_options['sort'];
811 }
812 if ( isset( $deprecated_options['sortable'] ) ) {
813 $options['sortable'] = $deprecated_options['sortable'];
814 }
815 if ( isset( $deprecated_options['limit'] ) ) {
816 $options['limit'] = $deprecated_options['limit'];
817 }
818
819 if ( isset( $deprecated_options['where'] ) ) {
820 if ( isset( $options['where'] ) ) {
821 $options['where']['manage'] = $deprecated_options['where'];
822 } else {
823 $options['where'] = array( 'manage' => $deprecated_options['where'] );
824 }
825 }
826 if ( isset( $deprecated_options['edit_where'] ) ) {
827 /*
828 if ( isset( $options[ 'where' ] ) )
829 $options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ];
830 else
831 $options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );*/
832
833 if ( isset( $options['restrict'] ) ) {
834 $options['restrict']['edit'] = (array) $deprecated_options['edit_where'];
835 } else {
836 $options['restrict'] = array( 'edit' => (array) $deprecated_options['edit_where'] );
837 }
838 }
839 if ( isset( $deprecated_options['duplicate_where'] ) ) {
840 /*
841 if ( isset( $options[ 'where' ] ) )
842 $options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ];
843 else
844 $options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );*/
845
846 if ( isset( $options['restrict'] ) ) {
847 $options['restrict']['duplicate'] = (array) $deprecated_options['duplicate_where'];
848 } else {
849 $options['restrict'] = array( 'duplicate' => (array) $deprecated_options['duplicate_where'] );
850 }
851 }
852 if ( isset( $deprecated_options['delete_where'] ) ) {
853 /*
854 if ( isset( $options[ 'where' ] ) )
855 $options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ];
856 else
857 $options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );*/
858
859 if ( isset( $options['restrict'] ) ) {
860 $options['restrict']['delete'] = (array) $deprecated_options['delete_where'];
861 } else {
862 $options['restrict'] = array( 'delete' => (array) $deprecated_options['delete_where'] );
863 }
864 }
865 if ( isset( $deprecated_options['reorder_where'] ) ) {
866 if ( isset( $options['where'] ) ) {
867 $options['where']['reorder'] = $deprecated_options['reorder_where'];
868 } else {
869 $options['where'] = array( 'reorder' => $deprecated_options['reorder_where'] );
870 }
871 }
872
873 if ( isset( $deprecated_options['sql'] ) ) {
874 $options['sql'] = array( 'sql' => $deprecated_options['sql'] );
875 }
876
877 if ( isset( $deprecated_options['search'] ) ) {
878 $options['searchable'] = $deprecated_options['search'];
879 }
880 if ( isset( $deprecated_options['search_across'] ) ) {
881 $options['search_across'] = $deprecated_options['search_across'];
882 }
883 if ( isset( $deprecated_options['search_across_picks'] ) ) {
884 $options['search_across_picks'] = $deprecated_options['search_across_picks'];
885 }
886 if ( isset( $deprecated_options['filters'] ) ) {
887 $options['filters'] = $deprecated_options['filters'];
888 }
889 if ( isset( $deprecated_options['custom_filters'] ) ) {
890 if ( is_callable( $deprecated_options['custom_filters'] ) ) {
891 add_filter( 'pods_ui_filters', $deprecated_options['custom_filters'] );
892 } else {
893 global $pods_ui_custom_filters;
894 $pods_ui_custom_filters = $deprecated_options['custom_filters'];
895 add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) );
896 }
897 }
898
899 if ( isset( $deprecated_options['disable_actions'] ) ) {
900 $options['actions_disabled'] = $deprecated_options['disable_actions'];
901 }
902 if ( isset( $deprecated_options['hide_actions'] ) ) {
903 $options['actions_hidden'] = $deprecated_options['hide_actions'];
904 }
905
906 if ( isset( $deprecated_options['wpcss'] ) ) {
907 $options['wpcss'] = $deprecated_options['wpcss'];
908 }
909
910 $remaining_options = array_diff_assoc( $options, $deprecated_options );
911
912 foreach ( $remaining_options as $option => $value ) {
913 if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) ) {
914 $options[ $option ] = $value;
915 }
916 }
917
918 return $options;
919 }
920
921 /**
922 *
923 */
924 public function deprecated_filters() {
925
926 global $pods_ui_custom_filters;
927 echo $pods_ui_custom_filters;
928 }
929
930 /**
931 * @param $options
932 *
933 * @return array|bool|mixed|null|PodsArray
934 */
935 public function setup( $options ) {
936
937 $options = pods_array( $options );
938
939 $options->validate( 'num_prefix', '' );
940 $options->validate( 'num', '', 'absint' );
941
942 if ( empty( $options->num_prefix ) ) {
943 $options->num_prefix = '';
944 }
945
946 if ( empty( $options->num ) ) {
947 $options->num = '';
948 }
949
950 $options->validate( 'id', pods_var( $options->num_prefix . 'id' . $options->num, 'get', $this->id ) );
951
952 $options->validate(
953 'do', pods_var( $options->num_prefix . 'do' . $options->num, 'get', $this->do ), 'in_array', array(
954 'save',
955 'create',
956 )
957 );
958
959 $options->validate( 'excluded', self::$excluded, 'array_merge' );
960
961 $options->validate( 'action', pods_var( $options->num_prefix . 'action' . $options->num, 'get', $this->action, null, true ), 'in_array', $this->actions );
962 $options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' );
963 $options->validate( 'action_bulk', pods_var( $options->num_prefix . 'action_bulk' . $options->num, 'get', $this->action_bulk, null, true ), 'isset', $this->actions_bulk );
964
965 $bulk = pods_var( $options->num_prefix . 'action_bulk_ids' . $options->num, 'get', array(), null, true );
966
967 if ( ! empty( $bulk ) ) {
968 $bulk = (array) pods_var( $options->num_prefix . 'action_bulk_ids' . $options->num, 'get', array(), null, true );
969 } else {
970 $bulk = array();
971 }
972
973 $options->validate( 'bulk', $bulk, 'array_merge', $this->bulk );
974
975 $options->validate( 'views', $this->views, 'array' );
976 $options->validate( 'view', pods_v( $options->num_prefix . 'view' . $options->num, 'get', $this->view, true ), 'isset', $this->views );
977
978 $options->validate( 'searchable', $this->searchable, 'boolean' );
979 $options->validate( 'search', pods_v( $options->num_prefix . 'search' . $options->num ) );
980 $options->validate( 'search_across', $this->search_across, 'boolean' );
981 $options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' );
982 $options->validate( 'filters', $this->filters, 'array' );
983 $options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' );
984 $options->validate( 'where', $this->where, 'array_merge' );
985
986 $options->validate( 'pagination', $this->pagination, 'boolean' );
987 $options->validate( 'pagination_type', $this->pagination_type );
988 $options->validate( 'pagination_location', $this->pagination_location );
989 $options->validate( 'page', pods_v( $options->num_prefix . 'pg' . $options->num, 'get', $this->page ), 'absint' );
990 $options->validate( 'limit', pods_v( $options->num_prefix . 'limit' . $options->num, 'get', $this->limit ), 'int' );
991
992 if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) {
993 $this->sql = array(
994 'table' => $this->pods_data->table,
995 'field_id' => $this->pods_data->field_id,
996 'field_index' => $this->pods_data->field_index,
997 );
998 }
999 $options->validate( 'sql', $this->sql, 'array_merge' );
1000
1001 $options->validate(
1002 'orderby_dir', strtoupper( pods_v( $options->num_prefix . 'orderby_dir' . $options->num, 'get', $this->orderby_dir, true ) ), 'in_array', array(
1003 'ASC',
1004 'DESC',
1005 )
1006 );
1007
1008 $options->validate( 'sortable', $this->sortable, 'boolean' );
1009
1010 $orderby = $this->orderby;
1011
1012 $provided_orderby = sanitize_text_field( pods_v( $options->num_prefix . 'orderby' . $options->num, 'get', '' ) );
1013
1014 // Enforce strict DB column name usage
1015 if ( ! empty( $options->sortable ) && ! empty( $provided_orderby ) ) {
1016 $orderby = pods_clean_name( $provided_orderby );
1017 }
1018
1019 if ( ! empty( $orderby ) ) {
1020 $orderby = array(
1021 'default' => $orderby,
1022 );
1023 } else {
1024 $orderby = array();
1025 }
1026
1027 $options->validate( 'orderby', $orderby, 'array_merge' );
1028
1029 $options->validate( 'params', $this->params, 'array' );
1030
1031 $options->validate( 'restrict', $this->restrict, 'array_merge' );
1032
1033 // handle author restrictions
1034 if ( ! empty( $options['restrict']['author_restrict'] ) ) {
1035 $restrict = $options['restrict'];
1036
1037 if ( ! is_array( $restrict['author_restrict'] ) ) {
1038 $restrict['author_restrict'] = array( $restrict['author_restrict'] => get_current_user_id() );
1039 }
1040
1041 if ( null === $restrict['edit'] ) {
1042 $restrict['edit'] = $restrict['author_restrict'];
1043 }
1044
1045 $options->restrict = $restrict;
1046 }
1047
1048 if ( null !== $options['restrict']['edit'] ) {
1049 $restrict = $options['restrict'];
1050
1051 if ( null === $restrict['duplicate'] ) {
1052 $restrict['duplicate'] = $restrict['edit'];
1053 }
1054
1055 if ( null === $restrict['delete'] ) {
1056 $restrict['delete'] = $restrict['edit'];
1057 }
1058
1059 if ( null === $restrict['manage'] ) {
1060 $restrict['manage'] = $restrict['edit'];
1061 }
1062
1063 if ( null === $restrict['reorder'] ) {
1064 $restrict['reorder'] = $restrict['edit'];
1065 }
1066
1067 $options->restrict = $restrict;
1068 }//end if
1069
1070 $item = __( 'Item', 'pods' );
1071 $items = __( 'Items', 'pods' );
1072
1073 if ( ! is_array( $this->label ) ) {
1074 $this->label = (array) $this->label;
1075 }
1076
1077 if ( is_object( $this->pod ) ) {
1078 $pod_data = $this->pod->pod_data;
1079 $pod_name = $this->pod->pod_data['name'];
1080 $pod_data = apply_filters( "pods_advanced_content_type_pod_data_{$pod_name}", $pod_data, $this->pod->pod_data['name'] );
1081 $pod_data = apply_filters( 'pods_advanced_content_type_pod_data', $pod_data, $this->pod->pod_data['name'] );
1082
1083 $this->label = array_merge( $this->label, $pod_data['options'] );
1084
1085 $item = pods_v( 'label_singular', $pod_data['options'], pods_v( 'label', $pod_data, $item, true ), true );
1086 $items = pods_v( 'label', $pod_data, $items, true );
1087 }
1088
1089 $options->validate( 'item', $item );
1090 $options->validate( 'items', $items );
1091
1092 $options->validate(
1093 'heading', array(
1094 'manage' => pods_v( 'label_manage', $this->label, __( 'Manage', 'pods' ) ),
1095 'add' => pods_v( 'label_add_new', $this->label, __( 'Add New', 'pods' ) ),
1096 'edit' => pods_v( 'label_edit', $this->label, __( 'Edit', 'pods' ) ),
1097 'duplicate' => pods_v( 'label_duplicate', $this->label, __( 'Duplicate', 'pods' ) ),
1098 'view' => pods_v( 'label_view', $this->label, __( 'View', 'pods' ) ),
1099 'reorder' => pods_v( 'label_reorder', $this->label, __( 'Reorder', 'pods' ) ),
1100 'search' => pods_v( 'label_search', $this->label, __( 'Search', 'pods' ) ),
1101 'views' => pods_v( 'label_view', $this->label, __( 'View', 'pods' ) ),
1102 ), 'array_merge'
1103 );
1104
1105 $options->validate(
1106 'header', array(
1107 'manage' => pods_v( 'label_manage_items', $this->label, sprintf( __( 'Manage %s', 'pods' ), $options->items ) ),
1108 'add' => pods_v( 'label_add_new_item', $this->label, sprintf( __( 'Add New %s', 'pods' ), $options->item ) ),
1109 'edit' => pods_v( 'label_edit_item', $this->label, sprintf( __( 'Edit %s', 'pods' ), $options->item ) ),
1110 'duplicate' => pods_v( 'label_duplicate_item', $this->label, sprintf( __( 'Duplicate %s', 'pods' ), $options->item ) ),
1111 'view' => pods_v( 'label_view_item', $this->label, sprintf( __( 'View %s', 'pods' ), $options->item ) ),
1112 'reorder' => pods_v( 'label_reorder_items', $this->label, sprintf( __( 'Reorder %s', 'pods' ), $options->items ) ),
1113 'search' => pods_v( 'label_search_items', $this->label, sprintf( __( 'Search %s', 'pods' ), $options->items ) ),
1114 ), 'array_merge'
1115 );
1116
1117 $options->validate(
1118 'label', array(
1119 'add' => pods_v( 'label_add_new_item', $this->label, sprintf( __( 'Add New %s', 'pods' ), $options->item ) ),
1120 'add_new' => pods_v( 'label_add_new', $this->label, __( 'Add New', 'pods' ) ),
1121 'edit' => pods_v( 'label_update_item', $this->label, sprintf( __( 'Update %s', 'pods' ), $options->item ) ),
1122 'duplicate' => pods_v( 'label_duplicate_item', $this->label, sprintf( __( 'Duplicate %s', 'pods' ), $options->item ) ),
1123 'delete' => pods_v( 'label_delete_item', $this->label, sprintf( __( 'Delete this %s', 'pods' ), $options->item ) ),
1124 'view' => pods_v( 'label_view_item', $this->label, sprintf( __( 'View %s', 'pods' ), $options->item ) ),
1125 'reorder' => pods_v( 'label_reorder_items', $this->label, sprintf( __( 'Reorder %s', 'pods' ), $options->items ) ),
1126 ), 'array_merge'
1127 );
1128
1129 $options->validate( 'fields', $this->fields, 'array_merge' );
1130
1131 // Set up default manage field.
1132 if ( empty( $options->fields['manage'] ) ) {
1133 $options->fields['manage'][ $options->sql['field_index'] ] = array(
1134 'label' => __( 'Name', 'pods' ),
1135 );
1136 }
1137
1138 $options->validate( 'export', $this->export, 'array_merge' );
1139 $options->validate( 'reorder', $this->reorder, 'array_merge' );
1140 $options->validate( 'screen_options', $this->screen_options, 'array_merge' );
1141
1142 $options->validate(
1143 'session', $this->session, 'in_array', array(
1144 'search',
1145 'filters',
1146 'show_per_page',
1147 'orderby',
1148 )
1149 );
1150 $options->validate(
1151 'user', $this->user, 'in_array', array(
1152 'search',
1153 'filters',
1154 'show_per_page',
1155 'orderby',
1156 )
1157 );
1158
1159 $options->validate( 'action_after', $this->action_after, 'array_merge' );
1160 $options->validate( 'action_links', $this->action_links, 'array_merge' );
1161 $options->validate( 'actions_disabled', $this->actions_disabled, 'array' );
1162 $options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' );
1163 $options->validate( 'actions_custom', $this->actions_custom, 'array_merge' );
1164
1165 if ( ! empty( $options->actions_disabled ) ) {
1166 if ( ! empty( $options->actions_bulk ) ) {
1167 $actions_bulk = $options->actions_bulk;
1168
1169 foreach ( $actions_bulk as $action => $action_opt ) {
1170 if ( in_array( $action, $options->actions_disabled ) ) {
1171 unset( $actions_bulk[ $action ] );
1172 }
1173 }
1174
1175 $options->actions_bulk = $actions_bulk;
1176 }
1177
1178 if ( ! empty( $options->actions_custom ) ) {
1179 $actions_custom = $options->actions_custom;
1180
1181 foreach ( $actions_custom as $action => $action_opt ) {
1182 if ( in_array( $action, $options->actions_disabled ) ) {
1183 unset( $actions_custom[ $action ] );
1184 }
1185 }
1186
1187 $options->actions_custom = $actions_custom;
1188 }
1189 }//end if
1190
1191 $options->validate( 'extra', $this->extra, 'array_merge' );
1192
1193 $options->validate( 'style', $this->style );
1194 $options->validate( 'icon', $this->icon );
1195 $options->validate( 'css', $this->css );
1196 $options->validate( 'wpcss', $this->wpcss, 'boolean' );
1197
1198 if ( true === $options['wpcss'] ) {
1199 global $user_ID;
1200 wp_get_current_user();
1201
1202 $color = get_user_meta( $user_ID, 'admin_color', true );
1203 if ( strlen( $color ) < 1 ) {
1204 $color = 'fresh';
1205 }
1206
1207 $this->wpcss = "colors-{$color}";
1208 }
1209
1210 $options = $options->dump();
1211
1212 if ( is_object( $this->pod ) ) {
1213 $options = $this->do_hook( $this->pod->pod . '_setup_options', $options );
1214 }
1215
1216 $options = $this->do_hook( 'setup_options', $options );
1217
1218 if ( false !== $options && ! empty( $options ) ) {
1219 foreach ( $options as $option => $value ) {
1220 if ( isset( $this->{$option} ) ) {
1221 $this->{$option} = $value;
1222 } else {
1223 $this->x[ $option ] = $value;
1224 }
1225 }
1226 }
1227
1228 $unique_identifier = pods_var( 'page' );
1229 // wp-admin page
1230 if ( is_object( $this->pod ) && isset( $this->pod->pod ) ) {
1231 $unique_identifier = '_' . $this->pod->pod;
1232 } elseif ( 0 < strlen( $this->sql['table'] ) ) {
1233 $unique_identifier = '_' . $this->sql['table'];
1234 }
1235
1236 $unique_identifier .= '_' . $this->page;
1237 if ( 0 < strlen( $this->num ) ) {
1238 $unique_identifier .= '_' . $this->num_prefix . $this->num;
1239 }
1240
1241 $this->unique_identifier = 'pods_ui_' . md5( $unique_identifier );
1242
1243 $this->setup_fields();
1244
1245 return $options;
1246 }
1247
1248 /**
1249 * @param null $fields
1250 * @param string $which
1251 *
1252 * @return array|bool|mixed|null
1253 */
1254 public function setup_fields( $fields = null, $which = 'fields' ) {
1255
1256 $init = false;
1257 if ( null === $fields ) {
1258 if ( isset( $this->fields[ $which ] ) ) {
1259 $fields = (array) $this->fields[ $which ];
1260 } elseif ( isset( $this->fields['manage'] ) ) {
1261 $fields = (array) $this->fields['manage'];
1262 } else {
1263 $fields = array();
1264 }
1265 if ( 'fields' === $which ) {
1266 $init = true;
1267 }
1268 }
1269 if ( ! empty( $fields ) ) {
1270 // Available Attributes
1271 // type = field type
1272 // type = date (data validation as date)
1273 // type = time (data validation as time)
1274 // type = datetime (data validation as datetime)
1275 // date_touch = use current timestamp when saving (even if readonly, if type is date-related)
1276 // date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related)
1277 // date_ongoing = use this additional field to search between as if the first is the "start" and the date_ongoing is the "end" for filter
1278 // type = text / other (single line text box)
1279 // type = desc (textarea)
1280 // type = number (data validation as int float)
1281 // type = decimal (data validation as decimal)
1282 // type = password (single line password box)
1283 // type = bool (checkbox)
1284 // type = related (select box)
1285 // related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items
1286 // related_field = field name on table to show (if type=related) - default "name"
1287 // related_multiple = true (ability to select multiple values if type=related)
1288 // related_sql = custom where / order by SQL (if type=related)
1289 // readonly = true (shows as text)
1290 // display = false (doesn't show on form, but can be saved)
1291 // search = this field is searchable
1292 // filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box)
1293 // comments = comments to show for field
1294 // comments_top = true (shows comments above field instead of below)
1295 // real_name = the real name of the field (if using an alias for 'name')
1296 // group_related = true (uses HAVING instead of WHERE for filtering field)
1297 $new_fields = array();
1298 $filterable = false;
1299 if ( empty( $this->filters ) && ( empty( $this->fields['search'] ) || 'search' === $which ) && false !== $this->searchable ) {
1300 $filterable = true;
1301 $this->filters = array();
1302 }
1303
1304 foreach ( $fields as $field => $attributes ) {
1305 if ( ! is_array( $attributes ) ) {
1306 if ( is_int( $field ) ) {
1307 $field = $attributes;
1308 $attributes = array();
1309 } else {
1310 $attributes = array( 'label' => $attributes );
1311 }
1312 }
1313
1314 if ( ! isset( $attributes['name'] ) ) {
1315 $attributes['name'] = $field;
1316 }
1317
1318 if ( ! isset( $attributes['real_name'] ) ) {
1319 $attributes['real_name'] = pods_var( 'name', $attributes, $field );
1320 }
1321
1322 if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes['real_name'] ] ) ) {
1323 $attributes = array_merge( $this->pod->fields[ $attributes['real_name'] ], $attributes );
1324 }
1325
1326 if ( ! isset( $attributes['options'] ) ) {
1327 $attributes['options'] = array();
1328 }
1329 if ( ! isset( $attributes['id'] ) ) {
1330 $attributes['id'] = '';
1331 }
1332 if ( ! isset( $attributes['label'] ) ) {
1333 $attributes['label'] = ucwords( str_replace( '_', ' ', $field ) );
1334 }
1335 if ( ! isset( $attributes['type'] ) ) {
1336 $attributes['type'] = 'text';
1337 }
1338 if ( ! isset( $attributes['options']['date_format_type'] ) ) {
1339 $attributes['options']['date_format_type'] = 'date';
1340 }
1341 if ( 'related' !== $attributes['type'] || ! isset( $attributes['related'] ) ) {
1342 $attributes['related'] = false;
1343 }
1344 if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_id'] ) ) {
1345 $attributes['related_id'] = 'id';
1346 }
1347 if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_field'] ) ) {
1348 $attributes['related_field'] = 'name';
1349 }
1350 if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_multiple'] ) ) {
1351 $attributes['related_multiple'] = false;
1352 }
1353 if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_sql'] ) ) {
1354 $attributes['related_sql'] = false;
1355 }
1356 if ( 'related' === $attributes['type'] && ( is_array( $attributes['related'] ) || strpos( $attributes['related'], ',' ) ) ) {
1357 if ( ! is_array( $attributes['related'] ) ) {
1358 $attributes['related'] = @explode( ',', $attributes['related'] );
1359 $related_items = array();
1360 foreach ( $attributes['related'] as $key => $label ) {
1361 if ( is_numeric( $key ) ) {
1362 $key = $label;
1363 $label = ucwords( str_replace( '_', ' ', $label ) );
1364 }
1365 $related_items[ $key ] = $label;
1366 }
1367 $attributes['related'] = $related_items;
1368 }
1369 if ( empty( $attributes['related'] ) ) {
1370 $attributes['related'] = false;
1371 }
1372 }
1373 if ( ! isset( $attributes['readonly'] ) ) {
1374 $attributes['readonly'] = false;
1375 }
1376 if ( ! isset( $attributes['date_touch'] ) || 'date' !== $attributes['type'] ) {
1377 $attributes['date_touch'] = false;
1378 }
1379 if ( ! isset( $attributes['date_touch_on_create'] ) || 'date' !== $attributes['type'] ) {
1380 $attributes['date_touch_on_create'] = false;
1381 }
1382 if ( ! isset( $attributes['display'] ) ) {
1383 $attributes['display'] = true;
1384 }
1385 if ( ! isset( $attributes['hidden'] ) ) {
1386 $attributes['hidden'] = false;
1387 }
1388 if ( ! isset( $attributes['sortable'] ) || false === $this->sortable ) {
1389 $attributes['sortable'] = $this->sortable;
1390 }
1391 if ( ! isset( $attributes['options']['search'] ) || false === $this->searchable ) {
1392 $attributes['options']['search'] = $this->searchable;
1393 }
1394 if ( ! isset( $attributes['options']['filter'] ) || false === $this->searchable ) {
1395 $attributes['options']['filter'] = $this->searchable;
1396 }
1397 /*
1398 if ( false !== $attributes[ 'options' ][ 'filter' ] && false !== $filterable )
1399 $this->filters[] = $field;*/
1400 if ( false === $attributes['options']['filter'] || ! isset( $attributes['filter_label'] ) || ! in_array( $field, $this->filters ) ) {
1401 $attributes['filter_label'] = $attributes['label'];
1402 }
1403 if ( false === $attributes['options']['filter'] || ! isset( $attributes['filter_default'] ) || ! in_array( $field, $this->filters ) ) {
1404 $attributes['filter_default'] = false;
1405 }
1406 if ( false === $attributes['options']['filter'] || ! isset( $attributes['date_ongoing'] ) || 'date' !== $attributes['type'] || ! in_array( $field, $this->filters ) ) {
1407 $attributes['date_ongoing'] = false;
1408 }
1409 if ( false === $attributes['options']['filter'] || ! isset( $attributes['date_ongoing'] ) || 'date' !== $attributes['type'] || ! isset( $attributes['date_ongoing_default'] ) || ! in_array( $field, $this->filters ) ) {
1410 $attributes['date_ongoing_default'] = false;
1411 }
1412 if ( ! isset( $attributes['export'] ) ) {
1413 $attributes['export'] = true;
1414 }
1415 if ( ! isset( $attributes['group_related'] ) ) {
1416 $attributes['group_related'] = false;
1417 }
1418 if ( ! isset( $attributes['comments'] ) ) {
1419 $attributes['comments'] = '';
1420 }
1421 if ( ! isset( $attributes['comments_top'] ) ) {
1422 $attributes['comments_top'] = false;
1423 }
1424 if ( ! isset( $attributes['custom_view'] ) ) {
1425 $attributes['custom_view'] = false;
1426 }
1427 if ( ! isset( $attributes['custom_input'] ) ) {
1428 $attributes['custom_input'] = false;
1429 }
1430 if ( isset( $attributes['display_helper'] ) ) {
1431 // pods ui backward compatibility
1432 $attributes['custom_display'] = $attributes['display_helper'];
1433 }
1434 if ( ! isset( $attributes['custom_display'] ) ) {
1435 $attributes['custom_display'] = false;
1436 }
1437 if ( ! isset( $attributes['custom_relate'] ) ) {
1438 $attributes['custom_relate'] = false;
1439 }
1440 if ( ! isset( $attributes['custom_form_display'] ) ) {
1441 $attributes['custom_form_display'] = false;
1442 }
1443 if ( ! isset( $attributes['css_values'] ) ) {
1444 $attributes['css_values'] = true;
1445 }
1446 if ( 'search_columns' === $which && ! $attributes['options']['search'] ) {
1447 continue;
1448 }
1449
1450 $attributes = PodsForm::field_setup( $attributes, null, $attributes['type'] );
1451
1452 $new_fields[ $field ] = $attributes;
1453 }//end foreach
1454 $fields = $new_fields;
1455 }//end if
1456
1457 if ( false !== $init ) {
1458 if ( empty( $this->fields_setup['fields'] ) ) {
1459 if ( 'fields' !== $which && ! empty( $this->fields ) ) {
1460 $this->fields = $this->setup_fields( $this->fields, 'fields' );
1461 } else {
1462 $this->fields['manage'] = $fields;
1463 }
1464
1465 $this->fields_setup['fields'] = true;
1466 }
1467
1468 if ( ! in_array( 'add', $this->actions_disabled ) || ! in_array( 'edit', $this->actions_disabled ) || ! in_array( 'duplicate', $this->actions_disabled ) ) {
1469 if ( empty( $this->fields_setup['form'] ) ) {
1470 if ( 'form' !== $which && isset( $this->fields['form'] ) && is_array( $this->fields['form'] ) ) {
1471 $this->fields['form'] = $this->setup_fields( $this->fields['form'], 'form' );
1472 } else {
1473 $this->fields['form'] = $fields;
1474 }
1475
1476 $this->fields_setup['form'] = true;
1477 }
1478
1479 if ( empty( $this->fields_setup['add'] ) ) {
1480 if ( ! in_array( 'add', $this->actions_disabled ) ) {
1481 if ( 'add' !== $which && isset( $this->fields['add'] ) && is_array( $this->fields['add'] ) ) {
1482 $this->fields['add'] = $this->setup_fields( $this->fields['add'], 'add' );
1483 }
1484 }
1485
1486 $this->fields_setup['add'] = true;
1487 }
1488
1489 if ( empty( $this->fields_setup['edit'] ) ) {
1490 if ( ! in_array( 'edit', $this->actions_disabled ) ) {
1491 if ( 'edit' !== $which && isset( $this->fields['edit'] ) && is_array( $this->fields['edit'] ) ) {
1492 $this->fields['edit'] = $this->setup_fields( $this->fields['edit'], 'edit' );
1493 }
1494 }
1495
1496 $this->fields_setup['edit'] = true;
1497 }
1498
1499 if ( empty( $this->fields_setup['duplicate'] ) ) {
1500 if ( ! in_array( 'duplicate', $this->actions_disabled ) ) {
1501 if ( 'duplicate' !== $which && isset( $this->fields['duplicate'] ) && is_array( $this->fields['duplicate'] ) ) {
1502 $this->fields['duplicate'] = $this->setup_fields( $this->fields['duplicate'], 'duplicate' );
1503 }
1504 }
1505
1506 $this->fields_setup['duplicate'] = true;
1507 }
1508 }//end if
1509
1510 if ( empty( $this->fields_setup['search'] ) ) {
1511 if ( false !== $this->searchable ) {
1512 if ( 'search' !== $which && isset( $this->fields['search'] ) && ! empty( $this->fields['search'] ) ) {
1513 $this->fields['search'] = $this->setup_fields( $this->fields['search'], 'search' );
1514 }
1515 } else {
1516 $this->fields['search'] = false;
1517 }
1518
1519 $this->fields_setup['search'] = true;
1520 }
1521
1522 if ( empty( $this->fields_setup['sort'] ) ) {
1523 if ( false !== $this->sortable ) {
1524 if ( 'sort' !== $which ) {
1525 if ( isset( $this->fields['sort'] ) && ! empty( $this->fields['sort'] ) ) {
1526 $this->fields['sort'] = $this->setup_fields( $this->fields['sort'], 'sort' );
1527 } else {
1528 $this->fields['sort'] = $fields;
1529 }
1530 }
1531 } else {
1532 $this->fields['sort'] = false;
1533 }
1534
1535 $this->fields_setup['sort'] = true;
1536 }
1537
1538 if ( empty( $this->fields_setup['export'] ) ) {
1539 if ( ! in_array( 'export', $this->actions_disabled, true ) ) {
1540 if ( 'export' !== $which && isset( $this->fields['export'] ) && ! empty( $this->fields['export'] ) ) {
1541 $this->fields['export'] = $this->setup_fields( $this->fields['export'], 'export' );
1542 }
1543 }
1544
1545 $this->fields_setup['export'] = true;
1546 }
1547
1548 if ( empty( $this->fields_setup['reorder'] ) ) {
1549 if ( ! in_array( 'reorder', $this->actions_disabled, true ) && false !== $this->reorder['on'] ) {
1550 if ( 'reorder' !== $which && isset( $this->fields['reorder'] ) && ! empty( $this->fields['reorder'] ) ) {
1551 $this->fields['reorder'] = $this->setup_fields( $this->fields['reorder'], 'reorder' );
1552 }
1553 }
1554
1555 $this->fields_setup['reorder'] = true;
1556 }
1557 }//end if
1558
1559 return $this->do_hook( 'setup_fields', $fields, $which, $init );
1560 }
1561
1562 /**
1563 * @param $msg
1564 * @param bool $error
1565 */
1566 public function message( $msg, $error = false ) {
1567
1568 $class = 'updated';
1569 $hook = 'message';
1570
1571 if ( $error ) {
1572 $class = 'error';
1573 $hook = 'error';
1574 }
1575
1576 $msg = $this->do_hook( $hook, $msg );
1577
1578 if ( empty( $msg ) ) {
1579 return;
1580 }
1581 ?>
1582 <div id="message" class="<?php echo esc_attr( $class ); ?> fade">
1583 <p><?php echo $msg; ?></p>
1584 </div>
1585 <?php
1586 }
1587
1588 /**
1589 * @param $msg
1590 *
1591 * @return bool
1592 */
1593 public function error( $msg ) {
1594
1595 $this->message( $msg, true );
1596
1597 return false;
1598 }
1599
1600 /**
1601 * @return mixed
1602 */
1603 public function go() {
1604
1605 $this->do_hook( 'go' );
1606 $_GET = pods_unsanitize( $_GET );
1607 // fix wp sanitization
1608 $_POST = pods_unsanitize( $_POST );
1609 // fix wp sanitization
1610 if ( false !== $this->css ) {
1611 ?>
1612 <link type="text/css" rel="stylesheet" href="<?php echo esc_url( $this->css ); ?>" />
1613 <?php
1614 }
1615 if ( false !== $this->wpcss ) {
1616 $stylesheets = array( 'global', 'wp-admin', $this->wpcss );
1617 foreach ( $stylesheets as $style ) {
1618 if ( ! wp_style_is( $style, 'queue' ) && ! wp_style_is( $style, 'to_do' ) && ! wp_style_is( $style, 'done' ) ) {
1619 wp_enqueue_style( $style );
1620 }
1621 }
1622 }
1623
1624 $this->ui_page = array( $this->action );
1625 if ( 'add' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) {
1626 $this->ui_page[] = 'form';
1627 if ( 'create' === $this->do && $this->save && ! in_array( $this->do, $this->actions_disabled ) && ! empty( $_POST ) ) {
1628 $this->ui_page[] = $this->do;
1629 $this->save( true );
1630 $this->manage();
1631 } else {
1632 $this->add();
1633 }
1634 } elseif ( ( 'edit' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) ) {
1635 $this->ui_page[] = 'form';
1636 if ( 'save' === $this->do && $this->save && ! empty( $_POST ) ) {
1637 $this->save();
1638 }
1639 $this->edit( ( 'duplicate' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) ? true : false );
1640 } elseif ( 'delete' === $this->action && ! in_array( $this->action, $this->actions_disabled ) && false !== wp_verify_nonce( $this->_nonce, 'pods-ui-action-delete-' . $this->id ) ) {
1641 $this->delete( $this->id );
1642 $this->manage();
1643 } elseif ( 'reorder' === $this->action && ! in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder['on'] ) {
1644 if ( 'save' === $this->do ) {
1645 $this->ui_page[] = $this->do;
1646 $this->reorder();
1647 }
1648 $this->manage( true );
1649 } elseif ( 'save' === $this->do && $this->save && ! in_array( $this->do, $this->actions_disabled ) && ! empty( $_POST ) ) {
1650 $this->ui_page[] = $this->do;
1651 $this->save();
1652 $this->manage();
1653 } elseif ( 'create' === $this->do && $this->save && ! in_array( $this->do, $this->actions_disabled ) && ! empty( $_POST ) ) {
1654 $this->ui_page[] = $this->do;
1655 $this->save( true );
1656 $this->manage();
1657 } elseif ( 'view' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) {
1658 $this->view();
1659 } else {
1660 if ( isset( $this->actions_custom[ $this->action ] ) ) {
1661 $use_nonce = false;
1662
1663 if ( is_array( $this->actions_custom[ $this->action ] ) ) {
1664 $more_args = [];
1665
1666 if ( ! empty( $this->actions_custom[ $this->action ]['more_args'] ) ) {
1667 $more_args = $this->actions_custom[ $this->action ]['more_args'];
1668 }
1669
1670 $use_nonce = ! empty( $this->actions_custom[ $this->action ]['nonce'] ) || ! empty( $more_args['nonce'] );
1671 }
1672
1673 $row = $this->row;
1674
1675 if ( empty( $row ) ) {
1676 $row = $this->get_row();
1677 }
1678
1679 if (
1680 $this->restricted( $this->action, $row )
1681 || (
1682 $use_nonce
1683 && false === wp_verify_nonce( $this->_nonce, 'pods-ui-action-' . $this->action . '-' . $this->id )
1684 )
1685 ) {
1686 return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1687 } elseif ( $more_args && false !== $this->callback_action( true, $this->action, $this->id, $row ) ) {
1688 return null;
1689 } elseif ( false !== $this->callback_action( true, $this->action, $this->id ) ) {
1690 return null;
1691 }
1692 }//end if
1693
1694 if ( ! in_array( 'manage', $this->actions_disabled ) ) {
1695 // handle session / user persistent settings for show_per_page, orderby, search, and filters
1696 $methods = array( 'session', 'user' );
1697
1698 // @todo fix this to set ($this) AND save (setting)
1699 foreach ( $methods as $method ) {
1700 foreach ( $this->$method as $setting ) {
1701 if ( 'show_per_page' === $setting ) {
1702 $value = $this->limit;
1703 } elseif ( 'orderby' === $setting ) {
1704 if ( empty( $this->orderby ) ) {
1705 $value = '';
1706 } elseif ( isset( $this->orderby['default'] ) ) {
1707 // save this if we have a default index set
1708 $value = $this->orderby['default'] . ' ' . ( false === strpos( $this->orderby['default'], ' ' ) ? $this->orderby_dir : '' );
1709 } else {
1710 $value = '';
1711 }
1712 } else {
1713 $value = $this->$setting;
1714 }
1715
1716 pods_v_set( $value, $setting, $method );
1717 }
1718 }
1719
1720 $this->manage();
1721 }//end if
1722 }//end if
1723 }
1724
1725 /**
1726 * @return mixed
1727 */
1728 public function add() {
1729
1730 if ( false !== $this->callback_action( 'add' ) ) {
1731 return null;
1732 }
1733
1734 if ( $this->restricted( $this->action ) ) {
1735 return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1736 }
1737
1738 $icon_style = '';
1739 if ( false !== $this->icon ) {
1740 $icon_style = ' style="background-position:0 0;background-size:100%;background-image:url(' . esc_url( $this->icon ) . ');"';
1741 }
1742 ?>
1743 <div class="wrap pods-ui">
1744 <div id="icon-edit-pages" class="icon32"<?php echo $icon_style; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>>
1745 <br />
1746 </div>
1747 <h2>
1748 <?php
1749 echo wp_kses_post( $this->header['add'] );
1750
1751 if ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
1752 $link = pods_query_arg(
1753 array(
1754 $this->num_prefix . 'action' . $this->num => 'manage',
1755 $this->num_prefix . 'id' . $this->num => '',
1756 ), self::$allowed, $this->exclusion()
1757 );
1758
1759 if ( ! empty( $this->action_links['manage'] ) ) {
1760 $link = $this->action_links['manage'];
1761 }
1762 ?>
1763 <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>
1764 <?php } ?>
1765 </h2>
1766
1767 <?php $this->form( true ); ?>
1768 </div>
1769 <?php
1770 }
1771
1772 /**
1773 * @param bool $duplicate
1774 *
1775 * @return bool|mixed
1776 */
1777 public function edit( $duplicate = false ) {
1778
1779 if ( in_array( 'duplicate', $this->actions_disabled ) ) {
1780 $duplicate = false;
1781 }
1782
1783 if ( empty( $this->row ) ) {
1784 $this->get_row();
1785 }
1786
1787 if ( $duplicate && false !== $this->callback_action( 'duplicate' ) ) {
1788 return null;
1789 } elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) {
1790 return null;
1791 }
1792
1793 if ( $this->restricted( $this->action ) ) {
1794 return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1795 }
1796
1797 $icon_style = '';
1798 if ( false !== $this->icon ) {
1799 $icon_style = ' style="background-position:0 0;background-size:100%;background-image:url(' . esc_url( $this->icon ) . ');"';
1800 }
1801 ?>
1802 <div class="wrap pods-ui">
1803 <div id="icon-edit-pages" class="icon32"<?php echo $icon_style; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>>
1804 <br />
1805 </div>
1806 <h2>
1807 <?php
1808 echo wp_kses_post( $this->do_template( $duplicate ? $this->header['duplicate'] : $this->header['edit'] ) );
1809
1810 if ( ! in_array( 'add', $this->actions_disabled ) && ! in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
1811 $link = pods_query_arg(
1812 array(
1813 $this->num_prefix . 'action' . $this->num => 'add',
1814 $this->num_prefix . 'id' . $this->num => '',
1815 $this->num_prefix . 'do' . $this->num => '',
1816 ), self::$allowed, $this->exclusion()
1817 );
1818
1819 if ( ! empty( $this->action_links['add'] ) ) {
1820 $link = $this->action_links['add'];
1821 }
1822 ?>
1823 <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading['add'] ); ?></a>
1824 <?php
1825 } elseif ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
1826 $link = pods_query_arg(
1827 array(
1828 $this->num_prefix . 'action' . $this->num => 'manage',
1829 $this->num_prefix . 'id' . $this->num => '',
1830 ), self::$allowed, $this->exclusion()
1831 );
1832
1833 if ( ! empty( $this->action_links['manage'] ) ) {
1834 $link = $this->action_links['manage'];
1835 }
1836 ?>
1837 <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>
1838 <?php
1839 }//end if
1840 ?>
1841 </h2>
1842
1843 <?php $this->form( false, $duplicate ); ?>
1844 </div>
1845 <?php
1846 }
1847
1848 /**
1849 * @param bool $create
1850 * @param bool $duplicate
1851 *
1852 * @return bool|mixed
1853 */
1854 public function form( $create = false, $duplicate = false ) {
1855
1856 if ( in_array( 'duplicate', $this->actions_disabled ) ) {
1857 $duplicate = false;
1858 }
1859
1860 if ( false !== $this->callback( 'form' ) ) {
1861 return null;
1862 }
1863
1864 $label = $this->label['add'];
1865 $id = null;
1866 $vars = array(
1867 $this->num_prefix . 'action' . $this->num => $this->action_after['add'],
1868 $this->num_prefix . 'do' . $this->num => 'create',
1869 $this->num_prefix . 'id' . $this->num => 'X_ID_X',
1870 );
1871
1872 $alt_vars = $vars;
1873 $alt_vars['action'] = 'manage';
1874 unset( $alt_vars['id'] );
1875
1876 if ( false === $create ) {
1877 if ( empty( $this->row ) ) {
1878 $this->get_row();
1879 }
1880
1881 if ( empty( $this->row ) && ( ! is_object( $this->pod ) || 'settings' !== $this->pod->pod_data['type'] ) ) {
1882 return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
1883 }
1884
1885 if ( $this->restricted( $this->action, $this->row ) ) {
1886 return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1887 }
1888
1889 $label = $this->do_template( $this->label['edit'] );
1890 $id = pods_v( $this->sql['field_id'], $this->row );
1891 $vars = array(
1892 $this->num_prefix . 'action' . $this->num => $this->action_after['edit'],
1893 $this->num_prefix . 'do' . $this->num => 'save',
1894 $this->num_prefix . 'id' . $this->num => $id,
1895 );
1896
1897 $alt_vars = $vars;
1898 $alt_vars['action'] = 'manage';
1899 unset( $alt_vars['id'] );
1900
1901 if ( $duplicate ) {
1902 $label = $this->do_template( $this->label['duplicate'] );
1903 $id = null;
1904 $vars = array(
1905 $this->num_prefix . 'action' . $this->num => $this->action_after['duplicate'],
1906 $this->num_prefix . 'do' . $this->num => 'create',
1907 $this->num_prefix . 'id' . $this->num => 'X_ID_X',
1908 );
1909
1910 $alt_vars = $vars;
1911 $alt_vars['action'] = 'manage';
1912 unset( $alt_vars['id'] );
1913 }
1914 } elseif ( $this->restricted( $this->action, $this->row ) ) {
1915 return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1916 }//end if
1917
1918 $fields = array();
1919
1920 if ( isset( $this->fields[ $this->action ] ) ) {
1921 $fields = $this->fields[ $this->action ];
1922 }
1923
1924 if ( is_object( $this->pod ) ) {
1925 $object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
1926
1927 if ( empty( $object_fields ) && in_array(
1928 $this->pod->pod_data['type'], array(
1929 'post_type',
1930 'taxonomy',
1931 'media',
1932 'user',
1933 'comment',
1934 )
1935 ) ) {
1936 $object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data['type'], $this->pod->pod_data );
1937 }
1938
1939 if ( empty( $fields ) ) {
1940 // Add core object fields if $fields is empty
1941 $fields = array_merge( $object_fields, $this->pod->fields );
1942 }
1943 }
1944
1945 $form_fields = $fields;
1946 // Temporary
1947 $fields = array();
1948
1949 foreach ( $form_fields as $k => $field ) {
1950 $name = $k;
1951
1952 $defaults = array(
1953 'name' => $name,
1954 );
1955
1956 if ( ! is_array( $field ) ) {
1957 $name = $field;
1958
1959 $field = array(
1960 'name' => $name,
1961 );
1962 }
1963
1964 $field = array_merge( $defaults, $field );
1965
1966 $field['name'] = trim( $field['name'] );
1967
1968 $default_value = pods_var_raw( 'default', $field );
1969 $value = pods_var_raw( 'value', $field );
1970
1971 if ( empty( $field['name'] ) ) {
1972 $field['name'] = trim( $name );
1973 }
1974
1975 if ( isset( $object_fields[ $field['name'] ] ) ) {
1976 $field = array_merge( $field, $object_fields[ $field['name'] ] );
1977 } elseif ( isset( $this->pod->fields[ $field['name'] ] ) ) {
1978 $field = array_merge( $this->pod->fields[ $field['name'] ], $field );
1979 }
1980
1981 if ( pods_var_raw( 'hidden', $field, false, null, true ) ) {
1982 $field['type'] = 'hidden';
1983 }
1984
1985 $fields[ $field['name'] ] = $field;
1986
1987 if ( empty( $this->id ) && null !== $default_value ) {
1988 $this->pod->row_override[ $field['name'] ] = $default_value;
1989 } elseif ( ! empty( $this->id ) && null !== $value ) {
1990 $this->pod->row[ $field['name'] ] = $value;
1991 }
1992 }//end foreach
1993
1994 unset( $form_fields );
1995 // Cleanup
1996 $fields = $this->do_hook( 'form_fields', $fields, $this->pod );
1997
1998 $pod =& $this->pod;
1999 $thank_you = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
2000 $thank_you_alt = pods_query_arg( $alt_vars, self::$allowed, $this->exclusion() );
2001 $obj =& $this;
2002 $singular_label = $this->item;
2003 $plural_label = $this->items;
2004
2005 if ( is_object( $this->pod ) && 'settings' === $this->pod->pod_data['type'] && 'settings' === $this->style ) {
2006 pods_view( PODS_DIR . 'ui/admin/form-settings.php', compact( array_keys( get_defined_vars() ) ) );
2007 } else {
2008 pods_view( PODS_DIR . 'ui/admin/form.php', compact( array_keys( get_defined_vars() ) ) );
2009 }
2010 }
2011
2012 /**
2013 * @return bool|mixed
2014 * @since 2.3.10
2015 */
2016 public function view() {
2017
2018 if ( false !== $this->callback_action( 'view' ) ) {
2019 return null;
2020 }
2021
2022 if ( empty( $this->row ) ) {
2023 $this->get_row();
2024 }
2025
2026 if ( empty( $this->row ) ) {
2027 return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
2028 }
2029
2030 $pod =& $this->pod;
2031 $obj =& $this;
2032
2033 $fields = array();
2034
2035 if ( isset( $this->fields[ $this->action ] ) ) {
2036 $fields = $this->fields[ $this->action ];
2037 }
2038
2039 if ( is_object( $this->pod ) ) {
2040 $object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
2041
2042 $object_field_objects = array(
2043 'post_type',
2044 'taxonomy',
2045 'media',
2046 'user',
2047 'comment',
2048 );
2049
2050 if ( empty( $object_fields ) && in_array( $this->pod->pod_data['type'], $object_field_objects ) ) {
2051 $object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data['type'], $this->pod->pod_data );
2052 }
2053
2054 if ( empty( $fields ) ) {
2055 // Add core object fields if $fields is empty
2056 $fields = array_merge( $object_fields, $this->pod->fields );
2057 }
2058 }
2059
2060 $view_fields = $fields;
2061 // Temporary
2062 $fields = array();
2063
2064 foreach ( $view_fields as $k => $field ) {
2065 $name = $k;
2066
2067 $defaults = array(
2068 'name' => $name,
2069 'type' => 'text',
2070 'options' => 'text',
2071 );
2072
2073 if ( ! is_array( $field ) ) {
2074 $name = $field;
2075
2076 $field = array(
2077 'name' => $name,
2078 );
2079 }
2080
2081 $field = array_merge( $defaults, $field );
2082
2083 $field['name'] = trim( $field['name'] );
2084
2085 $value = pods_var_raw( 'default', $field );
2086
2087 if ( empty( $field['name'] ) ) {
2088 $field['name'] = trim( $name );
2089 }
2090
2091 if ( isset( $object_fields[ $field['name'] ] ) ) {
2092 $field = array_merge( $field, $object_fields[ $field['name'] ] );
2093 } elseif ( isset( $this->pod->fields[ $field['name'] ] ) ) {
2094 $field = array_merge( $this->pod->fields[ $field['name'] ], $field );
2095 }
2096
2097 if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' === $field['type'] ) {
2098 continue;
2099 } elseif ( ! PodsForm::permission( $field['type'], $field['name'], $field['options'], $fields, $pod, $pod->id() ) ) {
2100 continue;
2101 }
2102
2103 $fields[ $field['name'] ] = $field;
2104
2105 if ( empty( $this->id ) && null !== $value ) {
2106 $this->pod->row_override[ $field['name'] ] = $value;
2107 }
2108 }//end foreach
2109
2110 unset( $view_fields );
2111 // Cleanup
2112
2113 $icon_style = '';
2114 if ( false !== $this->icon ) {
2115 $icon_style = ' style="background-position:0 0;background-size:100%;background-image:url(' . esc_url( $this->icon ) . ');"';
2116 }
2117 ?>
2118 <div class="wrap pods-ui">
2119 <div id="icon-edit-pages" class="icon32"<?php echo $icon_style; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>>
2120 <br />
2121 </div>
2122 <h2>
2123 <?php
2124 echo wp_kses_post( $this->do_template( $this->header['view'] ) );
2125
2126 if ( ! in_array( 'add', $this->actions_disabled ) && ! in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
2127 $link = pods_query_arg(
2128 array(
2129 $this->num_prefix . 'action' . $this->num => 'add',
2130 $this->num_prefix . 'id' . $this->num => '',
2131 $this->num_prefix . 'do' . $this->num => '',
2132 ), self::$allowed, $this->exclusion()
2133 );
2134
2135 if ( ! empty( $this->action_links['add'] ) ) {
2136 $link = $this->action_links['add'];
2137 }
2138 ?>
2139 <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading['add'] ); ?></a>
2140 <?php
2141 } elseif ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
2142 $link = pods_query_arg(
2143 array(
2144 $this->num_prefix . 'action' . $this->num => 'manage',
2145 $this->num_prefix . 'id' . $this->num => '',
2146 ), self::$allowed, $this->exclusion()
2147 );
2148
2149 if ( ! empty( $this->action_links['manage'] ) ) {
2150 $link = $this->action_links['manage'];
2151 }
2152 ?>
2153 <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>
2154 <?php
2155 }//end if
2156
2157 pods_view( PODS_DIR . 'ui/admin/view.php', compact( array_keys( get_defined_vars() ) ) );
2158 ?>
2159
2160 </h2>
2161 </div>
2162 <?php
2163 }
2164
2165 /**
2166 * Reorder data
2167 */
2168 public function reorder() {
2169
2170 // loop through order
2171 $order = (array) pods_var_raw( 'order', 'post', array(), null, true );
2172
2173 $params = array(
2174 'pod' => $this->pod->pod,
2175 'field' => $this->reorder['on'],
2176 'order' => $order,
2177 );
2178
2179 $reorder = pods_api()->reorder_pod_item( $params );
2180
2181 if ( $reorder ) {
2182 $this->message( sprintf( __( '<strong>Success!</strong> %s reordered successfully.', 'pods' ), $this->items ) );
2183 } else {
2184 $this->error( sprintf( __( '<strong>Error:</strong> %s has not been reordered.', 'pods' ), $this->items ) );
2185 }
2186 }
2187
2188 /**
2189 * @param bool $insert
2190 *
2191 * @return mixed
2192 */
2193 public function save( $insert = false ) {
2194
2195 $this->do_hook( 'pre_save', $insert );
2196
2197 if ( $this->callback( 'save', $insert ) ) {
2198 return null;
2199 }
2200
2201 global $wpdb;
2202 $action = __( 'saved', 'pods' );
2203 if ( true === $insert ) {
2204 $action = __( 'created', 'pods' );
2205 }
2206 $field_sql = array();
2207 $values = array();
2208 $data = array();
2209 foreach ( $this->fields['form'] as $field => $attributes ) {
2210 $vartype = '%s';
2211 if ( 'bool' === $attributes['type'] ) {
2212 $selected = ( 1 == pods_var( $field, 'post', 0 ) ) ? 1 : 0;
2213 } elseif ( '' == pods_var( $field, 'post', '' ) ) {
2214 continue;
2215 }
2216 if ( false === $attributes['display'] || false !== $attributes['readonly'] ) {
2217 if ( ! in_array( $attributes['type'], array( 'date', 'time', 'datetime' ) ) ) {
2218 continue;
2219 }
2220 if ( false === $attributes['date_touch'] && ( false === $attributes['date_touch_on_create'] || false === $insert || 0 < $this->id ) ) {
2221 continue;
2222 }
2223 }
2224 if ( in_array( $attributes['type'], array( 'date', 'time', 'datetime' ) ) ) {
2225 $format = 'Y-m-d H:i:s';
2226 if ( 'date' === $attributes['type'] ) {
2227 $format = 'Y-m-d';
2228 }
2229 if ( 'time' === $attributes['type'] ) {
2230 $format = 'H:i:s';
2231 }
2232 if ( false !== $attributes['date_touch'] || ( false !== $attributes['date_touch_on_create'] && true === $insert && $this->id < 1 ) ) {
2233 $value = date_i18n( $format );
2234 } else {
2235 $value = date_i18n( $format, strtotime( ( 'time' === $attributes['type'] ) ? date_i18n( 'Y-m-d ' ) : pods_var( $field, 'post', '' ) ) );
2236 }
2237 } else {
2238 if ( 'bool' === $attributes['type'] ) {
2239 $vartype = '%d';
2240 $value = 0;
2241 if ( '' != pods_var( $field, 'post', '' ) ) {
2242 $value = 1;
2243 }
2244 } elseif ( 'number' === $attributes['type'] ) {
2245 $vartype = '%d';
2246 $value = number_format( pods_var( $field, 'post', 0 ), 0, '', '' );
2247 } elseif ( 'decimal' === $attributes['type'] ) {
2248 $vartype = '%d';
2249 $value = number_format( pods_var( $field, 'post', 0 ), 2, '.', '' );
2250 } elseif ( 'related' === $attributes['type'] ) {
2251 if ( is_array( pods_var( $field, 'post', '' ) ) ) {
2252 $value = implode( ',', pods_var( $field, 'post', '' ) );
2253 } else {
2254 $value = pods_var( $field, 'post', '' );
2255 }
2256 } else {
2257 $value = pods_var( $field, 'post', '' );
2258 }//end if
2259 }//end if
2260
2261 if ( isset( $attributes['custom_save'] ) && false !== $attributes['custom_save'] && is_callable( $attributes['custom_save'] ) ) {
2262 $value = call_user_func_array(
2263 $attributes['custom_save'], array(
2264 $value,
2265 $field,
2266 $attributes,
2267 &$this,
2268 )
2269 );
2270 }
2271
2272 $field_sql[] = "`$field`=$vartype";
2273 $values[] = $value;
2274 $data[ $field ] = $value;
2275 }//end foreach
2276 $field_sql = implode( ',', $field_sql );
2277 if ( false === $insert && 0 < $this->id ) {
2278 $this->insert_id = $this->id;
2279 $values[] = $this->id;
2280 $check = $wpdb->query( $wpdb->prepare( "UPDATE $this->sql['table'] SET $field_sql WHERE id=%d", $values ) );
2281 } else {
2282 $check = $wpdb->query( $wpdb->prepare( "INSERT INTO $this->sql['table'] SET $field_sql", $values ) );
2283 }
2284 if ( $check ) {
2285 if ( empty( $this->insert_id ) ) {
2286 $this->insert_id = $wpdb->insert_id;
2287 }
2288 $this->message( sprintf( __( '<strong>Success!</strong> %1\$s %2\$s successfully.', 'pods' ), $this->item, $action ) );
2289 } else {
2290 $this->error( sprintf( __( '<strong>Error:</strong> %1\$s has not been %2\$s.', 'pods' ), $this->item, $action ) );
2291 }
2292 $this->do_hook( 'post_save', $this->insert_id, $data, $insert );
2293 }
2294
2295 /**
2296 * @param null $id
2297 *
2298 * @return bool|mixed
2299 */
2300 public function delete( $id = null ) {
2301
2302 $this->do_hook( 'pre_delete', $id );
2303
2304 if ( false !== $this->callback_action( 'delete', $id ) ) {
2305 return null;
2306 }
2307
2308 $id = pods_absint( $id );
2309
2310 if ( empty( $id ) ) {
2311 $id = pods_absint( $this->id );
2312 }
2313
2314 if ( $id < 1 ) {
2315 return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods' ) );
2316 }
2317
2318 if ( false === $id ) {
2319 $id = $this->id;
2320 }
2321
2322 if ( is_object( $this->pod ) ) {
2323 $check = $this->pod->delete( $id );
2324 } else {
2325 $check = $this->pods_data->delete( $this->sql['table'], array( $this->sql['field_id'] => $id ) );
2326 }
2327
2328 if ( $check ) {
2329 $this->message( sprintf( __( '<strong>Deleted:</strong> %s has been deleted.', 'pods' ), $this->item ) );
2330 } else {
2331 $this->error( sprintf( __( '<strong>Error:</strong> %s has not been deleted.', 'pods' ), $this->item ) );
2332 }
2333
2334 $this->do_hook( 'post_delete', $id );
2335 }
2336
2337 /**
2338 * Callback for deleting items in bulk
2339 */
2340 public function delete_bulk() {
2341
2342 $this->do_hook( 'pre_delete_bulk' );
2343
2344 if ( 1 != pods_var( 'deleted_bulk', 'get', 0 ) ) {
2345 $ids = $this->bulk;
2346
2347 $success = false;
2348
2349 if ( ! empty( $ids ) ) {
2350 $ids = (array) $ids;
2351
2352 foreach ( $ids as $id ) {
2353 $id = pods_absint( $id );
2354
2355 if ( empty( $id ) ) {
2356 continue;
2357 }
2358
2359 $callback = $this->callback( 'delete', $id );
2360 if ( $callback ) {
2361 $check = $callback;
2362 } elseif ( is_object( $this->pod ) ) {
2363 $check = $this->pod->delete( $id );
2364 } else {
2365 $check = $this->pods_data->delete( $this->sql['table'], array( $this->sql['field_id'] => $id ) );
2366 }
2367
2368 if ( $check ) {
2369 $success = true;
2370 }
2371 }
2372 }//end if
2373
2374 if ( $success ) {
2375 pods_redirect(
2376 pods_query_arg(
2377 array(
2378 'action_bulk' => 'delete',
2379 'deleted_bulk' => 1,
2380 ), array(
2381 'page',
2382 'lang',
2383 'action',
2384 'id',
2385 )
2386 )
2387 );
2388 } else {
2389 $this->error( sprintf( __( '<strong>Error:</strong> %s has not been deleted.', 'pods' ), $this->item ) );
2390 }
2391 } else {
2392 $this->message( sprintf( __( '<strong>Deleted:</strong> %s have been deleted.', 'pods' ), $this->items ) );
2393
2394 unset( $_GET['deleted_bulk'] );
2395 }//end if
2396
2397 $this->action_bulk = false;
2398 unset( $_GET['action_bulk'] );
2399
2400 $this->do_hook( 'post_delete_bulk' );
2401
2402 $this->manage();
2403 }
2404
2405 /**
2406 * Callback for exporting items in bulk
2407 */
2408 public function export_bulk() {
2409
2410 if ( ! empty( $_POST['bulk_export_type'] ) ) {
2411 if ( ! empty( $_POST['bulk_export_fields'] ) ) {
2412 $export_fields = $_POST['bulk_export_fields'];
2413
2414 $this->fields['export'] = array();
2415
2416 if ( $this->pod ) {
2417 $fields = $this->pod->fields();
2418
2419 foreach ( $fields as $field ) {
2420 if ( in_array( $field['name'], $export_fields ) ) {
2421 $this->fields['export'][] = $field;
2422 }
2423 }
2424 }
2425 }
2426
2427 // Set up where clause so that export function finds it
2428 if ( ! empty( $_POST['action_bulk_ids'] ) ) {
2429 $ids = (array) explode( ',', $_POST['action_bulk_ids'] );
2430 $ids = array_map( 'absint', $ids );
2431 $ids = array_filter( $ids );
2432
2433 if ( ! empty( $ids ) ) {
2434 $ids = implode( ', ', $ids );
2435
2436 $this->where = array(
2437 'manage' => '`' . pods_sanitize( $this->sql['field_id'] ) . '` IN ( ' . $ids . ' )',
2438 );
2439 }
2440 }
2441
2442 $this->export( $_POST['bulk_export_type'] );
2443
2444 // Cleanup since export function calls get_data before returning
2445 $this->action_bulk = '';
2446 $this->where = array();
2447 $this->data = false;
2448
2449 $_GET['action_bulk_ids'] = '';
2450
2451 $this->manage();
2452 } else {
2453 $this->export_fields_form();
2454 }//end if
2455
2456 }
2457
2458 /**
2459 * Select the pods fields to be exported
2460 */
2461 public function export_fields_form() {
2462
2463 ?>
2464 <div class="wrap pods-admin pods-ui">
2465 <h2><?php echo __( 'Choose Export Fields', 'pods' ); ?></h2>
2466
2467 <form method="post" id="pods_admin_ui_export_form">
2468 <?php
2469 // Avoid a bunch of inputs if there's a lot selected
2470 if ( ! empty( $_REQUEST['action_bulk_ids'] ) ) {
2471 $_GET['action_bulk_ids'] = implode( ',', (array) $_REQUEST['action_bulk_ids'] );
2472 }
2473
2474 $this->hidden_vars();
2475 ?>
2476
2477 <ul>
2478 <?php foreach ( $this->pod->fields() as $field_name => $field ) { ?>
2479 <li>
2480 <label for="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>">
2481 <input type="checkbox" name="bulk_export_fields[]" id="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>" value="<?php echo esc_attr( $field['name'] ); ?>" />
2482 <?php esc_html_e( $field['label'] ); ?>
2483 </label>
2484 </li>
2485 <?php } ?>
2486 </ul>
2487
2488 <p class="submit">
2489 <?php _e( 'Export as:', 'pods' ); ?>&nbsp;&nbsp;
2490 <?php foreach ( $this->export['formats'] as $format => $separator ) { ?>
2491 <input type="submit" id="export_type_<?php esc_attr_e( strtoupper( $format ) ); ?>" value=" <?php esc_attr_e( strtoupper( $format ) ); ?> " name="bulk_export_type" class="button-primary" />
2492 <?php } ?>
2493 </p>
2494 </form>
2495 </div>
2496 <?php
2497
2498 }
2499
2500 /**
2501 * @param null $export_type
2502 */
2503 public function export( $export_type = null ) {
2504
2505 if ( empty( $export_type ) ) {
2506 $export_type = pods_var( 'export_type', 'get', 'csv' );
2507 }
2508
2509 $export_type = trim( strtolower( $export_type ) );
2510
2511 $type = $export_type;
2512
2513 $delimiter = ',';
2514
2515 if ( ! empty( $this->export['formats'][ $export_type ] ) ) {
2516 $delimiter = $this->export['formats'][ $export_type ];
2517 }
2518
2519 $columns = array(
2520 $this->sql['field_id'] => 'ID',
2521 );
2522
2523 if ( empty( $this->fields['export'] ) && $this->pod && ! empty( $this->pod->fields ) ) {
2524 $this->fields['export'] = $this->pod->fields;
2525 }
2526
2527 if ( ! empty( $this->fields['export'] ) ) {
2528 foreach ( $this->fields['export'] as $field ) {
2529 $columns[ $field['name'] ] = $field['label'];
2530 }
2531 }
2532
2533 $params = array(
2534 'full' => true,
2535 'flatten' => true,
2536 'fields' => array_keys( $columns ),
2537 'type' => $type,
2538 'delimiter' => $delimiter,
2539 'columns' => $columns,
2540 );
2541
2542 $items = $this->get_data( $params );
2543
2544 $data = array(
2545 'columns' => $columns,
2546 'items' => $items,
2547 'fields' => $this->fields['export'],
2548 );
2549
2550 $migrate = pods_migrate( $type, $delimiter, $data );
2551
2552 $migrate->export();
2553
2554 $save_params = array(
2555 'attach' => true,
2556 );
2557
2558 $export_file = $migrate->save( $save_params );
2559
2560 $this->message( sprintf( __( '<strong>Success:</strong> Your export is ready, you can download it <a href="%s" target="_blank" rel="noopener noreferrer">here</a>', 'pods' ), $export_file ) );
2561
2562 // echo '<script type="text/javascript">window.open("' . esc_js( $export_file ) . '");</script>';
2563 $this->get_data();
2564 }
2565
2566 /**
2567 * @param $field
2568 *
2569 * @return array|bool|mixed|null
2570 */
2571 public function get_field( $field ) {
2572
2573 $value = null;
2574
2575 // use PodsData to get field
2576 $callback = $this->callback( 'get_field', $field );
2577 if ( $callback ) {
2578 return $callback;
2579 }
2580
2581 if ( isset( $this->row[ $field ] ) ) {
2582 $value = $this->row[ $field ];
2583 } elseif ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2584 if ( 'Pod' == get_class( $this->pod ) ) {
2585 $value = $this->pod->get_field( $field );
2586 } else {
2587 $value = $this->pod->field( $field );
2588 }
2589 }
2590
2591 return $this->do_hook( 'get_field', $value, $field );
2592 }
2593
2594 /**
2595 * Get find() params based on current UI action
2596 *
2597 * @param null|array $params
2598 * @param null|string $action
2599 *
2600 * @return array|mixed|void
2601 */
2602 public function get_params( $params = null, $action = null ) {
2603
2604 if ( null === $action ) {
2605 $action = $this->action;
2606 }
2607
2608 $defaults = array(
2609 'full' => false,
2610 'flatten' => true,
2611 'fields' => null,
2612 'type' => '',
2613 );
2614
2615 if ( ! empty( $params ) ) {
2616 if ( is_object( $params ) ) {
2617 $params = get_object_vars( $params );
2618 }
2619
2620 $params = (object) array_merge( $defaults, $params );
2621 } else {
2622 $params = (object) $defaults;
2623 }
2624
2625 if ( ! in_array( $action, array( 'manage', 'reorder' ) ) ) {
2626 $action = 'manage';
2627 }
2628
2629 $params_override = false;
2630
2631 $orderby = array();
2632
2633 $limit = $this->limit;
2634
2635 $sql = null;
2636
2637 if ( 'reorder' === $this->action ) {
2638 if ( ! empty( $this->reorder['orderby'] ) ) {
2639 $orderby[ $this->reorder['orderby'] ] = $this->reorder['orderby_dir'];
2640 } else {
2641 $orderby[ $this->reorder['on'] ] = $this->reorder['orderby_dir'];
2642 }
2643
2644 if ( ! empty( $this->reorder['limit'] ) ) {
2645 $limit = $this->reorder['limit'];
2646 }
2647
2648 if ( ! empty( $this->reorder['sql'] ) ) {
2649 $sql = $this->reorder['sql'];
2650 }
2651 }
2652
2653 if ( ! empty( $this->orderby ) ) {
2654 $this->orderby = (array) $this->orderby;
2655
2656 foreach ( $this->orderby as $order ) {
2657 if ( false !== strpos( $order, ' ' ) ) {
2658 $orderby[] = $order;
2659 } elseif ( ! isset( $orderby[ $order ] ) ) {
2660 $orderby[ $order ] = $this->orderby_dir;
2661 }
2662 }
2663 }
2664
2665 if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2666 $find_params = array(
2667 'where' => pods_v( $action, $this->where, null, true ),
2668 'orderby' => $orderby,
2669 'page' => (int) $this->page,
2670 'pagination' => true,
2671 'limit' => (int) $limit,
2672 'search' => $this->searchable,
2673 'search_query' => $this->search,
2674 'search_across' => $this->search_across,
2675 'search_across_picks' => $this->search_across_picks,
2676 'fields' => $this->fields['search'],
2677 'filters' => $this->filters,
2678 'sql' => $sql,
2679 );
2680
2681 $params_override = true;
2682 } else {
2683 $find_params = array(
2684 'table' => $this->sql['table'],
2685 'id' => $this->sql['field_id'],
2686 'index' => $this->sql['field_index'],
2687 'where' => pods_v( $action, $this->where, null, true ),
2688 'orderby' => $orderby,
2689 'page' => (int) $this->page,
2690 'pagination' => true,
2691 'limit' => (int) $limit,
2692 'search' => $this->searchable,
2693 'search_query' => $this->search,
2694 'fields' => $this->fields['search'],
2695 'sql' => $sql,
2696 );
2697
2698 if ( ! empty( $this->sql['select'] ) ) {
2699 $find_params['select'] = $this->sql['select'];
2700 }
2701 }//end if
2702
2703 if ( empty( $find_params['where'] ) && $this->restricted( $this->action ) ) {
2704 $find_params['where'] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
2705 }
2706
2707 if ( $params_override ) {
2708 $find_params = array_merge( $find_params, (array) $this->params );
2709 }
2710
2711 if ( $params->full ) {
2712 $find_params['limit'] = - 1;
2713 }
2714
2715 $find_params = apply_filters( 'pods_ui_get_params', $find_params, ( is_object( $this->pod ) ? $this->pod->pod : null ), $this );
2716
2717 /**
2718 * Filter Pods::find() parameters to make it more easily extended by plugins and developers.
2719 *
2720 * @param array $find_params Parameters used with Pods::find()
2721 * @param string $action Current action
2722 * @param PodsUI $this PodsUI instance
2723 *
2724 * @since 2.6.8
2725 */
2726 $find_params = apply_filters( 'pods_ui_get_find_params', $find_params, $action, $this );
2727
2728 // Debug purposes
2729 if ( 1 == pods_v( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
2730 pods_debug( $find_params );
2731 }
2732
2733 return $find_params;
2734 }
2735
2736 /**
2737 * @param null $params
2738 *
2739 * @return bool
2740 * @internal param bool $full Whether to get ALL data or use pagination
2741 */
2742 public function get_data( $params = null ) {
2743
2744 $action = $this->action;
2745
2746 $defaults = array(
2747 'full' => false,
2748 'flatten' => true,
2749 'fields' => null,
2750 'type' => '',
2751 );
2752
2753 if ( ! empty( $params ) ) {
2754 if ( is_object( $params ) ) {
2755 $params = get_object_vars( $params );
2756 }
2757
2758 $params = (object) array_merge( $defaults, $params );
2759 } else {
2760 $params = (object) $defaults;
2761 }
2762
2763 if ( ! in_array( $action, array( 'manage', 'reorder' ) ) ) {
2764 $action = 'manage';
2765 }
2766
2767 $find_params = $this->get_params( $params, $action );
2768
2769 if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2770 $this->pod->find( $find_params );
2771
2772 if ( ! $params->full ) {
2773 $data = $this->pod->data();
2774
2775 $this->data = $data;
2776
2777 if ( ! empty( $this->data ) ) {
2778 $this->data_keys = array_keys( $this->data );
2779 }
2780
2781 $this->total = $this->pod->total();
2782 $this->total_found = $this->pod->total_found();
2783 } else {
2784 $this->data_full = array();
2785
2786 $export_params = array(
2787 'fields' => $params->fields,
2788 'flatten' => true,
2789 );
2790
2791 if ( in_array( $params->type, array( 'json', 'xml' ) ) ) {
2792 $export_params['flatten'] = false;
2793 }
2794
2795 $export_params = $this->do_hook( 'export_options', $export_params, $params );
2796
2797 while ( $this->pod->fetch() ) {
2798 $this->data_full[ $this->pod->id() ] = $this->pod->export( $export_params );
2799 }
2800
2801 $this->pod->reset();
2802
2803 return $this->data_full;
2804 }//end if
2805 } else {
2806 if ( ! empty( $this->data ) ) {
2807 return $this->data;
2808 }
2809
2810 if ( empty( $this->sql['table'] ) ) {
2811 return $this->data;
2812 }
2813
2814 $this->pods_data->select( $find_params );
2815
2816 if ( ! $params->full ) {
2817 $this->data = $this->pods_data->data;
2818
2819 if ( ! empty( $this->data ) ) {
2820 $this->data_keys = array_keys( $this->data );
2821 }
2822
2823 $this->total = $this->pods_data->total();
2824 $this->total_found = $this->pods_data->total_found();
2825 } else {
2826 $this->data_full = $this->pods_data->data;
2827
2828 if ( ! empty( $this->data_full ) ) {
2829 $this->data_keys = array_keys( $this->data_full );
2830 }
2831
2832 return $this->data_full;
2833 }
2834 }//end if
2835
2836 return $this->data;
2837 }
2838
2839 /**
2840 * Sort out data alphabetically by a key
2841 */
2842 public function sort_data() {
2843
2844 // only do this if we have a default orderby
2845 if ( isset( $this->orderby['default'] ) ) {
2846 $orderby = $this->orderby['default'];
2847 foreach ( $this->data as $k => $v ) {
2848 $sorter[ $k ] = strtolower( $v[ $orderby ] );
2849 }
2850 if ( $this->orderby_dir == 'ASC' ) {
2851 asort( $sorter );
2852 } else {
2853 arsort( $sorter );
2854 }
2855 foreach ( $sorter as $key => $val ) {
2856 $intermediary[] = $this->data[ $key ];
2857 }
2858 if ( isset( $intermediary ) ) {
2859 $this->data = $intermediary;
2860 $this->data_keys = array_keys( $this->data );
2861 }
2862 }
2863 }
2864
2865 /**
2866 * @param int $counter
2867 * @param null $method
2868 *
2869 * @return array
2870 */
2871 public function get_row( &$counter = 0, $method = null ) {
2872
2873 if ( ! empty( $this->row ) && 0 < (int) $this->id && 'table' !== $method ) {
2874 return $this->row;
2875 }
2876
2877 if ( is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2878 $this->row = $this->pod->fetch();
2879 } else {
2880 $this->row = false;
2881
2882 if ( ! empty( $this->data ) ) {
2883 if ( empty( $this->data_keys ) || count( $this->data ) != count( $this->data_keys ) ) {
2884 $this->data_keys = array_keys( $this->data );
2885 }
2886
2887 if ( count( $this->data ) == $this->total && isset( $this->data_keys[ $counter ] ) && isset( $this->data[ $this->data_keys[ $counter ] ] ) ) {
2888 $this->row = $this->data[ $this->data_keys[ $counter ] ];
2889
2890 $counter ++;
2891 }
2892 }
2893
2894 if ( false === $this->row && 0 < (int) $this->id && ! empty( $this->sql['table'] ) ) {
2895 $this->pods_data->select(
2896 array(
2897 'table' => $this->sql['table'],
2898 'where' => '`' . pods_sanitize( $this->sql['field_id'] ) . '` = ' . (int) $this->id,
2899 'limit' => 1,
2900 )
2901 );
2902
2903 $this->row = $this->pods_data->fetch();
2904 }
2905 }//end if
2906
2907 return $this->row;
2908 }
2909
2910 /**
2911 * @param bool $reorder
2912 *
2913 * @return mixed|null
2914 */
2915 public function manage( $reorder = false ) {
2916 if ( false !== $this->callback_action( 'manage', $reorder ) ) {
2917 return null;
2918 }
2919
2920 if ( ! empty( $this->action_bulk ) && ! empty( $this->actions_bulk ) && isset( $this->actions_bulk[ $this->action_bulk ] ) && ! in_array( $this->action_bulk, $this->actions_disabled ) && ( ! empty( $this->bulk ) || 'export' === $this->action_bulk ) ) {
2921 if ( empty( $_REQUEST[ $this->num_prefix . '_wpnonce' . $this->num ] ) || false === wp_verify_nonce( $_REQUEST[ $this->num_prefix . '_wpnonce' . $this->num ], 'pods-ui-action-bulk' ) ) {
2922 pods_message( __( 'Invalid bulk request, please try again.', 'pods' ) );
2923 } elseif ( false !== $this->callback_bulk( $this->action_bulk, $this->bulk ) ) {
2924 return null;
2925 } elseif ( 'delete' === $this->action_bulk ) {
2926 $this->delete_bulk();
2927
2928 return;
2929 } elseif ( 'export' === $this->action_bulk ) {
2930 $this->export_bulk();
2931
2932 return;
2933 }
2934 }
2935
2936 $this->screen_meta();
2937
2938 wp_enqueue_script( 'jquery' );
2939
2940 if ( true === $reorder ) {
2941 wp_enqueue_script( 'jquery-ui-sortable' );
2942 }
2943
2944 $icon_style = '';
2945 if ( false !== $this->icon ) {
2946 $icon_style = ' style="background-position:0 0;background-size:100%;background-image:url(' . esc_url( $this->icon ) . ');"';
2947 }
2948
2949 /**
2950 * Allow adding custom CSS classes to the Pods::manage() container.
2951 *
2952 * @since 2.6.8
2953 *
2954 * @param array $custom_container_classes List of custom classes to use.
2955 * @param PodsUI $this PodsUI instance.
2956 */
2957 $custom_container_classes = apply_filters( 'pods_ui_manage_custom_container_classes', array() );
2958
2959 if ( is_admin() ) {
2960 array_unshift( $custom_container_classes, 'wrap' );
2961 }
2962
2963 array_unshift( $custom_container_classes, 'pods-admin' );
2964 array_unshift( $custom_container_classes, 'pods-ui' );
2965
2966 $custom_container_classes = array_map( 'sanitize_html_class', $custom_container_classes );
2967 $custom_container_classes = implode( ' ', $custom_container_classes );
2968 ?>
2969 <div class="<?php echo esc_attr( $custom_container_classes ); ?>">
2970 <div class="pods-admin-container">
2971 <?php if ( ! in_array( 'manage_header', $this->actions_disabled, true ) && ! in_array( 'manage_header', $this->actions_hidden, true ) ) : ?>
2972 <div id="icon-edit-pages" class="icon32"<?php echo $icon_style; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>>
2973 <br />
2974 </div>
2975 <h2>
2976 <?php
2977 if ( true === $reorder ) {
2978 echo wp_kses_post( $this->header['reorder'] );
2979
2980 if ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
2981 $link = pods_query_arg(
2982 array(
2983 $this->num_prefix . 'action' . $this->num => 'manage',
2984 $this->num_prefix . 'id' . $this->num => '',
2985 ),
2986 self::$allowed, $this->exclusion()
2987 );
2988
2989 if ( ! empty( $this->action_links['manage'] ) ) {
2990 $link = $this->action_links['manage'];
2991 }
2992 ?>
2993 <small>(<a href="<?php echo esc_url( $link ); ?>">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>)</small>
2994 <?php
2995 }
2996 } else {
2997 echo wp_kses_post( $this->header['manage'] );
2998 }
2999
3000 if ( ! in_array( 'add', $this->actions_disabled ) && ! in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
3001 $link = pods_query_arg(
3002 array(
3003 $this->num_prefix . 'action' . $this->num => 'add',
3004 $this->num_prefix . 'id' . $this->num => '',
3005 $this->num_prefix . 'do' . $this->num => '',
3006 ),
3007 self::$allowed, $this->exclusion()
3008 );
3009
3010 if ( ! empty( $this->action_links['add'] ) ) {
3011 $link = $this->action_links['add'];
3012 }
3013 ?>
3014 <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label['add_new'] ); ?></a>
3015 <?php
3016 }
3017 if ( ! in_array( 'reorder', $this->actions_disabled ) && ! in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder['on'] && ! $this->restricted( 'reorder' ) ) {
3018 $link = pods_query_arg( array( $this->num_prefix . 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() );
3019
3020 if ( ! empty( $this->action_links['reorder'] ) ) {
3021 $link = $this->action_links['reorder'];
3022 }
3023 ?>
3024 <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label['reorder'] ); ?></a>
3025 <?php
3026 }
3027 ?>
3028 </h2>
3029 <?php endif; ?>
3030
3031 <form id="posts-filter" action="" method="get">
3032 <?php
3033 $excluded_filters = array(
3034 $this->num_prefix . 'search' . $this->num,
3035 $this->num_prefix . 'pg' . $this->num,
3036 $this->num_prefix . 'action' . $this->num,
3037 $this->num_prefix . 'action_bulk' . $this->num,
3038 $this->num_prefix . 'action_bulk_ids' . $this->num,
3039 $this->num_prefix . '_wpnonce' . $this->num,
3040 );
3041
3042 $filters = $this->filters;
3043
3044 foreach ( $filters as $k => $filter ) {
3045 if ( isset( $this->pod->fields[ $filter ] ) ) {
3046 $filter_field = $this->pod->fields[ $filter ];
3047
3048 if ( isset( $this->fields['manage'][ $filter ] ) && is_array( $this->fields['manage'][ $filter ] ) ) {
3049 $filter_field = array_merge( $filter_field, $this->fields['manage'][ $filter ] );
3050 }
3051 } elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3052 $filter_field = $this->fields['manage'][ $filter ];
3053 } else {
3054 unset( $filters[ $k ] );
3055 continue;
3056 }
3057
3058 if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3059 if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) {
3060 unset( $filters[ $k ] );
3061 continue;
3062 }
3063 } elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) {
3064 unset( $filters[ $k ] );
3065 continue;
3066 }
3067
3068 $excluded_filters[] = 'filter_' . $filter . '_start';
3069 $excluded_filters[] = 'filter_' . $filter . '_end';
3070 $excluded_filters[] = 'filter_' . $filter;
3071 }//end foreach
3072
3073 $this->hidden_vars( $excluded_filters );
3074
3075 if ( false !== $this->callback( 'header', $reorder ) ) {
3076 return null;
3077 }
3078
3079 if ( false === $this->data ) {
3080 $this->get_data();
3081 } elseif ( $this->sortable ) {
3082 // we have the data already as an array
3083 $this->sort_data();
3084 }
3085
3086 if ( 'export' === $this->action && ! in_array( 'export', $this->actions_disabled, true ) ) {
3087 $this->export();
3088 }
3089
3090 if ( ( ! empty( $this->data ) || false !== $this->search || ( $this->filters_enhanced && ! empty( $this->views ) ) ) && ( ( $this->filters_enhanced && ! empty( $this->views ) ) || false !== $this->searchable ) ) {
3091 wp_enqueue_style( 'pods-styles' );
3092
3093 if ( $this->filters_enhanced ) {
3094 $this->filters();
3095 } else {
3096 ?>
3097 <p class="search-box" align="right">
3098 <?php
3099 foreach ( $this->filters as $filter ) {
3100 if ( isset( $this->pod->fields[ $filter ] ) ) {
3101 $filter_field = $this->pod->fields[ $filter ];
3102
3103 if ( isset( $this->fields['manage'][ $filter ] ) && is_array( $this->fields['manage'][ $filter ] ) ) {
3104 $filter_field = array_merge( $filter_field, $this->fields['manage'][ $filter ] );
3105 }
3106 } elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3107 $filter_field = $this->fields['manage'][ $filter ];
3108 } else {
3109 continue;
3110 }
3111 ?>
3112 <span class="pods-form-ui-filter-container pods-form-ui-filter-container-<?php echo esc_attr( $filter ); ?>">
3113 <?php
3114 if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3115 $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
3116 $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
3117
3118 // override default value
3119 $filter_field['options']['default_value'] = '';
3120 $filter_field['options'][ $filter_field['type'] . '_allow_empty' ] = 1;
3121
3122 if ( ! empty( $start ) && ! in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
3123 $start = PodsForm::field_method( $filter_field['type'], 'convert_date', $start, 'n/j/Y' );
3124 }
3125
3126 if ( ! empty( $end ) && ! in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
3127 $end = PodsForm::field_method( $filter_field['type'], 'convert_date', $end, 'n/j/Y' );
3128 }
3129 ?>
3130 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
3131 <?php esc_html_e( $filter_field['label'] ); ?>
3132 </label>
3133 <?php
3134 // Prevent p div issues.
3135 echo str_replace(
3136 array(
3137 '<div',
3138 '</div>',
3139 ),
3140 array(
3141 '<span',
3142 '</span>',
3143 ),
3144 PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field['type'], $filter_field )
3145 );
3146 ?>
3147
3148 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">
3149 to
3150 </label>
3151 <?php
3152 // Prevent p div issues.
3153 echo str_replace(
3154 array(
3155 '<div',
3156 '</div>',
3157 ),
3158 array(
3159 '<span',
3160 '</span>',
3161 ),
3162 PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field['type'], $filter_field )
3163 );
3164 } elseif ( 'pick' === $filter_field['type'] ) {
3165 $value = pods_var_raw( 'filter_' . $filter );
3166
3167 if ( strlen( $value ) < 1 ) {
3168 $value = pods_var_raw( 'filter_default', $filter_field );}
3169
3170 // override default value
3171 $filter_field['options']['default_value'] = '';
3172
3173 $filter_field['options']['pick_format_type'] = 'single';
3174 $filter_field['options']['pick_format_single'] = 'dropdown';
3175 $filter_field['options']['pick_allow_add_new'] = 0;
3176
3177 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields['search'], array(), null, true ), array(), null, true ), '', null, true );
3178 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
3179
3180 $options = array_merge( $filter_field, $filter_field['options'] );
3181 ?>
3182 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3183 <?php esc_html_e( $filter_field['label'] ); ?>
3184 </label>
3185 <?php
3186 // Prevent p div issues.
3187 echo str_replace(
3188 array(
3189 '<div',
3190 '</div>',
3191 ),
3192 array(
3193 '<span',
3194 '</span>',
3195 ),
3196 PodsForm::field( 'filter_' . $filter, $value, 'pick', $options )
3197 );
3198 } elseif ( 'boolean' === $filter_field['type'] ) {
3199 $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3200
3201 if ( strlen( $value ) < 1 ) {
3202 $value = pods_var_raw( 'filter_default', $filter_field );}
3203
3204 // override default value
3205 $filter_field['options']['default_value'] = '';
3206
3207 $filter_field['options']['pick_format_type'] = 'single';
3208 $filter_field['options']['pick_format_single'] = 'dropdown';
3209 $filter_field['options']['pick_allow_add_new'] = 0;
3210
3211 $filter_field['options']['pick_object'] = 'custom-simple';
3212 $filter_field['options']['pick_custom'] = array(
3213 '1' => pods_var_raw( 'boolean_yes_label', $filter_field['options'], __( 'Yes', 'pods' ), null, true ),
3214 '0' => pods_var_raw( 'boolean_no_label', $filter_field['options'], __( 'No', 'pods' ), null, true ),
3215 );
3216
3217 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields['search'], array(), null, true ), array(), null, true ), '', null, true );
3218 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
3219
3220 $options = array_merge( $filter_field, $filter_field['options'] );
3221 ?>
3222 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3223 <?php esc_html_e( $filter_field['label'] ); ?>
3224 </label>
3225 <?php
3226 // Prevent p div issues.
3227 echo str_replace(
3228 array(
3229 '<div',
3230 '</div>',
3231 ),
3232 array(
3233 '<span',
3234 '</span>',
3235 ),
3236 PodsForm::field( 'filter_' . $filter, $value, 'pick', $options )
3237 );
3238 } else {
3239 $value = pods_var_raw( 'filter_' . $filter );
3240
3241 if ( strlen( $value ) < 1 ) {
3242 $value = pods_var_raw( 'filter_default', $filter_field );}
3243
3244 // override default value
3245 $filter_field['options']['default_value'] = '';
3246
3247 $options = array();
3248 $options['input_helper'] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields['search'], array(), null, true ), array(), null, true ), '', null, true );
3249 $options['input_helper'] = pods_var_raw( 'ui_input_helper', $options, $options['input_helper'], null, true );
3250 ?>
3251 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3252 <?php esc_html_e( $filter_field['label'] ); ?>
3253 </label>
3254 <?php
3255 // Prevent p div issues.
3256 echo str_replace(
3257 array(
3258 '<div',
3259 '</div>',
3260 ),
3261 array(
3262 '<span',
3263 '</span>',
3264 ),
3265 PodsForm::field( 'filter_' . $filter, $value, 'text', $options )
3266 );
3267 }//end if
3268 ?>
3269 </span>
3270 <?php
3271 }//end foreach
3272
3273 if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
3274 ?>
3275 <span class="pods-form-ui-filter-container pods-form-ui-filter-container-search">
3276 <label<?php echo ( empty( $this->filters ) ) ? ' class="screen-reader-text"' : ''; ?> for="<?php echo esc_attr( $this->num_prefix ); ?>page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
3277 <?php echo PodsForm::field( $this->num_prefix . 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
3278 </span>
3279 <?php
3280 } else {
3281 echo PodsForm::field( $this->num_prefix . 'search' . $this->num, '', 'hidden' );
3282 }
3283
3284 echo PodsForm::submit_button( $this->header['search'], 'button', false, false, array( 'id' => $this->num_prefix . 'search' . $this->num . '-submit' ) );
3285
3286 if ( 0 < strlen( $this->search ) ) {
3287 $clear_filters = array(
3288 $this->num_prefix . 'search' . $this->num => false,
3289 );
3290
3291 foreach ( $this->filters as $filter ) {
3292 $clear_filters[ 'filter_' . $filter . '_start' ] = false;
3293 $clear_filters[ 'filter_' . $filter . '_end' ] = false;
3294 $clear_filters[ 'filter_' . $filter ] = false;
3295 }
3296 ?>
3297 <br class="clear" />
3298 <small>[<a href="<?php echo esc_url( pods_query_arg( $clear_filters, array( $this->num_prefix . 'orderby' . $this->num, $this->num_prefix . 'orderby_dir' . $this->num, $this->num_prefix . 'limit' . $this->num, 'page' ), $this->exclusion() ) ); ?>"><?php _e( 'Reset Filters', 'pods' ); ?></a>]</small>
3299 <br class="clear" />
3300 <?php
3301 }
3302 ?>
3303 </p>
3304 <?php
3305 }//end if
3306 } else {
3307 ?>
3308 <br class="clear" />
3309 <?php
3310 }//end if
3311
3312 if ( ! empty( $this->data ) && ( false !== $this->pagination_total || false !== $this->pagination || true === $reorder ) || ( ! in_array( 'export', $this->actions_disabled ) && ! in_array( 'export', $this->actions_hidden ) ) || ! empty( $this->actions_disabled ) ) {
3313 ?>
3314 <div class="tablenav">
3315 <?php
3316 if ( ! empty( $this->data ) && ! empty( $this->actions_bulk ) ) {
3317 ?>
3318 <div class="alignleft actions">
3319 <?php wp_nonce_field( 'pods-ui-action-bulk', $this->num_prefix . '_wpnonce' . $this->num, false ); ?>
3320
3321 <select name="<?php echo esc_attr( $this->num_prefix ); ?>action_bulk<?php echo esc_attr( $this->num ); ?>">
3322 <option value="-1" selected="selected"><?php _e( 'Bulk Actions', 'pods' ); ?></option>
3323
3324 <?php
3325 foreach ( $this->actions_bulk as $action => $action_data ) {
3326 if ( in_array( $action, $this->actions_hidden ) || in_array( $action, $this->actions_hidden ) ) {
3327 continue;}
3328
3329 if ( ! isset( $action_data['label'] ) ) {
3330 $action_data['label'] = ucwords( str_replace( '_', ' ', $action ) );}
3331 ?>
3332 <option value="<?php echo esc_attr( $action ); ?>"><?php esc_html_e( $action_data['label'] ); ?></option>
3333 <?php
3334 }
3335 ?>
3336 </select>
3337
3338 <input type="submit" id="<?php echo esc_attr( $this->num_prefix ); ?>doaction_bulk<?php echo esc_attr( $this->num ); ?>" class="button-secondary action" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
3339 </div>
3340 <?php
3341 }//end if
3342
3343 if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
3344 ?>
3345 <div class="tablenav-pages<?php esc_attr_e( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
3346 <?php $this->pagination( true ); ?>
3347 </div>
3348 <?php
3349 }
3350
3351 if ( true === $reorder ) {
3352 $link = pods_query_arg(
3353 array(
3354 $this->num_prefix . 'action' . $this->num => 'manage',
3355 $this->num_prefix . 'id' . $this->num => '',
3356 ), self::$allowed, $this->exclusion()
3357 );
3358
3359 if ( ! empty( $this->action_links['manage'] ) ) {
3360 $link = $this->action_links['manage'];
3361 }
3362 ?>
3363 <input type="button" value="<?php esc_attr_e( 'Update Order', 'pods' ); ?>" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" />
3364 <input type="button" value="<?php esc_attr_e( 'Cancel', 'pods' ); ?>" class="button" onclick="document.location='<?php echo esc_js( $link ); ?>';" />
3365 </form>
3366 <?php
3367 } elseif ( ! in_array( 'export', $this->actions_disabled ) && ! in_array( 'export', $this->actions_hidden ) ) {
3368 $export_document_location = pods_slash(
3369 pods_query_arg(
3370 array(
3371 $this->num_prefix . 'action_bulk' . $this->num => 'export',
3372 $this->num_prefix . '_wpnonce' . $this->num => wp_create_nonce( 'pods-ui-action-bulk' ),
3373 ), self::$allowed, $this->exclusion()
3374 )
3375 );
3376 ?>
3377 <div class="alignleft actions">
3378 <input type="button" value="<?php esc_attr_e( sprintf( __( 'Export all %s', 'pods' ), $this->items ) ); ?>" class="button" onclick="document.location='<?php echo $export_document_location; ?>';" />
3379 </div>
3380 <?php
3381 }//end if
3382 ?>
3383 <br class="clear" />
3384 </div>
3385 <?php
3386 } else {
3387 ?>
3388 <br class="clear" />
3389 <?php
3390 }//end if
3391 ?>
3392 <div class="clear"></div>
3393 <?php
3394 if ( empty( $this->data ) && false !== $this->default_none && false === $this->search ) {
3395 ?>
3396 <p><?php _e( 'Please use the search filter(s) above to display data', 'pods' ); ?>
3397 <?php
3398 if ( $this->export ) {
3399 ?>
3400 , <?php _e( 'or click on an Export to download a full copy of the data', 'pods' ); ?><?php } ?>.</p>
3401 <?php
3402 } else {
3403 $this->table( $reorder );}
3404 if ( ! empty( $this->data ) ) {
3405 if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
3406 ?>
3407 <div class="tablenav">
3408 <div class="tablenav-pages<?php esc_attr_e( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
3409 <?php $this->pagination(); ?>
3410 <br class="clear" />
3411 </div>
3412 </div>
3413 <?php
3414 }
3415 }
3416
3417 ?>
3418 </form>
3419 </div>
3420
3421 <?php
3422 /**
3423 * Allow additional output after the container area of the Pods UI manage screen.
3424 *
3425 * @since 2.7.17
3426 */
3427 do_action( 'pods_ui_manage_after_container' );
3428 ?>
3429 </div>
3430 <?php
3431 if ( $this->filters_enhanced ) {
3432 $this->filters_popup();
3433 }
3434 }
3435
3436 public function filters() {
3437
3438 include_once ABSPATH . 'wp-admin/includes/template.php';
3439
3440 wp_enqueue_script( 'thickbox' );
3441 wp_enqueue_style( 'thickbox' );
3442
3443 $filters = $this->filters;
3444
3445 foreach ( $filters as $k => $filter ) {
3446 if ( isset( $this->pod->fields[ $filter ] ) ) {
3447 $filter_field = $this->pod->fields[ $filter ];
3448
3449 if ( isset( $this->fields['manage'][ $filter ] ) && is_array( $this->fields['manage'][ $filter ] ) ) {
3450 $filter_field = array_merge( $filter_field, $this->fields['manage'][ $filter ] );
3451 }
3452 } elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3453 $filter_field = $this->fields['manage'][ $filter ];
3454 } else {
3455 continue;
3456 }
3457
3458 if ( isset( $filter_field ) && in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3459 if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) {
3460 unset( $filters[ $k ] );
3461 }
3462 } elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) {
3463 unset( $filters[ $k ] );
3464 }
3465 }
3466
3467 $filtered = false;
3468
3469 if ( ! empty( $filters ) ) {
3470 $filtered = true;
3471 }
3472 ?>
3473 <div class="pods-ui-filter-bar">
3474 <div class="pods-ui-filter-bar-primary">
3475 <?php
3476 if ( ! empty( $this->views ) ) {
3477 ?>
3478 <ul class="subsubsub">
3479 <li class="pods-ui-filter-view-label">
3480 <strong><?php echo wp_kses_post( $this->heading['views'] ); ?></strong></li>
3481
3482 <?php
3483 foreach ( $this->views as $view => $label ) {
3484 if ( false === strpos( $label, '<a' ) ) {
3485 $link = pods_query_arg(
3486 array(
3487 $this->num_prefix . 'view' . $this->num => $view,
3488 $this->num_prefix . 'pg' . $this->num => '',
3489 ), self::$allowed, $this->exclusion()
3490 );
3491
3492 if ( $this->view == $view ) {
3493 $label = '<a href="' . esc_url( $link ) . '" class="current">' . wp_kses_post( $label ) . '</a>';
3494 } else {
3495 $label = '<a href="' . esc_url( $link ) . '">' . wp_kses_post( $label ) . '</a>';
3496 }
3497 } else {
3498 $label = wp_kses_post( $label );
3499 }
3500 ?>
3501 <li class="view-<?php echo esc_attr( sanitize_html_class( str_replace( '/', '--', $view ) ) ); ?>">
3502 <?php
3503 /* Escaped above to support links */
3504 echo $label;
3505 ?>
3506 </li>
3507 <?php
3508 }//end foreach
3509 ?>
3510 </ul>
3511 <?php
3512 }//end if
3513 ?>
3514
3515 <?php
3516 if ( false !== $this->search && false !== $this->searchable ) {
3517 ?>
3518 <p class="search-box">
3519 <?php
3520 if ( $filtered || '' != pods_var_raw( $this->num_prefix . 'search' . $this->num, 'get', '', null, true ) ) {
3521 $clear_filters = array(
3522 $this->num_prefix . 'search' . $this->num => false,
3523 );
3524
3525 foreach ( $this->filters as $filter ) {
3526 $clear_filters[ 'filter_' . $filter . '_start' ] = false;
3527 $clear_filters[ 'filter_' . $filter . '_end' ] = false;
3528 $clear_filters[ 'filter_' . $filter ] = false;
3529 }
3530 ?>
3531 <a href="
3532 <?php
3533 echo esc_url(
3534 pods_query_arg(
3535 $clear_filters, array(
3536 $this->num_prefix . 'orderby' . $this->num,
3537 $this->num_prefix . 'orderby_dir' . $this->num,
3538 $this->num_prefix . 'limit' . $this->num,
3539 'page',
3540 ), $this->exclusion()
3541 )
3542 );
3543 ?>
3544 " class="pods-ui-filter-reset">[<?php _e( 'Reset', 'pods' ); ?>]</a>
3545 <?php
3546 }//end if
3547
3548 if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
3549 ?>
3550 &nbsp;&nbsp;
3551 <label class="screen-reader-text" for="<?php echo esc_attr( $this->num_prefix ); ?>page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
3552 <?php echo PodsForm::field( $this->num_prefix . 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
3553 <?php
3554 } else {
3555 echo PodsForm::field( $this->num_prefix . 'search' . $this->num, '', 'hidden' );
3556 }
3557 ?>
3558
3559 <?php echo PodsForm::submit_button( $this->header['search'], 'button', false, false, array( 'id' => $this->num_prefix . 'search' . $this->num . '-submit' ) ); ?>
3560 </p>
3561 <?php
3562 }//end if
3563 ?>
3564 </div>
3565
3566 <?php
3567 if ( ! empty( $this->filters ) ) {
3568 ?>
3569 <div class="pods-ui-filter-bar-secondary">
3570 <ul class="subsubsub">
3571 <?php
3572 if ( ! $filtered ) {
3573 ?>
3574 <li class="pods-ui-filter-bar-add-filter">
3575 <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
3576 <?php _e( 'Advanced Filters', 'pods' ); ?>
3577 </a>
3578 </li>
3579 <?php
3580 } else {
3581 ?>
3582 <li class="pods-ui-filter-bar-add-filter">
3583 <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>"> + <?php _e( 'Add Filter', 'pods' ); ?>
3584 </a>
3585 </li>
3586 <?php
3587 }
3588
3589 foreach ( $filters as $filter ) {
3590 $value = pods_var_raw( 'filter_' . $filter );
3591
3592 if ( isset( $this->pod->fields[ $filter ] ) ) {
3593 $filter_field = $this->pod->fields[ $filter ];
3594
3595 if ( isset( $this->fields['manage'][ $filter ] ) && is_array( $this->fields['manage'][ $filter ] ) ) {
3596 $filter_field = array_merge( $filter_field, $this->fields['manage'][ $filter ] );
3597 }
3598 } elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3599 $filter_field = $this->fields['manage'][ $filter ];
3600 } else {
3601 continue;
3602 }
3603
3604 $data_filter = 'filter_' . $filter;
3605
3606 $start = '';
3607 $end = '';
3608 $value_label = '';
3609
3610 if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3611 $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true );
3612 $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true );
3613
3614 if ( ! empty( $start ) && ! in_array(
3615 $start, array(
3616 '0000-00-00',
3617 '0000-00-00 00:00:00',
3618 '00:00:00',
3619 )
3620 ) ) {
3621 $start = PodsForm::field_method( $filter_field['type'], 'convert_date', $start, 'n/j/Y' );
3622 }
3623
3624 if ( ! empty( $end ) && ! in_array(
3625 $end, array(
3626 '0000-00-00',
3627 '0000-00-00 00:00:00',
3628 '00:00:00',
3629 )
3630 ) ) {
3631 $end = PodsForm::field_method( $filter_field['type'], 'convert_date', $end, 'n/j/Y' );
3632 }
3633
3634 $value = trim( $start . ' - ' . $end, ' -' );
3635
3636 $data_filter = 'filter_' . $filter . '_start';
3637 } elseif ( 'pick' === $filter_field['type'] ) {
3638 $value_label = trim( PodsForm::field_method( 'pick', 'value_to_label', $filter, $value, $filter_field, $this->pod->pod_data, null ) );
3639 } elseif ( 'boolean' === $filter_field['type'] ) {
3640 $yesno_options = array(
3641 '1' => pods_var_raw( 'boolean_yes_label', $filter_field['options'], __( 'Yes', 'pods' ), null, true ),
3642 '0' => pods_var_raw( 'boolean_no_label', $filter_field['options'], __( 'No', 'pods' ), null, true ),
3643 );
3644
3645 if ( isset( $yesno_options[ (string) $value ] ) ) {
3646 $value_label = $yesno_options[ (string) $value ];
3647 }
3648 }//end if
3649
3650 if ( strlen( $value_label ) < 1 ) {
3651 $value_label = $value;
3652 }
3653 ?>
3654 <li class="pods-ui-filter-bar-filter" data-filter="<?php echo esc_attr( $data_filter ); ?>">
3655 <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
3656 <strong><?php esc_html_e( $filter_field['label'] ); ?>:</strong>
3657 <?php esc_html_e( $value_label ); ?>
3658 </a>
3659
3660 <a href="#remove-filter" class="remove-filter" title="<?php esc_attr_e( 'Remove Filter', 'pods' ); ?>">x</a>
3661
3662 <?php
3663 if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3664 echo PodsForm::field( 'filter_' . $filter . '_start', $start, 'hidden' );
3665 echo PodsForm::field( 'filter_' . $filter . '_end', $end, 'hidden' );
3666 } else {
3667 echo PodsForm::field( $data_filter, $value, 'hidden' );
3668 }
3669 ?>
3670 </li>
3671 <?php
3672 }//end foreach
3673 ?>
3674 </ul>
3675 </div>
3676 <?php
3677 }//end if
3678 ?>
3679 </div>
3680
3681 <script type="text/javascript">
3682 document.addEventListener( 'DOMContentLoaded', function( event ) {
3683 jQuery( '.pods-ui-filter-bar-secondary' ).on( 'click', '.remove-filter', function ( e ) {
3684 jQuery( '.pods-ui-filter-popup #' + jQuery( this ).parent().data( 'filter' ) ).remove();
3685
3686 jQuery( this ).parent().find( 'input' ).each( function () {
3687 jQuery( this ).remove();
3688 } );
3689
3690 jQuery( 'form#posts-filter [name="<?php echo esc_attr( $this->num_prefix ); ?>pg<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3691 jQuery( 'form#posts-filter [name="<?php echo esc_attr( $this->num_prefix ); ?>action<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3692 jQuery( 'form#posts-filter [name="<?php echo esc_attr( $this->num_prefix ); ?>action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3693 jQuery( 'form#posts-filter [name="<?php echo esc_attr( $this->num_prefix ); ?>_wpnonce<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3694
3695 jQuery( 'form#posts-filter' ).submit();
3696
3697 e.preventDefault();
3698 } );
3699 } );
3700 </script>
3701 <?php
3702 }
3703
3704 public function filters_popup() {
3705
3706 $filters = $this->filters;
3707 ?>
3708 <div id="pods-ui-posts-filter-popup" class="pods-hidden">
3709 <form action="" method="get" class="pods-ui-posts-filter-popup">
3710 <h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
3711
3712 <div class="pods-ui-posts-filters">
3713 <?php
3714 $excluded_filters = array(
3715 $this->num_prefix . 'search' . $this->num,
3716 $this->num_prefix . 'pg' . $this->num,
3717 $this->num_prefix . 'action' . $this->num,
3718 $this->num_prefix . 'action_bulk' . $this->num,
3719 $this->num_prefix . 'action_bulk_ids' . $this->num,
3720 $this->num_prefix . '_wpnonce' . $this->num,
3721 );
3722
3723 foreach ( $filters as $filter ) {
3724 $excluded_filters[] = 'filters_relation';
3725 $excluded_filters[] = 'filters_compare_' . $filter;
3726 $excluded_filters[] = 'filter_' . $filter . '_start';
3727 $excluded_filters[] = 'filter_' . $filter . '_end';
3728 $excluded_filters[] = 'filter_' . $filter;
3729 }
3730
3731 $get = $_GET;
3732
3733 foreach ( $get as $k => $v ) {
3734 if ( in_array( $k, $excluded_filters ) || strlen( $v ) < 1 ) {
3735 continue;
3736 }
3737 ?>
3738 <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
3739 <?php
3740 }
3741
3742 $zebra = true;
3743
3744 foreach ( $filters as $filter ) {
3745 if ( empty( $filter ) ) {
3746 continue;
3747 }
3748
3749 if ( isset( $this->pod->fields[ $filter ] ) ) {
3750 $filter_field = $this->pod->fields[ $filter ];
3751
3752 if ( isset( $this->fields['manage'][ $filter ] ) && is_array( $this->fields['manage'][ $filter ] ) ) {
3753 $filter_field = array_merge( $filter_field, $this->fields['manage'][ $filter ] );
3754 }
3755 } elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3756 $filter_field = $this->fields['manage'][ $filter ];
3757 } else {
3758 continue;
3759 }
3760 ?>
3761 <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-<?php echo esc_attr( $filter . ( $zebra ? ' clear' : '' ) ); ?>">
3762 <?php
3763 if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3764 $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
3765 $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
3766
3767 // override default value
3768 $filter_field['options']['default_value'] = '';
3769 $filter_field['options'][ $filter_field['type'] . '_allow_empty' ] = 1;
3770
3771 if ( ! empty( $start ) && ! in_array(
3772 $start, array(
3773 '0000-00-00',
3774 '0000-00-00 00:00:00',
3775 '00:00:00',
3776 )
3777 ) ) {
3778 $start = PodsForm::field_method( $filter_field['type'], 'convert_date', $start, 'n/j/Y' );
3779 }
3780
3781 if ( ! empty( $end ) && ! in_array(
3782 $end, array(
3783 '0000-00-00',
3784 '0000-00-00 00:00:00',
3785 '00:00:00',
3786 )
3787 ) ) {
3788 $end = PodsForm::field_method( $filter_field['type'], 'convert_date', $end, 'n/j/Y' );
3789 }
3790 ?>
3791 <span class="pods-ui-posts-filter-toggle toggle-on<?php esc_attr_e( ( empty( $start ) && empty( $end ) ) ? '' : ' pods-hidden' ); ?>">+</span>
3792 <span class="pods-ui-posts-filter-toggle toggle-off<?php esc_attr_e( ( empty( $start ) && empty( $end ) ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3793
3794 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
3795 <?php esc_html_e( $filter_field['label'] ); ?>
3796 </label>
3797
3798 <span class="pods-ui-posts-filter<?php esc_attr_e( ( empty( $start ) && empty( $end ) ) ? ' pods-hidden' : '' ); ?>">
3799 <?php
3800 // Prevent p div issues.
3801 echo str_replace(
3802 array(
3803 '<div',
3804 '</div>',
3805 ),
3806 array(
3807 '<span',
3808 '</span>',
3809 ),
3810 PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field['type'], $filter_field )
3811 );
3812 ?>
3813
3814 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">to</label>
3815 <?php
3816 // Prevent p div issues.
3817 echo str_replace(
3818 array(
3819 '<div',
3820 '</div>',
3821 ),
3822 array(
3823 '<span',
3824 '</span>',
3825 ),
3826 PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field['type'], $filter_field )
3827 );
3828 ?>
3829 </span>
3830 <?php
3831 } elseif ( 'pick' === $filter_field['type'] ) {
3832 $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3833
3834 if ( strlen( $value ) < 1 ) {
3835 $value = pods_var_raw( 'filter_default', $filter_field );
3836 }
3837
3838 // override default value
3839 $filter_field['options']['default_value'] = '';
3840
3841 $filter_field['options']['pick_format_type'] = 'single';
3842 $filter_field['options']['pick_format_single'] = 'dropdown';
3843 $filter_field['options']['pick_allow_add_new'] = 0;
3844
3845 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields['search'], array(), null, true ), array(), null, true ), '', null, true );
3846 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
3847
3848 $options = array_merge( $filter_field, $filter_field['options'] );
3849 ?>
3850 <span class="pods-ui-posts-filter-toggle toggle-on<?php esc_attr_e( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3851 <span class="pods-ui-posts-filter-toggle toggle-off<?php esc_attr_e( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3852
3853 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3854 <?php esc_html_e( $filter_field['label'] ); ?>
3855 </label>
3856
3857 <span class="pods-ui-posts-filter<?php esc_attr_e( strlen( $value ) < 1 ? ' pods-hidden' : '' ); ?>">
3858 <?php
3859 // Prevent p div issues.
3860 echo str_replace(
3861 array(
3862 '<div',
3863 '</div>',
3864 ),
3865 array(
3866 '<span',
3867 '</span>',
3868 ),
3869 PodsForm::field( 'filter_' . $filter, $value, 'pick', $options )
3870 );
3871 ?>
3872 </span>
3873 <?php
3874 } elseif ( 'boolean' === $filter_field['type'] ) {
3875 $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3876
3877 if ( strlen( $value ) < 1 ) {
3878 $value = pods_var_raw( 'filter_default', $filter_field );
3879 }
3880
3881 // override default value
3882 $filter_field['options']['default_value'] = '';
3883
3884 $filter_field['options']['pick_format_type'] = 'single';
3885 $filter_field['options']['pick_format_single'] = 'dropdown';
3886 $filter_field['options']['pick_allow_add_new'] = 0;
3887
3888 $filter_field['options']['pick_object'] = 'custom-simple';
3889 $filter_field['options']['pick_custom'] = array(
3890 '1' => pods_var_raw( 'boolean_yes_label', $filter_field['options'], __( 'Yes', 'pods' ), null, true ),
3891 '0' => pods_var_raw( 'boolean_no_label', $filter_field['options'], __( 'No', 'pods' ), null, true ),
3892 );
3893
3894 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields['search'], array(), null, true ), array(), null, true ), '', null, true );
3895 $filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
3896
3897 $options = array_merge( $filter_field, $filter_field['options'] );
3898 ?>
3899 <span class="pods-ui-posts-filter-toggle toggle-on<?php esc_attr_e( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3900 <span class="pods-ui-posts-filter-toggle toggle-off<?php esc_attr_e( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3901
3902 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3903 <?php esc_html_e( $filter_field['label'] ); ?>
3904 </label>
3905
3906 <span class="pods-ui-posts-filter<?php esc_attr_e( strlen( $value ) < 1 ? ' pods-hidden' : '' ); ?>">
3907 <?php
3908 // Prevent p div issues.
3909 echo str_replace(
3910 array(
3911 '<div',
3912 '</div>',
3913 ),
3914 array(
3915 '<span',
3916 '</span>',
3917 ),
3918 PodsForm::field( 'filter_' . $filter, $value, 'pick', $options )
3919 );
3920 ?>
3921 </span>
3922 <?php
3923 } else {
3924 $value = pods_var_raw( 'filter_' . $filter );
3925
3926 if ( strlen( $value ) < 1 ) {
3927 $value = pods_var_raw( 'filter_default', $filter_field );
3928 }
3929
3930 $options = array(
3931 'input_helper' => pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields['search'], array(), null, true ), array(), null, true ), '', null, true ),
3932 );
3933
3934 if ( empty( $options['input_helper'] ) && isset( $filter_field['options'] ) && isset( $filter_field['options']['input_helper'] ) ) {
3935 $options['input_helper'] = $filter_field['options']['input_helper'];
3936 }
3937 ?>
3938 <span class="pods-ui-posts-filter-toggle toggle-on<?php esc_attr_e( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3939 <span class="pods-ui-posts-filter-toggle toggle-off<?php esc_attr_e( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3940
3941 <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3942 <?php esc_html_e( $filter_field['label'] ); ?>
3943 </label>
3944
3945 <span class="pods-ui-posts-filter<?php esc_attr_e( empty( $value ) ? ' pods-hidden' : '' ); ?>">
3946 <?php
3947 // Prevent p div issues.
3948 echo str_replace(
3949 array(
3950 '<div',
3951 '</div>',
3952 ),
3953 array(
3954 '<span',
3955 '</span>',
3956 ),
3957 PodsForm::field( 'filter_' . $filter, $value, 'text', $options )
3958 );
3959 ?>
3960 </span>
3961 <?php
3962 }//end if
3963 ?>
3964 </p>
3965 <?php
3966 $zebra = empty( $zebra );
3967 }//end foreach
3968 ?>
3969
3970 <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-search<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>">
3971 <label for="<?php echo esc_attr( $this->num_prefix ); ?>pods-form-ui-search<?php echo esc_attr( $this->num ); ?>"><?php _e( 'Search Text', 'pods' ); ?></label>
3972 <?php echo PodsForm::field( $this->num_prefix . 'search' . $this->num, pods_var_raw( $this->num_prefix . 'search' . $this->num ), 'text' ); ?>
3973 </p>
3974
3975 <?php $zebra = empty( $zebra ); ?>
3976 </div>
3977
3978 <p class="submit<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>">
3979 <input type="submit" value="<?php echo esc_attr( $this->header['search'] ); ?>" class="button button-primary" />
3980 </p>
3981 </form>
3982 </div>
3983
3984 <script type="text/javascript">
3985 document.addEventListener( 'DOMContentLoaded', function( event ) {
3986 jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) {
3987 jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'pods-hidden' );
3988
3989 jQuery( this ).hide();
3990 jQuery( this ).parent().find( '.toggle-off' ).show();
3991 } );
3992
3993 jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) {
3994 jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'pods-hidden' );
3995 jQuery( this ).parent().find( 'select, input' ).val( '' );
3996
3997 jQuery( this ).hide();
3998 jQuery( this ).parent().find( '.toggle-on' ).show();
3999 } );
4000
4001 jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) {
4002 if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'pods-hidden' ) ) {
4003 jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'pods-hidden' );
4004
4005 jQuery( this ).parent().find( '.toggle-on' ).hide();
4006 jQuery( this ).parent().find( '.toggle-off' ).show();
4007 }
4008 else {
4009 jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'pods-hidden' );
4010 jQuery( this ).parent().find( 'select, input' ).val( '' );
4011
4012 jQuery( this ).parent().find( '.toggle-on' ).show();
4013 jQuery( this ).parent().find( '.toggle-off' ).hide();
4014 }
4015 } );
4016 } );
4017 </script>
4018 <?php
4019 }
4020
4021 /**
4022 * @param bool $reorder
4023 *
4024 * @return bool|mixed
4025 */
4026 public function table( $reorder = false ) {
4027
4028 if ( false !== $this->callback( 'table', $reorder ) ) {
4029 return null;
4030 }
4031
4032 if ( empty( $this->data ) ) {
4033 ?>
4034 <p><?php echo pods_v( 'label_no_items_found', $this->label, sprintf( __( 'No %s found', 'pods' ), $this->items ) ); ?></p>
4035 <?php
4036 return false;
4037 }
4038 if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
4039
4040 ?>
4041 <style type="text/css">
4042 table.widefat.fixed tbody.reorderable tr {
4043 height: 50px;
4044 }
4045
4046 .dragme {
4047 background: url(<?php echo esc_url( PODS_URL ); ?>/ui/images/handle.gif) no-repeat;
4048 background-position: 8px 8px;
4049 cursor: pointer;
4050 }
4051
4052 .dragme strong {
4053 margin-left: 30px;
4054 }
4055 </style>
4056 <form action="
4057 <?php
4058 echo esc_url(
4059 pods_query_arg(
4060 array(
4061 $this->num_prefix . 'action' . $this->num => 'reorder',
4062 $this->num_prefix . 'do' . $this->num => 'save',
4063 'page' => pods_var_raw( 'page' ),
4064 ), self::$allowed, $this->exclusion()
4065 )
4066 );
4067 ?>
4068 " method="post" class="admin_ui_reorder_form">
4069 <?php
4070 }//end if
4071 $table_fields = $this->fields['manage'];
4072 if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] && ! empty( $this->fields['reorder'] ) ) {
4073 $table_fields = $this->fields['reorder'];
4074 }
4075 if ( false === $table_fields || empty( $table_fields ) ) {
4076 return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods' ) );
4077 }
4078 ?>
4079 <table class="widefat page fixed wp-list-table" cellspacing="0"<?php echo ( 1 == $reorder && $this->reorder ) ? ' id="admin_ui_reorder"' : ''; ?>>
4080 <thead>
4081 <tr>
4082 <?php
4083 if ( ! empty( $this->actions_bulk ) ) {
4084 ?>
4085 <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" />
4086 </th>
4087 <?php
4088 }
4089
4090 $name_field = false;
4091 $fields = array();
4092 if ( ! empty( $table_fields ) ) {
4093 foreach ( $table_fields as $field => $attributes ) {
4094 if ( false === $attributes['display'] ) {
4095 continue;
4096 }
4097 if ( false === $name_field ) {
4098 $id = 'title';
4099 } else {
4100 $id = '';
4101 }
4102 if ( 'other' === $attributes['type'] ) {
4103 $id = '';
4104 }
4105 if ( in_array( $attributes['type'], array( 'date', 'datetime', 'time' ) ) ) {
4106 $id = 'date';
4107 }
4108 if ( false === $name_field && 'title' === $id ) {
4109 $name_field = true;
4110 }
4111 $fields[ $field ] = $attributes;
4112 $fields[ $field ]['field_id'] = $id;
4113 $dir = 'DESC';
4114 $current_sort = ' asc';
4115 if ( isset( $this->orderby['default'] ) && $field == $this->orderby['default'] ) {
4116 if ( 'DESC' === $this->orderby_dir ) {
4117 $dir = 'ASC';
4118 $current_sort = ' desc';
4119 }
4120 }
4121
4122 $att_id = '';
4123 if ( ! empty( $id ) ) {
4124 $att_id = ' id="' . esc_attr( $id ) . '"';
4125 }
4126
4127 $width = '';
4128
4129 $column_classes = array(
4130 'manage-column',
4131 'column-' . $id,
4132 );
4133
4134 // Merge with the classes taken from the UI call
4135 if ( ! empty( $attributes['classes'] ) && is_array( $attributes['classes'] ) ) {
4136 $column_classes = array_merge( $column_classes, $attributes['classes'] );
4137 }
4138 if ( $id == 'title' ) {
4139 $column_classes[] = 'column-primary';
4140 }
4141
4142 if ( isset( $attributes['width'] ) && ! empty( $attributes['width'] ) ) {
4143 $width = ' style="width: ' . esc_attr( $attributes['width'] ) . '"';
4144 }
4145
4146 if ( $this->is_field_sortable( $attributes ) ) {
4147 $column_classes[] = 'sortable' . $current_sort;
4148 ?>
4149 <th scope="col"<?php echo $att_id; ?> class="<?php esc_attr_e( implode( ' ', $column_classes ) ); ?>"<?php echo $width; ?>>
4150 <a href="
4151 <?php
4152 echo esc_url_raw(
4153 pods_query_arg(
4154 array(
4155 $this->num_prefix . 'orderby' . $this->num => $field,
4156 $this->num_prefix . 'orderby_dir' . $this->num => $dir,
4157 ),
4158 array(
4159 $this->num_prefix . 'limit' . $this->num,
4160 $this->num_prefix . 'search' . $this->num,
4161 $this->num_prefix . 'pg' . $this->num,
4162 'page',
4163 'post_type',
4164 'taxonomy',
4165 ),
4166 $this->exclusion()
4167 )
4168 );
4169 ?>
4170 ">
4171 <span><?php esc_html_e( $attributes['label'] ); ?></span>
4172 <span class="sorting-indicator"></span> </a>
4173 </th>
4174 <?php
4175 } else {
4176 ?>
4177 <th scope="col"<?php echo $att_id; ?> class="<?php esc_attr_e( implode( ' ', $column_classes ) ); ?>"<?php echo $width; ?>><?php esc_html_e( $attributes['label'] ); ?></th>
4178 <?php
4179 }//end if
4180 }//end foreach
4181 }//end if
4182 ?>
4183 </tr>
4184 </thead>
4185 <?php
4186 if ( 6 < $this->total_found ) {
4187 ?>
4188 <tfoot>
4189 <tr>
4190 <?php
4191 if ( ! empty( $this->actions_bulk ) ) {
4192 ?>
4193 <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th>
4194 <?php
4195 }
4196
4197 if ( ! empty( $fields ) ) {
4198 foreach ( $fields as $field => $attributes ) {
4199 $dir = 'ASC';
4200 if ( $field == $this->orderby ) {
4201 $current_sort = 'desc';
4202 if ( 'ASC' === $this->orderby_dir ) {
4203 $dir = 'DESC';
4204 $current_sort = 'asc';
4205 }
4206 }
4207
4208 $width = '';
4209
4210 if ( isset( $attributes['width'] ) && ! empty( $attributes['width'] ) ) {
4211 $width = ' style="width: ' . esc_attr( $attributes['width'] ) . '"';
4212 }
4213
4214 if ( $this->is_field_sortable( $attributes ) ) {
4215 ?>
4216 <th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?> sortable <?php echo esc_attr( $current_sort ); ?>"<?php echo $width; ?>>
4217 <a href="
4218 <?php
4219 echo esc_url_raw(
4220 pods_query_arg(
4221 array(
4222 $this->num_prefix . 'orderby' . $this->num => $field,
4223 $this->num_prefix . 'orderby_dir' . $this->num => $dir,
4224 ), array(
4225 $this->num_prefix . 'limit' . $this->num,
4226 $this->num_prefix . 'search' . $this->num,
4227 $this->num_prefix . 'pg' . $this->num,
4228 'page',
4229 ), $this->exclusion()
4230 )
4231 );
4232 ?>
4233 "><span><?php esc_html_e( $attributes['label'] ); ?></span><span class="sorting-indicator"></span></a>
4234 </th>
4235 <?php
4236 } else {
4237 ?>
4238 <th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?>"<?php echo $width; ?>><?php esc_html_e( $attributes['label'] ); ?></th>
4239 <?php
4240 }//end if
4241 }//end foreach
4242 }//end if
4243 ?>
4244 </tr>
4245 </tfoot>
4246 <?php
4247 }//end if
4248 ?>
4249 <tbody id="the-list"<?php echo ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) ? ' class="reorderable"' : ''; ?>>
4250 <?php
4251 if ( ! empty( $this->data ) && is_array( $this->data ) ) {
4252 $counter = 0;
4253
4254 while ( $row = $this->get_row( $counter, 'table' ) ) {
4255 if ( is_object( $row ) ) {
4256 $row = get_object_vars( (object) $row );
4257 }
4258
4259 $toggle_class = '';
4260
4261 if ( is_array( $this->actions_custom ) && isset( $this->actions_custom['toggle'] ) ) {
4262 $toggle_class = ' pods-toggled-on';
4263
4264 if ( ! isset( $row['toggle'] ) || empty( $row['toggle'] ) ) {
4265 $toggle_class = ' pods-toggled-off';
4266 }
4267 }
4268 ?>
4269 <tr id="item-<?php echo esc_attr( $row[ $this->sql['field_id'] ] ); ?>" class="iedit<?php echo esc_attr( $toggle_class ); ?>">
4270 <?php
4271 if ( ! empty( $this->actions_bulk ) ) {
4272 ?>
4273 <th scope="row" class="check-column">
4274 <input type="checkbox" name="<?php echo esc_attr( $this->num_prefix ); ?>action_bulk_ids<?php echo esc_attr( $this->num ); ?>[]" value="<?php echo esc_attr( $row[ $this->sql['field_id'] ] ); ?>">
4275 </th>
4276 <?php
4277 }
4278 // Boolean for the first field to output after the check-column
4279 // will be set to false at the end of the first loop
4280 $first_field = true;
4281 foreach ( $fields as $field => $attributes ) {
4282 if ( false === $attributes['display'] ) {
4283 continue;
4284 }
4285
4286 if ( ! isset( $row[ $field ] ) ) {
4287 $row[ $field ] = $this->get_field( $field );
4288 }
4289
4290 $row_value = $row[ $field ];
4291
4292 if ( ! empty( $attributes['custom_display'] ) ) {
4293 if ( is_callable( $attributes['custom_display'] ) ) {
4294 $row_value = call_user_func_array(
4295 $attributes['custom_display'], array(
4296 $row,
4297 &$this,
4298 $row_value,
4299 $field,
4300 $attributes,
4301 )
4302 );
4303 } elseif ( is_object( $this->pod ) && class_exists( 'Pods_Helpers' ) ) {
4304 $row_value = $this->pod->helper( $attributes['custom_display'], $row_value, $field );
4305 }
4306 } else {
4307 ob_start();
4308
4309 $field_value = PodsForm::field_method( $attributes['type'], 'ui', $this->id, $row_value, $field, array_merge( $attributes, pods_var_raw( 'options', $attributes, array(), null, true ) ), $fields, $this->pod );
4310
4311 $field_output = trim( (string) ob_get_clean() );
4312
4313 if ( false === $field_value ) {
4314 $row_value = '';
4315 } elseif ( 0 < strlen( trim( (string) $field_value ) ) ) {
4316 $row_value = trim( (string) $field_value );
4317 } elseif ( 0 < strlen( $field_output ) ) {
4318 $row_value = $field_output;
4319 }
4320 }//end if
4321
4322 if ( false !== $attributes['custom_relate'] ) {
4323 global $wpdb;
4324 $table = $attributes['custom_relate'];
4325 $on = $this->sql['field_id'];
4326 $is = $row[ $this->sql['field_id'] ];
4327 $what = array( 'name' );
4328 if ( is_array( $table ) ) {
4329 if ( isset( $table['on'] ) ) {
4330 $on = pods_sanitize( $table['on'] );
4331 }
4332 if ( isset( $table['is'] ) && isset( $row[ $table['is'] ] ) ) {
4333 $is = pods_sanitize( $row[ $table['is'] ] );
4334 }
4335 if ( isset( $table['what'] ) ) {
4336 $what = array();
4337 if ( is_array( $table['what'] ) ) {
4338 foreach ( $table['what'] as $wha ) {
4339 $what[] = pods_sanitize( $wha );
4340 }
4341 } else {
4342 $what[] = pods_sanitize( $table['what'] );
4343 }
4344 }
4345 if ( isset( $table['table'] ) ) {
4346 $table = $table['table'];
4347 }
4348 }//end if
4349 $table = pods_sanitize( $table );
4350 $wha = implode( ',', $what );
4351 $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'";
4352 $value = @current( $wpdb->get_results( $sql, ARRAY_A ) );
4353 if ( ! empty( $value ) ) {
4354 $val = array();
4355 foreach ( $what as $wha ) {
4356 if ( isset( $value[ $wha ] ) ) {
4357 $val[] = $value[ $wha ];
4358 }
4359 }
4360 if ( ! empty( $val ) ) {
4361 $row_value = implode( ' ', $val );
4362 }
4363 }
4364 }//end if
4365
4366 $css_classes = array(
4367 'pods-ui-col-field-' . sanitize_title( $field ),
4368 );
4369
4370 // Merge with the classes taken from the UI call
4371 if ( ! empty( $attributes['classes'] ) && is_array( $attributes['classes'] ) ) {
4372 $css_classes = array_merge( $css_classes, $attributes['classes'] );
4373 }
4374
4375 if ( $attributes['css_values'] ) {
4376 $css_field_value = $row[ $field ];
4377
4378 if ( is_object( $css_field_value ) ) {
4379 $css_field_value = get_object_vars( $css_field_value );
4380 }
4381
4382 if ( is_array( $css_field_value ) ) {
4383 foreach ( $css_field_value as $css_field_val ) {
4384 if ( is_object( $css_field_val ) ) {
4385 $css_field_val = get_object_vars( $css_field_val );
4386 }
4387
4388 if ( is_array( $css_field_val ) ) {
4389 foreach ( $css_field_val as $css_field_v ) {
4390 if ( is_object( $css_field_v ) ) {
4391 $css_field_v = get_object_vars( $css_field_v );
4392 }
4393
4394 $css_classes[] = 'pods-ui-css-value-' . sanitize_title(
4395 str_replace(
4396 array(
4397 "\n",
4398 "\r",
4399 ), ' ', strip_tags( (string) $css_field_v )
4400 )
4401 );
4402 }
4403 } else {
4404 $css_classes[] = ' pods-ui-css-value-' . sanitize_title(
4405 str_replace(
4406 array(
4407 "\n",
4408 "\r",
4409 ), ' ', strip_tags( (string) $css_field_val )
4410 )
4411 );
4412 }//end if
4413 }//end foreach
4414 } else {
4415 $css_classes[] = ' pods-ui-css-value-' . sanitize_title(
4416 str_replace(
4417 array(
4418 "\n",
4419 "\r",
4420 ), ' ', strip_tags( (string) $css_field_value )
4421 )
4422 );
4423 }//end if
4424 }//end if
4425
4426 if ( is_object( $this->pod ) ) {
4427 $row_value = $this->do_hook( $this->pod->pod . '_field_value', $row_value, $field, $attributes, $row );
4428 }
4429
4430 $row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row );
4431
4432 if ( ! empty( $attributes['custom_display_formatted'] ) && is_callable( $attributes['custom_display_formatted'] ) ) {
4433 $row_value = call_user_func_array(
4434 $attributes['custom_display_formatted'], array(
4435 $row,
4436 &$this,
4437 $row_value,
4438 $field,
4439 $attributes,
4440 )
4441 );
4442 }
4443
4444 if ( 'title' === $attributes['field_id'] ) {
4445 $default_action = $this->do_hook( 'default_action', 'edit', $row );
4446
4447 if ( $first_field ) {
4448 $css_classes[] = 'column-primary';
4449 }
4450
4451 if ( is_admin() ) {
4452 $css_classes[] = 'post-title';
4453 $css_classes[] = 'page-title';
4454 }
4455
4456 $css_classes[] = 'column-title';
4457
4458 if ( 'raw' !== $attributes['type'] ) {
4459 // Deal with unexpected array values.
4460 if ( is_array( $row_value ) ) {
4461 if ( empty( $row_value ) ) {
4462 $row_value = '';
4463 } else {
4464 $row_value = pods_serial_comma( $row_value, $attributes );
4465 }
4466 }
4467
4468 $row_value = wp_kses_post( $row_value );
4469 }
4470
4471 /**
4472 * Allow filtering the display value used for a field in the table column.
4473 *
4474 * @since 2.7.29
4475 *
4476 * @param string $row_value The display value for the field.
4477 * @param string $field The field name.
4478 * @param array $attributes The field attributes.
4479 * @param array $row The other values for the row.
4480 * @param PodsUI $obj The PodsUI object.
4481 */
4482 $row_value = apply_filters( 'pods_ui_field_display_value', $row_value, $field, $attributes, $row, $this );
4483
4484 if ( ! in_array( 'edit', $this->actions_disabled ) && ! in_array( 'edit', $this->actions_hidden ) && ( false === $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder['on'] ) && 'edit' === $default_action ) {
4485 $link = pods_query_arg(
4486 array(
4487 $this->num_prefix . 'action' . $this->num => 'edit',
4488 $this->num_prefix . 'id' . $this->num => $row[ $this->sql['field_id'] ],
4489 ), self::$allowed, $this->exclusion()
4490 );
4491
4492 if ( ! empty( $this->action_links['edit'] ) ) {
4493 $link = $this->do_template( $this->action_links['edit'], $row );
4494 }
4495 ?>
4496 <td class="<?php esc_attr_e( implode( ' ', $css_classes ) ); ?>">
4497 <strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'Edit this item', 'pods' ); ?>">
4498 <?php
4499 /* Escaped above for non-HTML types */
4500 echo $row_value;
4501 ?>
4502 </a></strong>
4503 <?php
4504 } elseif ( ! in_array( 'view', $this->actions_disabled ) && ! in_array( 'view', $this->actions_hidden ) && ( false === $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder['on'] ) && 'view' === $default_action ) {
4505 $link = pods_query_arg(
4506 array(
4507 $this->num_prefix . 'action' . $this->num => 'view',
4508 $this->num_prefix . 'id' . $this->num => $row[ $this->sql['field_id'] ],
4509 ), self::$allowed, $this->exclusion()
4510 );
4511
4512 if ( ! empty( $this->action_links['view'] ) ) {
4513 $link = $this->do_template( $this->action_links['view'], $row );
4514 }
4515 ?>
4516 <td class="<?php esc_attr_e( implode( ' ', $css_classes ) ); ?>">
4517 <strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'View this item', 'pods' ); ?>">
4518 <?php
4519 /* Escaped above for non-HTML types */
4520 echo $row_value;
4521 ?>
4522 </a></strong>
4523 <?php
4524 } else {
4525 if ( 1 == $reorder && $this->reorder ) {
4526 $css_classes[] = 'dragme';
4527 }
4528 ?>
4529 <td class="<?php esc_attr_e( implode( ' ', $css_classes ) ); ?>">
4530 <strong>
4531 <?php
4532 /* Escaped above for non-HTML types */
4533 echo $row_value;
4534 ?>
4535 </strong>
4536 <?php
4537 }//end if
4538
4539 if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder['on'] ) {
4540 $toggle = false;
4541
4542 $actions = $this->get_actions( $row );
4543 $actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql['field_id'] ] );
4544
4545 if ( ! empty( $actions ) ) {
4546 ?>
4547 <div class="row-actions<?php echo esc_attr( $toggle ? ' row-actions-toggle' : '' ); ?>">
4548 <?php
4549 $this->callback( 'actions_start', $row, $actions );
4550
4551 echo implode( ' | ', $actions );
4552
4553 $this->callback( 'actions_end', $row, $actions );
4554 ?>
4555 </div>
4556 <?php
4557 }
4558 } else {
4559 ?>
4560 <input type="hidden" name="order[]" value="<?php echo esc_attr( $row[ $this->sql['field_id'] ] ); ?>" />
4561 <?php
4562 }//end if
4563
4564 if ( ! in_array( 'toggle_details', $this->actions_disabled, true ) ) {
4565 ?>
4566 <button type="button" class="toggle-row">
4567 <span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span>
4568 </button>
4569 <?php } ?>
4570 </td>
4571 <?php
4572 } elseif ( 'date' === $attributes['type'] ) {
4573 if ( $first_field ) {
4574 $css_classes[] = 'column-primary';
4575 }
4576 $css_classes[] = 'date';
4577 $css_classes[] = 'column-date';
4578 ?>
4579 <td class="<?php esc_attr_e( implode( ' ', $css_classes ) ); ?>" data-colname="<?php echo esc_attr( $attributes['label'] ); ?>">
4580 <abbr title="<?php echo esc_attr( $row_value ); ?>"><?php echo wp_kses_post( $row_value ); ?></abbr>
4581 <?php if ( $first_field && ! in_array( 'toggle_details', $this->actions_disabled, true ) ) { ?>
4582 <button type="button" class="toggle-row">
4583 <span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span>
4584 </button>
4585 <?php } ?>
4586 </td>
4587 <?php
4588 } else {
4589 if ( $first_field ) {
4590 $css_classes[] = 'column-primary';
4591 }
4592
4593 $css_classes[] = 'author';
4594
4595 if ( 'raw' !== $attributes['type'] ) {
4596 // Deal with unexpected array values.
4597 if ( is_array( $row_value ) ) {
4598 if ( empty( $row_value ) ) {
4599 $row_value = '';
4600 } else {
4601 $row_value = pods_serial_comma( $row_value, $attributes );
4602 }
4603 }
4604
4605 $row_value = wp_kses_post( $row_value );
4606 }
4607 ?>
4608 <td class="<?php esc_attr_e( implode( ' ', $css_classes ) ); ?>" data-colname="<?php echo esc_attr( $attributes['label'] ); ?>">
4609 <span>
4610 <?php
4611 /* Escaped above for non-HTML types */
4612 echo $row_value;
4613 ?>
4614 </span>
4615 <?php if ( $first_field && ! in_array( 'toggle_details', $this->actions_disabled, true ) ) { ?>
4616 <button type="button" class="toggle-row">
4617 <span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span>
4618 </button>
4619 <?php } ?>
4620 </td>
4621 <?php
4622 }//end if
4623 $first_field = false;
4624 }//end foreach
4625 ?>
4626 </tr>
4627 <?php
4628 }//end while
4629 }//end if
4630 ?>
4631 </tbody>
4632 </table>
4633 <?php
4634 if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
4635
4636 ?>
4637 </form>
4638 <?php
4639 }
4640 ?>
4641 <script type="text/javascript">
4642 document.addEventListener( 'DOMContentLoaded', function( event ) {
4643 jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
4644 <?php
4645 if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
4646 ?>
4647 jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} );
4648 jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) {
4649 jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' );
4650 jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
4651 } );
4652 <?php
4653 }
4654 ?>
4655 } );
4656 </script>
4657 <?php
4658 }
4659
4660 /**
4661 * Get actions for row.
4662 *
4663 * @param array $row
4664 *
4665 * @return array
4666 */
4667 public function get_actions( $row ) {
4668
4669 $field_id = '';
4670
4671 if ( ! empty( $row[ $this->sql['field_id'] ] ) ) {
4672 $field_id = $row[ $this->sql['field_id'] ];
4673 }
4674
4675 $actions = array();
4676
4677 if ( ! in_array( 'view', $this->actions_disabled ) && ! in_array( 'view', $this->actions_hidden ) ) {
4678 $link = pods_query_arg(
4679 array(
4680 $this->num_prefix . 'action' . $this->num => 'view',
4681 $this->num_prefix . 'id' . $this->num => $field_id,
4682 ), self::$allowed, $this->exclusion()
4683 );
4684
4685 if ( ! empty( $this->action_links['view'] ) ) {
4686 $link = $this->do_template( $this->action_links['view'], $row );
4687 }
4688
4689 $actions['view'] = '<span class="view"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>';
4690 }
4691
4692 if ( ! in_array( 'edit', $this->actions_disabled ) && ! in_array( 'edit', $this->actions_hidden ) && ! $this->restricted( 'edit', $row ) ) {
4693 $link = pods_query_arg(
4694 array(
4695 $this->num_prefix . 'action' . $this->num => 'edit',
4696 $this->num_prefix . 'id' . $this->num => $field_id,
4697 ), self::$allowed, $this->exclusion()
4698 );
4699
4700 if ( ! empty( $this->action_links['edit'] ) ) {
4701 $link = $this->do_template( $this->action_links['edit'], $row );
4702 }
4703
4704 $actions['edit'] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>';
4705 }
4706
4707 if ( ! in_array( 'duplicate', $this->actions_disabled ) && ! in_array( 'duplicate', $this->actions_hidden ) && ! $this->restricted( 'edit', $row ) ) {
4708 $link = pods_query_arg(
4709 array(
4710 $this->num_prefix . 'action' . $this->num => 'duplicate',
4711 $this->num_prefix . 'id' . $this->num => $field_id,
4712 ), self::$allowed, $this->exclusion()
4713 );
4714
4715 if ( ! empty( $this->action_links['duplicate'] ) ) {
4716 $link = $this->do_template( $this->action_links['duplicate'], $row );
4717 }
4718
4719 $actions['duplicate'] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>';
4720 }
4721
4722 if ( ! in_array( 'delete', $this->actions_disabled ) && ! in_array( 'delete', $this->actions_hidden ) && ! $this->restricted( 'delete', $row ) ) {
4723 $link = pods_query_arg(
4724 array(
4725 $this->num_prefix . 'action' . $this->num => 'delete',
4726 $this->num_prefix . 'id' . $this->num => $field_id,
4727 $this->num_prefix . '_wpnonce' . $this->num => wp_create_nonce( 'pods-ui-action-delete-' . $field_id ),
4728 ), self::$allowed, $this->exclusion()
4729 );
4730
4731 if ( ! empty( $this->action_links['delete'] ) ) {
4732 $link = add_query_arg( array( $this->num_prefix . '_wpnonce' . $this->num => wp_create_nonce( 'pods-ui-action-delete-' . $field_id ) ), $this->do_template( $this->action_links['delete'], $row ) );
4733 }
4734
4735 $actions['delete'] = '<span class="delete"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Delete this item', 'pods' ) . '" class="submitdelete" onclick="if(confirm(\'' . esc_attr__( 'You are about to permanently delete this item\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'pods' ) . '\')){return true;}return false;">' . __( 'Delete', 'pods' ) . '</a></span>';
4736 }
4737
4738 if ( is_array( $this->actions_custom ) ) {
4739 foreach ( $this->actions_custom as $custom_action => $custom_data ) {
4740 if ( 'add' !== $custom_action && is_array( $custom_data ) && ( isset( $custom_data['link'] ) || isset( $custom_data['callback'] ) ) && ! in_array( $custom_action, $this->actions_disabled ) && ! in_array( $custom_action, $this->actions_hidden ) ) {
4741 if ( ! in_array(
4742 $custom_action, array(
4743 'add',
4744 'view',
4745 'edit',
4746 'duplicate',
4747 'delete',
4748 'save',
4749 'export',
4750 'reorder',
4751 'manage',
4752 'table',
4753 )
4754 ) ) {
4755 if ( 'toggle' === $custom_action ) {
4756 $toggle = true;
4757 $toggle_labels = array(
4758 __( 'Enable', 'pods' ),
4759 __( 'Disable', 'pods' ),
4760 );
4761
4762 $custom_data['label'] = ( $row['toggle'] ? $toggle_labels[1] : $toggle_labels[0] );
4763 }
4764
4765 if ( ! isset( $custom_data['label'] ) ) {
4766 $custom_data['label'] = ucwords( str_replace( '_', ' ', $custom_action ) );
4767 }
4768
4769 if ( ! isset( $custom_data['link'] ) ) {
4770 $vars = array(
4771 $this->num_prefix . 'action' . $this->num => $custom_action,
4772 $this->num_prefix . 'id' . $this->num => $field_id,
4773 $this->num_prefix . '_wpnonce' . $this->num => wp_create_nonce( 'pods-ui-action-' . $custom_action . '-' . $field_id ),
4774 );
4775
4776 if ( 'toggle' === $custom_action ) {
4777 $vars[ $this->num_prefix . 'toggle' . $this->num ] = (int) ( ! $row['toggle'] );
4778 $vars[ $this->num_prefix . 'toggled' . $this->num ] = 1;
4779 }
4780
4781 $custom_data['link'] = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
4782
4783 if ( isset( $this->action_links[ $custom_action ] ) && ! empty( $this->action_links[ $custom_action ] ) ) {
4784 $custom_data['link'] = add_query_arg( array( $this->num_prefix . '_wpnonce' . $this->num => wp_create_nonce( 'pods-ui-action-' . $custom_action . '-' . $field_id ) ), $this->do_template( $this->action_links[ $custom_action ], $row ) );
4785 }
4786 }
4787
4788 $confirm = '';
4789
4790 if ( isset( $custom_data['confirm'] ) ) {
4791 $confirm = ' onclick="if(confirm(\'' . esc_js( $custom_data['confirm'] ) . '\')){return true;}return false;"';
4792 }
4793
4794 if ( $this->restricted( $custom_action, $row ) ) {
4795 continue;
4796 }
4797
4798 $actions[ $custom_action ] = '<span class="edit action-' . esc_attr( $custom_action ) . '"><a href="' . esc_url( $this->do_template( $custom_data['link'], $row ) ) . '" title="' . esc_attr( $custom_data['label'] ) . ' this item"' . $confirm . '>' . $custom_data['label'] . '</a></span>';
4799 }//end if
4800 }//end if
4801 }//end foreach
4802 }//end if
4803
4804 return $actions;
4805
4806 }
4807
4808 /**
4809 *
4810 */
4811 public function screen_meta() {
4812
4813 $screen_html = '';
4814 $help_html = '';
4815 $screen_link = '';
4816 $help_link = '';
4817 if ( ! empty( $this->screen_options ) && ! empty( $this->help ) ) {
4818 foreach ( $this->ui_page as $page ) {
4819 if ( isset( $this->screen_options[ $page ] ) ) {
4820 if ( is_array( $this->screen_options[ $page ] ) ) {
4821 if ( isset( $this->screen_options[ $page ]['link'] ) ) {
4822 $screen_link = $this->screen_options[ $page ]['link'];
4823 break;
4824 }
4825 } else {
4826 $screen_html = $this->screen_options[ $page ];
4827 break;
4828 }
4829 }
4830 }
4831 foreach ( $this->ui_page as $page ) {
4832 if ( isset( $this->help[ $page ] ) ) {
4833 if ( is_array( $this->help[ $page ] ) ) {
4834 if ( isset( $this->help[ $page ]['link'] ) ) {
4835 $help_link = $this->help[ $page ]['link'];
4836 break;
4837 }
4838 } else {
4839 $help_html = $this->help[ $page ];
4840 break;
4841 }
4842 }
4843 }
4844 }//end if
4845 $screen_html = $this->do_hook( 'screen_meta_screen_html', $screen_html );
4846 $screen_link = $this->do_hook( 'screen_meta_screen_link', $screen_link );
4847 $help_html = $this->do_hook( 'screen_meta_help_html', $help_html );
4848 $help_link = $this->do_hook( 'screen_meta_help_link', $help_link );
4849 if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) || 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
4850 ?>
4851 <div id="screen-meta">
4852 <?php
4853 $this->do_hook( 'screen_meta_pre' );
4854 if ( 0 < strlen( $screen_html ) ) {
4855 ?>
4856 <div id="screen-options-wrap" class="pods-hidden">
4857 <form id="adv-settings" action="" method="post">
4858 <?php
4859 echo $screen_html;
4860 $fields = array();
4861 foreach ( $this->ui_page as $page ) {
4862 if ( isset( $this->fields[ $page ] ) && ! empty( $this->fields[ $page ] ) ) {
4863 $fields = $this->fields[ $page ];
4864 }
4865 }
4866 if ( ! empty( $fields ) || true === $this->pagination ) {
4867 ?>
4868 <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
4869 <?php
4870 if ( ! empty( $fields ) ) {
4871 ?>
4872 <div class="metabox-prefs">
4873 <?php
4874 $this->do_hook( 'screen_meta_screen_options' );
4875 foreach ( $fields as $field => $attributes ) {
4876 if ( false === $attributes['display'] || true === $attributes['hidden'] ) {
4877 continue;
4878 }
4879 ?>
4880 <label for="<?php echo esc_attr( $field ); ?>-hide">
4881 <input class="hide-column-tog" name="<?php echo esc_attr( $this->unique_identifier ); ?>_<?php echo esc_attr( $field ); ?>-hide" type="checkbox" id="<?php echo esc_attr( $field ); ?>-hide" value="<?php echo esc_attr( $field ); ?>" checked="checked"><?php esc_html_e( $attributes['label'] ); ?>
4882 </label>
4883 <?php
4884 }
4885 ?>
4886 <br class="clear">
4887 </div>
4888 <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
4889 <?php
4890 }//end if
4891 ?>
4892 <div class="screen-options">
4893 <?php
4894 if ( true === $this->pagination ) {
4895 ?>
4896 <input type="text" class="screen-per-page" name="wp_screen_options[value]" id="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page" maxlength="3" value="20">
4897 <label for="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page"><?php esc_html_e( sprintf( __( '%s per page', 'pods' ), $this->items ) ); ?></label>
4898 <?php
4899 }
4900 $this->do_hook( 'screen_meta_screen_submit' );
4901 ?>
4902 <input type="submit" name="screen-options-apply" id="screen-options-apply" class="button" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
4903 <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page">
4904 <?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?>
4905 </div>
4906 <?php
4907 }//end if
4908 ?>
4909 </form>
4910 </div>
4911 <?php
4912 }//end if
4913 if ( 0 < strlen( $help_html ) ) {
4914 ?>
4915 <div id="contextual-help-wrap" class="pods-hidden">
4916 <div class="metabox-prefs">
4917 <?php echo $help_html; ?>
4918 </div>
4919 </div>
4920 <?php
4921 }
4922 ?>
4923 <div id="screen-meta-links">
4924 <?php
4925 $this->do_hook( 'screen_meta_links_pre' );
4926 if ( 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
4927 ?>
4928 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
4929 <?php
4930 if ( 0 < strlen( $help_link ) ) {
4931 ?>
4932 <a href="<?php echo esc_url( $help_link ); ?>" class="show-settings">Help</a>
4933 <?php
4934 } else {
4935 ?>
4936 <a href="#contextual-help" id="contextual-help-link" class="show-settings">Help</a>
4937 <?php
4938 }
4939 ?>
4940 </div>
4941 <?php
4942 }
4943 if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) ) {
4944 ?>
4945 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
4946 <?php
4947 if ( 0 < strlen( $screen_link ) ) {
4948 ?>
4949 <a href="<?php echo esc_url( $screen_link ); ?>" class="show-settings">Screen Options</a>
4950 <?php
4951 } else {
4952 ?>
4953 <a href="#screen-options" id="show-settings-link" class="show-settings">Screen Options</a>
4954 <?php
4955 }
4956 ?>
4957 </div>
4958 <?php
4959 }
4960 $this->do_hook( 'screen_meta_links_post' );
4961 ?>
4962 </div>
4963 <?php
4964 $this->do_hook( 'screen_meta_post' );
4965 ?>
4966 </div>
4967 <?php
4968 }//end if
4969 }
4970
4971 /**
4972 * @param bool $header
4973 *
4974 * @return mixed
4975 */
4976 public function pagination( $header = false ) {
4977
4978 if ( false !== $this->callback( 'pagination', $header ) ) {
4979 return null;
4980 }
4981
4982 // Check if we should show the pagination in this location.
4983 if ( $header && 'after' === $this->pagination_location ) {
4984 return null;
4985 } elseif ( ! $header && 'before' === $this->pagination_location ) {
4986 return null;
4987 }
4988
4989 $allowed_query_args = array(
4990 $this->num_prefix . 'limit' . $this->num,
4991 $this->num_prefix . 'orderby' . $this->num,
4992 $this->num_prefix . 'orderby_dir' . $this->num,
4993 $this->num_prefix . 'search' . $this->num,
4994 'filter_*',
4995 $this->num_prefix . 'view' . $this->num,
4996 $this->num_prefix . 'pg' . $this->num,
4997 'page',
4998 'post_type',
4999 'taxonomy',
5000 $this->num_prefix . 'action' . $this->num,
5001 );
5002
5003 $total_pages = ceil( $this->total_found / $this->limit );
5004 $request_uri = pods_query_arg(
5005 array( $this->num_prefix . 'pg' . $this->num => '' ), $allowed_query_args, $this->exclusion()
5006 );
5007
5008 $append = false;
5009
5010 if ( false !== strpos( $request_uri, '?' ) ) {
5011 $append = true;
5012 }
5013
5014 if ( false !== $this->pagination_total && ( $header || 1 != $this->total_found ) ) {
5015 $singular_label = strtolower( $this->item );
5016 $plural_label = strtolower( $this->items );
5017 ?>
5018 <span class="displaying-num"><?php echo number_format_i18n( $this->total_found ) . ' ' . _n( $singular_label, $plural_label, $this->total_found, 'pods' ) . $this->extra['total']; ?></span>
5019 <?php
5020 }
5021
5022 // Check if we need to output a different pagination type.
5023 if ( 'table' !== $this->pagination_type ) {
5024 // This pagination type requires a Pod object.
5025 if ( ! $this->pod instanceof Pods ) {
5026 return null;
5027 }
5028
5029 $pagination_params = array(
5030 'type' => $this->pagination_type,
5031 'page_var' => $this->num_prefix . 'pg' . $this->num,
5032 'format' => "{$this->num_prefix}pg{$this->num}=%#%",
5033 );
5034
5035 // Get global query args.
5036 global $pods_query_args;
5037
5038 // Store current args for reference.
5039 $old_query_args = isset( $pods_query_args ) ? $pods_query_args : null;
5040
5041 // Tell the pagination links what to include/exclude.
5042 $pods_query_args = [
5043 'allowed' => $allowed_query_args,
5044 'excluded' => $this->exclusion(),
5045 ];
5046
5047 echo $this->pod->pagination( $pagination_params );
5048
5049 // Reset global query args.
5050 $pods_query_args = $old_query_args;
5051
5052 return;
5053 }
5054
5055 if ( false !== $this->pagination ) {
5056 if ( 1 < $total_pages ) {
5057 $first_link = esc_url( $request_uri . ( $append ? '&' : '?' ) . $this->num_prefix . 'pg' . $this->num . '=1' );
5058 $prev_link = esc_url( $request_uri . ( $append ? '&' : '?' ) . $this->num_prefix . 'pg' . $this->num . '=' . max( $this->page - 1, 1 ) );
5059 $next_link = esc_url( $request_uri . ( $append ? '&' : '?' ) . $this->num_prefix . 'pg' . $this->num . '=' . min( $this->page + 1, $total_pages ) );
5060 $last_link = esc_url( $request_uri . ( $append ? '&' : '?' ) . $this->num_prefix . 'pg' . $this->num . '=' . $total_pages );
5061
5062 $classes = '';
5063 if ( 1 >= $this->page ) {
5064 $classes .= ' disabled';
5065 }
5066 if ( is_admin() ) {
5067 $classes .= ' button';
5068 }
5069 ?>
5070 <a class="first-page<?php echo esc_attr( $classes ); ?>" title="<?php esc_attr_e( 'Go to the first page', 'pods' ); ?>" href="<?php echo $first_link; ?>">&laquo;</a>
5071 <a class="prev-page<?php echo esc_attr( $classes ); ?>" title="<?php esc_attr_e( 'Go to the previous page', 'pods' ); ?>" href="<?php echo $prev_link; ?>">&lsaquo;</a>
5072 <?php
5073 if ( true == $header ) {
5074 ?>
5075 <span class="paging-input"><input class="current-page" title="<?php esc_attr_e( 'Current page', 'pods' ); ?>" type="text" name="<?php echo esc_attr( $this->num_prefix ); ?>pg<?php echo esc_attr( $this->num ); ?>" value="<?php esc_attr_e( absint( $this->page ) ); ?>" size="<?php esc_attr_e( strlen( $total_pages ) ); ?>"> <?php _e( 'of', 'pods' ); ?>
5076 <span class="total-pages"><?php echo absint( $total_pages ); ?></span></span>
5077 <script type="text/javascript">
5078 document.addEventListener( 'DOMContentLoaded', function( event ) {
5079 var pageInput = jQuery( 'input.current-page' );
5080 var currentPage = pageInput.val();
5081 pageInput.closest( 'form' ).submit( function ( e ) {
5082 if ( ( 1 > jQuery( 'select[name="<?php echo esc_attr( $this->num_prefix ); ?>action<?php echo esc_attr( $this->num ); ?>"]' ).length || jQuery( 'select[name="<?php echo esc_attr( $this->num_prefix ); ?>action<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 ) && ( 1 > jQuery( 'select[name="<?php echo esc_attr( $this->num_prefix ); ?>action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).length || jQuery( 'select[name="<?php echo esc_attr( $this->num_prefix ); ?>action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 ) && pageInput.val() == currentPage ) {
5083 pageInput.val( '1' );
5084 }
5085 } );
5086 } );
5087 </script>
5088 <?php
5089 } else {
5090 ?>
5091 <span class="paging-input"><?php echo absint( $this->page ); ?> <?php _e( 'of', 'pods' ); ?>
5092 <span class="total-pages"><?php echo number_format_i18n( $total_pages ); ?></span></span>
5093 <?php
5094 }//end if
5095 $classes = '';
5096 if ( $this->page >= $total_pages ) {
5097 $classes .= ' disabled';
5098 }
5099 if ( is_admin() ) {
5100 $classes .= ' button';
5101 }
5102 ?>
5103 <a class="next-page<?php echo esc_attr( $classes ); ?>" title="<?php esc_attr_e( 'Go to the next page', 'pods' ); ?>" href="<?php echo $next_link; ?>">&rsaquo;</a>
5104 <a class="last-page<?php echo esc_attr( $classes ); ?>" title="<?php esc_attr_e( 'Go to the last page', 'pods' ); ?>" href="<?php echo $last_link; ?>">&raquo</a>
5105 <?php
5106 }//end if
5107 }//end if
5108 }
5109
5110 /**
5111 * @param bool $options
5112 *
5113 * @return mixed
5114 */
5115 public function limit( $options = false ) {
5116
5117 if ( false !== $this->callback( 'limit', $options ) ) {
5118 return null;
5119 }
5120
5121 if ( false === $options || ! is_array( $options ) || empty( $options ) ) {
5122 $options = array( 10, 25, 50, 100, 200 );
5123 }
5124
5125 if ( ! in_array( $this->limit, $options ) && - 1 != $this->limit ) {
5126 $this->limit = $options[1];
5127 }
5128
5129 foreach ( $options as $option ) {
5130 if ( $option == $this->limit ) {
5131 echo ' <span class="page-numbers current">' . esc_html( $option ) . '</span>';
5132 } else {
5133 echo ' <a href="' . esc_url(
5134 pods_query_arg(
5135 array( 'limit' => $option ), array(
5136 $this->num_prefix . 'orderby' . $this->num,
5137 $this->num_prefix . 'orderby_dir' . $this->num,
5138 $this->num_prefix . 'search' . $this->num,
5139 'filter_*',
5140 'page',
5141 ), $this->exclusion()
5142 )
5143 ) . '">' . esc_html( $option ) . '</a>';
5144 }
5145 }
5146 }
5147
5148 /**
5149 * @param $code
5150 * @param bool|array $row
5151 *
5152 * @return mixed
5153 */
5154 public function do_template( $code, $row = false ) {
5155
5156 if ( is_object( $this->pod ) && 1 == 0 && 0 < $this->pod->id() ) {
5157 return $this->pod->do_magic_tags( $code );
5158 } else {
5159 if ( false !== $row ) {
5160 $this->temp_row = $this->row;
5161 $this->row = $row;
5162 }
5163
5164 $code = preg_replace_callback( '/({@(.*?)})/m', array( $this, 'do_magic_tags' ), $code );
5165
5166 if ( false !== $row ) {
5167 $this->row = $this->temp_row;
5168 unset( $this->temp_row );
5169 }
5170 }
5171
5172 return $code;
5173 }
5174
5175 /**
5176 * @param $tag
5177 *
5178 * @return string
5179 */
5180 public function do_magic_tags( $tag ) {
5181
5182 if ( is_array( $tag ) ) {
5183 if ( ! isset( $tag[2] ) && strlen( trim( $tag[2] ) ) < 1 ) {
5184 return '';
5185 }
5186
5187 $tag = $tag[2];
5188 }
5189
5190 $tag = trim( $tag, ' {@}' );
5191 $tag = explode( ',', $tag );
5192
5193 if ( empty( $tag ) || ! isset( $tag[0] ) || strlen( trim( $tag[0] ) ) < 1 ) {
5194 return null;
5195 }
5196
5197 foreach ( $tag as $k => $v ) {
5198 $tag[ $k ] = trim( $v );
5199 }
5200
5201 $field_name = $tag[0];
5202
5203 $value = $this->get_field( $field_name );
5204
5205 if ( isset( $tag[1] ) && ! empty( $tag[1] ) && is_callable( $tag[1] ) ) {
5206 $value = call_user_func_array( $tag[1], array( $value, $field_name, $this->row, &$this ) );
5207 }
5208
5209 $before = '';
5210 $after = '';
5211
5212 if ( isset( $tag[2] ) && ! empty( $tag[2] ) ) {
5213 $before = $tag[2];
5214 }
5215
5216 if ( isset( $tag[3] ) && ! empty( $tag[3] ) ) {
5217 $after = $tag[3];
5218 }
5219
5220 if ( 0 < strlen( $value ) ) {
5221 return $before . $value . $after;
5222 }
5223
5224 return null;
5225 }
5226
5227 /**
5228 * @param bool|array $exclude
5229 * @param bool|array $array
5230 */
5231 public function hidden_vars( $exclude = false, $array = false ) {
5232
5233 $exclude = $this->do_hook( 'hidden_vars', $exclude, $array );
5234 if ( false === $exclude ) {
5235 $exclude = array();
5236 }
5237 if ( ! is_array( $exclude ) ) {
5238 $exclude = explode( ',', $exclude );
5239 }
5240 $get = $_GET;
5241 if ( is_array( $array ) ) {
5242 foreach ( $array as $key => $val ) {
5243 if ( 0 < strlen( $val ) ) {
5244 $get[ $key ] = $val;
5245 } else {
5246 unset( $get[ $key ] );
5247 }
5248 }
5249 }
5250 foreach ( $get as $k => $v ) {
5251 if ( in_array( $k, $exclude, true ) ) {
5252 continue;
5253 }
5254
5255 if ( is_array( $v ) ) {
5256 foreach ( $v as $vk => $vv ) {
5257 ?>
5258 <input type="hidden" name="<?php echo esc_attr( $k ); ?>[<?php echo esc_attr( $vk ); ?>]" value="<?php echo esc_attr( $vv ); ?>" />
5259 <?php
5260 }
5261 } else {
5262 ?>
5263 <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
5264 <?php
5265 }
5266 }
5267 }
5268
5269 /**
5270 * @return array
5271 */
5272 public function exclusion() {
5273
5274 $exclusion = self::$excluded;
5275
5276 foreach ( $exclusion as $k => $exclude ) {
5277 $exclusion[ $k ] = $this->num_prefix . $exclude . $this->num;
5278 }
5279
5280 return $exclusion;
5281 }
5282
5283 /**
5284 * @param string $action
5285 * @param null $row
5286 *
5287 * @return bool
5288 */
5289 public function restricted( $action = 'edit', $row = null ) {
5290
5291 $restricted = false;
5292
5293 $restrict = array();
5294
5295 if ( isset( $this->restrict[ $action ] ) ) {
5296 $restrict = (array) $this->restrict[ $action ];
5297 }
5298
5299 // @todo Build 'edit', 'duplicate', 'delete' action support for 'where' which runs another find() query
5300 /*
5301 if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) {
5302 $where = pods_var_raw( $action, $this->where, null, null, true );
5303
5304 if ( !empty( $where ) ) {
5305 $restricted = true;
5306
5307 $old_where = $this->where[ $action ];
5308
5309 $id = $this->row[ $this->sql[ 'field_id' ] ];
5310
5311 if ( is_array( $where ) ) {
5312 if ( 'OR' == pods_var( 'relation', $where ) )
5313 $where = array( $where );
5314
5315 $where[] = "`t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
5316 }
5317 else
5318 $where = "( {$where} ) AND `t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
5319
5320 $this->where[ $action ] = $where;
5321
5322 $data = false;
5323
5324 //$data = $this->get_data();
5325
5326 $this->where[ $action ] = $old_where;
5327
5328 if ( empty( $data ) )
5329 $restricted = true;
5330 }
5331 }*/
5332
5333 $author_restrict = false;
5334
5335 if ( ! empty( $this->restrict['author_restrict'] ) && $restrict === $this->restrict['author_restrict'] ) {
5336 $restricted = false;
5337 $author_restrict = true;
5338
5339 if ( is_object( $this->pod ) ) {
5340 $restricted = true;
5341
5342 if ( 'settings' === $this->pod->pod_data['type'] && 'add' === $action ) {
5343 $action = 'edit';
5344 }
5345
5346 if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) {
5347 $restricted = false;
5348 } else {
5349 // Disable legacy check.
5350 $author_restrict = false;
5351
5352 $pod = $this->pod;
5353 if ( ! $pod->id() && $row ) {
5354 $pod->fetch( $row );
5355 }
5356
5357 // Check if the current user is the author of this item.
5358 $author = $pod->field( 'author', true );
5359 $is_author = false;
5360 if ( $author && (int) wp_get_current_user()->ID === (int) pods_v( 'ID', $author, 0 ) ) {
5361 $is_author = true;
5362 }
5363
5364 $cap_actions = array( $action );
5365 if ( 'manage' === $action || 'reorder' === $action ) {
5366 if ( ! in_array( 'edit', $this->actions_disabled, true ) ) {
5367 $cap_actions[] = 'edit';
5368 }
5369 if ( ! in_array( 'delete', $this->actions_disabled, true ) ) {
5370 $cap_actions[] = 'delete';
5371 }
5372 }
5373
5374 foreach ( $cap_actions as $cap ) {
5375 if ( $is_author ) {
5376 // Only need regular capability.
5377 if ( current_user_can( 'pods_' . $cap . '_' . $this->pod->pod ) ) {
5378 $restricted = false;
5379 break;
5380 }
5381 } else {
5382 // This item is created by another user so the "others" capability is required as well.
5383 if (
5384 current_user_can( 'pods_' . $cap . '_' . $this->pod->pod ) &&
5385 current_user_can( 'pods_' . $cap . '_others_' . $this->pod->pod )
5386 ) {
5387 $restricted = false;
5388 break;
5389 }
5390 }
5391 }
5392 }
5393
5394 }//end if
5395
5396 }//end if
5397
5398 if ( $restricted && ! empty( $restrict ) ) {
5399 $relation = strtoupper( trim( pods_v( 'relation', $restrict, 'AND', null, true ) ) );
5400
5401 if ( 'AND' !== $relation ) {
5402 $relation = 'OR';
5403 }
5404
5405 $okay = true;
5406
5407 foreach ( $restrict as $field => $match ) {
5408 if ( 'relation' === $field ) {
5409 continue;
5410 }
5411
5412 if ( is_array( $match ) ) {
5413 $match_okay = true;
5414
5415 $match_relation = strtoupper( trim( pods_v( 'relation', $match, 'OR', null, true ) ) );
5416
5417 if ( 'AND' !== $match_relation ) {
5418 $match_relation = 'OR';
5419 }
5420
5421 foreach ( $match as $the_field => $the_match ) {
5422 if ( 'relation' === $the_field ) {
5423 continue;
5424 }
5425
5426 $value = null;
5427
5428 if ( is_object( $this->pod ) ) {
5429 $value = $this->pod->field( $the_match, true );
5430 } else {
5431 if ( empty( $row ) ) {
5432 $row = $this->row;
5433 }
5434
5435 if ( isset( $row[ $the_match ] ) ) {
5436 if ( is_array( $row[ $the_match ] ) ) {
5437 if ( false !== strpos( $the_match, '.' ) ) {
5438 $the_matches = explode( '.', $the_match );
5439
5440 $value = $row[ $the_match ];
5441
5442 foreach ( $the_matches as $m ) {
5443 if ( is_array( $value ) && isset( $value[ $m ] ) ) {
5444 $value = $value[ $m ];
5445 } else {
5446 $value = null;
5447
5448 break;
5449 }
5450 }
5451 }
5452 } else {
5453 $value = $row[ $the_match ];
5454 }
5455 }//end if
5456 }//end if
5457
5458 if ( is_array( $value ) ) {
5459 if ( ! in_array( $the_match, $value ) ) {
5460 $match_okay = false;
5461 } elseif ( 'OR' === $match_relation ) {
5462 $match_okay = true;
5463
5464 break;
5465 }
5466 } elseif ( $value == $the_match ) {
5467 $match_okay = false;
5468 } elseif ( 'OR' === $match_relation ) {
5469 $match_okay = true;
5470
5471 break;
5472 }
5473 }//end foreach
5474
5475 if ( ! $match_okay ) {
5476 $okay = false;
5477 }
5478 if ( 'OR' === $relation ) {
5479 $okay = true;
5480
5481 break;
5482 }
5483 } else {
5484 $value = null;
5485
5486 if ( is_object( $this->pod ) ) {
5487 $value = $this->pod->field( $match, true );
5488 } else {
5489 if ( empty( $row ) ) {
5490 $row = $this->row;
5491 }
5492
5493 if ( isset( $row[ $match ] ) ) {
5494 if ( is_array( $row[ $match ] ) ) {
5495 if ( false !== strpos( $match, '.' ) ) {
5496 $matches = explode( '.', $match );
5497
5498 $value = $row[ $match ];
5499
5500 foreach ( $matches as $m ) {
5501 if ( is_array( $value ) && isset( $value[ $m ] ) ) {
5502 $value = $value[ $m ];
5503 } else {
5504 $value = null;
5505
5506 break;
5507 }
5508 }
5509 }
5510 } else {
5511 $value = $row[ $match ];
5512 }
5513 }//end if
5514 }//end if
5515
5516 if ( is_array( $value ) ) {
5517 if ( ! in_array( $match, $value ) ) {
5518 $okay = false;
5519 } elseif ( 'OR' === $relation ) {
5520 $okay = true;
5521
5522 break;
5523 }
5524 } elseif ( $value != $match ) {
5525 $okay = false;
5526 } elseif ( 'OR' === $relation ) {
5527 $okay = true;
5528
5529 break;
5530 }
5531 }//end if
5532 }//end foreach
5533
5534 // Legacy author restrict check.
5535 if ( $author_restrict && ! $okay && ! empty( $row ) ) {
5536 foreach ( $this->restrict['author_restrict'] as $key => $val ) {
5537 $author_restricted = $this->get_field( $key );
5538
5539 if ( ! empty( $author_restricted ) ) {
5540 if ( ! is_array( $author_restricted ) ) {
5541 $author_restricted = (array) $author_restricted;
5542 }
5543 $author_restricted = array_map( 'intval', $author_restricted );
5544
5545 if ( is_array( $val ) ) {
5546 foreach ( $val as $v ) {
5547 if ( in_array( (int) $v, $author_restricted, true ) ) {
5548 $restricted = false;
5549 }
5550 }
5551 } elseif ( in_array( (int) $val, $author_restricted, true ) ) {
5552 $restricted = false;
5553 }
5554 }
5555 }//end foreach
5556 }//end if
5557
5558 if ( $okay ) {
5559 $restricted = false;
5560 }
5561 }//end if
5562
5563 if (
5564 isset( $this->actions_custom[ $action ]['restrict_callback'] )
5565 && is_callable( $this->actions_custom[ $action ]['restrict_callback'] )
5566 ) {
5567 $restricted = call_user_func( $this->actions_custom[ $action ]['restrict_callback'], $restricted, $restrict, $action, $row, $this );
5568 }
5569
5570 $restricted = $this->do_hook( 'restricted_' . $action, $restricted, $restrict, $action, $row );
5571
5572 return $restricted;
5573 }
5574
5575 /**
5576 * Normalize and get the field data from a field.
5577 *
5578 * @since 2.7.28
5579 *
5580 * @param string|array $field The field data.
5581 *
5582 * @return array|false The field data or false if invalid / not found.
5583 */
5584 public function get_field_data( $field, $which = 'manage' ) {
5585 $field_data = $field;
5586
5587 if ( ! is_array( $field_data ) ) {
5588 // Field is not set.
5589 if ( ! isset( $this->fields[ $which ][ $field ] ) ) {
5590 return false;
5591 }
5592
5593 $field_data = $this->fields[ $which ][ $field ];
5594 } elseif ( ! isset( $field_data['name'] ) ) {
5595 // Field name is required.
5596 return false;
5597 }
5598
5599 return $field_data;
5600 }
5601
5602 /**
5603 * Determine whether a field is searchable.
5604 *
5605 * @since 2.7.28
5606 *
5607 * @param string|array $field The field data.
5608 *
5609 * @return bool Whether a field is searchable.
5610 */
5611 public function is_field_searchable( $field ) {
5612 $field_data = $this->get_field_data( $field );
5613
5614 // Field not valid.
5615 if ( ! $field_data ) {
5616 return false;
5617 }
5618
5619 $field = $field_data['name'];
5620
5621 // Provided as a search field.
5622 if ( isset( $this->fields['search'][ $field ] ) ) {
5623 return true;
5624 }
5625
5626 // Search is turned on individually and we don't have a list of search-only fields.
5627 return ! empty( $field_data['options']['search'] ) && empty( $this->fields['search'] );
5628 }
5629
5630 /**
5631 * Determine whether a field is sortable.
5632 *
5633 * @since 2.7.28
5634 *
5635 * @param string|array $field The field data.
5636 *
5637 * @return bool Whether a field is sortable.
5638 */
5639 public function is_field_sortable( $field ) {
5640 $field_data = $this->get_field_data( $field );
5641
5642 // Field not valid.
5643 if ( ! $field_data ) {
5644 return false;
5645 }
5646
5647 $field = $field_data['name'];
5648
5649 // Provided as a sort field.
5650 if ( isset( $this->fields['sort'][ $field ] ) ) {
5651 return true;
5652 }
5653
5654 // Sort is turned on individually and we don't have a list of sort-only fields.
5655 return ! empty( $field_data['sortable'] ) && empty( $this->fields['sort'] );
5656 }
5657
5658 /**
5659 * Check for a custom action callback and run it
5660 *
5661 * @return bool|mixed
5662 */
5663 public function callback() {
5664
5665 $args = func_get_args();
5666
5667 if ( empty( $args ) ) {
5668 return false;
5669 }
5670
5671 $action = array_shift( $args );
5672
5673 // Do hook
5674 $callback_args = $args;
5675 array_unshift( $callback_args, null );
5676 array_unshift( $callback_args, $action );
5677
5678 $callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
5679
5680 if ( null === $callback ) {
5681 $callback = false;
5682 }
5683
5684 $args[] = $this;
5685
5686 if ( isset( $this->actions_custom[ $action ] ) ) {
5687 if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ]['callback'] ) && is_callable( $this->actions_custom[ $action ]['callback'] ) ) {
5688 $callback = call_user_func_array( $this->actions_custom[ $action ]['callback'], $args );
5689 } elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
5690 $callback = call_user_func_array( $this->actions_custom[ $action ], $args );
5691 }
5692 }
5693
5694 return $callback;
5695
5696 }
5697
5698 /**
5699 * Check for a custom action callback and run it (deprecated reverse arg order)
5700 *
5701 * @return bool|mixed
5702 */
5703 public function callback_action() {
5704
5705 $args = func_get_args();
5706
5707 if ( empty( $args ) ) {
5708 return false;
5709 }
5710
5711 $action = array_shift( $args );
5712
5713 $deprecated = false;
5714
5715 if ( is_bool( $action ) ) {
5716 $deprecated = $action;
5717
5718 $action = array_shift( $args );
5719 }
5720
5721 // Do hook
5722 $callback_args = $args;
5723 array_unshift( $callback_args, null );
5724 array_unshift( $callback_args, 'action_' . $action );
5725
5726 $callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
5727
5728 if ( null === $callback ) {
5729 $callback = false;
5730 }
5731
5732 $args[] = $this;
5733
5734 // Deprecated reverse arg order
5735 if ( $deprecated ) {
5736 $args = array_reverse( $args );
5737 }
5738
5739 if ( isset( $this->actions_custom[ $action ] ) ) {
5740 if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ]['callback'] ) && is_callable( $this->actions_custom[ $action ]['callback'] ) ) {
5741 $callback = call_user_func_array( $this->actions_custom[ $action ]['callback'], $args );
5742 } elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
5743 $callback = call_user_func_array( $this->actions_custom[ $action ], $args );
5744 }
5745 }
5746
5747 return $callback;
5748
5749 }
5750
5751 /**
5752 * Check for a bulk action callback and run it
5753 *
5754 * @return bool|mixed Callback result
5755 */
5756 public function callback_bulk() {
5757
5758 $args = func_get_args();
5759
5760 if ( empty( $args ) ) {
5761 return false;
5762 }
5763
5764 $action = array_shift( $args );
5765
5766 $deprecated = false;
5767
5768 if ( is_bool( $action ) ) {
5769 $deprecated = $action;
5770
5771 $action = array_shift( $args );
5772 }
5773
5774 // Do hook
5775 $callback_args = $args;
5776 array_unshift( $callback_args, null );
5777 array_unshift( $callback_args, 'bulk_action_' . $action );
5778
5779 $callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
5780
5781 if ( null === $callback ) {
5782 $callback = false;
5783 }
5784
5785 $args[] = $this;
5786
5787 // Deprecated reverse arg order
5788 if ( $deprecated ) {
5789 $args = array_reverse( $args );
5790 }
5791
5792 if ( isset( $this->actions_bulk[ $action ] ) ) {
5793 if ( is_array( $this->actions_bulk[ $action ] ) && isset( $this->actions_bulk[ $action ]['callback'] ) && is_callable( $this->actions_bulk[ $action ]['callback'] ) ) {
5794 $callback = call_user_func_array( $this->actions_bulk[ $action ]['callback'], $args );
5795 } elseif ( is_callable( $this->actions_bulk[ $action ] ) ) {
5796 $callback = call_user_func_array( $this->actions_bulk[ $action ], $args );
5797 }
5798 }
5799
5800 return $callback;
5801
5802 }
5803
5804 /*
5805 // Example code for use with $this->do_hook
5806 public function my_filter_function ($args, $obj) {
5807 $obj[0]->item = 'Post';
5808 $obj[0]->add = true;
5809 // args are an array (0 => $arg1, 1 => $arg2)
5810 // may have more than one arg, dependant on filter
5811 return $args;
5812 }
5813 add_filter('pods_ui_post_init', 'my_filter_function', 10, 2);
5814 */
5815 /**
5816 * @return array|bool|mixed|null
5817 */
5818 private function do_hook() {
5819
5820 $args = func_get_args();
5821
5822 if ( empty( $args ) ) {
5823 return false;
5824 }
5825
5826 $name = array_shift( $args );
5827
5828 return pods_do_hook( 'ui', $name, $args, $this );
5829
5830 }
5831 }
5832