Completed
Pull Request — 2.x (#3632)
by Scott Kingsley
05:31
created

PodsUI::export()   C

Complexity

Conditions 9
Paths 32

Size

Total Lines 62
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 34
nc 32
nop 1
dl 0
loc 62
rs 6.6867
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
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;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
504
        }
505
506
        $this->go();
507
    }
508
509
    /**
510
     * @param $deprecated_options
511
     *
512
     * @return array
513
     */
514
    public function setup_deprecated ( $deprecated_options ) {
515
        $options = array();
516
517
        if ( isset( $deprecated_options[ 'id' ] ) )
518
            $options[ 'id' ] = $deprecated_options[ 'id' ];
519
        if ( isset( $deprecated_options[ 'action' ] ) )
520
            $options[ 'action' ] = $deprecated_options[ 'action' ];
521
        if ( isset( $deprecated_options[ 'num' ] ) )
522
            $options[ 'num' ] = $deprecated_options[ 'num' ];
523
524
        if ( isset( $deprecated_options[ 'title' ] ) )
525
            $options[ 'items' ] = $deprecated_options[ 'title' ];
526
        if ( isset( $deprecated_options[ 'item' ] ) )
527
            $options[ 'item' ] = $deprecated_options[ 'item' ];
528
529
        if ( isset( $deprecated_options[ 'label' ] ) )
530
            $options[ 'label' ] = array(
531
                'add' => $deprecated_options[ 'label' ],
532
                'edit' => $deprecated_options[ 'label' ],
533
                'duplicate' => $deprecated_options[ 'label' ]
534
            );
535
        if ( isset( $deprecated_options[ 'label_add' ] ) ) {
536
            if ( isset( $options[ 'label' ] ) )
537
                $options[ 'label' ][ 'add' ] = $deprecated_options[ 'label_add' ];
538
            else
539
                $options[ 'label' ] = array( 'add' => $deprecated_options[ 'label_add' ] );
540
        }
541
        if ( isset( $deprecated_options[ 'label_edit' ] ) ) {
542
            if ( isset( $options[ 'label' ] ) )
543
                $options[ 'label' ][ 'edit' ] = $deprecated_options[ 'label_edit' ];
544
            else
545
                $options[ 'label' ] = array( 'edit' => $deprecated_options[ 'label_edit' ] );
546
        }
547
        if ( isset( $deprecated_options[ 'label_duplicate' ] ) ) {
548
            if ( isset( $options[ 'label' ] ) )
549
                $options[ 'label' ][ 'duplicate' ] = $deprecated_options[ 'label_duplicate' ];
550
            else
551
                $options[ 'label' ] = array( 'duplicate' => $deprecated_options[ 'label_duplicate' ] );
552
        }
553
554
        if ( isset( $deprecated_options[ 'icon' ] ) )
555
            $options[ 'icon' ] = $deprecated_options[ 'icon' ];
556
557
        if ( isset( $deprecated_options[ 'columns' ] ) )
558
            $options[ 'fields' ] = array( 'manage' => $deprecated_options[ 'columns' ] );
559
        if ( isset( $deprecated_options[ 'reorder_columns' ] ) ) {
560
            if ( isset( $options[ 'fields' ] ) )
561
                $options[ 'fields' ][ 'reorder' ] = $deprecated_options[ 'reorder_columns' ];
562
            else
563
                $options[ 'fields' ] = array( 'reorder' => $deprecated_options[ 'reorder_columns' ] );
564
        }
565 View Code Duplication
        if ( isset( $deprecated_options[ 'add_fields' ] ) ) {
566
            if ( isset( $options[ 'fields' ] ) ) {
567
                if ( !isset( $options[ 'fields' ][ 'add' ] ) )
568
                    $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'add_fields' ];
569
                if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
570
                    $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'add_fields' ];
571
                if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
572
                    $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'add_fields' ];
573
            }
574
            else
575
                $options[ 'fields' ] = array(
576
                    'add' => $deprecated_options[ 'add_fields' ],
577
                    'edit' => $deprecated_options[ 'add_fields' ],
578
                    'duplicate' => $deprecated_options[ 'add_fields' ]
579
                );
580
        }
581 View Code Duplication
        if ( isset( $deprecated_options[ 'edit_fields' ] ) ) {
582
            if ( isset( $options[ 'fields' ] ) ) {
583
                if ( !isset( $options[ 'fields' ][ 'add' ] ) )
584
                    $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'edit_fields' ];
585
                if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
586
                    $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'edit_fields' ];
587
                if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
588
                    $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'edit_fields' ];
589
            }
590
            else
591
                $options[ 'fields' ] = array(
592
                    'add' => $deprecated_options[ 'edit_fields' ],
593
                    'edit' => $deprecated_options[ 'edit_fields' ],
594
                    'duplicate' => $deprecated_options[ 'edit_fields' ]
595
                );
596
        }
597
        if ( isset( $deprecated_options[ 'duplicate_fields' ] ) ) {
598
            if ( isset( $options[ 'fields' ] ) )
599
                $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_fields' ];
600
            else
601
                $options[ 'fields' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_fields' ] );
602
        }
603
604
        if ( isset( $deprecated_options[ 'session_filters' ] ) && false === $deprecated_options[ 'session_filters' ] )
605
            $options[ 'session' ] = false;
606 View Code Duplication
        if ( isset( $deprecated_options[ 'user_per_page' ] ) ) {
607
            if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
608
                $options[ 'user' ] = array( 'orderby' );
609
            else
610
                $options[ 'user' ] = false;
611
        }
612 View Code Duplication
        if ( isset( $deprecated_options[ 'user_sort' ] ) ) {
613
            if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
614
                $options[ 'user' ] = array( 'show_per_page' );
615
            else
616
                $options[ 'user' ] = false;
617
        }
618
619
        if ( isset( $deprecated_options[ 'custom_list' ] ) ) {
620
            if ( isset( $options[ 'actions_custom' ] ) )
621
                $options[ 'actions_custom' ][ 'manage' ] = $deprecated_options[ 'custom_list' ];
622
            else
623
                $options[ 'actions_custom' ] = array( 'manage' => $deprecated_options[ 'custom_list' ] );
624
        }
625
        if ( isset( $deprecated_options[ 'custom_reorder' ] ) ) {
626
            if ( isset( $options[ 'actions_custom' ] ) )
627
                $options[ 'actions_custom' ][ 'reorder' ] = $deprecated_options[ 'custom_reorder' ];
628
            else
629
                $options[ 'actions_custom' ] = array( 'reorder' => $deprecated_options[ 'custom_reorder' ] );
630
        }
631
        if ( isset( $deprecated_options[ 'custom_add' ] ) ) {
632
            if ( isset( $options[ 'actions_custom' ] ) )
633
                $options[ 'actions_custom' ][ 'add' ] = $deprecated_options[ 'custom_add' ];
634
            else
635
                $options[ 'actions_custom' ] = array( 'add' => $deprecated_options[ 'custom_add' ] );
636
        }
637
        if ( isset( $deprecated_options[ 'custom_edit' ] ) ) {
638
            if ( isset( $options[ 'actions_custom' ] ) )
639
                $options[ 'actions_custom' ][ 'edit' ] = $deprecated_options[ 'custom_edit' ];
640
            else
641
                $options[ 'actions_custom' ] = array( 'edit' => $deprecated_options[ 'custom_edit' ] );
642
        }
643
        if ( isset( $deprecated_options[ 'custom_duplicate' ] ) ) {
644
            if ( isset( $options[ 'actions_custom' ] ) )
645
                $options[ 'actions_custom' ][ 'duplicate' ] = $deprecated_options[ 'custom_duplicate' ];
646
            else
647
                $options[ 'actions_custom' ] = array( 'duplicate' => $deprecated_options[ 'custom_duplicate' ] );
648
        }
649
        if ( isset( $deprecated_options[ 'custom_delete' ] ) ) {
650
            if ( isset( $options[ 'actions_custom' ] ) )
651
                $options[ 'actions_custom' ][ 'delete' ] = $deprecated_options[ 'custom_delete' ];
652
            else
653
                $options[ 'actions_custom' ] = array( 'delete' => $deprecated_options[ 'custom_delete' ] );
654
        }
655
        if ( isset( $deprecated_options[ 'custom_save' ] ) ) {
656
            if ( isset( $options[ 'actions_custom' ] ) )
657
                $options[ 'actions_custom' ][ 'save' ] = $deprecated_options[ 'custom_save' ];
658
            else
659
                $options[ 'actions_custom' ] = array( 'save' => $deprecated_options[ 'custom_save' ] );
660
        }
661
662
        if ( isset( $deprecated_options[ 'custom_actions' ] ) )
663
            $options[ 'actions_custom' ] = $deprecated_options[ 'custom_actions' ];
664
        if ( isset( $deprecated_options[ 'action_after_save' ] ) )
665
            $options[ 'action_after' ] = array(
666
                'add' => $deprecated_options[ 'action_after_save' ],
667
                'edit' => $deprecated_options[ 'action_after_save' ],
668
                'duplicate' => $deprecated_options[ 'action_after_save' ]
669
            );
670
        if ( isset( $deprecated_options[ 'edit_link' ] ) ) {
671
            if ( isset( $options[ 'action_links' ] ) )
672
                $options[ 'action_links' ][ 'edit' ] = $deprecated_options[ 'edit_link' ];
673
            else
674
                $options[ 'action_links' ] = array( 'edit' => $deprecated_options[ 'edit_link' ] );
675
        }
676
        if ( isset( $deprecated_options[ 'view_link' ] ) ) {
677
            if ( isset( $options[ 'action_links' ] ) )
678
                $options[ 'action_links' ][ 'view' ] = $deprecated_options[ 'view_link' ];
679
            else
680
                $options[ 'action_links' ] = array( 'view' => $deprecated_options[ 'view_link' ] );
681
        }
682
        if ( isset( $deprecated_options[ 'duplicate_link' ] ) ) {
683
            if ( isset( $options[ 'action_links' ] ) )
684
                $options[ 'action_links' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_link' ];
685
            else
686
                $options[ 'action_links' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_link' ] );
687
        }
688
689
        if ( isset( $deprecated_options[ 'reorder' ] ) )
690
            $options[ 'reorder' ] = array(
691
                'on' => $deprecated_options[ 'reorder' ],
692
                'orderby' => $deprecated_options[ 'reorder' ]
693
            );
694
        if ( isset( $deprecated_options[ 'reorder_sort' ] ) && isset( $options[ 'reorder' ] ) )
695
            $options[ 'reorder' ][ 'orderby' ] = $deprecated_options[ 'reorder_sort' ];
696
        if ( isset( $deprecated_options[ 'reorder_limit' ] ) && isset( $options[ 'reorder' ] ) )
697
            $options[ 'reorder' ][ 'limit' ] = $deprecated_options[ 'reorder_limit' ];
698
        if ( isset( $deprecated_options[ 'reorder_sql' ] ) && isset( $options[ 'reorder' ] ) )
699
            $options[ 'reorder' ][ 'sql' ] = $deprecated_options[ 'reorder_sql' ];
700
701
        if ( isset( $deprecated_options[ 'sort' ] ) )
702
            $options[ 'orderby' ] = $deprecated_options[ 'sort' ];
703
        if ( isset( $deprecated_options[ 'sortable' ] ) )
704
            $options[ 'sortable' ] = $deprecated_options[ 'sortable' ];
705
        if ( isset( $deprecated_options[ 'limit' ] ) )
706
            $options[ 'limit' ] = $deprecated_options[ 'limit' ];
707
708
        if ( isset( $deprecated_options[ 'where' ] ) ) {
709
            if ( isset( $options[ 'where' ] ) )
710
                $options[ 'where' ][ 'manage' ] = $deprecated_options[ 'where' ];
711
            else
712
                $options[ 'where' ] = array( 'manage' => $deprecated_options[ 'where' ] );
713
        }
714 View Code Duplication
        if ( isset( $deprecated_options[ 'edit_where' ] ) ) {
715
            /*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...
716
                $options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ];
717
            else
718
                $options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );*/
719
720
            if ( isset( $options[ 'restrict' ] ) )
721
                $options[ 'restrict' ][ 'edit' ] = (array) $deprecated_options[ 'edit_where' ];
722
            else
723
                $options[ 'restrict' ] = array( 'edit' => (array) $deprecated_options[ 'edit_where' ] );
724
        }
725 View Code Duplication
        if ( isset( $deprecated_options[ 'duplicate_where' ] ) ) {
726
            /*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...
727
                $options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ];
728
            else
729
                $options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );*/
730
731
            if ( isset( $options[ 'restrict' ] ) )
732
                $options[ 'restrict' ][ 'duplicate' ] = (array) $deprecated_options[ 'duplicate_where' ];
733
            else
734
                $options[ 'restrict' ] = array( 'duplicate' => (array) $deprecated_options[ 'duplicate_where' ] );
735
        }
736 View Code Duplication
        if ( isset( $deprecated_options[ 'delete_where' ] ) ) {
737
            /*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...
738
                $options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ];
739
            else
740
                $options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );*/
741
742
            if ( isset( $options[ 'restrict' ] ) )
743
                $options[ 'restrict' ][ 'delete' ] = (array) $deprecated_options[ 'delete_where' ];
744
            else
745
                $options[ 'restrict' ] = array( 'delete' => (array) $deprecated_options[ 'delete_where' ] );
746
        }
747
        if ( isset( $deprecated_options[ 'reorder_where' ] ) ) {
748
            if ( isset( $options[ 'where' ] ) )
749
                $options[ 'where' ][ 'reorder' ] = $deprecated_options[ 'reorder_where' ];
750
            else
751
                $options[ 'where' ] = array( 'reorder' => $deprecated_options[ 'reorder_where' ] );
752
        }
753
754
        if ( isset( $deprecated_options[ 'sql' ] ) )
755
            $options[ 'sql' ] = array( 'sql' => $deprecated_options[ 'sql' ] );
756
757
        if ( isset( $deprecated_options[ 'search' ] ) )
758
            $options[ 'searchable' ] = $deprecated_options[ 'search' ];
759
        if ( isset( $deprecated_options[ 'search_across' ] ) )
760
            $options[ 'search_across' ] = $deprecated_options[ 'search_across' ];
761
        if ( isset( $deprecated_options[ 'search_across_picks' ] ) )
762
            $options[ 'search_across_picks' ] = $deprecated_options[ 'search_across_picks' ];
763
        if ( isset( $deprecated_options[ 'filters' ] ) )
764
            $options[ 'filters' ] = $deprecated_options[ 'filters' ];
765
        if ( isset( $deprecated_options[ 'custom_filters' ] ) ) {
766
            if ( is_callable( $deprecated_options[ 'custom_filters' ] ) )
767
                add_filter( 'pods_ui_filters', $deprecated_options[ 'custom_filters' ] );
768
            else {
769
                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...
770
                $pods_ui_custom_filters = $deprecated_options[ 'custom_filters' ];
771
                add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) );
772
            }
773
        }
774
775
        if ( isset( $deprecated_options[ 'disable_actions' ] ) )
776
            $options[ 'actions_disabled' ] = $deprecated_options[ 'disable_actions' ];
777
        if ( isset( $deprecated_options[ 'hide_actions' ] ) )
778
            $options[ 'actions_hidden' ] = $deprecated_options[ 'hide_actions' ];
779
780
        if ( isset( $deprecated_options[ 'wpcss' ] ) )
781
            $options[ 'wpcss' ] = $deprecated_options[ 'wpcss' ];
782
783
        $remaining_options = array_diff_assoc( $options, $deprecated_options );
784
785
        foreach ( $remaining_options as $option => $value ) {
786
            if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) )
787
                $options[ $option ] = $value;
788
        }
789
790
        return $options;
791
    }
792
793
    /**
794
     *
795
     */
796
    public function deprecated_filters () {
797
        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...
798
        echo $pods_ui_custom_filters;
799
    }
800
801
    /**
802
     * @param $options
803
     *
804
     * @return array|bool|mixed|null|PodsArray
805
     */
806
    public function setup ( $options ) {
807
        $options = pods_array( $options );
808
809
        $options->validate( 'num', '', 'absint' );
810
811
        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...
812
            $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...
813
814
        $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...
815
816
        $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...
817
            'save',
818
            'create'
819
        ) );
820
821
        $options->validate( 'excluded', self::$excluded, 'array_merge' );
822
823
        $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...
824
        $options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' );
825
        $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...
826
827
        $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...
828
829
        if ( !empty( $bulk ) )
830
            $bulk = (array) pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true );
831
        else
832
            $bulk = array();
833
834
        $options->validate( 'bulk', $bulk, 'array_merge', $this->bulk );
835
836
        $options->validate( 'views', $this->views, 'array' );
837
        $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...
838
839
        $options->validate( 'searchable', $this->searchable, 'boolean' );
840
        $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...
841
        $options->validate( 'search_across', $this->search_across, 'boolean' );
842
        $options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' );
843
        $options->validate( 'filters', $this->filters, 'array' );
844
        $options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' );
845
        $options->validate( 'where', $this->where, 'array_merge' );
846
847
        $options->validate( 'pagination', $this->pagination, 'boolean' );
848
        $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...
849
        $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...
850
851
        if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) {
852
            $this->sql = array(
853
                'table' => $this->pods_data->table,
854
                'field_id' => $this->pods_data->field_id,
855
                'field_index' => $this->pods_data->field_index
856
            );
857
        }
858
        $options->validate( 'sql', $this->sql, 'array_merge' );
859
860
        $options->validate( 'orderby_dir', strtoupper( pods_v( 'orderby_dir' . $options[ 'num' ], 'get', $this->orderby_dir, true ) ), 'in_array', array( 'ASC', 'DESC' ) );
861
862
	    $orderby = $this->orderby;
863
864
	    // Enforce strict DB column name usage
865
	    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...
866
		    $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...
867
	    }
868
869
        if ( !empty( $orderby ) ) {
870
            $orderby = array(
871
                'default' => $orderby
872
            );
873
        }
874
        else
875
            $orderby = array();
876
877
        $options->validate( 'orderby', $orderby, 'array_merge' );
878
        $options->validate( 'sortable', $this->sortable, 'boolean' );
879
880
        $options->validate( 'params', $this->params, 'array' );
881
882
        $options->validate( 'restrict', $this->restrict, 'array_merge' );
883
884
        // handle author restrictions
885
        if ( !empty( $options[ 'restrict' ][ 'author_restrict' ] ) ) {
886
            $restrict = $options[ 'restrict' ];
887
888
            if ( !is_array( $restrict[ 'author_restrict' ] ) )
889
                $restrict[ 'author_restrict' ] = array( $restrict[ 'author_restrict' ] => get_current_user_id() );
890
891
            if ( null === $restrict[ 'edit' ] )
892
                $restrict[ 'edit' ] = $restrict[ 'author_restrict' ];
893
894
            $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...
895
        }
896
897
        if ( null !== $options[ 'restrict' ][ 'edit' ] ) {
898
            $restrict = $options[ 'restrict' ];
899
900
            if ( null === $restrict[ 'duplicate' ] )
901
                $restrict[ 'duplicate' ] = $restrict[ 'edit' ];
902
903
            if ( null === $restrict[ 'delete' ] )
904
                $restrict[ 'delete' ] = $restrict[ 'edit' ];
905
906
            if ( null === $restrict[ 'manage' ] )
907
                $restrict[ 'manage' ] = $restrict[ 'edit' ];
908
909
            if ( null === $restrict[ 'reorder' ] )
910
                $restrict[ 'reorder' ] = $restrict[ 'edit' ];
911
912
            $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...
913
        }
