Completed
Pull Request — 2.x (#4569)
by Scott Kingsley
08:49
created

PodsUI::limit()   D

Complexity

Conditions 9
Paths 13

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
dl 0
loc 32
rs 4.909
c 0
b 0
f 0
eloc 21
nc 13
nop 1
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();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $x. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
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
	 * @var string
59
	 */
60
	public $num = '';
61
	// allows multiple co-existing PodsUI instances with separate functionality in URL
62
	/**
63
	 * @var array
64
	 */
65
	public static $excluded = array(
66
		'do',
67
		'id',
68
		'pg',
69
		'search',
70
		'filter_*',
71
		'orderby',
72
		'orderby_dir',
73
		'limit',
74
		'action',
75
		'action_bulk',
76
		'action_bulk_ids',
77
		'_wpnonce',
78
		'view',
79
		'export',
80
		'export_type',
81
		'export_delimiter',
82
		'remove_export',
83
		'updated',
84
		'duplicate',
85
		'message',
86
	);
87
	// used in var_update
88
	public static $allowed = array(
89
		'page',
90
		'post_type',
91
	);
92
93
	// ui
94
	/**
95
	 * @var bool
96
	 */
97
	public $item = false;
98
	// to be set with localized string
99
	/**
100
	 * @var bool
101
	 */
102
	public $items = false;
103
	// to be set with localized string
104
	/**
105
	 * @var bool
106
	 */
107
	public $heading = false;
108
	// to be set with localized string array
109
	/**
110
	 * @var bool
111
	 */
112
	public $header = false;
113
	// to be set with localized string array
114
	/**
115
	 * @var bool
116
	 */
117
	public $label = false;
118
	// to be set with localized string array
119
	/**
120
	 * @var bool
121
	 */
122
	public $icon = false;
123
124
	/**
125
	 * @var bool
126
	 */
127
	public $css = false;
128
	// set to a URL of stylesheet to include
129
	/**
130
	 * @var bool
131
	 */
132
	public $wpcss = false;
133
	// set to true to include WP Admin stylesheets
134
	/**
135
	 * @var array
136
	 */
137
	public $fields = array(
138
		'manage'    => array(),
139
		'search'    => array(),
140
		'form'      => array(),
141
		'add'       => array(),
142
		'edit'      => array(),
143
		'duplicate' => array(),
144
		'view'      => array(),
145
		'reorder'   => array(),
146
		'export'    => array(),
147
	);
148
149
	/**
150
	 * @var bool
151
	 */
152
	public $searchable = true;
153
154
	/**
155
	 * @var bool
156
	 */
157
	public $sortable = true;
158
159
	/**
160
	 * @var bool
161
	 */
162
	public $pagination = true;
163
164
	/**
165
	 * @var bool
166
	 */
167
	public $pagination_total = true;
168
169
	/**
170
	 * @var array
171
	 */
172
	public $export = array(
173
		'on'      => false,
174
		'formats' => array(
175
			'csv'  => ',',
176
			'tsv'  => "\t",
177
			'xml'  => false,
178
			'json' => false,
179
		),
180
		'url'     => false,
181
		'type'    => false,
182
	);
183
184
	/**
185
	 * @var array
186
	 */
187
	public $reorder = array(
188
		'on'          => false,
189
		'limit'       => 250,
190
		'orderby'     => false,
191
		'orderby_dir' => 'ASC',
192
		'sql'         => null,
193
	);
194
195
	/**
196
	 * @var array
197
	 */
198
	public $screen_options = array();
199
	// set to 'page' => 'Text'; false hides link
200
	/**
201
	 * @var array
202
	 */
203
	public $help = array();
204
	// set to 'page' => 'Text'; 'page' => array('link' => 'yourhelplink'); false hides link
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
205
	// data
206
	/**
207
	 * @var bool
208
	 */
209
	public $search = false;
210
211
	/**
212
	 * @var bool
213
	 */
214
	public $filters_enhanced = false;
215
216
	/**
217
	 * @var array
218
	 */
219
	public $filters = array();
220
221
	/**
222
	 * @var string
223
	 */
224
	public $view = false;
225
226
	/**
227
	 * @var array
228
	 */
229
	public $views = array();
230
231
	/**
232
	 * @var bool
233
	 */
234
	public $search_across = true;
235
236
	/**
237
	 * @var bool
238
	 */
239
	public $search_across_picks = false;
240
241
	/**
242
	 * @var bool
243
	 */
244
	public $default_none = false;
245
246
	/**
247
	 * @var array
248
	 */
249
	public $where = array(
250
		'manage'  => null,
251
		/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
252
		'edit' => null,
253
        'duplicate' => null,
254
        'delete' => null,*/
255
		'reorder' => null,
256
	);
257
258
	/**
259
	 * @var bool
260
	 */
261
	public $orderby = false;
262
263
	/**
264
	 * @var string
265
	 */
266
	public $orderby_dir = 'DESC';
267
268
	/**
269
	 * @var int
270
	 */
271
	public $limit = 25;
272
273
	/**
274
	 * @var int
275
	 */
276
	public $page = 1;
277
278
	/**
279
	 * @var int
280
	 */
281
	public $total = 0;
282
283
	/**
284
	 * @var int
285
	 */
286
	public $total_found = 0;
287
288
	/**
289
	 * @var array
290
	 */
291
	public $session = array(
292
		'search',
293
		'filters',
294
	);
295
	// allowed: search, filters, show_per_page, orderby (priority over usermeta)
296
	/**
297
	 * @var array
298
	 */
299
	public $user = array(
300
		'show_per_page',
301
		'orderby',
302
	);
303
	// allowed: search, filters, show_per_page, orderby (priority under session)
304
	// advanced data
305
	/**
306
	 * @var array
307
	 */
308
	public $sql = array(
309
		'table'       => null,
310
		'field_id'    => 'id',
311
		'field_index' => 'name',
312
		'select'      => null,
313
		'sql'         => null,
314
	);
315
316
	/**
317
	 * @var array
318
	 */
319
	public $params = array();
320
321
	/**
322
	 * @var bool|array
323
	 */
324
	public $data = false;
325
326
	/**
327
	 * @var bool|array
328
	 */
329
	public $data_full = false;
330
331
	/**
332
	 * @var array
333
	 */
334
	public $data_keys = array();
335
336
	/**
337
	 * @var array
338
	 */
339
	public $row = array();
340
341
	// actions
342
	/**
343
	 * @var string
344
	 */
345
	public $action = 'manage';
346
347
	/**
348
	 * @var string
349
	 */
350
	public $action_bulk = false;
351
352
	/**
353
	 * @var array
354
	 */
355
	public $bulk = array();
356
357
	/**
358
	 * @var array
359
	 */
360
	public $action_after = array(
361
		'add'       => 'edit',
362
		'edit'      => 'edit',
363
		'duplicate' => 'edit',
364
	);
365
	// set action to 'manage'
366
	/**
367
	 * @var bool
368
	 */
369
	public $do = false;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $do. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
370
371
	/**
372
	 * @var array
373
	 */
374
	public $action_links = array(
375
		'manage'    => null,
376
		'add'       => null,
377
		'edit'      => null,
378
		'duplicate' => null,
379
		'view'      => null,
380
		'delete'    => null,
381
		'reorder'   => null,
382
	);
383
	// custom links (ex. /my-link/{@id}/
384
	/**
385
	 * @var array
386
	 */
387
	public $actions_disabled = array(
388
		'view',
389
		'export',
390
	);
391
	// disable actions
392
	/**
393
	 * @var array
394
	 */
395
	public $actions_hidden = array();
396
	// hide actions to not show them but allow them
397
	/**
398
	 * @var array
399
	 */
400
	public $actions_custom = array();
401
	// overwrite existing actions or add your own
402
	/**
403
	 * @var array
404
	 */
405
	public $actions_bulk = array();
406
	// enabled bulk actions
407
	/**
408
	 * @var array
409
	 */
410
	public $restrict = array(
411
		'manage'          => null,
412
		'edit'            => null,
413
		'duplicate'       => null,
414
		'delete'          => null,
415
		'reorder'         => null,
416
		'author_restrict' => null,
417
	);
418
419
	/**
420
	 * @var array
421
	 */
422
	public $extra = array(
423
		'total' => null,
424
	);
425
426
	/**
427
	 * @var string
428
	 */
429
	public $style = 'post_type';
430
431
	/**
432
	 * @var bool
433
	 */
434
	public $save = false;
435
	// Allow custom save handling for tables that aren't Pod-based
436
	/**
437
	 * Generate UI for Data Management
438
	 *
439
	 * @param mixed $options    Object, Array, or String containing Pod or Options to be used
440
	 * @param bool  $deprecated Set to true to support old options array from Pods UI plugin
441
	 *
442
	 * @return \PodsUI
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
443
	 *
444
	 * @license http://www.gnu.org/licenses/gpl-2.0.html
445
	 * @since   2.0
446
	 */
447
	public function __construct( $options, $deprecated = false ) {
448
449
		$this->_nonce = pods_v( '_wpnonce', 'request' );
450
451
		$object = null;
452
453
		if ( is_object( $options ) ) {
454
			$object  = $options;
455
			$options = array();
456
457
			if ( isset( $object->ui ) ) {
458
				$options = (array) $object->ui;
459
460
				unset( $object->ui );
461
			}
462
463
			if ( is_object( $object ) && ( 'Pods' == get_class( $object ) || 'Pod' == get_class( $object ) ) ) {
464
				$this->pod =& $object;
465
			}
466
		}
467
468
		if ( ! is_array( $options ) ) {
469
			// @todo need to come back to this and allow for multi-dimensional strings
470
			// like: option=value&option2=value2&option3=key[val],key2[val2]&option4=this,that,another
471
			if ( false !== strpos( $options, '=' ) || false !== strpos( $options, '&' ) ) {
472
				parse_str( $options, $options );
473
			} else {
474
				$options = array( 'pod' => $options );
475
			}
476
		}
477
478
		if ( ! is_object( $object ) && isset( $options['pod'] ) ) {
479
			if ( is_object( $options['pod'] ) ) {
480
				$this->pod = $options['pod'];
481
			} elseif ( isset( $options['id'] ) ) {
482
				$this->pod = pods( $options['pod'], $options['id'] );
483
			} else {
484
				$this->pod = pods( $options['pod'] );
485
			}
486
487
			unset( $options['pod'] );
488
		} elseif ( is_object( $object ) ) {
489
			$this->pod = $object;
490
		}
491
492
		if ( false !== $deprecated || ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) ) ) {
493
			$options = $this->setup_deprecated( $options );
494
		}
495
496
		if ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) && is_object( $this->pod->_data ) ) {
0 ignored issues
show
Documentation introduced by
The property _data does not exist on object<Pod>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
497
			$this->pods_data =& $this->pod->_data;
0 ignored issues
show
Documentation introduced by
The property _data does not exist on object<Pod>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
498
		} elseif ( is_object( $this->pod ) && 'Pods' == get_class( $this->pod ) && is_object( $this->pod->data ) ) {
499
			$this->pods_data =& $this->pod->data;
500
		} elseif ( is_object( $this->pod ) ) {
501
			$this->pods_data = pods_data( $this->pod->pod );
502
		} elseif ( ! is_object( $this->pod ) ) {
503
			$this->pods_data = pods_data( $this->pod );
504
		}
505
506
		$options = $this->do_hook( 'pre_init', $options );
507
508
		$this->setup( $options );
509
510
		if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id ) {
511
			if ( $this->id != $this->pods_data->id ) {
512
				$this->row = $this->pods_data->fetch( $this->id );
513
			} else {
514
				$this->row = $this->pods_data->row;
515
			}
516
		}
517
518
		if ( ( ! is_object( $this->pod ) || 'Pods' != get_class( $this->pod ) ) && false === $this->sql['table'] && false === $this->data ) {
519
			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' ) );
520
521
			return false;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
522
		}
523
524
		// Assign pod labels
525
		// @todo This is also done in setup(), maybe a better / more central way?
526
		if ( is_object( $this->pod ) && ! empty( $this->pod->pod_data['options'] ) ) {
527
			$pod_options = $this->pod->pod_data['options'];
528
			$pod_options = apply_filters( 'pods_advanced_content_type_pod_data_' . $this->pod->pod_data['name'], $pod_options, $this->pod->pod_data['name'] );
529
			$pod_options = apply_filters( 'pods_advanced_content_type_pod_data', $pod_options, $this->pod->pod_data['name'] );
530
531
			$this->label = array_merge( $this->label, $pod_options );
532
		}
533
534
		$this->go();
535
	}
536
537
	/**
538
	 * @param $deprecated_options
539
	 *
540
	 * @return array
541
	 */
542
	public function setup_deprecated( $deprecated_options ) {
543
544
		$options = array();
545
546
		if ( isset( $deprecated_options['id'] ) ) {
547
			$options['id'] = $deprecated_options['id'];
548
		}
549
		if ( isset( $deprecated_options['action'] ) ) {
550
			$options['action'] = $deprecated_options['action'];
551
		}
552
		if ( isset( $deprecated_options['num'] ) ) {
553
			$options['num'] = $deprecated_options['num'];
554
		}
555
556
		if ( isset( $deprecated_options['title'] ) ) {
557
			$options['items'] = $deprecated_options['title'];
558
		}
559
		if ( isset( $deprecated_options['item'] ) ) {
560
			$options['item'] = $deprecated_options['item'];
561
		}
562
563
		if ( isset( $deprecated_options['label'] ) ) {
564
			$options['label'] = array(
565
				'add'       => $deprecated_options['label'],
566
				'edit'      => $deprecated_options['label'],
567
				'duplicate' => $deprecated_options['label'],
568
			);
569
		}
570
		if ( isset( $deprecated_options['label_add'] ) ) {
571
			if ( isset( $options['label'] ) ) {
572
				$options['label']['add'] = $deprecated_options['label_add'];
573
			} else {
574
				$options['label'] = array( 'add' => $deprecated_options['label_add'] );
575
			}
576
		}
577
		if ( isset( $deprecated_options['label_edit'] ) ) {
578
			if ( isset( $options['label'] ) ) {
579
				$options['label']['edit'] = $deprecated_options['label_edit'];
580
			} else {
581
				$options['label'] = array( 'edit' => $deprecated_options['label_edit'] );
582
			}
583
		}
584
		if ( isset( $deprecated_options['label_duplicate'] ) ) {
585
			if ( isset( $options['label'] ) ) {
586
				$options['label']['duplicate'] = $deprecated_options['label_duplicate'];
587
			} else {
588
				$options['label'] = array( 'duplicate' => $deprecated_options['label_duplicate'] );
589
			}
590
		}
591
592
		if ( isset( $deprecated_options['icon'] ) ) {
593
			$options['icon'] = $deprecated_options['icon'];
594
		}
595
596
		if ( isset( $deprecated_options['columns'] ) ) {
597
			$options['fields'] = array( 'manage' => $deprecated_options['columns'] );
598
		}
599
		if ( isset( $deprecated_options['reorder_columns'] ) ) {
600
			if ( isset( $options['fields'] ) ) {
601
				$options['fields']['reorder'] = $deprecated_options['reorder_columns'];
602
			} else {
603
				$options['fields'] = array( 'reorder' => $deprecated_options['reorder_columns'] );
604
			}
605
		}
606
		if ( isset( $deprecated_options['add_fields'] ) ) {
607
			if ( isset( $options['fields'] ) ) {
608
				if ( ! isset( $options['fields']['add'] ) ) {
609
					$options['fields']['add'] = $deprecated_options['add_fields'];
610
				}
611
				if ( ! isset( $options['fields']['edit'] ) ) {
612
					$options['fields']['edit'] = $deprecated_options['add_fields'];
613
				}
614
				if ( ! isset( $options['fields']['duplicate'] ) ) {
615
					$options['fields']['duplicate'] = $deprecated_options['add_fields'];
616
				}
617
			} else {
618
				$options['fields'] = array(
619
					'add'       => $deprecated_options['add_fields'],
620
					'edit'      => $deprecated_options['add_fields'],
621
					'duplicate' => $deprecated_options['add_fields'],
622
				);
623
			}
624
		}
625
		if ( isset( $deprecated_options['edit_fields'] ) ) {
626
			if ( isset( $options['fields'] ) ) {
627
				if ( ! isset( $options['fields']['add'] ) ) {
628
					$options['fields']['add'] = $deprecated_options['edit_fields'];
629
				}
630
				if ( ! isset( $options['fields']['edit'] ) ) {
631
					$options['fields']['edit'] = $deprecated_options['edit_fields'];
632
				}
633
				if ( ! isset( $options['fields']['duplicate'] ) ) {
634
					$options['fields']['duplicate'] = $deprecated_options['edit_fields'];
635
				}
636
			} else {
637
				$options['fields'] = array(
638
					'add'       => $deprecated_options['edit_fields'],
639
					'edit'      => $deprecated_options['edit_fields'],
640
					'duplicate' => $deprecated_options['edit_fields'],
641
				);
642
			}
643
		}
644
		if ( isset( $deprecated_options['duplicate_fields'] ) ) {
645
			if ( isset( $options['fields'] ) ) {
646
				$options['fields']['duplicate'] = $deprecated_options['duplicate_fields'];
647
			} else {
648
				$options['fields'] = array( 'duplicate' => $deprecated_options['duplicate_fields'] );
649
			}
650
		}
651
652
		if ( isset( $deprecated_options['session_filters'] ) && false === $deprecated_options['session_filters'] ) {
653
			$options['session'] = false;
654
		}
655
		if ( isset( $deprecated_options['user_per_page'] ) ) {
656
			if ( isset( $options['user'] ) && ! empty( $options['user'] ) ) {
657
				$options['user'] = array( 'orderby' );
658
			} else {
659
				$options['user'] = false;
660
			}
661
		}
662
		if ( isset( $deprecated_options['user_sort'] ) ) {
663
			if ( isset( $options['user'] ) && ! empty( $options['user'] ) ) {
664
				$options['user'] = array( 'show_per_page' );
665
			} else {
666
				$options['user'] = false;
667
			}
668
		}
669
670
		if ( isset( $deprecated_options['custom_list'] ) ) {
671
			if ( isset( $options['actions_custom'] ) ) {
672
				$options['actions_custom']['manage'] = $deprecated_options['custom_list'];
673
			} else {
674
				$options['actions_custom'] = array( 'manage' => $deprecated_options['custom_list'] );
675
			}
676
		}
677
		if ( isset( $deprecated_options['custom_reorder'] ) ) {
678
			if ( isset( $options['actions_custom'] ) ) {
679
				$options['actions_custom']['reorder'] = $deprecated_options['custom_reorder'];
680
			} else {
681
				$options['actions_custom'] = array( 'reorder' => $deprecated_options['custom_reorder'] );
682
			}
683
		}
684
		if ( isset( $deprecated_options['custom_add'] ) ) {
685
			if ( isset( $options['actions_custom'] ) ) {
686
				$options['actions_custom']['add'] = $deprecated_options['custom_add'];
687
			} else {
688
				$options['actions_custom'] = array( 'add' => $deprecated_options['custom_add'] );
689
			}
690
		}
691
		if ( isset( $deprecated_options['custom_edit'] ) ) {
692
			if ( isset( $options['actions_custom'] ) ) {
693
				$options['actions_custom']['edit'] = $deprecated_options['custom_edit'];
694
			} else {
695
				$options['actions_custom'] = array( 'edit' => $deprecated_options['custom_edit'] );
696
			}
697
		}
698
		if ( isset( $deprecated_options['custom_duplicate'] ) ) {
699
			if ( isset( $options['actions_custom'] ) ) {
700
				$options['actions_custom']['duplicate'] = $deprecated_options['custom_duplicate'];
701
			} else {
702
				$options['actions_custom'] = array( 'duplicate' => $deprecated_options['custom_duplicate'] );
703
			}
704
		}
705
		if ( isset( $deprecated_options['custom_delete'] ) ) {
706
			if ( isset( $options['actions_custom'] ) ) {
707
				$options['actions_custom']['delete'] = $deprecated_options['custom_delete'];
708
			} else {
709
				$options['actions_custom'] = array( 'delete' => $deprecated_options['custom_delete'] );
710
			}
711
		}
712
		if ( isset( $deprecated_options['custom_save'] ) ) {
713
			if ( isset( $options['actions_custom'] ) ) {
714
				$options['actions_custom']['save'] = $deprecated_options['custom_save'];
715
			} else {
716
				$options['actions_custom'] = array( 'save' => $deprecated_options['custom_save'] );
717
			}
718
		}
719
720
		if ( isset( $deprecated_options['custom_actions'] ) ) {
721
			$options['actions_custom'] = $deprecated_options['custom_actions'];
722
		}
723
		if ( isset( $deprecated_options['action_after_save'] ) ) {
724
			$options['action_after'] = array(
725
				'add'       => $deprecated_options['action_after_save'],
726
				'edit'      => $deprecated_options['action_after_save'],
727
				'duplicate' => $deprecated_options['action_after_save'],
728
			);
729
		}
730
		if ( isset( $deprecated_options['edit_link'] ) ) {
731
			if ( isset( $options['action_links'] ) ) {
732
				$options['action_links']['edit'] = $deprecated_options['edit_link'];
733
			} else {
734
				$options['action_links'] = array( 'edit' => $deprecated_options['edit_link'] );
735
			}
736
		}
737
		if ( isset( $deprecated_options['view_link'] ) ) {
738
			if ( isset( $options['action_links'] ) ) {
739
				$options['action_links']['view'] = $deprecated_options['view_link'];
740
			} else {
741
				$options['action_links'] = array( 'view' => $deprecated_options['view_link'] );
742
			}
743
		}
744
		if ( isset( $deprecated_options['duplicate_link'] ) ) {
745
			if ( isset( $options['action_links'] ) ) {
746
				$options['action_links']['duplicate'] = $deprecated_options['duplicate_link'];
747
			} else {
748
				$options['action_links'] = array( 'duplicate' => $deprecated_options['duplicate_link'] );
749
			}
750
		}
751
752
		if ( isset( $deprecated_options['reorder'] ) ) {
753
			$options['reorder'] = array(
754
				'on'      => $deprecated_options['reorder'],
755
				'orderby' => $deprecated_options['reorder'],
756
			);
757
		}
758
		if ( isset( $deprecated_options['reorder_sort'] ) && isset( $options['reorder'] ) ) {
759
			$options['reorder']['orderby'] = $deprecated_options['reorder_sort'];
760
		}
761
		if ( isset( $deprecated_options['reorder_limit'] ) && isset( $options['reorder'] ) ) {
762
			$options['reorder']['limit'] = $deprecated_options['reorder_limit'];
763
		}
764
		if ( isset( $deprecated_options['reorder_sql'] ) && isset( $options['reorder'] ) ) {
765
			$options['reorder']['sql'] = $deprecated_options['reorder_sql'];
766
		}
767
768
		if ( isset( $deprecated_options['sort'] ) ) {
769
			$options['orderby'] = $deprecated_options['sort'];
770
		}
771
		if ( isset( $deprecated_options['sortable'] ) ) {
772
			$options['sortable'] = $deprecated_options['sortable'];
773
		}
774
		if ( isset( $deprecated_options['limit'] ) ) {
775
			$options['limit'] = $deprecated_options['limit'];
776
		}
777
778
		if ( isset( $deprecated_options['where'] ) ) {
779
			if ( isset( $options['where'] ) ) {
780
				$options['where']['manage'] = $deprecated_options['where'];
781
			} else {
782
				$options['where'] = array( 'manage' => $deprecated_options['where'] );
783
			}
784
		}
785
		if ( isset( $deprecated_options['edit_where'] ) ) {
786
			/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
787
			if ( isset( $options[ 'where' ] ) )
788
                $options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ];
789
            else
790
                $options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );*/
791
792
			if ( isset( $options['restrict'] ) ) {
793
				$options['restrict']['edit'] = (array) $deprecated_options['edit_where'];
794
			} else {
795
				$options['restrict'] = array( 'edit' => (array) $deprecated_options['edit_where'] );
796
			}
797
		}
