Completed
Pull Request — 2.x (#3602)
by
unknown
05:50
created

PodsUI::reorder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package Pods
4
 */
5
class PodsUI {
6
7
	/**
8
	 * @var null Nonce for security
9
	 */
10
	private $_nonce = null;
11
12
    // internal
13
    /**
14
     * @var bool|PodsData
15
     */
16
    private $pods_data = false;
17
18
    /**
19
     * @var array
20
     */
21
    private $actions = array(
22
        'manage',
23
        'add',
24
        'edit',
25
        'duplicate',
26
        'save',
27
        //'view',
28
        'delete',
29
        'reorder',
30
        'export'
31
    );
32
33
    /**
34
     * @var array
35
     */
36
    private $ui_page = array();
37
38
    /**
39
     * @var bool
40
     */
41
    private $unique_identifier = false;
42
43
    // base
44
    public $x = array();
45
46
    /**
47
     * @var array|bool|mixed|null|Pods
48
     */
49
    public $pod = false;
50
51
    /**
52
     * @var int
53
     */
54
    public $id = 0;
55
56
    /**
57
     * @var string
58
     */
59
    public $num = ''; // allows multiple co-existing PodsUI instances with separate functionality in URL
60
61
    /**
62
     * @var array
63
     */
64
    static $excluded = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $excluded.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
65
        'do',
66
        'id',
67
        'pg',
68
        'search',
69
        'filter_*',
70
        'orderby',
71
        'orderby_dir',
72
        'limit',
73
        'action',
74
        'action_bulk',
75
        'action_bulk_ids',
76
        '_wpnonce',
77
        'view',
78
        'export',
79
        'export_type',
80
        'export_delimiter',
81
        'remove_export',
82
        'updated',
83
        'duplicate',
84
		'message'
85
    ); // used in var_update
86
87
    static $allowed = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $allowed.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
88
        'page',
89
        'post_type'
90
    );
91
92
    // ui
93
    /**
94
     * @var bool
95
     */
96
    public $item = false; // to be set with localized string
97
    /**
98
     * @var bool
99
     */
100
    public $items = false; // to be set with localized string
101
    /**
102
     * @var bool
103
     */
104
    public $heading = false; // to be set with localized string array
105
    /**
106
     * @var bool
107
     */
108
    public $header = false; // to be set with localized string array
109
    /**
110
     * @var bool
111
     */
112
    public $label = false; // to be set with localized string array
113
    /**
114
     * @var bool
115
     */
116
    public $icon = false;
117
118
    /**
119
     * @var bool
120
     */
121
    public $css = false; // set to a URL of stylesheet to include
122
    /**
123
     * @var bool
124
     */
125
    public $wpcss = false; // set to true to include WP Admin stylesheets
126
    /**
127
     * @var array
128
     */
129
    public $fields = array(
130
        'manage' => array(),
131
        'search' => array(),
132
        'form' => array(),
133
        'add' => array(),
134
        'edit' => array(),
135
        'duplicate' => array(),
136
        'view' => array(),
137
        'reorder' => array(),
138
        'export' => array()
139
    );
140
141
    /**
142
     * @var bool
143
     */
144
    public $searchable = true;
145
146
    /**
147
     * @var bool
148
     */
149
    public $sortable = true;
150
151
    /**
152
     * @var bool
153
     */
154
    public $pagination = true;
155
156
    /**
157
     * @var bool
158
     */
159
    public $pagination_total = true;
160
161
    /**
162
     * @var array
163
     */
164
    public $export = array(
165
        'on' => false,
166
        'formats' => array(
167
            'csv' => ',',
168
            'tsv' => "\t",
169
            'xml' => false,
170
            'json' => false
171
        ),
172
        'url' => false,
173
        'type' => false
174
    );
175
176
    /**
177
     * @var array
178
     */
179
    public $reorder = array(
180
        'on' => false,
181
        'limit' => 250,
182
        'orderby' => false,
183
        'orderby_dir' => 'ASC',
184
        'sql' => null
185
    );
186
187
    /**
188
     * @var array
189
     */
190
    public $screen_options = array(); // set to 'page' => 'Text'; false hides link
191
    /**
192
     * @var array
193
     */
194
    public $help = array(); // 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...
195
196
    // data
197
    /**
198
     * @var bool
199
     */
200
    public $search = false;
201
202
    /**
203
     * @var bool
204
     */
205
    public $filters_enhanced = false;
206
207
    /**
208
     * @var array
209
     */
210
    public $filters = array();
211
212
    /**
213
     * @var string
214
     */
215
    public $view = false;
216
217
    /**
218
     * @var array
219
     */
220
    public $views = array();
221
222
    /**
223
     * @var bool
224
     */
225
    public $search_across = true;
226
227
    /**
228
     * @var bool
229
     */
230
    public $search_across_picks = false;
231
232
    /**
233
     * @var bool
234
     */
235
    public $default_none = false;
236
237
    /**
238
     * @var array
239
     */
240
    public $where = array(
241
        'manage' => null,
242
        /*'edit' => null,
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
243
        'duplicate' => null,
244
        'delete' => null,*/
245
        'reorder' => null
246
    );
247
248
    /**
249
     * @var bool
250
     */
251
    public $orderby = false;
252
253
    /**
254
     * @var string
255
     */
256
    public $orderby_dir = 'DESC';
257
258
    /**
259
     * @var int
260
     */
261
    public $limit = 25;
262
263
    /**
264
     * @var int
265
     */
266
    public $page = 1;
267
268
    /**
269
     * @var int
270
     */
271
    public $total = 0;
272
273
    /**
274
     * @var int
275
     */
276
    public $total_found = 0;
277
278
    /**
279
     * @var array
280
     */
281
    public $session = array(
282
        'search',
283
        'filters'
284
    ); // allowed: search, filters, show_per_page, orderby (priority over usermeta)
285
    /**
286
     * @var array
287
     */
288
    public $user = array(
289
        'show_per_page',
290
        'orderby'
291
    ); // allowed: search, filters, show_per_page, orderby (priority under session)
292
293
    // advanced data
294
    /**
295
     * @var array
296
     */
297
    public $sql = array(
298
        'table' => null,
299
        'field_id' => 'id',
300
        'field_index' => 'name',
301
        'select' => null,
302
        'sql' => null
303
    );
304
305
    /**
306
     * @var array
307
     */
308
    public $params = array();
309
310
    /**
311
     * @var bool|array
312
     */
313
    public $data = false;
314
315
    /**
316
     * @var bool|array
317
     */
318
    public $data_full = false;
319
320
    /**
321
     * @var array
322
     */
323
    public $data_keys = array();
324
325
    /**
326
     * @var array
327
     */
328
    public $row = array();
329
330
    // actions
331
    /**
332
     * @var string
333
     */
334
    public $action = 'manage';
335
336
    /**
337
     * @var string
338
     */
339
    public $action_bulk = false;
340
341
    /**
342
     * @var array
343
     */
344
    public $bulk = array();
345
346
    /**
347
     * @var array
348
     */
349
    public $action_after = array(
350
        'add' => 'edit',
351
        'edit' => 'edit',
352
        'duplicate' => 'edit'
353
    ); // set action to 'manage'
354
    /**
355
     * @var bool
356
     */
357
    public $do = false;
358
359
    /**
360
     * @var array
361
     */
362
    public $action_links = array(
363
		'manage' => null,
364
        'add' => null,
365
        'edit' => null,
366
        'duplicate' => null,
367
        'view' => null,
368
        'delete' => null,
369
        'reorder' => null
370
    ); // custom links (ex. /my-link/{@id}/
371
372
    /**
373
     * @var array
374
     */
375
    public $actions_disabled = array(
376
        'view',
377
        'export'
378
    ); // disable actions
379
380
    /**
381
     * @var array
382
     */
383
    public $actions_hidden = array(); // hide actions to not show them but allow them
384
385
    /**
386
     * @var array
387
     */
388
    public $actions_custom = array(); // overwrite existing actions or add your own
389
390
    /**
391
     * @var array
392
     */
393
    public $actions_bulk = array(); // enabled bulk actions
394
395
    /**
396
     * @var array
397
     */
398
    public $restrict = array(
399
        'manage' => null,
400
        'edit' => null,
401
        'duplicate' => null,
402
        'delete' => null,
403
        'reorder' => null,
404
        'author_restrict' => null
405
    );
406
407
    /**
408
     * @var array
409
     */
410
    public $extra = array(
411
        'total' => null
412
    );
413
414
    /**
415
     * @var string
416
     */
417
    public $style = 'post_type';
418
419
    /**
420
     * @var bool
421
     */
422
    public $save = false; // Allow custom save handling for tables that aren't Pod-based
423
424
    /**
425
     * Generate UI for Data Management
426
     *
427
     * @param mixed $options Object, Array, or String containing Pod or Options to be used
428
     * @param bool $deprecated Set to true to support old options array from Pods UI plugin
429
     *
430
     * @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...
431
     *
432
     * @license http://www.gnu.org/licenses/gpl-2.0.html
433
     * @since 2.0
434
     */
435
    public function __construct ( $options, $deprecated = false ) {
436
437
		$this->_nonce = pods_v( '_wpnonce', 'request' );
438
439
        $object = null;
440
441
        if ( is_object( $options ) ) {
442
            $object = $options;
443
            $options = array();
444
445
            if ( isset( $object->ui ) ) {
446
                $options = (array) $object->ui;
447
448
                unset( $object->ui );
449
            }
450
451
            if ( is_object( $object ) && ( 'Pods' == get_class( $object ) || 'Pod' == get_class( $object ) ) )
452
                $this->pod =& $object;
453
        }
454
455
        if ( !is_array( $options ) ) {
456
            // @todo need to come back to this and allow for multi-dimensional strings
457
            // like: option=value&option2=value2&option3=key[val],key2[val2]&option4=this,that,another
458
            if ( false !== strpos( $options, '=' ) || false !== strpos( $options, '&' ) )
459
                parse_str( $options, $options );
460
            else
461
                $options = array( 'pod' => $options );
462
        }
463
464
        if ( !is_object( $object ) && isset( $options[ 'pod' ] ) ) {
465
            if ( is_object( $options[ 'pod' ] ) )
466
                $this->pod = $options[ 'pod' ];
467
            elseif ( isset( $options[ 'id' ] ) )
468
                $this->pod = pods( $options[ 'pod' ], $options[ 'id' ] );
469
            else
470
                $this->pod = pods( $options[ 'pod' ] );
471
472
            unset( $options[ 'pod' ] );
473
        }
474
        elseif ( is_object( $object ) )
475
            $this->pod = $object;
476
477
        if ( false !== $deprecated || ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) ) )
478
            $options = $this->setup_deprecated( $options );
479
480
        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...
481
            $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...
482
        elseif ( is_object( $this->pod ) && 'Pods' == get_class( $this->pod ) && is_object( $this->pod->data ) )
483
            $this->pods_data =& $this->pod->data;
484
        elseif ( is_object( $this->pod ) )
485
            $this->pods_data = pods_data( $this->pod->pod );
486
        elseif ( !is_object( $this->pod ) )
487
            $this->pods_data = pods_data( $this->pod );
488
489
        $options = $this->do_hook( 'pre_init', $options );
490
				$this->add_bulk_action_export();
491
        $this->setup( $options );
492
493
        if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id ) {
494
            if ( $this->id != $this->pods_data->id )
495
                $this->row = $this->pods_data->fetch( $this->id );
496
            else
497
                $this->row = $this->pods_data->row;
498
        }
499
500
        if ( ( !is_object( $this->pod ) || 'Pods' != get_class( $this->pod ) ) && false === $this->sql[ 'table' ] && false === $this->data ) {
501
            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' ) );
502
503
            return false;
504
        }
505
506
        $this->go();
507
    }
508
509
    /**
510
     * add the Custom Bulk Action "Export Pods"
511
    */
512
    public function add_bulk_action_export() {
513
        $this->actions_bulk['export_pods'] =  array (
514
            'label' => 'Export Pods',
515
            'callback' => array (
516
                &$this,
517
                'export_pods'
518
            )
519
        );
520
    }
521
522
523
    /**
524
     * @param $deprecated_options
525
     *
526
     * @return array
527
     */
528
    public function setup_deprecated ( $deprecated_options ) {
529
        $options = array();
530
531
        if ( isset( $deprecated_options[ 'id' ] ) )
532
            $options[ 'id' ] = $deprecated_options[ 'id' ];
533
        if ( isset( $deprecated_options[ 'action' ] ) )
534
            $options[ 'action' ] = $deprecated_options[ 'action' ];
535
        if ( isset( $deprecated_options[ 'num' ] ) )
536
            $options[ 'num' ] = $deprecated_options[ 'num' ];
537
538
        if ( isset( $deprecated_options[ 'title' ] ) )
539
            $options[ 'items' ] = $deprecated_options[ 'title' ];
540
        if ( isset( $deprecated_options[ 'item' ] ) )
541
            $options[ 'item' ] = $deprecated_options[ 'item' ];
542
543
        if ( isset( $deprecated_options[ 'label' ] ) )
544
            $options[ 'label' ] = array(
545
                'add' => $deprecated_options[ 'label' ],
546
                'edit' => $deprecated_options[ 'label' ],
547
                'duplicate' => $deprecated_options[ 'label' ]
548
            );
549
        if ( isset( $deprecated_options[ 'label_add' ] ) ) {
550
            if ( isset( $options[ 'label' ] ) )
551
                $options[ 'label' ][ 'add' ] = $deprecated_options[ 'label_add' ];
552
            else
553
                $options[ 'label' ] = array( 'add' => $deprecated_options[ 'label_add' ] );
554
        }
555
        if ( isset( $deprecated_options[ 'label_edit' ] ) ) {
556
            if ( isset( $options[ 'label' ] ) )
557
                $options[ 'label' ][ 'edit' ] = $deprecated_options[ 'label_edit' ];
558
            else
559
                $options[ 'label' ] = array( 'edit' => $deprecated_options[ 'label_edit' ] );
560
        }
561
        if ( isset( $deprecated_options[ 'label_duplicate' ] ) ) {
562
            if ( isset( $options[ 'label' ] ) )
563
                $options[ 'label' ][ 'duplicate' ] = $deprecated_options[ 'label_duplicate' ];
564
            else
565
                $options[ 'label' ] = array( 'duplicate' => $deprecated_options[ 'label_duplicate' ] );
566
        }
567
568
        if ( isset( $deprecated_options[ 'icon' ] ) )
569
            $options[ 'icon' ] = $deprecated_options[ 'icon' ];
570
571
        if ( isset( $deprecated_options[ 'columns' ] ) )
572
            $options[ 'fields' ] = array( 'manage' => $deprecated_options[ 'columns' ] );
573
        if ( isset( $deprecated_options[ 'reorder_columns' ] ) ) {
574
            if ( isset( $options[ 'fields' ] ) )
575
                $options[ 'fields' ][ 'reorder' ] = $deprecated_options[ 'reorder_columns' ];
576
            else
577
                $options[ 'fields' ] = array( 'reorder' => $deprecated_options[ 'reorder_columns' ] );
578
        }
579 View Code Duplication
        if ( isset( $deprecated_options[ 'add_fields' ] ) ) {
580
            if ( isset( $options[ 'fields' ] ) ) {
581
                if ( !isset( $options[ 'fields' ][ 'add' ] ) )
582
                    $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'add_fields' ];
583
                if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
584
                    $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'add_fields' ];
585
                if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
586
                    $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'add_fields' ];
587
            }
588
            else
589
                $options[ 'fields' ] = array(
590
                    'add' => $deprecated_options[ 'add_fields' ],
591
                    'edit' => $deprecated_options[ 'add_fields' ],
592
                    'duplicate' => $deprecated_options[ 'add_fields' ]
593
                );
594
        }
595 View Code Duplication
        if ( isset( $deprecated_options[ 'edit_fields' ] ) ) {
596
            if ( isset( $options[ 'fields' ] ) ) {
597
                if ( !isset( $options[ 'fields' ][ 'add' ] ) )
598
                    $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'edit_fields' ];
599
                if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
600
                    $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'edit_fields' ];
601
                if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
602
                    $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'edit_fields' ];
603
            }
604
            else
605
                $options[ 'fields' ] = array(
606
                    'add' => $deprecated_options[ 'edit_fields' ],
607
                    'edit' => $deprecated_options[ 'edit_fields' ],
608
                    'duplicate' => $deprecated_options[ 'edit_fields' ]
609
                );
610
        }