914
915
        $item = __( 'Item', 'pods' );
916
        $items = __( 'Items', 'pods' );
917
918
        if ( is_object( $this->pod ) ) {
919
            $item = pods_var_raw( 'label_singular', $this->pod->pod_data[ 'options' ], pods_var_raw( 'label', $this->pod->pod_data, $item, null, true ), null, true );
920
            $items = pods_var_raw( 'label', $this->pod->pod_data, $items, null, true );
921
        }
922
923
        $options->validate( 'item', $item );
924
        $options->validate( 'items', $items );
925
926
        $options->validate( 'heading', array(
927
            'manage' => __( 'Manage', 'pods' ),
928
            'add' => __( 'Add New', 'pods' ),
929
            'edit' => __( 'Edit', 'pods' ),
930
            'duplicate' => __( 'Duplicate', 'pods' ),
931
            'view' => __( 'View', 'pods' ),
932
            'reorder' => __( 'Reorder', 'pods' ),
933
            'search' => __( 'Search', 'pods' ),
934
            'views' => __( 'View', 'pods' )
935
        ), 'array_merge' );
936
937
        $options->validate( 'header', array(
938
            '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...
939
            '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...
940
            '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...
941
            '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...
942
            '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...
943
            '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...
944
            '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...
945
        ), 'array_merge' );
946
947
        $options->validate( 'label', array(
948
            '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...
949
            'add_new' => __( 'Add New', 'pods' ),
950
            '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...
951
            '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...
952
            '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...
953
            '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...
954
            '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...
955
        ), 'array_merge' );
956
957
        $options->validate( 'fields', array(
958
            'manage' => array(
959
                $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...
960
            )
961
        ), 'array' );
962
963
        $options->validate( 'export', $this->export, 'array_merge' );
964
        $options->validate( 'reorder', $this->reorder, 'array_merge' );
965
        $options->validate( 'screen_options', $this->screen_options, 'array_merge' );
966
967
        $options->validate( 'session', $this->session, 'in_array', array(
968
            'search',
969
            'filters',
970
            'show_per_page',
971
            'orderby'
972
        ) );
973
        $options->validate( 'user', $this->user, 'in_array', array(
974
            'search',
975
            'filters',
976
            'show_per_page',
977
            'orderby'
978
        ) );
979
980
        $options->validate( 'action_after', $this->action_after, 'array_merge' );
981
        $options->validate( 'action_links', $this->action_links, 'array_merge' );
982
        $options->validate( 'actions_disabled', $this->actions_disabled, 'array' );
983
        $options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' );
984
        $options->validate( 'actions_custom', $this->actions_custom, 'array_merge' );
985
986
		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...
987 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...
988
				$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...
989
990
				foreach ( $actions_bulk as $action => $action_opt ) {
991
					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...
992
						unset( $actions_bulk[ $action ] );
993
					}
994
				}
995
996
				$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...
997
			}
998
999 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...
1000
				$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...
1001
1002
				foreach ( $actions_custom as $action => $action_opt ) {
1003
					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...
1004
						unset( $actions_custom[ $action ] );
1005
					}
1006
				}
1007
1008
				$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...
1009
			}
1010
		}
1011
1012
        $options->validate( 'extra', $this->extra, 'array_merge' );
1013
1014
        $options->validate( 'style', $this->style );
1015
        $options->validate( 'icon', $this->icon );
1016
        $options->validate( 'css', $this->css );
1017
        $options->validate( 'wpcss', $this->wpcss, 'boolean' );
1018
1019
        if ( true === $options[ 'wpcss' ] ) {
1020
            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...
1021
            wp_get_current_user();
1022
1023
            $color = get_user_meta( $user_ID, 'admin_color', true );
1024
            if ( strlen( $color ) < 1 )
1025
                $color = 'fresh';
1026
1027
            $this->wpcss = "colors-{$color}";
1028
        }
1029
1030
        $options = $options->dump();
1031
1032
        if ( is_object( $this->pod ) )
1033
            $options = $this->do_hook( $this->pod->pod . '_setup_options', $options );
1034
1035
        $options = $this->do_hook( 'setup_options', $options );
1036
1037
        if ( false !== $options && !empty( $options ) ) {
1038
            foreach ( $options as $option => $value ) {
1039
                if ( isset( $this->{$option} ) )
1040
                    $this->{$option} = $value;
1041
                else
1042
                    $this->x[ $option ] = $value;
1043
            }
1044
        }
1045
1046
        $unique_identifier = pods_var( 'page', 'get' ); // wp-admin page
1047
        if ( is_object( $this->pod ) && isset( $this->pod->pod ) )
1048
            $unique_identifier = '_' . $this->pod->pod;
1049
        elseif ( 0 < strlen( $this->sql[ 'table' ] ) )
1050
            $unique_identifier = '_' . $this->sql[ 'table' ];
1051
1052
        $unique_identifier .= '_' . $this->page;
1053
        if ( 0 < strlen( $this->num ) )
1054
            $unique_identifier .= '_' . $this->num;
1055
1056
        $this->unique_identifier = 'pods_ui_' . md5( $unique_identifier );
1057
1058
        $this->setup_fields();
1059
1060
        return $options;
1061
    }
1062
1063
    /**
1064
     * @param null $fields
1065
     * @param string $which
1066
     *
1067
     * @return array|bool|mixed|null
1068
     */
1069
    public function setup_fields ( $fields = null, $which = 'fields' ) {
1070
        $init = false;
1071
        if ( null === $fields ) {
1072
            if ( isset( $this->fields[ $which ] ) )
1073
                $fields = (array) $this->fields[ $which ];
1074
            elseif ( isset( $this->fields[ 'manage' ] ) )
1075
                $fields = (array) $this->fields[ 'manage' ];
1076
            else
1077
                $fields = array();
1078
            if ( 'fields' == $which )
1079
                $init = true;
1080
        }
1081
        if ( !empty( $fields ) ) {
1082
            // Available Attributes
1083
            // type = field type
1084
            // type = date (data validation as date)
1085
            // type = time (data validation as time)
1086
            // type = datetime (data validation as datetime)
1087
            // date_touch = use current timestamp when saving (even if readonly, if type is date-related)
1088
            // date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related)
1089
            // 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
1090
            // type = text / other (single line text box)
1091
            // type = desc (textarea)
1092
            // type = number (data validation as int float)
1093
            // type = decimal (data validation as decimal)
1094
            // type = password (single line password box)
1095
            // type = bool (checkbox)
1096
            // type = related (select box)
1097
            // related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items
1098
            // related_field = field name on table to show (if type=related) - default "name"
1099
            // related_multiple = true (ability to select multiple values if type=related)
1100
            // related_sql = custom where / order by SQL (if type=related)
1101
            // readonly = true (shows as text)
1102
            // display = false (doesn't show on form, but can be saved)
1103
            // search = this field is searchable
1104
            // filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box)
1105
            // comments = comments to show for field
1106
            // comments_top = true (shows comments above field instead of below)
1107
            // real_name = the real name of the field (if using an alias for 'name')
1108
            // group_related = true (uses HAVING instead of WHERE for filtering field)
1109
            $new_fields = array();
1110
            $filterable = false;
1111
            if ( empty( $this->filters ) && ( empty( $this->fields[ 'search' ] ) || 'search' == $which ) && false !== $this->searchable ) {
1112
                $filterable = true;
1113
                $this->filters = array();
1114
            }
1115
1116
            foreach ( $fields as $field => $attributes ) {
1117
                if ( !is_array( $attributes ) ) {
1118
                    if ( is_int( $field ) ) {
1119
                        $field = $attributes;
1120
                        $attributes = array();
1121
                    }
1122
                    else
1123
                        $attributes = array( 'label' => $attributes );
1124
                }
1125
1126
                if ( !isset( $attributes[ 'real_name' ] ) )
1127
                    $attributes[ 'real_name' ] = pods_var( 'name', $attributes, $field );
1128
1129
                if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes[ 'real_name' ] ] ) )
1130
                    $attributes = array_merge( $this->pod->fields[ $attributes[ 'real_name' ] ], $attributes );
1131
1132
                if ( !isset( $attributes[ 'options' ] ) )
1133
                    $attributes[ 'options' ] = array();
1134
                if ( !isset( $attributes[ 'id' ] ) )
1135
                    $attributes[ 'id' ] = '';
1136
                if ( !isset( $attributes[ 'label' ] ) )
1137
                    $attributes[ 'label' ] = ucwords( str_replace( '_', ' ', $field ) );
1138
                if ( !isset( $attributes[ 'type' ] ) )
1139
                    $attributes[ 'type' ] = 'text';
1140
                if ( !isset( $attributes[ 'options' ][ 'date_format_type' ] ) )
1141
                    $attributes[ 'options' ][ 'date_format_type' ] = 'date';
1142 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related' ] ) )
1143
                    $attributes[ 'related' ] = false;
1144 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_id' ] ) )
1145
                    $attributes[ 'related_id' ] = 'id';
1146 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_field' ] ) )
1147
                    $attributes[ 'related_field' ] = 'name';
1148 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_multiple' ] ) )
1149
                    $attributes[ 'related_multiple' ] = false;
1150 View Code Duplication
                if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_sql' ] ) )
1151
                    $attributes[ 'related_sql' ] = false;
1152
                if ( 'related' == $attributes[ 'type' ] && ( is_array( $attributes[ 'related' ] ) || strpos( $attributes[ 'related' ], ',' ) ) ) {
1153
                    if ( !is_array( $attributes[ 'related' ] ) ) {
1154
                        $attributes[ 'related' ] = @explode( ',', $attributes[ 'related' ] );
1155
                        $related_items = array();
1156
                        foreach ( $attributes[ 'related' ] as $key => $label ) {
1157
                            if ( is_numeric( $key ) ) {
1158
                                $key = $label;
1159
                                $label = ucwords( str_replace( '_', ' ', $label ) );
1160
                            }
1161
                            $related_items[ $key ] = $label;
1162
                        }
1163
                        $attributes[ 'related' ] = $related_items;
1164
                    }
1165
                    if ( empty( $attributes[ 'related' ] ) )
1166
                        $attributes[ 'related' ] = false;
1167
                }
1168
                if ( !isset( $attributes[ 'readonly' ] ) )
1169
                    $attributes[ 'readonly' ] = false;
1170
                if ( !isset( $attributes[ 'date_touch' ] ) || 'date' != $attributes[ 'type' ] )
1171
                    $attributes[ 'date_touch' ] = false;
1172
                if ( !isset( $attributes[ 'date_touch_on_create' ] ) || 'date' != $attributes[ 'type' ] )
1173
                    $attributes[ 'date_touch_on_create' ] = false;
1174
                if ( !isset( $attributes[ 'display' ] ) )
1175
                    $attributes[ 'display' ] = true;
1176
                if ( !isset( $attributes[ 'hidden' ] ) )
1177
                    $attributes[ 'hidden' ] = false;
1178
                if ( !isset( $attributes[ 'sortable' ] ) || false === $this->sortable )
1179
                    $attributes[ 'sortable' ] = $this->sortable;
1180 View Code Duplication
                if ( !isset( $attributes[ 'options' ][ 'search' ] ) || false === $this->searchable )
1181
                    $attributes[ 'options' ][ 'search' ] = $this->searchable;
1182 View Code Duplication
                if ( !isset( $attributes[ 'options' ][ 'filter' ] ) || false === $this->searchable )
1183
                    $attributes[ 'options' ][ 'filter' ] = $this->searchable;
1184
                /*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...
1185
                    $this->filters[] = $field;*/
1186
                if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_label' ] ) || !in_array( $field, $this->filters ) )
1187
                    $attributes[ 'filter_label' ] = $attributes[ 'label' ];
1188
                if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_default' ] ) || !in_array( $field, $this->filters ) )
1189
                    $attributes[ 'filter_default' ] = false;
1190 View Code Duplication
                if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !in_array( $field, $this->filters ) )
1191
                    $attributes[ 'date_ongoing' ] = false;
1192 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 ) )
1193
                    $attributes[ 'date_ongoing_default' ] = false;
1194
                if ( !isset( $attributes[ 'export' ] ) )
1195
                    $attributes[ 'export' ] = true;
1196
                if ( !isset( $attributes[ 'group_related' ] ) )
1197
                    $attributes[ 'group_related' ] = false;
1198
                if ( !isset( $attributes[ 'comments' ] ) )
1199
                    $attributes[ 'comments' ] = '';
1200
                if ( !isset( $attributes[ 'comments_top' ] ) )
1201
                    $attributes[ 'comments_top' ] = false;
1202
                if ( !isset( $attributes[ 'custom_view' ] ) )
1203
                    $attributes[ 'custom_view' ] = false;
1204
                if ( !isset( $attributes[ 'custom_input' ] ) )
1205
                    $attributes[ 'custom_input' ] = false;
1206
                if ( isset( $attributes[ 'display_helper' ] ) ) // pods ui backward compatibility
1207
                    $attributes[ 'custom_display' ] = $attributes[ 'display_helper' ];
1208
                if ( !isset( $attributes[ 'custom_display' ] ) )
1209
                    $attributes[ 'custom_display' ] = false;
1210
                if ( !isset( $attributes[ 'custom_relate' ] ) )
1211
                    $attributes[ 'custom_relate' ] = false;
1212
                if ( !isset( $attributes[ 'custom_form_display' ] ) )
1213
                    $attributes[ 'custom_form_display' ] = false;
1214
                if ( !isset( $attributes[ 'css_values' ] ) )
1215
                    $attributes[ 'css_values' ] = true;
1216
                if ( 'search_columns' == $which && !$attributes[ 'options' ][ 'search' ] )
1217
                    continue;
1218
1219
                $attributes = PodsForm::field_setup( $attributes, null, $attributes[ 'type' ] );
1220
1221
                $new_fields[ $field ] = $attributes;
1222
            }
1223
            $fields = $new_fields;
1224
        }
1225
        if ( false !== $init ) {
1226
            if ( 'fields' != $which && !empty( $this->fields ) )
1227
                $this->fields = $this->setup_fields( $this->fields, 'fields' );
1228
            else
1229
                $this->fields[ 'manage' ] = $fields;
1230
1231
            if ( !in_array( 'add', $this->actions_disabled ) || !in_array( 'edit', $this->actions_disabled ) || !in_array( 'duplicate', $this->actions_disabled ) ) {
1232
                if ( 'form' != $which && isset( $this->fields[ 'form' ] ) && is_array( $this->fields[ 'form' ] ) )
1233
                    $this->fields[ 'form' ] = $this->setup_fields( $this->fields[ 'form' ], 'form' );
1234
                else
1235
                    $this->fields[ 'form' ] = $fields;
1236
1237
                if ( !in_array( 'add', $this->actions_disabled ) ) {
1238
                    if ( 'add' != $which && isset( $this->fields[ 'add' ] ) && is_array( $this->fields[ 'add' ] ) )
1239
                        $this->fields[ 'add' ] = $this->setup_fields( $this->fields[ 'add' ], 'add' );
1240
                }
1241
                if ( !in_array( 'edit', $this->actions_disabled ) ) {
1242
                    if ( 'edit' != $which && isset( $this->fields[ 'edit' ] ) && is_array( $this->fields[ 'edit' ] ) )
1243
                        $this->fields[ 'edit' ] = $this->setup_fields( $this->fields[ 'edit' ], 'edit' );
1244
                }
1245
                if ( !in_array( 'duplicate', $this->actions_disabled ) ) {
1246
                    if ( 'duplicate' != $which && isset( $this->fields[ 'duplicate' ] ) && is_array( $this->fields[ 'duplicate' ] ) )
1247
                        $this->fields[ 'duplicate' ] = $this->setup_fields( $this->fields[ 'duplicate' ], 'duplicate' );
1248
                }
1249
            }
1250
1251 View Code Duplication
            if ( false !== $this->searchable ) {
1252
                if ( 'search' != $which && isset( $this->fields[ 'search' ] ) &&!empty( $this->fields[ 'search' ] ) )
1253
                    $this->fields[ 'search' ] = $this->setup_fields( $this->fields[ 'search' ], 'search' );
1254
                else
1255
                    $this->fields[ 'search' ] = $fields;
1256
            }
1257
            else
1258
                $this->fields[ 'search' ] = false;
1259
1260
            if ( !in_array( 'export', $this->actions_disabled ) ) {
1261
                if ( 'export' != $which && isset( $this->fields[ 'export' ] ) &&!empty( $this->fields[ 'export' ] ) )
1262
                    $this->fields[ 'export' ] = $this->setup_fields( $this->fields[ 'export' ], 'export' );
1263
            }
1264
1265 View Code Duplication
            if ( !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
1266
                if ( 'reorder' != $which && isset( $this->fields[ 'reorder' ] ) &&!empty( $this->fields[ 'reorder' ] ) )
1267
                    $this->fields[ 'reorder' ] = $this->setup_fields( $this->fields[ 'reorder' ], 'reorder' );
1268
                else
1269
                    $this->fields[ 'reorder' ] = $fields;
1270
            }
1271
        }
1272
        return $this->do_hook( 'setup_fields', $fields, $which, $init );
1273
    }
1274
1275
    /**
1276
     * @param $msg
1277
     * @param bool $error
1278
     */
1279
    public function message ( $msg, $error = false ) {
1280
        $msg = $this->do_hook( ( $error ) ? 'error' : 'message', $msg );
1281
        ?>
1282
    <div id="message" class="<?php echo esc_attr( ( $error ) ? 'error' : 'updated' ); ?> fade"><p><?php echo $msg; ?></p></div>
1283
    <?php
1284
    }
1285
1286
    /**
1287
     * @param $msg
1288
     *
1289
     * @return bool
1290
     */
1291
    public function error ( $msg ) {
1292
        $this->message( $msg, true );
1293
1294
        return false;
1295
    }
1296
1297
    /**
1298
     * @return mixed
1299
     */
1300
    public function go () {
1301
        $this->do_hook( 'go' );
1302
        $_GET = pods_unsanitize( $_GET ); // fix wp sanitization
1303
        $_POST = pods_unsanitize( $_POST ); // fix wp sanitization
1304
1305
        if ( false !== $this->css ) {
1306
            ?>
1307
        <link type="text/css" rel="stylesheet" href="<?php echo esc_url( $this->css ); ?>" />
1308
        <?php
1309
        }
1310
        if ( false !== $this->wpcss ) {
1311
            $stylesheets = array( 'global', 'wp-admin', $this->wpcss );
1312
            foreach ( $stylesheets as $style ) {
1313
                if ( !wp_style_is( $style, 'queue' ) && !wp_style_is( $style, 'to_do' ) && !wp_style_is( $style, 'done' ) )
1314
                    wp_enqueue_style( $style );
1315
            }
1316
        }
1317
1318
        $this->ui_page = array( $this->action );
1319
        if ( 'add' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
1320
            $this->ui_page[] = 'form';
1321 View Code Duplication
            if ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
1322
                $this->ui_page[] = $this->do;
1323
                $this->save( true );
1324
                $this->manage();
1325
            }
1326
            else
1327
                $this->add();
1328
        }
