PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / deprecated / classes / Pods.php
pods / deprecated / classes Last commit date
Pods.php 3 days ago PodsAPI.php 3 days ago
Pods.php
736 lines
1 <?php
2 require_once PODS_DIR . 'deprecated/deprecated.php';
3
4 /**
5 * @package Pods\Deprecated
6 */
7 class Pods_Deprecated {
8
9 private $obj;
10
11 public $id;
12
13 public $data;
14
15 public $datatype;
16
17 public $datatype_id;
18
19 /**
20 * Constructor - Pods Deprecated functionality (pre 2.0)
21 *
22 * @param object $obj The Pods object
23 *
24 * @license http://www.gnu.org/licenses/gpl-2.0.html
25 * @since 2.0.0
26 */
27 public function __construct( $obj ) {
28
29 // backwards-compatibility with references to $this->var_name
30 $vars = get_object_vars( $obj );
31
32 foreach ( (array) $vars as $key => $val ) {
33 $this->{$key} = $val;
34 }
35
36 // keeping references pointing back to the source
37 $this->obj =& $obj;
38 }
39
40 /**
41 * Set a custom data value (no database changes)
42 *
43 * @param string $name The field name
44 * @param mixed $data The value to set
45 *
46 * @return mixed The value of $data
47 * @since 1.2.0
48 */
49 public function set_field( $name, $data = null ) {
50
51 if ( Pod::$deprecated_notice ) {
52 pods_deprecated( 'Pods::set_field', '2.0' );
53 }
54
55 $this->obj->row[ $name ] = $data;
56
57 return $this->obj->row[ $name ];
58 }
59
60 /**
61 * Display HTML for all datatype fields
62 *
63 * @deprecated 2.0.0
64 *
65 * @param null $id
66 * @param null $public_fields
67 * @param string $label
68 */
69 public function showform( $id = null, $public_fields = null, $label = 'Save changes' ) {
70
71 if ( Pod::$deprecated_notice ) {
72 pods_deprecated( 'Pods::showform', '2.0' );
73 }
74
75 $public_columns =& $public_fields;
76
77 $pod = $this->obj->pod;
78 $pod_id = $this->obj->pod_id;
79 $this->obj->type_counter = array();
80
81 if ( ! empty( $public_fields ) ) {
82 $attributes = array();
83
84 foreach ( $public_fields as $key => $value ) {
85 if ( is_array( $public_fields[ $key ] ) ) {
86 $attributes[ $key ] = $value;
87 } else {
88 $attributes[ $value ] = array();
89 }
90 }
91 }
92
93 $fields = $this->obj->fields;
94
95 // Re-order the fields if a public form
96 if ( ! empty( $attributes ) ) {
97 $fields = array();
98
99 foreach ( $attributes as $key => $value ) {
100 if ( isset( $this->obj->fields[ $key ] ) ) {
101 $fields[ $key ] = $this->obj->fields[ $key ];
102 }
103 }
104 }
105
106 do_action( 'pods_showform_pre', $pod_id, $public_fields, $label, $this );
107
108 foreach ( $fields as $key => $field ) {
109 if ( ! is_array( $field ) || in_array( $key, array( 'created', 'modified' ), true ) ) {
110 continue;
111 }
112
113 // Pass options so they can be manipulated via form
114 $field = array_merge( $field['options'], $field );
115
116 // Replace field attributes with public form attributes
117 if ( ! empty( $attributes ) && is_array( $attributes[ $key ] ) ) {
118 $field = array_merge( $field, $attributes[ $key ] );
119 }
120
121 // Replace the input helper name with the helper code
122 if ( ! empty( $field['input_helper'] ) ) {
123 $helper = $this->obj->api->load_helper( array( 'name' => $field['input_helper'] ) );
124 $field['input_helper'] = '';
125
126 if ( ! empty( $helper ) ) {
127 $field['input_helper'] = $helper['code'];
128 }
129 }
130
131 if ( empty( $field['label'] ) ) {
132 $field['label'] = ucwords( $key );
133 }
134
135 if ( 1 == $field['required'] ) {
136 $field['label'] .= ' <span class="red">*</span>';
137 }
138
139 if ( ! empty( $field['pick_val'] ) ) {
140 $selected_ids = array();
141 $pick_object = $field['pick_object'];
142 $pick_val = $field['pick_val'];
143
144 if ( 'pod' === $pick_object ) {
145 $pick_pod = $this->obj->api->load_pod( array( 'name' => $pick_val ) );
146 $pick_object = $pick_pod['type'];
147 $pick_val = $pick_pod['name'];
148 }
149
150 $pick_table = '';
151 $pick_join = '';
152 $pick_where = '';
153
154 $pick_field_id = 'id';
155 $pick_field_name = 'name';
156 switch ( $pick_object ) {
157 case 'pod':
158 $pick_table = "@wp_pods_{$pick_val}";
159 $pick_field_id = 'id';
160 $pick_field_name = 'name';
161 break;
162 case 'post_type':
163 $pick_table = '@wp_posts';
164 $pick_field_id = 'ID';
165 $pick_field_name = 'post_title';
166 $pick_where = "t.`post_type` = '{$pick_val}'";
167 break;
168 case 'taxonomy':
169 $pick_table = '@wp_terms';
170 $pick_field_id = 'term_id';
171 $pick_field_name = 'name';
172 $pick_join = '`@wp_term_taxonomy` AS tx ON tx.`term_id` = t.`term_id';
173 $pick_where = "tx.`taxonomy` = '{$pick_val}' AND tx.`taxonomy` IS NOT NULL";
174 break;
175 case 'user':
176 $pick_table = '@wp_users';
177 $pick_field_id = 'ID';
178 $pick_field_name = 'user_login';
179 break;
180 case 'comment':
181 $pick_table = '@wp_comments';
182 $pick_field_id = 'comment_ID';
183 $pick_field_name = 'comment_date';
184 $pick_where = "t.`comment_type` = '{$pick_val}'";
185 break;
186 case 'table':
187 $pick_table = "{$pick_val}";
188 $pick_field_id = 'id';
189 $pick_field_name = 'name';
190 break;
191 }//end switch
192
193 $sql = 'SELECT `related_item_id` FROM `@wp_podsrel` WHERE `item_id` = %d AND `field_id` = %d';
194
195 $sql = array( $sql, array( $id, $field['id'] ) );
196
197 $result = pods_query( $sql, $this );
198
199 foreach ( $result as $row ) {
200 $selected_ids[] = $row->related_item_id;
201 }
202
203 // Use default values for public forms
204 if ( empty( $selected_ids ) && ! empty( $field['default'] ) ) {
205 $default_ids = $field['default'];
206
207 if ( ! is_array( $field['default'] ) ) {
208 $default_ids = explode( ',', $default_ids );
209 }
210
211 foreach ( $default_ids as $default_id ) {
212 $default_id = pods_absint( $default_id );
213
214 if ( 0 < $default_id ) {
215 $selected_ids[] = $default_id;
216 }
217 }
218 }
219
220 // If the PICK field is unique, get values already chosen
221 $exclude = false;
222
223 if ( 1 == $field['unique'] ) {
224 $unique_where = ( empty( $id ) ) ? '' : ' AND `item_id` != %d';
225
226 $sql = "SELECT `related_item_id` FROM `@wp_podsrel` WHERE `field_id` = %d {$unique_where}";
227
228 $sql = array( $sql, array( $field['id'] ) );
229
230 if ( ! empty( $id ) ) {
231 $sql[1][] = $id;
232 }
233
234 $result = pods_query( $sql, $this );
235
236 if ( ! empty( $result ) ) {
237
238 $exclude = array();
239
240 foreach ( $result as $row ) {
241 $exclude[] = (int) $row->related_item_id;
242 }
243
244 $exclude = implode( ',', $exclude );
245 }
246 }//end if
247
248 if ( ! empty( $field['options']['pick_filter'] ) ) {
249 $pick_where .= ' AND ' . $field['options']['pick_filter'];
250 }
251
252 $params = array(
253 'exclude' => $exclude,
254 'selected_ids' => $selected_ids,
255 'table' => $pick_table,
256 'field_id' => $pick_field_id,
257 'field_name' => $pick_field_name,
258 'join' => $pick_join,
259 'orderby' => $field['options']['pick_orderby'],
260 'where' => $pick_where,
261 );
262
263 $this->obj->row[ $key ] = $this->get_dropdown_values( $params );
264 } else {
265 // Set a default value if no value is entered
266 if ( ! isset( $this->obj->row[ $key ] ) || ( null === $this->obj->row[ $key ] || false === $this->obj->row[ $key ] ) ) {
267 if ( ! empty( $field['default'] ) ) {
268 $this->obj->row[ $key ] = $field['default'];
269 } else {
270 $this->obj->row[ $key ] = null;
271 }
272 }
273 }//end if
274
275 $this->obj->build_field_html( $field );
276 }//end foreach
277
278 $uri_hash = wp_hash( $_SERVER['REQUEST_URI'] );
279
280 $save_button_atts = array(
281 'type' => 'button',
282 'class' => 'button btn_save',
283 'value' => $label,
284 'onclick' => 'saveForm(1)',
285 );
286
287 $save_button_atts = apply_filters( 'pods_showform_save_button_atts', $save_button_atts, $this );
288 $atts = '';
289
290 foreach ( $save_button_atts as $att => $value ) {
291 $atts .= ' ' . esc_attr( $att ) . '="' . esc_attr( $value ) . '"';
292 }
293
294 $save_button = '<input ' . $atts . '/>';
295 ?>
296 <div>
297 <input type="hidden" class="form num id" value="<?php echo esc_attr( $id ); ?>" />
298 <input type="hidden" class="form txt pod" value="<?php echo esc_attr( $pod ); ?>" />
299 <input type="hidden" class="form txt pod_id" value="<?php echo esc_attr( $pod_id ); ?>" />
300 <input type="hidden" class="form txt form_count" value="1" />
301 <input type="hidden" class="form txt token" value="<?php echo esc_attr( pods_generate_key( $pod, $uri_hash, $public_fields, 1 ) ); ?>" />
302 <input type="hidden" class="form txt uri_hash" value="<?php echo esc_attr( $uri_hash ); ?>" />
303 <?php echo apply_filters( 'pods_showform_save_button', $save_button, $save_button_atts, $this ); ?>
304 </div>
305 <?php
306 do_action( 'pods_showform_post', $pod_id, $public_fields, $label, $this );
307 }
308
309 /**
310 * Get pod or category drop-down values
311 *
312 * @param array $params
313 *
314 * @return array
315 */
316 public function get_dropdown_values( $params ) {
317
318 if ( Pod::$deprecated_notice ) {
319 pods_deprecated( 'Pods::get_dropdown_values', '2.0' );
320 }
321
322 global $wpdb;
323
324 $params = (object) $params;
325
326 $params->orderby = empty( $params->orderby ) ? '' : ' ORDER BY ' . $params->orderby;
327 $params->join = empty( $params->join ) ? '' : ' LEFT JOIN ' . $params->join;
328
329 $where = ( false !== $params->exclude ) ? "WHERE `t`.term_id NOT IN ({$params->exclude})" : '';
330
331 if ( ! empty( $params->pick_filter ) ) {
332 $where .= ( empty( $where ) ? ' WHERE ' : ' AND ' ) . $params->pick_filter;
333 }
334
335 if ( ! empty( $params->where ) ) {
336 $where .= ( empty( $where ) ? ' WHERE ' : ' AND ' ) . $params->where;
337 }
338
339 $sql = "
340 SELECT
341 `t`.`{$params->field_id}` AS `id`,
342 `t`.`{$params->field_name}` AS `name`
343 FROM `{$params->table}` AS `t`
344 {$params->join}
345 {$where}
346 {$params->orderby}
347 ";
348
349 // override with custom dropdown values
350 $sql = apply_filters( 'pods_get_dropdown_values', $sql, $params, $this );
351
352 $val = array();
353 $result = pods_query( $sql );
354
355 foreach ( $result as $row ) {
356 $row = get_object_vars( $row );
357 $row['active'] = false;
358
359 if ( ! empty( $params->selected_ids ) ) {
360 $row['active'] = in_array( $row['id'], $params->selected_ids );
361 }
362
363 $val[] = $row;
364 }
365
366 return $val;
367 }
368
369 /**
370 * Build public input form
371 *
372 * @deprecated 2.0.0
373 *
374 * @param null $fields
375 * @param string $label
376 * @param null $thankyou_url
377 */
378 public function publicForm( $fields = null, $label = 'Save Changes', $thankyou_url = null ) {
379
380 if ( Pod::$deprecated_notice ) {
381 pods_deprecated( 'Pods::publicForm', '2.0', 'Pods::form' );
382 }
383
384 if ( ! empty( $fields ) ) {
385 // Just update field name here, form() will handle the rest
386 foreach ( $fields as $k => $field ) {
387 $name = $k;
388
389 if ( ! is_array( $field ) ) {
390 $name = $field;
391 $field = array();
392 } elseif ( isset( $field['name'] ) ) {
393 $name = $field['name'];
394 }
395
396 if ( in_array(
397 $name, array(
398 'created',
399 'modified',
400 'author',
401 ), true
402 ) && isset( $this->obj->fields[ $name . '2' ] ) ) {
403 $name .= '2';
404 }
405
406 $field['name'] = $name;
407
408 $fields[ $k ] = $field;
409 }//end foreach
410 }//end if
411
412 echo $this->obj->form( $fields, $label, $thankyou_url );
413 }
414
415 /**
416 * Build HTML for a single field
417 *
418 * @deprecated 2.0.0
419 *
420 * @param array $field Field data.
421 */
422 public function build_field_html( $field ) {
423
424 if ( Pod::$deprecated_notice ) {
425 pods_deprecated( 'Pods::build_field_html', '2.0' );
426 }
427
428 include PODS_DIR . 'deprecated/input_fields.php';
429 }
430
431 /**
432 * Fetch a row of results from the DB
433 *
434 * @since 1.2.0
435 * @deprecated 2.0.0
436 */
437 public function fetchRecord() {
438
439 if ( Pod::$deprecated_notice ) {
440 pods_deprecated( 'Pods::fetchRecord', '2.0', 'Pods::fetch' );
441 }
442
443 return $this->obj->fetch();
444 }
445
446 /**
447 * Return a field's value(s)
448 *
449 * @param string $name The field name
450 * @param string $orderby (optional) The orderby string, for PICK fields
451 *
452 * @since 1.2.0
453 * @deprecated 2.0.0
454 * @return array|mixed
455 */
456 public function get_field( $name, $orderby = null ) {
457
458 if ( Pod::$deprecated_notice ) {
459 pods_deprecated( 'Pods::get_field', '2.0', 'Pods::field' );
460 }
461
462 $value = $this->obj->field(
463 array(
464 'name' => $name,
465 'orderby' => $orderby,
466 'deprecated' => true,
467 )
468 );
469
470 if ( is_array( $value ) && ! empty( $value ) ) {
471 if ( false === strpos( $name, '.' ) && ! isset( $value[0] ) ) {
472 $value = array( $value );
473 } elseif ( false !== strpos( $name, '.' ) && 1 == count( $value ) ) {
474 // fix for single tableless fields
475 $value = current( $value );
476 }
477 }
478
479 return $value;
480 }
481
482 /**
483 * Get the current item's pod ID from its datatype ID and tbl_row_id
484 *
485 * @return int The ID from the wp_pod table
486 * @since 1.2.0
487 * @deprecated 2.0.0
488 */
489 public function get_pod_id() {
490
491 if ( Pod::$deprecated_notice ) {
492 pods_deprecated( 'Pods::get_pod_id', '2.0' );
493 }
494
495 if ( ! empty( $this->obj->row ) ) {
496 return $this->obj->row[ $this->obj->data->field_id ];
497 }
498
499 return false;
500 }
501
502 /**
503 * Search and filter records
504 *
505 * @since 1.x.x
506 * @deprecated 2.0.0
507 *
508 * @param null $orderby
509 * @param int $rows_per_page
510 * @param null $where
511 * @param null $sql
512 *
513 * @return
514 */
515 public function findRecords( $orderby = null, $rows_per_page = 15, $where = null, $sql = null ) {
516
517 if ( Pod::$deprecated_notice ) {
518 pods_deprecated( 'Pods::findRecords', '2.0', 'Pods::find' );
519 }
520
521 $find = array(
522 ' p.created',
523 '`p`.`created`',
524 '`p`.created',
525 ' p.`created`',
526 ' p.modified',
527 '`p`.`modified`',
528 '`p`.modified',
529 ' p.`modified`',
530 ' p.id',
531 '`p`.`id`',
532 '`p`.id',
533 ' p.`id`',
534 ' p.pod_id',
535 '`p`.`pod_id`',
536 '`p`.pod_id',
537 ' p.`pod_id`',
538 );
539
540 $replace = array(
541 ' t.created',
542 '`t`.`created`',
543 '`t`.created',
544 ' t.`created`',
545 ' t.modified',
546 '`t`.`modified`',
547 '`t`.modified',
548 ' t.`modified`',
549 ' t.id',
550 '`t`.`id`',
551 '`t`.id',
552 ' t.`id`',
553 ' t.id',
554 '`t`.`id`',
555 '`t`.id',
556 ' t.`id`',
557 );
558
559 $params = array(
560 'where' => $where,
561 'orderby' => "`t`.`{$this->obj->data->field_id}` DESC",
562 'limit' => (int) $rows_per_page,
563 'page' => $this->obj->page,
564 'search' => $this->obj->search,
565 'search_across' => true,
566 'search_across_picks' => false,
567 'sql' => $sql,
568 );
569
570 if ( is_array( $orderby ) ) {
571 $params = array_merge( $params, $orderby );
572 } elseif ( ! empty( $orderby ) ) {
573 $params['orderby'] = $orderby;
574 }
575
576 $params['where'] = trim( str_replace( $find, $replace, ' ' . $params['where'] ) );
577 $params['orderby'] = trim( str_replace( $find, $replace, ' ' . $params['orderby'] ) );
578
579 $params = (object) $params;
580
581 $this->obj->limit = $params->limit;
582 $this->obj->page = $params->page;
583 $this->obj->search = $params->search;
584
585 return $this->obj->find( $params );
586 }
587
588 /**
589 * Return a single record
590 *
591 * @since 1.x.x
592 * @deprecated 2.0.0
593 *
594 * @param int $id Item ID.
595 *
596 * @return
597 */
598 public function getRecordById( $id ) {
599
600 if ( Pod::$deprecated_notice ) {
601 pods_deprecated( 'Pods::getRecordById', '2.0', 'Pods::fetch_item' );
602 }
603
604 return $this->obj->fetch_item( $id );
605 }
606
607 /**
608 * Fetch the total row count
609 *
610 * @deprecated 2.0.0
611 */
612 public function getTotalRows() {
613
614 if ( Pod::$deprecated_notice ) {
615 pods_deprecated( 'Pods::getTotalRows', '2.0', 'Pods::total_found' );
616 }
617
618 return $this->obj->total_found();
619 }
620
621 /**
622 * (Re)set the MySQL result pointer
623 *
624 * @deprecated 2.0.0
625 *
626 * @param int $row_number
627 *
628 * @return
629 */
630 public function resetPointer( $row_number = 0 ) {
631
632 if ( Pod::$deprecated_notice ) {
633 pods_deprecated( 'Pods::resetPointer', '2.0', 'Pods::reset' );
634 }
635
636 return $this->obj->reset( $row_number );
637 }
638
639 /**
640 * Display the pagination controls
641 *
642 * @deprecated 2.0.0
643 *
644 * @param string $label
645 */
646 public function getPagination( $label = 'Go to page:' ) {
647
648 if ( Pod::$deprecated_notice ) {
649 pods_deprecated( 'Pods::getPagination', '2.0', 'Pods::pagination' );
650 }
651
652 echo $this->obj->pagination(
653 array(
654 'type' => 'advanced',
655 'label' => $label,
656 )
657 );
658 }
659
660 /**
661 * Display the list filters
662 *
663 * @deprecated 2.0.0
664 *
665 * @param null $filters
666 * @param string $label
667 * @param string $action
668 */
669 public function getFilters( $filters = null, $label = 'Filter', $action = '' ) {
670
671 if ( Pod::$deprecated_notice ) {
672 pods_deprecated( 'Pods::getFilters', '2.0', 'Pods::filters' );
673 }
674
675 $params = array(
676 'fields' => $filters,
677 'label' => $label,
678 'action' => $action,
679 );
680
681 if ( is_array( $filters ) ) {
682 $params = array_merge( $params, $filters );
683 }
684
685 echo $this->obj->filters( $params );
686 }
687
688 /**
689 * Run a helper within a Pod Page or WP Template
690 *
691 * @param string $helper_name Helper name.
692 * @param null|string|array $value Field value.
693 * @param null|string $name Field name.
694 *
695 * @return mixed Anything returned by the helper
696 * @internal param string $helper The helper name
697 *
698 * @since 1.2.0
699 * @deprecated 2.0.0
700 */
701 public function pod_helper( $helper_name, $value = null, $name = null ) {
702
703 if ( Pod::$deprecated_notice ) {
704 pods_deprecated( 'Pods::pod_helper', '2.0', 'Pods::helper' );
705 }
706
707 $params = array(
708 'helper' => $helper_name,
709 'value' => $value,
710 'name' => $name,
711 'deprecated' => true,
712 );
713
714 return $this->obj->helper( $params );
715 }
716
717 /**
718 * Display the page template
719 *
720 * @deprecated 2.0.0
721 *
722 * @param string $template_name Template name.
723 * @param null|string $code Template code override.
724 *
725 * @return
726 */
727 public function showTemplate( $template_name, $code = null ) {
728
729 if ( Pod::$deprecated_notice ) {
730 pods_deprecated( 'Pods::showTemplate', '2.0', 'Pods::template' );
731 }
732
733 return $this->obj->template( $template_name, $code, true );
734 }
735 }
736