798
		if ( isset( $deprecated_options['duplicate_where'] ) ) {
799
			/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
800
			if ( isset( $options[ 'where' ] ) )
801
                $options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ];
802
            else
803
                $options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );*/
804
805
			if ( isset( $options['restrict'] ) ) {
806
				$options['restrict']['duplicate'] = (array) $deprecated_options['duplicate_where'];
807
			} else {
808
				$options['restrict'] = array( 'duplicate' => (array) $deprecated_options['duplicate_where'] );
809
			}
810
		}
811
		if ( isset( $deprecated_options['delete_where'] ) ) {
812
			/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
813
			if ( isset( $options[ 'where' ] ) )
814
                $options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ];
815
            else
816
                $options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );*/
817
818
			if ( isset( $options['restrict'] ) ) {
819
				$options['restrict']['delete'] = (array) $deprecated_options['delete_where'];
820
			} else {
821
				$options['restrict'] = array( 'delete' => (array) $deprecated_options['delete_where'] );
822
			}
823
		}
824
		if ( isset( $deprecated_options['reorder_where'] ) ) {
825
			if ( isset( $options['where'] ) ) {
826
				$options['where']['reorder'] = $deprecated_options['reorder_where'];
827
			} else {
828
				$options['where'] = array( 'reorder' => $deprecated_options['reorder_where'] );
829
			}
830
		}
831
832
		if ( isset( $deprecated_options['sql'] ) ) {
833
			$options['sql'] = array( 'sql' => $deprecated_options['sql'] );
834
		}
835
836
		if ( isset( $deprecated_options['search'] ) ) {
837
			$options['searchable'] = $deprecated_options['search'];
838
		}
839
		if ( isset( $deprecated_options['search_across'] ) ) {
840
			$options['search_across'] = $deprecated_options['search_across'];
841
		}
842
		if ( isset( $deprecated_options['search_across_picks'] ) ) {
843
			$options['search_across_picks'] = $deprecated_options['search_across_picks'];
844
		}
845
		if ( isset( $deprecated_options['filters'] ) ) {
846
			$options['filters'] = $deprecated_options['filters'];
847
		}
848
		if ( isset( $deprecated_options['custom_filters'] ) ) {
849
			if ( is_callable( $deprecated_options['custom_filters'] ) ) {
850
				add_filter( 'pods_ui_filters', $deprecated_options['custom_filters'] );
851
			} else {
852
				global $pods_ui_custom_filters;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
Comprehensibility Naming introduced by
The variable name $pods_ui_custom_filters exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
853
				$pods_ui_custom_filters = $deprecated_options['custom_filters'];
854
				add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) );
855
			}
856
		}
857
858
		if ( isset( $deprecated_options['disable_actions'] ) ) {
859
			$options['actions_disabled'] = $deprecated_options['disable_actions'];
860
		}
861
		if ( isset( $deprecated_options['hide_actions'] ) ) {
862
			$options['actions_hidden'] = $deprecated_options['hide_actions'];
863
		}
864
865
		if ( isset( $deprecated_options['wpcss'] ) ) {
866
			$options['wpcss'] = $deprecated_options['wpcss'];
867
		}
868
869
		$remaining_options = array_diff_assoc( $options, $deprecated_options );
870
871
		foreach ( $remaining_options as $option => $value ) {
872
			if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) ) {
873
				$options[ $option ] = $value;
874
			}
875
		}
876
877
		return $options;
878
	}
879
880
	/**
881
	 *
882
	 */
883
	public function deprecated_filters() {
884
885
		global $pods_ui_custom_filters;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
Comprehensibility Naming introduced by
The variable name $pods_ui_custom_filters exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
886
		echo $pods_ui_custom_filters;
887
	}
888
889
	/**
890
	 * @param $options
891
	 *
892
	 * @return array|bool|mixed|null|PodsArray
893
	 */
894
	public function setup( $options ) {
895
896
		$options = pods_array( $options );
897
898
		$options->validate( 'num', '', 'absint' );
899
900
		if ( empty( $options->num ) ) {
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
901
			$options->num = '';
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
902
		}
903
904
		$options->validate( 'id', pods_var( 'id' . $options->num, 'get', $this->id ) );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
905
906
		$options->validate(
907
			'do', pods_var( 'do' . $options->num, 'get', $this->do ), 'in_array', array(
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
908
				'save',
909
				'create',
910
			)
911
		);
912
913
		$options->validate( 'excluded', self::$excluded, 'array_merge' );
914
915
		$options->validate( 'action', pods_var( 'action' . $options->num, 'get', $this->action, null, true ), 'in_array', $this->actions );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
916
		$options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' );
917
		$options->validate( 'action_bulk', pods_var( 'action_bulk' . $options->num, 'get', $this->action_bulk, null, true ), 'isset', $this->actions_bulk );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
918
919
		$bulk = pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
920
921
		if ( ! empty( $bulk ) ) {
922
			$bulk = (array) pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true );
923
		} else {
924
			$bulk = array();
925
		}
926
927
		$options->validate( 'bulk', $bulk, 'array_merge', $this->bulk );
928
929
		$options->validate( 'views', $this->views, 'array' );
930
		$options->validate( 'view', pods_var( 'view' . $options->num, 'get', $this->view, null, true ), 'isset', $this->views );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
931
932
		$options->validate( 'searchable', $this->searchable, 'boolean' );
933
		$options->validate( 'search', pods_var( 'search' . $options->num, 'get' ) );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
934
		$options->validate( 'search_across', $this->search_across, 'boolean' );
935
		$options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' );
936
		$options->validate( 'filters', $this->filters, 'array' );
937
		$options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' );
938
		$options->validate( 'where', $this->where, 'array_merge' );
939
940
		$options->validate( 'pagination', $this->pagination, 'boolean' );
941
		$options->validate( 'page', pods_var( 'pg' . $options->num, 'get', $this->page ), 'absint' );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
942
		$options->validate( 'limit', pods_var( 'limit' . $options->num, 'get', $this->limit ), 'int' );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
943
944
		if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) {
945
			$this->sql = array(
946
				'table'       => $this->pods_data->table,
947
				'field_id'    => $this->pods_data->field_id,
948
				'field_index' => $this->pods_data->field_index,
949
			);
950
		}
951
		$options->validate( 'sql', $this->sql, 'array_merge' );
952
953
		$options->validate(
954
			'orderby_dir', strtoupper( pods_v( 'orderby_dir' . $options['num'], 'get', $this->orderby_dir, true ) ), 'in_array', array(
955
				'ASC',
956
				'DESC',
957
			)
958
		);
959
960
		$orderby = $this->orderby;
961
962
		// Enforce strict DB column name usage
963
		if ( ! empty( $_GET[ 'orderby' . $options->num ] ) ) {
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
964
			$orderby = pods_clean_name( $_GET[ 'orderby' . $options->num ], true, false );
0 ignored issues
show
Documentation introduced by
The property num does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
965
		}
966
967
		if ( ! empty( $orderby ) ) {
968
			$orderby = array(
969
				'default' => $orderby,
970
			);
971
		} else {
972
			$orderby = array();
973
		}
974
975
		$options->validate( 'orderby', $orderby, 'array_merge' );
976
		$options->validate( 'sortable', $this->sortable, 'boolean' );
977
978
		$options->validate( 'params', $this->params, 'array' );
979
980
		$options->validate( 'restrict', $this->restrict, 'array_merge' );
981
982
		// handle author restrictions
983
		if ( ! empty( $options['restrict']['author_restrict'] ) ) {
984
			$restrict = $options['restrict'];
985
986
			if ( ! is_array( $restrict['author_restrict'] ) ) {
987
				$restrict['author_restrict'] = array( $restrict['author_restrict'] => get_current_user_id() );
988
			}
989
990
			if ( null === $restrict['edit'] ) {
991
				$restrict['edit'] = $restrict['author_restrict'];
992
			}
993
994
			$options->restrict = $restrict;
0 ignored issues
show
Documentation introduced by
The property restrict does not exist on object<PodsArray>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
995
		}
996
997
		if ( null !== $options['restrict']['edit'] ) {
998
			$restrict = $options['restrict'];
999
1000
			if ( null === $restrict['duplicate'] ) {
1001
				$restrict['duplicate'] = $restrict['edit'];
1002
			}
1003
1004
			if ( null === $restrict['delete'] ) {
1005
				$restrict['delete'] = $restrict['edit'];
1006
			}
1007
1008
			if ( null === $restrict['manage'] ) {
1009
				$restrict['manage'] = $restrict['edit'];
1010
			}
1011
1012
			if ( null === $restrict['reorder'] ) {
1013
				$restrict['reorder'] = $restrict['edit'];
1014
			}
1015
1016
			$options->restrict = $restrict;
0 ignored issues
show
Documentation introduced by
The property restrict does not exist on object<PodsArray>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1017
		}//end if
1018
1019
		$item  = __( 'Item', 'pods' );
1020
		$items = __( 'Items', 'pods' );
1021
1022
		if ( ! is_array( $this->label ) ) {
1023
			$this->label = (array) $this->label;
1024
		}
1025
1026
		if ( is_object( $this->pod ) ) {
1027
			$pod_data = $this->pod->pod_data;
1028
			$pod_data = apply_filters( 'pods_advanced_content_type_pod_data_' . $this->pod->pod_data['name'], $pod_data, $this->pod->pod_data['name'] );
1029
			$pod_data = apply_filters( 'pods_advanced_content_type_pod_data', $pod_data, $this->pod->pod_data['name'] );
1030
1031
			$this->label = array_merge( $this->label, $pod_data['options'] );
1032
1033
			$item  = pods_v( 'label_singular', $pod_data['options'], pods_v( 'label', $pod_data, $item, true ), true );
1034
			$items = pods_v( 'label', $pod_data, $items, true );
1035
		}
1036
1037
		$options->validate( 'item', $item );
1038
		$options->validate( 'items', $items );
1039
1040
		$options->validate(
1041
			'heading', array(
1042
				'manage'    => pods_v( 'label_manage', $this->label, __( 'Manage', 'pods' ) ),
1043
				'add'       => pods_v( 'label_add_new', $this->label, __( 'Add New', 'pods' ) ),
1044
				'edit'      => pods_v( 'label_edit', $this->label, __( 'Edit', 'pods' ) ),
1045
				'duplicate' => pods_v( 'label_duplicate', $this->label, __( 'Duplicate', 'pods' ) ),
1046
				'view'      => pods_v( 'label_view', $this->label, __( 'View', 'pods' ) ),
1047
				'reorder'   => pods_v( 'label_reorder', $this->label, __( 'Reorder', 'pods' ) ),
1048
				'search'    => pods_v( 'label_search', $this->label, __( 'Search', 'pods' ) ),
1049
				'views'     => pods_v( 'label_view', $this->label, __( 'View', 'pods' ) ),
1050
			), 'array_merge'
1051
		);