1329
        elseif ( ( 'edit' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ) {
1330
            $this->ui_page[] = 'form';
1331
            if ( 'save' == $this->do && $this->save && !empty( $_POST ) )
1332
                $this->save();
1333
            $this->edit( ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ? true : false );
1334
        }
1335
        elseif ( 'delete' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== wp_verify_nonce( $this->_nonce, 'pods-ui-action-delete' ) ) {
1336
            $this->delete( $this->id );
1337
            $this->manage();
1338
        }
1339
        elseif ( 'reorder' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
1340
            if ( 'save' == $this->do ) {
1341
                $this->ui_page[] = $this->do;
1342
                $this->reorder();
1343
            }
1344
            $this->manage( true );
1345
        }
1346
        elseif ( 'save' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
1347
            $this->ui_page[] = $this->do;
1348
            $this->save();
1349
            $this->manage();
1350
        }
1351 View Code Duplication
        elseif ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
1352
            $this->ui_page[] = $this->do;
1353
            $this->save( true );
1354
            $this->manage();
1355
        }
1356
        elseif ( 'view' == $this->action && !in_array( $this->action, $this->actions_disabled ) )
1357
            $this->view();
1358
		else {
1359
			if ( isset( $this->actions_custom[ $this->action ] ) ) {
1360
				$more_args = false;
1361
1362
				if ( is_array( $this->actions_custom[ $this->action ] ) && isset( $this->actions_custom[ $this->action ][ 'more_args' ] ) ) {
1363
					$more_args = $this->actions_custom[ $this->action ][ 'more_args' ];
1364
				}
1365
1366
				$row = $this->row;
1367
1368
				if ( empty( $row ) ) {
1369
					$row = $this->get_row();
1370
				}
1371
1372
				if ( $this->restricted( $this->action, $row ) || ( $more_args && ! empty( $more_args[ 'nonce' ] ) && false === wp_verify_nonce( $this->_nonce, 'pods-ui-action-' . $this->action ) ) ) {
1373
					return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1374
				}
1375
				elseif ( $more_args && false !== $this->callback_action( true, $this->action, $this->id, $row ) ) {
1376
					return null;
1377
				}
1378
				elseif ( false !== $this->callback_action( true, $this->action, $this->id ) ) {
1379
					return null;
1380
				}
1381
			}
1382
1383
			if ( !in_array( 'manage', $this->actions_disabled ) ) {
1384
				// handle session / user persistent settings for show_per_page, orderby, search, and filters
1385
				$methods = array( 'session', 'user' );
1386
1387
				// @todo fix this to set ($this) AND save (setting)
1388
				foreach ( $methods as $method ) {
1389
					foreach ( $this->$method as $setting ) {
1390
						if ( 'show_per_page' == $setting )
1391
							$value = $this->limit;
1392
						elseif ( 'orderby' == $setting ) {
1393
							if ( empty( $this->orderby ) )
1394
								$value = '';
1395
							// save this if we have a default index set
1396
							elseif ( isset( $this->orderby[ 'default' ] ) ) {
1397
								$value = $this->orderby[ 'default' ] . ' '
1398
										 . ( false === strpos( $this->orderby[ 'default' ], ' ' ) ? $this->orderby_dir : '' );
1399
							}
1400
							else
1401
								$value = '';
1402
						}
1403
						else
1404
							$value = $this->$setting;
1405
1406
						pods_v_set( $value, $setting, $method );
1407
					}
1408
				}
1409
1410
				$this->manage();
1411
			}
1412
		}
1413
    }
1414
1415
    /**
1416
     * @return mixed
1417
     */
1418
    public function add () {
1419
		if ( false !== $this->callback_action( 'add' ) ) {
1420
			return null;
1421
		}
1422
        ?>
1423
    <div class="wrap pods-ui">
1424
        <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>
1425
        <h2>
1426
            <?php
1427
            echo wp_kses_post( $this->header[ 'add' ] );
1428
1429
			$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1430
1431
			if ( !empty( $this->action_links[ 'manage' ] ) ) {
1432
				$link = $this->action_links[ 'manage' ];
1433
			}
1434
            ?>
1435
            <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
1436
        </h2>
1437
1438
        <?php $this->form( true ); ?>
1439
    </div>
1440
    <?php
1441
    }
1442
1443
    /**
1444
     * @param bool $duplicate
1445
     *
1446
     * @return mixed
1447
     */
1448
    public function edit ( $duplicate = false ) {
1449
        if ( in_array( 'duplicate', $this->actions_disabled ) )
1450
            $duplicate = false;
1451
1452
        if ( empty( $this->row ) )
1453
            $this->get_row();
1454
1455
		if ( $duplicate && false !== $this->callback_action( 'duplicate' ) ) {
1456
			return null;
1457
		}
1458
		elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) {
1459
			return null;
1460
		}
1461
        ?>
1462
    <div class="wrap pods-ui">
1463
        <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>
1464
        <h2>
1465
            <?php
1466
            echo wp_kses_post( $this->do_template( $duplicate ? $this->header[ 'duplicate' ] : $this->header[ 'edit' ] ) );
1467
1468 View Code Duplication
            if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
1469
                $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1470
1471
                if ( !empty( $this->action_links[ 'add' ] ) )
1472
                    $link = $this->action_links[ 'add' ];
1473
                ?>
1474
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading[ 'add' ] ); ?></a>
1475
                <?php
1476
            }
1477
            elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
1478
                $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1479
1480
                if ( !empty( $this->action_links[ 'manage' ] ) )
1481
                    $link = $this->action_links[ 'manage' ];
1482
                ?>
1483
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
1484
                <?php
1485
            }
1486
            ?>
1487
        </h2>
1488
1489
        <?php $this->form( false, $duplicate ); ?>
1490
    </div>
1491
    <?php
1492
    }
1493
1494
    /**
1495
     * @param bool $create
1496
     * @param bool $duplicate
1497
     *
1498
     * @return bool|mixed
1499
     */
1500
    public function form ( $create = false, $duplicate = false ) {
1501
        if ( in_array( 'duplicate', $this->actions_disabled ) )
1502
            $duplicate = false;
1503
1504
		if ( false !== $this->callback( 'form' ) ) {
1505
			return null;
1506
		}
1507
1508
        $label = $this->label[ 'add' ];
1509
        $id = null;
1510
        $vars = array(
1511
            'action' . $this->num => $this->action_after[ 'add' ],
1512
            'do' . $this->num => 'create',
1513
            'id' . $this->num => 'X_ID_X'
1514
        );
1515
1516
        $alt_vars = $vars;
1517
        $alt_vars[ 'action' ] = 'manage';
1518
        unset( $alt_vars[ 'id' ] );
1519
1520
        if ( false === $create ) {
1521
            if ( empty( $this->row ) )
1522
                $this->get_row();
1523
1524
            if ( empty( $this->row ) && ( !is_object( $this->pod ) || 'settings' != $this->pod->pod_data[ 'type' ] ) )
1525
                return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
1526
1527
            if ( $this->restricted( $this->action, $this->row ) )
1528
                return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
1529
1530
            $label = $this->do_template( $this->label[ 'edit' ] );
1531
            $id = $this->row[ $this->sql[ 'field_id' ] ];
1532
            $vars = array(
1533
                'action' . $this->num => $this->action_after[ 'edit' ],
1534
                'do' . $this->num => 'save',
1535
                'id' . $this->num => $id
1536
            );
1537
1538
            $alt_vars = $vars;
1539
            $alt_vars[ 'action' ] = 'manage';
1540
            unset( $alt_vars[ 'id' ] );
1541
1542
            if ( $duplicate ) {
1543
                $label = $this->do_template( $this->label[ 'duplicate' ] );
1544
                $id = null;
1545
                $vars = array(
1546
                    'action' . $this->num => $this->action_after[ 'duplicate' ],
1547
                    'do' . $this->num => 'create',
1548
                    'id' . $this->num => 'X_ID_X'
1549
                );
1550
1551
                $alt_vars = $vars;
1552
                $alt_vars[ 'action' ] = 'manage';
1553
                unset( $alt_vars[ 'id' ] );
1554
            }
1555
        }
1556
1557
		$fields = array();
1558
1559
        if ( isset( $this->fields[ $this->action ] ) )
1560
            $fields = $this->fields[ $this->action ];
1561
1562 View Code Duplication
        if ( is_object( $this->pod ) ) {
1563
            $object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
1564
1565
            if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], array( 'post_type', 'taxonomy', 'media', 'user', 'comment' ) ) )
1566
                $object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data );
1567
1568
            if ( empty( $fields ) ) {
1569
                // Add core object fields if $fields is empty
1570
                $fields = array_merge( $object_fields, $this->pod->fields );
1571
            }
1572
        }
1573
1574
        $form_fields = $fields; // Temporary
1575
1576
        $fields = array();
1577
1578
        foreach ( $form_fields as $k => $field ) {
1579
            $name = $k;
1580
1581
            $defaults = array(
1582
                'name' => $name
1583
            );
1584
1585
            if ( !is_array( $field ) ) {
1586
                $name = $field;
1587
1588
                $field = array(
1589
                    'name' => $name
1590
                );
1591
            }
1592
1593
            $field = array_merge( $defaults, $field );
1594
1595
            $field[ 'name' ] = trim( $field[ 'name' ] );
1596
1597
            $default_value = pods_var_raw( 'default', $field );
1598
            $value = pods_var_raw( 'value', $field );
1599
1600
            if ( empty( $field[ 'name' ] ) )
1601
                $field[ 'name' ] = trim( $name );
1602
1603 View Code Duplication
            if ( isset( $object_fields[ $field[ 'name' ] ] ) )
1604
                $field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
1605
            elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) )
1606
                $field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field );
1607
1608 View Code Duplication
            if ( pods_var_raw( 'hidden', $field, false, null, true ) )
1609
                $field[ 'type' ] = 'hidden';
1610
1611
			$fields[ $field[ 'name' ] ] = $field;
1612
1613 View Code Duplication
            if ( empty( $this->id ) && null !== $default_value ) {
1614
                $this->pod->row_override[ $field[ 'name' ] ] = $default_value;
1615
			}
1616
			elseif ( !empty( $this->id ) && null !== $value ) {
1617
                $this->pod->row[ $field[ 'name' ] ] = $value;
1618
			}
1619
        }
1620
1621
        unset( $form_fields ); // Cleanup
1622
1623
        $fields = $this->do_hook( 'form_fields', $fields, $this->pod );
1624
1625
        $pod =& $this->pod;
1626
        $thank_you = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
1627
        $thank_you_alt = pods_query_arg( $alt_vars, self::$allowed, $this->exclusion() );
1628
        $obj =& $this;
1629
        $singular_label = $this->item;
1630
        $plural_label = $this->items;
1631
1632
        if ( is_object( $this->pod ) && 'settings' == $this->pod->pod_data[ 'type' ] && 'settings' == $this->style )
1633
            pods_view( PODS_DIR . 'ui/admin/form-settings.php', compact( array_keys( get_defined_vars() ) ) );
1634
        else
1635
            pods_view( PODS_DIR . 'ui/admin/form.php', compact( array_keys( get_defined_vars() ) ) );
1636
    }
1637
1638
    /**
1639
     * @return bool|mixed
1640
	 * @since 2.3.10
1641
     */
1642
    public function view () {
1643
1644
		if ( false !== $this->callback_action( 'view' ) ) {
1645
            return null;
1646
		}
1647
1648
        if ( empty( $this->row ) ) {
1649
            $this->get_row();
1650
		}
1651
1652
        if ( empty( $this->row ) ) {
1653
            return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
1654
		}
1655
1656
		$pod =& $this->pod;
1657
		$obj =& $this;
1658
1659
		$fields = array();
1660
1661
		if ( isset( $this->fields[ $this->action ] ) ) {
1662
			$fields = $this->fields[ $this->action ];
1663
		}
1664
1665 View Code Duplication
		if ( is_object( $this->pod ) ) {
1666
			$object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
1667
1668
			$object_field_objects = array(
1669
				'post_type',
1670
				'taxonomy',
1671
				'media',
1672
				'user',
1673
				'comment'
1674
			);
1675
1676
			if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], $object_field_objects ) ) {
1677
				$object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data );
1678
			}
1679
1680
			if ( empty( $fields ) ) {
1681
				// Add core object fields if $fields is empty
1682
				$fields = array_merge( $object_fields, $this->pod->fields );
1683
			}
1684
		}
1685
1686
		$view_fields = $fields; // Temporary
1687
1688
		$fields = array();
1689
1690
		foreach ( $view_fields as $k => $field ) {
1691
			$name = $k;
1692
1693
			$defaults = array(
1694
				'name' => $name,
1695
				'type' => 'text',
1696
				'options' => 'text'
1697
			);
1698
1699
			if ( !is_array( $field ) ) {
1700
				$name = $field;
1701
1702
				$field = array(
1703
					'name' => $name
1704
				);
1705
			}
1706
1707
			$field = array_merge( $defaults, $field );
1708
1709
			$field[ 'name' ] = trim( $field[ 'name' ] );
1710
1711
			$value = pods_var_raw( 'default', $field );
1712
1713
			if ( empty( $field[ 'name' ] ) ) {
1714
				$field[ 'name' ] = trim( $name );
1715
			}
1716
1717 View Code Duplication
			if ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
1718
				$field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
1719
			}
1720
			elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) ) {
1721
				$field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field );
1722
			}
1723
1724 View Code Duplication
			if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' == $field[ 'type' ] ) {
1725
				continue;
1726
			}
1727
			elseif ( !PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
1728
				continue;
1729
			}
1730
1731
			$fields[ $field[ 'name' ] ] = $field;
1732
1733
			if ( empty( $this->id ) && null !== $value ) {
1734
				$this->pod->row_override[ $field[ 'name' ] ] = $value;
1735
			}
1736
		}
1737
1738
		unset( $view_fields ); // Cleanup
1739
		?>
1740
		<div class="wrap pods-ui">
1741
			<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>
1742
			<h2>
1743
				<?php
1744
					echo wp_kses_post( $this->do_template( $this->header[ 'view' ] ) );
1745
1746 View Code Duplication
					if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
1747
						$link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() );
1748
1749
						if ( !empty( $this->action_links[ 'add' ] ) ) {
1750
							$link = $this->action_links[ 'add' ];
1751
						}
1752
				?>
1753
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->heading[ 'add' ] ); ?></a>
1754
				<?php
1755
					}
1756
					elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
1757
						$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
1758
1759
						if ( !empty( $this->action_links[ 'manage' ] ) ) {
1760
							$link = $this->action_links[ 'manage' ];
1761
						}
1762
				?>
1763
					<a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>
1764
				<?php
1765
					}
1766
1767
					pods_view( PODS_DIR . 'ui/admin/view.php', compact( array_keys( get_defined_vars() ) ) );
1768
				?>
1769
1770
			</h2>
1771
		</div>
1772
	<?php
1773
	}
1774
1775
1776
    /**
1777
     * Reorder data
1778
     */
1779
    public function reorder () {
1780
        // loop through order
1781
        $order = (array) pods_var_raw( 'order', 'post', array(), null, true );
1782
1783
        $params = array(
1784
            'pod' => $this->pod->pod,
1785
            'field' => $this->reorder[ 'on' ],
1786
            'order' => $order
1787
        );
1788
1789
        $reorder = pods_api()->reorder_pod_item( $params );
1790
1791
        if ( $reorder )
1792
            $this->message( sprintf( __( "<strong>Success!</strong> %s reordered successfully.", 'pods' ), $this->items ) );
1793
        else
1794
            $this->error( sprintf( __( "<strong>Error:</strong> %s has not been reordered.", 'pods' ), $this->items ) );
1795
    }
1796
1797
    /**
1798
     * @param bool $insert
1799
     *
1800
     * @return mixed
1801
     */
1802
    public function save ( $insert = false ) {
1803
        $this->do_hook( 'pre_save', $insert );
1804
1805
        if ( $this->callback( 'save', $insert ) ) {
1806
			return null;
1807
		}
1808
1809
        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...
1810
        $action = __( 'saved', 'pods' );
1811
        if ( true === $insert )
1812
            $action = __( 'created', 'pods' );
1813
        $field_sql = array();
1814
        $values = array();
1815
        $data = array();
1816
        foreach ( $this->fields[ 'form' ] as $field => $attributes ) {
1817
            $vartype = '%s';
1818
            if ( 'bool' == $attributes[ 'type' ] )
1819
                $selected = ( 1 == pods_var( $field, 'post', 0 ) ) ? 1 : 0;
1820
            elseif ( '' == pods_var( $field, 'post', '' ) )
1821
                continue;
1822
            if ( false === $attributes[ 'display' ] || false !== $attributes[ 'readonly' ] ) {
1823
                if ( !in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) )
1824
                    continue;
1825
                if ( false === $attributes[ 'date_touch' ] && ( false === $attributes[ 'date_touch_on_create' ] || false === $insert || 0 < $this->id ) )
1826
                    continue;
1827
            }
1828
            if ( in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) ) {
1829
                $format = "Y-m-d H:i:s";
1830
                if ( 'date' == $attributes[ 'type' ] )
1831
                    $format = "Y-m-d";
1832
                if ( 'time' == $attributes[ 'type' ] )
1833
                    $format = "H:i:s";
1834
                if ( false !== $attributes[ 'date_touch' ] || ( false !== $attributes[ 'date_touch_on_create' ] && true === $insert && $this->id < 1 ) )
1835
                    $value = date_i18n( $format );
1836
                else
1837
                    $value = date_i18n( $format, strtotime( ( 'time' == $attributes[ 'type' ] ) ? date_i18n( 'Y-m-d ' ) : pods_var( $field, 'post', '' ) ) );
1838
            }
1839
            else {
1840
                if ( 'bool' == $attributes[ 'type' ] ) {
1841
                    $vartype = '%d';
1842
                    $value = 0;
1843
                    if ( '' != pods_var( $field, 'post', '' ) )
1844
                        $value = 1;
1845
                }
1846 View Code Duplication
                elseif ( 'number' == $attributes[ 'type' ] ) {
1847
                    $vartype = '%d';
1848
                    $value = number_format( pods_var( $field, 'post', 0 ), 0, '', '' );
1849
                }
1850 View Code Duplication
                elseif ( 'decimal' == $attributes[ 'type' ] ) {
1851
                    $vartype = '%d';
1852
                    $value = number_format( pods_var( $field, 'post', 0 ), 2, '.', '' );
1853
                }
1854
                elseif ( 'related' == $attributes[ 'type' ] ) {
1855
                    if ( is_array( pods_var( $field, 'post', '' ) ) )
1856
                        $value = implode( ',', pods_var( $field, 'post', '' ) );
1857
                    else
1858
                        $value = pods_var( $field, 'post', '' );
1859
                }
1860
                else
1861
                    $value = pods_var( $field, 'post', '' );
1862
            }
1863
1864 View Code Duplication
            if ( isset( $attributes[ 'custom_save' ] ) && false !== $attributes[ 'custom_save' ] && is_callable( $attributes[ 'custom_save' ] ) )
1865
                $value = call_user_func_array( $attributes[ 'custom_save' ], array( $value, $field, $attributes, &$this ) );
1866
1867
            $field_sql[] = "`$field`=$vartype";
1868
            $values[] = $value;
1869
            $data[ $field ] = $value;
1870
        }
1871
        $field_sql = implode( ',', $field_sql );
1872
        if ( false === $insert && 0 < $this->id ) {
1873
            $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...
1874
            $values[] = $this->id;
1875
            $check = $wpdb->query( $wpdb->prepare( "UPDATE $this->sql['table'] SET $field_sql WHERE id=%d", $values ) );
1876
        }
1877
        else
1878
            $check = $wpdb->query( $wpdb->prepare( "INSERT INTO $this->sql['table'] SET $field_sql", $values ) );
1879
        if ( $check ) {
1880
            if ( 0 == $this->insert_id )
1881
                $this->insert_id = $wpdb->insert_id;
1882
            $this->message( sprintf( __( "<strong>Success!</strong> %s %s successfully.", 'pods' ), $this->item, $action ) );
1883
        }