611
        if ( isset( $deprecated_options[ 'duplicate_fields' ] ) ) {
612
            if ( isset( $options[ 'fields' ] ) )
613
                $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_fields' ];
614
            else
615
                $options[ 'fields' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_fields' ] );
616
        }
617
618
        if ( isset( $deprecated_options[ 'session_filters' ] ) && false === $deprecated_options[ 'session_filters' ] )
619
            $options[ 'session' ] = false;
620 View Code Duplication
        if ( isset( $deprecated_options[ 'user_per_page' ] ) ) {
621
            if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
622
                $options[ 'user' ] = array( 'orderby' );
623
            else
624
                $options[ 'user' ] = false;
625
        }
626 View Code Duplication
        if ( isset( $deprecated_options[ 'user_sort' ] ) ) {
627
            if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
628
                $options[ 'user' ] = array( 'show_per_page' );
629
            else
630
                $options[ 'user' ] = false;
631
        }
632
633
        if ( isset( $deprecated_options[ 'custom_list' ] ) ) {
634
            if ( isset( $options[ 'actions_custom' ] ) )
635
                $options[ 'actions_custom' ][ 'manage' ] = $deprecated_options[ 'custom_list' ];
636
            else
637
                $options[ 'actions_custom' ] = array( 'manage' => $deprecated_options[ 'custom_list' ] );
638
        }
639
        if ( isset( $deprecated_options[ 'custom_reorder' ] ) ) {
640
            if ( isset( $options[ 'actions_custom' ] ) )
641
                $options[ 'actions_custom' ][ 'reorder' ] = $deprecated_options[ 'custom_reorder' ];
642
            else
643
                $options[ 'actions_custom' ] = array( 'reorder' => $deprecated_options[ 'custom_reorder' ] );
644
        }
645
        if ( isset( $deprecated_options[ 'custom_add' ] ) ) {
646
            if ( isset( $options[ 'actions_custom' ] ) )
647
                $options[ 'actions_custom' ][ 'add' ] = $deprecated_options[ 'custom_add' ];
648
            else
649
                $options[ 'actions_custom' ] = array( 'add' => $deprecated_options[ 'custom_add' ] );
650
        }
651
        if ( isset( $deprecated_options[ 'custom_edit' ] ) ) {
652
            if ( isset( $options[ 'actions_custom' ] ) )
653
                $options[ 'actions_custom' ][ 'edit' ] = $deprecated_options[ 'custom_edit' ];
654
            else
655
                $options[ 'actions_custom' ] = array( 'edit' => $deprecated_options[ 'custom_edit' ] );
656
        }
657
        if ( isset( $deprecated_options[ 'custom_duplicate' ] ) ) {
658
            if ( isset( $options[ 'actions_custom' ] ) )
659
                $options[ 'actions_custom' ][ 'duplicate' ] = $deprecated_options[ 'custom_duplicate' ];
660
            else
661
                $options[ 'actions_custom' ] = array( 'duplicate' => $deprecated_options[ 'custom_duplicate' ] );
662
        }
663
        if ( isset( $deprecated_options[ 'custom_delete' ] ) ) {
664
            if ( isset( $options[ 'actions_custom' ] ) )
665
                $options[ 'actions_custom' ][ 'delete' ] = $deprecated_options[ 'custom_delete' ];
666
            else
667
                $options[ 'actions_custom' ] = array( 'delete' => $deprecated_options[ 'custom_delete' ] );
668
        }
669
        if ( isset( $deprecated_options[ 'custom_save' ] ) ) {
670
            if ( isset( $options[ 'actions_custom' ] ) )
671
                $options[ 'actions_custom' ][ 'save' ] = $deprecated_options[ 'custom_save' ];
672
            else
673
                $options[ 'actions_custom' ] = array( 'save' => $deprecated_options[ 'custom_save' ] );
674
        }
675
676
        if ( isset( $deprecated_options[ 'custom_actions' ] ) )
677
            $options[ 'actions_custom' ] = $deprecated_options[ 'custom_actions' ];
678
        if ( isset( $deprecated_options[ 'action_after_save' ] ) )
679
            $options[ 'action_after' ] = array(
680
                'add' => $deprecated_options[ 'action_after_save' ],
681
                'edit' => $deprecated_options[ 'action_after_save' ],
682
                'duplicate' => $deprecated_options[ 'action_after_save' ]
683
            );
684
        if ( isset( $deprecated_options[ 'edit_link' ] ) ) {
685
            if ( isset( $options[ 'action_links' ] ) )
686
                $options[ 'action_links' ][ 'edit' ] = $deprecated_options[ 'edit_link' ];
687
            else
688
                $options[ 'action_links' ] = array( 'edit' => $deprecated_options[ 'edit_link' ] );
689
        }
690
        if ( isset( $deprecated_options[ 'view_link' ] ) ) {
691
            if ( isset( $options[ 'action_links' ] ) )
692
                $options[ 'action_links' ][ 'view' ] = $deprecated_options[ 'view_link' ];
693
            else
694
                $options[ 'action_links' ] = array( 'view' => $deprecated_options[ 'view_link' ] );
695
        }
696
        if ( isset( $deprecated_options[ 'duplicate_link' ] ) ) {
697
            if ( isset( $options[ 'action_links' ] ) )
698
                $options[ 'action_links' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_link' ];
699
            else
700
                $options[ 'action_links' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_link' ] );
701
        }
702
703
        if ( isset( $deprecated_options[ 'reorder' ] ) )
704
            $options[ 'reorder' ] = array(
705
                'on' => $deprecated_options[ 'reorder' ],
706
                'orderby' => $deprecated_options[ 'reorder' ]
707
            );
708
        if ( isset( $deprecated_options[ 'reorder_sort' ] ) && isset( $options[ 'reorder' ] ) )
709
            $options[ 'reorder' ][ 'orderby' ] = $deprecated_options[ 'reorder_sort' ];
710
        if ( isset( $deprecated_options[ 'reorder_limit' ] ) && isset( $options[ 'reorder' ] ) )
711
            $options[ 'reorder' ][ 'limit' ] = $deprecated_options[ 'reorder_limit' ];
712
        if ( isset( $deprecated_options[ 'reorder_sql' ] ) && isset( $options[ 'reorder' ] ) )
713
            $options[ 'reorder' ][ 'sql' ] = $deprecated_options[ 'reorder_sql' ];
714
715
        if ( isset( $deprecated_options[ 'sort' ] ) )
716
            $options[ 'orderby' ] = $deprecated_options[ 'sort' ];
717
        if ( isset( $deprecated_options[ 'sortable' ] ) )
718
            $options[ 'sortable' ] = $deprecated_options[ 'sortable' ];
719
        if ( isset( $deprecated_options[ 'limit' ] ) )
720
            $options[ 'limit' ] = $deprecated_options[ 'limit' ];
721
722
        if ( isset( $deprecated_options[ 'where' ] ) ) {
723
            if ( isset( $options[ 'where' ] ) )
724
                $options[ 'where' ][ 'manage' ] = $deprecated_options[ 'where' ];
725
            else
726
                $options[ 'where' ] = array( 'manage' => $deprecated_options[ 'where' ] );
727
        }
728 View Code Duplication
        if ( isset( $deprecated_options[ 'edit_where' ] ) ) {
729
            /*if ( isset( $options[ 'where' ] ) )
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
730
                $options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ];
731
            else
732
                $options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );*/
733
734
            if ( isset( $options[ 'restrict' ] ) )
735
                $options[ 'restrict' ][ 'edit' ] = (array) $deprecated_options[ 'edit_where' ];
736
            else
737
                $options[ 'restrict' ] = array( 'edit' => (array) $deprecated_options[ 'edit_where' ] );
738
        }
739 View Code Duplication
        if ( isset( $deprecated_options[ 'duplicate_where' ] ) ) {
740
            /*if ( isset( $options[ 'where' ] ) )
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
741
                $options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ];
742
            else
743
                $options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );*/
744
745
            if ( isset( $options[ 'restrict' ] ) )
746
                $options[ 'restrict' ][ 'duplicate' ] = (array) $deprecated_options[ 'duplicate_where' ];
747
            else
748
                $options[ 'restrict' ] = array( 'duplicate' => (array) $deprecated_options[ 'duplicate_where' ] );
749
        }
750 View Code Duplication
        if ( isset( $deprecated_options[ 'delete_where' ] ) ) {
751
            /*if ( isset( $options[ 'where' ] ) )
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
752
                $options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ];
753
            else
754
                $options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );*/
755
756
            if ( isset( $options[ 'restrict' ] ) )
757
                $options[ 'restrict' ][ 'delete' ] = (array) $deprecated_options[ 'delete_where' ];
758
            else
759
                $options[ 'restrict' ] = array( 'delete' => (array) $deprecated_options[ 'delete_where' ] );
760
        }
761
        if ( isset( $deprecated_options[ 'reorder_where' ] ) ) {
762
            if ( isset( $options[ 'where' ] ) )
763
                $options[ 'where' ][ 'reorder' ] = $deprecated_options[ 'reorder_where' ];
764
            else
765
                $options[ 'where' ] = array( 'reorder' => $deprecated_options[ 'reorder_where' ] );
766
        }
767
768
        if ( isset( $deprecated_options[ 'sql' ] ) )
769
            $options[ 'sql' ] = array( 'sql' => $deprecated_options[ 'sql' ] );
770
771
        if ( isset( $deprecated_options[ 'search' ] ) )
772
            $options[ 'searchable' ] = $deprecated_options[ 'search' ];
773
        if ( isset( $deprecated_options[ 'search_across' ] ) )
774
            $options[ 'search_across' ] = $deprecated_options[ 'search_across' ];
775
        if ( isset( $deprecated_options[ 'search_across_picks' ] ) )
776
            $options[ 'search_across_picks' ] = $deprecated_options[ 'search_across_picks' ];
777
        if ( isset( $deprecated_options[ 'filters' ] ) )
778
            $options[ 'filters' ] = $deprecated_options[ 'filters' ];
779
        if ( isset( $deprecated_options[ 'custom_filters' ] ) ) {
780
            if ( is_callable( $deprecated_options[ 'custom_filters' ] ) )
781
                add_filter( 'pods_ui_filters', $deprecated_options[ 'custom_filters' ] );
782
            else {
783
                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...
784
                $pods_ui_custom_filters = $deprecated_options[ 'custom_filters' ];
785
                add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) );
786
            }
787
        }
788
789
        if ( isset( $deprecated_options[ 'disable_actions' ] ) )
790
            $options[ 'actions_disabled' ] = $deprecated_options[ 'disable_actions' ];
791
        if ( isset( $deprecated_options[ 'hide_actions' ] ) )
792
            $options[ 'actions_hidden' ] = $deprecated_options[ 'hide_actions' ];
793
794
        if ( isset( $deprecated_options[ 'wpcss' ] ) )
795
            $options[ 'wpcss' ] = $deprecated_options[ 'wpcss' ];
796
797
        $remaining_options = array_diff_assoc( $options, $deprecated_options );
798
799
        foreach ( $remaining_options as $option => $value ) {
800
            if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) )
801
                $options[ $option ] = $value;
802
        }
803
804
        return $options;
805
    }
806
807
    /**
808
     *
809
     */
810
    public function deprecated_filters () {
811
        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...
812
        echo $pods_ui_custom_filters;
813
    }
814
815
    /**
816
     * @param $options
817
     *
818
     * @return array|bool|mixed|null|PodsArray
819
     */
820
    public function setup ( $options ) {
821
        $options = pods_array( $options );
822
823
        $options->validate( 'num', '', 'absint' );
824
825
        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...
826
            $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...
827
828
        $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...
829
830
        $options->validate( '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...
831
            'save',
832
            'create'
833
        ) );
834
835
        $options->validate( 'excluded', self::$excluded, 'array_merge' );
836
837
        $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...
838
        $options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' );
839
        $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...
840
841
        $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...
842
843
        if ( !empty( $bulk ) )
844
            $bulk = (array) pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true );
845
        else
846
            $bulk = array();
847
848
        $options->validate( 'bulk', $bulk, 'array_merge', $this->bulk );
849
850
        $options->validate( 'views', $this->views, 'array' );
851
        $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...
852
853
        $options->validate( 'searchable', $this->searchable, 'boolean' );
854
        $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...
855
        $options->validate( 'search_across', $this->search_across, 'boolean' );
856
        $options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' );
857
        $options->validate( 'filters', $this->filters, 'array' );
858
        $options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' );
859
        $options->validate( 'where', $this->where, 'array_merge' );
860
861
        $options->validate( 'pagination', $this->pagination, 'boolean' );
862
        $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...
863
        $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...
864
865
        if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) {
866
            $this->sql = array(
867
                'table' => $this->pods_data->table,
868
                'field_id' => $this->pods_data->field_id,
869
                'field_index' => $this->pods_data->field_index
870
            );
871
        }
872
        $options->validate( 'sql', $this->sql, 'array_merge' );
873
874
        $options->validate( 'orderby_dir', strtoupper( pods_v( 'orderby_dir' . $options[ 'num' ], 'get', $this->orderby_dir, true ) ), 'in_array', array( 'ASC', 'DESC' ) );
875
876
	    $orderby = $this->orderby;
877
878
	    // Enforce strict DB column name usage
879
	    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...
880
		    $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...
881
	    }
882
883
        if ( !empty( $orderby ) ) {
884
            $orderby = array(
885
                'default' => $orderby
886
            );
887
        }
888
        else
889
            $orderby = array();
890
891
        $options->validate( 'orderby', $orderby, 'array_merge' );
892
        $options->validate( 'sortable', $this->sortable, 'boolean' );
893
894
        $options->validate( 'params', $this->params, 'array' );
895
896
        $options->validate( 'restrict', $this->restrict, 'array_merge' );
897
898
        // handle author restrictions
899
        if ( !empty( $options[ 'restrict' ][ 'author_restrict' ] ) ) {
900
            $restrict = $options[ 'restrict' ];
901
902
            if ( !is_array( $restrict[ 'author_restrict' ] ) )
903
                $restrict[ 'author_restrict' ] = array( $restrict[ 'author_restrict' ] => get_current_user_id() );
904
905
            if ( null === $restrict[ 'edit' ] )
906
                $restrict[ 'edit' ] = $restrict[ 'author_restrict' ];
907
908
            $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...
909
        }
910
911
        if ( null !== $options[ 'restrict' ][ 'edit' ] ) {
912
            $restrict = $options[ 'restrict' ];
913
914
            if ( null === $restrict[ 'duplicate' ] )
915
                $restrict[ 'duplicate' ] = $restrict[ 'edit' ];
916
917
            if ( null === $restrict[ 'delete' ] )
918
                $restrict[ 'delete' ] = $restrict[ 'edit' ];
919
920
            if ( null === $restrict[ 'manage' ] )
921
                $restrict[ 'manage' ] = $restrict[ 'edit' ];
922
923
            if ( null === $restrict[ 'reorder' ] )
924
                $restrict[ 'reorder' ] = $restrict[ 'edit' ];
925
926
            $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...
927
        }
928
929
        $item = __( 'Item', 'pods' );
930
        $items = __( 'Items', 'pods' );
931
932
        if ( is_object( $this->pod ) ) {
933
            $item = pods_var_raw( 'label_singular', $this->pod->pod_data[ 'options' ], pods_var_raw( 'label', $this->pod->pod_data, $item, null, true ), null, true );
934
            $items = pods_var_raw( 'label', $this->pod->pod_data, $items, null, true );
935
        }
936
937
        $options->validate( 'item', $item );
938
        $options->validate( 'items', $items );
939
940
        $options->validate( 'heading', array(
941
            'manage' => __( 'Manage', 'pods' ),
942
            'add' => __( 'Add New', 'pods' ),
943
            'edit' => __( 'Edit', 'pods' ),
944
            'duplicate' => __( 'Duplicate', 'pods' ),
945
            'view' => __( 'View', 'pods' ),
946
            'reorder' => __( 'Reorder', 'pods' ),
947
            'search' => __( 'Search', 'pods' ),
948
            'views' => __( 'View', 'pods' )
949
        ), 'array_merge' );
950
951
        $options->validate( 'header', array(
952
            'manage' => 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...
953
            'add' => 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...
954
            'edit' => 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...
955
            'duplicate' => 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...
956
            'view' => 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...
957
            'reorder' => 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...
958
            'search' => 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...
959
        ), 'array_merge' );
960
961
        $options->validate( 'label', array(
962
            'add' => sprintf( __( 'Save 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...
963
            'add_new' => __( 'Add New', 'pods' ),
964
            'edit' => sprintf( __( 'Save %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...
965
            'duplicate' => sprintf( __( 'Save 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...
966
            'delete' => 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...
967
            'view' => 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...
968
            'reorder' => 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...
969
        ), 'array_merge' );
970
971
        $options->validate( 'fields', array(
972
            'manage' => array(
973
                $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...
974
            )
975
        ), 'array' );
976
977
        $options->validate( 'export', $this->export, 'array_merge' );
978
        $options->validate( 'reorder', $this->reorder, 'array_merge' );
979
        $options->validate( 'screen_options', $this->screen_options, 'array_merge' );
980
981
        $options->validate( 'session', $this->session, 'in_array', array(
982
            'search',
983
            'filters',
984
            'show_per_page',
985
            'orderby'
986
        ) );
987
        $options->validate( 'user', $this->user, 'in_array', array(
988
            'search',
989
            'filters',
990
            'show_per_page',
991
            'orderby'
992
        ) );
993
994
        $options->validate( 'action_after', $this->action_after, 'array_merge' );
995
        $options->validate( 'action_links', $this->action_links, 'array_merge' );
996
        $options->validate( 'actions_disabled', $this->actions_disabled, 'array' );
997
        $options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' );
998
        $options->validate( 'actions_custom', $this->actions_custom, 'array_merge' );
999
1000
		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...
1001 View Code Duplication
			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...
1002
				$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...
1003
1004
				foreach ( $actions_bulk as $action => $action_opt ) {
1005
					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...
1006
						unset( $actions_bulk[ $action ] );
1007
					}
1008
				}
1009
1010
				$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...
1011
			}
1012
1013 View Code Duplication
			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...
1014
				$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...
1015
1016
				foreach ( $actions_custom as $action => $action_opt ) {
1017
					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...
1018
						unset( $actions_custom[ $action ] );
1019
					}
1020
				}
1021
1022
				$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...
1023
			}
1024
		}
1025
1026
        $options->validate( 'extra', $this->extra, 'array_merge' );
1027
1028
        $options->validate( 'style', $this->style );
1029
        $options->validate( 'icon', $this->icon );
1030
        $options->validate( 'css', $this->css );
1031
        $options->validate( 'wpcss', $this->wpcss, 'boolean' );
1032
1033
        if ( true === $options[ 'wpcss' ] ) {
1034
            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...
1035
            wp_get_current_user();
1036
1037
            $color = get_user_meta( $user_ID, 'admin_color', true );
1038
            if ( strlen( $color ) < 1 )
1039
                $color = 'fresh';
1040
1041
            $this->wpcss = "colors-{$color}";
1042
        }
1043
1044
        $options = $options->dump();
1045
1046
        if ( is_object( $this->pod ) )
1047
            $options = $this->do_hook( $this->pod->pod . '_setup_options', $options );
1048
1049
        $options = $this->do_hook( 'setup_options', $options );
1050
1051
        if ( false !== $options && !empty( $options ) ) {
1052
            foreach ( $options as $option => $value ) {
1053
                if ( isset( $this->{$option} ) )
1054
                    $this->{$option} = $value;
1055
                else
1056
                    $this->x[ $option ] = $value;
1057
            }
1058
        }
1059
1060
        $unique_identifier = pods_var( 'page', 'get' ); // wp-admin page
1061
        if ( is_object( $this->pod ) && isset( $this->pod->pod ) )
1062
            $unique_identifier = '_' . $this->pod->pod;
1063
        elseif ( 0 < strlen( $this->sql[ 'table' ] ) )
1064
            $unique_identifier = '_' . $this->sql[ 'table' ];
1065
1066
        $unique_identifier .= '_' . $this->page;
1067
        if ( 0 < strlen( $this->num ) )
1068
            $unique_identifier .= '_' . $this->num;
1069
1070
        $this->unique_identifier = 'pods_ui_' . md5( $unique_identifier );
1071
1072
        $this->setup_fields();
1073
1074
        return $options;
1075
    }
1076
1077
    /**
1078
     * @param null $fields
1079
     * @param string $which
1080
     *
1081
     * @return array|bool|mixed|null
1082
     */
1083
    public function setup_fields ( $fields = null, $which = 'fields' ) {
1084
        $init = false;
1085
        if ( null === $fields ) {
1086
            if ( isset( $this->fields[ $which ] ) )
1087
                $fields = (array) $this->fields[ $which ];
1088
            elseif ( isset( $this->fields[ 'manage' ] ) )
1089
                $fields = (array) $this->fields[ 'manage' ];
1090
            else
1091
                $fields = array();
1092
            if ( 'fields' == $which )
1093
                $init = true;
1094
        }
1095
        if ( !empty( $fields ) ) {
1096
            // Available Attributes
1097
            // type = field type
1098
            // type = date (data validation as date)
1099
            // type = time (data validation as time)
1100
            // type = datetime (data validation as datetime)
1101
            // date_touch = use current timestamp when saving (even if readonly, if type is date-related)
1102
            // date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related)
1103
            // 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
1104
            // type = text / other (single line text box)
1105
            // type = desc (textarea)
1106
            // type = number (data validation as int float)
1107
            // type = decimal (data validation as decimal)
1108
            // type = password (single line password box)
1109
            // type = bool (checkbox)
1110
            // type = related (select box)
1111
            // related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items
1112
            // related_field = field name on table to show (if type=related) - default "name"
1113
            // related_multiple = true (ability to select multiple values if type=related)
1114
            // related_sql = custom where / order by SQL (if type=related)
1115
            // readonly = true (shows as text)
1116
            // display = false (doesn't show on form, but can be saved)
1117
            // search = this field is searchable
1118
            // filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box)
1119
            // comments = comments to show for field
1120
            // comments_top = true (shows comments above field instead of below)
1121
            // real_name = the real name of the field (if using an alias for 'name')
1122
            // group_related = true (uses HAVING instead of WHERE for filtering field)
1123
            $new_fields = array();
1124
            $filterable = false;
1125
            if ( empty( $this->filters ) && ( empty( $this->fields[ 'search' ] ) || 'search' == $which ) && false !== $this->searchable ) {
1126
                $filterable = true;
1127
                $this->filters = array();
1128
            }
1129
1130
            foreach ( $fields as $field => $attributes ) {
1131
                if ( !is_array( $attributes ) ) {
1132
                    if ( is_int( $field ) ) {
1133
                        $field = $attributes;
1134
                        $attributes = array();
1135
                    }
1136
                    else
1137
                        $attributes = array( 'label' => $attributes );
1138
                }
1139
1140
                if ( !isset( $attributes[ 'real_name' ] ) )
1141
                    $attributes[ 'real_name' ] = pods_var( 'name', $attributes, $field );
1142
1143
                if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes[ 'real_name' ] ] ) )
1144
                    $attributes = array_merge( $this->pod->fields[ $attributes[ 'real_name' ] ], $attributes );
1145
1146
                if ( !isset( $attributes[ 'options' ] ) )
1147
                    $attributes[ 'options' ] = array();
1148
                if ( !isset( $attributes[ 'id' ] ) )
1149
                    $attributes[ 'id' ] = '';
1150
                if ( !isset( $attributes[ 'label' ] ) )
1151
                    $attributes[ 'label' ] = ucwords( str_replace( '_', ' ', $field ) );
1152
                if ( !isset( $attributes[ 'type' ] ) )
1153
                    $attributes[ 'type' ] = 'text';
1154
                if ( !isset( $attributes[ 'options' ][ 'date_format_type' ] ) )
1155
                    $attributes[ 'options' ][ 'date_format_type' ] = 'date';
1156 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related' ] ) )
1157
                    $attributes[ 'related' ] = false;
1158 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_id' ] ) )
1159
                    $attributes[ 'related_id' ] = 'id';
1160 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_field' ] ) )
1161
                    $attributes[ 'related_field' ] = 'name';
1162 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_multiple' ] ) )
1163
                    $attributes[ 'related_multiple' ] = false;
1164 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_sql' ] ) )
1165
                    $attributes[ 'related_sql' ] = false;
1166
                if ( 'related' == $attributes[ 'type' ] && ( is_array( $attributes[ 'related' ] ) || strpos( $attributes[ 'related' ], ',' ) ) ) {
1167
                    if ( !is_array( $attributes[ 'related' ] ) ) {
1168
                        $attributes[ 'related' ] = @explode( ',', $attributes[ 'related' ] );
1169
                        $related_items = array();
1170
                        foreach ( $attributes[ 'related' ] as $key => $label ) {
1171
                            if ( is_numeric( $key ) ) {
1172
                                $key = $label;
1173
                                $label = ucwords( str_replace( '_', ' ', $label ) );
1174
                            }
1175
                            $related_items[ $key ] = $label;
1176
                        }
1177
                        $attributes[ 'related' ] = $related_items;
1178
                    }
1179
                    if ( empty( $attributes[ 'related' ] ) )
1180
                        $attributes[ 'related' ] = false;
1181
                }