1052
1053
		$options->validate(
1054
			'header', array(
1055
				'manage'    => pods_v( 'label_manage_items', $this->label, sprintf( __( 'Manage %s', 'pods' ), $options->items ) ),
0 ignored issues
show
Documentation introduced by
The property items does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1056
				'add'       => pods_v( 'label_add_new_item', $this->label, sprintf( __( 'Add New %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1057
				'edit'      => pods_v( 'label_edit_item', $this->label, sprintf( __( 'Edit %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1058
				'duplicate' => pods_v( 'label_duplicate_item', $this->label, sprintf( __( 'Duplicate %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1059
				'view'      => pods_v( 'label_view_item', $this->label, sprintf( __( 'View %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1060
				'reorder'   => pods_v( 'label_reorder_items', $this->label, sprintf( __( 'Reorder %s', 'pods' ), $options->items ) ),
0 ignored issues
show
Documentation introduced by
The property items does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1061
				'search'    => pods_v( 'label_search_items', $this->label, sprintf( __( 'Search %s', 'pods' ), $options->items ) ),
0 ignored issues
show
Documentation introduced by
The property items does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1062
			), 'array_merge'
1063
		);
1064
1065
		$options->validate(
1066
			'label', array(
1067
				'add'       => pods_v( 'label_add_new_item', $this->label, sprintf( __( 'Add New %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1068
				'add_new'   => pods_v( 'label_add_new', $this->label, __( 'Add New', 'pods' ) ),
1069
				'edit'      => pods_v( 'label_update_item', $this->label, sprintf( __( 'Update %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1070
				'duplicate' => pods_v( 'label_duplicate_item', $this->label, sprintf( __( 'Duplicate %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1071
				'delete'    => pods_v( 'label_delete_item', $this->label, sprintf( __( 'Delete this %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1072
				'view'      => pods_v( 'label_view_item', $this->label, sprintf( __( 'View %s', 'pods' ), $options->item ) ),
0 ignored issues
show
Documentation introduced by
The property item does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1073
				'reorder'   => pods_v( 'label_reorder_items', $this->label, sprintf( __( 'Reorder %s', 'pods' ), $options->items ) ),
0 ignored issues
show
Documentation introduced by
The property items does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1074
			), 'array_merge'
1075
		);
1076
1077
		$options->validate(
1078
			'fields', array(
1079
				'manage' => array(
1080
					$options->sql['field_index'] => array( 'label' => __( 'Name', 'pods' ) ),
0 ignored issues
show
Documentation introduced by
The property sql does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1081
				),
1082
			), 'array'
1083
		);
1084
1085
		$options->validate( 'export', $this->export, 'array_merge' );
1086
		$options->validate( 'reorder', $this->reorder, 'array_merge' );
1087
		$options->validate( 'screen_options', $this->screen_options, 'array_merge' );
1088
1089
		$options->validate(
1090
			'session', $this->session, 'in_array', array(
1091
				'search',
1092
				'filters',
1093
				'show_per_page',
1094
				'orderby',
1095
			)
1096
		);
1097
		$options->validate(
1098
			'user', $this->user, 'in_array', array(
1099
				'search',
1100
				'filters',
1101
				'show_per_page',
1102
				'orderby',
1103
			)
1104
		);
1105
1106
		$options->validate( 'action_after', $this->action_after, 'array_merge' );
1107
		$options->validate( 'action_links', $this->action_links, 'array_merge' );
1108
		$options->validate( 'actions_disabled', $this->actions_disabled, 'array' );
1109
		$options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' );
1110
		$options->validate( 'actions_custom', $this->actions_custom, 'array_merge' );
1111
1112
		if ( ! empty( $options->actions_disabled ) ) {
0 ignored issues
show
Documentation introduced by
The property actions_disabled does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1113
			if ( ! empty( $options->actions_bulk ) ) {
0 ignored issues
show
Documentation introduced by
The property actions_bulk does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1114
				$actions_bulk = $options->actions_bulk;
0 ignored issues
show
Documentation introduced by
The property actions_bulk does not exist on object<PodsArray>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1115
1116
				foreach ( $actions_bulk as $action => $action_opt ) {
1117
					if ( in_array( $action, $options->actions_disabled ) ) {
0 ignored issues
show
Documentation introduced by
The property actions_disabled does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1118
						unset( $actions_bulk[ $action ] );
1119
					}
1120
				}
1121
1122
				$options->actions_bulk = $actions_bulk;
0 ignored issues
show
Documentation introduced by
The property actions_bulk does not exist on object<PodsArray>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1123
			}
1124
1125
			if ( ! empty( $options->actions_custom ) ) {
0 ignored issues
show
Documentation introduced by
The property actions_custom does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1126
				$actions_custom = $options->actions_custom;
0 ignored issues
show
Documentation introduced by
The property actions_custom does not exist on object<PodsArray>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1127
1128
				foreach ( $actions_custom as $action => $action_opt ) {
1129
					if ( in_array( $action, $options->actions_disabled ) ) {
0 ignored issues
show
Documentation introduced by
The property actions_disabled does not exist on object<PodsArray>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1130
						unset( $actions_custom[ $action ] );
1131
					}
1132
				}
1133
1134
				$options->actions_custom = $actions_custom;
0 ignored issues
show
Documentation introduced by
The property actions_custom does not exist on object<PodsArray>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1135
			}
1136
		}//end if
1137
1138
		$options->validate( 'extra', $this->extra, 'array_merge' );
1139
1140
		$options->validate( 'style', $this->style );
1141
		$options->validate( 'icon', $this->icon );
1142
		$options->validate( 'css', $this->css );
1143
		$options->validate( 'wpcss', $this->wpcss, 'boolean' );
1144
1145
		if ( true === $options['wpcss'] ) {
1146
			global $user_ID;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1147
			wp_get_current_user();
1148
1149
			$color = get_user_meta( $user_ID, 'admin_color', true );
0 ignored issues
show
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
1150
			if ( strlen( $color ) < 1 ) {
1151
				$color = 'fresh';
1152
			}
1153
1154
			$this->wpcss = "colors-{$color}";
1155
		}
1156
1157
		$options = $options->dump();
1158
1159
		if ( is_object( $this->pod ) ) {
1160
			$options = $this->do_hook( $this->pod->pod . '_setup_options', $options );
1161
		}
1162
1163
		$options = $this->do_hook( 'setup_options', $options );
1164
1165
		if ( false !== $options && ! empty( $options ) ) {
1166
			foreach ( $options as $option => $value ) {
1167
				if ( isset( $this->{$option} ) ) {
1168
					$this->{$option} = $value;
1169
				} else {
1170
					$this->x[ $option ] = $value;
1171
				}
1172
			}
1173
		}
1174
1175
		$unique_identifier = pods_var( 'page', 'get' );
1176
		// wp-admin page
1177
		if ( is_object( $this->pod ) && isset( $this->pod->pod ) ) {
1178
			$unique_identifier = '_' . $this->pod->pod;
1179
		} elseif ( 0 < strlen( $this->sql['table'] ) ) {
1180
			$unique_identifier = '_' . $this->sql['table'];
1181
		}
1182
1183
		$unique_identifier .= '_' . $this->page;
1184
		if ( 0 < strlen( $this->num ) ) {
1185
			$unique_identifier .= '_' . $this->num;
1186
		}
1187
1188
		$this->unique_identifier = 'pods_ui_' . md5( $unique_identifier );
1189
1190
		$this->setup_fields();
1191
1192
		return $options;
1193
	}
1194
1195
	/**
1196
	 * @param null   $fields
1197
	 * @param string $which
1198
	 *
1199
	 * @return array|bool|mixed|null
1200
	 */
1201
	public function setup_fields( $fields = null, $which = 'fields' ) {
1202
1203
		$init = false;
1204
		if ( null === $fields ) {
1205
			if ( isset( $this->fields[ $which ] ) ) {
1206
				$fields = (array) $this->fields[ $which ];
1207
			} elseif ( isset( $this->fields['manage'] ) ) {
1208
				$fields = (array) $this->fields['manage'];
1209
			} else {
1210
				$fields = array();
1211
			}
1212
			if ( 'fields' === $which ) {
1213
				$init = true;
1214
			}
1215
		}
1216
		if ( ! empty( $fields ) ) {
1217
			// Available Attributes
1218
			// type = field type
1219
			// type = date (data validation as date)
1220
			// type = time (data validation as time)
1221
			// type = datetime (data validation as datetime)
1222
			// date_touch = use current timestamp when saving (even if readonly, if type is date-related)
1223
			// date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related)
1224
			// 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
1225
			// type = text / other (single line text box)
1226
			// type = desc (textarea)
1227
			// type = number (data validation as int float)
1228
			// type = decimal (data validation as decimal)
1229
			// type = password (single line password box)
1230
			// type = bool (checkbox)
1231
			// type = related (select box)
1232
			// related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items
1233
			// related_field = field name on table to show (if type=related) - default "name"
1234
			// related_multiple = true (ability to select multiple values if type=related)
1235
			// related_sql = custom where / order by SQL (if type=related)
1236
			// readonly = true (shows as text)
1237
			// display = false (doesn't show on form, but can be saved)
1238
			// search = this field is searchable
1239
			// filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box)
1240
			// comments = comments to show for field
1241
			// comments_top = true (shows comments above field instead of below)
1242
			// real_name = the real name of the field (if using an alias for 'name')
1243
			// group_related = true (uses HAVING instead of WHERE for filtering field)
1244
			$new_fields = array();
1245
			$filterable = false;
1246
			if ( empty( $this->filters ) && ( empty( $this->fields['search'] ) || 'search' === $which ) && false !== $this->searchable ) {
1247
				$filterable    = true;
1248
				$this->filters = array();
1249
			}
1250
1251
			foreach ( $fields as $field => $attributes ) {
1252
				if ( ! is_array( $attributes ) ) {
1253
					if ( is_int( $field ) ) {
1254
						$field      = $attributes;
1255
						$attributes = array();
1256
					} else {
1257
						$attributes = array( 'label' => $attributes );
1258
					}
1259
				}
1260
1261
				if ( ! isset( $attributes['real_name'] ) ) {
1262
					$attributes['real_name'] = pods_var( 'name', $attributes, $field );
1263
				}
1264
1265
				if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes['real_name'] ] ) ) {
1266
					$attributes = array_merge( $this->pod->fields[ $attributes['real_name'] ], $attributes );
1267
				}
1268
1269
				if ( ! isset( $attributes['options'] ) ) {
1270
					$attributes['options'] = array();
1271
				}
1272
				if ( ! isset( $attributes['id'] ) ) {
1273
					$attributes['id'] = '';
1274
				}
1275
				if ( ! isset( $attributes['label'] ) ) {
1276
					$attributes['label'] = ucwords( str_replace( '_', ' ', $field ) );
1277
				}
1278
				if ( ! isset( $attributes['type'] ) ) {
1279
					$attributes['type'] = 'text';
1280
				}
1281
				if ( ! isset( $attributes['options']['date_format_type'] ) ) {
1282
					$attributes['options']['date_format_type'] = 'date';
1283
				}
1284
				if ( 'related' !== $attributes['type'] || ! isset( $attributes['related'] ) ) {
1285
					$attributes['related'] = false;
1286
				}
1287
				if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_id'] ) ) {
1288
					$attributes['related_id'] = 'id';
1289
				}
1290
				if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_field'] ) ) {
1291
					$attributes['related_field'] = 'name';
1292
				}
1293
				if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_multiple'] ) ) {
1294
					$attributes['related_multiple'] = false;
1295
				}
1296
				if ( 'related' !== $attributes['type'] || ! isset( $attributes['related_sql'] ) ) {
1297
					$attributes['related_sql'] = false;
1298
				}
1299
				if ( 'related' === $attributes['type'] && ( is_array( $attributes['related'] ) || strpos( $attributes['related'], ',' ) ) ) {
1300
					if ( ! is_array( $attributes['related'] ) ) {
1301
						$attributes['related'] = @explode( ',', $attributes['related'] );
0 ignored issues
show
Coding Style introduced by
Silencing errors is discouraged
Loading history...
1302
						$related_items         = array();
1303
						foreach ( $attributes['related'] as $key => $label ) {
1304
							if ( is_numeric( $key ) ) {
1305
								$key   = $label;
1306
								$label = ucwords( str_replace( '_', ' ', $label ) );
1307
							}
1308
							$related_items[ $key ] = $label;
1309
						}
1310
						$attributes['related'] = $related_items;
1311
					}
1312
					if ( empty( $attributes['related'] ) ) {
1313
						$attributes['related'] = false;
1314
					}
1315
				}
1316
				if ( ! isset( $attributes['readonly'] ) ) {
1317
					$attributes['readonly'] = false;
1318
				}
1319
				if ( ! isset( $attributes['date_touch'] ) || 'date' !== $attributes['type'] ) {
1320
					$attributes['date_touch'] = false;
1321
				}
1322
				if ( ! isset( $attributes['date_touch_on_create'] ) || 'date' !== $attributes['type'] ) {
1323
					$attributes['date_touch_on_create'] = false;
1324
				}
1325
				if ( ! isset( $attributes['display'] ) ) {
1326
					$attributes['display'] = true;
1327
				}
1328
				if ( ! isset( $attributes['hidden'] ) ) {
1329
					$attributes['hidden'] = false;
1330
				}
1331
				if ( ! isset( $attributes['sortable'] ) || false === $this->sortable ) {
1332
					$attributes['sortable'] = $this->sortable;
1333
				}
1334
				if ( ! isset( $attributes['options']['search'] ) || false === $this->searchable ) {
1335
					$attributes['options']['search'] = $this->searchable;
1336
				}
1337
				if ( ! isset( $attributes['options']['filter'] ) || false === $this->searchable ) {
1338
					$attributes['options']['filter'] = $this->searchable;
1339
				}
1340
				/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1341
				if ( false !== $attributes[ 'options' ][ 'filter' ] && false !== $filterable )
1342
                    $this->filters[] = $field;*/
1343
				if ( false === $attributes['options']['filter'] || ! isset( $attributes['filter_label'] ) || ! in_array( $field, $this->filters ) ) {
1344
					$attributes['filter_label'] = $attributes['label'];
1345
				}
1346
				if ( false === $attributes['options']['filter'] || ! isset( $attributes['filter_default'] ) || ! in_array( $field, $this->filters ) ) {
1347
					$attributes['filter_default'] = false;
1348
				}
1349
				if ( false === $attributes['options']['filter'] || ! isset( $attributes['date_ongoing'] ) || 'date' !== $attributes['type'] || ! in_array( $field, $this->filters ) ) {
1350
					$attributes['date_ongoing'] = false;
1351
				}
1352
				if ( false === $attributes['options']['filter'] || ! isset( $attributes['date_ongoing'] ) || 'date' !== $attributes['type'] || ! isset( $attributes['date_ongoing_default'] ) || ! in_array( $field, $this->filters ) ) {
1353
					$attributes['date_ongoing_default'] = false;
1354
				}
1355
				if ( ! isset( $attributes['export'] ) ) {
1356
					$attributes['export'] = true;
1357
				}
1358
				if ( ! isset( $attributes['group_related'] ) ) {
1359
					$attributes['group_related'] = false;
1360
				}
1361
				if ( ! isset( $attributes['comments'] ) ) {
1362
					$attributes['comments'] = '';
1363
				}
1364
				if ( ! isset( $attributes['comments_top'] ) ) {
1365
					$attributes['comments_top'] = false;
1366
				}
1367
				if ( ! isset( $attributes['custom_view'] ) ) {
1368
					$attributes['custom_view'] = false;
1369
				}
1370
				if ( ! isset( $attributes['custom_input'] ) ) {
1371
					$attributes['custom_input'] = false;
1372
				}
1373
				if ( isset( $attributes['display_helper'] ) ) {
1374
					// pods ui backward compatibility
1375
					$attributes['custom_display'] = $attributes['display_helper'];
1376
				}
1377
				if ( ! isset( $attributes['custom_display'] ) ) {
1378
					$attributes['custom_display'] = false;
1379
				}
1380
				if ( ! isset( $attributes['custom_relate'] ) ) {
1381
					$attributes['custom_relate'] = false;
1382
				}
1383
				if ( ! isset( $attributes['custom_form_display'] ) ) {
1384
					$attributes['custom_form_display'] = false;
1385
				}
1386
				if ( ! isset( $attributes['css_values'] ) ) {
1387
					$attributes['css_values'] = true;
1388
				}
1389
				if ( 'search_columns' === $which && ! $attributes['options']['search'] ) {
1390
					continue;
1391
				}
1392
1393
				$attributes = PodsForm::field_setup( $attributes, null, $attributes['type'] );
1394
1395
				$new_fields[ $field ] = $attributes;
1396
			}//end foreach
1397
			$fields = $new_fields;
1398
		}//end if
1399
		if ( false !== $init ) {
1400
			if ( 'fields' !== $which && ! empty( $this->fields ) ) {
1401
				$this->fields = $this->setup_fields( $this->fields, 'fields' );
1402
			} else {
1403
				$this->fields['manage'] = $fields;
1404
			}
1405
1406
			if ( ! in_array( 'add', $this->actions_disabled ) || ! in_array( 'edit', $this->actions_disabled ) || ! in_array( 'duplicate', $this->actions_disabled ) ) {
1407
				if ( 'form' !== $which && isset( $this->fields['form'] ) && is_array( $this->fields['form'] ) ) {
1408
					$this->fields['form'] = $this->setup_fields( $this->fields['form'], 'form' );
1409
				} else {
1410
					$this->fields['form'] = $fields;
1411
				}
1412
1413
				if ( ! in_array( 'add', $this->actions_disabled ) ) {
1414
					if ( 'add' !== $which && isset( $this->fields['add'] ) && is_array( $this->fields['add'] ) ) {
1415
						$this->fields['add'] = $this->setup_fields( $this->fields['add'], 'add' );
1416
					}
1417
				}
1418
				if ( ! in_array( 'edit', $this->actions_disabled ) ) {
1419
					if ( 'edit' !== $which && isset( $this->fields['edit'] ) && is_array( $this->fields['edit'] ) ) {
1420
						$this->fields['edit'] = $this->setup_fields( $this->fields['edit'], 'edit' );
1421
					}
1422
				}
1423
				if ( ! in_array( 'duplicate', $this->actions_disabled ) ) {
1424
					if ( 'duplicate' !== $which && isset( $this->fields['duplicate'] ) && is_array( $this->fields['duplicate'] ) ) {
1425
						$this->fields['duplicate'] = $this->setup_fields( $this->fields['duplicate'], 'duplicate' );
1426
					}
1427
				}
1428
			}//end if
1429
1430
			if ( false !== $this->searchable ) {
1431
				if ( 'search' !== $which && isset( $this->fields['search'] ) && ! empty( $this->fields['search'] ) ) {
1432
					$this->fields['search'] = $this->setup_fields( $this->fields['search'], 'search' );
1433
				} else {
1434
					$this->fields['search'] = $fields;
1435
				}
1436
			} else {
1437
				$this->fields['search'] = false;
1438
			}
1439
1440
			if ( ! in_array( 'export', $this->actions_disabled ) ) {
1441
				if ( 'export' !== $which && isset( $this->fields['export'] ) && ! empty( $this->fields['export'] ) ) {
1442
					$this->fields['export'] = $this->setup_fields( $this->fields['export'], 'export' );
1443
				}
1444
			}
1445
1446
			if ( ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
1447
				if ( 'reorder' !== $which && isset( $this->fields['reorder'] ) && ! empty( $this->fields['reorder'] ) ) {
1448
					$this->fields['reorder'] = $this->setup_fields( $this->fields['reorder'], 'reorder' );
1449
				} else {
1450
					$this->fields['reorder'] = $fields;
1451
				}
1452
			}
1453
		}//end if
1454
1455
		return $this->do_hook( 'setup_fields', $fields, $which, $init );
1456
	}
1457
1458
	/**
1459
	 * @param      $msg
1460
	 * @param bool $error
1461
	 */
1462
	public function message( $msg, $error = false ) {
1463
1464
		$msg = $this->do_hook( ( $error ) ? 'error' : 'message', $msg );
1465
		?>
1466
		<div id="message" class="<?php echo esc_attr( ( $error ) ? 'error' : 'updated' ); ?> fade">
1467
			<p><?php echo $msg; ?></p></div>
1468
		<?php
1469
	}
1470
1471
	/**
1472
	 * @param $msg
1473
	 *
1474
	 * @return bool
1475
	 */
1476
	public function error( $msg ) {
1477
1478
		$this->message( $msg, true );
1479
1480
		return false;
1481
	}
1482
1483
	/**
1484
	 * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1485
	 */
1486
	public function go() {
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 3 characters.

Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.

Loading history...
1487
1488
		$this->do_hook( 'go' );
1489
		$_GET = pods_unsanitize( $_GET );
1490
		// fix wp sanitization
1491
		$_POST = pods_unsanitize( $_POST );
1492
		// fix wp sanitization
1493
		if ( false !== $this->css ) {
1494
			?>
1495
			<link type="text/css" rel="stylesheet" href="<?php echo esc_url( $this->css ); ?>" />
0 ignored issues
show
introduced by
Stylesheets must be registered/enqueued via wp_enqueue_style
Loading history...
1496
			<?php
1497
		}
1498
		if ( false !== $this->wpcss ) {
1499
			$stylesheets = array( 'global', 'wp-admin', $this->wpcss );
1500
			foreach ( $stylesheets as $style ) {
1501
				if ( ! wp_style_is( $style, 'queue' ) && ! wp_style_is( $style, 'to_do' ) && ! wp_style_is( $style, 'done' ) ) {
1502
					wp_enqueue_style( $style );
1503
				}
1504
			}
1505
		}
1506
1507
		$this->ui_page = array( $this->action );
1508
		if ( 'add' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) {
1509
			$this->ui_page[] = 'form';
1510
			if ( 'create' === $this->do && $this->save && ! in_array( $this->do, $this->actions_disabled ) && ! empty( $_POST ) ) {
1511
				$this->ui_page[] = $this->do;
1512
				$this->save( true );
1513
				$this->manage();
1514
			} else {
1515
				$this->add();
1516
			}
1517
		} elseif ( ( 'edit' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) ) {
1518
			$this->ui_page[] = 'form';
1519
			if ( 'save' === $this->do && $this->save && ! empty( $_POST ) ) {
1520
				$this->save();
1521
			}
1522
			$this->edit( ( 'duplicate' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) ? true : false );
1523
		} elseif ( 'delete' === $this->action && ! in_array( $this->action, $this->actions_disabled ) && false !== wp_verify_nonce( $this->_nonce, 'pods-ui-action-delete' ) ) {
1524
			$this->delete( $this->id );
1525
			$this->manage();
1526
		} elseif ( 'reorder' === $this->action && ! in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder['on'] ) {
1527
			if ( 'save' === $this->do ) {
1528
				$this->ui_page[] = $this->do;
1529
				$this->reorder();
1530
			}
1531
			$this->manage( true );
1532
		} elseif ( 'save' === $this->do && $this->save && ! in_array( $this->do, $this->actions_disabled ) && ! empty( $_POST ) ) {
1533
			$this->ui_page[] = $this->do;
1534
			$this->save();
1535
			$this->manage();
1536
		} elseif ( 'create' === $this->do && $this->save && ! in_array( $this->do, $this->actions_disabled ) && ! empty( $_POST ) ) {
1537
			$this->ui_page[] = $this->do;
1538
			$this->save( true );
1539
			$this->manage();
1540
		} elseif ( 'view' === $this->action && ! in_array( $this->action, $this->actions_disabled ) ) {
1541
			$this->view();
1542
		} else {
1543
			if ( isset( $this->actions_custom[ $this->action ] ) ) {
1544
				$more_args = false;
1545
1546
				if ( is_array( $this->actions_custom[ $this->action ] ) && isset( $this->actions_custom[ $this->action ]['more_args'] ) ) {
1547
					$more_args = $this->actions_custom[ $this->action ]['more_args'];
1548
				}
1549
1550
				$row = $this->row;
1551
1552
				if ( empty( $row ) ) {
1553
					$row = $this->get_row();
1554
				}
1555
1556
				if ( $this->restricted( $this->action, $row ) || ( $more_args && ! empty( $more_args['nonce'] ) && false === wp_verify_nonce( $this->_nonce, 'pods-ui-action-' . $this->action ) ) ) {
1557
					return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1558
				} elseif ( $more_args && false !== $this->callback_action( true, $this->action, $this->id, $row ) ) {
1559
					return null;
1560
				} elseif ( false !== $this->callback_action( true, $this->action, $this->id ) ) {
1561
					return null;
1562
				}
1563
			}//end if
1564
1565
			if ( ! in_array( 'manage', $this->actions_disabled ) ) {
1566
				// handle session / user persistent settings for show_per_page, orderby, search, and filters
1567
				$methods = array( 'session', 'user' );
1568
1569
				// @todo fix this to set ($this) AND save (setting)
1570
				foreach ( $methods as $method ) {
1571
					foreach ( $this->$method as $setting ) {
1572
						if ( 'show_per_page' === $setting ) {
1573
							$value = $this->limit;
1574
						} elseif ( 'orderby' === $setting ) {
1575
							if ( empty( $this->orderby ) ) {
1576
								$value = '';
1577
							} elseif ( isset( $this->orderby['default'] ) ) {
1578
								// save this if we have a default index set
1579
								$value = $this->orderby['default'] . ' ' . ( false === strpos( $this->orderby['default'], ' ' ) ? $this->orderby_dir : '' );
1580
							} else {
1581
								$value = '';
1582
							}
1583
						} else {
1584
							$value = $this->$setting;
1585
						}
1586
1587
						pods_v_set( $value, $setting, $method );
1588
					}
1589
				}
1590
1591
				$this->manage();
1592
			}//end if
1593
		}//end if
1594
	}
1595
1596
	/**
1597
	 * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1598
	 */
1599
	public function add() {
1600
1601
		if ( false !== $this->callback_action( 'add' ) ) {
1602
			return null;
1603
		}
1604
1605
		if ( $this->restricted( $this->action ) ) {
1606
			return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1607
		}
1608
		?>
1609
		<div class="wrap pods-ui">
1610
			<div id="icon-edit-pages" class="icon32"
1611
			<?php
1612
			if ( false !== $this->icon ) {
1613
?>
1614
 style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>>
1615
				<br /></div>
1616
			<h2>
1617
				<?php
1618
				echo wp_kses_post( $this->header['add'] );
1619
1620
				if ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
1621
					$link = pods_query_arg(
1622
						array(
1623
							'action' . $this->num => 'manage',
1624
							'id' . $this->num     => '',
1625
						), self::$allowed, $this->exclusion()
1626
					);
1627
1628
					if ( ! empty( $this->action_links['manage'] ) ) {
1629
						$link = $this->action_links['manage'];
1630
					}
1631
					?>
1632
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>
1633
				<?php } ?>
1634
			</h2>
1635
1636
			<?php $this->form( true ); ?>
1637
		</div>
1638
		<?php
1639
	}
1640
1641
	/**
1642
	 * @param bool $duplicate
1643
	 *
1644
	 * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1645
	 */
1646
	public function edit( $duplicate = false ) {
1647
1648
		if ( in_array( 'duplicate', $this->actions_disabled ) ) {
1649
			$duplicate = false;
1650
		}
1651
1652
		if ( empty( $this->row ) ) {
1653
			$this->get_row();
1654
		}
1655
1656
		if ( $duplicate && false !== $this->callback_action( 'duplicate' ) ) {
1657
			return null;
1658
		} elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) {
1659
			return null;
1660
		}
1661
1662
		if ( $this->restricted( $this->action ) ) {
1663
			return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1664
		}
1665
		?>
1666
		<div class="wrap pods-ui">
1667
			<div id="icon-edit-pages" class="icon32"
1668
			<?php
1669
			if ( false !== $this->icon ) {
1670
?>
1671
 style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>>
1672
				<br /></div>
1673
			<h2>
1674
				<?php
1675
				echo wp_kses_post( $this->do_template( $duplicate ? $this->header['duplicate'] : $this->header['edit'] ) );
1676
1677
				if ( ! in_array( 'add', $this->actions_disabled ) && ! in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
1678
					$link = pods_query_arg(
1679
						array(
1680
							'action' . $this->num => 'add',
1681
							'id' . $this->num     => '',
1682
							'do' . $this->num = '',
1683
						), self::$allowed, $this->exclusion()
1684
					);
1685
1686
					if ( ! empty( $this->action_links['add'] ) ) {
1687
						$link = $this->action_links['add'];
1688
					}
1689
					?>
1690
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading['add'] ); ?></a>
1691
					<?php
1692
				} elseif ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
1693
					$link = pods_query_arg(
1694
						array(
1695
							'action' . $this->num => 'manage',
1696
							'id' . $this->num     => '',
1697
						), self::$allowed, $this->exclusion()
1698
					);
1699
1700
					if ( ! empty( $this->action_links['manage'] ) ) {
1701
						$link = $this->action_links['manage'];
1702
					}
1703
					?>
1704
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>
1705
					<?php
1706
				}//end if
1707
				?>
1708
			</h2>
1709
1710
			<?php $this->form( false, $duplicate ); ?>
1711
		</div>
1712
		<?php
1713
	}
1714
1715
	/**
1716
	 * @param bool $create
1717
	 * @param bool $duplicate
1718
	 *
1719
	 * @return bool|mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1720
	 */
1721
	public function form( $create = false, $duplicate = false ) {
1722
1723
		if ( in_array( 'duplicate', $this->actions_disabled ) ) {
1724
			$duplicate = false;
1725
		}
1726
1727
		if ( false !== $this->callback( 'form' ) ) {
1728
			return null;
1729
		}
1730
1731
		$label = $this->label['add'];
1732
		$id    = null;
1733
		$vars  = array(
1734
			'action' . $this->num => $this->action_after['add'],
1735
			'do' . $this->num     => 'create',
1736
			'id' . $this->num     => 'X_ID_X',
1737
		);
1738
1739
		$alt_vars           = $vars;
1740
		$alt_vars['action'] = 'manage';
1741
		unset( $alt_vars['id'] );
1742
1743
		if ( false === $create ) {
1744
			if ( empty( $this->row ) ) {
1745
				$this->get_row();
1746
			}
1747
1748
			if ( empty( $this->row ) && ( ! is_object( $this->pod ) || 'settings' !== $this->pod->pod_data['type'] ) ) {
1749
				return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
1750
			}
1751
1752
			if ( $this->restricted( $this->action, $this->row ) ) {
1753
				return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1754
			}
1755
1756
			$label = $this->do_template( $this->label['edit'] );
1757
			$id    = $this->row[ $this->sql['field_id'] ];
1758
			$vars  = array(
1759
				'action' . $this->num => $this->action_after['edit'],
1760
				'do' . $this->num     => 'save',
1761
				'id' . $this->num     => $id,
1762
			);
1763
1764
			$alt_vars           = $vars;
1765
			$alt_vars['action'] = 'manage';
1766
			unset( $alt_vars['id'] );
1767
1768
			if ( $duplicate ) {
1769
				$label = $this->do_template( $this->label['duplicate'] );
1770
				$id    = null;
1771
				$vars  = array(
1772
					'action' . $this->num => $this->action_after['duplicate'],
1773
					'do' . $this->num     => 'create',
1774
					'id' . $this->num     => 'X_ID_X',
1775
				);
1776
1777
				$alt_vars           = $vars;
1778
				$alt_vars['action'] = 'manage';
1779
				unset( $alt_vars['id'] );
1780
			}
1781
		} elseif ( $this->restricted( $this->action, $this->row ) ) {
1782
			return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1783
		}//end if
1784
1785
		$fields = array();
1786
1787
		if ( isset( $this->fields[ $this->action ] ) ) {
1788
			$fields = $this->fields[ $this->action ];
1789
		}
1790
1791
		if ( is_object( $this->pod ) ) {
1792
			$object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
1793
1794
			if ( empty( $object_fields ) && in_array(
1795
				$this->pod->pod_data['type'], array(
1796
					'post_type',
1797
					'taxonomy',
1798
					'media',
1799
					'user',
1800
					'comment',
1801
				)
1802
			) ) {
1803
				$object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data['type'], $this->pod->pod_data );
1804
			}
1805
1806
			if ( empty( $fields ) ) {
1807
				// Add core object fields if $fields is empty
1808
				$fields = array_merge( $object_fields, $this->pod->fields );
1809
			}
1810
		}
1811
1812
		$form_fields = $fields;
1813
		// Temporary
1814
		$fields = array();
1815
1816
		foreach ( $form_fields as $k => $field ) {
1817
			$name = $k;
1818
1819
			$defaults = array(
1820
				'name' => $name,
1821
			);
1822
1823
			if ( ! is_array( $field ) ) {
1824
				$name = $field;
1825
1826
				$field = array(
1827
					'name' => $name,
1828
				);
1829
			}
1830
1831
			$field = array_merge( $defaults, $field );
1832
1833
			$field['name'] = trim( $field['name'] );
1834
1835
			$default_value = pods_var_raw( 'default', $field );
1836
			$value         = pods_var_raw( 'value', $field );
1837
1838
			if ( empty( $field['name'] ) ) {
1839
				$field['name'] = trim( $name );
1840
			}
1841
1842
			if ( isset( $object_fields[ $field['name'] ] ) ) {
1843
				$field = array_merge( $field, $object_fields[ $field['name'] ] );
1844
			} elseif ( isset( $this->pod->fields[ $field['name'] ] ) ) {
1845
				$field = array_merge( $this->pod->fields[ $field['name'] ], $field );
1846
			}
1847
1848
			if ( pods_var_raw( 'hidden', $field, false, null, true ) ) {
1849
				$field['type'] = 'hidden';
1850
			}
1851
1852
			$fields[ $field['name'] ] = $field;
1853
1854
			if ( empty( $this->id ) && null !== $default_value ) {
1855
				$this->pod->row_override[ $field['name'] ] = $default_value;
1856
			} elseif ( ! empty( $this->id ) && null !== $value ) {
1857
				$this->pod->row[ $field['name'] ] = $value;
1858
			}
1859
		}//end foreach
1860
1861
		unset( $form_fields );
1862
		// Cleanup
1863
		$fields = $this->do_hook( 'form_fields', $fields, $this->pod );
1864
1865
		$pod            =& $this->pod;
1866
		$thank_you      = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
1867
		$thank_you_alt  = pods_query_arg( $alt_vars, self::$allowed, $this->exclusion() );
1868
		$obj            =& $this;
1869
		$singular_label = $this->item;
1870
		$plural_label   = $this->items;
1871
1872
		if ( is_object( $this->pod ) && 'settings' === $this->pod->pod_data['type'] && 'settings' === $this->style ) {
1873
			pods_view( PODS_DIR . 'ui/admin/form-settings.php', compact( array_keys( get_defined_vars() ) ) );
1874
		} else {
1875
			pods_view( PODS_DIR . 'ui/admin/form.php', compact( array_keys( get_defined_vars() ) ) );
1876
		}
1877
	}
1878
1879
	/**
1880
	 * @return bool|mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1881
	 * @since 2.3.10
1882
	 */
1883
	public function view() {
1884
1885
		if ( false !== $this->callback_action( 'view' ) ) {
1886
			return null;
1887
		}
1888
1889
		if ( empty( $this->row ) ) {
1890
			$this->get_row();
1891
		}
1892
1893
		if ( empty( $this->row ) ) {
1894
			return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
1895
		}
1896
1897
		$pod =& $this->pod;
1898
		$obj =& $this;
1899
1900
		$fields = array();
1901
1902
		if ( isset( $this->fields[ $this->action ] ) ) {
1903
			$fields = $this->fields[ $this->action ];
1904
		}
1905
1906
		if ( is_object( $this->pod ) ) {
1907
			$object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
1908
1909
			$object_field_objects = array(
1910
				'post_type',
1911
				'taxonomy',
1912
				'media',
1913
				'user',
1914
				'comment',
1915
			);
1916
1917
			if ( empty( $object_fields ) && in_array( $this->pod->pod_data['type'], $object_field_objects ) ) {
1918
				$object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data['type'], $this->pod->pod_data );
1919
			}
1920
1921
			if ( empty( $fields ) ) {
1922
				// Add core object fields if $fields is empty
1923
				$fields = array_merge( $object_fields, $this->pod->fields );
1924
			}
1925
		}
1926
1927
		$view_fields = $fields;
1928
		// Temporary
1929
		$fields = array();
1930
1931
		foreach ( $view_fields as $k => $field ) {
1932
			$name = $k;
1933
1934
			$defaults = array(
1935
				'name'    => $name,
1936
				'type'    => 'text',
1937
				'options' => 'text',
1938
			);
1939
1940
			if ( ! is_array( $field ) ) {
1941
				$name = $field;
1942
1943
				$field = array(
1944
					'name' => $name,
1945
				);
1946
			}
1947
1948
			$field = array_merge( $defaults, $field );
1949
1950
			$field['name'] = trim( $field['name'] );
1951
1952
			$value = pods_var_raw( 'default', $field );
1953
1954
			if ( empty( $field['name'] ) ) {
1955
				$field['name'] = trim( $name );
1956
			}
1957
1958
			if ( isset( $object_fields[ $field['name'] ] ) ) {
1959
				$field = array_merge( $field, $object_fields[ $field['name'] ] );
1960
			} elseif ( isset( $this->pod->fields[ $field['name'] ] ) ) {
1961
				$field = array_merge( $this->pod->fields[ $field['name'] ], $field );
1962
			}
1963
1964
			if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' === $field['type'] ) {
1965
				continue;
1966
			} elseif ( ! PodsForm::permission( $field['type'], $field['name'], $field['options'], $fields, $pod, $pod->id() ) ) {
1967
				continue;
1968
			}
1969
1970
			$fields[ $field['name'] ] = $field;
1971
1972
			if ( empty( $this->id ) && null !== $value ) {
1973
				$this->pod->row_override[ $field['name'] ] = $value;
1974
			}
1975
		}//end foreach
1976
1977
		unset( $view_fields );
1978
		// Cleanup
1979
		?>
1980
		<div class="wrap pods-ui">
1981
			<div id="icon-edit-pages" class="icon32"
1982
			<?php
1983
			if ( false !== $this->icon ) {
1984
?>
1985
 style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>>
1986
				<br /></div>
1987
			<h2>
1988
				<?php
1989
				echo wp_kses_post( $this->do_template( $this->header['view'] ) );
1990
1991
				if ( ! in_array( 'add', $this->actions_disabled ) && ! in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
1992
					$link = pods_query_arg(
1993
						array(
1994
							'action' . $this->num => 'add',
1995
							'id' . $this->num     => '',
1996
							'do' . $this->num = '',
1997
						), self::$allowed, $this->exclusion()
1998
					);
1999
2000
					if ( ! empty( $this->action_links['add'] ) ) {
2001
						$link = $this->action_links['add'];
2002
					}
2003
					?>
2004
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading['add'] ); ?></a>
2005
					<?php
2006
				} elseif ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
2007
					$link = pods_query_arg(
2008
						array(
2009
							'action' . $this->num => 'manage',
2010
							'id' . $this->num     => '',
2011
						), self::$allowed, $this->exclusion()
2012
					);
2013
2014
					if ( ! empty( $this->action_links['manage'] ) ) {
2015
						$link = $this->action_links['manage'];
2016
					}
2017
					?>
2018
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>
2019
					<?php
2020
				}//end if
2021
2022
				pods_view( PODS_DIR . 'ui/admin/view.php', compact( array_keys( get_defined_vars() ) ) );
2023
				?>
2024
2025
			</h2>
2026
		</div>
2027
		<?php
2028
	}
2029
2030
	/**
2031
	 * Reorder data
2032
	 */
2033
	public function reorder() {
2034
2035
		// loop through order
2036
		$order = (array) pods_var_raw( 'order', 'post', array(), null, true );
2037
2038
		$params = array(
2039
			'pod'   => $this->pod->pod,
2040
			'field' => $this->reorder['on'],
2041
			'order' => $order,
2042
		);
2043
2044
		$reorder = pods_api()->reorder_pod_item( $params );
2045
2046
		if ( $reorder ) {
2047
			$this->message( sprintf( __( '<strong>Success!</strong> %s reordered successfully.', 'pods' ), $this->items ) );
2048
		} else {
2049
			$this->error( sprintf( __( '<strong>Error:</strong> %s has not been reordered.', 'pods' ), $this->items ) );
2050
		}
2051
	}
2052
2053
	/**
2054
	 * @param bool $insert
2055
	 *
2056
	 * @return mixed
2057
	 */
2058
	public function save( $insert = false ) {
2059
2060
		$this->do_hook( 'pre_save', $insert );
2061
2062
		if ( $this->callback( 'save', $insert ) ) {
2063
			return null;
2064
		}
2065
2066
		global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2067
		$action = __( 'saved', 'pods' );
2068
		if ( true === $insert ) {
2069
			$action = __( 'created', 'pods' );
2070
		}
2071
		$field_sql = array();
2072
		$values    = array();
2073
		$data      = array();
2074
		foreach ( $this->fields['form'] as $field => $attributes ) {
2075
			$vartype = '%s';
2076
			if ( 'bool' === $attributes['type'] ) {
2077
				$selected = ( 1 == pods_var( $field, 'post', 0 ) ) ? 1 : 0;
2078
			} elseif ( '' == pods_var( $field, 'post', '' ) ) {
2079
				continue;
2080
			}
2081
			if ( false === $attributes['display'] || false !== $attributes['readonly'] ) {
2082
				if ( ! in_array( $attributes['type'], array( 'date', 'time', 'datetime' ) ) ) {
2083
					continue;
2084
				}
2085
				if ( false === $attributes['date_touch'] && ( false === $attributes['date_touch_on_create'] || false === $insert || 0 < $this->id ) ) {
2086
					continue;
2087
				}
2088
			}
2089
			if ( in_array( $attributes['type'], array( 'date', 'time', 'datetime' ) ) ) {
2090
				$format = 'Y-m-d H:i:s';
2091
				if ( 'date' === $attributes['type'] ) {
2092
					$format = 'Y-m-d';
2093
				}
2094
				if ( 'time' === $attributes['type'] ) {
2095
					$format = 'H:i:s';
2096
				}
2097
				if ( false !== $attributes['date_touch'] || ( false !== $attributes['date_touch_on_create'] && true === $insert && $this->id < 1 ) ) {
2098
					$value = date_i18n( $format );
2099
				} else {
2100
					$value = date_i18n( $format, strtotime( ( 'time' === $attributes['type'] ) ? date_i18n( 'Y-m-d ' ) : pods_var( $field, 'post', '' ) ) );
2101
				}
2102
			} else {
2103
				if ( 'bool' === $attributes['type'] ) {
2104
					$vartype = '%d';
2105
					$value   = 0;
2106
					if ( '' != pods_var( $field, 'post', '' ) ) {
2107
						$value = 1;
2108
					}
2109
				} elseif ( 'number' === $attributes['type'] ) {
2110
					$vartype = '%d';
2111
					$value   = number_format( pods_var( $field, 'post', 0 ), 0, '', '' );
2112
				} elseif ( 'decimal' === $attributes['type'] ) {
2113
					$vartype = '%d';
2114
					$value   = number_format( pods_var( $field, 'post', 0 ), 2, '.', '' );
2115
				} elseif ( 'related' === $attributes['type'] ) {
2116
					if ( is_array( pods_var( $field, 'post', '' ) ) ) {
2117
						$value = implode( ',', pods_var( $field, 'post', '' ) );
2118
					} else {
2119
						$value = pods_var( $field, 'post', '' );
2120
					}
2121
				} else {
2122
					$value = pods_var( $field, 'post', '' );
2123
				}//end if
2124
			}//end if
2125
2126
			if ( isset( $attributes['custom_save'] ) && false !== $attributes['custom_save'] && is_callable( $attributes['custom_save'] ) ) {
2127
				$value = call_user_func_array(
2128
					$attributes['custom_save'], array(
2129
						$value,
2130
						$field,
2131
						$attributes,
2132
						&$this,
2133
					)
2134
				);
2135
			}
2136
2137
			$field_sql[]    = "`$field`=$vartype";
2138
			$values[]       = $value;
2139
			$data[ $field ] = $value;
2140
		}//end foreach
2141
		$field_sql = implode( ',', $field_sql );
2142
		if ( false === $insert && 0 < $this->id ) {
2143
			$this->insert_id = $this->id;
0 ignored issues
show
Bug introduced by
The property insert_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
2144
			$values[]        = $this->id;
2145
			$check           = $wpdb->query( $wpdb->prepare( "UPDATE $this->sql['table'] SET $field_sql WHERE id=%d", $values ) );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
2146
		} else {
2147
			$check = $wpdb->query( $wpdb->prepare( "INSERT INTO $this->sql['table'] SET $field_sql", $values ) );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
2148
		}
2149
		if ( $check ) {
2150
			if ( 0 == $this->insert_id ) {
2151
				$this->insert_id = $wpdb->insert_id;
2152
			}
2153
			$this->message( sprintf( __( '<strong>Success!</strong> %1\$s %2\$s successfully.', 'pods' ), $this->item, $action ) );
2154
		} else {
2155
			$this->error( sprintf( __( '<strong>Error:</strong> %1\$s has not been %2\$s.', 'pods' ), $this->item, $action ) );
2156
		}
2157
		$this->do_hook( 'post_save', $this->insert_id, $data, $insert );
2158
	}
2159
2160
	/**
2161
	 * @param null $id
2162
	 *
2163
	 * @return bool|mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
2164
	 */
2165
	public function delete( $id = null ) {
2166
2167
		$this->do_hook( 'pre_delete', $id );
2168
2169
		if ( false !== $this->callback_action( 'delete', $id ) ) {
2170
			return null;
2171
		}
2172
2173
		$id = pods_absint( $id );
2174
2175
		if ( empty( $id ) ) {
2176
			$id = pods_absint( $this->id );
2177
		}
2178
2179
		if ( $id < 1 ) {
2180
			return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods' ) );
2181
		}
2182
2183
		if ( false === $id ) {
2184
			$id = $this->id;
2185
		}
2186
2187
		if ( is_object( $this->pod ) ) {
2188
			$check = $this->pod->delete( $id );
2189
		} else {
2190
			$check = $this->pods_data->delete( $this->sql['table'], array( $this->sql['field_id'] => $id ) );
2191
		}
2192
2193
		if ( $check ) {
2194
			$this->message( sprintf( __( '<strong>Deleted:</strong> %s has been deleted.', 'pods' ), $this->item ) );
2195
		} else {
2196
			$this->error( sprintf( __( '<strong>Error:</strong> %s has not been deleted.', 'pods' ), $this->item ) );
2197
		}
2198
2199
		$this->do_hook( 'post_delete', $id );
2200
	}
2201
2202
	/**
2203
	 * Callback for deleting items in bulk
2204
	 */
2205
	public function delete_bulk() {
2206
2207
		$this->do_hook( 'pre_delete_bulk' );
2208
2209
		if ( 1 != pods_var( 'deleted_bulk', 'get', 0 ) ) {
2210
			$ids = $this->bulk;
2211
2212
			$success = false;
2213
2214
			if ( ! empty( $ids ) ) {
2215
				$ids = (array) $ids;
2216
2217
				foreach ( $ids as $id ) {
2218
					$id = pods_absint( $id );
2219
2220
					if ( empty( $id ) ) {
2221
						continue;
2222
					}
2223
2224
					if ( $callback = $this->callback( 'delete', $id ) ) {
2225
						$check = $callback;
2226
					} elseif ( is_object( $this->pod ) ) {
2227
						$check = $this->pod->delete( $id );
2228
					} else {
2229
						$check = $this->pods_data->delete( $this->sql['table'], array( $this->sql['field_id'] => $id ) );
2230
					}
2231
2232
					if ( $check ) {
2233
						$success = true;
2234
					}
2235
				}
2236
			}//end if
2237
2238
			if ( $success ) {
2239
				pods_redirect(
2240
					pods_query_arg(
2241
						array(
2242
							'action_bulk'  => 'delete',
2243
							'deleted_bulk' => 1,
2244
						), array(
2245
							'page',
2246
							'lang',
2247
							'action',
2248
							'id',
2249
						)
2250
					)
2251
				);
2252
			} else {
2253
				$this->error( sprintf( __( '<strong>Error:</strong> %s has not been deleted.', 'pods' ), $this->item ) );
2254
			}
2255
		} else {
2256
			$this->message( sprintf( __( '<strong>Deleted:</strong> %s have been deleted.', 'pods' ), $this->items ) );
2257
2258
			unset( $_GET['deleted_bulk'] );
2259
		}//end if
2260
2261
		$this->action_bulk = false;
2262
		unset( $_GET['action_bulk'] );
2263
2264
		$this->do_hook( 'post_delete_bulk' );
2265
2266
		$this->manage();
2267
	}
2268
2269
	/**
2270
	 * Callback for exporting items in bulk
2271
	 */
2272
	public function export_bulk() {
2273
2274
		if ( ! empty( $_POST['bulk_export_type'] ) ) {
2275
			if ( ! empty( $_POST['bulk_export_fields'] ) ) {
2276
				$export_fields = $_POST['bulk_export_fields'];
2277
2278
				$this->fields['export '] = array();
2279
2280
				if ( $this->pod ) {
2281
					$fields = $this->pod->fields();
2282
2283
					foreach ( $fields as $field ) {
2284
						if ( in_array( $field['name'], $export_fields ) ) {
2285
							$this->fields['export'][] = $field;
2286
						}
2287
					}
2288
				}
2289
			}
2290
2291
			// Set up where clause so that export function finds it
2292
			if ( ! empty( $_POST['action_bulk_ids'] ) ) {
2293
				$ids = (array) explode( ',', $_POST['action_bulk_ids'] );
2294
				$ids = array_map( 'absint', $ids );
2295
				$ids = array_filter( $ids );
2296
2297
				if ( ! empty( $ids ) ) {
2298
					$ids = implode( ', ', $ids );
2299
2300
					$this->where = array(
2301
						'manage' => '`' . pods_sanitize( $this->sql['field_id'] ) . '` IN ( ' . $ids . ' )',
2302
					);
2303
				}
2304
			}
2305
2306
			$this->export( $_POST['bulk_export_type'] );
2307
2308
			// Cleanup since export function calls get_data before returning
2309
			$this->action_bulk = '';
2310
			$this->where       = array();
2311
			$this->data        = false;
2312
2313
			$_GET['action_bulk_ids'] = '';
2314
2315
			$this->manage();
2316
		} else {
2317
			$this->export_fields_form();
2318
		}//end if
2319
2320
	}
2321
2322
	/**
2323
	 * Select the pods fields to be exported
2324
	 */
2325
	public function export_fields_form() {
2326
2327
		?>
2328
		<div class="wrap pods-admin pods-ui">
2329
			<h2><?php echo __( 'Choose Export Fields', 'pods' ); ?></h2>
2330
2331
			<form method="post" id="pods_admin_ui_export_form">
2332
				<?php
2333
				// Avoid a bunch of inputs if there's a lot selected
2334
				if ( ! empty( $_REQUEST['action_bulk_ids'] ) ) {
2335
					$_GET['action_bulk_ids'] = implode( ',', (array) $_REQUEST['action_bulk_ids'] );
2336
				}
2337
2338
				$this->hidden_vars();
2339
				?>
2340
2341
				<ul>
2342
					<?php foreach ( $this->pod->fields() as $field_name => $field ) { ?>
2343
						<li>
2344
							<label for="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>">
2345
								<input type="checkbox" name="bulk_export_fields[]" id="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>" value="<?php echo esc_attr( $field['name'] ); ?>" />
2346
								<?php echo esc_html( $field['label'] ); ?>
2347
							</label>
2348
						</li>
2349
					<?php } ?>
2350
				</ul>
2351
2352
				<p class="submit">
2353
					<?php _e( 'Export as:', 'pods' ); ?>&nbsp;&nbsp;
2354
					<?php foreach ( $this->export['formats'] as $format => $separator ) { ?>
2355
						<input type="submit" id="export_type_<?php echo esc_attr( strtoupper( $format ) ); ?>" value=" <?php echo esc_attr( strtoupper( $format ) ); ?> " name="bulk_export_type" class="button-primary" />
2356
					<?php } ?>
2357
				</p>
2358
			</form>
2359
		</div>
2360
		<?php
2361
2362
	}
2363
2364
	/**
2365
	 * @param null $export_type
2366
	 */
2367
	public function export( $export_type = null ) {
2368
2369
		if ( empty( $export_type ) ) {
2370
			$export_type = pods_var( 'export_type', 'get', 'csv' );
2371
		}
2372
2373
		$export_type = trim( strtolower( $export_type ) );
2374
2375
		$type = $export_type;
2376
2377
		$delimiter = ',';
2378
2379
		if ( ! empty( $this->export['formats'][ $export_type ] ) ) {
2380
			$delimiter = $this->export['formats'][ $export_type ];
2381
		}
2382
2383
		$columns = array(
2384
			$this->sql['field_id'] => 'ID',
2385
		);
2386
2387
		if ( empty( $this->fields['export'] ) && $this->pod && ! empty( $this->pod->fields ) ) {
2388
			$this->fields['export'] = $this->pod->fields;
2389
		}
2390
2391
		if ( ! empty( $this->fields['export'] ) ) {
2392
			foreach ( $this->fields['export'] as $field ) {
2393
				$columns[ $field['name'] ] = $field['label'];
2394
			}
2395
		}
2396
2397
		$params = array(
2398
			'full'      => true,
2399
			'flatten'   => true,
2400
			'fields'    => array_keys( $columns ),
2401
			'type'      => $type,
2402
			'delimiter' => $delimiter,
2403
			'columns'   => $columns,
2404
		);
2405
2406
		$items = $this->get_data( $params );
2407
2408
		$data = array(
2409
			'columns' => $columns,
2410
			'items'   => $items,
2411
			'fields'  => $this->fields['export'],
2412
		);
2413
2414
		$migrate = pods_migrate( $type, $delimiter, $data );
2415
2416
		$migrate->export();
2417
2418
		$save_params = array(
2419
			'attach' => true,
2420
		);
2421
2422
		$export_file = $migrate->save( $save_params );
2423
2424
		$this->message( sprintf( __( '<strong>Success:</strong> Your export is ready, you can download it <a href="%s" target="_blank">here</a>', 'pods' ), $export_file ) );
2425
2426
		// echo '<script type="text/javascript">window.open("' . esc_js( $export_file ) . '");</script>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2427
		$this->get_data();
2428
	}
2429
2430
	/**
2431
	 * @param $field
2432
	 *
2433
	 * @return array|bool|mixed|null
2434
	 */
2435
	public function get_field( $field ) {
2436
2437
		$value = null;
2438
2439
		// use PodsData to get field
2440
		if ( $callback = $this->callback( 'get_field', $field ) ) {
2441
			return $callback;
2442
		}
2443
2444
		if ( isset( $this->row[ $field ] ) ) {
2445
			$value = $this->row[ $field ];
2446
		} elseif ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2447
			if ( 'Pod' == get_class( $this->pod ) ) {
2448
				$value = $this->pod->get_field( $field );
0 ignored issues
show
Documentation Bug introduced by
The method get_field does not exist on object<Pod>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
2449
			} else {
2450
				$value = $this->pod->field( $field );
2451
			}
2452
		}
2453
2454
		return $this->do_hook( 'get_field', $value, $field );
2455
	}
2456
2457
	/**
2458
	 * Get find() params based on current UI action
2459
	 *
2460
	 * @param null|array  $params
2461
	 * @param null|string $action
2462
	 *
2463
	 * @return array|mixed|void
2464
	 */
2465
	public function get_params( $params = null, $action = null ) {
2466
2467
		if ( null === $action ) {
2468
			$action = $this->action;
2469
		}
2470
2471
		$defaults = array(
2472
			'full'    => false,
2473
			'flatten' => true,
2474
			'fields'  => null,
2475
			'type'    => '',
2476
		);
2477
2478
		if ( ! empty( $params ) && is_array( $params ) ) {
2479
			$params = (object) array_merge( $defaults, $params );
2480
		} else {
2481
			$params = (object) $defaults;
2482
		}
2483
2484
		if ( ! in_array( $action, array( 'manage', 'reorder' ) ) ) {
2485
			$action = 'manage';
2486
		}
2487
2488
		$params_override = false;
2489
2490
		$orderby = array();
2491
2492
		$limit = $this->limit;
2493
2494
		$sql = null;
2495
2496
		if ( 'reorder' === $this->action ) {
2497
			if ( ! empty( $this->reorder['orderby'] ) ) {
2498
				$orderby[ $this->reorder['orderby'] ] = $this->reorder['orderby_dir'];
2499
			} else {
2500
				$orderby[ $this->reorder['on'] ] = $this->reorder['orderby_dir'];
2501
			}
2502
2503
			if ( ! empty( $this->reorder['limit'] ) ) {
2504
				$limit = $this->reorder['limit'];
2505
			}
2506
2507
			if ( ! empty( $this->reorder['sql'] ) ) {
2508
				$sql = $this->reorder['sql'];
2509
			}
2510
		}
2511
2512
		if ( ! empty( $this->orderby ) ) {
2513
			$this->orderby = (array) $this->orderby;
2514
2515
			foreach ( $this->orderby as $order ) {
2516
				if ( false !== strpos( $order, ' ' ) ) {
2517
					$orderby[] = $order;
2518
				} elseif ( ! isset( $orderby[ $order ] ) ) {
2519
					$orderby[ $order ] = $this->orderby_dir;
2520
				}
2521
			}
2522
		}
2523
2524
		if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2525
			$find_params = array(
2526
				'where'               => pods_v( $action, $this->where, null, true ),
2527
				'orderby'             => $orderby,
2528
				'page'                => (int) $this->page,
2529
				'pagination'          => true,
2530
				'limit'               => (int) $limit,
2531
				'search'              => $this->searchable,
2532
				'search_query'        => $this->search,
2533
				'search_across'       => $this->search_across,
2534
				'search_across_picks' => $this->search_across_picks,
2535
				'filters'             => $this->filters,
2536
				'sql'                 => $sql,
2537
			);
2538
2539
			$params_override = true;
2540
		} else {
2541
			$find_params = array(
2542
				'table'        => $this->sql['table'],
2543
				'id'           => $this->sql['field_id'],
2544
				'index'        => $this->sql['field_index'],
2545
				'where'        => pods_v( $action, $this->where, null, true ),
2546
				'orderby'      => $orderby,
2547
				'page'         => (int) $this->page,
2548
				'pagination'   => true,
2549
				'limit'        => (int) $limit,
2550
				'search'       => $this->searchable,
2551
				'search_query' => $this->search,
2552
				'fields'       => $this->fields['search'],
2553
				'sql'          => $sql,
2554
			);
2555
2556
			if ( ! empty( $this->sql['select'] ) ) {
2557
				$find_params['select'] = $this->sql['select'];
2558
			}
2559
		}//end if
2560
2561
		if ( empty( $find_params['where'] ) && $this->restricted( $this->action ) ) {
2562
			$find_params['where'] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
2563
		}
2564
2565
		if ( $params_override ) {
2566
			$find_params = array_merge( $find_params, (array) $this->params );
2567
		}
2568
2569
		if ( $params->full ) {
2570
			$find_params['limit'] = - 1;
2571
		}
2572
2573
		$find_params = apply_filters( 'pods_ui_get_params', $find_params, ( is_object( $this->pod ) ? $this->pod->pod : null ), $this );
2574
2575
		/**
2576
		 * Filter Pods::find() parameters to make it more easily extended by plugins and developers.
2577
		 *
2578
		 * @param array  $find_params Parameters used with Pods::find()
2579
		 * @param string $action      Current action
2580
		 * @param PodsUI $this        PodsUI instance
2581
		 *
2582
		 * @since 2.6.8
2583
		 */
2584
		$find_params = apply_filters( 'pods_ui_get_find_params', $find_params, $action, $this );
2585
2586
		// Debug purposes
2587
		if ( 1 == pods_v( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
2588
			pods_debug( $find_params );
2589
		}
2590
2591
		return $find_params;
2592
	}
2593
2594
	/**
2595
	 * @param null $params
2596
	 *
2597
	 * @return bool
2598
	 * @internal param bool $full Whether to get ALL data or use pagination
2599
	 */
2600
	public function get_data( $params = null ) {
2601
2602
		$action = $this->action;
2603
2604
		$defaults = array(
2605
			'full'    => false,
2606
			'flatten' => true,
2607
			'fields'  => null,
2608
			'type'    => '',
2609
		);
2610
2611
		if ( ! empty( $params ) && is_array( $params ) ) {
2612
			$params = (object) array_merge( $defaults, $params );
2613
		} else {
2614
			$params = (object) $defaults;
2615
		}
2616
2617
		if ( ! in_array( $action, array( 'manage', 'reorder' ) ) ) {
2618
			$action = 'manage';
2619
		}
2620
2621
		$find_params = $this->get_params( $params, $action );
2622
2623
		if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2624
			$this->pod->find( $find_params );
0 ignored issues
show
Bug introduced by
The method find does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2625
2626
			if ( ! $params->full ) {
2627
				$data = $this->pod->data();
0 ignored issues
show
Bug introduced by
The method data does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2628
2629
				$this->data = $data;
2630
2631
				if ( ! empty( $this->data ) ) {
2632
					$this->data_keys = array_keys( $this->data );
2633
				}
2634
2635
				$this->total       = $this->pod->total();
0 ignored issues
show
Bug introduced by
The method total does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2636
				$this->total_found = $this->pod->total_found();
0 ignored issues
show
Bug introduced by
The method total_found does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2637
			} else {
2638
				$this->data_full = array();
2639
2640
				$export_params = array(
2641
					'fields'  => $params->fields,
2642
					'flatten' => true,
2643
				);
2644
2645
				if ( in_array( $params->type, array( 'json', 'xml' ) ) ) {
2646
					$export_params['flatten'] = false;
2647
				}
2648
2649
				$export_params = $this->do_hook( 'export_options', $export_params, $params );
2650
2651
				while ( $this->pod->fetch() ) {
0 ignored issues
show
Bug introduced by
The method fetch does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2652
					$this->data_full[ $this->pod->id() ] = $this->pod->export( $export_params );
0 ignored issues
show
Bug introduced by
The method id does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method export does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2653
				}
2654
2655
				$this->pod->reset();
0 ignored issues
show
Bug introduced by
The method reset does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2656
2657
				return $this->data_full;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->data_full; (array) is incompatible with the return type documented by PodsUI::get_data of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
2658
			}//end if
2659
		} else {
2660
			if ( ! empty( $this->data ) ) {
2661
				return $this->data;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->data; of type boolean|array adds the type array to the return on line 2661 which is incompatible with the return type documented by PodsUI::get_data of type boolean.
Loading history...
2662
			}
2663
2664
			if ( empty( $this->sql['table'] ) ) {
2665
				return $this->data;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->data; of type boolean|array adds the type array to the return on line 2665 which is incompatible with the return type documented by PodsUI::get_data of type boolean.
Loading history...
2666
			}
2667
2668
			$this->pods_data->select( $find_params );
2669
2670
			if ( ! $params->full ) {
2671
				$this->data = $this->pods_data->data;
2672
2673
				if ( ! empty( $this->data ) ) {
2674
					$this->data_keys = array_keys( $this->data );
2675
				}
2676
2677
				$this->total       = $this->pods_data->total();
2678
				$this->total_found = $this->pods_data->total_found();
2679
			} else {
2680
				$this->data_full = $this->pods_data->data;
2681
2682
				if ( ! empty( $this->data_full ) ) {
2683
					$this->data_keys = array_keys( $this->data_full );
2684
				}
2685
2686
				return $this->data_full;
2687
			}
2688
		}//end if
2689
2690
		return $this->data;
2691
	}
2692
2693
	/**
2694
	 * Sort out data alphabetically by a key
2695
	 */
2696
	public function sort_data() {
2697
2698
		// only do this if we have a default orderby
2699
		if ( isset( $this->orderby['default'] ) ) {
2700
			$orderby = $this->orderby['default'];
2701
			foreach ( $this->data as $k => $v ) {
0 ignored issues
show
Bug introduced by
The expression $this->data of type boolean|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
2702
				$sorter[ $k ] = strtolower( $v[ $orderby ] );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sorter was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sorter = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2703
			}
2704
			if ( $this->orderby_dir == 'ASC' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
2705
				asort( $sorter );
2706
			} else {
2707
				arsort( $sorter );
2708
			}
2709
			foreach ( $sorter as $key => $val ) {
2710
				$intermediary[] = $this->data[ $key ];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$intermediary was never initialized. Although not strictly required by PHP, it is generally a good practice to add $intermediary = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2711
			}
2712
			if ( isset( $intermediary ) ) {
2713
				$this->data      = $intermediary;
2714
				$this->data_keys = array_keys( $this->data );
2715
			}
2716
		}
2717
	}
2718
2719
	/**
2720
	 * @param int  $counter
2721
	 * @param null $method
2722
	 *
2723
	 * @return array
2724
	 */
2725
	public function get_row( &$counter = 0, $method = null ) {
2726
2727
		if ( ! empty( $this->row ) && 0 < (int) $this->id && 'table' !== $method ) {
2728
			return $this->row;
2729
		}
2730
2731
		if ( is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2732
			$this->row = $this->pod->fetch();
0 ignored issues
show
Bug introduced by
The method fetch does only exist in Pods, but not in Pod.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
2733
		} else {
2734
			$this->row = false;
2735
2736
			if ( ! empty( $this->data ) ) {
2737
				if ( empty( $this->data_keys ) || count( $this->data ) != count( $this->data_keys ) ) {
2738
					$this->data_keys = array_keys( $this->data );
2739
				}
2740
2741
				if ( count( $this->data ) == $this->total && isset( $this->data_keys[ $counter ] ) && isset( $this->data[ $this->data_keys[ $counter ] ] ) ) {
2742
					$this->row = $this->data[ $this->data_keys[ $counter ] ];
2743
2744
					$counter ++;
2745
				}
2746
			}
2747
2748
			if ( false === $this->row && 0 < (int) $this->id && ! empty( $this->sql['table'] ) ) {
2749
				$this->pods_data->select(
2750
					array(
2751
						'table' => $this->sql['table'],
2752
						'where' => '`' . pods_sanitize( $this->sql['field_id'] ) . '` = ' . (int) $this->id,
2753
						'limit' => 1,
2754
					)
2755
				);
2756
2757
				$this->row = $this->pods_data->fetch();
2758
			}
2759
		}//end if
2760
2761
		return $this->row;
2762
	}
2763
2764
	/**
2765
	 * @param bool $reorder
2766
	 *
2767
	 * @return mixed|null
2768
	 */
2769
	public function manage( $reorder = false ) {
2770
		if ( false !== $this->callback_action( 'manage', $reorder ) ) {
2771
			return null;
2772
		}
2773
2774
		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 ) ) {
2775
			if ( empty( $_REQUEST[ '_wpnonce' . $this->num ] ) || false === wp_verify_nonce( $_REQUEST[ '_wpnonce' . $this->num ], 'pods-ui-action-bulk' ) ) {
2776
				pods_message( __( 'Invalid bulk request, please try again.', 'pods' ) );
2777
			} elseif ( false !== $this->callback_bulk( $this->action_bulk, $this->bulk ) ) {
2778
				return null;
2779
			} elseif ( 'delete' === $this->action_bulk ) {
2780
				$this->delete_bulk();
2781
2782
				return;
2783
			} elseif ( 'export' === $this->action_bulk ) {
2784
				$this->export_bulk();
2785
2786
				return;
2787
			}
2788
		}
2789
2790
		$this->screen_meta();
2791
2792
		if ( true === $reorder ) {
2793
			wp_enqueue_script( 'jquery-ui-sortable' );}
2794
		?>
2795
	<div class="wrap pods-admin pods-ui">
2796
		<div id="icon-edit-pages" class="icon32"
2797
		<?php
2798
		if ( false !== $this->icon ) {
2799
?>
2800
 style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
2801
		<h2>
2802
			<?php
2803
			if ( true === $reorder ) {
2804
				echo wp_kses_post( $this->header['reorder'] );
2805
2806
				if ( ! in_array( 'manage', $this->actions_disabled ) && ! in_array( 'manage', $this->actions_hidden ) && ! $this->restricted( 'manage' ) ) {
2807
					$link = pods_query_arg(
2808
						array(
2809
							'action' . $this->num => 'manage',
2810
							'id' . $this->num     => '',
2811
						), self::$allowed, $this->exclusion()
2812
					);
2813
2814
					if ( ! empty( $this->action_links['manage'] ) ) {
2815
						$link = $this->action_links['manage'];
2816
					}
2817
				?>
2818
				<small>(<a href="<?php echo esc_url( $link ); ?>">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading['manage'] ); ?></a>)</small>
2819
				<?php
2820
				}
2821
			} else {
2822
				echo wp_kses_post( $this->header['manage'] );}
2823
2824
			if ( ! in_array( 'add', $this->actions_disabled ) && ! in_array( 'add', $this->actions_hidden ) && ! $this->restricted( 'add' ) ) {
2825
				$link = pods_query_arg(
2826
					array(
2827
						'action' . $this->num => 'add',
2828
						'id' . $this->num     => '',
2829
						'do' . $this->num     => '',
2830
					), self::$allowed, $this->exclusion()
2831
				);
2832
2833
				if ( ! empty( $this->action_links['add'] ) ) {
2834
					$link = $this->action_links['add'];}
2835
				?>
2836
				<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label['add_new'] ); ?></a>
2837
				<?php
2838
			}
2839
			if ( ! in_array( 'reorder', $this->actions_disabled ) && ! in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder['on'] && ! $this->restricted( 'reorder' ) ) {
2840
				$link = pods_query_arg( array( 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() );
2841
2842
				if ( ! empty( $this->action_links['reorder'] ) ) {
2843
					$link = $this->action_links['reorder'];}
2844
				?>
2845
				<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label['reorder'] ); ?></a>
2846
				<?php
2847
			}
2848
			?>
2849
		</h2>
2850
2851
		<form id="posts-filter" action="" method="get">
2852
			<?php
2853
				$excluded_filters = array(
2854
					'search' . $this->num,
2855
					'pg' . $this->num,
2856
					'action' . $this->num,
2857
					'action_bulk' . $this->num,
2858
					'action_bulk_ids' . $this->num,
2859
					'_wpnonce' . $this->num,
2860
				);
2861
2862
				$filters = $this->filters;
2863
2864
			foreach ( $filters as $k => $filter ) {
2865
				if ( isset( $this->pod->fields[ $filter ] ) ) {
2866
					$filter_field = $this->pod->fields[ $filter ];
2867
				} elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
2868
					$filter_field = $this->fields['manage'][ $filter ];
2869
				} else {
2870
					unset( $filters[ $k ] );
2871
					continue;
2872
				}
2873
2874
				if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
2875
					if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) {
2876
						unset( $filters[ $k ] );
2877
						continue;
2878
					}
2879
				} elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) {
2880
					unset( $filters[ $k ] );
2881
					continue;
2882
				}
2883
2884
				$excluded_filters[] = 'filter_' . $filter . '_start';
2885
				$excluded_filters[] = 'filter_' . $filter . '_end';
2886
				$excluded_filters[] = 'filter_' . $filter;
2887
			}//end foreach
2888
2889
				$get = $_GET;
2890
2891
			foreach ( $get as $k => $v ) {
2892
				if ( is_array( $v ) || in_array( $k, $excluded_filters ) || strlen( $v ) < 1 ) {
2893
					continue;}
2894
			?>
2895
			<input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
2896
			<?php
2897
			}
2898
2899
			if ( false !== $this->callback( 'header', $reorder ) ) {
2900
				return null;
2901
			}
2902
2903
			if ( false === $this->data ) {
2904
				$this->get_data();} elseif ( $this->sortable ) {
2905
				// we have the data already as an array
2906
				$this->sort_data();}
2907
2908
				if ( ! in_array( 'export', $this->actions_disabled ) && 'export' === $this->action ) {
2909
					$this->export();}
2910
2911
				if ( ( ! empty( $this->data ) || false !== $this->search || ( $this->filters_enhanced && ! empty( $this->views ) ) ) && ( ( $this->filters_enhanced && ! empty( $this->views ) ) || false !== $this->searchable ) ) {
2912
					if ( $this->filters_enhanced ) {
2913
						$this->filters();} else {
2914
										?>
2915
										<p class="search-box" align="right">
2916
										<?php
2917
										$excluded_filters = array( 'search' . $this->num, 'pg' . $this->num );
2918
2919
										foreach ( $this->filters as $filter ) {
2920
											$excluded_filters[] = 'filter_' . $filter . '_start';
2921
											$excluded_filters[] = 'filter_' . $filter . '_end';
2922
											$excluded_filters[] = 'filter_' . $filter;
2923
										}
2924
2925
										$this->hidden_vars( $excluded_filters );
2926
2927
										foreach ( $this->filters as $filter ) {
2928
											if ( isset( $this->pod->fields[ $filter ] ) ) {
2929
												$filter_field = $this->pod->fields[ $filter ];
2930
											} elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
2931
												$filter_field = $this->fields['manage'][ $filter ];
2932
											} else {
2933
												continue;
2934
											}
2935
2936
											if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
2937
												$start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
2938
												$end   = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
2939
2940
												// override default value
2941
												$filter_field['options']['default_value']                          = '';
2942
												$filter_field['options'][ $filter_field['type'] . '_allow_empty' ] = 1;
2943
2944
												if ( ! empty( $start ) && ! in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
2945
													$start = PodsForm::field_method( $filter_field['type'], 'convert_date', $start, 'n/j/Y' );}
2946
2947
												if ( ! empty( $end ) && ! in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
2948
													$end = PodsForm::field_method( $filter_field['type'], 'convert_date', $end, 'n/j/Y' );}
2949
										?>
2950
											<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
2951
							<?php echo esc_html( $filter_field['label'] ); ?>
2952
						</label>
2953
						<?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field['type'], $filter_field ); ?>
2954
2955
						<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">
2956
							to
2957
						</label>
2958
					<?php
2959
							echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field['type'], $filter_field );
2960
											} elseif ( 'pick' === $filter_field['type'] ) {
2961
												$value = pods_var_raw( 'filter_' . $filter, 'get' );
2962
2963
												if ( strlen( $value ) < 1 ) {
2964
													$value = pods_var_raw( 'filter_default', $filter_field );}
2965
2966
												// override default value
2967
												$filter_field['options']['default_value'] = '';
2968
2969
												$filter_field['options']['pick_format_type']   = 'single';
2970
												$filter_field['options']['pick_format_single'] = 'dropdown';
2971
2972
												$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 );
2973
												$filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
2974
2975
												$options = array_merge( $filter_field, $filter_field['options'] );
2976
										?>
2977
											<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
2978
							<?php echo esc_html( $filter_field['label'] ); ?>
2979
						</label>
2980
					<?php
2981
							echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
2982
											} elseif ( 'boolean' === $filter_field['type'] ) {
2983
												$value = pods_var_raw( 'filter_' . $filter, 'get', '' );
2984
2985
												if ( strlen( $value ) < 1 ) {
2986
													$value = pods_var_raw( 'filter_default', $filter_field );}
2987
2988
												// override default value
2989
												$filter_field['options']['default_value'] = '';
2990
2991
												$filter_field['options']['pick_format_type']   = 'single';
2992
												$filter_field['options']['pick_format_single'] = 'dropdown';
2993
2994
												$filter_field['options']['pick_object'] = 'custom-simple';
2995
												$filter_field['options']['pick_custom'] = array(
2996
													'1' => pods_var_raw( 'boolean_yes_label', $filter_field['options'], __( 'Yes', 'pods' ), null, true ),
2997
													'0' => pods_var_raw( 'boolean_no_label', $filter_field['options'], __( 'No', 'pods' ), null, true ),
0 ignored issues
show
introduced by
Detected usage of 0, possible slow query.
Loading history...
2998
												);
2999
3000
												$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 );
3001
												$filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
3002
3003
												$options = array_merge( $filter_field, $filter_field['options'] );
3004
										?>
3005
											<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3006
							<?php echo esc_html( $filter_field['label'] ); ?>
3007
						</label>
3008
					<?php
3009
							echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
3010
											} else {
3011
												$value = pods_var_raw( 'filter_' . $filter, 'get' );
3012
3013
												if ( strlen( $value ) < 1 ) {
3014
													$value = pods_var_raw( 'filter_default', $filter_field );}
3015
3016
												// override default value
3017
												$filter_field['options']['default_value'] = '';
3018
3019
												$options                 = array();
3020
												$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 );