1884
        else
1885
            $this->error( sprintf( __( "<strong>Error:</strong> %s has not been %s.", 'pods' ), $this->item, $action ) );
1886
        $this->do_hook( 'post_save', $this->insert_id, $data, $insert );
1887
    }
1888
1889
    /**
1890
     * @param null $id
1891
     *
1892
     * @return bool|mixed
1893
     */
1894
    public function delete ( $id = null ) {
1895
        $this->do_hook( 'pre_delete', $id );
1896
1897
		if ( false !== $this->callback_action( 'delete', $id ) ) {
1898
			return null;
1899
		}
1900
1901
        $id = pods_absint( $id );
1902
1903
        if ( empty( $id ) )
1904
            $id = pods_absint( $this->id );
1905
1906
        if ( $id < 1 )
1907
            return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods' ) );
1908
1909
        if ( false === $id )
1910
            $id = $this->id;
1911
1912
        if ( is_object( $this->pod ) )
1913
            $check = $this->pod->delete( $id );
1914 View Code Duplication
        else
1915
            $check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) );
1916
1917
        if ( $check )
1918
            $this->message( sprintf( __( "<strong>Deleted:</strong> %s has been deleted.", 'pods' ), $this->item ) );
1919
        else
1920
            $this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) );
1921
1922
        $this->do_hook( 'post_delete', $id );
1923
    }
1924
1925
    /**
1926
     * Callback for deleting items in bulk
1927
     */
1928
    public function delete_bulk () {
1929
        $this->do_hook( 'pre_delete_bulk' );
1930
1931
        if ( 1 != pods_var( 'deleted_bulk', 'get', 0 ) ) {
1932
            $ids = $this->bulk;
1933
1934
            $success = false;
1935
1936
            if ( !empty( $ids ) ) {
1937
                $ids = (array) $ids;
1938
1939
                foreach ( $ids as $id ) {
1940
                    $id = pods_absint( $id );
1941
1942
                    if ( empty( $id ) )
1943
                        continue;
1944
1945
					if ( $callback = $this->callback( 'delete', $id ) ) {
1946
						$check = $callback;
1947
					}
1948
                    elseif ( is_object( $this->pod ) )
1949
                        $check = $this->pod->delete( $id );
1950 View Code Duplication
                    else
1951
                        $check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) );
1952
1953
                    if ( $check )
1954
                        $success = true;
1955
                }
1956
            }
1957
1958
            if ( $success )
1959
                pods_redirect( pods_query_arg( array( 'action_bulk' => 'delete', 'deleted_bulk' => 1 ), array( 'page', 'lang', 'action', 'id' ) ) );
1960
            else
1961
                $this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) );
1962
        }
1963
        else {
1964
            $this->message( sprintf( __( "<strong>Deleted:</strong> %s have been deleted.", 'pods' ), $this->items ) );
1965
1966
            unset( $_GET[ 'deleted_bulk' ] );
1967
        }
1968
1969
        $this->action_bulk = false;
1970
        unset( $_GET[ 'action_bulk' ] );
1971
1972
        $this->do_hook( 'post_delete_bulk' );
1973
1974
        $this->manage();
1975
    }
1976
1977
	/**
1978
     * Callback for exporting items in bulk
1979
	 */
1980
	public function export_bulk() {
1981
1982
		if ( ! empty( $_POST['bulk_export_type'] ) ) {
1983
			if ( ! empty( $_POST['bulk_export_fields'] ) ) {
1984
				$export_fields = $_POST['bulk_export_fields'];
1985
1986
                $this->fields['export'] = array();
1987
1988
                if ( $this->pod ) {
1989
                    $fields = $this->pod->fields();
1990
1991
                    foreach ( $fields as $field ) {
1992
                        if ( in_array( $field['name'], $export_fields ) ) {
1993
                            $this->fields['export'][] = $field;
1994
                        }
1995
                    }
1996
                }
1997
			}
1998
1999
			// Set up where clause so that export function finds it
2000
            if ( ! empty( $_POST['action_bulk_ids'] ) ) {
2001
                $ids = (array) explode(',', $_POST['action_bulk_ids']);
2002
                $ids = array_map( 'absint', $ids );
2003
                $ids = array_filter( $ids );
2004
2005
                if ( ! empty( $ids ) ) {
2006
                    $ids = implode( ', ', $ids );
2007
2008
                    $this->where = array(
2009
                        'manage' => '`' . pods_sanitize( $this->sql['field_id'] ) . '` IN ( ' . $ids . ' )',
2010
                    );
2011
                }
2012
            }
2013
2014
			$this->export( $_POST['bulk_export_type'] );
2015
2016
			// Cleanup since export function calls get_data before returning
2017
			$this->action_bulk = '';
2018
			$this->where = array();
2019
			$this->data  = false;
2020
			$_GET['action_bulk_ids'] = ''; 
2021
2022
			$this->manage();
2023
		} else {
2024
			$this->export_fields_form();
2025
		}
2026
2027
	}
2028
2029
    /**
2030
     * Select the pods fields to be exported
2031
    */
2032
    public function export_fields_form() {
2033
2034
    ?>
2035
        <div class="wrap pods-admin pods-ui">
2036
            <h2><?php echo __( 'Choose Export Fields', 'pods' ); ?></h2>
2037
2038
            <form method="post" id="pods_admin_ui_export_form">
2039
                <?php
2040
                    // Avoid a bunch of inputs if there's a lot selected
2041
                    if ( ! empty( $_REQUEST['action_bulk_ids'] ) ) {
2042
	                    $_GET['action_bulk_ids'] = implode( ',', (array) $_REQUEST['action_bulk_ids'] );
2043
                    }
2044
2045
                    $this->hidden_vars();
2046
                ?>
2047
2048
                <ul>
2049
                     <?php foreach ( $this->pod->fields() as $field_name => $field ) { ?>
2050
                         <li>
2051
                             <label for="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>">
2052
	                             <input type="checkbox" name="bulk_export_fields[]" id="bulk_export_fields_<?php echo esc_attr( $field['name'] ); ?>" value="<?php echo esc_attr( $field['name'] ); ?>" />
2053
	                             <?php echo esc_html( $field['label'] ); ?>
2054
                             </label>
2055
                         </li>
2056
                     <?php } ?>
2057
                </ul>
2058
2059
	            <p class="submit">
2060
                    <?php _e( 'Export as:', 'pods' ); ?>&nbsp;&nbsp;
2061
	                <?php foreach ( $this->export[ 'formats' ] as $format => $separator ) { ?>
2062
	                    <input type="submit" id="export_type_<?php echo esc_attr( strtoupper( $format ) ); ?>" value=" <?php echo esc_attr( strtoupper( $format ) ); ?> " name="bulk_export_type" class="button-primary" />
2063
	                <?php } ?>
2064
	            </p>
2065
            </form>
2066
        </div>
2067
    <?php
2068
2069
    }
2070
2071
    public function export( $export_type = null ) {
2072
2073
	    if ( empty( $export_type ) ) {
2074
		    $export_type = pods_var( 'export_type', 'get', 'csv' );
2075
	    }
2076
2077
	    $export_type = trim( strtolower( $export_type ) );
2078
2079
        $type = 'sv'; // covers csv + tsv
2080
2081
        if ( in_array( $export_type, array( 'xml', 'json' ) ) )
2082
            $type = $export_type;
2083
2084
        $delimiter = ',';
2085
2086
	    if ( ! empty( $this->export['formats'][ $export_type ] ) ) {
2087
		    $delimiter = $this->export['formats'][ $export_type ];
2088
	    }
2089
2090
        $columns = array(
2091
	        $this->sql['field_id'] => 'ID',
2092
        );
2093
2094
	    if ( empty( $this->fields['export'] ) && $this->pod && ! empty( $this->pod->fields ) ) {
2095
		    $this->fields['export'] = $this->pod->fields;
2096
	    }
2097
2098
	    if ( ! empty( $this->fields['export'] ) ) {
2099
		    foreach ( $this->fields['export'] as $field ) {
2100
			    $columns[ $field['name'] ] = $field['label'];
2101
		    }
2102
	    }
2103
2104
        $params = array(
2105
            'full' => true,
2106
            'flatten' => true,
2107
            'fields' => array_keys( $columns ),
2108
            'type' => $type,
2109
            'delimiter' => $delimiter,
2110
            'columns' => $columns
2111
        );
2112
2113
        $items = $this->get_data( $params );
2114
2115
        $data = array(
2116
            'columns' => $columns,
2117
            'items' => $items,
2118
            'fields' => $this->fields[ 'export' ]
2119
        );
2120
2121
        $migrate = pods_migrate( $type, $delimiter, $data );
2122
2123
        $migrate->export();
2124
2125
        $export_file = $migrate->save();
2126
2127
        $this->message( sprintf( __( '<strong>Success:</strong> Your export is ready, you can download it <a href="%s" target="_blank">here</a>', 'pods' ), $export_file ) );
2128
2129
        //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...
2130
2131
        $this->get_data();
2132
    }
2133
2134
    /**
2135
     * @param $field
2136
     *
2137
     * @return array|bool|mixed|null
2138
     */
2139
    public function get_field ( $field ) {
2140
        $value = null;
2141
2142
        // use PodsData to get field
2143
2144
		if ( $callback = $this->callback( 'get_field', $field ) ) {
2145
			return $callback;
2146
		}
2147
2148
        if ( isset( $this->row[ $field ] ) ) {
2149
            $value = $this->row[ $field ];
2150
		}
2151
        elseif ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2152
            if ( 'Pod' == get_class( $this->pod ) )
2153
                $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...
2154
            else
2155
                $value = $this->pod->field( $field );
2156
        }
2157
2158
        return $this->do_hook( 'get_field', $value, $field );
2159
    }
2160
2161
    /**
2162
     * Get find() params based on current UI action
2163
     *
2164
     * @param null|array $params
2165
     * @param null|string $action
2166
     */
2167
    public function get_params( $params = null, $action = null ) {
2168
2169
        if ( null === $action ) {
2170
            $action = $this->action;
2171
        }
2172
2173
        $defaults = array(
2174
            'full' => false,
2175
            'flatten' => true,
2176
            'fields' => null,
2177
            'type' => ''
2178
        );
2179
2180 View Code Duplication
        if ( !empty( $params ) && is_array( $params ) )
2181
            $params = (object) array_merge( $defaults, $params );
2182
        else
2183
            $params = (object) $defaults;
2184
2185
        if ( !in_array( $action, array( 'manage', 'reorder' ) ) )
2186
            $action = 'manage';
2187
2188
        $params_override = false;
2189
2190
        $orderby = array();
2191
2192
        $limit = $this->limit;
2193
2194
        $sql = null;
2195
2196
	    if ( 'reorder' == $this->action ) {
2197
		    if ( ! empty( $this->reorder[ 'orderby' ] ) ) {
2198
			    $orderby[ $this->reorder[ 'orderby' ] ] = $this->reorder[ 'orderby_dir' ];
2199
		    } else {
2200
			    $orderby[ $this->reorder[ 'on' ] ] = $this->reorder[ 'orderby_dir' ];
2201
		    }
2202
2203
		    if ( ! empty( $this->reorder[ 'limit' ] ) ) {
2204
			    $limit = $this->reorder[ 'limit' ];
2205
		    }
2206
2207
		    if ( ! empty( $this->reorder[ 'sql' ] ) ) {
2208
			    $sql = $this->reorder[ 'sql' ];
2209
		    }
2210
	    }
2211
2212
        if ( !empty( $this->orderby ) ) {
2213
            $this->orderby = (array) $this->orderby;
2214
2215
            foreach ( $this->orderby as $order ) {
2216
                if ( false !== strpos( $order, ' ' ) ) {
2217
                    $orderby[] = $order;
2218
                }
2219
                elseif ( !isset( $orderby[ $order ] ) ) {
2220
                    $orderby[ $order ] = $this->orderby_dir;
2221
                }
2222
            }
2223
        }
2224
2225
        if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2226
            $find_params = array(
2227
                'where' => pods_v( $action, $this->where, null, true ),
2228
                'orderby' => $orderby,
2229
                'page' => (int) $this->page,
2230
                'pagination' => true,
2231
                'limit' => (int) $limit,
2232
                'search' => $this->searchable,
2233
                'search_query' => $this->search,
2234
                'search_across' => $this->search_across,
2235
                'search_across_picks' => $this->search_across_picks,
2236
                'filters' => $this->filters,
2237
                'sql' => $sql
2238
            );
2239
2240
            $params_override = true;
2241
        }
2242
        else {
2243
            $find_params = array(
2244
                'table' => $this->sql[ 'table' ],
2245
                'id' => $this->sql[ 'field_id' ],
2246
                'index' => $this->sql[ 'field_index' ],
2247
                'where' => pods_v( $action, $this->where, null, true ),
2248
                'orderby' => $orderby,
2249
                'page' => (int) $this->page,
2250
                'pagination' => true,
2251
                'limit' => (int) $limit,
2252
                'search' => $this->searchable,
2253
                'search_query' => $this->search,
2254
                'fields' => $this->fields[ 'search' ],
2255
                'sql' => $sql
2256
            );
2257
2258
		if ( ! empty( $this->sql['select'] ) ) {
2259
			$find_params['select'] = $this->sql['select'];
2260
		}
2261
        }
2262
2263
        if ( empty( $find_params[ 'where' ] ) && $this->restricted( $this->action ) )
2264
            $find_params[ 'where' ] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
2265
2266
        if ( $params_override ) {
2267
            $find_params = array_merge( $find_params, (array) $this->params );
2268
        }
2269
2270
        if ( $params->full )
2271
            $find_params[ 'limit' ] = -1;
2272
            
2273
        $find_params = apply_filters('pods_ui_get_params', $find_params, $this->pod->pod, $this);
2274
2275
		/**
2276
		 * Filter Pods::find() parameters to make it more easily extended by plugins and developers.
2277
		 *
2278
		 * @param array  $find_params Parameters used with Pods::find()
2279
		 * @param string $action      Current action
2280
		 * @param PodsUI $this        PodsUI instance
2281
		 *
2282
		 * @since 2.6.8
2283
		 */
2284
		$find_params = apply_filters( 'pods_ui_get_find_params', $find_params, $action, $this );
2285
2286
        // Debug purposes
2287 View Code Duplication
        if ( 1 == pods_v( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) )
2288
            pods_debug( $find_params );
2289
2290
        return $find_params;
2291
    }
2292
2293
    /**
2294
     * @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...
2295
     *
2296
     * @return bool
2297
     */
2298
    public function get_data ( $params = null ) {
2299
        $action = $this->action;
2300
2301
        $defaults = array(
2302
            'full' => false,
2303
            'flatten' => true,
2304
            'fields' => null,
2305
            'type' => ''
2306
        );
2307
2308 View Code Duplication
        if ( !empty( $params ) && is_array( $params ) )
2309
            $params = (object) array_merge( $defaults, $params );
2310
        else
2311
            $params = (object) $defaults;
2312
2313
        if ( !in_array( $action, array( 'manage', 'reorder' ) ) )
2314
            $action = 'manage';
2315
2316
        $find_params = $this->get_params( $params, $action );
2317
2318
        if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
2319
            $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...
2320
2321
            if ( !$params->full ) {
2322
                $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...
2323
2324
                $this->data = $data;
2325
2326
                if ( !empty( $this->data ) ) {
2327
                    $this->data_keys = array_keys( $this->data );
2328
                }
2329
2330
                $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...
2331
                $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...
2332
            }
2333
            else {
2334
                $this->data_full = array();
2335
2336
                $export_params = array(
2337
                    'fields' => $params->fields,
2338
                    'flatten' => true
2339
                );
2340
2341
                if ( in_array( $params->type, array( 'json', 'xml' ) ) )
2342
                    $export_params[ 'flatten' ] = false;
2343
2344
                $export_params = $this->do_hook( 'export_options', $export_params, $params );
2345
2346
                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...
2347
                    $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...
2348
                }
2349
2350
                $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...
2351
2352
                return $this->data_full;
2353
            }
2354
        }
2355
        else {
2356
            if ( !empty( $this->data ) )
2357
                return $this->data;
2358
2359
            if ( empty( $this->sql[ 'table' ] ) )
2360
                return $this->data;
2361
2362
            $this->pods_data->select( $find_params );
2363
2364
            if ( !$params->full ) {
2365
                $this->data = $this->pods_data->data;
2366
2367
                if ( !empty( $this->data ) ) {
2368
					$this->data_keys = array_keys( $this->data );
2369
				}
2370
2371
                $this->total = $this->pods_data->total();
2372
                $this->total_found = $this->pods_data->total_found();
2373
            }
2374
            else {
2375
                $this->data_full = $this->pods_data->data;
2376
2377
                if ( !empty( $this->data_full ) ) {
2378
					$this->data_keys = array_keys( $this->data_full );
2379
				}
2380
2381
                return $this->data_full;
2382
            }
2383
        }
2384
2385
        return $this->data;
2386
    }
2387
2388
    /**
2389
     * Sort out data alphabetically by a key
2390
     */
2391
    public function sort_data () {
2392
        // only do this if we have a default orderby
2393
        if ( isset( $this->orderby[ 'default' ] ) ) {
2394
            $orderby = $this->orderby[ 'default' ];
2395
            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...
2396
                $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...
2397
            }
2398
            if ( $this->orderby_dir == 'ASC' )
2399
                asort( $sorter );
2400
            else
2401
                arsort( $sorter );
2402
            foreach ( $sorter as $key => $val ) {
2403
                $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...
2404
            }
2405
            if ( isset( $intermediary ) ) {
2406
                $this->data = $intermediary;
2407
                $this->data_keys = array_keys( $this->data );
2408
            }
2409
        }
2410
    }
2411
2412
    /**
2413
     * @return array
2414
     */
2415
    public function get_row ( &$counter = 0, $method = null ) {
2416
        if ( !empty( $this->row ) && 0 < (int) $this->id && 'table' != $method )
2417
            return $this->row;
2418
2419
        if ( is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) )
2420
            $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...
2421
        else {
2422
            $this->row = false;
2423
2424
            if ( !empty( $this->data ) ) {
2425
                if ( empty( $this->data_keys ) || count( $this->data ) != count( $this->data_keys ) ) {
2426
                    $this->data_keys = array_keys( $this->data );
2427
				}
2428
2429
                if ( count( $this->data ) == $this->total && isset( $this->data_keys[ $counter ] ) && isset( $this->data[ $this->data_keys[ $counter ] ] ) ) {
2430
                    $this->row = $this->data[ $this->data_keys[ $counter ] ];
2431
2432
                    $counter++;
2433
                }
2434
            }
2435
2436
            if ( false === $this->row && 0 < (int) $this->id && !empty( $this->sql[ 'table' ] ) ) {
2437
                $this->pods_data->select(
2438
                    array(
2439
                        'table' => $this->sql[ 'table' ],
2440
                        'where' => '`' . pods_sanitize( $this->sql['field_id'] ) . '` = ' . (int) $this->id,
2441
                        'limit' => 1
2442
                    )
2443
                );
2444
2445
                $this->row = $this->pods_data->fetch();
2446
            }
2447
        }
2448
2449
        return $this->row;
2450
    }
2451
2452
    /**
2453
     * @param bool $reorder
2454
     *
2455
     * @return mixed|null
2456
     */