1182
                if ( !isset( $attributes[ 'readonly' ] ) )
1183
                    $attributes[ 'readonly' ] = false;
1184
                if ( !isset( $attributes[ 'date_touch' ] ) || 'date' != $attributes[ 'type' ] )
1185
                    $attributes[ 'date_touch' ] = false;
1186
                if ( !isset( $attributes[ 'date_touch_on_create' ] ) || 'date' != $attributes[ 'type' ] )
1187
                    $attributes[ 'date_touch_on_create' ] = false;
1188
                if ( !isset( $attributes[ 'display' ] ) )
1189
                    $attributes[ 'display' ] = true;
1190
                if ( !isset( $attributes[ 'hidden' ] ) )
1191
                    $attributes[ 'hidden' ] = false;
1192
                if ( !isset( $attributes[ 'sortable' ] ) || false === $this->sortable )
1193
                    $attributes[ 'sortable' ] = $this->sortable;
1194 View Code Duplication
                if ( !isset( $attributes[ 'options' ][ 'search' ] ) || false === $this->searchable )
1195
                    $attributes[ 'options' ][ 'search' ] = $this->searchable;
1196 View Code Duplication
                if ( !isset( $attributes[ 'options' ][ 'filter' ] ) || false === $this->searchable )
1197
                    $attributes[ 'options' ][ 'filter' ] = $this->searchable;
1198
                /*if ( false !== $attributes[ 'options' ][ 'filter' ] && false !== $filterable )
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
1199
                    $this->filters[] = $field;*/
1200
                if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_label' ] ) || !in_array( $field, $this->filters ) )
1201
                    $attributes[ 'filter_label' ] = $attributes[ 'label' ];
1202
                if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_default' ] ) || !in_array( $field, $this->filters ) )
1203
                    $attributes[ 'filter_default' ] = false;
1204 View Code Duplication
                if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !in_array( $field, $this->filters ) )
1205
                    $attributes[ 'date_ongoing' ] = false;
1206 View Code Duplication
                if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !isset( $attributes[ 'date_ongoing_default' ] ) || !in_array( $field, $this->filters ) )
1207
                    $attributes[ 'date_ongoing_default' ] = false;
1208
                if ( !isset( $attributes[ 'export' ] ) )
1209
                    $attributes[ 'export' ] = true;
1210
                if ( !isset( $attributes[ 'group_related' ] ) )
1211
                    $attributes[ 'group_related' ] = false;
1212
                if ( !isset( $attributes[ 'comments' ] ) )
1213
                    $attributes[ 'comments' ] = '';
1214
                if ( !isset( $attributes[ 'comments_top' ] ) )
1215
                    $attributes[ 'comments_top' ] = false;
1216
                if ( !isset( $attributes[ 'custom_view' ] ) )
1217
                    $attributes[ 'custom_view' ] = false;
1218
                if ( !isset( $attributes[ 'custom_input' ] ) )
1219
                    $attributes[ 'custom_input' ] = false;
1220
                if ( isset( $attributes[ 'display_helper' ] ) ) // pods ui backward compatibility
1221
                    $attributes[ 'custom_display' ] = $attributes[ 'display_helper' ];
1222
                if ( !isset( $attributes[ 'custom_display' ] ) )
1223
                    $attributes[ 'custom_display' ] = false;
1224
                if ( !isset( $attributes[ 'custom_relate' ] ) )
1225
                    $attributes[ 'custom_relate' ] = false;
1226
                if ( !isset( $attributes[ 'custom_form_display' ] ) )
1227
                    $attributes[ 'custom_form_display' ] = false;
1228
                if ( !isset( $attributes[ 'css_values' ] ) )
1229
                    $attributes[ 'css_values' ] = true;
1230
                if ( 'search_columns' == $which && !$attributes[ 'options' ][ 'search' ] )
1231
                    continue;
1232
1233
                $attributes = PodsForm::field_setup( $attributes, null, $attributes[ 'type' ] );
1234
1235
                $new_fields[ $field ] = $attributes;
1236
            }
1237
            $fields = $new_fields;
1238
        }
1239
        if ( false !== $init ) {
1240
            if ( 'fields' != $which && !empty( $this->fields ) )
1241
                $this->fields = $this->setup_fields( $this->fields, 'fields' );
1242
            else
1243
                $this->fields[ 'manage' ] = $fields;
1244
1245
            if ( !in_array( 'add', $this->actions_disabled ) || !in_array( 'edit', $this->actions_disabled ) || !in_array( 'duplicate', $this->actions_disabled ) ) {
1246
                if ( 'form' != $which && isset( $this->fields[ 'form' ] ) && is_array( $this->fields[ 'form' ] ) )
1247
                    $this->fields[ 'form' ] = $this->setup_fields( $this->fields[ 'form' ], 'form' );
1248
                else
1249
                    $this->fields[ 'form' ] = $fields;
1250
1251
                if ( !in_array( 'add', $this->actions_disabled ) ) {
1252
                    if ( 'add' != $which && isset( $this->fields[ 'add' ] ) && is_array( $this->fields[ 'add' ] ) )
1253
                        $this->fields[ 'add' ] = $this->setup_fields( $this->fields[ 'add' ], 'add' );
1254
                }
1255
                if ( !in_array( 'edit', $this->actions_disabled ) ) {
1256
                    if ( 'edit' != $which && isset( $this->fields[ 'edit' ] ) && is_array( $this->fields[ 'edit' ] ) )
1257
                        $this->fields[ 'edit' ] = $this->setup_fields( $this->fields[ 'edit' ], 'edit' );
1258
                }
1259
                if ( !in_array( 'duplicate', $this->actions_disabled ) ) {
1260
                    if ( 'duplicate' != $which && isset( $this->fields[ 'duplicate' ] ) && is_array( $this->fields[ 'duplicate' ] ) )
1261
                        $this->fields[ 'duplicate' ] = $this->setup_fields( $this->fields[ 'duplicate' ], 'duplicate' );
1262
                }
1263
            }
1264
1265 View Code Duplication
            if ( false !== $this->searchable ) {
1266
                if ( 'search' != $which && isset( $this->fields[ 'search' ] ) &&!empty( $this->fields[ 'search' ] ) )
1267
                    $this->fields[ 'search' ] = $this->setup_fields( $this->fields[ 'search' ], 'search' );
1268
                else
1269
                    $this->fields[ 'search' ] = $fields;
1270
            }
1271
            else
1272
                $this->fields[ 'search' ] = false;
1273
1274
            if ( !in_array( 'export', $this->actions_disabled ) ) {
1275
                if ( 'export' != $which && isset( $this->fields[ 'export' ] ) &&!empty( $this->fields[ 'export' ] ) )
1276
                    $this->fields[ 'export' ] = $this->setup_fields( $this->fields[ 'export' ], 'export' );
1277
            }
1278
1279 View Code Duplication
            if ( !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
1280
                if ( 'reorder' != $which && isset( $this->fields[ 'reorder' ] ) &&!empty( $this->fields[ 'reorder' ] ) )
1281
                    $this->fields[ 'reorder' ] = $this->setup_fields( $this->fields[ 'reorder' ], 'reorder' );
1282
                else
1283
                    $this->fields[ 'reorder' ] = $fields;
1284
            }
1285
        }
1286
        return $this->do_hook( 'setup_fields', $fields, $which, $init );
1287
    }
1288
1289
    /**
1290
     * @param $msg
1291
     * @param bool $error
1292
     */
1293
    public function message ( $msg, $error = false ) {
1294
        $msg = $this->do_hook( ( $error ) ? 'error' : 'message', $msg );
1295
        ?>
1296
    <div id="message" class="<?php echo esc_attr( ( $error ) ? 'error' : 'updated' ); ?> fade"><p><?php echo $msg; ?></p></div>
1297
    <?php
1298
    }
1299
1300
    /**
1301
     * @param $msg
1302
     *
1303
     * @return bool
1304
     */
1305
    public function error ( $msg ) {
1306
        $this->message( $msg, true );
1307
1308
        return false;
1309
    }
1310
1311
    /**
1312
     * @return mixed
1313
     */
1314
    public function go () {
1315
        $this->do_hook( 'go' );
1316
        $_GET = pods_unsanitize( $_GET ); // fix wp sanitization
1317
        $_POST = pods_unsanitize( $_POST ); // fix wp sanitization
1318
1319
        if ( false !== $this->css ) {
1320
            ?>
1321
        <link type="text/css" rel="stylesheet" href="<?php echo esc_url( $this->css ); ?>" />
1322
        <?php
1323
        }
1324
        if ( false !== $this->wpcss ) {
1325
            $stylesheets = array( 'global', 'wp-admin', $this->wpcss );
1326
            foreach ( $stylesheets as $style ) {
1327
                if ( !wp_style_is( $style, 'queue' ) && !wp_style_is( $style, 'to_do' ) && !wp_style_is( $style, 'done' ) )
1328
                    wp_enqueue_style( $style );
1329
            }
1330
        }
1331
1332
        $this->ui_page = array( $this->action );
1333
        if ( 'add' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
1334
            $this->ui_page[] = 'form';
1335 View Code Duplication
            if ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
1336
                $this->ui_page[] = $this->do;
1337
                $this->save( true );
1338
                $this->manage();
1339
            }
1340
            else
1341
                $this->add();
1342
        }
1343
        elseif ( ( 'edit' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ) {
1344
            $this->ui_page[] = 'form';
1345
            if ( 'save' == $this->do && $this->save && !empty( $_POST ) )
1346
                $this->save();
1347
            $this->edit( ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ? true : false );
1348
        }
1349
        elseif ( 'delete' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== wp_verify_nonce( $this->_nonce, 'pods-ui-action-delete' ) ) {
1350
            $this->delete( $this->id );
1351
            $this->manage();
1352
        }
1353
        elseif ( 'reorder' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
1354
            if ( 'save' == $this->do ) {
1355
                $this->ui_page[] = $this->do;
1356
                $this->reorder();
1357
            }
1358
            $this->manage( true );
1359
        }
1360
        elseif ( 'save' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
1361
            $this->ui_page[] = $this->do;
1362
            $this->save();
1363
            $this->manage();
1364
        }
1365 View Code Duplication
        elseif ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
1366
            $this->ui_page[] = $this->do;
1367
            $this->save( true );
1368
            $this->manage();
1369
        }
1370
        elseif ( 'view' == $this->action && !in_array( $this->action, $this->actions_disabled ) )
1371
            $this->view();
1372
		else {
1373
			if ( isset( $this->actions_custom[ $this->action ] ) ) {
1374
				$more_args = false;
1375
1376
				if ( is_array( $this->actions_custom[ $this->action ] ) && isset( $this->actions_custom[ $this->action ][ 'more_args' ] ) ) {
1377
					$more_args = $this->actions_custom[ $this->action ][ 'more_args' ];
1378
				}
1379
1380
				$row = $this->row;
1381
1382
				if ( empty( $row ) ) {
1383
					$row = $this->get_row();
1384
				}
1385
1386
				if ( $this->restricted( $this->action, $row ) || ( $more_args && ! empty( $more_args[ 'nonce' ] ) && false === wp_verify_nonce( $this->_nonce, 'pods-ui-action-' . $this->action ) ) ) {
1387
					return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1388
				}
1389
				elseif ( $more_args && false !== $this->callback_action( true, $this->action, $this->id, $row ) ) {
1390
					return null;
1391
				}
1392
				elseif ( false !== $this->callback_action( true, $this->action, $this->id ) ) {
1393
					return null;
1394
				}
1395
			}
1396
1397
			if ( !in_array( 'manage', $this->actions_disabled ) ) {
1398
				// handle session / user persistent settings for show_per_page, orderby, search, and filters
1399
				$methods = array( 'session', 'user' );
1400
1401
				// @todo fix this to set ($this) AND save (setting)
1402
				foreach ( $methods as $method ) {
1403
					foreach ( $this->$method as $setting ) {
1404
						if ( 'show_per_page' == $setting )
1405
							$value = $this->limit;
1406
						elseif ( 'orderby' == $setting ) {
1407
							if ( empty( $this->orderby ) )
1408
								$value = '';
1409
							// save this if we have a default index set
1410
							elseif ( isset( $this->orderby[ 'default' ] ) ) {
1411
								$value = $this->orderby[ 'default' ] . ' '
1412
										 . ( false === strpos( $this->orderby[ 'default' ], ' ' ) ? $this->orderby_dir : '' );
1413
							}
1414
							else
1415
								$value = '';
1416
						}
1417
						else
1418
							$value = $this->$setting;
1419
1420
						pods_v_set( $value, $setting, $method );
1421
					}
1422
				}
1423
1424
				$this->manage();
1425
			}
1426
		}
1427
    }
1428
1429
    /**
1430
     * @return mixed
1431
     */
1432
    public function add () {
1433
		if ( false !== $this->callback_action( 'add' ) ) {
1434
			return null;
1435
		}
1436
        ?>
1437
    <div class="wrap pods-ui">
1438
        <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
1439
        <h2>
1440
            <?php
1441
            echo $this->header[ 'add' ];
1442
1443
			$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1444
1445
			if ( !empty( $this->action_links[ 'manage' ] ) ) {
1446
				$link = $this->action_links[ 'manage' ];
1447
			}
1448
            ?>
1449
            <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
1450
        </h2>
1451
1452
        <?php $this->form( true ); ?>
1453
    </div>
1454
    <?php
1455
    }
1456
1457
    /**
1458
     * @param bool $duplicate
1459
     *
1460
     * @return mixed
1461
     */
1462
    public function edit ( $duplicate = false ) {
1463
        if ( in_array( 'duplicate', $this->actions_disabled ) )
1464
            $duplicate = false;
1465
1466
        if ( empty( $this->row ) )
1467
            $this->get_row();
1468
1469
		if ( $duplicate && false !== $this->callback_action( 'duplicate' ) ) {
1470
			return null;
1471
		}
1472
		elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) {
1473
			return null;
1474
		}
1475
        ?>
1476
    <div class="wrap pods-ui">
1477
        <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
1478
        <h2>
1479
            <?php
1480
            echo $this->do_template( $duplicate ? $this->header[ 'duplicate' ] : $this->header[ 'edit' ] );
1481
1482 View Code Duplication
            if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
1483
                $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1484
1485
                if ( !empty( $this->action_links[ 'add' ] ) )
1486
                    $link = $this->action_links[ 'add' ];
1487
                ?>
1488
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->heading[ 'add' ]; ?></a>
1489
                <?php
1490
            }
1491
            elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
1492
                $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1493
1494
                if ( !empty( $this->action_links[ 'manage' ] ) )
1495
                    $link = $this->action_links[ 'manage' ];
1496
                ?>
1497
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
1498
                <?php
1499
            }
1500
            ?>
1501
        </h2>
1502
1503
        <?php $this->form( false, $duplicate ); ?>
1504
    </div>
1505
    <?php
1506
    }
1507
1508
    /**
1509
     * @param bool $create
1510
     * @param bool $duplicate
1511
     *
1512
     * @return bool|mixed
1513
     */
1514
    public function form ( $create = false, $duplicate = false ) {
1515
        if ( in_array( 'duplicate', $this->actions_disabled ) )
1516
            $duplicate = false;
1517
1518
		if ( false !== $this->callback( 'form' ) ) {
1519
			return null;
1520
		}
1521
1522
        $label = $this->label[ 'add' ];
1523
        $id = null;
1524
        $vars = array(
1525
            'action' . $this->num => $this->action_after[ 'add' ],
1526
            'do' . $this->num => 'create',
1527
            'id' . $this->num => 'X_ID_X'
1528
        );
1529
1530
        $alt_vars = $vars;
1531
        $alt_vars[ 'action' ] = 'manage';
1532
        unset( $alt_vars[ 'id' ] );
1533
1534
        if ( false === $create ) {
1535
            if ( empty( $this->row ) )
1536
                $this->get_row();
1537
1538
            if ( empty( $this->row ) && ( !is_object( $this->pod ) || 'settings' != $this->pod->pod_data[ 'type' ] ) )
1539
                return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
1540
1541
            if ( $this->restricted( $this->action, $this->row ) )
1542
                return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1543
1544
            $label = $this->do_template( $this->label[ 'edit' ] );
1545
            $id = $this->row[ $this->sql[ 'field_id' ] ];
1546
            $vars = array(
1547
                'action' . $this->num => $this->action_after[ 'edit' ],
1548
                'do' . $this->num => 'save',
1549
                'id' . $this->num => $id
1550
            );
1551
1552
            $alt_vars = $vars;
1553
            $alt_vars[ 'action' ] = 'manage';
1554
            unset( $alt_vars[ 'id' ] );
1555
1556
            if ( $duplicate ) {
1557
                $label = $this->do_template( $this->label[ 'duplicate' ] );
1558
                $id = null;
1559
                $vars = array(
1560
                    'action' . $this->num => $this->action_after[ 'duplicate' ],
1561
                    'do' . $this->num => 'create',
1562
                    'id' . $this->num => 'X_ID_X'
1563
                );
1564
1565
                $alt_vars = $vars;
1566
                $alt_vars[ 'action' ] = 'manage';
1567
                unset( $alt_vars[ 'id' ] );
1568
            }
1569
        }
1570
1571
		$fields = array();
1572
1573
        if ( isset( $this->fields[ $this->action ] ) )
1574
            $fields = $this->fields[ $this->action ];
1575
1576 View Code Duplication
        if ( is_object( $this->pod ) ) {
1577
            $object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
1578
1579
            if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], array( 'post_type', 'taxonomy', 'media', 'user', 'comment' ) ) )
1580
                $object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data );
1581
1582
            if ( empty( $fields ) ) {
1583
                // Add core object fields if $fields is empty
1584
                $fields = array_merge( $object_fields, $this->pod->fields );
1585
            }
1586
        }
1587
1588
        $form_fields = $fields; // Temporary
1589
1590
        $fields = array();
1591
1592
        foreach ( $form_fields as $k => $field ) {
1593
            $name = $k;
1594
1595
            $defaults = array(
1596
                'name' => $name
1597
            );
1598
1599
            if ( !is_array( $field ) ) {
1600
                $name = $field;
1601
1602
                $field = array(
1603
                    'name' => $name
1604
                );
1605
            }
1606
1607
            $field = array_merge( $defaults, $field );
1608
1609
            $field[ 'name' ] = trim( $field[ 'name' ] );
1610
1611
            $default_value = pods_var_raw( 'default', $field );
1612
            $value = pods_var_raw( 'value', $field );
1613
1614
            if ( empty( $field[ 'name' ] ) )
1615
                $field[ 'name' ] = trim( $name );
1616
1617 View Code Duplication
            if ( isset( $object_fields[ $field[ 'name' ] ] ) )
1618
                $field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
1619
            elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) )
1620
                $field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field );
1621
1622 View Code Duplication
            if ( pods_var_raw( 'hidden', $field, false, null, true ) )
1623
                $field[ 'type' ] = 'hidden';
1624
1625
			$fields[ $field[ 'name' ] ] = $field;
1626
1627 View Code Duplication
            if ( empty( $this->id ) && null !== $default_value ) {
1628
                $this->pod->row_override[ $field[ 'name' ] ] = $default_value;
1629
			}
1630
			elseif ( !empty( $this->id ) && null !== $value ) {
1631
                $this->pod->row[ $field[ 'name' ] ] = $value;
1632
			}
1633
        }
1634
1635
        unset( $form_fields ); // Cleanup
1636
1637
        $fields = $this->do_hook( 'form_fields', $fields, $this->pod );
1638
1639
        $pod =& $this->pod;
1640
        $thank_you = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
1641
        $thank_you_alt = pods_query_arg( $alt_vars, self::$allowed, $this->exclusion() );
1642
        $obj =& $this;
1643
        $singular_label = $this->item;
1644
        $plural_label = $this->items;
1645
1646
        if ( is_object( $this->pod ) && 'settings' == $this->pod->pod_data[ 'type' ] && 'settings' == $this->style )
1647
            pods_view( PODS_DIR . 'ui/admin/form-settings.php', compact( array_keys( get_defined_vars() ) ) );
1648
        else
1649
            pods_view( PODS_DIR . 'ui/admin/form.php', compact( array_keys( get_defined_vars() ) ) );
1650
    }
1651
1652
    /**
1653
     * @return bool|mixed
1654
	 * @since 2.3.10
1655
     */