3021
												$options['input_helper'] = pods_var_raw( 'ui_input_helper', $options, $options['input_helper'], null, true );
3022
										?>
3023
											<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3024
							<?php echo esc_html( $filter_field['label'] ); ?>
3025
						</label>
3026
					<?php
3027
							echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options );
3028
											}//end if
3029
										}//end foreach
3030
3031
										if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
3032
										?>
3033
											&nbsp;&nbsp; <label<?php echo ( empty( $this->filters ) ) ? ' class="screen-reader-text"' : ''; ?> for="page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
3034
						<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
3035
					<?php
3036
										} else {
3037
											echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
3038
										}
3039
										?>
3040
										<?php echo PodsForm::submit_button( $this->header['search'], 'button', false, false, array( 'id' => 'search' . $this->num . '-submit' ) ); ?>
3041
					<?php
3042
					if ( 0 < strlen( $this->search ) ) {
3043
						$clear_filters = array(
3044
							'search' . $this->num => false,
3045
						);
3046
3047
						foreach ( $this->filters as $filter ) {
3048
							$clear_filters[ 'filter_' . $filter . '_start' ] = false;
3049
							$clear_filters[ 'filter_' . $filter . '_end' ]   = false;
3050
							$clear_filters[ 'filter_' . $filter ]            = false;
3051
						}
3052
						?>
3053
						<br class="clear" />
3054
						<small>[<a href="<?php echo esc_url( pods_query_arg( $clear_filters, array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'limit' . $this->num, 'page' ), $this->exclusion() ) ); ?>"><?php _e( 'Reset Filters', 'pods' ); ?></a>]</small>
3055
						<br class="clear" />
3056
						<?php
3057
					}