2457
    public function manage ( $reorder = false ) {
2458
		if ( false !== $this->callback_action( 'manage', $reorder ) ) {
2459
			return null;
2460
		}
2461
2462
        if ( !empty( $this->action_bulk ) && !empty( $this->actions_bulk ) && isset( $this->actions_bulk[ $this->action_bulk ] ) && !in_array( $this->action_bulk, $this->actions_disabled ) && ( ! empty( $this->bulk ) || 'export' == $this->action_bulk ) ) {
2463
	        if ( empty( $_REQUEST[ '_wpnonce' . $this->num ] ) || false === wp_verify_nonce( $_REQUEST[ '_wpnonce' . $this->num ], 'pods-ui-action-bulk' ) ) {
2464
		        pods_message( __( 'Invalid bulk request, please try again.', 'pods' ) );
2465
	        }
2466
	        elseif ( false !== $this->callback_bulk( $this->action_bulk, $this->bulk ) ) {
2467
				return null;
2468
			}
2469
            elseif ( 'delete' == $this->action_bulk ) {
2470
                $this->delete_bulk();
2471
2472
                return;
2473
			}
2474
            elseif ( 'export' == $this->action_bulk ) {
2475
                $this->export_bulk();
2476
2477
                return;
2478
			}
2479
        }
2480
2481
        $this->screen_meta();
2482
2483
        if ( true === $reorder )
2484
            wp_enqueue_script( 'jquery-ui-sortable' );
2485
        ?>
2486
    <div class="wrap pods-admin pods-ui">
2487
        <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>
2488
        <h2>
2489
            <?php
2490
            if ( true === $reorder ) {
2491
                echo wp_kses_post( $this->header[ 'reorder' ] );
2492
2493
				$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
2494
2495
                if ( !empty( $this->action_links[ 'manage' ] ) )
2496
                    $link = $this->action_links[ 'manage' ];
2497
                ?>
2498
                <small>(<a href="<?php echo esc_url( $link ); ?>">&laquo; <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>)</small>
2499
                <?php
2500
            }
2501
            else
2502
                echo wp_kses_post( $this->header[ 'manage' ] );
2503
2504
            if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
2505
                $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num => '' ), self::$allowed, $this->exclusion() );
2506
2507
                if ( !empty( $this->action_links[ 'add' ] ) )
2508
                    $link = $this->action_links[ 'add' ];
2509
                ?>
2510
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label[ 'add_new' ] ); ?></a>
2511
                <?php
2512
            }
2513
            if ( !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) {
2514
                $link = pods_query_arg( array( 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() );
2515
2516
                if ( !empty( $this->action_links[ 'reorder' ] ) )
2517
                    $link = $this->action_links[ 'reorder' ];
2518
                ?>
2519
                <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo wp_kses_post( $this->label[ 'reorder' ] ); ?></a>
2520
                <?php
2521
            }
2522
            ?>
2523
        </h2>
2524
2525
		<form id="posts-filter" action="" method="get">
2526
        	<?php
2527
                $excluded_filters = array(
2528
                    'search' . $this->num,
2529
                    'pg' . $this->num,
2530
                    'action' . $this->num,
2531
                    'action_bulk' . $this->num,
2532
                    'action_bulk_ids' . $this->num,
2533
	                '_wpnonce' . $this->num
2534
                );
2535
2536
                $filters = $this->filters;
2537
2538
                foreach ( $filters as $k => $filter ) {
2539 View Code Duplication
					if ( isset( $this->pod->fields[ $filter ] ) ) {
2540
						$filter_field = $this->pod->fields[ $filter ];
2541
					}
2542
					elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2543
						$filter_field = $this->fields[ 'manage' ][ $filter ];
2544
					}
2545
					else {
2546
						unset( $filters[ $k ] );
2547
						continue;
2548
					}
2549
2550 View Code Duplication
                    if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2551
                        if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) {
2552
                            unset( $filters[ $k ] );
2553
                            continue;
2554
                        }
2555
                    }
2556
                    elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) {
2557
                        unset( $filters[ $k ] );
2558
                        continue;
2559
                    }
2560
2561
                    $excluded_filters[] = 'filter_' . $filter . '_start';
2562
                    $excluded_filters[] = 'filter_' . $filter . '_end';
2563
                    $excluded_filters[] = 'filter_' . $filter;
2564
                }
2565
2566
                $get = $_GET;
2567
2568 View Code Duplication
                foreach ( $get as $k => $v ) {
2569
                    if ( is_array( $v ) || in_array( $k, $excluded_filters ) || strlen( $v ) < 1 )
2570
                        continue;
2571
			?>
2572
				<input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
2573
			<?php
2574
                }
2575
2576
			if ( false !== $this->callback( 'header', $reorder ) ) {
2577
				return null;
2578
			}
2579
2580
            if ( false === $this->data )
2581
                $this->get_data();
2582
            elseif ( $this->sortable ) // we have the data already as an array
2583
                $this->sort_data();
2584
2585
            if ( !in_array( 'export', $this->actions_disabled ) && 'export' == $this->action )
2586
                $this->export();
2587
2588
            if ( ( !empty( $this->data ) || false !== $this->search || ( $this->filters_enhanced && !empty( $this->views ) ) ) && ( ( $this->filters_enhanced && !empty( $this->views ) ) || false !== $this->searchable ) ) {
2589
                if ( $this->filters_enhanced )
2590
                    $this->filters();
2591
                else {
2592
                ?>
2593
                <p class="search-box" align="right">
2594
                    <?php
2595
                    $excluded_filters = array( 'search' . $this->num, 'pg' . $this->num );
2596
2597
                    foreach ( $this->filters as $filter ) {
2598
                        $excluded_filters[] = 'filter_' . $filter . '_start';
2599
                        $excluded_filters[] = 'filter_' . $filter . '_end';
2600
                        $excluded_filters[] = 'filter_' . $filter;
2601
                    }
2602
2603
                    $this->hidden_vars( $excluded_filters );
2604
2605
                    foreach ( $this->filters as $filter ) {
2606 View Code Duplication
						if ( isset( $this->pod->fields[ $filter ] ) ) {
2607
							$filter_field = $this->pod->fields[ $filter ];
2608
						}
2609
						elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2610
							$filter_field = $this->fields[ 'manage' ][ $filter ];
2611
						}
2612
						else {
2613
							continue;
2614
						}
2615
2616
                        if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2617
                            $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
2618
                            $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
2619
2620
                            // override default value
2621
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2622
                            $filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1;
2623
2624
2625 View Code Duplication
                            if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
2626
                                $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
2627
2628 View Code Duplication
                            if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
2629
                                $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
2630
                    ?>
2631
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
2632
                            <?php echo esc_html( $filter_field[ 'label' ] ); ?>
2633
                        </label>
2634
                        <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
2635
2636
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">
2637
                            to
2638
                        </label>
2639
                    <?php
2640
                            echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field );
2641
                        }
2642
                        elseif ( 'pick' == $filter_field[ 'type' ] ) {
2643
                            $value = pods_var_raw( 'filter_' . $filter, 'get' );
2644
2645
                            if ( strlen( $value ) < 1 )
2646
                                $value = pods_var_raw( 'filter_default', $filter_field );
2647
2648
                            // override default value
2649
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2650
2651
                            $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
2652
                            $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
2653
2654
                            $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 );
2655
                            $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
2656
2657
                            $options = array_merge( $filter_field, $filter_field[ 'options' ] );
2658
                    ?>
2659
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
2660
                            <?php echo esc_html( $filter_field[ 'label' ] ); ?>
2661
                        </label>
2662
                    <?php
2663
                            echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
2664
                        }
2665
                        elseif ( 'boolean' == $filter_field[ 'type' ] ) {
2666
                            $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
2667
2668
                            if ( strlen( $value ) < 1 )
2669
                                $value = pods_var_raw( 'filter_default', $filter_field );
2670
2671
                            // override default value
2672
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2673
2674
                            $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
2675
                            $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
2676
2677
                            $filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple';
2678
                            $filter_field[ 'options' ][ 'pick_custom' ] = array(
2679
                                '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
2680
                                '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
2681
                            );
2682
2683
                            $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 );
2684
                            $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
2685
2686
                            $options = array_merge( $filter_field, $filter_field[ 'options' ] );
2687
                    ?>
2688
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
2689
                            <?php echo esc_html( $filter_field[ 'label' ] ); ?>
2690
                        </label>
2691
                    <?php
2692
                            echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
2693
                        }
2694
                        else {
2695
                            $value = pods_var_raw( 'filter_' . $filter, 'get' );
2696
2697
                            if ( strlen( $value ) < 1 )
2698
                                $value = pods_var_raw( 'filter_default', $filter_field );
2699
2700
                            // override default value
2701
                            $filter_field[ 'options' ][ 'default_value' ] = '';
2702
2703
                            $options = array();
2704
                            $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 );
2705
                            $options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $options, $options[ 'input_helper' ], null, true );
2706
                    ?>
2707
                        <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
2708
                            <?php echo esc_html( $filter_field[ 'label' ] ); ?>
2709
                        </label>
2710
                    <?php
2711
                            echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options );
2712
                        }
2713
                    }
2714
2715
					if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
2716
					?>
2717
						&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>
2718
						<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
2719
					<?php
2720
					}
2721
					else {
2722
						echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
2723
					}
2724
                    ?>
2725
                    <?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?>
2726
                    <?php
2727
                    if ( 0 < strlen( $this->search ) ) {
2728
                        $clear_filters = array(
2729
							'search' . $this->num => false
2730
						);
2731
2732 View Code Duplication
                        foreach ( $this->filters as $filter ) {
2733
                            $clear_filters[ 'filter_' . $filter . '_start' ] = false;
2734
                            $clear_filters[ 'filter_' . $filter . '_end' ] = false;
2735
                            $clear_filters[ 'filter_' . $filter ] = false;
2736
                        }
2737
                        ?>
2738
                        <br class="clear" />
2739
                        <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>
2740
                        <br class="clear" />
2741
                        <?php
2742
                    }
2743
                    ?>
2744
                </p>
2745
                <?php
2746
            }
2747
            }
2748
            else {
2749
                ?>
2750
                <br class="clear" />
2751
                <?php
2752
            }
2753
2754
            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 ) ) {
2755
                ?>
2756
                <div class="tablenav">
2757
                    <?php
2758
                    if ( !empty( $this->data ) && !empty( $this->actions_bulk ) ) {
2759
                ?>
2760
                    <div class="alignleft actions">
2761
	                    <?php wp_nonce_field( 'pods-ui-action-bulk', '_wpnonce' . $this->num, false ); ?>
2762
2763
                        <select name="action_bulk<?php echo esc_attr( $this->num ); ?>">
2764
                            <option value="-1" selected="selected"><?php _e( 'Bulk Actions', 'pods' ); ?></option>
2765
2766
                            <?php
2767
                                foreach ( $this->actions_bulk as $action => $action_data ) {
2768
                                    if ( in_array( $action, $this->actions_hidden ) || in_array( $action, $this->actions_hidden ) )
2769
                                        continue;
2770
2771 View Code Duplication
                                    if ( !isset( $action_data[ 'label' ] ) )
2772
                                        $action_data[ 'label' ] = ucwords( str_replace( '_', ' ', $action ) );
2773
                            ?>
2774
                                <option value="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $action_data[ 'label' ] ); ?></option>
2775
                            <?php
2776
                                }
2777
                            ?>
2778
                        </select>
2779
2780
                        <input type="submit" id="doaction_bulk<?php echo esc_attr( $this->num ); ?>" class="button-secondary action" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
2781
                    </div>
2782
                <?php
2783
                    }
2784
2785 View Code Duplication
                    if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
2786
                        ?>
2787
                        <div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
2788
                            <?php $this->pagination( 1 ); ?>
2789
                        </div>
2790
                        <?php
2791
                    }
2792
2793
                    if ( true === $reorder ) {
2794
						$link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() );
2795
2796
						if ( !empty( $this->action_links[ 'manage' ] ) ) {
2797
							$link = $this->action_links[ 'manage' ];
2798
						}
2799
                        ?>
2800
                        <input type="button" value="<?php esc_attr_e( 'Update Order', 'pods' ); ?>" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" />
2801
                        <input type="button" value="<?php esc_attr_e( 'Cancel', 'pods' ); ?>" class="button" onclick="document.location='<?php echo esc_js( $link ); ?>';" />
2802
                    </form>
2803
				<?php
2804
                    }
2805
                    elseif ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) {
2806
                        ?>
2807
                        <div class="alignleft actions">
2808
                            <input type="button" value="<?php echo esc_attr( sprintf( __( 'Export all %s', 'pods' ), $this->items ) ); ?>" class="button" onclick="document.location='<?php echo pods_slash( pods_query_arg( array( 'action_bulk' . $this->num => 'export', '_wpnonce' => wp_create_nonce( 'pods-ui-action-bulk' ) ), self::$allowed, $this->exclusion() ) ); ?>';" />
2809
                        </div>
2810
                        <?php
2811
                    }
2812
                    ?>
2813
                    <br class="clear" />
2814
                </div>
2815
                <?php
2816
            }
2817
            else {
2818
                ?>
2819
                <br class="clear" />
2820
                <?php
2821
            }
2822
            ?>
2823
            <div class="clear"></div>
2824
            <?php
2825
            if ( empty( $this->data ) && false !== $this->default_none && false === $this->search ) {
2826
                ?>
2827
                <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...
2828
                <?php
2829
            }
2830
            else
2831
                $this->table( $reorder );
2832 View Code Duplication
            if ( !empty( $this->data ) ) {
2833
                if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
2834
                    ?>
2835
                    <div class="tablenav">
2836
                        <div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>">
2837
                            <?php $this->pagination( 0 ); ?>
2838
                            <br class="clear" />
2839
                        </div>
2840
                    </div>
2841
                    <?php
2842
                }
2843
            }
2844
2845
            ?>
2846
        </form>
2847
    </div>
2848
    <?php
2849
        if ( $this->filters_enhanced )
2850
            $this->filters_popup();
2851
    }
2852
2853
    public function filters () {
2854
		include_once ABSPATH . 'wp-admin/includes/template.php';
2855
2856
        wp_enqueue_script( 'thickbox' );
2857
        wp_enqueue_style( 'pods-ui-list-table', PODS_URL . 'ui/css/pods-ui-list-table.css', array( 'thickbox' ), PODS_VERSION );
2858
2859
        $filters = $this->filters;
2860
2861
        foreach ( $filters as $k => $filter ) {
2862 View Code Duplication
			if ( isset( $this->pod->fields[ $filter ] ) ) {
2863
				$filter_field = $this->pod->fields[ $filter ];
2864
			}
2865
			elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2866
				$filter_field = $this->fields[ 'manage' ][ $filter ];
2867
			}
2868
			else {
2869
				continue;
2870
			}
2871
2872 View Code Duplication
            if ( isset( $filter_field ) && in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2873
                if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) )
2874
                    unset( $filters[ $k ] );
2875
            }
2876
            elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) )
2877
                unset( $filters[ $k ] );
2878
        }
2879
2880
        $filtered = false;
2881
2882
        if ( !empty( $filters ) )
2883
            $filtered = true;
2884
?>
2885
    <div class="pods-ui-filter-bar">
2886
        <div class="pods-ui-filter-bar-primary">
2887
            <?php
2888
                if ( !empty( $this->views ) ) {
2889
            ?>
2890
                <ul class="subsubsub">
2891
                    <li class="pods-ui-filter-view-label"><strong><?php echo wp_kses_post( $this->heading[ 'views' ] ); ?></strong></li>
2892
2893
                    <?php
2894
                        foreach ( $this->views as $view => $label ) {
2895
                            if ( false === strpos( $label, '<a' ) ) {
2896
                                $link = pods_query_arg( array( 'view' . $this->num => $view, 'pg' . $this->num => '' ), self::$allowed, $this->exclusion() );
2897
2898
                                if ( $this->view == $view )
2899
                                    $label = '<a href="' . esc_url( $link ) . '" class="current">' . esc_html( $label ) . '</a>';
2900
                                else
2901
                                    $label = '<a href="' . esc_url( $link ) . '">' . esc_html( $label ) . '</a>';
2902
                            }
2903
                    ?>
2904
                        <li class="<?php echo esc_attr( $view ); ?>"><?php echo esc_html( $label ); ?></li>
2905
                    <?php
2906
                        }
2907
                    ?>
2908
                </ul>
2909
            <?php
2910
                }
2911
            ?>
2912
2913
            <?php
2914
                if ( false !== $this->search && false !== $this->searchable ) {
2915
            ?>
2916
                <p class="search-box">
2917
                    <?php
2918
                        if ( $filtered || '' != pods_var_raw( 'search' . $this->num, 'get', '', null, true ) ) {
2919
                            $clear_filters = array(
2920
								'search' . $this->num => false
2921
							);
2922
2923 View Code Duplication
                            foreach ( $this->filters as $filter ) {
2924
                                $clear_filters[ 'filter_' . $filter . '_start' ] = false;
2925
                                $clear_filters[ 'filter_' . $filter . '_end' ] = false;
2926
                                $clear_filters[ 'filter_' . $filter ] = false;
2927
                            }
2928
                    ?>
2929
                        <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>
2930
                    <?php
2931
                        }
2932
2933
						if ( false !== $this->do_hook( 'filters_show_search', true ) ) {
2934
					?>
2935
						&nbsp;&nbsp; <label class="screen-reader-text" for="page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
2936
						<?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?>
2937
					<?php
2938
						}
2939
						else {
2940
							echo PodsForm::field( 'search' . $this->num, '', 'hidden' );
2941
						}
2942
					?>
2943
2944
                    <?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?>
2945
                </p>
2946
            <?php
2947
                }
2948
            ?>
2949
        </div>
2950
2951
        <?php
2952
            if ( !empty( $this->filters ) ) {
2953
        ?>
2954
            <div class="pods-ui-filter-bar-secondary">
2955
                <ul class="subsubsub">
2956
                    <?php
2957
                        if ( !$filtered ) {
2958
                    ?>
2959
                        <li class="pods-ui-filter-bar-add-filter">
2960
                            <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
2961
                                <?php _e( 'Advanced Filters', 'pods' ); ?>
2962
                            </a>
2963
                        </li>
2964
                    <?php
2965
                        }
2966
                        else {
2967
                    ?>
2968
                        <li class="pods-ui-filter-bar-add-filter">
2969
                            <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
2970
                                + <?php _e( 'Add Filter', 'pods' ); ?>
2971
                            </a>
2972
                        </li>
2973
                    <?php
2974
                        }
2975
2976
                        foreach ( $filters as $filter ) {
2977
                            $value = pods_var_raw( 'filter_' . $filter, 'get' );
2978
2979 View Code Duplication
							if ( isset( $this->pod->fields[ $filter ] ) ) {
2980
								$filter_field = $this->pod->fields[ $filter ];
2981
							}
2982
							elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
2983
								$filter_field = $this->fields[ 'manage' ][ $filter ];
2984
							}
2985
							else {
2986
								continue;
2987
							}
2988
2989
                            $data_filter = 'filter_' . $filter;
2990
2991
                            $start = $end = $value_label = '';
2992
2993
                            if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
2994
                                $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true );
2995
                                $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true );
2996
2997 View Code Duplication
                                if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
2998
                                    $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
2999
3000 View Code Duplication
                                if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
3001
                                    $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
3002
3003
                                $value = trim( $start . ' - ' . $end, ' -' );
3004
3005
                                $data_filter = 'filter_' . $filter . '_start';
3006
                            }
3007
                            elseif ( 'pick' == $filter_field[ 'type' ] )
3008
                                $value_label = trim( PodsForm::field_method( 'pick', 'value_to_label', $filter, $value, $filter_field, $this->pod->pod_data, null ) );