1656
    public function view () {
1657
1658
		if ( false !== $this->callback_action( 'view' ) ) {
1659
            return null;
1660
		}
1661
1662
        if ( empty( $this->row ) ) {
1663
            $this->get_row();
1664
		}
1665
1666
        if ( empty( $this->row ) ) {
1667
            return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
1668
		}
1669
1670
		$pod =& $this->pod;
1671
		$obj =& $this;
1672
1673
		$fields = array();
1674
1675
		if ( isset( $this->fields[ $this->action ] ) ) {
1676
			$fields = $this->fields[ $this->action ];
1677
		}
1678
1679 View Code Duplication
		if ( is_object( $this->pod ) ) {
1680
			$object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
1681
1682
			$object_field_objects = array(
1683
				'post_type',
1684
				'taxonomy',
1685
				'media',
1686
				'user',
1687
				'comment'
1688
			);
1689
1690
			if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], $object_field_objects ) ) {
1691
				$object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data );
1692
			}
1693
1694
			if ( empty( $fields ) ) {
1695
				// Add core object fields if $fields is empty
1696
				$fields = array_merge( $object_fields, $this->pod->fields );
1697
			}
1698
		}
1699
1700
		$view_fields = $fields; // Temporary
1701
1702
		$fields = array();
1703
1704
		foreach ( $view_fields as $k => $field ) {
1705
			$name = $k;
1706
1707
			$defaults = array(
1708
				'name' => $name,
1709
				'type' => 'text',
1710
				'options' => 'text'
1711
			);
1712
1713
			if ( !is_array( $field ) ) {
1714
				$name = $field;
1715
1716
				$field = array(
1717
					'name' => $name
1718
				);
1719
			}
1720
1721
			$field = array_merge( $defaults, $field );
1722
1723
			$field[ 'name' ] = trim( $field[ 'name' ] );
1724
1725
			$value = pods_var_raw( 'default', $field );
1726
1727
			if ( empty( $field[ 'name' ] ) ) {
1728
				$field[ 'name' ] = trim( $name );
1729
			}
1730
1731 View Code Duplication
			if ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
1732
				$field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
1733
			}
1734
			elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) ) {
1735
				$field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field );
1736
			}
1737
1738 View Code Duplication
			if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' == $field[ 'type' ] ) {
1739
				continue;
1740
			}
1741
			elseif ( !PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
1742
				continue;
1743
			}
1744
1745
			$fields[ $field[ 'name' ] ] = $field;
1746
1747
			if ( empty( $this->id ) && null !== $value ) {
1748
				$this->pod->row_override[ $field[ 'name' ] ] = $value;
1749
			}
1750
		}
1751
1752
		unset( $view_fields ); // Cleanup
1753
		?>
1754
		<div class="wrap pods-ui">
1755
			<div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
1756
			<h2>
1757
				<?php
1758
					echo $this->do_template( $this->header[ 'view' ] );
1759
1760 View Code Duplication
					if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
1761
						$link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1762
1763
						if ( !empty( $this->action_links[ 'add' ] ) ) {
1764
							$link = $this->action_links[ 'add' ];
1765
						}
1766
				?>
1767
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->heading[ 'add' ]; ?></a>
1768
				<?php
1769
					}
1770
					elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
1771
						$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1772
1773
						if ( !empty( $this->action_links[ 'manage' ] ) ) {
1774
							$link = $this->action_links[ 'manage' ];
1775
						}
1776
				?>
1777
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
1778
				<?php
1779
					}
1780
1781
					pods_view( PODS_DIR . 'ui/admin/view.php', compact( array_keys( get_defined_vars() ) ) );
1782
				?>
1783
1784
			</h2>
1785
		</div>
1786
	<?php
1787
	}
1788
1789
1790
    /**
1791
     * Reorder data
1792
     */
1793
    public function reorder () {
1794
        // loop through order
1795
        $order = (array) pods_var_raw( 'order', 'post', array(), null, true );
1796
1797
        $params = array(
1798
            'pod' => $this->pod->pod,
1799
            'field' => $this->reorder[ 'on' ],
1800
            'order' => $order
1801
        );
1802
1803
        $reorder = pods_api()->reorder_pod_item( $params );
1804
1805
        if ( $reorder )
1806
            $this->message( sprintf( __( "<strong>Success!</strong> %s reordered successfully.", 'pods' ), $this->items ) );
1807
        else
1808
            $this->error( sprintf( __( "<strong>Error:</strong> %s has not been reordered.", 'pods' ), $this->items ) );
1809
    }
1810
1811
    /**
1812
     * @param bool $insert
1813
     *
1814
     * @return mixed
1815
     */
1816
    public function save ( $insert = false ) {
1817
        $this->do_hook( 'pre_save', $insert );
1818
1819
        if ( $this->callback( 'save', $insert ) ) {
1820
			return null;
1821
		}
1822
1823
        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...
1824
        $action = __( 'saved', 'pods' );
1825
        if ( true === $insert )
1826
            $action = __( 'created', 'pods' );
1827
        $field_sql = array();
1828
        $values = array();
1829
        $data = array();
1830
        foreach ( $this->fields[ 'form' ] as $field => $attributes ) {
1831
            $vartype = '%s';
1832
            if ( 'bool' == $attributes[ 'type' ] )
1833
                $selected = ( 1 == pods_var( $field, 'post', 0 ) ) ? 1 : 0;
1834
            elseif ( '' == pods_var( $field, 'post', '' ) )
1835
                continue;
1836
            if ( false === $attributes[ 'display' ] || false !== $attributes[ 'readonly' ] ) {
1837
                if ( !in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) )
1838
                    continue;
1839
                if ( false === $attributes[ 'date_touch' ] && ( false === $attributes[ 'date_touch_on_create' ] || false === $insert || 0 < $this->id ) )
1840
                    continue;
1841
            }
1842
            if ( in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) ) {
1843
                $format = "Y-m-d H:i:s";
1844
                if ( 'date' == $attributes[ 'type' ] )
1845
                    $format = "Y-m-d";
1846
                if ( 'time' == $attributes[ 'type' ] )
1847
                    $format = "H:i:s";
1848
                if ( false !== $attributes[ 'date_touch' ] || ( false !== $attributes[ 'date_touch_on_create' ] && true === $insert && $this->id < 1 ) )
1849
                    $value = date_i18n( $format );
1850
                else
1851
                    $value = date_i18n( $format, strtotime( ( 'time' == $attributes[ 'type' ] ) ? date_i18n( 'Y-m-d ' ) : pods_var( $field, 'post', '' ) ) );
1852
            }
1853
            else {
1854
                if ( 'bool' == $attributes[ 'type' ] ) {
1855
                    $vartype = '%d';
1856
                    $value = 0;
1857
                    if ( '' != pods_var( $field, 'post', '' ) )
1858
                        $value = 1;
1859
                }
1860 View Code Duplication
                elseif ( 'number' == $attributes[ 'type' ] ) {
1861
                    $vartype = '%d';
1862
                    $value = number_format( pods_var( $field, 'post', 0 ), 0, '', '' );
1863
                }
1864 View Code Duplication
                elseif ( 'decimal' == $attributes[ 'type' ] ) {
1865
                    $vartype = '%d';
1866
                    $value = number_format( pods_var( $field, 'post', 0 ), 2, '.', '' );
1867
                }
1868
                elseif ( 'related' == $attributes[ 'type' ] ) {
1869
                    if ( is_array( pods_var( $field, 'post', '' ) ) )
1870
                        $value = implode( ',', pods_var( $field, 'post', '' ) );
1871
                    else
1872
                        $value = pods_var( $field, 'post', '' );
1873
                }
1874
                else
1875
                    $value = pods_var( $field, 'post', '' );
1876
            }
1877
1878 View Code Duplication
            if ( isset( $attributes[ 'custom_save' ] ) && false !== $attributes[ 'custom_save' ] && is_callable( $attributes[ 'custom_save' ] ) )
1879
                $value = call_user_func_array( $attributes[ 'custom_save' ], array( $value, $field, $attributes, &$this ) );
1880
1881
            $field_sql[] = "`$field`=$vartype";
1882
            $values[] = $value;
1883
            $data[ $field ] = $value;
1884
        }
1885
        $field_sql = implode( ',', $field_sql );
1886
        if ( false === $insert && 0 < $this->id ) {
1887
            $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...
1888
            $values[] = $this->id;
1889
            $check = $wpdb->query( $wpdb->prepare( "UPDATE $this->sql['table'] SET $field_sql WHERE id=%d", $values ) );
1890
        }
1891
        else
1892
            $check = $wpdb->query( $wpdb->prepare( "INSERT INTO $this->sql['table'] SET $field_sql", $values ) );
1893
        if ( $check ) {
1894
            if ( 0 == $this->insert_id )
1895
                $this->insert_id = $wpdb->insert_id;
1896
            $this->message( sprintf( __( "<strong>Success!</strong> %s %s successfully.", 'pods' ), $this->item, $action ) );
1897
        }
1898
        else
1899
            $this->error( sprintf( __( "<strong>Error:</strong> %s has not been %s.", 'pods' ), $this->item, $action ) );
1900
        $this->do_hook( 'post_save', $this->insert_id, $data, $insert );
1901
    }
1902
1903
    /**
1904
     * @param null $id
1905
     *
1906
     * @return bool|mixed
1907
     */
1908
    public function delete ( $id = null ) {
1909
        $this->do_hook( 'pre_delete', $id );
1910
1911
		if ( false !== $this->callback_action( 'delete', $id ) ) {
1912
			return null;
1913
		}
1914
1915
        $id = pods_absint( $id );
1916
1917
        if ( empty( $id ) )
1918
            $id = pods_absint( $this->id );
1919
1920
        if ( $id < 1 )
1921
            return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods' ) );
1922
1923
        if ( false === $id )
1924
            $id = $this->id;
1925
1926
        if ( is_object( $this->pod ) )
1927
            $check = $this->pod->delete( $id );
1928 View Code Duplication
        else
1929
            $check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) );
1930
1931
        if ( $check )
1932
            $this->message( sprintf( __( "<strong>Deleted:</strong> %s has been deleted.", 'pods' ), $this->item ) );
1933
        else
1934
            $this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) );
1935
1936
        $this->do_hook( 'post_delete', $id );
1937
    }
1938
1939
    /**
1940
     * @param null $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1941
     *
1942
     * @return bool|mixed
1943
     */
1944
    public function delete_bulk () {
1945
        $this->do_hook( 'pre_delete_bulk' );
1946
1947
        if ( 1 != pods_var( 'deleted_bulk', 'get', 0 ) ) {
1948
            $ids = $this->bulk;
1949
1950
            $success = false;
1951
1952
            if ( !empty( $ids ) ) {
1953
                $ids = (array) $ids;
1954
1955
                foreach ( $ids as $id ) {
1956
                    $id = pods_absint( $id );
1957
1958
                    if ( empty( $id ) )
1959
                        continue;
1960
1961
					if ( $callback = $this->callback( 'delete', $id ) ) {
1962
						$check = $callback;
1963
					}
1964
                    elseif ( is_object( $this->pod ) )
1965
                        $check = $this->pod->delete( $id );
1966 View Code Duplication
                    else
1967
                        $check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) );
1968
1969
                    if ( $check )
1970
                        $success = true;
1971
                }
1972
            }
1973
1974
            if ( $success )
1975
                pods_redirect( pods_query_arg( array( 'action_bulk' => 'delete', 'deleted_bulk' => 1 ), array( 'page', 'lang', 'action', 'id' ) ) );
1976
            else
1977
                $this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) );
1978
        }
1979
        else {
1980
            $this->message( sprintf( __( "<strong>Deleted:</strong> %s have been deleted.", 'pods' ), $this->items ) );
1981
1982
            unset( $_GET[ 'deleted_bulk' ] );
1983
        }
1984
1985
        $this->action_bulk = false;
1986
        unset( $_GET[ 'action_bulk' ] );
1987
1988
        $this->do_hook( 'post_delete_bulk' );
1989
1990
        $this->manage();
1991
    }
1992
1993
    /**
1994
     * Callback for exporting Pods data
1995
    */
1996
    public function export_pods( $obj ) {
0 ignored issues
show
Unused Code introduced by
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1997
        if (isset($_REQUEST['export_pod'])) {
1998
            // Hack 1 : Set up type so that export function finds it
1999
            $type = $_REQUEST['export_pod'];
2000
            pods_v_set( $type, 'export_type' );
2001
2002
            // Hack 2: Set up fields so that export function finds it
2003
            $export_fields = empty ( $_POST ['export_fields'] ) ? array () : $_POST ['export_fields'];
2004
            foreach ( $this->pod->fields() as $field ) {
2005
                if (in_array ( $field ['id'], $export_fields )) {
2006
                    $this->fields[ 'export' ][] = $field;
2007
                }
2008
            }
2009
2010
            // Hack 3: Set up where clause so that export function finds it
2011
            $ids = implode ( ",", $_GET ['action_bulk_ids'] );
2012
            $this->where = array(
2013
                'manage' => "id IN ($ids)",
2014
            );
2015
2016
            $this->export();
2017
2018
            // Hack 4: Cleanup since export function calls get_data before returning
2019
            $this->action_bulk = '';
2020
            $this->where = array();
2021
            $this->data = false;
2022
            $this->manage();
2023
        }
2024
        else {
2025
            $this->export_fields_form();
2026
        }
2027
    }
2028
2029
    /**
2030
     * Select the pods fields to be exported
2031
    */
2032
    public function export_fields_form() { ?>
2033
        <div class="wrap pods-admin pods-ui">
2034
            <h2>Choose Export Fields</h2>
2035
                <form method="POST" id="export_form" class="ac-custom ac-checkbox ac-cross">
2036
                <?php foreach ($_GET as $key => $value) {
2037
                    if ( $key== "action_bulk_ids" ) { ?>
2038
                        <input type="hidden" name= "<?php echo $key;?>[]" value="<?php echo implode(",",$value);?>">
2039
                    <?php } else { ?>
2040
                        <input type="hidden" name= "<?php echo $key;?>" value="<?php echo $value?>">
2041
                    <?php } ?>
2042
                <?php } ?>
2043
                <ul>
2044
                     <?php foreach (  $this->pod->fields() as $field_name => $detail ) { ?>
2045
                         <li class="av_one_fourth">
2046
                             <input type="checkbox" name="export_fields[]" id="export_fields_<?php echo $detail[ 'id' ]; ?>" value="<?php echo $detail[ 'id' ]; ?>" />
2047
                             <label for="cb"><?php echo $detail[ 'label' ];?> </label>
2048
                         </li>
2049
                     <?php } ?>
2050
                </ul>
2051
                <input type="submit" id="export_pod_csv" value="csv" name="export_pod" class="button-primary">
2052
                <input type="submit" id="export_pod_tsv" value="tsv" name="export_pod" class="button-primary">
2053
                <input type="submit" id="export_pod_xml" value="xml" name="export_pod" class="button-primary">
2054
            </form>
2055
        </div>
2056
    <?php
2057
    }
2058
2059
    public function export () {
2060
        $export_type = pods_var( 'export_type', 'get', 'csv' );
2061
2062
        $type = 'sv'; // covers csv + tsv
2063
2064
        if ( in_array( $export_type, array( 'xml', 'json' ) ) )
2065
            $type = $export_type;
2066
2067
        $delimiter = ',';
2068
2069
        if ( 'tsv' == $export_type )
2070
            $delimiter = "\t";
2071
2072
        $columns = array();
2073
2074
        if ( empty( $this->fields[ 'export' ] ) ) {
2075
            $this->fields[ 'export' ] = $this->pod->fields;
2076
2077
            $columns = array(
2078
                $this->pod->pod_data[ 'field_id' ] => 'ID'
2079
            );
2080
        }
2081
2082
        foreach ( $this->fields[ 'export' ] as $field ) {
2083
            $columns[ $field[ 'name' ] ] = $field[ 'label' ];
2084
        }
2085
2086
        $params = array(
2087
            'full' => true,
2088
            'flatten' => true,
2089
            'fields' => array_keys( $columns ),
2090
            'type' => $type,
2091
            'delimiter' => $delimiter,
2092
            'columns' => $columns
2093
        );
2094
2095
        $items = $this->get_data( $params );
2096
2097
        $data = array(
2098
            'columns' => $columns,
2099
            'items' => $items,
2100
            'fields' => $this->fields[ 'export' ]
2101
        );
2102
2103
        $migrate = pods_migrate( $type, $delimiter, $data );
2104
2105
        $migrate->export();
2106
2107
        $export_file = $migrate->save();
2108
2109
        $this->message( sprintf( __( '<strong>Success:</strong> Your export is ready, you can download it <a href="%s" target="_blank">here</a>', 'pods' ), $export_file ) );
2110
2111
        //echo '<script type="text/javascript">window.open("' . esc_js( $export_file ) . '");</script>';
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...
2112
2113
        $this->get_data();
2114
    }
2115
2116
    /**
2117
     * @param $field
2118
     *
2119
     * @return array|bool|mixed|null
2120
     */
2121
    public function get_field ( $field ) {
2122
        $value = null;
2123
2124
        // use PodsData to get field
2125
2126
		if ( $callback = $this->callback( 'get_field', $field ) ) {
2127
			return $callback;
2128
		}
2129
2130
        if ( isset( $this->row[ $field ] ) ) {
2131
            $value = $this->row[ $field ];
2132
		}
2133
        elseif ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2134
            if ( 'Pod' == get_class( $this->pod ) )
2135
                $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...
2136
            else
2137
                $value = $this->pod->field( $field );
2138
        }
2139
2140
        return $this->do_hook( 'get_field', $value, $field );
2141
    }
2142
2143
    /**
2144
     * Get find() params based on current UI action
2145
     *
2146
     * @param null|array $params
2147
     * @param null|string $action
2148
     */
2149
    public function get_params( $params = null, $action = null ) {
2150
2151
        if ( null === $action ) {
2152
            $action = $this->action;
2153
        }
2154
2155
        $defaults = array(
2156
            'full' => false,
2157
            'flatten' => true,
2158
            'fields' => null,
2159
            'type' => ''
2160
        );
2161
2162 View Code Duplication
        if ( !empty( $params ) && is_array( $params ) )
2163
            $params = (object) array_merge( $defaults, $params );
2164
        else
2165
            $params = (object) $defaults;
2166
2167
        if ( !in_array( $action, array( 'manage', 'reorder' ) ) )
2168
            $action = 'manage';
2169
2170
        $params_override = false;
2171
2172
        $orderby = array();
2173
2174
        $limit = $this->limit;
2175
2176
        $sql = null;
2177
2178
	    if ( 'reorder' == $this->action ) {
2179
		    if ( ! empty( $this->reorder[ 'orderby' ] ) ) {
2180
			    $orderby[ $this->reorder[ 'orderby' ] ] = $this->reorder[ 'orderby_dir' ];
2181
		    } else {
2182
			    $orderby[ $this->reorder[ 'on' ] ] = $this->reorder[ 'orderby_dir' ];
2183
		    }
2184
2185
		    if ( ! empty( $this->reorder[ 'limit' ] ) ) {
2186
			    $limit = $this->reorder[ 'limit' ];
2187
		    }
2188
2189
		    if ( ! empty( $this->reorder[ 'sql' ] ) ) {
2190
			    $sql = $this->reorder[ 'sql' ];
2191
		    }
2192
	    }
2193
2194
        if ( !empty( $this->orderby ) ) {
2195
            $this->orderby = (array) $this->orderby;
2196
2197
            foreach ( $this->orderby as $order ) {
2198
                if ( false !== strpos( $order, ' ' ) ) {
2199
                    $orderby[] = $order;
2200
                }
2201
                elseif ( !isset( $orderby[ $order ] ) ) {
2202
                    $orderby[ $order ] = $this->orderby_dir;
2203
                }
2204
            }
2205
        }
2206
2207
        if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2208
            $find_params = array(
2209
                'where' => pods_v( $action, $this->where, null, true ),
2210
                'orderby' => $orderby,
2211
                'page' => (int) $this->page,
2212
                'pagination' => true,
2213
                'limit' => (int) $limit,
2214
                'search' => $this->searchable,
2215
                'search_query' => $this->search,
2216
                'search_across' => $this->search_across,
2217
                'search_across_picks' => $this->search_across_picks,
2218
                'filters' => $this->filters,
2219
                'sql' => $sql
2220
            );
2221
2222
            $params_override = true;
2223
        }