3058
					?>
3059
					</p>
3060
					<?php
3061
						}//end if
3062
				} else {
3063
					?>
3064
					<br class="clear" />
3065
					<?php
3066
				}//end if
3067
3068
				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 ) ) {
3069
					?>
3070
					<div class="tablenav">
3071
					<?php
3072
					if ( ! empty( $this->data ) && ! empty( $this->actions_bulk ) ) {
3073
				?>
3074
					<div class="alignleft actions">
3075
						<?php wp_nonce_field( 'pods-ui-action-bulk', '_wpnonce' . $this->num, false ); ?>
3076
3077
						<select name="action_bulk<?php echo esc_attr( $this->num ); ?>">
3078
							<option value="-1" selected="selected"><?php _e( 'Bulk Actions', 'pods' ); ?></option>
3079
3080
							<?php
3081
							foreach ( $this->actions_bulk as $action => $action_data ) {
3082
								if ( in_array( $action, $this->actions_hidden ) || in_array( $action, $this->actions_hidden ) ) {
3083
									continue;}
3084
3085
								if ( ! isset( $action_data['label'] ) ) {
3086
									$action_data['label'] = ucwords( str_replace( '_', ' ', $action ) );}
3087
							?>
3088
							<option value="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $action_data['label'] ); ?></option>
3089
							<?php
3090
							}
3091
							?>
3092
						</select>
3093
3094
						<input type="submit" id="doaction_bulk<?php echo esc_attr( $this->num ); ?>" class="button-secondary action" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
3095
					</div>
3096
				<?php
3097
					}//end if
3098
3099
					if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
3100
						?>
3101
						<div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
3102
							<?php $this->pagination( 1 ); ?>
3103
						</div>
3104
						<?php
3105
					}
3106
3107
					if ( true === $reorder ) {
3108
						$link = pods_query_arg(
3109
							array(
3110
								'action' . $this->num => 'manage',
3111
								'id' . $this->num     => '',
3112
							), self::$allowed, $this->exclusion()
3113
						);
3114
3115
						if ( ! empty( $this->action_links['manage'] ) ) {
3116
							$link = $this->action_links['manage'];
3117
						}
3118
						?>
3119
						<input type="button" value="<?php esc_attr_e( 'Update Order', 'pods' ); ?>" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" />
3120
						<input type="button" value="<?php esc_attr_e( 'Cancel', 'pods' ); ?>" class="button" onclick="document.location='<?php echo esc_js( $link ); ?>';" />
3121
					</form>
3122
				<?php
3123
					} elseif ( ! in_array( 'export', $this->actions_disabled ) && ! in_array( 'export', $this->actions_hidden ) ) {
3124
						?>
3125
						<div class="alignleft actions">
3126
							<input type="button" value="<?php echo esc_attr( sprintf( __( 'Export all %s', 'pods' ), $this->items ) ); ?>" class="button" onclick="document.location=';
3127
																	<?php
3128
																	echo pods_slash(
3129
																		pods_query_arg(
3130
																			array(
3131
																				'action_bulk' . $this->num => 'export',
3132
																				'_wpnonce' => wp_create_nonce( 'pods-ui-action-bulk' ),
3133
																			), self::$allowed, $this->exclusion()
3134
																		)
3135
																	);
3136
							?>
3137
							';" />
3138
						</div>
3139
						<?php
3140
					}//end if
3141
					?>
3142
					<br class="clear" />
3143
					</div>
3144
					<?php
3145
				} else {
3146
					?>
3147
					<br class="clear" />
3148
					<?php
3149
				}//end if
3150
			?>
3151
			<div class="clear"></div>
3152
			<?php
3153
			if ( empty( $this->data ) && false !== $this->default_none && false === $this->search ) {
3154
				?>
3155
				<p><?php _e( 'Please use the search filter(s) above to display data', 'pods' ); ?>
3156
								<?php
3157
								if ( $this->export ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->export of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
3158
				?>
3159
				, <?php _e( 'or click on an Export to download a full copy of the data', 'pods' ); ?><?php } ?>.</p>
3160
				<?php
3161
			} else {
3162
				$this->table( $reorder );}
3163
			if ( ! empty( $this->data ) ) {
3164
				if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
3165
					?>
3166
					<div class="tablenav">
3167
						<div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
3168
							<?php $this->pagination( 0 ); ?>
3169
							<br class="clear" />
3170
						</div>
3171
					</div>
3172
					<?php
3173
				}
3174
			}
3175
3176
			?>
3177
		</form>
3178
	</div>
3179
	<?php
3180
	if ( $this->filters_enhanced ) {
3181
		$this->filters_popup();}
3182
	}
3183
3184
	public function filters() {
3185
3186
		include_once ABSPATH . 'wp-admin/includes/template.php';
3187
3188
		wp_enqueue_script( 'thickbox' );
3189
		wp_enqueue_style( 'pods-styles' );
3190
3191
		$filters = $this->filters;
3192
3193
		foreach ( $filters as $k => $filter ) {
3194
			if ( isset( $this->pod->fields[ $filter ] ) ) {
3195
				$filter_field = $this->pod->fields[ $filter ];
3196
			} elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3197
				$filter_field = $this->fields['manage'][ $filter ];
3198
			} else {
3199
				continue;
3200
			}
3201
3202
			if ( isset( $filter_field ) && in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3203
				if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) {
3204
					unset( $filters[ $k ] );
3205
				}
3206
			} elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) {
3207
				unset( $filters[ $k ] );
3208
			}
3209
		}
3210
3211
		$filtered = false;
3212
3213
		if ( ! empty( $filters ) ) {
3214
			$filtered = true;
3215
		}
3216
		?>
3217
		<div class="pods-ui-filter-bar">
3218
			<div class="pods-ui-filter-bar-primary">
3219
				<?php
3220
				if ( ! empty( $this->views ) ) {
3221
					?>
3222
					<ul class="subsubsub">
3223
						<li class="pods-ui-filter-view-label">
3224
							<strong><?php echo wp_kses_post( $this->heading['views'] ); ?></strong></li>
3225
3226
						<?php
3227
						foreach ( $this->views as $view => $label ) {
3228
							if ( false === strpos( $label, '<a' ) ) {
3229
								$link = pods_query_arg(
3230
									array(
3231
										'view' . $this->num => $view,
3232
										'pg' . $this->num => '',
3233
									), self::$allowed, $this->exclusion()
3234
								);
3235
3236
								if ( $this->view == $view ) {
3237
									$label = '<a href="' . esc_url( $link ) . '" class="current">' . esc_html( $label ) . '</a>';
3238
								} else {
3239
									$label = '<a href="' . esc_url( $link ) . '">' . esc_html( $label ) . '</a>';
3240
								}
3241
							} else {
3242
								$label = wp_kses_post( $label );
3243
							}
3244
							?>
3245
							<li class="<?php echo esc_attr( $view ); ?>">
3246
								<?php
3247
								/* Escaped above to support links */
3248
								echo $label;
3249
								?>
3250
							</li>
3251
							<?php
3252
						}//end foreach
3253
						?>
3254
					</ul>
3255
					<?php
3256
				}//end if