3009
                            elseif ( 'boolean' == $filter_field[ 'type' ] ) {
3010
                                $yesno_options = array(
3011
                                    '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
3012
                                    '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
3013
                                );
3014
3015
                                if ( isset( $yesno_options[ (string) $value ] ) )
3016
                                    $value_label = $yesno_options[ (string) $value ];
3017
                            }
3018
3019
                            if ( strlen( $value_label ) < 1 )
3020
                                $value_label = $value;
3021
                    ?>
3022
                        <li class="pods-ui-filter-bar-filter" data-filter="<?php echo esc_attr( $data_filter ); ?>">
3023
                            <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
3024
                                <strong><?php echo esc_html( $filter_field[ 'label' ] ); ?>:</strong>
3025
                                <?php echo esc_html( $value_label ); ?>
3026
                            </a>
3027
3028
                            <a href="#remove-filter" class="remove-filter" title="<?php esc_attr_e( 'Remove Filter', 'pods' ); ?>">x</a>
3029
3030
                            <?php
3031
                                if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
3032
                                    echo PodsForm::field( 'filter_' . $filter . '_start', $start, 'hidden' );
3033
                                    echo PodsForm::field( 'filter_' . $filter . '_end', $end, 'hidden' );
3034
                                }
3035
                                else
3036
                                    echo PodsForm::field( $data_filter, $value, 'hidden' );
3037
                            ?>
3038
                        </li>
3039
                    <?php
3040
                        }
3041
                    ?>
3042
                </ul>
3043
            </div>
3044
        <?php
3045
            }
3046
        ?>
3047
    </div>
3048
3049
    <script type="text/javascript">
3050
        jQuery( function() {
3051
            jQuery( '.pods-ui-filter-bar-secondary' ).on( 'click', '.remove-filter', function ( e ) {
3052
                jQuery( '.pods-ui-filter-popup #' + jQuery( this ).parent().data( 'filter' ) ).remove();
3053
3054
                jQuery( this ).parent().find( 'input' ).each( function () {
3055
                    jQuery( this ).remove();
3056
                } );
3057
3058
                jQuery( 'form#posts-filter [name="pg<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3059
                jQuery( 'form#posts-filter [name="action<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3060
                jQuery( 'form#posts-filter [name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3061
	            jQuery( 'form#posts-filter [name="_wpnonce<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true );
3062
3063
                jQuery( 'form#posts-filter' ).submit();
3064
3065
                e.preventDefault();
3066
            } );
3067
        } );
3068
    </script>
3069
<?php
3070
    }
3071
3072
    public function filters_popup () {
3073
        $filters = $this->filters;
3074
?>
3075
    <div id="pods-ui-posts-filter-popup" class="hidden">
3076
        <form action="" method="get" class="pods-ui-posts-filter-popup">
3077
            <h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
3078
3079
            <div class="pods-ui-posts-filters">
3080
                <?php
3081
                    $excluded_filters = array(
3082
                        'search' . $this->num,
3083
                        'pg' . $this->num,
3084
                        'action' . $this->num,
3085
                        'action_bulk' . $this->num,
3086
                        'action_bulk_ids' . $this->num,
3087
                        '_wpnonce' . $this->num
3088
                    );
3089
3090
                    foreach ( $filters as $filter ) {
3091
                        $excluded_filters[] = 'filters_relation';
3092
                        $excluded_filters[] = 'filters_compare_' . $filter;
3093
                        $excluded_filters[] = 'filter_' . $filter . '_start';
3094
                        $excluded_filters[] = 'filter_' . $filter . '_end';
3095
                        $excluded_filters[] = 'filter_' . $filter;
3096
                    }
3097
3098
                    $get = $_GET;
3099
3100 View Code Duplication
                    foreach ( $get as $k => $v ) {
3101
                        if ( in_array( $k, $excluded_filters ) || strlen( $v ) < 1 )
3102
                            continue;
3103
                ?>
3104
                    <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
3105
                <?php
3106
                    }
3107
3108
                    $zebra = true;
3109
3110
                    foreach ( $filters as $filter ) {
3111
                        if ( empty( $filter ) )
3112
                            continue;
3113
3114 View Code Duplication
						if ( isset( $this->pod->fields[ $filter ] ) ) {
3115
							$filter_field = $this->pod->fields[ $filter ];
3116
						}
3117
						elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) {
3118
							$filter_field = $this->fields[ 'manage' ][ $filter ];
3119
						}
3120
						else {
3121
							continue;
3122
						}
3123
                ?>
3124
                    <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-<?php echo esc_attr( $filter . ( $zebra ? ' clear' : '' ) ); ?>">
3125
                        <?php
3126
                            if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
3127
                                $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true );
3128
                                $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true );
3129
3130
                                // override default value
3131
                                $filter_field[ 'options' ][ 'default_value' ] = '';
3132
                                $filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1;
3133
3134 View Code Duplication
                                if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
3135
                                    $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' );
3136
3137 View Code Duplication
                                if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
3138
                                    $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' );
3139
                        ?>
3140
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? '' : ' hidden' ); ?>">+</span>
3141
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3142
3143
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start">
3144
                                <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3145
                            </label>
3146
3147
                            <span class="pods-ui-posts-filter<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>">
3148
                                <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?>
3149
3150
                                <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">to</label>
3151
                                <?php echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field ); ?>
3152
                            </span>
3153
                        <?php
3154
                            }
3155
                            elseif ( 'pick' == $filter_field[ 'type' ] ) {
3156
                                $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3157
3158
                                if ( strlen( $value ) < 1 )
3159
                                    $value = pods_var_raw( 'filter_default', $filter_field );
3160
3161
                                // override default value
3162
                                $filter_field[ 'options' ][ 'default_value' ] = '';
3163
3164
                                $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
3165
                                $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
3166
3167
                                $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 );
3168
                                $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
3169
3170
                                $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3171
                        ?>
3172
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3173
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3174
3175
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3176
                                <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3177
                            </label>
3178
3179
                            <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
3180
                                <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3181
                            </span>
3182
                        <?php
3183
                            }
3184
                            elseif ( 'boolean' == $filter_field[ 'type' ] ) {
3185
                                $value = pods_var_raw( 'filter_' . $filter, 'get', '' );
3186
3187
                                if ( strlen( $value ) < 1 )
3188
                                    $value = pods_var_raw( 'filter_default', $filter_field );
3189
3190
                                // override default value
3191
                                $filter_field[ 'options' ][ 'default_value' ] = '';
3192
3193
                                $filter_field[ 'options' ][ 'pick_format_type' ] = 'single';
3194
                                $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown';
3195
3196
                                $filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple';
3197
                                $filter_field[ 'options' ][ 'pick_custom' ] = array(
3198
                                    '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),
3199
                                    '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true )
3200
                                );
3201
3202
                                $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 );
3203
                                $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true );
3204
3205
                                $options = array_merge( $filter_field, $filter_field[ 'options' ] );
3206
                        ?>
3207
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3208
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3209
3210
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3211
                                <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3212
                            </label>
3213
3214
                            <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>">
3215
                                <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
3216
                            </span>
3217
                        <?php
3218
                            }
3219
                            else {
3220
                                $value = pods_var_raw( 'filter_' . $filter, 'get' );
3221
3222
                                if ( strlen( $value ) < 1 )
3223
                                    $value = pods_var_raw( 'filter_default', $filter_field );
3224
3225
                                $options = array(
3226
                                    '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 )
3227
                                );
3228
3229
                                if ( empty( $options[ 'input_helper' ] ) && isset( $filter_field[ 'options' ] ) && isset( $filter_field[ 'options' ][ 'input_helper' ] ) )
3230
                                    $options[ 'input_helper' ] = $filter_field[ 'options' ][ 'input_helper' ];
3231
                        ?>
3232
                            <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
3233
                            <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
3234
3235
                            <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>">
3236
                                <?php echo esc_html( $filter_field[ 'label' ] ); ?>
3237
                            </label>
3238
3239
                            <span class="pods-ui-posts-filter<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>">
3240
                                <?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?>
3241
                            </span>
3242
                        <?php
3243
                            }
3244
                        ?>
3245
                    </p>
3246
                <?php
3247
                        $zebra = empty( $zebra );
3248
                    }
3249
                ?>
3250
3251
                <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-search<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>">
3252
                    <label for="pods-form-ui-search<?php echo esc_attr( $this->num ); ?>"><?php _e( 'Search Text', 'pods' ); ?></label>
3253
                    <?php echo PodsForm::field( 'search' . $this->num, pods_var_raw( 'search' . $this->num, 'get' ), 'text' ); ?>
3254
                </p>
3255
3256
                <?php $zebra = empty( $zebra ); ?>
3257
            </div>
3258
3259
            <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>
3260
        </form>
3261
    </div>
3262
3263
    <script type="text/javascript">
3264
        jQuery( function () {
3265
            jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) {
3266
                jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
3267
3268
                jQuery( this ).hide();
3269
                jQuery( this ).parent().find( '.toggle-off' ).show();
3270
            } );
3271
3272
            jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) {
3273
                jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
3274
                jQuery( this ).parent().find( 'select, input' ).val( '' );
3275
3276
                jQuery( this ).hide();
3277
                jQuery( this ).parent().find( '.toggle-on' ).show();
3278
            } );
3279
3280
            jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) {
3281
                if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'hidden' ) ) {
3282
                    jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
3283
3284
                    jQuery( this ).parent().find( '.toggle-on' ).hide();
3285
                    jQuery( this ).parent().find( '.toggle-off' ).show();
3286
                }
3287
                else {
3288
                    jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
3289
                    jQuery( this ).parent().find( 'select, input' ).val( '' );
3290
3291
                    jQuery( this ).parent().find( '.toggle-on' ).show();
3292
                    jQuery( this ).parent().find( '.toggle-off' ).hide();
3293
                }
3294
            } );
3295
        } );
3296
    </script>
3297
<?php
3298
    }
3299
3300
    /**
3301
     * @param bool $reorder
3302
     *
3303
     * @return bool|mixed
3304
     */
3305
    public function table ( $reorder = false ) {
3306
		if ( false !== $this->callback( 'table', $reorder ) ) {
3307
			return null;
3308
		}
3309
3310
        if ( empty( $this->data ) ) {
3311
            ?>
3312
        <p><?php echo sprintf( __( 'No %s found', 'pods' ), $this->items ); ?></p>
3313
        <?php
3314
            return false;
3315
        }
3316
        if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
3317
            ?>
3318
        <style type="text/css">
3319
            table.widefat.fixed tbody.reorderable tr {
3320
                height: 50px;
3321
            }
3322
3323
            .dragme {
3324
                background: url(<?php echo esc_url( PODS_URL ); ?>/ui/images/handle.gif) no-repeat;
3325
                background-position: 8px 8px;
3326
                cursor: pointer;
3327
            }
3328
3329
            .dragme strong {
3330
                margin-left: 30px;
3331
            }
3332
        </style>
3333
<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">
3334
<?php
3335
        }
3336
        $table_fields = $this->fields[ 'manage' ];
3337 View Code Duplication
        if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] )
3338
            $table_fields = $this->fields[ 'reorder' ];
3339
        if ( false === $table_fields || empty( $table_fields ) )
3340
            return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods' ) );
3341
        ?>
3342
        <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...
3343
            <thead>
3344
                <tr>
3345
                    <?php
3346
                        if ( !empty( $this->actions_bulk ) ) {
3347
            ?>
3348
                            <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th>
3349
            <?php
3350
                        }
3351
3352
                    $name_field = false;
3353
                    $fields = array();
3354
                    if ( !empty( $table_fields ) ) {
3355
                        foreach ( $table_fields as $field => $attributes ) {
3356
                            if ( false === $attributes[ 'display' ] )
3357
                                continue;
3358
                            if ( false === $name_field )
3359
                                $id = 'title';
3360
                            else
3361
                                $id = '';
3362
                            if ( 'other' == $attributes[ 'type' ] )
3363
                                $id = '';
3364
                            if ( in_array( $attributes[ 'type' ], array( 'date', 'datetime', 'time' ) ) )
3365
                                $id = 'date';
3366
                            if ( false === $name_field && 'title' == $id )
3367
                                $name_field = true;
3368
                            $fields[ $field ] = $attributes;
3369
                            $fields[ $field ][ 'field_id' ] = $id;
3370
                            $dir = 'DESC';
3371
                            $current_sort = ' asc';
3372
                            if ( isset( $this->orderby[ 'default' ] ) && $field == $this->orderby[ 'default' ] ) {
3373
                                if ( 'DESC' == $this->orderby_dir ) {
3374
                                    $dir = 'ASC';
3375
                                    $current_sort = ' desc';
3376
                                }
3377
                            }
3378
3379
                            $att_id = '';
3380
                            if ( !empty( $id ) )
3381
                                $att_id = ' id="' . esc_attr( $id ) . '"';
3382
3383
                            $width = '';
3384
3385
                            $column_classes = array(
3386
                                'manage-column',
3387
                                'column-' . $id
3388
                            );
3389
3390
                            // Merge with the classes taken from the UI call
3391 View Code Duplication
                            if ( ! empty( $attributes['classes'] ) && is_array( $attributes['classes'] ) ) {
3392
                                $column_classes = array_merge( $column_classes, $attributes['classes'] );
3393
                            }
3394
                            if ( $id == 'title' ) {
3395
                                $column_classes[] = 'column-primary';
3396
                            }
3397
3398 View Code Duplication
                            if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) )
3399
                                $width = ' style="width: ' . esc_attr( $attributes[ 'width' ] ) . '"';
3400
3401
                            if ( $fields[ $field ][ 'sortable' ] ) {
3402
                                $column_classes[] = 'sortable' . $current_sort;
3403
                                ?>
3404
                                <th scope="col"<?php echo $att_id; ?> class="<?php echo esc_attr( implode( ' ', $column_classes ) ); ?>"<?php echo $width; ?>>
3405
                                    <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 esc_html( $attributes[ 'label' ] ); ?></span> <span class="sorting-indicator"></span> </a>
3406
                                </th>
3407
                                <?php
3408
                            }
3409
                            else {
3410
                                ?>
3411
                                <th scope="col"<?php echo $att_id; ?> class="<?php echo esc_attr( implode( ' ', $column_classes ) ); ?>"<?php echo $width; ?>><?php echo esc_html( $attributes[ 'label' ] ); ?></th>
3412
                                <?php
3413
                            }
3414
                        }
3415
                    }
3416
                    ?>
3417
                </tr>
3418
            </thead>
3419
            <?php
3420
            if ( 6 < $this->total_found ) {
3421
                ?>
3422
                <tfoot>
3423
                    <tr>
3424
                        <?php
3425
                            if ( !empty( $this->actions_bulk ) ) {
3426
            ?>
3427
                                <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th>
3428
            <?php
3429
                            }
3430
3431
                        if ( !empty( $fields ) ) {
3432
                            foreach ( $fields as $field => $attributes ) {
3433
                                $dir = 'ASC';
3434
                                if ( $field == $this->orderby ) {
3435
                                    $current_sort = 'desc';
3436
                                    if ( 'ASC' == $this->orderby_dir ) {
3437
                                        $dir = 'DESC';
3438
                                        $current_sort = 'asc';
3439
                                    }
3440
                                }
3441
3442
                                $width = '';
3443
3444 View Code Duplication
                                if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) )
3445
                                    $width = ' style="width: ' . esc_attr( $attributes[ 'width' ] ) . '"';
3446
3447
                                if ( $fields[ $field ][ 'sortable' ] ) {
3448
                                    ?>
3449
                                    <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 esc_html( $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...
3450
                                    <?php
3451
                                }
3452
                                else {
3453
                                    ?>
3454
                                    <th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?>"<?php echo $width; ?>><?php echo esc_html( $attributes[ 'label' ] ); ?></th>
3455
                                    <?php
3456
                                }
3457
                            }
3458
                        }
3459
                        ?>
3460
                    </tr>
3461
                </tfoot>
3462
                <?php
3463
            }
3464
            ?>
3465
            <tbody id="the-list"<?php echo ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) ? ' class="reorderable"' : ''; ?>>
3466
                <?php
3467
                if ( !empty( $this->data ) && is_array( $this->data ) ) {
3468
                    $counter = 0;
3469
3470
                    while ( $row = $this->get_row( $counter, 'table' ) ) {
3471
                        if ( is_object( $row ) )
3472
                            $row = get_object_vars( (object) $row );
3473
3474
                        $toggle_class = '';
3475
3476
                        if ( is_array( $this->actions_custom ) && isset( $this->actions_custom[ 'toggle' ] ) ) {
3477
                            $toggle_class = ' pods-toggled-on';
3478
3479
                            if ( !isset( $row[ 'toggle' ] ) || empty( $row[ 'toggle' ] ) )
3480
                                $toggle_class = ' pods-toggled-off';
3481
                        }
3482
                        ?>
3483
                        <tr id="item-<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" class="iedit<?php echo esc_attr( $toggle_class ); ?>">
3484
                            <?php
3485
                                if ( !empty( $this->actions_bulk ) ) {
3486
            ?>
3487
                                <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>
3488
            <?php
3489
                                }
3490
                            // Boolean for the first field to output after the check-column
3491
                            // will be set to false at the end of the first loop
3492
                            $first_field = true;
3493
                            foreach ( $fields as $field => $attributes ) {
3494
                                if ( false === $attributes[ 'display' ] )
3495
                                    continue;
3496
3497
                                if ( !isset( $row[ $field ] ) ) {
3498
                                    $row[ $field ] = $this->get_field( $field );
3499
								}
3500
3501
								$row_value = $row[ $field ];
3502
3503
                                if ( !empty( $attributes[ 'custom_display' ] ) ) {
3504
                                    if ( is_callable( $attributes[ 'custom_display' ] ) )
3505
                                        $row_value = call_user_func_array( $attributes[ 'custom_display' ], array( $row, &$this, $row_value, $field, $attributes ) );
3506
                                    elseif ( is_object( $this->pod ) && class_exists( 'Pods_Helpers' ) )
3507
                                        $row_value = $this->pod->helper( $attributes[ 'custom_display' ], $row_value, $field );
3508
                                }
3509
                                else {
3510
                                    ob_start();
3511
3512
                                    $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 );
3513
3514
                                    $field_output = trim( (string) ob_get_clean() );
3515
3516
                                    if ( false === $field_value )
3517
                                        $row_value = '';
3518
                                    elseif ( 0 < strlen( trim( (string) $field_value ) ) )
3519
                                        $row_value = trim( (string) $field_value );
3520
                                    elseif ( 0 < strlen( $field_output ) )
3521
                                        $row_value = $field_output;
3522
                                }
3523
3524
                                if ( false !== $attributes[ 'custom_relate' ] ) {
3525
                                    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...
3526
                                    $table = $attributes[ 'custom_relate' ];
3527
                                    $on = $this->sql[ 'field_id' ];
3528
                                    $is = $row[ $this->sql[ 'field_id' ] ];
3529
                                    $what = array( 'name' );
3530
                                    if ( is_array( $table ) ) {
3531
                                        if ( isset( $table[ 'on' ] ) )
3532
                                            $on = pods_sanitize( $table[ 'on' ] );
3533
                                        if ( isset( $table[ 'is' ] ) && isset( $row[ $table[ 'is' ] ] ) )
3534
                                            $is = pods_sanitize( $row[ $table[ 'is' ] ] );
3535
                                        if ( isset( $table[ 'what' ] ) ) {
3536
                                            $what = array();
3537
                                            if ( is_array( $table[ 'what' ] ) ) {
3538
                                                foreach ( $table[ 'what' ] as $wha ) {
3539
                                                    $what[] = pods_sanitize( $wha );
3540
                                                }
3541
                                            }
3542
                                            else
3543
                                                $what[] = pods_sanitize( $table[ 'what' ] );
3544
                                        }
3545
                                        if ( isset( $table[ 'table' ] ) )
3546
                                            $table = $table[ 'table' ];
3547
                                    }
3548
                                    $table = pods_sanitize( $table );
3549
                                    $wha = implode( ',', $what );
3550
                                    $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'";
3551
                                    $value = @current( $wpdb->get_results( $sql, ARRAY_A ) );
3552
                                    if ( !empty( $value ) ) {
3553
                                        $val = array();
3554
                                        foreach ( $what as $wha ) {
3555
                                            if ( isset( $value[ $wha ] ) )
3556
                                                $val[] = $value[ $wha ];
3557
                                        }
3558
                                        if ( !empty( $val ) )
3559
                                            $row_value = implode( ' ', $val );
3560
                                    }
3561
                                }
3562
3563
                                $css_classes = array(
3564
                                    'pods-ui-col-field-' . sanitize_title( $field )
3565
                                );
3566
3567
                                // Merge with the classes taken from the UI call
3568 View Code Duplication
                                if ( ! empty( $attributes['classes'] ) && is_array( $attributes['classes'] ) ) {
3569
                                    $css_classes = array_merge( $css_classes, $attributes['classes'] );
3570
                                }
3571
3572
								if ( $attributes[ 'css_values' ] ) {
3573
									$css_field_value = $row[ $field ];
3574
3575
									if ( is_object( $css_field_value ) ) {
3576
										$css_field_value = get_object_vars( $css_field_value );
3577
									}
3578
3579
									if ( is_array( $css_field_value ) ) {
3580
										foreach ( $css_field_value as $css_field_val ) {
3581
											if ( is_object( $css_field_val ) ) {
3582
												$css_field_val = get_object_vars( $css_field_val );
3583
											}
3584
3585
											if ( is_array( $css_field_val ) ) {
3586
												foreach ( $css_field_val as $css_field_v ) {
3587
													if ( is_object( $css_field_v ) ) {
3588
														$css_field_v = get_object_vars( $css_field_v );
3589
													}
3590
3591
													$css_classes[] = 'pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_v ) ) );
3592
												}
3593
											}
3594 View Code Duplication
											else {
3595
												$css_classes[] = ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_val ) ) );
3596
											}
3597
										}
3598
									}