2224
        else {
2225
            $find_params = array(
2226
                'table' => $this->sql[ 'table' ],
2227
                'id' => $this->sql[ 'field_id' ],
2228
                'index' => $this->sql[ 'field_index' ],
2229
                'where' => pods_v( $action, $this->where, null, true ),
2230
                'orderby' => $orderby,
2231
                'page' => (int) $this->page,
2232
                'pagination' => true,
2233
                'limit' => (int) $limit,
2234
                'search' => $this->searchable,
2235
                'search_query' => $this->search,
2236
                'fields' => $this->fields[ 'search' ],
2237
                'sql' => $sql
2238
            );
2239
2240
		if ( ! empty( $this->sql['select'] ) ) {
2241
			$find_params['select'] = $this->sql['select'];
2242
		}
2243
        }
2244
2245
        if ( empty( $find_params[ 'where' ] ) && $this->restricted( $this->action ) )
2246
            $find_params[ 'where' ] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
2247
2248
        if ( $params_override ) {
2249
            $find_params = array_merge( $find_params, (array) $this->params );
2250
        }
2251
2252
        if ( $params->full )
2253
            $find_params[ 'limit' ] = -1;
2254
2255
        // Debug purposes
2256 View Code Duplication
        if ( 1 == pods_v( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
2257
            pods_debug( $find_params );
2258
2259
        return $find_params;
2260
    }
2261
2262
    /**
2263
     * @param bool $full Whether to get ALL data or use pagination
0 ignored issues
show
Bug introduced by
There is no parameter named $full. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2264
     *
2265
     * @return bool
2266
     */
2267
    public function get_data ( $params = null ) {
2268
        $action = $this->action;
2269
2270
        $defaults = array(
2271
            'full' => false,
2272
            'flatten' => true,
2273
            'fields' => null,
2274
            'type' => ''
2275
        );
2276
2277 View Code Duplication
        if ( !empty( $params ) && is_array( $params ) )
2278
            $params = (object) array_merge( $defaults, $params );
2279
        else
2280
            $params = (object) $defaults;
2281
2282
        if ( !in_array( $action, array( 'manage', 'reorder' ) ) )
2283
            $action = 'manage';
2284
2285
        $find_params = $this->get_params( $params );
2286
2287
        if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2288
            $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...
2289
2290
            if ( !$params->full ) {
2291
                $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...
2292
2293
                $this->data = $data;
2294
2295
                if ( !empty( $this->data ) ) {
2296
                    $this->data_keys = array_keys( $this->data );
2297
                }
2298
2299
                $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...
2300
                $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...
2301
            }
2302
            else {
2303
                $this->data_full = array();
2304
2305
                $export_params = array(
2306
                    'fields' => $params->fields,
2307
                    'flatten' => true
2308
                );
2309
2310
                if ( in_array( $params->type, array( 'json', 'xml' ) ) )
2311
                    $export_params[ 'flatten' ] = false;
2312
2313
                $export_params = $this->do_hook( 'export_options', $export_params, $params );
2314
2315
                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...
2316
                    $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...
2317
                }
2318
2319
                $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...
2320
2321
                return $this->data_full;
2322
            }
2323
        }
2324
        else {
2325
            if ( !empty( $this->data ) )
2326
                return $this->data;
2327
2328
            if ( empty( $this->sql[ 'table' ] ) )
2329
                return $this->data;
2330
2331
            $this->pods_data->select( $find_params );
2332
2333
            if ( !$params->full ) {
2334
                $this->data = $this->pods_data->data;
2335
2336
                if ( !empty( $this->data ) ) {
2337
					$this->data_keys = array_keys( $this->data );
2338
				}
2339
2340
                $this->total = $this->pods_data->total();
2341
                $this->total_found = $this->pods_data->total_found();
2342
            }
2343
            else {
2344
                $this->data_full = $this->pods_data->data;
2345
2346
                if ( !empty( $this->data_full ) ) {
2347
					$this->data_keys = array_keys( $this->data_full );
2348
				}
2349
2350
                return $this->data_full;
2351
            }
2352
        }
2353
2354
        return $this->data;
2355
    }
2356
2357
    /**
2358
     * Sort out data alphabetically by a key
2359
     */
2360
    public function sort_data () {
2361
        // only do this if we have a default orderby
2362
        if ( isset( $this->orderby[ 'default' ] ) ) {
2363
            $orderby = $this->orderby[ 'default' ];
2364
            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...
2365
                $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...
2366
            }
2367
            if ( $this->orderby_dir == 'ASC' )
2368
                asort( $sorter );
2369
            else
2370
                arsort( $sorter );
2371
            foreach ( $sorter as $key => $val ) {
2372
                $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...
2373
            }
2374
            if ( isset( $intermediary ) ) {
2375
                $this->data = $intermediary;
2376
                $this->data_keys = array_keys( $this->data );
2377
            }
2378
        }
2379
    }
2380
2381
    /**
2382
     * @return array
2383
     */
2384
    public function get_row ( &$counter = 0, $method = null ) {
2385
        if ( !empty( $this->row ) && 0 < (int) $this->id && 'table' != $method )
2386
            return $this->row;
2387
2388
        if ( is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) )
2389
            $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...
2390
        else {
2391
            $this->row = false;
2392
2393
            if ( !empty( $this->data ) ) {
2394
                if ( empty( $this->data_keys ) || count( $this->data ) != count( $this->data_keys ) ) {
2395
                    $this->data_keys = array_keys( $this->data );
2396
				}
2397
2398
                if ( count( $this->data ) == $this->total && isset( $this->data_keys[ $counter ] ) && isset( $this->data[ $this->data_keys[ $counter ] ] ) ) {
2399
                    $this->row = $this->data[ $this->data_keys[ $counter ] ];
2400
2401
                    $counter++;
2402
                }
2403
            }
2404
2405
            if ( false === $this->row && 0 < (int) $this->id && !empty( $this->sql[ 'table' ] ) ) {
2406
                $this->pods_data->select(
2407
                    array(
2408
                        'table' => $this->sql[ 'table' ],
2409
                        'where' => '`' . $this->sql[ 'field_id' ] . '` = ' . (int) $this->id,
2410
                        'limit' => 1
2411
                    )
2412
                );
2413
2414
                $this->row = $this->pods_data->fetch();
2415
            }
2416
        }
2417
2418
        return $this->row;
2419
    }
2420
2421
    /**
2422
     * @param bool $reorder
2423
     *
2424
     * @return mixed|null
2425
     */
2426
    public function manage ( $reorder = false ) {
2427
		if ( false !== $this->callback_action( 'manage', $reorder ) ) {
2428
			return null;
2429
		}
2430
2431
        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 ) ) {
2432
	        if ( empty( $_REQUEST[ '_wpnonce' . $this->num ] ) || false === wp_verify_nonce( $_REQUEST[ '_wpnonce' . $this->num ], 'pods-ui-action-bulk' ) ) {
2433
		        pods_message( __( 'Invalid bulk request, please try again.', 'pods' ) );
2434
	        }
2435
	        elseif ( false !== $this->callback_bulk( $this->action_bulk, $this->bulk ) ) {
2436
				return null;
2437
			}
2438
            elseif ( 'delete' == $this->action_bulk ) {
2439
                return $this->delete_bulk();
2440
			}
2441
        }
2442
2443
        $this->screen_meta();
2444
2445
        if ( true === $reorder )
2446
            wp_enqueue_script( 'jquery-ui-sortable' );
2447
        ?>
2448
    <div class="wrap pods-admin pods-ui">
2449
        <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div>
2450
        <h2>
2451
            <?php
2452
            if ( true === $reorder ) {
2453
                echo $this->header[ 'reorder' ];
2454
2455
				$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
2456
2457
                if ( !empty( $this->action_links[ 'manage' ] ) )
2458
                    $link = $this->action_links[ 'manage' ];
2459
                ?>
2460
                <small>(<a href="<?php echo esc_url( $link ); ?>">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>)</small>
2461
                <?php
2462
            }
2463
            else
2464
                echo $this->header[ 'manage' ];
2465
2466
            if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
2467
                $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num => '' ), self::$allowed, $this->exclusion() );
2468
2469
                if ( !empty( $this->action_links[ 'add' ] ) )
2470
                    $link = $this->action_links[ 'add' ];
2471
                ?>
2472
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->label[ 'add_new' ]; ?></a>
2473
                <?php
2474
            }
2475
            if ( !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) {
2476
                $link = pods_query_arg( array( 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() );
2477
2478
                if ( !empty( $this->action_links[ 'reorder' ] ) )
2479
                    $link = $this->action_links[ 'reorder' ];
2480
                ?>
2481
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->label[ 'reorder' ]; ?></a>
2482
                <?php
2483
            }
2484
            ?>
2485
        </h2>
2486
2487
		<form id="posts-filter" action="" method="get">
2488
        	<?php
2489
                $excluded_filters = array(
2490
                    'search' . $this->num,
2491
                    'pg' . $this->num,
2492
                    'action' . $this->num,
2493
                    'action_bulk' . $this->num,
2494
                    'action_bulk_ids' . $this->num,
2495
	                '_wpnonce' . $this->num
2496
                );
2497
2498
                $filters = $this->filters;
2499
2500
                foreach ( $filters as $k => $filter ) {
2501 View Code Duplication
					if ( isset( $this->pod->fields[ $filter ] ) ) {
2502
						$filter_field = $this->pod->fields[ $filter ];
2503
					}
2504
					elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2505
						$filter_field = $this->fields[ 'manage' ][ $filter ];
2506
					}
2507
					else {
2508
						unset( $filters[ $k ] );
2509
						continue;
2510
					}
2511
2512 View Code Duplication
                    if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2513
                        if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) {
2514
                            unset( $filters[ $k ] );
2515
                            continue;
2516
                        }
2517
                    }
2518
                    elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) {
2519
                        unset( $filters[ $k ] );
2520
                        continue;
2521
                    }
2522
2523
                    $excluded_filters[] = 'filter_' . $filter . '_start';
2524
                    $excluded_filters[] = 'filter_' . $filter . '_end';
2525
                    $excluded_filters[] = 'filter_' . $filter;
2526
                }
2527
2528
                $get = $_GET;
2529
2530 View Code Duplication
                foreach ( $get as $k => $v ) {
2531
                    if ( is_array( $v ) || in_array( $k, $excluded_filters ) || strlen( $v ) < 1 )
2532
                        continue;
2533
			?>
2534
				<input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
2535
			<?php
2536
                }
2537
2538
			if ( false !== $this->callback( 'header', $reorder ) ) {
2539
				return null;
2540
			}
2541
2542
            if ( false === $this->data )
2543
                $this->get_data();
2544
            elseif ( $this->sortable ) // we have the data already as an array
2545
                $this->sort_data();
2546
2547
            if ( !in_array( 'export', $this->actions_disabled ) && 'export' == $this->action )
2548
                $this->export();
2549
2550
            if ( ( !empty( $this->data ) || false !== $this->search || ( $this->filters_enhanced && !empty( $this->views ) ) ) && ( ( $this->filters_enhanced && !empty( $this->views ) ) || false !== $this->searchable ) ) {
2551
                if ( $this->filters_enhanced )
2552
                    $this->filters();
2553
                else {
2554
                ?>
2555
                <p class="search-box" align="right">
2556
                    <?php
2557
                    $excluded_filters = array( 'search' . $this->num, 'pg' . $this->num );
2558
2559
                    foreach ( $this->filters as $filter ) {
2560
                        $excluded_filters[] = 'filter_' . $filter . '_start';
2561
                        $excluded_filters[] = 'filter_' . $filter . '_end';
2562
                        $excluded_filters[] = 'filter_' . $filter;
2563
                    }
2564
2565
                    $this->hidden_vars( $excluded_filters );
2566
2567
                    foreach ( $this->filters as $filter ) {
2568 View Code Duplication
						if ( isset( $this->pod->fields[ $filter ] ) ) {
2569
							$filter_field = $this->pod->fields[ $filter ];
2570
						}
2571
						elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2572
							$filter_field = $this->fields[ 'manage' ][ $filter ];
2573
						}
2574
						else {
2575
							continue;
2576
						}
2577
2578
                        if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2579
                            $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
2580
                            $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
2581
2582
                            // override default value
2583
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2584
                            $filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1;
2585
2586
2587 View Code Duplication
                            if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
2588
                                $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
2589
2590 View Code Duplication
                            if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
2591
                                $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
2592
                    ?>
2593
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
2594
                            <?php echo $filter_field[ 'label' ]; ?>
2595
                        </label>
2596
                        <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
2597
2598
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">
2599
                            to
2600
                        </label>
2601
                    <?php
2602
                            echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field );
2603
                        }
2604
                        elseif ( 'pick' == $filter_field[ 'type' ] ) {
2605
                            $value = pods_var_raw( 'filter_' . $filter, 'get' );
2606
2607
                            if ( strlen( $value ) < 1 )
2608
                                $value = pods_var_raw( 'filter_default', $filter_field );
2609
2610
                            // override default value
2611
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2612
2613
                            $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
2614
                            $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
2615
2616
                            $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 );
2617
                            $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
2618
2619
                            $options = array_merge( $filter_field, $filter_field[ 'options' ] );
2620
                    ?>
2621
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
2622
                            <?php echo $filter_field[ 'label' ]; ?>
2623
                        </label>
2624
                    <?php
2625
                            echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
2626
                        }
2627
                        elseif ( 'boolean' == $filter_field[ 'type' ] ) {
2628
                            $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
2629
2630
                            if ( strlen( $value ) < 1 )
2631
                                $value = pods_var_raw( 'filter_default', $filter_field );
2632
2633
                            // override default value
2634
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2635
2636
                            $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
2637
                            $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
2638
2639
                            $filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple';
2640
                            $filter_field[ 'options' ][ 'pick_custom' ] = array(
2641
                                '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
2642
                                '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
2643
                            );
2644
2645
                            $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 );
2646
                            $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
2647
2648
                            $options = array_merge( $filter_field, $filter_field[ 'options' ] );
2649
                    ?>
2650
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
2651
                            <?php echo $filter_field[ 'label' ]; ?>
2652
                        </label>
2653
                    <?php
2654
                            echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
2655
                        }
2656
                        else {
2657
                            $value = pods_var_raw( 'filter_' . $filter, 'get' );
2658
2659
                            if ( strlen( $value ) < 1 )
2660
                                $value = pods_var_raw( 'filter_default', $filter_field );
2661
2662
                            // override default value
2663
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2664
2665
                            $options = array();
2666
                            $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 );
2667
                            $options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $options, $options[ 'input_helper' ], null, true );
2668
                    ?>
2669
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
2670
                            <?php echo $filter_field[ 'label' ]; ?>
2671
                        </label>
2672
                    <?php
2673
                            echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options );
2674
                        }
2675
                    }
2676
2677
					if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
2678
					?>
2679
						&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>
2680
						<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
2681
					<?php
2682
					}
2683
					else {
2684
						echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
2685
					}
2686
                    ?>
2687
                    <?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?>
2688
                    <?php
2689
                    if ( 0 < strlen( $this->search ) ) {
2690
                        $clear_filters = array(
2691
							'search' . $this->num => false
2692
						);
2693
2694 View Code Duplication
                        foreach ( $this->filters as $filter ) {
2695
                            $clear_filters[ 'filter_' . $filter . '_start' ] = false;
2696
                            $clear_filters[ 'filter_' . $filter . '_end' ] = false;
2697
                            $clear_filters[ 'filter_' . $filter ] = false;
2698
                        }
2699
                        ?>
2700
                        <br class="clear" />
2701
                        <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>
2702
                        <br class="clear" />
2703
                        <?php
2704
                    }
2705
                    ?>
2706
                </p>
2707
                <?php
2708
            }
2709
            }
2710
            else {
2711
                ?>
2712
                <br class="clear" />
2713
                <?php
2714
            }
2715
2716
            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 ) ) {
2717
                ?>
2718
                <div class="tablenav">
2719
                    <?php
2720
                    if ( !empty( $this->data ) && !empty( $this->actions_bulk ) ) {
2721
                ?>
2722
                    <div class="alignleft actions">
2723
	                    <?php wp_nonce_field( 'pods-ui-action-bulk', '_wpnonce' . $this->num, false ); ?>
2724
2725
                        <select name="action_bulk<?php echo esc_attr( $this->num ); ?>">
2726
                            <option value="-1" selected="selected"><?php _e( 'Bulk Actions', 'pods' ); ?></option>
2727
2728
                            <?php
2729
                                foreach ( $this->actions_bulk as $action => $action_data ) {
2730
                                    if ( in_array( $action, $this->actions_hidden ) || in_array( $action, $this->actions_hidden ) )
2731
                                        continue;
2732
2733 View Code Duplication
                                    if ( !isset( $action_data[ 'label' ] ) )
2734
                                        $action_data[ 'label' ] = ucwords( str_replace( '_', ' ', $action ) );
2735
                            ?>
2736
                                <option value="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $action_data[ 'label' ] ); ?></option>
2737
                            <?php
2738
                                }
2739
                            ?>
2740
                        </select>
2741
2742
                        <input type="submit" id="doaction_bulk<?php echo esc_attr( $this->num ); ?>" class="button-secondary action" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
2743
                    </div>
2744
                <?php
2745
                    }
2746
2747 View Code Duplication
                    if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
2748
                        ?>
2749
                        <div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
2750
                            <?php $this->pagination( 1 ); ?>
2751
                        </div>
2752
                        <?php
2753
                    }
2754
2755
                    if ( true === $reorder ) {
2756
						$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
2757
2758
						if ( !empty( $this->action_links[ 'manage' ] ) ) {
2759
							$link = $this->action_links[ 'manage' ];
2760
						}
2761
                        ?>
2762
                        <input type="button" value="<?php esc_attr_e( 'Update Order', 'pods' ); ?>" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" />
2763
                        <input type="button" value="<?php esc_attr_e( 'Cancel', 'pods' ); ?>" class="button" onclick="document.location='<?php echo esc_js( $link ); ?>';" />
2764
                    </form>
2765
				<?php
2766
                    }
2767
                    elseif ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) {
2768
                        ?>
2769
                        <div class="alignleft actions">
2770
                            <strong><?php _e( 'Export', 'pods' ); ?>:</strong>
2771
                            <?php
2772
                            foreach ( $this->export[ 'formats' ] as $format => $separator ) {
2773
                                ?>
2774
                                <input type="button" value=" <?php echo esc_attr( strtoupper( $format ) ); ?> " class="button" onclick="document.location='<?php echo pods_slash( pods_query_arg( array( 'action' . $this->num => 'export', 'export_type' . $this->num => $format, '_wpnonce' => wp_create_nonce( 'pods-ui-action-export' ) ), self::$allowed, $this->exclusion() ) ); ?>';" />
2775
                                <?php
2776
                            }
2777
                            ?>
2778
                        </div>
2779
                        <?php
2780
                    }
2781
                    ?>
2782
                    <br class="clear" />
2783
                </div>
2784
                <?php
2785
            }
2786
            else {
2787
                ?>
2788
                <br class="clear" />
2789
                <?php
2790
            }
2791
            ?>
2792
            <div class="clear"></div>
2793
            <?php
2794
            if ( empty( $this->data ) && false !== $this->default_none && false === $this->search ) {
2795
                ?>
2796
                <p><?php _e( 'Please use the search filter(s) above to display data', 'pods' ); ?><?php if ( $this->export ) { ?>, <?php _e( 'or click on an Export to download a full copy of the data', 'pods' ); ?><?php } ?>.</p>
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...
2797
                <?php
2798
            }
2799
            else
2800
                $this->table( $reorder );
2801 View Code Duplication
            if ( !empty( $this->data ) ) {
2802
                if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
2803
                    ?>
2804
                    <div class="tablenav">
2805
                        <div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
2806
                            <?php $this->pagination( 0 ); ?>
2807
                            <br class="clear" />
2808
                        </div>
2809
                    </div>
2810
                    <?php
2811
                }
2812
            }
2813
2814
            ?>
2815
        </form>
2816
    </div>
2817
    <?php
2818
        if ( $this->filters_enhanced )
2819
            $this->filters_popup();
2820
    }
2821
2822
    public function filters () {
2823
		include_once ABSPATH . 'wp-admin/includes/template.php';
2824
2825
        wp_enqueue_script( 'thickbox' );
2826
        wp_enqueue_style( 'pods-ui-list-table', PODS_URL . 'ui/css/pods-ui-list-table.css', array( 'thickbox' ), PODS_VERSION );
2827
2828
        $filters = $this->filters;
2829
2830
        foreach ( $filters as $k => $filter ) {
2831 View Code Duplication
			if ( isset( $this->pod->fields[ $filter ] ) ) {
2832
				$filter_field = $this->pod->fields[ $filter ];
2833
			}
2834
			elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2835
				$filter_field = $this->fields[ 'manage' ][ $filter ];
2836
			}
2837
			else {
2838
				continue;
2839
			}
2840
2841 View Code Duplication
            if ( isset( $filter_field ) && in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2842
                if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) )
2843
                    unset( $filters[ $k ] );