3257
				?>
3258
3259
				<?php
3260
				if ( false !== $this->search && false !== $this->searchable ) {
3261
					?>
3262
					<p class="search-box">
3263
						<?php
3264
						if ( $filtered || '' != pods_var_raw( 'search' . $this->num, 'get', '', null, true ) ) {
3265
							$clear_filters = array(
3266
								'search' . $this->num => false,
3267
							);
3268
3269
							foreach ( $this->filters as $filter ) {
3270
								$clear_filters[ 'filter_' . $filter . '_start' ] = false;
3271
								$clear_filters[ 'filter_' . $filter . '_end' ]   = false;
3272
								$clear_filters[ 'filter_' . $filter ]            = false;
3273
							}
3274
							?>
3275
							<a href="
3276
							<?php
3277
							echo esc_url(
3278
								pods_query_arg(
3279
									$clear_filters, array(
3280
										'orderby' . $this->num,
3281
										'orderby_dir' . $this->num,
3282
										'limit' . $this->num,
3283
										'page',
3284
									), $this->exclusion()
3285
								)
3286
							);
3287
							?>
3288
							" class="pods-ui-filter-reset">[<?php _e( 'Reset', 'pods' ); ?>]</a>
3289
							<?php
3290
						}//end if
3291
3292
						if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
3293
							?>
3294
							&nbsp;&nbsp;
3295
							<label class="screen-reader-text" for="page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
3296
							<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
3297
							<?php
3298
						} else {
3299
							echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
3300
						}
3301
						?>
3302
3303
						<?php echo PodsForm::submit_button( $this->header['search'], 'button', false, false, array( 'id' => 'search' . $this->num . '-submit' ) ); ?>
3304
					</p>
3305
					<?php
3306
				}//end if
3307
				?>
3308
			</div>
3309
3310
			<?php
3311
			if ( ! empty( $this->filters ) ) {
3312
				?>
3313
				<div class="pods-ui-filter-bar-secondary">
3314
					<ul class="subsubsub">
3315
						<?php
3316
						if ( ! $filtered ) {
3317
							?>
3318
							<li class="pods-ui-filter-bar-add-filter">
3319
								<a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
3320
									<?php _e( 'Advanced Filters', 'pods' ); ?>
3321
								</a>
3322
							</li>
3323
							<?php
3324
						} else {
3325
							?>
3326
							<li class="pods-ui-filter-bar-add-filter">
3327
								<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' ); ?>
3328
								</a>
3329
							</li>
3330
							<?php
3331
						}
3332
3333
						foreach ( $filters as $filter ) {
3334
							$value = pods_var_raw( 'filter_' . $filter, 'get' );
3335
3336
							if ( isset( $this->pod->fields[ $filter ] ) ) {
3337
								$filter_field = $this->pod->fields[ $filter ];
3338
							} elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3339
								$filter_field = $this->fields['manage'][ $filter ];
3340
							} else {
3341
								continue;
3342
							}
3343
3344
							$data_filter = 'filter_' . $filter;
3345
3346
							$start = $end = $value_label = '';
3347
3348
							if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3349
								$start = pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true );
3350
								$end   = pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true );
3351
3352
								if ( ! empty( $start ) && ! in_array(
3353
									$start, array(
3354
										'0000-00-00',
3355
										'0000-00-00 00:00:00',
3356
										'00:00:00',
3357
									)
3358
								) ) {
3359
									$start = PodsForm::field_method( $filter_field['type'], 'convert_date', $start, 'n/j/Y' );
3360
								}
3361
3362
								if ( ! empty( $end ) && ! in_array(
3363
									$end, array(
3364
										'0000-00-00',
3365
										'0000-00-00 00:00:00',
3366
										'00:00:00',
3367
									)
3368
								) ) {
3369
									$end = PodsForm::field_method( $filter_field['type'], 'convert_date', $end, 'n/j/Y' );
3370
								}
3371
3372
								$value = trim( $start . ' - ' . $end, ' -' );
3373
3374
								$data_filter = 'filter_' . $filter . '_start';
3375
							} elseif ( 'pick' === $filter_field['type'] ) {
3376
								$value_label = trim( PodsForm::field_method( 'pick', 'value_to_label', $filter, $value, $filter_field, $this->pod->pod_data, null ) );
3377
							} elseif ( 'boolean' === $filter_field['type'] ) {
3378
								$yesno_options = array(
3379
									'1' => pods_var_raw( 'boolean_yes_label', $filter_field['options'], __( 'Yes', 'pods' ), null, true ),
3380
									'0' => pods_var_raw( 'boolean_no_label', $filter_field['options'], __( 'No', 'pods' ), null, true ),
0 ignored issues
show
introduced by
Detected usage of 0, possible slow query.
Loading history...
3381
								);
3382
3383
								if ( isset( $yesno_options[ (string) $value ] ) ) {
3384
									$value_label = $yesno_options[ (string) $value ];
3385
								}
3386
							}//end if
3387
3388
							if ( strlen( $value_label ) < 1 ) {
3389
								$value_label = $value;
3390
							}
3391
							?>
3392
							<li class="pods-ui-filter-bar-filter" data-filter="<?php echo esc_attr( $data_filter ); ?>">
3393
								<a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
3394
									<strong><?php echo esc_html( $filter_field['label'] ); ?>:</strong>
3395
									<?php echo esc_html( $value_label ); ?>
3396
								</a>
3397
3398
								<a href="#remove-filter" class="remove-filter" title="<?php esc_attr_e( 'Remove Filter', 'pods' ); ?>">x</a>
3399
3400
								<?php
3401
								if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3402
									echo PodsForm::field( 'filter_' . $filter . '_start', $start, 'hidden' );
3403
									echo PodsForm::field( 'filter_' . $filter . '_end', $end, 'hidden' );
3404
								} else {
3405
									echo PodsForm::field( $data_filter, $value, 'hidden' );
3406
								}
3407
								?>
3408
							</li>
3409
							<?php
3410
						}//end foreach
3411
						?>
3412
					</ul>
3413
				</div>
3414
				<?php
3415
			}//end if
3416
			?>
3417
		</div>
3418
3419
		<script type="text/javascript">
3420
			jQuery( function () {
3421
				jQuery( '.pods-ui-filter-bar-secondary' ).on( 'click', '.remove-filter', function ( e ) {
3422
					jQuery( '.pods-ui-filter-popup #' + jQuery( this ).parent().data( 'filter' ) ).remove();
3423
3424
					jQuery( this ).parent().find( 'input' ).each( function () {
3425
						jQuery( this ).remove();
3426
					} );
3427
3428
					jQuery( 'form#posts-filter [name="pg<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3429
					jQuery( 'form#posts-filter [name="action<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3430
					jQuery( 'form#posts-filter [name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3431
					jQuery( 'form#posts-filter [name="_wpnonce<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3432
3433
					jQuery( 'form#posts-filter' ).submit();
3434
3435
					e.preventDefault();
3436
				} );
3437
			} );
3438
		</script>
3439
		<?php
3440
	}
3441
3442
	public function filters_popup() {
3443
3444
		$filters = $this->filters;
3445
		?>
3446
		<div id="pods-ui-posts-filter-popup" class="pods-hidden">
3447
			<form action="" method="get" class="pods-ui-posts-filter-popup">
3448
				<h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
3449
3450
				<div class="pods-ui-posts-filters">
3451
					<?php
3452
					$excluded_filters = array(
3453
						'search' . $this->num,
3454
						'pg' . $this->num,
3455
						'action' . $this->num,
3456
						'action_bulk' . $this->num,
3457
						'action_bulk_ids' . $this->num,
3458
						'_wpnonce' . $this->num,
3459
					);
3460
3461
					foreach ( $filters as $filter ) {
3462
						$excluded_filters[] = 'filters_relation';
3463
						$excluded_filters[] = 'filters_compare_' . $filter;
3464
						$excluded_filters[] = 'filter_' . $filter . '_start';
3465
						$excluded_filters[] = 'filter_' . $filter . '_end';
3466
						$excluded_filters[] = 'filter_' . $filter;
3467
					}
3468
3469
					$get = $_GET;
3470
3471
					foreach ( $get as $k => $v ) {
3472
						if ( in_array( $k, $excluded_filters ) || strlen( $v ) < 1 ) {
3473
							continue;
3474
						}
3475
						?>
3476
						<input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
3477
						<?php
3478
					}
3479
3480
					$zebra = true;
3481
3482
					foreach ( $filters as $filter ) {
3483
						if ( empty( $filter ) ) {
3484
							continue;
3485
						}
3486
3487
						if ( isset( $this->pod->fields[ $filter ] ) ) {
3488
							$filter_field = $this->pod->fields[ $filter ];
3489
						} elseif ( isset( $this->fields['manage'][ $filter ] ) ) {
3490
							$filter_field = $this->fields['manage'][ $filter ];
3491
						} else {
3492
							continue;
3493
						}
3494
						?>
3495
						<p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-<?php echo esc_attr( $filter . ( $zebra ? ' clear' : '' ) ); ?>">
3496
							<?php
3497
							if ( in_array( $filter_field['type'], array( 'date', 'datetime', 'time' ) ) ) {
3498
								$start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
3499
								$end   = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
3500
3501
								// override default value
3502
								$filter_field['options']['default_value']                          = '';
3503
								$filter_field['options'][ $filter_field['type'] . '_allow_empty' ] = 1;
3504
3505
								if ( ! empty( $start ) && ! in_array(
3506
									$start, array(
3507
										'0000-00-00',
3508
										'0000-00-00 00:00:00',
3509
										'00:00:00',
3510
									)
3511
								) ) {
3512
									$start = PodsForm::field_method( $filter_field['type'], 'convert_date', $start, 'n/j/Y' );
3513
								}
3514
3515
								if ( ! empty( $end ) && ! in_array(
3516
									$end, array(
3517
										'0000-00-00',
3518
										'0000-00-00 00:00:00',
3519
										'00:00:00',
3520
									)
3521
								) ) {
3522
									$end = PodsForm::field_method( $filter_field['type'], 'convert_date', $end, 'n/j/Y' );
3523
								}
3524
								?>
3525
								<span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? '' : ' pods-hidden' ); ?>">+</span>
3526
								<span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3527
3528
								<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
3529
									<?php echo esc_html( $filter_field['label'] ); ?>
3530
								</label>
3531
3532
								<span class="pods-ui-posts-filter<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' pods-hidden' : '' ); ?>">
3533
								<?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field['type'], $filter_field ); ?>
3534
3535
									<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">to</label>
3536
									<?php echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field['type'], $filter_field ); ?>
3537
							</span>
3538
								<?php
3539
							} elseif ( 'pick' === $filter_field['type'] ) {
3540
								$value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3541
3542
								if ( strlen( $value ) < 1 ) {
3543
									$value = pods_var_raw( 'filter_default', $filter_field );
3544
								}
3545
3546
								// override default value
3547
								$filter_field['options']['default_value'] = '';
3548
3549
								$filter_field['options']['pick_format_type']   = 'single';
3550
								$filter_field['options']['pick_format_single'] = 'dropdown';
3551
3552
								$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 );
3553
								$filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
3554
3555
								$options = array_merge( $filter_field, $filter_field['options'] );
3556
								?>
3557
								<span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3558
								<span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3559
3560
								<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3561
									<?php echo esc_html( $filter_field['label'] ); ?>
3562
								</label>
3563
3564
								<span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' pods-hidden' : '' ); ?>">
3565
								<?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3566
							</span>
3567
								<?php
3568
							} elseif ( 'boolean' === $filter_field['type'] ) {
3569
								$value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3570
3571
								if ( strlen( $value ) < 1 ) {
3572
									$value = pods_var_raw( 'filter_default', $filter_field );
3573
								}
3574
3575
								// override default value
3576
								$filter_field['options']['default_value'] = '';
3577
3578
								$filter_field['options']['pick_format_type']   = 'single';
3579
								$filter_field['options']['pick_format_single'] = 'dropdown';
3580
3581
								$filter_field['options']['pick_object'] = 'custom-simple';
3582
								$filter_field['options']['pick_custom'] = array(
3583
									'1' => pods_var_raw( 'boolean_yes_label', $filter_field['options'], __( 'Yes', 'pods' ), null, true ),
3584
									'0' => pods_var_raw( 'boolean_no_label', $filter_field['options'], __( 'No', 'pods' ), null, true ),
0 ignored issues
show
introduced by
Detected usage of 0, possible slow query.
Loading history...
3585
								);
3586
3587
								$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 );
3588
								$filter_field['options']['input_helper'] = pods_var_raw( 'ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true );
3589
3590
								$options = array_merge( $filter_field, $filter_field['options'] );
3591
								?>
3592
								<span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3593
								<span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3594
3595
								<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3596
									<?php echo esc_html( $filter_field['label'] ); ?>
3597
								</label>
3598
3599
								<span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' pods-hidden' : '' ); ?>">
3600
								<?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3601
							</span>
3602
								<?php
3603
							} else {
3604
								$value = pods_var_raw( 'filter_' . $filter, 'get' );
3605
3606
								if ( strlen( $value ) < 1 ) {
3607
									$value = pods_var_raw( 'filter_default', $filter_field );
3608
								}
3609
3610
								$options = array(
3611
									'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 ),
3612
								);
3613
3614
								if ( empty( $options['input_helper'] ) && isset( $filter_field['options'] ) && isset( $filter_field['options']['input_helper'] ) ) {
3615
									$options['input_helper'] = $filter_field['options']['input_helper'];
3616
								}
3617
								?>
3618
								<span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' pods-hidden' ); ?>">+</span>
3619
								<span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3620
3621
								<label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3622
									<?php echo esc_html( $filter_field['label'] ); ?>
3623
								</label>
3624
3625
								<span class="pods-ui-posts-filter<?php echo esc_attr( empty( $value ) ? ' pods-hidden' : '' ); ?>">
3626
								<?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?>
3627
							</span>
3628
								<?php
3629
							}//end if
3630
							?>
3631
						</p>
3632
						<?php
3633
						$zebra = empty( $zebra );
3634
					}//end foreach
3635
					?>
3636
3637
					<p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-search<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>">
3638
						<label for="pods-form-ui-search<?php echo esc_attr( $this->num ); ?>"><?php _e( 'Search Text', 'pods' ); ?></label>
3639
						<?php echo PodsForm::field( 'search' . $this->num, pods_var_raw( 'search' . $this->num, 'get' ), 'text' ); ?>
3640
					</p>
3641
3642
					<?php $zebra = empty( $zebra ); ?>
3643
				</div>
3644
3645
				<p class="submit<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>">
3646
					<input type="submit" value="<?php echo esc_attr( $this->header['search'] ); ?>" class="button button-primary" />
3647
				</p>
3648
			</form>
3649
		</div>
3650
3651
		<script type="text/javascript">
3652
			jQuery( function () {
3653
				jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) {
3654
					jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'pods-hidden' );
3655
3656
					jQuery( this ).hide();
3657
					jQuery( this ).parent().find( '.toggle-off' ).show();
3658
				} );
3659
3660
				jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) {
3661
					jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'pods-hidden' );
3662
					jQuery( this ).parent().find( 'select, input' ).val( '' );
3663
3664
					jQuery( this ).hide();
3665
					jQuery( this ).parent().find( '.toggle-on' ).show();
3666
				} );
3667
3668
				jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) {
3669
					if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'pods-hidden' ) ) {
3670
						jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'pods-hidden' );
3671
3672
						jQuery( this ).parent().find( '.toggle-on' ).hide();
3673
						jQuery( this ).parent().find( '.toggle-off' ).show();
3674
					}
3675
					else {
3676
						jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'pods-hidden' );
3677
						jQuery( this ).parent().find( 'select, input' ).val( '' );
3678
3679
						jQuery( this ).parent().find( '.toggle-on' ).show();
3680
						jQuery( this ).parent().find( '.toggle-off' ).hide();
3681
					}
3682
				} );
3683
			} );
3684
		</script>
3685
		<?php
3686
	}
3687
3688
	/**
3689
	 * @param bool $reorder
3690
	 *
3691
	 * @return bool|mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
3692
	 */
3693
	public function table( $reorder = false ) {
3694
3695
		if ( false !== $this->callback( 'table', $reorder ) ) {
3696
			return null;
3697
		}
3698
3699
		if ( empty( $this->data ) ) {
3700
			?>
3701
			<p><?php echo pods_v( 'label_no_items_found', $this->label, sprintf( __( 'No %s found', 'pods' ), $this->items ) ); ?></p>
3702
			<?php
3703
			return false;
3704
		}
3705
		if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
3706
3707
			?>
3708
			<style type="text/css">
3709
			table.widefat.fixed tbody.reorderable tr {
3710
				height: 50px;
3711
			}
3712
3713
			.dragme {
3714
				background:          url(<?php echo esc_url( PODS_URL ); ?>/ui/images/handle.gif) no-repeat;
3715
				background-position: 8px 8px;
3716
				cursor:              pointer;
3717
			}
3718
3719
			.dragme strong {
3720
				margin-left: 30px;
3721
			}
3722
			</style>
3723
			<form action="
3724
			<?php
3725
			echo esc_url(
3726
				pods_query_arg(
3727
					array(
3728
						'action' . $this->num => 'reorder',
3729
						'do' . $this->num     => 'save',
3730
						'page'                => pods_var_raw( 'page' ),
3731
					), self::$allowed, $this->exclusion()
3732
				)
3733
			);
3734
		?>
3735
		" method="post" class="admin_ui_reorder_form">
3736
					<?php
3737
		}//end if
3738
			$table_fields = $this->fields['manage'];
3739
		if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
3740
			$table_fields = $this->fields['reorder'];
3741
		}
3742
		if ( false === $table_fields || empty( $table_fields ) ) {
3743
			return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods' ) );
3744
		}
3745
			?>
3746
			<table class="widefat page fixed wp-list-table" cellspacing="0"<?php echo ( 1 == $reorder && $this->reorder ) ? ' id="admin_ui_reorder"' : ''; ?>>
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->reorder of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
3747
				<thead>
3748
				<tr>
3749
					<?php
3750
					if ( ! empty( $this->actions_bulk ) ) {
3751
						?>
3752
						<th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" />
3753
						</th>
3754
						<?php
3755
					}
3756
3757
					$name_field = false;
3758
					$fields     = array();
3759
					if ( ! empty( $table_fields ) ) {
3760
						foreach ( $table_fields as $field => $attributes ) {
3761
							if ( false === $attributes['display'] ) {
3762
								continue;
3763
							}
3764
							if ( false === $name_field ) {
3765
								$id = 'title';
3766
							} else {
3767
								$id = '';
3768
							}
3769
							if ( 'other' === $attributes['type'] ) {
3770
								$id = '';
3771
							}
3772
							if ( in_array( $attributes['type'], array( 'date', 'datetime', 'time' ) ) ) {
3773
								$id = 'date';
3774
							}
3775
							if ( false === $name_field && 'title' === $id ) {
3776
								$name_field = true;
3777
							}
3778
							$fields[ $field ]             = $attributes;
3779
							$fields[ $field ]['field_id'] = $id;
3780
							$dir                          = 'DESC';
3781
							$current_sort                 = ' asc';
3782
							if ( isset( $this->orderby['default'] ) && $field == $this->orderby['default'] ) {
3783
								if ( 'DESC' === $this->orderby_dir ) {
3784
									$dir          = 'ASC';
3785
									$current_sort = ' desc';
3786
								}
3787
							}
3788
3789
							$att_id = '';
3790
							if ( ! empty( $id ) ) {
3791
								$att_id = ' id="' . esc_attr( $id ) . '"';
3792
							}
3793
3794
							$width = '';
3795
3796
							$column_classes = array(
3797
								'manage-column',
3798
								'column-' . $id,
3799
							);
3800
3801
							// Merge with the classes taken from the UI call
3802
							if ( ! empty( $attributes['classes'] ) && is_array( $attributes['classes'] ) ) {
3803
								$column_classes = array_merge( $column_classes, $attributes['classes'] );
3804
							}
3805
							if ( $id == 'title' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
3806
								$column_classes[] = 'column-primary';
3807
							}
3808
3809
							if ( isset( $attributes['width'] ) && ! empty( $attributes['width'] ) ) {
3810
								$width = ' style="width: ' . esc_attr( $attributes['width'] ) . '"';
3811
							}
3812
3813
							if ( $fields[ $field ]['sortable'] ) {
3814
								$column_classes[] = 'sortable' . $current_sort;
3815
								?>
3816
								<th scope="col"<?php echo $att_id; ?> class="<?php echo esc_attr( implode( ' ', $column_classes ) ); ?>"<?php echo $width; ?>>
3817
									<a href="
3818
									<?php
3819
									echo esc_url_raw(
3820
										pods_query_arg(
3821
											array(
3822
												'orderby' . $this->num => $field,
3823
												'orderby_dir' . $this->num => $dir,
3824
											), array(
3825
												'limit' . $this->num,
3826
												'search' . $this->num,
3827
												'pg' . $this->num,
3828
												'page',
3829
											), $this->exclusion()
3830
										)
3831
									);
3832
									?>
3833
									">
3834
										<span><?php echo esc_html( $attributes['label'] ); ?></span>
3835
										<span class="sorting-indicator"></span> </a>
3836
								</th>
3837
								<?php
3838
							} else {
3839
								?>
3840
								<th scope="col"<?php echo $att_id; ?> class="<?php echo esc_attr( implode( ' ', $column_classes ) ); ?>"<?php echo $width; ?>><?php echo esc_html( $attributes['label'] ); ?></th>
3841
								<?php
3842
							}//end if
3843
						}//end foreach
3844
					}//end if
3845
					?>
3846
				</tr>
3847
				</thead>
3848
				<?php
3849
				if ( 6 < $this->total_found ) {
3850
					?>
3851
					<tfoot>
3852
					<tr>
3853
						<?php
3854
						if ( ! empty( $this->actions_bulk ) ) {
3855
							?>
3856
							<th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th>
3857
							<?php
3858
						}
3859
3860
						if ( ! empty( $fields ) ) {
3861
							foreach ( $fields as $field => $attributes ) {
3862
								$dir = 'ASC';
3863
								if ( $field == $this->orderby ) {
3864
									$current_sort = 'desc';
3865
									if ( 'ASC' === $this->orderby_dir ) {
3866
										$dir          = 'DESC';
3867
										$current_sort = 'asc';
3868
									}
3869
								}
3870
3871
								$width = '';
3872
3873
								if ( isset( $attributes['width'] ) && ! empty( $attributes['width'] ) ) {
3874
									$width = ' style="width: ' . esc_attr( $attributes['width'] ) . '"';
3875
								}
3876
3877
								if ( $fields[ $field ]['sortable'] ) {
3878
									?>
3879
									<th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?> sortable <?php echo esc_attr( $current_sort ); ?>"<?php echo $width; ?>>
0 ignored issues
show
Bug introduced by
The variable $id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $current_sort does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3880
										<a href="
3881
										<?php
3882
										echo esc_url_raw(
3883
											pods_query_arg(
3884
												array(
3885
													'orderby' . $this->num     => $field,
3886
													'orderby_dir' . $this->num => $dir,
3887
												), array(
3888
													'limit' . $this->num,
3889
													'search' . $this->num,
3890
													'pg' . $this->num,
3891
													'page',
3892
												), $this->exclusion()
3893
											)
3894
										);
3895
										?>
3896
										"><span><?php echo esc_html( $attributes['label'] ); ?></span><span class="sorting-indicator"></span></a>
3897
									</th>
3898
									<?php
3899
								} else {
3900
									?>
3901
									<th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?>"<?php echo $width; ?>><?php echo esc_html( $attributes['label'] ); ?></th>
3902
									<?php
3903
								}//end if
3904
							}//end foreach
3905
						}//end if
3906
						?>
3907
					</tr>
3908
					</tfoot>
3909
					<?php
3910
				}//end if