3599 View Code Duplication
									else {
3600
										$css_classes[] = ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_value ) ) );
3601
									}
3602
								}
3603
3604
                                if ( is_object( $this->pod ) )
3605
                                    $row_value = $this->do_hook( $this->pod->pod . '_field_value', $row_value, $field, $attributes, $row );
3606
3607
                                $row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row );
3608
3609
                                if ( 'title' == $attributes[ 'field_id' ] ) {
3610
									$default_action = $this->do_hook( 'default_action', 'edit', $row );
3611
3612
                                    if ( $first_field ) {
3613
                                        $css_classes[] = 'column-primary';
3614
                                    }
3615
                                    $css_classes[] = 'post-title';
3616
                                    $css_classes[] = 'page-title';
3617
                                    $css_classes[] = 'column-title';
3618
3619
                                    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 ) {
3620
                                        $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3621
3622
                                        if ( !empty( $this->action_links[ 'edit' ] ) )
3623
                                            $link = $this->do_template( $this->action_links[ 'edit' ], $row );
3624
                                        ?>
3625
                <td class="<?php echo esc_attr( implode( ' ', $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 wp_kses_post( $row_value ); ?></a></strong>
3626
                                        <?php
3627
                                    }
3628
                                    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 ) {
3629
                                        $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3630
3631
                                        if ( !empty( $this->action_links[ 'view' ] ) )
3632
                                            $link = $this->do_template( $this->action_links[ 'view' ], $row );
3633
                                        ?>
3634
                <td class="<?php echo esc_attr( implode( ' ', $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 wp_kses_post( $row_value ); ?></a></strong>
3635
                                        <?php
3636
                                    }
3637
                                    else {
3638
                                        if ( 1 == $reorder && $this->reorder ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->reorder of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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

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

Loading history...
3639
                                            $css_classes[] = 'dragme';
3640
                                        }
3641
                                        ?>
3642
                <td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>"><strong><?php echo wp_kses_post( $row_value ); ?></strong>
3643
                                        <?php
3644
                                    }
3645
3646
                                    if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) {
3647
                                        $toggle = false;
3648
                                        $actions = array();
3649
3650 View Code Duplication
                                        if ( !in_array( 'view', $this->actions_disabled ) && !in_array( 'view', $this->actions_hidden ) ) {
3651
                                            $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3652
3653
                                            if ( !empty( $this->action_links[ 'view' ] ) )
3654
                                                $link = $this->do_template( $this->action_links[ 'view' ], $row );
3655
3656
                                            $actions[ 'view' ] = '<span class="view"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>';
3657
                                        }
3658
3659 View Code Duplication
                                        if ( !in_array( 'edit', $this->actions_disabled ) && !in_array( 'edit', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3660
                                            $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3661
3662
                                            if ( !empty( $this->action_links[ 'edit' ] ) )
3663
                                                $link = $this->do_template( $this->action_links[ 'edit' ], $row );
3664
3665
                                            $actions[ 'edit' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>';
3666
                                        }
3667
3668 View Code Duplication
                                        if ( !in_array( 'duplicate', $this->actions_disabled ) && !in_array( 'duplicate', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) {
3669
                                            $link = pods_query_arg( array( 'action' . $this->num => 'duplicate', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() );
3670
3671
                                            if ( !empty( $this->action_links[ 'duplicate' ] ) )
3672
                                                $link = $this->do_template( $this->action_links[ 'duplicate' ], $row );
3673
3674
                                            $actions[ 'duplicate' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>';
3675
                                        }
3676
3677
                                        if ( !in_array( 'delete', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) && !$this->restricted( 'delete', $row ) ) {
3678
                                            $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() );
3679
3680
                                            if ( !empty( $this->action_links[ 'delete' ] ) ) {
3681
	                                            $link = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), $this->do_template( $this->action_links[ 'delete' ], $row ) );
3682
                                            }
3683
3684
                                            $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>';
3685
                                        }
3686
3687
                                        if ( is_array( $this->actions_custom ) ) {
3688
                                            foreach ( $this->actions_custom as $custom_action => $custom_data ) {
3689
												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 ) ) {
3690
                                                    if ( !in_array( $custom_action, array( 'add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table' ) ) ) {
3691
                                                        if ( 'toggle' == $custom_action ) {
3692
                                                            $toggle = true;
3693
                                                            $toggle_labels = array(
3694
                                                                __( 'Enable', 'pods' ),
3695
                                                                __( 'Disable', 'pods' )
3696
                                                            );
3697
3698
                                                            $custom_data[ 'label' ] = ( $row[ 'toggle' ] ? $toggle_labels[ 1 ] : $toggle_labels[ 0 ] );
3699
                                                        }
3700
3701
                                                        if ( !isset( $custom_data[ 'label' ] ) )
3702
                                                            $custom_data[ 'label' ] = ucwords( str_replace( '_', ' ', $custom_action ) );
3703
3704
                                                        if ( !isset( $custom_data[ 'link' ] ) ) {
3705
                                                            $vars = array(
3706
                                                                'action' => $custom_action,
3707
                                                                'id' => $row[ $this->sql[ 'field_id' ] ],
3708
                                                                '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action )
3709
                                                            );
3710
3711
                                                            if ( 'toggle' == $custom_action ) {
3712
                                                                $vars[ 'toggle' ] = (int) ( !$row[ 'toggle' ] );
3713
                                                                $vars[ 'toggled' ] = 1;
3714
                                                            }
3715
3716
                                                            $custom_data[ 'link' ] = pods_query_arg( $vars, self::$allowed, $this->exclusion() );
3717
3718
                                                            if ( isset( $this->action_links[ $custom_action ] ) && !empty( $this->action_links[ $custom_action ] ) ) {
3719
	                                                            $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 ) );
3720
                                                            }
3721
                                                        }
3722
3723
                                                        $confirm = '';
3724
3725
                                                        if ( isset( $custom_data[ 'confirm' ] ) )
3726
                                                            $confirm = ' onclick="if(confirm(\'' . esc_js( $custom_data[ 'confirm' ] ) . '\')){return true;}return false;"';
3727
3728
                                                        if ( $this->restricted( $custom_action, $row ) ) {
3729
                                                            continue;
3730
														}
3731
3732
                                                        $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>';
3733
                                                    }
3734
                                                }
3735
                                            }
3736
                                        }
3737
3738
                                        $actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql[ 'field_id' ] ] );
3739
3740
                                        if ( !empty( $actions ) ) {
3741
                                            ?>
3742
                                            <div class="row-actions<?php echo esc_attr( $toggle ? ' row-actions-toggle' : '' ); ?>">
3743
                                                <?php
3744
													$this->callback( 'actions_start', $row, $actions );
3745
3746
													echo implode( ' | ', $actions );
3747
3748
													$this->callback( 'actions_end', $row, $actions );
3749
                                                ?>
3750
                                            </div>
3751
                                            <?php
3752
                                        }
3753
                                    }
3754
                                    else {
3755
                                        ?>
3756
                                        <input type="hidden" name="order[]" value="<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" />
3757
                                        <?php
3758
                                    }
3759
                                    ?><button type="button" class="toggle-row"><span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span></button>
3760
                </td>
3761
<?php
3762
                                }
3763
                                elseif ( 'date' == $attributes[ 'type' ] ) {
3764
                                    if ( $first_field ) {
3765
                                        $css_classes[] = 'column-primary';
3766
                                    }
3767
                                    $css_classes[] = 'date';
3768
                                    $css_classes[] = 'column-date';
3769
                                    ?>
3770
                                    <td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>" data-colname="<?php echo esc_attr( $attributes['label'] ); ?>">
3771
                                        <abbr title="<?php echo esc_attr( $row_value ); ?>"><?php echo wp_kses_post( $row_value ); ?></abbr>
3772
                                        <?php if ( $first_field ) { ?><button type="button" class="toggle-row"><span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span></button><?php }; ?>
3773
                                    </td>
3774
                                    <?php
3775
                                }
3776
                                else {
3777
                                    if ( $first_field ) {
3778
                                        $css_classes[] = 'column-primary';
3779
                                    }
3780
                                    $css_classes[] = 'author';
3781
                                    ?>
3782
                                    <td class="<?php echo esc_attr( implode( ' ', $css_classes ) ); ?>" data-colname="<?php echo esc_attr( $attributes['label'] ); ?>">
3783
                                        <span><?php echo wp_kses_post( $row_value ); ?></span>
3784
                                        <?php if ( $first_field ) { ?><button type="button" class="toggle-row"><span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'pods' ); ?></span></button><?php }; ?>
3785
                                    </td>
3786
                                    <?php
3787
                                }
3788
                                $first_field = false;
3789
                            }
3790
                            ?>
3791
                        </tr>
3792
                        <?php
3793
                    }
3794
                }
3795
                ?>
3796
            </tbody>
3797
        </table>
3798
        <?php
3799 View Code Duplication
        if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
3800
            ?>
3801
</form>
3802
<?php
3803
        }
3804
        ?>
3805
    <script type="text/javascript">
3806
        jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
3807
            <?php
3808 View Code Duplication
            if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
3809
                ?>
3810
            jQuery( document ).ready( function () {
3811
                jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} );
3812
                jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) {
3813
                    jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' );
3814
                    jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
3815
                } );
3816
            } );
3817
                <?php
3818
            }
3819
            ?>
3820
    </script>
3821
    <?php
3822
    }
3823
3824
    /**
3825
     *
3826
     */
3827
    public function screen_meta () {
3828
        $screen_html = $help_html = '';
3829
        $screen_link = $help_link = '';
3830
        if ( !empty( $this->screen_options ) && !empty( $this->help ) ) {
3831 View Code Duplication
            foreach ( $this->ui_page as $page ) {
3832
                if ( isset( $this->screen_options[ $page ] ) ) {
3833
                    if ( is_array( $this->screen_options[ $page ] ) ) {
3834
                        if ( isset( $this->screen_options[ $page ][ 'link' ] ) ) {
3835
                            $screen_link = $this->screen_options[ $page ][ 'link' ];
3836
                            break;
3837
                        }
3838
                    }
3839
                    else {
3840
                        $screen_html = $this->screen_options[ $page ];
3841
                        break;
3842
                    }
3843
                }
3844
            }
3845 View Code Duplication
            foreach ( $this->ui_page as $page ) {
3846
                if ( isset( $this->help[ $page ] ) ) {
3847
                    if ( is_array( $this->help[ $page ] ) ) {
3848
                        if ( isset( $this->help[ $page ][ 'link' ] ) ) {
3849
                            $help_link = $this->help[ $page ][ 'link' ];
3850
                            break;
3851
                        }
3852
                    }
3853
                    else {
3854
                        $help_html = $this->help[ $page ];
3855
                        break;
3856
                    }
3857
                }
3858
            }
3859
        }
3860
        $screen_html = $this->do_hook( 'screen_meta_screen_html', $screen_html );
3861
        $screen_link = $this->do_hook( 'screen_meta_screen_link', $screen_link );
3862
        $help_html = $this->do_hook( 'screen_meta_help_html', $help_html );
3863
        $help_link = $this->do_hook( 'screen_meta_help_link', $help_link );
3864
        if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) || 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
3865
            ?>
3866
        <div id="screen-meta">
3867
            <?php
3868
            $this->do_hook( 'screen_meta_pre' );
3869
            if ( 0 < strlen( $screen_html ) ) {
3870
                ?>
3871
                <div id="screen-options-wrap" class="hidden">
3872
                    <form id="adv-settings" action="" method="post">
3873
                        <?php
3874
                        echo $screen_html;
3875
                        $fields = array();
3876
                        foreach ( $this->ui_page as $page ) {
3877 View Code Duplication
                            if ( isset( $this->fields[ $page ] ) && !empty( $this->fields[ $page ] ) )
3878
                                $fields = $this->fields[ $page ];
3879
                        }
3880
                        if ( !empty( $fields ) || true === $this->pagination ) {
3881
                            ?>
3882
                            <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
3883
                            <?php
3884
                            if ( !empty( $fields ) ) {
3885
                                ?>
3886
                                <div class="metabox-prefs">
3887
                                    <?php
3888
                                    $this->do_hook( 'screen_meta_screen_options' );
3889
                                    foreach ( $fields as $field => $attributes ) {
3890
                                        if ( false === $attributes[ 'display' ] || true === $attributes[ 'hidden' ] )
3891
                                            continue;
3892
                                        ?>
3893
                                        <label for="<?php echo esc_attr( $field ); ?>-hide">
3894
                                            <input class="hide-column-tog" name="<?php echo esc_attr( $this->unique_identifier ); ?>_<?php echo esc_attr( $field ); ?>-hide" type="checkbox" id="<?php echo esc_attr( $field ); ?>-hide" value="<?php echo esc_attr( $field ); ?>" checked="checked"><?php echo esc_html( $attributes[ 'label' ] ); ?></label>
3895
                                        <?php
3896
                                    }
3897
                                    ?>
3898
                                    <br class="clear">
3899
                                </div>
3900
                                <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
3901
                                <?php
3902
                            }
3903
                            ?>
3904
                            <div class="screen-options">
3905
                                <?php
3906
                                if ( true === $this->pagination ) {
3907
                                    ?>
3908
                                    <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 esc_html( $this->items ); ?> per page</label>
3909
                                    <?php
3910
                                }
3911
                                $this->do_hook( 'screen_meta_screen_submit' );
3912
                                ?>
3913
                                <input type="submit" name="screen-options-apply" id="screen-options-apply" class="button" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>">
3914
                                <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page">
3915
                                <?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?>
3916
                            </div>
3917
                            <?php
3918
                        }
3919
                        ?>
3920
                    </form>
3921
                </div>
3922
                <?php
3923
            }
3924
            if ( 0 < strlen( $help_html ) ) {
3925
                ?>
3926
                <div id="contextual-help-wrap" class="hidden">
3927
                    <div class="metabox-prefs">
3928
                        <?php echo $help_html; ?>
3929
                    </div>
3930
                </div>
3931
                <?php
3932
            }
3933
            ?>
3934
            <div id="screen-meta-links">
3935
                <?php
3936
                $this->do_hook( 'screen_meta_links_pre' );
3937
                if ( 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
3938
                    ?>
3939
                    <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
3940
                        <?php
3941
                        if ( 0 < strlen( $help_link ) ) {
3942
                            ?>
3943
                            <a href="<?php echo esc_url( $help_link ); ?>" class="show-settings">Help</a>
3944
                            <?php
3945
                        }
3946
                        else {
3947
                            ?>
3948
                            <a href="#contextual-help" id="contextual-help-link" class="show-settings">Help</a>
3949
                            <?php
3950
                        }
3951
                        ?>
3952
                    </div>
3953
                    <?php
3954
                }
3955
                if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) ) {
3956
                    ?>
3957
                    <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
3958
                        <?php
3959
                        if ( 0 < strlen( $screen_link ) ) {
3960
                            ?>
3961
                            <a href="<?php echo esc_url( $screen_link ); ?>" class="show-settings">Screen Options</a>
3962
                            <?php
3963
                        }
3964
                        else {
3965
                            ?>
3966
                            <a href="#screen-options" id="show-settings-link" class="show-settings">Screen Options</a>
3967
                            <?php
3968
                        }
3969
                        ?>
3970
                    </div>
3971
                    <?php
3972
                }
3973
                $this->do_hook( 'screen_meta_links_post' );
3974
                ?>
3975
            </div>
3976
            <?php
3977
            $this->do_hook( 'screen_meta_post' );
3978
            ?>
3979
        </div>
3980
        <?php
3981
        }
3982
    }
3983
3984
    /**
3985
     * @param bool $header
3986
     *
3987
     * @return mixed
3988
     */
3989
    public function pagination ( $header = false ) {
3990
		if ( false !== $this->callback( 'pagination', $header ) ) {
3991
			return null;
3992
		}
3993
3994
        $total_pages = ceil( $this->total_found / $this->limit );
3995
        $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() );
3996
3997
        $append = false;
3998
3999
        if ( false !== strpos( $request_uri, '?' ) )
4000
            $append = true;
4001
4002
        if ( false !== $this->pagination_total && ( $header || 1 != $this->total_found ) ) {
4003
            $singular_label = strtolower( $this->item );
4004
            $plural_label = strtolower( $this->items );
4005
            ?>
4006
        <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>
4007
        <?php
4008
        }
4009
4010
        if ( false !== $this->pagination ) {
4011
            if ( 1 < $total_pages ) {
4012
                ?>
4013
            <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>
4014
            <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>
4015
            <?php
4016
                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...
4017
                    ?>
4018
                <span class="paging-input"><input class="current-page" title="<?php esc_attr_e( 'Current page', 'pods' ); ?>" type="text" name="pg<?php echo esc_attr( $this->num ); ?>" value="<?php echo esc_attr( absint( $this->page ) ); ?>" size="<?php echo esc_attr( strlen( $total_pages ) ); ?>"> <?php _e( 'of', 'pods' ); ?> <span class="total-pages"><?php echo absint( $total_pages ); ?></span></span>
4019
                <script>
4020
4021
                    jQuery( document ).ready( function ( $ ) {
4022
                        var pageInput = $( 'input.current-page' );
4023
                        var currentPage = pageInput.val();
4024
                        pageInput.closest( 'form' ).submit( function ( e ) {
4025
                            if (
4026
	                            ( 1 > $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).length
4027
	                              || $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 )
4028
	                            && ( 1 > $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).length
4029
	                                 || $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 )
4030
	                            && pageInput.val() == currentPage ) {
4031
                                pageInput.val( '1' );
4032
                            }
4033
                        } );
4034
                    } );