2844
            }
2845
            elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) )
2846
                unset( $filters[ $k ] );
2847
        }
2848
2849
        $filtered = false;
2850
2851
        if ( !empty( $filters ) )
2852
            $filtered = true;
2853
?>
2854
    <div class="pods-ui-filter-bar">
2855
        <div class="pods-ui-filter-bar-primary">
2856
            <?php
2857
                if ( !empty( $this->views ) ) {
2858
            ?>
2859
                <ul class="subsubsub">
2860
                    <li class="pods-ui-filter-view-label"><strong><?php echo $this->heading[ 'views' ]; ?></strong></li>
2861
2862
                    <?php
2863
                        foreach ( $this->views as $view => $label ) {
2864
                            if ( false === strpos( $label, '<a' ) ) {
2865
                                $link = pods_query_arg( array( 'view' . $this->num => $view, 'pg' . $this->num => '' ), self::$allowed, $this->exclusion() );
2866
2867
                                if ( $this->view == $view )
2868
                                    $label = '<a href="' . esc_url( $link ) . '" class="current">' . $label . '</a>';
2869
                                else
2870
                                    $label = '<a href="' . esc_url( $link ) . '">' . $label . '</a>';
2871
                            }
2872
                    ?>
2873
                        <li class="<?php echo esc_attr( $view ); ?>"><?php echo $label; ?></li>
2874
                    <?php
2875
                        }
2876
                    ?>
2877
                </ul>
2878
            <?php
2879
                }
2880
            ?>
2881
2882
            <?php
2883
                if ( false !== $this->search && false !== $this->searchable ) {
2884
            ?>
2885
                <p class="search-box">
2886
                    <?php
2887
                        if ( $filtered || '' != pods_var_raw( 'search' . $this->num, 'get', '', null, true ) ) {
2888
                            $clear_filters = array(
2889
								'search' . $this->num => false
2890
							);
2891
2892 View Code Duplication
                            foreach ( $this->filters as $filter ) {
2893
                                $clear_filters[ 'filter_' . $filter . '_start' ] = false;
2894
                                $clear_filters[ 'filter_' . $filter . '_end' ] = false;
2895
                                $clear_filters[ 'filter_' . $filter ] = false;
2896
                            }
2897
                    ?>
2898
                        <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() ) ); ?>" class="pods-ui-filter-reset">[<?php _e( 'Reset', 'pods' ); ?>]</a>
2899
                    <?php
2900
                        }
2901
2902
						if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
2903
					?>
2904
						&nbsp;&nbsp; <label class="screen-reader-text" for="page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
2905
						<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
2906
					<?php
2907
						}
2908
						else {
2909
							echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
2910
						}
2911
					?>
2912
2913
                    <?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?>
2914
                </p>
2915
            <?php
2916
                }
2917
            ?>
2918
        </div>
2919
2920
        <?php
2921
            if ( !empty( $this->filters ) ) {
2922
        ?>
2923
            <div class="pods-ui-filter-bar-secondary">
2924
                <ul class="subsubsub">
2925
                    <?php
2926
                        if ( !$filtered ) {
2927
                    ?>
2928
                        <li class="pods-ui-filter-bar-add-filter">
2929
                            <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
2930
                                <?php _e( 'Advanced Filters', 'pods' ); ?>
2931
                            </a>
2932
                        </li>
2933
                    <?php
2934
                        }
2935
                        else {
2936
                    ?>
2937
                        <li class="pods-ui-filter-bar-add-filter">
2938
                            <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
2939
                                + <?php _e( 'Add Filter', 'pods' ); ?>
2940
                            </a>
2941
                        </li>
2942
                    <?php
2943
                        }
2944
2945
                        foreach ( $filters as $filter ) {
2946
                            $value = pods_var_raw( 'filter_' . $filter, 'get' );
2947
2948 View Code Duplication
							if ( isset( $this->pod->fields[ $filter ] ) ) {
2949
								$filter_field = $this->pod->fields[ $filter ];
2950
							}
2951
							elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2952
								$filter_field = $this->fields[ 'manage' ][ $filter ];
2953
							}
2954
							else {
2955
								continue;
2956
							}
2957
2958
                            $data_filter = 'filter_' . $filter;
2959
2960
                            $start = $end = $value_label = '';
2961
2962
                            if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2963
                                $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true );
2964
                                $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true );
2965
2966 View Code Duplication
                                if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
2967
                                    $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
2968
2969 View Code Duplication
                                if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
2970
                                    $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
2971
2972
                                $value = trim( $start . ' - ' . $end, ' -' );
2973
2974
                                $data_filter = 'filter_' . $filter . '_start';
2975
                            }
2976
                            elseif ( 'pick' == $filter_field[ 'type' ] )
2977
                                $value_label = trim( PodsForm::field_method( 'pick', 'value_to_label', $filter, $value, $filter_field, $this->pod->pod_data, null ) );
2978
                            elseif ( 'boolean' == $filter_field[ 'type' ] ) {
2979
                                $yesno_options = array(
2980
                                    '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
2981
                                    '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
2982
                                );
2983
2984
                                if ( isset( $yesno_options[ (string) $value ] ) )
2985
                                    $value_label = $yesno_options[ (string) $value ];
2986
                            }
2987
2988
                            if ( strlen( $value_label ) < 1 )
2989
                                $value_label = $value;
2990
                    ?>
2991
                        <li class="pods-ui-filter-bar-filter" data-filter="<?php echo esc_attr( $data_filter ); ?>">
2992
                            <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
2993
                                <strong><?php echo $filter_field[ 'label' ]; ?>:</strong>
2994
                                <?php echo esc_html( $value_label ); ?>
2995
                            </a>
2996
2997
                            <a href="#remove-filter" class="remove-filter" title="<?php esc_attr_e( 'Remove Filter', 'pods' ); ?>">x</a>
2998
2999
                            <?php
3000
                                if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
3001
                                    echo PodsForm::field( 'filter_' . $filter . '_start', $start, 'hidden' );
3002
                                    echo PodsForm::field( 'filter_' . $filter . '_end', $end, 'hidden' );
3003
                                }
3004
                                else
3005
                                    echo PodsForm::field( $data_filter, $value, 'hidden' );
3006
                            ?>
3007
                        </li>
3008
                    <?php
3009
                        }
3010
                    ?>
3011
                </ul>
3012
            </div>
3013
        <?php
3014
            }
3015
        ?>
3016
    </div>
3017
3018
    <script type="text/javascript">
3019
        jQuery( function() {
3020
            jQuery( '.pods-ui-filter-bar-secondary' ).on( 'click', '.remove-filter', function ( e ) {
3021
                jQuery( '.pods-ui-filter-popup #' + jQuery( this ).parent().data( 'filter' ) ).remove();
3022
3023
                jQuery( this ).parent().find( 'input' ).each( function () {
3024
                    jQuery( this ).remove();
3025
                } );
3026
3027
                jQuery( 'form#posts-filter [name="pg<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3028
                jQuery( 'form#posts-filter [name="action<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3029
                jQuery( 'form#posts-filter [name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3030
	            jQuery( 'form#posts-filter [name="_wpnonce<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3031
3032
                jQuery( 'form#posts-filter' ).submit();
3033
3034
                e.preventDefault();
3035
            } );
3036
        } );
3037
    </script>
3038
<?php
3039
    }
3040
3041
    public function filters_popup () {
3042
        $filters = $this->filters;
3043
?>
3044
    <div id="pods-ui-posts-filter-popup" class="hidden">
3045
        <form action="" method="get" class="pods-ui-posts-filter-popup">
3046
            <h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
3047
3048
            <div class="pods-ui-posts-filters">
3049
                <?php
3050
                    $excluded_filters = array(
3051
                        'search' . $this->num,
3052
                        'pg' . $this->num,
3053
                        'action' . $this->num,
3054
                        'action_bulk' . $this->num,
3055
                        'action_bulk_ids' . $this->num,
3056
                        '_wpnonce' . $this->num
3057
                    );
3058
3059
                    foreach ( $filters as $filter ) {
3060
                        $excluded_filters[] = 'filters_relation';
3061
                        $excluded_filters[] = 'filters_compare_' . $filter;
3062
                        $excluded_filters[] = 'filter_' . $filter . '_start';
3063
                        $excluded_filters[] = 'filter_' . $filter . '_end';
3064
                        $excluded_filters[] = 'filter_' . $filter;
3065
                    }
3066
3067
                    $get = $_GET;
3068
3069 View Code Duplication
                    foreach ( $get as $k => $v ) {
3070
                        if ( in_array( $k, $excluded_filters ) || strlen( $v ) < 1 )
3071
                            continue;
3072
                ?>
3073
                    <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
3074
                <?php
3075
                    }
3076
3077
                    $zebra = true;
3078
3079
                    foreach ( $filters as $filter ) {
3080
                        if ( empty( $filter ) )
3081
                            continue;
3082
3083 View Code Duplication
						if ( isset( $this->pod->fields[ $filter ] ) ) {
3084
							$filter_field = $this->pod->fields[ $filter ];
3085
						}
3086
						elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
3087
							$filter_field = $this->fields[ 'manage' ][ $filter ];
3088
						}
3089
						else {
3090
							continue;
3091
						}
3092
                ?>
3093
                    <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-<?php echo esc_attr( $filter . ( $zebra ? ' clear' : '' ) ); ?>">
3094
                        <?php
3095
                            if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
3096
                                $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
3097
                                $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
3098
3099
                                // override default value
3100
                                $filter_field[ 'options' ][ 'default_value' ] = '';
3101
                                $filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1;
3102
3103 View Code Duplication
                                if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
3104
                                    $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
3105
3106 View Code Duplication
                                if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
3107
                                    $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
3108
                        ?>
3109
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? '' : ' hidden' ); ?>">+</span>
3110
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3111
3112
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
3113
                                <?php echo $filter_field[ 'label' ]; ?>
3114
                            </label>
3115
3116
                            <span class="pods-ui-posts-filter<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>">
3117
                                <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
3118
3119
                                <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">to</label>
3120
                                <?php echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field ); ?>
3121
                            </span>
3122
                        <?php
3123
                            }
3124
                            elseif ( 'pick' == $filter_field[ 'type' ] ) {
3125
                                $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3126
3127
                                if ( strlen( $value ) < 1 )
3128
                                    $value = pods_var_raw( 'filter_default', $filter_field );
3129
3130
                                // override default value
3131
                                $filter_field[ 'options' ][ 'default_value' ] = '';
3132
3133
                                $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
3134
                                $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
3135
3136
                                $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 );
3137
                                $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
3138
3139
                                $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3140
                        ?>
3141
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3142
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3143
3144
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3145
                                <?php echo $filter_field[ 'label' ]; ?>
3146
                            </label>
3147
3148
                            <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
3149
                                <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3150
                            </span>
3151
                        <?php
3152
                            }
3153
                            elseif ( 'boolean' == $filter_field[ 'type' ] ) {
3154
                                $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3155
3156
                                if ( strlen( $value ) < 1 )
3157
                                    $value = pods_var_raw( 'filter_default', $filter_field );
3158
3159
                                // override default value
3160
                                $filter_field[ 'options' ][ 'default_value' ] = '';
3161
3162
                                $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
3163
                                $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
3164
3165
                                $filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple';
3166
                                $filter_field[ 'options' ][ 'pick_custom' ] = array(
3167
                                    '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
3168
                                    '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
3169
                                );
3170
3171
                                $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 );
3172
                                $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
3173
3174
                                $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3175
                        ?>
3176
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3177
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3178
3179
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3180
                                <?php echo $filter_field[ 'label' ]; ?>
3181
                            </label>
3182
3183
                            <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
3184
                                <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3185
                            </span>
3186
                        <?php
3187
                            }
3188
                            else {
3189
                                $value = pods_var_raw( 'filter_' . $filter, 'get' );
3190
3191
                                if ( strlen( $value ) < 1 )
3192
                                    $value = pods_var_raw( 'filter_default', $filter_field );
3193
3194
                                $options = array(
3195
                                    '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 )
3196
                                );
3197
3198
                                if ( empty( $options[ 'input_helper' ] ) && isset( $filter_field[ 'options' ] ) && isset( $filter_field[ 'options' ][ 'input_helper' ] ) )
3199
                                    $options[ 'input_helper' ] = $filter_field[ 'options' ][ 'input_helper' ];
3200
                        ?>
3201
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3202
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3203
3204
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3205
                                <?php echo $filter_field[ 'label' ]; ?>
3206
                            </label>
3207
3208
                            <span class="pods-ui-posts-filter<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>">
3209
                                <?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?>
3210
                            </span>
3211
                        <?php
3212
                            }
3213
                        ?>
3214
                    </p>
3215
                <?php
3216
                        $zebra = empty( $zebra );
3217
                    }
3218
                ?>
3219
3220
                <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-search<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>">
3221
                    <label for="pods-form-ui-search<?php echo esc_attr( $this->num ); ?>"><?php _e( 'Search Text', 'pods' ); ?></label>
3222
                    <?php echo PodsForm::field( 'search' . $this->num, pods_var_raw( 'search' . $this->num, 'get' ), 'text' ); ?>
3223
                </p>
3224
3225
                <?php $zebra = empty( $zebra ); ?>
3226
            </div>
3227
3228
            <p class="submit<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>"><input type="submit" value="<?php echo esc_attr( $this->header[ 'search' ] ); ?>" class="button button-primary" /></p>
3229
        </form>
3230
    </div>
3231
3232
    <script type="text/javascript">
3233
        jQuery( function () {
3234
            jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) {
3235
                jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
3236
3237
                jQuery( this ).hide();
3238
                jQuery( this ).parent().find( '.toggle-off' ).show();
3239
            } );
3240
3241
            jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) {
3242
                jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
3243
                jQuery( this ).parent().find( 'select, input' ).val( '' );
3244
3245
                jQuery( this ).hide();
3246
                jQuery( this ).parent().find( '.toggle-on' ).show();
3247
            } );
3248
3249
            jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) {
3250
                if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'hidden' ) ) {
3251
                    jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
3252
3253
                    jQuery( this ).parent().find( '.toggle-on' ).hide();
3254
                    jQuery( this ).parent().find( '.toggle-off' ).show();
3255
                }
3256
                else {
3257
                    jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
3258
                    jQuery( this ).parent().find( 'select, input' ).val( '' );
3259
3260
                    jQuery( this ).parent().find( '.toggle-on' ).show();
3261
                    jQuery( this ).parent().find( '.toggle-off' ).hide();
3262
                }
3263
            } );
3264
        } );
3265
    </script>
3266
<?php
3267
    }
3268
3269
    /**
3270
     * @param bool $reorder
3271
     *
3272
     * @return bool|mixed
3273
     */
3274
    public function table ( $reorder = false ) {
3275
		if ( false !== $this->callback( 'table', $reorder ) ) {
3276
			return null;
3277
		}
3278
3279
        if ( empty( $this->data ) ) {
3280
            ?>
3281
        <p><?php echo sprintf( __( 'No %s found', 'pods' ), $this->items ); ?></p>
3282
        <?php
3283
            return false;
3284
        }
3285
        if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
3286
            ?>
3287
        <style type="text/css">
3288
            table.widefat.fixed tbody.reorderable tr {
3289
                height: 50px;
3290
            }
3291
3292
            .dragme {
3293
                background: url(<?php echo esc_url( PODS_URL ); ?>/ui/images/handle.gif) no-repeat;
3294
                background-position: 8px 8px;
3295
                cursor: pointer;
3296
            }
3297
3298
            .dragme strong {
3299
                margin-left: 30px;
3300
            }
3301
        </style>
3302
<form action="<?php echo esc_url( pods_query_arg( array( 'action' . $this->num => 'reorder', 'do' . $this->num => 'save', 'page' => pods_var_raw( 'page' ) ), self::$allowed, $this->exclusion() ) ); ?>" method="post" class="admin_ui_reorder_form">
3303
<?php
3304
        }
3305
        $table_fields = $this->fields[ 'manage' ];
3306 View Code Duplication
        if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] )
3307
            $table_fields = $this->fields[ 'reorder' ];
3308
        if ( false === $table_fields || empty( $table_fields ) )
3309
            return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods' ) );
3310
        ?>
3311
        <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...
3312
            <thead>
3313
                <tr>
3314
                    <?php
3315
                        if ( !empty( $this->actions_bulk ) ) {
3316
            ?>
3317
                            <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th>
3318
            <?php
3319
                        }
3320
3321
                    $name_field = false;
3322
                    $fields = array();
3323
                    if ( !empty( $table_fields ) ) {
3324
                        foreach ( $table_fields as $field => $attributes ) {
3325
                            if ( false === $attributes[ 'display' ] )
3326
                                continue;
3327
                            if ( false === $name_field )
3328
                                $id = 'title';
3329
                            else
3330
                                $id = '';
3331
                            if ( 'other' == $attributes[ 'type' ] )
3332
                                $id = '';
3333
                            if ( in_array( $attributes[ 'type' ], array( 'date', 'datetime', 'time' ) ) )
3334
                                $id = 'date';
3335
                            if ( false === $name_field && 'title' == $id )
3336
                                $name_field = true;
3337
                            $fields[ $field ] = $attributes;
3338
                            $fields[ $field ][ 'field_id' ] = $id;
3339
                            $dir = 'DESC';
3340
                            $current_sort = ' asc';
3341
                            if ( isset( $this->orderby[ 'default' ] ) && $field == $this->orderby[ 'default' ] ) {
3342
                                if ( 'DESC' == $this->orderby_dir ) {
3343
                                    $dir = 'ASC';
3344
                                    $current_sort = ' desc';
3345
                                }
3346
                            }
3347
3348
                            $att_id = '';
3349
                            if ( !empty( $id ) )
3350
                                $att_id = ' id="' . esc_attr( $id ) . '"';
3351
3352
                            $width = '';
3353
3354 View Code Duplication
                            if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) )
3355
                                $width = ' style="width: ' . esc_attr( $attributes[ 'width' ] ) . '"';
3356
3357
                            if ( $fields[ $field ][ 'sortable' ] ) {
3358
                                ?>
3359
                                <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr( $id ); ?> sortable<?php echo esc_attr( $current_sort ); ?>"<?php echo $width; ?>>
3360
                                    <a href="<?php echo esc_url_raw( pods_query_arg( array( 'orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir ), array( 'limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page' ), $this->exclusion() ) ); ?>"> <span><?php echo $attributes[ 'label' ]; ?></span> <span class="sorting-indicator"></span> </a>
3361
                                </th>
3362
                                <?php
3363
                            }
3364
                            else {
3365
                                ?>
3366
                                <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr( $id ); ?>"<?php echo $width; ?>><?php echo $attributes[ 'label' ]; ?></th>
3367
                                <?php
3368
                            }
3369
                        }
3370
                    }
3371
                    ?>
3372
                </tr>
3373
            </thead>
3374
            <?php
3375
            if ( 6 < $this->total_found ) {
3376
                ?>
3377
                <tfoot>
3378
                    <tr>
3379
                        <?php
3380
                            if ( !empty( $this->actions_bulk ) ) {
3381
            ?>
3382
                                <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th>
3383
            <?php
3384
                            }
3385
3386
                        if ( !empty( $fields ) ) {
3387
                            foreach ( $fields as $field => $attributes ) {
3388
                                $dir = 'ASC';
3389
                                if ( $field == $this->orderby ) {
3390
                                    $current_sort = 'desc';
3391
                                    if ( 'ASC' == $this->orderby_dir ) {
3392
                                        $dir = 'DESC';
3393
                                        $current_sort = 'asc';
3394
                                    }
3395
                                }
3396
3397
                                $width = '';
3398
3399 View Code Duplication
                                if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) )
3400
                                    $width = ' style="width: ' . esc_attr( $attributes[ 'width' ] ) . '"';
3401
3402
                                if ( $fields[ $field ][ 'sortable' ] ) {
3403
                                    ?>
3404
                                    <th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?> sortable <?php echo esc_attr( $current_sort ); ?>"<?php echo $width; ?>><a href="<?php echo esc_url_raw( pods_query_arg( array( 'orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir ), array( 'limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page' ), $this->exclusion() ) ); ?>"><span><?php echo $attributes[ 'label' ]; ?></span><span class="sorting-indicator"></span></a></th>
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...
3405
                                    <?php
3406
                                }
3407
                                else {
3408
                                    ?>
3409
                                    <th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?>"<?php echo $width; ?>><?php echo $attributes[ 'label' ]; ?></th>
3410
                                    <?php
3411
                                }
3412
                            }
3413
                        }
3414
                        ?>
3415
                    </tr>
3416
                </tfoot>
3417
                <?php
3418
            }
3419
            ?>
3420
            <tbody id="the-list"<?php echo ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) ? ' class="reorderable"' : ''; ?>>