3911
				?>
3912
				<tbody id="the-list"<?php echo ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) ? ' class="reorderable"' : ''; ?>>
3913
				<?php
3914
				if ( ! empty( $this->data ) && is_array( $this->data ) ) {
3915
					$counter = 0;
3916
3917
					while ( $row = $this->get_row( $counter, 'table' ) ) {
3918
						if ( is_object( $row ) ) {
3919
							$row = get_object_vars( (object) $row );
3920
						}
3921
3922
						$toggle_class = '';
3923
3924
						if ( is_array( $this->actions_custom ) && isset( $this->actions_custom['toggle'] ) ) {
3925
							$toggle_class = ' pods-toggled-on';
3926
3927
							if ( ! isset( $row['toggle'] ) || empty( $row['toggle'] ) ) {
3928
								$toggle_class = ' pods-toggled-off';
3929
							}
3930
						}
3931
						?>
3932
						<tr id="item-<?php echo esc_attr( $row[ $this->sql['field_id'] ] ); ?>" class="iedit<?php echo esc_attr( $toggle_class ); ?>">
3933
							<?php
3934
							if ( ! empty( $this->actions_bulk ) ) {
3935
								?>
3936
								<th scope="row" class="check-column">
3937
									<input type="checkbox" name="action_bulk_ids<?php echo esc_attr( $this->num ); ?>[]" value="<?php echo esc_attr( $row[ $this->sql['field_id'] ] ); ?>">
3938
								</th>
3939
								<?php
3940
							}
3941
							// Boolean for the first field to output after the check-column
3942
							// will be set to false at the end of the first loop
3943
							$first_field = true;
3944
							foreach ( $fields as $field => $attributes ) {
3945
								if ( false === $attributes['display'] ) {
3946
									continue;
3947
								}
3948
3949
								if ( ! isset( $row[ $field ] ) ) {
3950
									$row[ $field ] = $this->get_field( $field );
3951
								}
3952
3953
								$row_value = $row[ $field ];
3954
3955
								if ( ! empty( $attributes['custom_display'] ) ) {
3956
									if ( is_callable( $attributes['custom_display'] ) ) {
3957
										$row_value = call_user_func_array(
3958
											$attributes['custom_display'], array(
3959
												$row,
3960
												&$this,
3961
												$row_value,
3962
												$field,
3963
												$attributes,
3964
											)
3965
										);
3966
									} elseif ( is_object( $this->pod ) && class_exists( 'Pods_Helpers' ) ) {
3967
										$row_value = $this->pod->helper( $attributes['custom_display'], $row_value, $field );
3968
									}
3969
								} else {
3970
									ob_start();
3971
3972
									$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 );
3973
3974
									$field_output = trim( (string) ob_get_clean() );
3975
3976
									if ( false === $field_value ) {
3977
										$row_value = '';
3978
									} elseif ( 0 < strlen( trim( (string) $field_value ) ) ) {
3979
										$row_value = trim( (string) $field_value );
3980
									} elseif ( 0 < strlen( $field_output ) ) {
3981
										$row_value = $field_output;
3982
									}
3983
								}//end if
3984
3985
								if ( false !== $attributes['custom_relate'] ) {
3986
									global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
3987
									$table = $attributes['custom_relate'];
3988
									$on    = $this->sql['field_id'];
3989
									$is    = $row[ $this->sql['field_id'] ];
3990
									$what  = array( 'name' );
3991
									if ( is_array( $table ) ) {
3992
										if ( isset( $table['on'] ) ) {
3993
											$on = pods_sanitize( $table['on'] );
3994
										}
3995
										if ( isset( $table['is'] ) && isset( $row[ $table['is'] ] ) ) {
3996
											$is = pods_sanitize( $row[ $table['is'] ] );
3997
										}
3998
										if ( isset( $table['what'] ) ) {
3999
											$what = array();
4000
											if ( is_array( $table['what'] ) ) {
4001
												foreach ( $table['what'] as $wha ) {
4002
													$what[] = pods_sanitize( $wha );
4003
												}
4004
											} else {
4005
												$what[] = pods_sanitize( $table['what'] );
4006
											}
4007
										}
4008
										if ( isset( $table['table'] ) ) {
4009
											$table = $table['table'];
4010
										}
4011
									}//end if
4012
									$table = pods_sanitize( $table );
4013
									$wha   = implode( ',', $what );
4014
									$sql   = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'";
4015
									$value = @current( $wpdb->get_results( $sql, ARRAY_A ) );
0 ignored issues
show
Coding Style introduced by
Silencing errors is discouraged
Loading history...
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
4016
									if ( ! empty( $value ) ) {
4017
										$val = array();
4018
										foreach ( $what as $wha ) {
4019
											if ( isset( $value[ $wha ] ) ) {
4020
												$val[] = $value[ $wha ];
4021
											}
4022
										}
4023
										if ( ! empty( $val ) ) {
4024
											$row_value = implode( ' ', $val );
4025
										}
4026
									}
4027
								}//end if
4028
4029
								$css_classes = array(
4030
									'pods-ui-col-field-' . sanitize_title( $field ),
4031
								);
4032
4033
								// Merge with the classes taken from the UI call
4034
								if ( ! empty( $attributes['classes'] ) && is_array( $attributes['classes'] ) ) {
4035
									$css_classes = array_merge( $css_classes, $attributes['classes'] );
4036
								}
4037
4038
								if ( $attributes['css_values'] ) {
4039
									$css_field_value = $row[ $field ];
4040
4041
									if ( is_object( $css_field_value ) ) {
4042
										$css_field_value = get_object_vars( $css_field_value );
4043
									}
4044
4045
									if ( is_array( $css_field_value ) ) {
4046
										foreach ( $css_field_value as $css_field_val ) {
4047
											if ( is_object( $css_field_val ) ) {
4048
												$css_field_val = get_object_vars( $css_field_val );
4049
											}
4050
4051
											if ( is_array( $css_field_val ) ) {
4052
												foreach ( $css_field_val as $css_field_v ) {
4053
													if ( is_object( $css_field_v ) ) {
4054
														$css_field_v = get_object_vars( $css_field_v );
4055
													}
4056
4057
													$css_classes[] = 'pods-ui-css-value-' . sanitize_title(
4058
														str_replace(
4059
															array(
4060
																"\n",
4061
																"\r",
4062
															), ' ', strip_tags( (string) $css_field_v )
4063
														)
4064
													);
4065
												}
4066
											} else {
4067
												$css_classes[] = ' pods-ui-css-value-' . sanitize_title(
4068
													str_replace(
4069
														array(
4070
															"\n",
4071
															"\r",
4072
														), ' ', strip_tags( (string) $css_field_val )
4073
													)
4074
												);
4075
											}//end if
4076
										}//end foreach
4077
									} else {
4078
										$css_classes[] = ' pods-ui-css-value-' . sanitize_title(
4079
											str_replace(
4080
												array(
4081
													"\n",
4082
													"\r",
4083
												), ' ', strip_tags( (string) $css_field_value )
4084
											)
4085
										);
4086
									}//end if
4087
								}//end if
4088
4089
								if ( is_object( $this->pod ) ) {
4090
									$row_value = $this->do_hook( $this->pod->pod . '_field_value', $row_value, $field, $attributes, $row );
4091
								}
4092
4093
								$row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row );
4094
4095
								if ( ! empty( $attributes['custom_display_formatted'] ) && is_callable( $attributes['custom_display_formatted'] ) ) {
4096
									$row_value = call_user_func_array(
4097
										$attributes['custom_display_formatted'], array(
4098
											$row,
4099
											&$this,
4100
											$row_value,
4101
											$field,
4102
											$attributes,
4103
										)
4104
									);
4105
								}
4106
4107
								if ( 'title' === $attributes['field_id'] ) {
4108
									$default_action = $this->do_hook( 'default_action', 'edit', $row );
4109
4110
									if ( $first_field ) {
4111
										$css_classes[] = 'column-primary';
4112
									}
4113
									$css_classes[] = 'post-title';
4114
									$css_classes[] = 'page-title';
4115
									$css_classes[] = 'column-title';
4116
4117
									if ( 'raw' !== $attributes['type'] ) {
4118
										$row_value = wp_kses_post( $row_value );
4119
									}
4120
4121
									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 ) {
4122
										$link = pods_query_arg(
4123
											array(
4124
												'action' . $this->num => 'edit',
4125
												'id' . $this->num     => $row[ $this->sql['field_id'] ],
4126
											), self::$allowed, $this->exclusion()
4127
										);
4128
4129
										if ( ! empty( $this->action_links['edit'] ) ) {
4130
											$link = $this->do_template( $this->action_links['edit'], $row );
4131
										}
4132
										?>
4133
										<td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>">
4134
										<strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'Edit this item', 'pods' ); ?>">
4135
																						<?php
4136
																						/* Escaped above for non-HTML types */
4137
																						echo $row_value;
4138
												?>
4139
												</a></strong>
4140
										<?php
4141
									} 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 ) {
4142
										$link = pods_query_arg(
4143
											array(
4144
												'action' . $this->num => 'view',
4145
												'id' . $this->num     => $row[ $this->sql['field_id'] ],
4146
											), self::$allowed, $this->exclusion()
4147
										);
4148
4149
										if ( ! empty( $this->action_links['view'] ) ) {
4150
											$link = $this->do_template( $this->action_links['view'], $row );
4151
										}
4152
										?>
4153
										<td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>">
4154
										<strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'View this item', 'pods' ); ?>">
4155
																						<?php
4156
																						/* Escaped above for non-HTML types */
4157
																						echo $row_value;
4158
												?>
4159
												</a></strong>
4160
										<?php
4161
									} else {
4162
										if ( 1 == $reorder && $this->reorder ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->reorder of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
4163
											$css_classes[] = 'dragme';
4164
										}
4165
										?>
4166
										<td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>">
4167
										<strong>
4168
										<?php
4169
										/* Escaped above for non-HTML types */
4170
											echo $row_value;
4171
											?>
4172
											</strong>
4173
										<?php
4174
									}//end if
4175
4176
									if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder['on'] ) {
4177
										$toggle = false;
4178
4179
										$actions = $this->get_actions( $row );
4180
										$actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql['field_id'] ] );
4181
4182
										if ( ! empty( $actions ) ) {
4183
											?>
4184
											<div class="row-actions<?php echo esc_attr( $toggle ? ' row-actions-toggle' : '' ); ?>">
4185
												<?php
4186
												$this->callback( 'actions_start', $row, $actions );
4187
4188
												echo implode( ' | ', $actions );
4189
4190
												$this->callback( 'actions_end', $row, $actions );
4191
												?>
4192
											</div>
4193
											<?php
4194
										}
4195
									} else {
4196
										?>
4197
										<input type="hidden" name="order[]" value="<?php echo esc_attr( $row[ $this->sql['field_id'] ] ); ?>" />
4198
										<?php
4199
									}//end if
4200
									?>
4201
									<button type="button" class="toggle-row">
4202
										<span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span>
4203
									</button>
4204
									</td>
4205
									<?php
4206
								} elseif ( 'date' === $attributes['type'] ) {
4207
									if ( $first_field ) {
4208
										$css_classes[] = 'column-primary';
4209
									}
4210
									$css_classes[] = 'date';
4211
									$css_classes[] = 'column-date';
4212
									?>
4213
									<td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>" data-colname="<?php echo esc_attr( $attributes['label'] ); ?>">
4214
										<abbr title="<?php echo esc_attr( $row_value ); ?>"><?php echo wp_kses_post( $row_value ); ?></abbr>
4215
										<?php if ( $first_field ) { ?>
4216
											<button type="button" class="toggle-row">
4217
											<span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span>
4218
											</button><?php } ?>
4219
									</td>
4220
									<?php
4221
								} else {
4222
									if ( $first_field ) {
4223
										$css_classes[] = 'column-primary';
4224
									}
4225
4226
									$css_classes[] = 'author';
4227
4228
									if ( 'raw' !== $attributes['type'] ) {
4229
										$row_value = wp_kses_post( $row_value );
4230
									}
4231
									?>
4232
									<td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>" data-colname="<?php echo esc_attr( $attributes['label'] ); ?>">
4233
										<span>
4234
										<?php
4235
										/* Escaped above for non-HTML types */
4236
											echo $row_value;
4237
											?>
4238
											</span>
4239
										<?php if ( $first_field ) { ?>
4240
											<button type="button" class="toggle-row">
4241
											<span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span>
4242
											</button><?php } ?>
4243
									</td>
4244
									<?php
4245
								}//end if
4246
								$first_field = false;
4247
							}//end foreach
4248
							?>
4249
						</tr>
4250
						<?php
4251
					}//end while
4252
				}//end if
4253
				?>
4254
				</tbody>
4255
			</table>
4256
			<?php
4257
			if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
4258
4259
			?>
4260
		</form>
4261
		<?php
4262
			}
4263
		?>
4264
		<script type="text/javascript">
4265
			jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
4266
			<?php
4267
			if ( true === $reorder && ! in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder['on'] ) {
4268
			?>
4269
			jQuery( document ).ready( function () {
4270
				jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} );
4271
				jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) {
4272
					jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' );
4273
					jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
4274
				} );
4275
			} );
4276
			<?php
4277
			}
4278
			?>
4279
		</script>
4280
		<?php
4281
	}
4282
4283
	/**
4284
	 * Get actions for row.
4285
	 *
4286
	 * @param array $row
4287
	 *
4288
	 * @return array
4289
	 */
4290
	public function get_actions( $row ) {
4291
4292
		$actions = array();
4293
4294
		if ( ! in_array( 'view', $this->actions_disabled ) && ! in_array( 'view', $this->actions_hidden ) ) {
4295
			$link = pods_query_arg(
4296
				array(
4297
					'action' . $this->num => 'view',
4298
					'id' . $this->num     => $row[ $this->sql['field_id'] ],
4299
				), self::$allowed, $this->exclusion()
4300
			);
4301
4302
			if ( ! empty( $this->action_links['view'] ) ) {
4303
				$link = $this->do_template( $this->action_links['view'], $row );
4304
			}
4305
4306
			$actions['view'] = '<span class="view"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>';
4307
		}
4308
4309
		if ( ! in_array( 'edit', $this->actions_disabled ) && ! in_array( 'edit', $this->actions_hidden ) && ! $this->restricted( 'edit', $row ) ) {
4310
			$link = pods_query_arg(
4311
				array(
4312
					'action' . $this->num => 'edit',
4313
					'id' . $this->num     => $row[ $this->sql['field_id'] ],
4314
				), self::$allowed, $this->exclusion()
4315
			);
4316
4317
			if ( ! empty( $this->action_links['edit'] ) ) {
4318
				$link = $this->do_template( $this->action_links['edit'], $row );
4319
			}
4320
4321
			$actions['edit'] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>';
4322
		}
4323
4324
		if ( ! in_array( 'duplicate', $this->actions_disabled ) && ! in_array( 'duplicate', $this->actions_hidden ) && ! $this->restricted( 'edit', $row ) ) {
4325
			$link = pods_query_arg(
4326
				array(
4327
					'action' . $this->num => 'duplicate',
4328
					'id' . $this->num     => $row[ $this->sql['field_id'] ],
4329
				), self::$allowed, $this->exclusion()
4330
			);
4331
4332
			if ( ! empty( $this->action_links['duplicate'] ) ) {
4333
				$link = $this->do_template( $this->action_links['duplicate'], $row );
4334
			}
4335
4336
			$actions['duplicate'] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>';
4337
		}
4338
4339
		if ( ! in_array( 'delete', $this->actions_disabled ) && ! in_array( 'delete', $this->actions_hidden ) && ! $this->restricted( 'delete', $row ) ) {
4340
			$link = pods_query_arg(
4341
				array(
4342
					'action' . $this->num => 'delete',
4343
					'id' . $this->num     => $row[ $this->sql['field_id'] ],
4344
					'_wpnonce'            => wp_create_nonce( 'pods-ui-action-delete' ),
4345
				), self::$allowed, $this->exclusion()
4346
			);
4347
4348
			if ( ! empty( $this->action_links['delete'] ) ) {
4349
				$link = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), $this->do_template( $this->action_links['delete'], $row ) );
4350
			}
4351
4352
			$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>';
4353
		}
4354
4355
		if ( is_array( $this->actions_custom ) ) {
4356
			foreach ( $this->actions_custom as $custom_action => $custom_data ) {
4357
				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 ) ) {
4358
					if ( ! in_array(
4359
						$custom_action, array(
4360
							'add',
4361
							'view',
4362
							'edit',
4363
							'duplicate',
4364
							'delete',
4365
							'save',
4366
							'export',
4367
							'reorder',
4368
							'manage',
4369
							'table',
4370
						)
4371
					) ) {
4372
						if ( 'toggle' === $custom_action ) {
4373
							$toggle        = true;
4374
							$toggle_labels = array(
4375
								__( 'Enable', 'pods' ),
4376
								__( 'Disable', 'pods' ),
4377
							);
4378
4379
							$custom_data['label'] = ( $row['toggle'] ? $toggle_labels[1] : $toggle_labels[0] );
4380
						}
4381
4382
						if ( ! isset( $custom_data['label'] ) ) {
4383
							$custom_data['label'] = ucwords( str_replace( '_', ' ', $custom_action ) );
4384
						}
4385
4386
						if ( ! isset( $custom_data['link'] ) ) {
4387
							$vars = array(
4388
								'action'   => $custom_action,
4389
								'id'       => $row[ $this->sql['field_id'] ],
4390
								'_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action ),
4391
							);
4392
4393
							if ( 'toggle' === $custom_action ) {
4394
								$vars['toggle']  = (int) ( ! $row['toggle'] );
4395
								$vars['toggled'] = 1;
4396
							}
4397
4398
							$custom_data['link'] = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
4399
4400
							if ( isset( $this->action_links[ $custom_action ] ) && ! empty( $this->action_links[ $custom_action ] ) ) {
4401
								$custom_data['link'] = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action ) ), $this->do_template( $this->action_links[ $custom_action ], $row ) );
4402
							}
4403
						}
4404
4405
						$confirm = '';
4406
4407
						if ( isset( $custom_data['confirm'] ) ) {
4408
							$confirm = ' onclick="if(confirm(\'' . esc_js( $custom_data['confirm'] ) . '\')){return true;}return false;"';
4409
						}
4410
4411
						if ( $this->restricted( $custom_action, $row ) ) {
4412
							continue;
4413
						}
4414
4415
						$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>';
4416
					}//end if
4417
				}//end if
4418
			}//end foreach
4419
		}//end if
4420
4421
		return $actions;
4422
4423
	}
4424
4425
	/**
4426
	 *
4427
	 */
4428
	public function screen_meta() {
4429
4430
		$screen_html = $help_html = '';
4431
		$screen_link = $help_link = '';
4432
		if ( ! empty( $this->screen_options ) && ! empty( $this->help ) ) {
4433
			foreach ( $this->ui_page as $page ) {
4434
				if ( isset( $this->screen_options[ $page ] ) ) {
4435
					if ( is_array( $this->screen_options[ $page ] ) ) {
4436
						if ( isset( $this->screen_options[ $page ]['link'] ) ) {
4437
							$screen_link = $this->screen_options[ $page ]['link'];
4438
							break;
4439
						}
4440
					} else {
4441
						$screen_html = $this->screen_options[ $page ];
4442
						break;
4443
					}
4444
				}
4445
			}
4446
			foreach ( $this->ui_page as $page ) {
4447
				if ( isset( $this->help[ $page ] ) ) {
4448
					if ( is_array( $this->help[ $page ] ) ) {
4449
						if ( isset( $this->help[ $page ]['link'] ) ) {
4450
							$help_link = $this->help[ $page ]['link'];
4451
							break;
4452
						}
4453
					} else {
4454
						$help_html = $this->help[ $page ];
4455
						break;
4456
					}
4457
				}
4458
			}
4459
		}//end if
4460
		$screen_html = $this->do_hook( 'screen_meta_screen_html', $screen_html );
4461
		$screen_link = $this->do_hook( 'screen_meta_screen_link', $screen_link );
4462
		$help_html   = $this->do_hook( 'screen_meta_help_html', $help_html );
4463
		$help_link   = $this->do_hook( 'screen_meta_help_link', $help_link );
4464
		if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) || 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
4465
			?>
4466
			<div id="screen-meta">
4467
				<?php
4468
				$this->do_hook( 'screen_meta_pre' );
4469
				if ( 0 < strlen( $screen_html ) ) {
4470
					?>
4471
					<div id="screen-options-wrap" class="pods-hidden">
4472
						<form id="adv-settings" action="" method="post">
4473
							<?php
4474
							echo $screen_html;
4475
							$fields = array();
4476
							foreach ( $this->ui_page as $page ) {
4477
								if ( isset( $this->fields[ $page ] ) && ! empty( $this->fields[ $page ] ) ) {
4478
									$fields = $this->fields[ $page ];
4479
								}
4480
							}
4481
							if ( ! empty( $fields ) || true === $this->pagination ) {
4482
								?>
4483
								<h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
4484
								<?php
4485
								if ( ! empty( $fields ) ) {
4486
									?>
4487
									<div class="metabox-prefs">
4488
										<?php
4489
										$this->do_hook( 'screen_meta_screen_options' );
4490
										foreach ( $fields as $field => $attributes ) {
4491
											if ( false === $attributes['display'] || true === $attributes['hidden'] ) {
4492
												continue;
4493
											}
4494
											?>
4495
											<label for="<?php echo esc_attr( $field ); ?>-hide">
4496
												<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 echo esc_html( $attributes['label'] ); ?>
4497
											</label>
4498
											<?php
4499
										}
4500
										?>
4501
										<br class="clear">
4502
									</div>
4503
									<h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
4504
									<?php
4505
								}//end if
4506
								?>
4507
								<div class="screen-options">
4508
									<?php
4509
									if ( true === $this->pagination ) {
4510
										?>
4511
										<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">
4512
										<label for="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page"><?php echo esc_html( sprintf( __( '%s per page', 'pods' ), $this->items ) ); ?></label>
4513
										<?php
4514
									}
4515
									$this->do_hook( 'screen_meta_screen_submit' );
4516
									?>
4517
									<input type="submit" name="screen-options-apply" id="screen-options-apply" class="button" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
4518
									<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page">
4519
									<?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?>
4520
								</div>
4521
								<?php
4522
							}//end if
4523
							?>
4524
						</form>
4525
					</div>
4526
					<?php
4527
				}//end if
4528
				if ( 0 < strlen( $help_html ) ) {
4529
					?>
4530
					<div id="contextual-help-wrap" class="pods-hidden">
4531
						<div class="metabox-prefs">
4532
							<?php echo $help_html; ?>
4533
						</div>
4534
					</div>
4535
					<?php
4536
				}
4537
				?>
4538
				<div id="screen-meta-links">
4539
					<?php
4540
					$this->do_hook( 'screen_meta_links_pre' );
4541
					if ( 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
4542
						?>
4543
						<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
4544
							<?php
4545
							if ( 0 < strlen( $help_link ) ) {
4546
								?>
4547
								<a href="<?php echo esc_url( $help_link ); ?>" class="show-settings">Help</a>
4548
								<?php
4549
							} else {
4550
								?>
4551
								<a href="#contextual-help" id="contextual-help-link" class="show-settings">Help</a>
4552
								<?php
4553
							}
4554
							?>
4555
						</div>
4556
						<?php
4557
					}
4558
					if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) ) {
4559
						?>
4560
						<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
4561
							<?php
4562
							if ( 0 < strlen( $screen_link ) ) {
4563
								?>
4564
								<a href="<?php echo esc_url( $screen_link ); ?>" class="show-settings">Screen Options</a>
4565
								<?php
4566
							} else {
4567
								?>
4568
								<a href="#screen-options" id="show-settings-link" class="show-settings">Screen Options</a>
4569
								<?php
4570
							}
4571
							?>
4572
						</div>
4573
						<?php
4574
					}