4035
                </script>
4036
                <?php
4037
                }
4038
                else {
4039
                    ?>
4040
                <span class="paging-input"><?php echo absint( $this->page ); ?> <?php _e( 'of', 'pods' ); ?> <span class="total-pages"><?php echo number_format_i18n( $total_pages ); ?></span></span>
4041
                <?php
4042
                }
4043
                ?>
4044
            <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>
4045
            <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>
4046
            <?php
4047
            }
4048
        }
4049
    }
4050
4051
    /**
4052
     * @param bool $options
4053
     *
4054
     * @return mixed
4055
     */
4056
    public function limit ( $options = false ) {
4057
		if ( false !== $this->callback( 'limit', $options ) ) {
4058
			return null;
4059
		}
4060
4061
        if ( false === $options || !is_array( $options ) || empty( $options ) )
4062
            $options = array( 10, 25, 50, 100, 200 );
4063
4064
        if ( !in_array( $this->limit, $options ) && -1 != $this->limit )
4065
            $this->limit = $options[ 1 ];
4066
4067
        foreach ( $options as $option ) {
4068
            if ( $option == $this->limit )
4069
                echo ' <span class="page-numbers current">' . esc_html( $option ) . '</span>';
4070
            else
4071
                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>';
4072
        }
4073
    }
4074
4075
    /**
4076
     * @param $code
4077
     * @param bool|array $row
4078
     *
4079
     * @return mixed
4080
     */
4081
    public function do_template ( $code, $row = false ) {
4082
        if ( is_object( $this->pod ) && 1 == 0 && 0 < $this->pod->id() )
4083
            return $this->pod->do_magic_tags( $code );
4084
        else {
4085
            if ( false !== $row ) {
4086
                $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...
4087
                $this->row = $row;
4088
            }
4089
4090
            $code = preg_replace_callback( "/({@(.*?)})/m", array( $this, "do_magic_tags" ), $code );
4091
4092
            if ( false !== $row ) {
4093
                $this->row = $this->temp_row;
4094
                unset( $this->temp_row );
4095
            }
4096
        }
4097
4098
        return $code;
4099
    }
4100
4101
    /**
4102
     * @param $tag
4103
     *
4104
     * @return string
4105
     */
4106
    public function do_magic_tags ( $tag ) {
4107 View Code Duplication
        if ( is_array( $tag ) ) {
4108
            if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 )
4109
                return '';
4110
4111
            $tag = $tag[ 2 ];
4112
        }
4113
4114
        $tag = trim( $tag, ' {@}' );
4115
        $tag = explode( ',', $tag );
4116
4117 View Code Duplication
        if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 )
4118
            return null;
4119
4120
        foreach ( $tag as $k => $v ) {
4121
            $tag[ $k ] = trim( $v );
4122
        }
4123
4124
        $field_name = $tag[ 0 ];
4125
4126
        $value = $this->get_field( $field_name );
4127
4128 View Code Duplication
        if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) && is_callable( $tag[ 1 ] ) )
4129
            $value = call_user_func_array( $tag[ 1 ], array( $value, $field_name, $this->row, &$this ) );
4130
4131
        $before = $after = '';
4132
4133
        if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) )
4134
            $before = $tag[ 2 ];
4135
4136
        if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) )
4137
            $after = $tag[ 3 ];
4138
4139
        if ( 0 < strlen( $value ) )
4140
            return $before . $value . $after;
4141
4142
        return null;
4143
    }
4144
4145
    /**
4146
     * @param bool|array $exclude
4147
     * @param bool|array $array
4148
     */
4149
    public function hidden_vars ( $exclude = false, $array = false ) {
4150
        $exclude = $this->do_hook( 'hidden_vars', $exclude, $array );
4151
        if ( false === $exclude )
4152
            $exclude = array();
4153
        if ( !is_array( $exclude ) )
4154
            $exclude = explode( ',', $exclude );
4155
        $get = $_GET;
4156
        if ( is_array( $array ) ) {
4157
            foreach ( $array as $key => $val ) {
4158
                if ( 0 < strlen( $val ) )
4159
                    $get[ $key ] = $val;
4160
                else
4161
                    unset( $get[ $key ] );
4162
            }
4163
        }
4164
        foreach ( $get as $k => $v ) {
4165
            if ( in_array( $k, $exclude ) )
4166
                continue;
4167
4168
            if ( is_array( $v ) ) {
4169
                foreach ( $v as $vk => $vv ) {
4170
?>
4171
    <input type="hidden" name="<?php echo esc_attr( $k ); ?>[<?php echo esc_attr( $vk ); ?>]" value="<?php echo esc_attr( $vv ); ?>" />
4172
<?php
4173
               }
4174
            }
4175
            else {
4176
?>
4177
    <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
4178
<?php
4179
            }
4180
        }
4181
    }
4182
4183
    /**
4184
     * @return array
4185
     */
4186
    public function exclusion () {
4187
        $exclusion = self::$excluded;
4188
4189
        foreach ( $exclusion as $k => $exclude ) {
4190
            $exclusion[ $k ] = $exclude . $this->num;
4191
        }
4192
4193
        return $exclusion;
4194
    }
4195
4196
    public function restricted ( $action = 'edit', $row = null ) {
4197
        $restricted = false;
4198
4199
        $restrict = array();
4200
4201
        if ( isset( $this->restrict[ $action ] ) )
4202
            $restrict = (array) $this->restrict[ $action ];
4203
4204
        // @todo Build 'edit', 'duplicate', 'delete' action support for 'where' which runs another find() query
4205
        /*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...
4206
            $where = pods_var_raw( $action, $this->where, null, null, true );
4207
4208
            if ( !empty( $where ) ) {
4209
                $restricted = true;
4210
4211
                $old_where = $this->where[ $action ];
4212
4213
                $id = $this->row[ $this->sql[ 'field_id' ] ];
4214
4215
                if ( is_array( $where ) ) {
4216
                    if ( 'OR' == pods_var( 'relation', $where ) )
4217
                        $where = array( $where );
4218
4219
                    $where[] = "`t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
4220
                }
4221
                else
4222
                    $where = "( {$where} ) AND `t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id;
4223
4224
                $this->where[ $action ] = $where;
4225
4226
                $data = false;
4227
4228
                //$data = $this->get_data();
4229
4230
                $this->where[ $action ] = $old_where;
4231
4232
                if ( empty( $data ) )
4233
                    $restricted = true;
4234
            }
4235
        }*/
4236
4237
        $author_restrict = false;
4238
4239
        if ( !empty( $this->restrict[ 'author_restrict' ] ) && $restrict === $this->restrict[ 'author_restrict' ] ) {
4240
            $restricted = false;
4241
4242
            $author_restrict = true;
4243
4244
            if ( is_object( $this->pod ) ) {
4245
                $restricted = true;
4246
4247
                if ( 'settings' == $this->pod->pod_data[ 'type' ] && 'add' == $action )
4248
                    $action = 'edit';
4249
4250
                if ( pods_is_admin( array( 'pods', 'pods_content' ) ) )
4251
                    $restricted = false;
4252
                elseif ( 'manage' == $action ) {
4253
                    if ( !in_array( 'edit', $this->actions_disabled ) && current_user_can( 'pods_edit_' . $this->pod->pod ) && current_user_can( 'pods_edit_others_' . $this->pod->pod ) )
4254
                        $restricted = false;
4255
                    elseif ( !in_array( 'delete', $this->actions_disabled ) && current_user_can( 'pods_delete_' . $this->pod->pod ) && current_user_can( 'pods_delete_others_' . $this->pod->pod ) )
4256
                        $restricted = false;
4257 View Code Duplication
                    elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) )
4258
                        $restricted = false;
4259
                }
4260 View Code Duplication
                elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) )
4261
                    $restricted = false;
4262
            }
4263
            /* @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...
4264
            else {
4265
                $restricted = true;
4266
4267
                if ( pods_is_admin( array( 'pods', 'pods_content' ) ) )
4268
                    $restricted = false;
4269
                elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) )
4270
                    $restricted = false;
4271
            }*/
4272
        }
4273
4274
        if ( $restricted && !empty( $restrict ) ) {
4275
            $relation = strtoupper( trim( pods_var( 'relation', $restrict, 'AND', null, true ) ) );
4276
4277
            if ( 'AND' != $relation )
4278
                $relation = 'OR';
4279
4280
            $okay = true;
4281
4282
            foreach ( $restrict as $field => $match ) {
4283
                if ( 'relation' == $field )
4284
                    continue;
4285
4286
                if ( is_array( $match ) ) {
4287
                    $match_okay = true;
4288
4289
                    $match_relation = strtoupper( trim( pods_var( 'relation', $match, 'OR', null, true ) ) );
4290
4291
                    if ( 'AND' != $match_relation )
4292
                        $match_relation = 'OR';
4293
4294
                    foreach ( $match as $the_field => $the_match ) {
4295
                        if ( 'relation' == $the_field )
4296
                            continue;
4297
4298
                        $value = null;
4299
4300 View Code Duplication
                        if ( is_object( $this->pod ) )
4301
                            $value = $this->pod->field( $the_match, true );
4302
                        else {
4303
                            if ( empty( $row ) )
4304
                                $row = $this->row;
4305
4306
                            if ( isset( $row[ $the_match ] ) ) {
4307
                                if ( is_array( $row[ $the_match ] ) ) {
4308
                                    if ( false !== strpos( $the_match, '.' ) ) {
4309
                                        $the_matches = explode( '.', $the_match );
4310
4311
                                        $value = $row[ $the_match ];
4312
4313
                                        foreach ( $the_matches as $m ) {
4314
                                            if ( is_array( $value ) && isset( $value[ $m ] ) )
4315
                                                $value = $value[ $m ];
4316
                                            else {
4317
                                                $value = null;
4318
4319
                                                break;
4320
                                            }
4321
                                        }
4322
                                    }
4323
                                }
4324
                                else
4325
                                    $value = $row[ $the_match ];
4326
                            }
4327
                        }
4328
4329 View Code Duplication
                        if ( is_array( $value ) ) {
4330
                            if ( !in_array( $the_match, $value ) )
4331
                                $match_okay = false;
4332
                            elseif ( 'OR' == $match_relation ) {
4333
                                $match_okay = true;
4334
4335
                                break;
4336
                            }
4337
                        }
4338
                        elseif ( $value == $the_match )
4339
                            $match_okay = false;
4340
                        elseif ( 'OR' == $match_relation ) {
4341
                            $match_okay = true;
4342
4343
                            break;
4344
                        }
4345
                    }
4346
4347
                    if ( !$match_okay )
4348
                        $okay = false;
4349
                    if ( 'OR' == $relation ) {
4350
                        $okay = true;
4351
4352
                        break;
4353
                    }
4354
                }
4355
                else {
4356
                    $value = null;
4357
4358 View Code Duplication
                    if ( is_object( $this->pod ) )
4359
                        $value = $this->pod->field( $match, true );
4360
                    else {
4361
                        if ( empty( $row ) )
4362
                            $row = $this->row;
4363
4364
                        if ( isset( $row[ $match ] ) ) {
4365
                            if ( is_array( $row[ $match ] ) ) {
4366
                                if ( false !== strpos( $match, '.' ) ) {
4367
                                    $matches = explode( '.', $match );
4368
4369
                                    $value = $row[ $match ];
4370
4371
                                    foreach ( $matches as $m ) {
4372
                                        if ( is_array( $value ) && isset( $value[ $m ] ) )
4373
                                            $value = $value[ $m ];
4374
                                        else {
4375
                                            $value = null;
4376
4377
                                            break;
4378
                                        }
4379
                                    }
4380
                                }
4381
                            }
4382
                            else
4383
                                $value = $row[ $match ];
4384
                        }
4385
                    }
4386
4387 View Code Duplication
                    if ( is_array( $value ) ) {
4388
                        if ( !in_array( $match, $value ) )
4389
                            $okay = false;
4390
                        elseif ( 'OR' == $relation ) {
4391
                            $okay = true;
4392
4393
                            break;
4394
                        }
4395
                    }
4396
                    elseif ( $value != $match )
4397
                        $okay = false;
4398
                    elseif ( 'OR' == $relation ) {
4399
                        $okay = true;
4400
4401
                        break;
4402
                    }
4403
                }
4404
            }
4405
4406
            if ( !empty( $author_restrict ) ) {
4407
                if ( is_object( $this->pod ) && 'manage' == $action ) {
4408
                    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 ) )
4409
                        $okay = false;
4410
                }
4411
                if ( is_object( $this->pod ) && !current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) )
4412
                    $okay = false;
4413
                /* @todo determine proper logic for non-pods capabilities
4414
                elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) )
4415
                    $okay = false;*/
4416
4417
                if ( !$okay && !empty( $row ) ) {
4418
                    foreach ( $this->restrict[ 'author_restrict' ] as $key => $val ) {
4419
                        $author_restricted = $this->get_field( $key );
4420
4421
                        if ( !empty( $author_restricted ) ) {
4422
                            if ( !is_array( $author_restricted ) )
4423
                                $author_restricted = (array) $author_restricted;
4424
4425
                            if ( is_array( $val ) ) {
4426
                                foreach ( $val as $v ) {
4427
                                    if ( in_array( $v, $author_restricted ) )
4428
                                        $okay = true;
4429
                                }
4430
                            }
4431
                            elseif ( in_array( $val, $author_restricted ) )
4432
                                $okay = true;
4433
                        }
4434
                    }
4435
                }
4436
            }
4437
4438
            if ( $okay )
4439
                $restricted = false;
4440
        }
4441
4442
		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' ] ) ) {
4443
			$restricted = call_user_func( $this->actions_custom[ $action ][ 'restrict_callback' ], $restricted, $restrict, $action, $row, $this );
4444
		}
4445
4446
        $restricted = $this->do_hook( 'restricted_' . $action, $restricted, $restrict, $action, $row );
4447
4448
        return $restricted;
4449
    }
4450
4451
	/**
4452
	 * Check for a custom action callback and run it
4453
	 *
4454
	 * @return bool|mixed
4455
	 */
4456
	public function callback() {
4457
4458
		$args = func_get_args();
4459
4460
		if ( empty( $args ) ) {
4461
			return false;
4462
		}
4463
4464
		$action = array_shift( $args );
4465
4466
		// Do hook
4467
		$callback_args = $args;
4468
		array_unshift( $callback_args, null );
4469
		array_unshift( $callback_args, $action );
4470
4471
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
4472
4473
		if ( null === $callback ) {
4474
			$callback = false;
4475
		}
4476
4477
		$args[] = $this;
4478
4479
		if ( isset( $this->actions_custom[ $action ] ) ) {
4480
			if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ][ 'callback' ] ) && is_callable( $this->actions_custom[ $action ][ 'callback' ] ) ) {
4481
				$callback = call_user_func_array( $this->actions_custom[ $action ][ 'callback' ], $args );
4482
			}
4483
			elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
4484
				$callback = call_user_func_array( $this->actions_custom[ $action ], $args );
4485
			}
4486
		}
4487
4488
		return $callback;
4489
4490
	}
4491
4492
	/**
4493
	 * Check for a custom action callback and run it (deprecated reverse arg order)
4494
	 *
4495
	 * @return bool|mixed
4496
	 */
4497 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...
4498
4499
		$args = func_get_args();
4500
4501
		if ( empty( $args ) ) {
4502
			return false;
4503
		}
4504
4505
		$action = array_shift( $args );
4506
4507
		$deprecated = false;
4508
4509
		if ( is_bool( $action ) ) {
4510
			$deprecated = $action;
4511
4512
			$action = array_shift( $args );
4513
		}
4514
4515
		// Do hook
4516
		$callback_args = $args;
4517
		array_unshift( $callback_args, null );
4518
		array_unshift( $callback_args, 'action_' . $action );
4519
4520
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
4521
4522
		if ( null === $callback ) {
4523
			$callback = false;
4524
		}
4525
4526
		$args[] = $this;
4527
4528
		// Deprecated reverse arg order
4529
		if ( $deprecated ) {
4530
			$args = array_reverse( $args );
4531
		}
4532
4533
		if ( isset( $this->actions_custom[ $action ] ) ) {
4534
			if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ][ 'callback' ] ) && is_callable( $this->actions_custom[ $action ][ 'callback' ] ) ) {
4535
				$callback = call_user_func_array( $this->actions_custom[ $action ][ 'callback' ], $args );
4536
			}
4537
			elseif ( is_callable( $this->actions_custom[ $action ] ) ) {
4538
				$callback = call_user_func_array( $this->actions_custom[ $action ], $args );
4539
			}
4540
		}
4541
4542
		return $callback;
4543
4544
	}
4545
4546
	/**
4547
	 * Check for a bulk action callback and run it
4548
	 *
4549
	 * @return bool|mixed Callback result
4550
	 */
4551 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...
4552
4553
		$args = func_get_args();
4554
4555
		if ( empty( $args ) ) {
4556
			return false;
4557
		}
4558
4559
		$action = array_shift( $args );
4560
4561
		$deprecated = false;
4562
4563
		if ( is_bool( $action ) ) {
4564
			$deprecated = $action;
4565
4566
			$action = array_shift( $args );
4567
		}
4568
4569
		// Do hook
4570
		$callback_args = $args;
4571
		array_unshift( $callback_args, null );
4572
		array_unshift( $callback_args, 'bulk_action_' . $action );
4573
4574
		$callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args );
4575
4576
		if ( null === $callback ) {
4577
			$callback = false;
4578
		}
4579
4580
		$args[] = $this;
4581
4582
		// Deprecated reverse arg order
4583
		if ( $deprecated ) {
4584
			$args = array_reverse( $args );
4585
		}
4586
4587
		if ( isset( $this->actions_bulk[ $action ] ) ) {
4588
			if ( is_array( $this->actions_bulk[ $action ] ) && isset( $this->actions_bulk[ $action ][ 'callback' ] ) && is_callable( $this->actions_bulk[ $action ][ 'callback' ] ) ) {
4589
				$callback = call_user_func_array( $this->actions_bulk[ $action ][ 'callback' ], $args );
4590
			}
4591
			elseif ( is_callable( $this->actions_bulk[ $action ] ) ) {
4592
				$callback = call_user_func_array( $this->actions_bulk[ $action ], $args );
4593
			}
4594
		}
4595
4596
		return $callback;
4597
4598
	}
4599
4600
    /*
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...
4601
        // Example code for use with $this->do_hook
4602
        public function my_filter_function ($args, $obj) {
4603
            $obj[0]->item = 'Post';
4604
            $obj[0]->add = true;
4605
            // args are an array (0 => $arg1, 1 => $arg2)
4606
            // may have more than one arg, dependant on filter
4607
            return $args;
4608
        }
4609
        add_filter('pods_ui_post_init', 'my_filter_function', 10, 2);
4610
    */
4611
    /**
4612
     * @return array|bool|mixed|null
4613
     */
4614 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...
4615
4616
		$args = func_get_args();
4617
4618
		if ( empty( $args ) ) {
4619
			return false;
4620
		}
4621
4622
		$name = array_shift( $args );
4623
4624
		return pods_do_hook( "ui", $name, $args, $this );
4625
4626
	}
4627
}
4628