3421
                <?php
3422
                if ( !empty( $this->data ) && is_array( $this->data ) ) {
3423
                    $counter = 0;
3424
3425
                    while ( $row = $this->get_row( $counter, 'table' ) ) {
3426
                        if ( is_object( $row ) )
3427
                            $row = get_object_vars( (object) $row );
3428
3429
                        $toggle_class = '';
3430
3431
                        if ( is_array( $this->actions_custom ) && isset( $this->actions_custom[ 'toggle' ] ) ) {
3432
                            $toggle_class = ' pods-toggled-on';
3433
3434
                            if ( !isset( $row[ 'toggle' ] ) || empty( $row[ 'toggle' ] ) )
3435
                                $toggle_class = ' pods-toggled-off';
3436
                        }
3437
                        ?>
3438
                        <tr id="item-<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" class="iedit<?php echo esc_attr( $toggle_class ); ?>">
3439
                            <?php
3440
                                if ( !empty( $this->actions_bulk ) ) {
3441
            ?>
3442
                                <th scope="row" class="check-column"><input type="checkbox" name="action_bulk_ids<?php echo esc_attr( $this->num ); ?>[]" value="<?php echo esc_attr( $row[$this->sql['field_id']] ); ?>"></th>
3443
            <?php
3444
                                }
3445
3446
                            foreach ( $fields as $field => $attributes ) {
3447
                                if ( false === $attributes[ 'display' ] )
3448
                                    continue;
3449
3450
                                if ( !isset( $row[ $field ] ) ) {
3451
                                    $row[ $field ] = $this->get_field( $field );
3452
								}
3453
3454
								$row_value = $row[ $field ];
3455
3456
                                if ( !empty( $attributes[ 'custom_display' ] ) ) {
3457
                                    if ( is_callable( $attributes[ 'custom_display' ] ) )
3458
                                        $row_value = call_user_func_array( $attributes[ 'custom_display' ], array( $row, &$this, $row_value, $field, $attributes ) );
3459
                                    elseif ( is_object( $this->pod ) && class_exists( 'Pods_Helpers' ) )
3460
                                        $row_value = $this->pod->helper( $attributes[ 'custom_display' ], $row_value, $field );
3461
                                }
3462
                                else {
3463
                                    ob_start();
3464
3465
                                    $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 );
3466
3467
                                    $field_output = trim( (string) ob_get_clean() );
3468
3469
                                    if ( false === $field_value )
3470
                                        $row_value = '';
3471
                                    elseif ( 0 < strlen( trim( (string) $field_value ) ) )
3472
                                        $row_value = trim( (string) $field_value );
3473
                                    elseif ( 0 < strlen( $field_output ) )
3474
                                        $row_value = $field_output;
3475
                                }
3476
3477
                                if ( false !== $attributes[ 'custom_relate' ] ) {
3478
                                    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...
3479
                                    $table = $attributes[ 'custom_relate' ];
3480
                                    $on = $this->sql[ 'field_id' ];
3481
                                    $is = $row[ $this->sql[ 'field_id' ] ];
3482
                                    $what = array( 'name' );
3483
                                    if ( is_array( $table ) ) {
3484
                                        if ( isset( $table[ 'on' ] ) )
3485
                                            $on = pods_sanitize( $table[ 'on' ] );
3486
                                        if ( isset( $table[ 'is' ] ) && isset( $row[ $table[ 'is' ] ] ) )
3487
                                            $is = pods_sanitize( $row[ $table[ 'is' ] ] );
3488
                                        if ( isset( $table[ 'what' ] ) ) {
3489
                                            $what = array();
3490
                                            if ( is_array( $table[ 'what' ] ) ) {
3491
                                                foreach ( $table[ 'what' ] as $wha ) {
3492
                                                    $what[] = pods_sanitize( $wha );
3493
                                                }
3494
                                            }
3495
                                            else
3496
                                                $what[] = pods_sanitize( $table[ 'what' ] );
3497
                                        }
3498
                                        if ( isset( $table[ 'table' ] ) )
3499
                                            $table = $table[ 'table' ];
3500
                                    }
3501
                                    $table = pods_sanitize( $table );
3502
                                    $wha = implode( ',', $what );
3503
                                    $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'";
3504
                                    $value = @current( $wpdb->get_results( $sql, ARRAY_A ) );
3505
                                    if ( !empty( $value ) ) {
3506
                                        $val = array();
3507
                                        foreach ( $what as $wha ) {
3508
                                            if ( isset( $value[ $wha ] ) )
3509
                                                $val[] = $value[ $wha ];
3510
                                        }
3511
                                        if ( !empty( $val ) )
3512
                                            $row_value = implode( ' ', $val );
3513
                                    }
3514
                                }
3515
3516
								$css_classes = ' pods-ui-col-field-' . sanitize_title( $field );
3517
3518
								if ( $attributes[ 'css_values' ] ) {
3519
									$css_field_value = $row[ $field ];
3520
3521
									if ( is_object( $css_field_value ) ) {
3522
										$css_field_value = get_object_vars( $css_field_value );
3523
									}
3524
3525
									if ( is_array( $css_field_value ) ) {
3526
										foreach ( $css_field_value as $css_field_val ) {
3527
											if ( is_object( $css_field_val ) ) {
3528
												$css_field_val = get_object_vars( $css_field_val );
3529
											}
3530
3531
											if ( is_array( $css_field_val ) ) {
3532
												foreach ( $css_field_val as $css_field_v ) {
3533
													if ( is_object( $css_field_v ) ) {
3534
														$css_field_v = get_object_vars( $css_field_v );
3535
													}
3536
3537
													$css_classes .= ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_v ) ) );
3538
												}
3539
											}
3540 View Code Duplication
											else {
3541
												$css_classes .= ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_val ) ) );
3542
											}
3543
										}
3544
									}
3545 View Code Duplication
									else {
3546
										$css_classes .= ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_value ) ) );
3547
									}
3548
								}
3549
3550
                                if ( is_object( $this->pod ) )
3551
                                    $row_value = $this->do_hook( $this->pod->pod . '_field_value', $row_value, $field, $attributes, $row );
3552
3553
                                $row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row );
3554
3555
                                if ( 'title' == $attributes[ 'field_id' ] ) {
3556
									$default_action = $this->do_hook( 'default_action', 'edit', $row );
3557
3558
                                    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 ) {
3559
                                        $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3560
3561
                                        if ( !empty( $this->action_links[ 'edit' ] ) )
3562
                                            $link = $this->do_template( $this->action_links[ 'edit' ], $row );
3563
                                        ?>
3564
                <td class="post-title page-title column-title<?php echo esc_attr( $css_classes ); ?>"><strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'Edit this item', 'pods' ); ?>"><?php echo $row_value; ?></a></strong>
3565
                                        <?php
3566
                                    }
3567
                                    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 ) {
3568
                                        $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3569
3570
                                        if ( !empty( $this->action_links[ 'view' ] ) )
3571
                                            $link = $this->do_template( $this->action_links[ 'view' ], $row );
3572
                                        ?>
3573
                <td class="post-title page-title column-title<?php echo esc_attr( $css_classes ); ?>"><strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'View this item', 'pods' ); ?>"><?php echo $row_value; ?></a></strong>
3574
                                        <?php
3575
                                    }
3576
                                    else {
3577
                                        ?>
3578
                <td class="post-title page-title column-title<?php echo esc_attr( $css_classes ); ?><?php echo esc_attr( ( 1 == $reorder && $this->reorder ) ? ' dragme' : '' ); ?>"><strong><?php echo $row_value; ?></strong>
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...
3579
                                        <?php
3580
                                    }
3581
3582
                                    if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) {
3583
                                        $toggle = false;
3584
                                        $actions = array();
3585
3586 View Code Duplication
                                        if ( !in_array( 'view', $this->actions_disabled ) && !in_array( 'view', $this->actions_hidden ) ) {
3587
                                            $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3588
3589
                                            if ( !empty( $this->action_links[ 'view' ] ) )
3590
                                                $link = $this->do_template( $this->action_links[ 'view' ], $row );
3591
3592
                                            $actions[ 'view' ] = '<span class="view"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>';
3593
                                        }
3594
3595 View Code Duplication
                                        if ( !in_array( 'edit', $this->actions_disabled ) && !in_array( 'edit', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3596
                                            $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3597
3598
                                            if ( !empty( $this->action_links[ 'edit' ] ) )
3599
                                                $link = $this->do_template( $this->action_links[ 'edit' ], $row );
3600
3601
                                            $actions[ 'edit' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>';
3602
                                        }
3603
3604 View Code Duplication
                                        if ( !in_array( 'duplicate', $this->actions_disabled ) && !in_array( 'duplicate', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3605
                                            $link = pods_query_arg( array( 'action' . $this->num => 'duplicate', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3606
3607
                                            if ( !empty( $this->action_links[ 'duplicate' ] ) )
3608
                                                $link = $this->do_template( $this->action_links[ 'duplicate' ], $row );
3609
3610
                                            $actions[ 'duplicate' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>';
3611
                                        }
3612
3613
                                        if ( !in_array( 'delete', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) && !$this->restricted( 'delete', $row ) ) {
3614
                                            $link = pods_query_arg( array( 'action' . $this->num => 'delete', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ], '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), self::$allowed, $this->exclusion() );
3615
3616
                                            if ( !empty( $this->action_links[ 'delete' ] ) ) {
3617
	                                            $link = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), $this->do_template( $this->action_links[ 'delete' ], $row ) );
3618
                                            }
3619
3620
                                            $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>';
3621
                                        }
3622
3623
                                        if ( is_array( $this->actions_custom ) ) {
3624
                                            foreach ( $this->actions_custom as $custom_action => $custom_data ) {
3625
												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 ) ) {
3626
                                                    if ( !in_array( $custom_action, array( 'add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table' ) ) ) {
3627
                                                        if ( 'toggle' == $custom_action ) {
3628
                                                            $toggle = true;
3629
                                                            $toggle_labels = array(
3630
                                                                __( 'Enable', 'pods' ),
3631
                                                                __( 'Disable', 'pods' )
3632
                                                            );
3633
3634
                                                            $custom_data[ 'label' ] = ( $row[ 'toggle' ] ? $toggle_labels[ 1 ] : $toggle_labels[ 0 ] );
3635
                                                        }
3636
3637
                                                        if ( !isset( $custom_data[ 'label' ] ) )
3638
                                                            $custom_data[ 'label' ] = ucwords( str_replace( '_', ' ', $custom_action ) );
3639
3640
                                                        if ( !isset( $custom_data[ 'link' ] ) ) {
3641
                                                            $vars = array(
3642
                                                                'action' => $custom_action,
3643
                                                                'id' => $row[ $this->sql[ 'field_id' ] ],
3644
                                                                '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action )
3645
                                                            );
3646
3647
                                                            if ( 'toggle' == $custom_action ) {
3648
                                                                $vars[ 'toggle' ] = (int) ( !$row[ 'toggle' ] );
3649
                                                                $vars[ 'toggled' ] = 1;
3650
                                                            }
3651
3652
                                                            $custom_data[ 'link' ] = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
3653
3654
                                                            if ( isset( $this->action_links[ $custom_action ] ) && !empty( $this->action_links[ $custom_action ] ) ) {
3655
	                                                            $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 ) );
3656
                                                            }
3657
                                                        }
3658
3659
                                                        $confirm = '';
3660
3661
                                                        if ( isset( $custom_data[ 'confirm' ] ) )
3662
                                                            $confirm = ' onclick="if(confirm(\'' . esc_js( $custom_data[ 'confirm' ] ) . '\')){return true;}return false;"';
3663
3664
                                                        if ( $this->restricted( $custom_action, $row ) ) {
3665
                                                            continue;
3666
														}
3667
3668
                                                        $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>';
3669
                                                    }
3670
                                                }
3671
                                            }
3672
                                        }
3673
3674
                                        $actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql[ 'field_id' ] ] );
3675
3676
                                        if ( !empty( $actions ) ) {
3677
                                            ?>
3678
                                            <div class="row-actions<?php echo esc_attr( $toggle ? ' row-actions-toggle' : '' ); ?>">
3679
                                                <?php
3680
													$this->callback( 'actions_start', $row, $actions );
3681
3682
													echo implode( ' | ', $actions );
3683
3684
													$this->callback( 'actions_end', $row, $actions );
3685
                                                ?>
3686
                                            </div>
3687
                                            <?php
3688
                                        }
3689
                                    }
3690
                                    else {
3691
                                        ?>
3692
                                        <input type="hidden" name="order[]" value="<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" />
3693
                                        <?php
3694
                                    }
3695
                                    ?>
3696
                </td>
3697
<?php
3698
                                }
3699
                                elseif ( 'date' == $attributes[ 'type' ] ) {
3700
                                    ?>
3701
                                    <td class="date column-date<?php echo esc_attr( $css_classes ); ?>"><abbr title="<?php echo esc_attr( $row_value ); ?>"><?php echo $row_value; ?></abbr></td>
3702
                                    <?php
3703
                                }
3704
                                else {
3705
                                    ?>
3706
                                    <td class="author<?php echo esc_attr( $css_classes ); ?>"><span><?php echo $row_value; ?></span></td>
3707
                                    <?php
3708
                                }
3709
                            }
3710
                            ?>
3711
                        </tr>
3712
                        <?php
3713
                    }
3714
                }
3715
                ?>
3716
            </tbody>
3717
        </table>
3718
        <?php
3719 View Code Duplication
        if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
3720
            ?>
3721
</form>
3722
<?php
3723
        }
3724
        ?>
3725
    <script type="text/javascript">
3726
        jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
3727
            <?php
3728 View Code Duplication
            if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
3729
                ?>
3730
            jQuery( document ).ready( function () {
3731
                jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} );
3732
                jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) {
3733
                    jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' );
3734
                    jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
3735
                } );
3736
            } );
3737
                <?php
3738
            }
3739
            ?>
3740
    </script>
3741
    <?php
3742
    }
3743
3744
    /**
3745
     *
3746
     */
3747
    public function screen_meta () {
3748
        $screen_html = $help_html = '';
3749
        $screen_link = $help_link = '';
3750
        if ( !empty( $this->screen_options ) && !empty( $this->help ) ) {
3751 View Code Duplication
            foreach ( $this->ui_page as $page ) {
3752
                if ( isset( $this->screen_options[ $page ] ) ) {
3753
                    if ( is_array( $this->screen_options[ $page ] ) ) {
3754
                        if ( isset( $this->screen_options[ $page ][ 'link' ] ) ) {
3755
                            $screen_link = $this->screen_options[ $page ][ 'link' ];
3756
                            break;
3757
                        }
3758
                    }
3759
                    else {
3760
                        $screen_html = $this->screen_options[ $page ];
3761
                        break;
3762
                    }
3763
                }
3764
            }
3765 View Code Duplication
            foreach ( $this->ui_page as $page ) {
3766
                if ( isset( $this->help[ $page ] ) ) {
3767
                    if ( is_array( $this->help[ $page ] ) ) {
3768
                        if ( isset( $this->help[ $page ][ 'link' ] ) ) {
3769
                            $help_link = $this->help[ $page ][ 'link' ];
3770
                            break;
3771
                        }
3772
                    }
3773
                    else {
3774
                        $help_html = $this->help[ $page ];
3775
                        break;
3776
                    }
3777
                }
3778
            }
3779
        }
3780
        $screen_html = $this->do_hook( 'screen_meta_screen_html', $screen_html );
3781
        $screen_link = $this->do_hook( 'screen_meta_screen_link', $screen_link );
3782
        $help_html = $this->do_hook( 'screen_meta_help_html', $help_html );
3783
        $help_link = $this->do_hook( 'screen_meta_help_link', $help_link );
3784
        if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) || 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
3785
            ?>
3786
        <div id="screen-meta">
3787
            <?php
3788
            $this->do_hook( 'screen_meta_pre' );
3789
            if ( 0 < strlen( $screen_html ) ) {
3790
                ?>
3791
                <div id="screen-options-wrap" class="hidden">
3792
                    <form id="adv-settings" action="" method="post">
3793
                        <?php
3794
                        echo $screen_html;
3795
                        $fields = array();
3796
                        foreach ( $this->ui_page as $page ) {
3797 View Code Duplication
                            if ( isset( $this->fields[ $page ] ) && !empty( $this->fields[ $page ] ) )
3798
                                $fields = $this->fields[ $page ];
3799
                        }
3800
                        if ( !empty( $fields ) || true === $this->pagination ) {
3801
                            ?>
3802
                            <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
3803
                            <?php
3804
                            if ( !empty( $fields ) ) {
3805
                                ?>
3806
                                <div class="metabox-prefs">
3807
                                    <?php
3808
                                    $this->do_hook( 'screen_meta_screen_options' );
3809
                                    foreach ( $fields as $field => $attributes ) {
3810
                                        if ( false === $attributes[ 'display' ] || true === $attributes[ 'hidden' ] )
3811
                                            continue;
3812
                                        ?>
3813
                                        <label for="<?php echo esc_attr( $field ); ?>-hide">
3814
                                            <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 $attributes[ 'label' ]; ?></label>
3815
                                        <?php
3816
                                    }
3817
                                    ?>
3818
                                    <br class="clear">
3819
                                </div>
3820
                                <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
3821
                                <?php
3822
                            }
3823
                            ?>
3824
                            <div class="screen-options">
3825
                                <?php
3826
                                if ( true === $this->pagination ) {
3827
                                    ?>
3828
                                    <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"> <label for="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page"><?php echo $this->items; ?> per page</label>
3829
                                    <?php
3830
                                }
3831
                                $this->do_hook( 'screen_meta_screen_submit' );
3832
                                ?>
3833
                                <input type="submit" name="screen-options-apply" id="screen-options-apply" class="button" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
3834
                                <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page">
3835
                                <?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?>
3836
                            </div>
3837
                            <?php
3838
                        }
3839
                        ?>
3840
                    </form>
3841
                </div>
3842
                <?php
3843
            }
3844
            if ( 0 < strlen( $help_html ) ) {
3845
                ?>
3846
                <div id="contextual-help-wrap" class="hidden">
3847
                    <div class="metabox-prefs">
3848
                        <?php echo $help_html; ?>
3849
                    </div>
3850
                </div>
3851
                <?php
3852
            }
3853
            ?>
3854
            <div id="screen-meta-links">
3855
                <?php
3856
                $this->do_hook( 'screen_meta_links_pre' );
3857
                if ( 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
3858
                    ?>
3859
                    <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
3860
                        <?php
3861
                        if ( 0 < strlen( $help_link ) ) {
3862
                            ?>
3863
                            <a href="<?php echo esc_url( $help_link ); ?>" class="show-settings">Help</a>
3864
                            <?php
3865
                        }
3866
                        else {
3867
                            ?>
3868
                            <a href="#contextual-help" id="contextual-help-link" class="show-settings">Help</a>
3869
                            <?php
3870
                        }
3871
                        ?>
3872
                    </div>
3873
                    <?php
3874
                }
3875
                if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) ) {
3876
                    ?>
3877
                    <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
3878
                        <?php
3879
                        if ( 0 < strlen( $screen_link ) ) {
3880
                            ?>
3881
                            <a href="<?php echo esc_url( $screen_link ); ?>" class="show-settings">Screen Options</a>
3882
                            <?php
3883
                        }
3884
                        else {
3885
                            ?>
3886
                            <a href="#screen-options" id="show-settings-link" class="show-settings">Screen Options</a>
3887
                            <?php
3888
                        }
3889
                        ?>
3890
                    </div>
3891
                    <?php
3892
                }
3893
                $this->do_hook( 'screen_meta_links_post' );
3894
                ?>
3895
            </div>
3896
            <?php
3897
            $this->do_hook( 'screen_meta_post' );
3898
            ?>
3899
        </div>
3900
        <?php
3901
        }
3902
    }
3903
3904
    /**
3905
     * @param bool $header
3906
     *
3907
     * @return mixed
3908
     */