4575
					$this->do_hook( 'screen_meta_links_post' );
4576
					?>
4577
				</div>
4578
				<?php
4579
				$this->do_hook( 'screen_meta_post' );
4580
				?>
4581
			</div>
4582
			<?php
4583
		}//end if
4584
	}
4585
4586
	/**
4587
	 * @param bool $header
4588
	 *
4589
	 * @return mixed
4590
	 */
4591
	public function pagination( $header = false ) {
4592
4593
		if ( false !== $this->callback( 'pagination', $header ) ) {
4594
			return null;
4595
		}
4596
4597
		$total_pages = ceil( $this->total_found / $this->limit );
4598
		$request_uri = pods_query_arg(
4599
			array( 'pg' . $this->num => '' ), array(
4600
				'limit' . $this->num,
4601
				'orderby' . $this->num,
4602
				'orderby_dir' . $this->num,
4603
				'search' . $this->num,
4604
				'filter_*',
4605
				'view' . $this->num,
4606
				'page' . $this->num,
4607
			), $this->exclusion()
4608
		);
4609
4610
		$append = false;
4611
4612
		if ( false !== strpos( $request_uri, '?' ) ) {
4613
			$append = true;
4614
		}
4615
4616
		if ( false !== $this->pagination_total && ( $header || 1 != $this->total_found ) ) {
4617
			$singular_label = strtolower( $this->item );
4618
			$plural_label   = strtolower( $this->items );
4619
			?>
4620
			<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>
4621
			<?php
4622
		}
4623
4624
		if ( false !== $this->pagination ) {
4625
			if ( 1 < $total_pages ) {
4626
				?>
4627
				<a class="first-page<?php echo esc_attr( ( 1 < $this->page ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the first page', 'pods' ); ?>" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=1' ); ?>">&laquo;</a>
4628
				<a class="prev-page<?php echo esc_attr( ( 1 < $this->page ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the previous page', 'pods' ); ?>" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=' . max( $this->page - 1, 1 ) ); ?>">&lsaquo;</a>
4629
				<?php
4630
				if ( true == $header ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
4631
					?>
4632
					<span class="paging-input"><input class="current-page" title="<?php esc_attr_e( 'Current page', 'pods' ); ?>" type="text" name="pg<?php echo esc_attr( $this->num ); ?>" value="<?php echo esc_attr( absint( $this->page ) ); ?>" size="<?php echo esc_attr( strlen( $total_pages ) ); ?>"> <?php _e( 'of', 'pods' ); ?>
4633
						<span class="total-pages"><?php echo absint( $total_pages ); ?></span></span>
4634
					<script>
4635
4636
						jQuery( document ).ready( function ( $ ) {
4637
							var pageInput = $( 'input.current-page' );
4638
							var currentPage = pageInput.val();
4639
							pageInput.closest( 'form' ).submit( function ( e ) {
4640
								if ( ( 1 > $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).length || $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 ) && ( 1 > $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).length || $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 ) && pageInput.val() == currentPage ) {
4641
									pageInput.val( '1' );
4642
								}
4643
							} );
4644
						} );
4645
					</script>
4646
					<?php
4647
				} else {
4648
					?>
4649
					<span class="paging-input"><?php echo absint( $this->page ); ?> <?php _e( 'of', 'pods' ); ?>
4650
						<span class="total-pages"><?php echo number_format_i18n( $total_pages ); ?></span></span>
4651
					<?php
4652
				}//end if
4653
				?>
4654
				<a class="next-page<?php echo esc_attr( ( $this->page < $total_pages ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the next page', 'pods' ); ?>" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=' . min( $this->page + 1, $total_pages ) ); ?>">&rsaquo;</a>
4655
				<a class="last-page<?php echo esc_attr( ( $this->page < $total_pages ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the last page', 'pods' ); ?>'" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=' . $total_pages ); ?>">&raquo;</a>
4656
				<?php
4657
			}//end if
4658
		}//end if
4659
	}
4660
4661
	/**
4662
	 * @param bool $options
4663
	 *
4664
	 * @return mixed
4665
	 */
4666
	public function limit( $options = false ) {
4667
4668
		if ( false !== $this->callback( 'limit', $options ) ) {
4669
			return null;
4670
		}
4671
4672
		if ( false === $options || ! is_array( $options ) || empty( $options ) ) {
4673
			$options = array( 10, 25, 50, 100, 200 );
4674
		}
4675
4676
		if ( ! in_array( $this->limit, $options ) && - 1 != $this->limit ) {
4677
			$this->limit = $options[1];
4678
		}
4679
4680
		foreach ( $options as $option ) {
4681
			if ( $option == $this->limit ) {
4682
				echo ' <span class="page-numbers current">' . esc_html( $option ) . '</span>';
4683
			} else {
4684
				echo ' <a href="' . esc_url(
4685
					pods_query_arg(
4686
						array( 'limit' => $option ), array(
4687
							'orderby' . $this->num,
4688
							'orderby_dir' . $this->num,
4689
							'search' . $this->num,
4690
							'filter_*',
4691
							'page' . $this->num,
4692
						), $this->exclusion()
4693
					)
4694
				) . '">' . esc_html( $option ) . '</a>';
4695
			}
4696
		}
4697
	}
4698
4699
	/**
4700
	 * @param            $code
4701
	 * @param bool|array $row
4702
	 *
4703
	 * @return mixed
4704
	 */
4705
	public function do_template( $code, $row = false ) {
4706
4707
		if ( is_object( $this->pod ) && 1 == 0 && 0 < $this->pod->id() ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
4708
			return $this->pod->do_magic_tags( $code );
4709
		} else {
4710
			if ( false !== $row ) {
4711
				$this->temp_row = $this->row;
0 ignored issues
show
Bug introduced by
The property temp_row does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
4712
				$this->row      = $row;
4713
			}
4714
4715
			$code = preg_replace_callback( '/({@(.*?)})/m', array( $this, 'do_magic_tags' ), $code );
4716
4717
			if ( false !== $row ) {
4718
				$this->row = $this->temp_row;
4719
				unset( $this->temp_row );
4720
			}
4721
		}
4722
4723
		return $code;
4724
	}
4725
4726
	/**
4727
	 * @param $tag
4728
	 *
4729
	 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
4730
	 */
4731
	public function do_magic_tags( $tag ) {
4732
4733
		if ( is_array( $tag ) ) {
4734
			if ( ! isset( $tag[2] ) && strlen( trim( $tag[2] ) ) < 1 ) {
4735
				return '';
4736
			}
4737
4738
			$tag = $tag[2];
4739
		}
4740
4741
		$tag = trim( $tag, ' {@}' );
4742
		$tag = explode( ',', $tag );
4743
4744
		if ( empty( $tag ) || ! isset( $tag[0] ) || strlen( trim( $tag[0] ) ) < 1 ) {
4745
			return null;
4746
		}
4747
4748
		foreach ( $tag as $k => $v ) {
4749
			$tag[ $k ] = trim( $v );
4750
		}
4751
4752
		$field_name = $tag[0];
4753
4754
		$value = $this->get_field( $field_name );
4755
4756
		if ( isset( $tag[1] ) && ! empty( $tag[1] ) && is_callable( $tag[1] ) ) {
4757
			$value = call_user_func_array( $tag[1], array( $value, $field_name, $this->row, &$this ) );
4758
		}
4759
4760
		$before = $after = '';
4761
4762
		if ( isset( $tag[2] ) && ! empty( $tag[2] ) ) {
4763
			$before = $tag[2];
4764
		}
4765
4766
		if ( isset( $tag[3] ) && ! empty( $tag[3] ) ) {
4767
			$after = $tag[3];
4768
		}
4769
4770
		if ( 0 < strlen( $value ) ) {
4771
			return $before . $value . $after;
4772
		}
4773
4774
		return null;
4775
	}
4776
4777
	/**
4778
	 * @param bool|array $exclude
4779
	 * @param bool|array $array
4780
	 */
4781
	public function hidden_vars( $exclude = false, $array = false ) {
4782
4783
		$exclude = $this->do_hook( 'hidden_vars', $exclude, $array );
4784
		if ( false === $exclude ) {
4785
			$exclude = array();
4786
		}
4787
		if ( ! is_array( $exclude ) ) {
4788
			$exclude = explode( ',', $exclude );
4789
		}
4790
		$get = $_GET;
4791
		if ( is_array( $array ) ) {
4792
			foreach ( $array as $key => $val ) {
4793
				if ( 0 < strlen( $val ) ) {
4794
					$get[ $key ] = $val;
4795
				} else {
4796
					unset( $get[ $key ] );
4797
				}
4798
			}
4799
		}
4800
		foreach ( $get as $k => $v ) {
4801
			if ( in_array( $k, $exclude ) ) {
4802
				continue;
4803
			}
4804
4805
			if ( is_array( $v ) ) {
4806
				foreach ( $v as $vk => $vv ) {
4807
					?>
4808
					<input type="hidden" name="<?php echo esc_attr( $k ); ?>[<?php echo esc_attr( $vk ); ?>]" value="<?php echo esc_attr( $vv ); ?>" />
4809
					<?php
4810
				}
4811
			} else {
4812
				?>
4813
				<input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
4814
				<?php
4815
			}
4816
		}
4817
	}
4818
4819
	/**
4820
	 * @return array
4821
	 */
4822
	public function exclusion() {
4823
4824
		$exclusion = self::$excluded;
4825
4826
		foreach ( $exclusion as $k => $exclude ) {
4827
			$exclusion[ $k ] = $exclude . $this->num;
4828
		}
4829
4830
		return $exclusion;
4831
	}
4832
4833
	/**
4834
	 * @param string $action
4835
	 * @param null   $row
4836
	 *
4837
	 * @return bool
4838
	 */
4839
	public function restricted( $action = 'edit', $row = null ) {
4840
4841
		$restricted = false;
4842
4843
		$restrict = array();
4844
4845
		if ( isset( $this->restrict[ $action ] ) ) {
4846
			$restrict = (array) $this->restrict[ $action ];
4847
		}
4848
4849
		// @todo Build 'edit', 'duplicate', 'delete' action support for 'where' which runs another find() query
4850
		/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4851
		if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) {
4852
            $where = pods_var_raw( $action, $this->where, null, null, true );
4853
4854
            if ( !empty( $where ) ) {
4855
                $restricted = true;
4856
4857
                $old_where = $this->where[ $action ];
4858
4859
                $id = $this->row[ $this->sql[ 'field_id' ] ];
4860
4861
                if ( is_array( $where ) ) {
4862
                    if ( 'OR' == pods_var( 'relation', $where ) )
4863
                        $where = array( $where );
4864
4865
                    $where[] = "`t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
4866
                }
4867
                else
4868
                    $where = "( {$where} ) AND `t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
4869
4870
                $this->where[ $action ] = $where;
4871
4872
                $data = false;
4873
4874
                //$data = $this->get_data();
4875
4876
                $this->where[ $action ] = $old_where;
4877
4878
                if ( empty( $data ) )
4879
                    $restricted = true;
4880
            }
4881
        }*/
4882
4883
		$author_restrict = false;
4884
4885
		if ( ! empty( $this->restrict['author_restrict'] ) && $restrict === $this->restrict['author_restrict'] ) {
4886
			$restricted = false;
4887
4888
			$author_restrict = true;
4889
4890
			if ( is_object( $this->pod ) ) {
4891
				$restricted = true;
4892
4893
				if ( 'settings' === $this->pod->pod_data['type'] && 'add' === $action ) {
4894
					$action = 'edit';
4895
				}
4896
4897
				if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) {
4898
					$restricted = false;
4899
				} elseif ( 'manage' === $action ) {
4900
					if ( ! in_array( 'edit', $this->actions_disabled ) && current_user_can( 'pods_edit_' . $this->pod->pod ) && current_user_can( 'pods_edit_others_' . $this->pod->pod ) ) {
4901
						$restricted = false;
4902
					} elseif ( ! in_array( 'delete', $this->actions_disabled ) && current_user_can( 'pods_delete_' . $this->pod->pod ) && current_user_can( 'pods_delete_others_' . $this->pod->pod ) ) {
4903
						$restricted = false;
4904
					} elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) ) {
4905
						$restricted = false;
4906
					}
4907
				} elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) ) {
4908
					$restricted = false;
4909
				}
4910
			}//end if
4911
			/*
4912
			 @todo determine proper logic for non-pods capabilities
4913
			 * else {
4914
			 * $restricted = true;
4915
			 *
4916
			 * if ( pods_is_admin( array( 'pods', 'pods_content' ) ) )
4917
			 * $restricted = false;
4918
			 * elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) )
4919
			 * $restricted = false;
4920
			 * }*/
4921
		}//end if
4922
4923
		if ( $restricted && ! empty( $restrict ) ) {
4924
			$relation = strtoupper( trim( pods_var( 'relation', $restrict, 'AND', null, true ) ) );
4925
4926
			if ( 'AND' !== $relation ) {
4927
				$relation = 'OR';
4928
			}
4929
4930
			$okay = true;
4931
4932
			foreach ( $restrict as $field => $match ) {
4933
				if ( 'relation' === $field ) {
4934
					continue;
4935
				}
4936
4937
				if ( is_array( $match ) ) {
4938
					$match_okay = true;
4939
4940
					$match_relation = strtoupper( trim( pods_var( 'relation', $match, 'OR', null, true ) ) );
4941
4942
					if ( 'AND' !== $match_relation ) {
4943
						$match_relation = 'OR';
4944
					}
4945
4946
					foreach ( $match as $the_field => $the_match ) {
4947
						if ( 'relation' === $the_field ) {
4948
							continue;
4949
						}
4950
4951
						$value = null;
4952
4953
						if ( is_object( $this->pod ) ) {
4954
							$value = $this->pod->field( $the_match, true );
4955
						} else {
4956
							if ( empty( $row ) ) {
4957
								$row = $this->row;
4958
							}
4959
4960
							if ( isset( $row[ $the_match ] ) ) {
4961
								if ( is_array( $row[ $the_match ] ) ) {
4962
									if ( false !== strpos( $the_match, '.' ) ) {
4963
										$the_matches = explode( '.', $the_match );
4964
4965
										$value = $row[ $the_match ];
4966
4967
										foreach ( $the_matches as $m ) {
4968
											if ( is_array( $value ) && isset( $value[ $m ] ) ) {
4969
												$value = $value[ $m ];
4970
											} else {
4971
												$value = null;
4972
4973
												break;
4974
											}
4975
										}
4976
									}
4977
								} else {
4978
									$value = $row[ $the_match ];
4979
								}
4980
							}//end if
4981
						}//end if
4982
4983
						if ( is_array( $value ) ) {
4984
							if ( ! in_array( $the_match, $value ) ) {
4985
								$match_okay = false;
4986
							} elseif ( 'OR' === $match_relation ) {
4987
								$match_okay = true;
4988
4989
								break;
4990
							}
4991
						} elseif ( $value == $the_match ) {
4992
							$match_okay = false;
4993
						} elseif ( 'OR' === $match_relation ) {
4994
							$match_okay = true;
4995
4996
							break;
4997
						}
4998
					}//end foreach
4999
5000
					if ( ! $match_okay ) {
5001
						$okay = false;
5002
					}
5003
					if ( 'OR' === $relation ) {
5004
						$okay = true;
5005
5006
						break;
5007
					}
5008
				} else {
5009
					$value = null;
5010
5011
					if ( is_object( $this->pod ) ) {
5012
						$value = $this->pod->field( $match, true );
5013
					} else {
5014
						if ( empty( $row ) ) {
5015
							$row = $this->row;
5016
						}
5017
5018
						if ( isset( $row[ $match ] ) ) {
5019
							if ( is_array( $row[ $match ] ) ) {
5020
								if ( false !== strpos( $match, '.' ) ) {
5021
									$matches = explode( '.', $match );
5022
5023
									$value = $row[ $match ];
5024
5025
									foreach ( $matches as $m ) {
5026
										if ( is_array( $value ) && isset( $value[ $m ] ) ) {
5027
											$value = $value[ $m ];
5028
										} else {
5029
											$value = null;
5030
5031
											break;
5032
										}
5033
									}
5034
								}
5035
							} else {
5036
								$value = $row[ $match ];
5037
							}
5038
						}//end if
5039
					}//end if
5040
5041
					if ( is_array( $value ) ) {
5042
						if ( ! in_array( $match, $value ) ) {
5043
							$okay = false;
5044
						} elseif ( 'OR' === $relation ) {
5045
							$okay = true;
5046
5047
							break;
5048
						}
5049
					} elseif ( $value != $match ) {
5050
						$okay = false;
5051
					} elseif ( 'OR' === $relation ) {
5052
						$okay = true;
5053
5054
						break;
5055
					}
5056
				}//end if
5057
			}//end foreach
5058
5059
			if ( ! empty( $author_restrict ) ) {
5060
				if ( is_object( $this->pod ) && 'manage' === $action ) {
5061
					if ( ! in_array( 'edit', $this->actions_disabled ) && ! current_user_can( 'pods_edit_' . $this->pod->pod ) && ! in_array( 'delete', $this->actions_disabled ) && ! current_user_can( 'pods_delete_' . $this->pod->pod ) ) {
5062
						$okay = false;
5063
					}
5064
				}
5065
				if ( is_object( $this->pod ) && ! current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) ) {
5066
					$okay = false;
5067
				}
5068
				/*
5069
				 @todo determine proper logic for non-pods capabilities
5070
				 * elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) )
5071
				 * $okay = false;*/
5072
5073
				if ( ! $okay && ! empty( $row ) ) {
5074
					foreach ( $this->restrict['author_restrict'] as $key => $val ) {
5075
						$author_restricted = $this->get_field( $key );
5076
5077
						if ( ! empty( $author_restricted ) ) {
5078
							if ( ! is_array( $author_restricted ) ) {
5079
								$author_restricted = (array) $author_restricted;
5080
							}
5081
5082
							if ( is_array( $val ) ) {
5083
								foreach ( $val as $v ) {
5084
									if ( in_array( $v, $author_restricted ) ) {
5085
										$okay = true;
5086
									}
5087
								}
5088
							} elseif ( in_array( $val, $author_restricted ) ) {
5089
								$okay = true;
5090
							}
5091
						}
5092
					}
5093
				}//end if
5094
			}//end if
5095
5096
			if ( $okay ) {
5097
				$restricted = false;
5098
			}
5099
		}//end if
5100
5101
		if ( isset( $this->actions_custom[ $action ] ) && is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ]['restrict_callback'] ) && is_callable( $this->actions_custom[ $action ]['restrict_callback'] ) ) {
5102
			$restricted = call_user_func( $this->actions_custom[ $action ]['restrict_callback'], $restricted, $restrict, $action, $row, $this );
5103
		}
5104
5105
		$restricted = $this->do_hook( 'restricted_' . $action, $restricted, $restrict, $action, $row );
5106
5107
		return $restricted;
5108
	}
5109
5110
	/**
5111
	 * Check for a custom action callback and run it
5112
	 *
5113
	 * @return bool|mixed
5114
	 */
5115
	public function callback() {
5116
5117
		$args = func_get_args();
5118
5119
		if ( empty( $args ) ) {
5120
			return false;
5121
		}
5122
5123
		$action = array_shift( $args );
5124
5125
		// Do hook
5126
		$callback_args = $args;
5127
		array_unshift( $callback_args, null );
5128
		array_unshift( $callback_args, $action );
5129
5130
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
5131
5132
		if ( null === $callback ) {
5133
			$callback = false;
5134
		}
5135
5136
		$args[] = $this;
5137
5138
		if ( isset( $this->actions_custom[ $action ] ) ) {
5139
			if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ]['callback'] ) && is_callable( $this->actions_custom[ $action ]['callback'] ) ) {
5140
				$callback = call_user_func_array( $this->actions_custom[ $action ]['callback'], $args );
5141
			} elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
5142
				$callback = call_user_func_array( $this->actions_custom[ $action ], $args );
5143
			}
5144
		}
5145
5146
		return $callback;
5147
5148
	}
5149
5150
	/**
5151
	 * Check for a custom action callback and run it (deprecated reverse arg order)
5152
	 *
5153
	 * @return bool|mixed
5154
	 */
5155
	public function callback_action() {
5156
5157
		$args = func_get_args();
5158
5159
		if ( empty( $args ) ) {
5160
			return false;
5161
		}
5162
5163
		$action = array_shift( $args );
5164
5165
		$deprecated = false;
5166
5167
		if ( is_bool( $action ) ) {
5168
			$deprecated = $action;
5169
5170
			$action = array_shift( $args );
5171
		}
5172
5173
		// Do hook
5174
		$callback_args = $args;
5175
		array_unshift( $callback_args, null );
5176
		array_unshift( $callback_args, 'action_' . $action );
5177
5178
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
5179
5180
		if ( null === $callback ) {
5181
			$callback = false;
5182
		}
5183
5184
		$args[] = $this;
5185
5186
		// Deprecated reverse arg order
5187
		if ( $deprecated ) {
5188
			$args = array_reverse( $args );
5189
		}
5190
5191
		if ( isset( $this->actions_custom[ $action ] ) ) {
5192
			if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ]['callback'] ) && is_callable( $this->actions_custom[ $action ]['callback'] ) ) {
5193
				$callback = call_user_func_array( $this->actions_custom[ $action ]['callback'], $args );
5194
			} elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
5195
				$callback = call_user_func_array( $this->actions_custom[ $action ], $args );
5196
			}
5197
		}
5198
5199
		return $callback;
5200
5201
	}
5202
5203
	/**
5204
	 * Check for a bulk action callback and run it
5205
	 *
5206
	 * @return bool|mixed Callback result
5207
	 */
5208
	public function callback_bulk() {
5209
5210
		$args = func_get_args();
5211
5212
		if ( empty( $args ) ) {
5213
			return false;
5214
		}
5215
5216
		$action = array_shift( $args );
5217
5218
		$deprecated = false;
5219
5220
		if ( is_bool( $action ) ) {
5221
			$deprecated = $action;
5222
5223
			$action = array_shift( $args );
5224
		}
5225
5226
		// Do hook
5227
		$callback_args = $args;
5228
		array_unshift( $callback_args, null );
5229
		array_unshift( $callback_args, 'bulk_action_' . $action );
5230
5231
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
5232
5233
		if ( null === $callback ) {
5234
			$callback = false;
5235
		}
5236
5237
		$args[] = $this;
5238
5239
		// Deprecated reverse arg order
5240
		if ( $deprecated ) {
5241
			$args = array_reverse( $args );
5242
		}
5243
5244
		if ( isset( $this->actions_bulk[ $action ] ) ) {
5245
			if ( is_array( $this->actions_bulk[ $action ] ) && isset( $this->actions_bulk[ $action ]['callback'] ) && is_callable( $this->actions_bulk[ $action ]['callback'] ) ) {
5246
				$callback = call_user_func_array( $this->actions_bulk[ $action ]['callback'], $args );
5247
			} elseif ( is_callable( $this->actions_bulk[ $action ] ) ) {
5248
				$callback = call_user_func_array( $this->actions_bulk[ $action ], $args );
5249
			}
5250
		}
5251
5252
		return $callback;
5253
5254
	}
5255
5256
	/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
5257
        // Example code for use with $this->do_hook
5258
        public function my_filter_function ($args, $obj) {
5259
            $obj[0]->item = 'Post';
5260
            $obj[0]->add = true;
5261
            // args are an array (0 => $arg1, 1 => $arg2)
5262
            // may have more than one arg, dependant on filter
5263
            return $args;
5264
        }
5265
        add_filter('pods_ui_post_init', 'my_filter_function', 10, 2);
5266
    */
5267
	/**
5268
	 * @return array|bool|mixed|null
5269
	 */
5270
	private function do_hook() {
5271
5272
		$args = func_get_args();
5273
5274
		if ( empty( $args ) ) {
5275
			return false;
5276
		}
5277
5278
		$name = array_shift( $args );
5279
5280
		return pods_do_hook( 'ui', $name, $args, $this );
5281
5282
	}
5283
}
5284