3909
    public function pagination ( $header = false ) {
3910
		if ( false !== $this->callback( 'pagination', $header ) ) {
3911
			return null;
3912
		}
3913
3914
        $total_pages = ceil( $this->total_found / $this->limit );
3915
        $request_uri = pods_query_arg( array( 'pg' . $this->num => '' ), array( 'limit' . $this->num, 'orderby' . $this->num, 'orderby_dir' . $this->num, 'search' . $this->num, 'filter_*', 'view' . $this->num, 'page' . $this->num ), $this->exclusion() );
3916
3917
        $append = false;
3918
3919
        if ( false !== strpos( $request_uri, '?' ) )
3920
            $append = true;
3921
3922
        if ( false !== $this->pagination_total && ( $header || 1 != $this->total_found ) ) {
3923
            $singular_label = strtolower( $this->item );
3924
            $plural_label = strtolower( $this->items );
3925
            ?>
3926
        <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>
3927
        <?php
3928
        }
3929
3930
        if ( false !== $this->pagination ) {
3931
            if ( 1 < $total_pages ) {
3932
                ?>
3933
            <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>
3934
            <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>
3935
            <?php
3936
                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...
3937
                    ?>
3938
                <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( $this->page ); ?>" size="<?php echo esc_attr( strlen( $total_pages ) ); ?>"> <?php _e( 'of', 'pods' ); ?> <span class="total-pages"><?php echo $total_pages; ?></span></span>
3939
                <script>
3940
3941
                    jQuery( document ).ready( function ( $ ) {
3942
                        var pageInput = $( 'input.current-page' );
3943
                        var currentPage = pageInput.val();
3944
                        pageInput.closest( 'form' ).submit( function ( e ) {
3945
                            if (
3946
	                            ( 1 > $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).length
3947
	                              || $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 )
3948
	                            && ( 1 > $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).length
3949
	                                 || $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 )
3950
	                            && pageInput.val() == currentPage ) {
3951
                                pageInput.val( '1' );
3952
                            }
3953
                        } );
3954
                    } );
3955
                </script>
3956
                <?php
3957
                }
3958
                else {
3959
                    ?>
3960
                <span class="paging-input"><?php echo $this->page; ?> <?php _e( 'of', 'pods' ); ?> <span class="total-pages"><?php echo number_format_i18n( $total_pages ); ?></span></span>
3961
                <?php
3962
                }
3963
                ?>
3964
            <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>
3965
            <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>
3966
            <?php
3967
            }
3968
        }
3969
    }
3970
3971
    /**
3972
     * @param bool $options
3973
     *
3974
     * @return mixed
3975
     */
3976
    public function limit ( $options = false ) {
3977
		if ( false !== $this->callback( 'limit', $options ) ) {
3978
			return null;
3979
		}
3980
3981
        if ( false === $options || !is_array( $options ) || empty( $options ) )
3982
            $options = array( 10, 25, 50, 100, 200 );
3983
3984
        if ( !in_array( $this->limit, $options ) && -1 != $this->limit )
3985
            $this->limit = $options[ 1 ];
3986
3987
        foreach ( $options as $option ) {
3988
            if ( $option == $this->limit )
3989
                echo ' <span class="page-numbers current">' . esc_html( $option ) . '</span>';
3990
            else
3991
                echo ' <a href="' . esc_url( pods_query_arg( array( 'limit' => $option ), array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'search' . $this->num, 'filter_*', 'page' . $this->num ), $this->exclusion() ) ) . '">' . esc_html( $option ) . '</a>';
3992
        }
3993
    }
3994
3995
    /**
3996
     * @param $code
3997
     * @param bool|array $row
3998
     *
3999
     * @return mixed
4000
     */
4001
    public function do_template ( $code, $row = false ) {
4002
        if ( is_object( $this->pod ) && 1 == 0 && 0 < $this->pod->id() )
4003
            return $this->pod->do_magic_tags( $code );
4004
        else {
4005
            if ( false !== $row ) {
4006
                $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...
4007
                $this->row = $row;
4008
            }
4009
4010
            $code = preg_replace_callback( "/({@(.*?)})/m", array( $this, "do_magic_tags" ), $code );
4011
4012
            if ( false !== $row ) {
4013
                $this->row = $this->temp_row;
4014
                unset( $this->temp_row );
4015
            }
4016
        }
4017
4018
        return $code;
4019
    }
4020
4021
    /**
4022
     * @param $tag
4023
     *
4024
     * @return string
4025
     */
4026
    public function do_magic_tags ( $tag ) {
4027 View Code Duplication
        if ( is_array( $tag ) ) {
4028
            if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 )
4029
                return '';
4030
4031
            $tag = $tag[ 2 ];
4032
        }
4033
4034
        $tag = trim( $tag, ' {@}' );
4035
        $tag = explode( ',', $tag );
4036
4037 View Code Duplication
        if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 )
4038
            return null;
4039
4040
        foreach ( $tag as $k => $v ) {
4041
            $tag[ $k ] = trim( $v );
4042
        }
4043
4044
        $field_name = $tag[ 0 ];
4045
4046
        $value = $this->get_field( $field_name );
4047
4048 View Code Duplication
        if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) && is_callable( $tag[ 1 ] ) )
4049
            $value = call_user_func_array( $tag[ 1 ], array( $value, $field_name, $this->row, &$this ) );
4050
4051
        $before = $after = '';
4052
4053
        if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) )
4054
            $before = $tag[ 2 ];
4055
4056
        if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) )
4057
            $after = $tag[ 3 ];
4058
4059
        if ( 0 < strlen( $value ) )
4060
            return $before . $value . $after;
4061
4062
        return null;
4063
    }
4064
4065
    /**
4066
     * @param bool|array $exclude
4067
     * @param bool|array $array
4068
     */
4069
    public function hidden_vars ( $exclude = false, $array = false ) {
4070
        $exclude = $this->do_hook( 'hidden_vars', $exclude, $array );
4071
        if ( false === $exclude )
4072
            $exclude = array();
4073
        if ( !is_array( $exclude ) )
4074
            $exclude = explode( ',', $exclude );
4075
        $get = $_GET;
4076
        if ( is_array( $array ) ) {
4077
            foreach ( $array as $key => $val ) {
4078
                if ( 0 < strlen( $val ) )
4079
                    $get[ $key ] = $val;
4080
                else
4081
                    unset( $get[ $key ] );
4082
            }
4083
        }
4084
        foreach ( $get as $k => $v ) {
4085
            if ( in_array( $k, $exclude ) )
4086
                continue;
4087
4088
            if ( is_array( $v ) ) {
4089
                foreach ( $v as $vk => $vv ) {
4090
?>
4091
    <input type="hidden" name="<?php echo esc_attr( $k ); ?>[<?php echo esc_attr( $vk ); ?>]" value="<?php echo esc_attr( $vv ); ?>" />
4092
<?php
4093
               }
4094
            }
4095
            else {
4096
?>
4097
    <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
4098
<?php
4099
            }
4100
        }
4101
    }
4102
4103
    /**
4104
     * @return array
4105
     */
4106
    public function exclusion () {
4107
        $exclusion = self::$excluded;
4108
4109
        foreach ( $exclusion as $k => $exclude ) {
4110
            $exclusion[ $k ] = $exclude . $this->num;
4111
        }
4112
4113
        return $exclusion;
4114
    }
4115
4116
    public function restricted ( $action = 'edit', $row = null ) {
4117
        $restricted = false;
4118
4119
        $restrict = array();
4120
4121
        if ( isset( $this->restrict[ $action ] ) )
4122
            $restrict = (array) $this->restrict[ $action ];
4123
4124
        // @todo Build 'edit', 'duplicate', 'delete' action support for 'where' which runs another find() query
4125
        /*if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) {
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...
4126
            $where = pods_var_raw( $action, $this->where, null, null, true );
4127
4128
            if ( !empty( $where ) ) {
4129
                $restricted = true;
4130
4131
                $old_where = $this->where[ $action ];
4132
4133
                $id = $this->row[ $this->sql[ 'field_id' ] ];
4134
4135
                if ( is_array( $where ) ) {
4136
                    if ( 'OR' == pods_var( 'relation', $where ) )
4137
                        $where = array( $where );
4138
4139
                    $where[] = "`t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
4140
                }
4141
                else
4142
                    $where = "( {$where} ) AND `t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
4143
4144
                $this->where[ $action ] = $where;
4145
4146
                $data = false;
4147
4148
                //$data = $this->get_data();
4149
4150
                $this->where[ $action ] = $old_where;
4151
4152
                if ( empty( $data ) )
4153
                    $restricted = true;
4154
            }
4155
        }*/
4156
4157
        $author_restrict = false;
4158
4159
        if ( !empty( $this->restrict[ 'author_restrict' ] ) && $restrict === $this->restrict[ 'author_restrict' ] ) {
4160
            $restricted = false;
4161
4162
            $author_restrict = true;
4163
4164
            if ( is_object( $this->pod ) ) {
4165
                $restricted = true;
4166
4167
                if ( 'settings' == $this->pod->pod_data[ 'type' ] && 'add' == $action )
4168
                    $action = 'edit';
4169
4170
                if ( pods_is_admin( array( 'pods', 'pods_content' ) ) )
4171
                    $restricted = false;
4172
                elseif ( 'manage' == $action ) {
4173
                    if ( !in_array( 'edit', $this->actions_disabled ) && current_user_can( 'pods_edit_' . $this->pod->pod ) && current_user_can( 'pods_edit_others_' . $this->pod->pod ) )
4174
                        $restricted = false;
4175
                    elseif ( !in_array( 'delete', $this->actions_disabled ) && current_user_can( 'pods_delete_' . $this->pod->pod ) && current_user_can( 'pods_delete_others_' . $this->pod->pod ) )
4176
                        $restricted = false;
4177 View Code Duplication
                    elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) )
4178
                        $restricted = false;
4179
                }
4180 View Code Duplication
                elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) )
4181
                    $restricted = false;
4182
            }
4183
            /* @todo determine proper logic for non-pods capabilities
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
4184
            else {
4185
                $restricted = true;
4186
4187
                if ( pods_is_admin( array( 'pods', 'pods_content' ) ) )
4188
                    $restricted = false;
4189
                elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) )
4190
                    $restricted = false;
4191
            }*/
4192
        }
4193
4194
        if ( $restricted && !empty( $restrict ) ) {
4195
            $relation = strtoupper( trim( pods_var( 'relation', $restrict, 'AND', null, true ) ) );
4196
4197
            if ( 'AND' != $relation )
4198
                $relation = 'OR';
4199
4200
            $okay = true;
4201
4202
            foreach ( $restrict as $field => $match ) {
4203
                if ( 'relation' == $field )
4204
                    continue;
4205
4206
                if ( is_array( $match ) ) {
4207
                    $match_okay = true;
4208
4209
                    $match_relation = strtoupper( trim( pods_var( 'relation', $match, 'OR', null, true ) ) );
4210
4211
                    if ( 'AND' != $match_relation )
4212
                        $match_relation = 'OR';
4213
4214
                    foreach ( $match as $the_field => $the_match ) {
4215
                        if ( 'relation' == $the_field )
4216
                            continue;
4217
4218
                        $value = null;
4219
4220 View Code Duplication
                        if ( is_object( $this->pod ) )
4221
                            $value = $this->pod->field( $the_match, true );
4222
                        else {
4223
                            if ( empty( $row ) )
4224
                                $row = $this->row;
4225
4226
                            if ( isset( $row[ $the_match ] ) ) {
4227
                                if ( is_array( $row[ $the_match ] ) ) {
4228
                                    if ( false !== strpos( $the_match, '.' ) ) {
4229
                                        $the_matches = explode( '.', $the_match );
4230
4231
                                        $value = $row[ $the_match ];
4232
4233
                                        foreach ( $the_matches as $m ) {
4234
                                            if ( is_array( $value ) && isset( $value[ $m ] ) )
4235
                                                $value = $value[ $m ];
4236
                                            else {
4237
                                                $value = null;
4238
4239
                                                break;
4240
                                            }
4241
                                        }
4242
                                    }
4243
                                }
4244
                                else
4245
                                    $value = $row[ $the_match ];
4246
                            }
4247
                        }
4248
4249 View Code Duplication
                        if ( is_array( $value ) ) {
4250
                            if ( !in_array( $the_match, $value ) )
4251
                                $match_okay = false;
4252
                            elseif ( 'OR' == $match_relation ) {
4253
                                $match_okay = true;
4254
4255
                                break;
4256
                            }
4257
                        }
4258
                        elseif ( $value == $the_match )
4259
                            $match_okay = false;
4260
                        elseif ( 'OR' == $match_relation ) {
4261
                            $match_okay = true;
4262
4263
                            break;
4264
                        }
4265
                    }
4266
4267
                    if ( !$match_okay )
4268
                        $okay = false;
4269
                    if ( 'OR' == $relation ) {
4270
                        $okay = true;
4271
4272
                        break;
4273
                    }
4274
                }
4275
                else {
4276
                    $value = null;
4277
4278 View Code Duplication
                    if ( is_object( $this->pod ) )
4279
                        $value = $this->pod->field( $match, true );
4280
                    else {
4281
                        if ( empty( $row ) )
4282
                            $row = $this->row;
4283
4284
                        if ( isset( $row[ $match ] ) ) {
4285
                            if ( is_array( $row[ $match ] ) ) {
4286
                                if ( false !== strpos( $match, '.' ) ) {
4287
                                    $matches = explode( '.', $match );
4288
4289
                                    $value = $row[ $match ];
4290
4291
                                    foreach ( $matches as $m ) {
4292
                                        if ( is_array( $value ) && isset( $value[ $m ] ) )
4293
                                            $value = $value[ $m ];
4294
                                        else {
4295
                                            $value = null;
4296
4297
                                            break;
4298
                                        }
4299
                                    }
4300
                                }
4301
                            }
4302
                            else
4303
                                $value = $row[ $match ];
4304
                        }
4305
                    }
4306
4307 View Code Duplication
                    if ( is_array( $value ) ) {
4308
                        if ( !in_array( $match, $value ) )
4309
                            $okay = false;
4310
                        elseif ( 'OR' == $relation ) {
4311
                            $okay = true;
4312
4313
                            break;
4314
                        }
4315
                    }
4316
                    elseif ( $value != $match )
4317
                        $okay = false;
4318
                    elseif ( 'OR' == $relation ) {
4319
                        $okay = true;
4320
4321
                        break;
4322
                    }
4323
                }
4324
            }
4325
4326
            if ( !empty( $author_restrict ) ) {
4327
                if ( is_object( $this->pod ) && 'manage' == $action ) {
4328
                    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 ) )
4329
                        $okay = false;
4330
                }
4331
                if ( is_object( $this->pod ) && !current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) )
4332
                    $okay = false;
4333
                /* @todo determine proper logic for non-pods capabilities
4334
                elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) )
4335
                    $okay = false;*/
4336
4337
                if ( !$okay && !empty( $row ) ) {
4338
                    foreach ( $this->restrict[ 'author_restrict' ] as $key => $val ) {
4339
                        $author_restricted = $this->get_field( $key );
4340
4341
                        if ( !empty( $author_restricted ) ) {
4342
                            if ( !is_array( $author_restricted ) )
4343
                                $author_restricted = (array) $author_restricted;
4344
4345
                            if ( is_array( $val ) ) {
4346
                                foreach ( $val as $v ) {
4347
                                    if ( in_array( $v, $author_restricted ) )
4348
                                        $okay = true;
4349
                                }
4350
                            }
4351
                            elseif ( in_array( $val, $author_restricted ) )
4352
                                $okay = true;
4353
                        }
4354
                    }
4355
                }
4356
            }
4357
4358
            if ( $okay )
4359
                $restricted = false;
4360
        }
4361
4362
		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' ] ) ) {
4363
			$restricted = call_user_func( $this->actions_custom[ $action ][ 'restrict_callback' ], $restricted, $restrict, $action, $row, $this );
4364
		}
4365
4366
        $restricted = $this->do_hook( 'restricted_' . $action, $restricted, $restrict, $action, $row );
4367
4368
        return $restricted;
4369
    }
4370
4371
	/**
4372
	 * Check for a custom action callback and run it
4373
	 *
4374
	 * @return bool|mixed
4375
	 */
4376
	public function callback() {
4377
4378
		$args = func_get_args();
4379
4380
		if ( empty( $args ) ) {
4381
			return false;
4382
		}
4383
4384
		$action = array_shift( $args );
4385
4386
		// Do hook
4387
		$callback_args = $args;
4388
		array_unshift( $callback_args, null );
4389
		array_unshift( $callback_args, $action );
4390
4391
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
4392
4393
		if ( null === $callback ) {
4394
			$callback = false;
4395
		}
4396
4397
		$args[] = $this;
4398
4399
		if ( isset( $this->actions_custom[ $action ] ) ) {
4400
			if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ][ 'callback' ] ) && is_callable( $this->actions_custom[ $action ][ 'callback' ] ) ) {
4401
				$callback = call_user_func_array( $this->actions_custom[ $action ][ 'callback' ], $args );
4402
			}
4403
			elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
4404
				$callback = call_user_func_array( $this->actions_custom[ $action ], $args );
4405
			}
4406
		}
4407
4408
		return $callback;
4409
4410
	}
4411
4412
	/**
4413
	 * Check for a custom action callback and run it (deprecated reverse arg order)
4414
	 *
4415
	 * @return bool|mixed
4416
	 */
4417 View Code Duplication
	public function callback_action() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4418
4419
		$args = func_get_args();
4420
4421
		if ( empty( $args ) ) {
4422
			return false;
4423
		}
4424
4425
		$action = array_shift( $args );
4426
4427
		$deprecated = false;
4428
4429
		if ( is_bool( $action ) ) {
4430
			$deprecated = $action;
4431
4432
			$action = array_shift( $args );
4433
		}
4434
4435
		// Do hook
4436
		$callback_args = $args;
4437
		array_unshift( $callback_args, null );
4438
		array_unshift( $callback_args, 'action_' . $action );
4439
4440
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
4441
4442
		if ( null === $callback ) {
4443
			$callback = false;
4444
		}
4445
4446
		$args[] = $this;
4447
4448
		// Deprecated reverse arg order
4449
		if ( $deprecated ) {
4450
			$args = array_reverse( $args );
4451
		}
4452
4453
		if ( isset( $this->actions_custom[ $action ] ) ) {
4454
			if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ][ 'callback' ] ) && is_callable( $this->actions_custom[ $action ][ 'callback' ] ) ) {
4455
				$callback = call_user_func_array( $this->actions_custom[ $action ][ 'callback' ], $args );
4456
			}
4457
			elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
4458
				$callback = call_user_func_array( $this->actions_custom[ $action ], $args );
4459
			}
4460
		}
4461
4462
		return $callback;
4463
4464
	}
4465
4466
	/**
4467
	 * Check for a bulk action callback and run it
4468
	 *
4469
	 * @return bool|mixed Callback result
4470
	 */
4471 View Code Duplication
	public function callback_bulk() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4472
4473
		$args = func_get_args();
4474
4475
		if ( empty( $args ) ) {
4476
			return false;
4477
		}
4478
4479
		$action = array_shift( $args );
4480
4481
		$deprecated = false;
4482
4483
		if ( is_bool( $action ) ) {
4484
			$deprecated = $action;
4485
4486
			$action = array_shift( $args );
4487
		}
4488
4489
		// Do hook
4490
		$callback_args = $args;
4491
		array_unshift( $callback_args, null );
4492
		array_unshift( $callback_args, 'bulk_action_' . $action );
4493
4494
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
4495
4496
		if ( null === $callback ) {
4497
			$callback = false;
4498
		}
4499
4500
		$args[] = $this;
4501
4502
		// Deprecated reverse arg order
4503
		if ( $deprecated ) {
4504
			$args = array_reverse( $args );
4505
		}
4506
4507
		if ( isset( $this->actions_bulk[ $action ] ) ) {
4508
			if ( is_array( $this->actions_bulk[ $action ] ) && isset( $this->actions_bulk[ $action ][ 'callback' ] ) && is_callable( $this->actions_bulk[ $action ][ 'callback' ] ) ) {
4509
				$callback = call_user_func_array( $this->actions_bulk[ $action ][ 'callback' ], $args );
4510
			}
4511
			elseif ( is_callable( $this->actions_bulk[ $action ] ) ) {
4512
				$callback = call_user_func_array( $this->actions_bulk[ $action ], $args );
4513
			}
4514
		}
4515
4516
		return $callback;
4517
4518
	}
4519
4520
    /*
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...
4521
        // Example code for use with $this->do_hook
4522
        public function my_filter_function ($args, $obj) {
4523
            $obj[0]->item = 'Post';
4524
            $obj[0]->add = true;
4525
            // args are an array (0 => $arg1, 1 => $arg2)
4526
            // may have more than one arg, dependant on filter
4527
            return $args;
4528
        }
4529
        add_filter('pods_ui_post_init', 'my_filter_function', 10, 2);
4530
    */
4531
    /**
4532
     * @return array|bool|mixed|null
4533
     */
4534 View Code Duplication
	private function do_hook() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4535
4536
		$args = func_get_args();
4537
4538
		if ( empty( $args ) ) {
4539
			return false;
4540
		}
4541
4542
		$name = array_shift( $args );
4543
4544
		return pods_do_hook( "ui", $name, $args, $this );
4545
4546
	}
4547
}
4548