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 |
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 deprecated since 2.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 = $pick_join = $pick_where = ''; |
151
|
|
|
|
152
|
|
|
$pick_field_id = 'id'; |
153
|
|
|
$pick_field_name = 'name'; |
154
|
|
|
switch ( $pick_object ) { |
155
|
|
|
case 'pod': |
156
|
|
|
$pick_table = "@wp_pods_{$pick_val}"; |
157
|
|
|
$pick_field_id = 'id'; |
158
|
|
|
$pick_field_name = 'name'; |
159
|
|
|
break; |
160
|
|
|
case 'post_type': |
161
|
|
|
$pick_table = '@wp_posts'; |
162
|
|
|
$pick_field_id = 'ID'; |
163
|
|
|
$pick_field_name = 'post_title'; |
164
|
|
|
$pick_where = "t.`post_type` = '{$pick_val}'"; |
165
|
|
|
break; |
166
|
|
|
case 'taxonomy': |
167
|
|
|
$pick_table = '@wp_terms'; |
168
|
|
|
$pick_field_id = 'term_id'; |
169
|
|
|
$pick_field_name = 'name'; |
170
|
|
|
$pick_join = '`@wp_term_taxonomy` AS tx ON tx.`term_id` = t.`term_id'; |
171
|
|
|
$pick_where = "tx.`taxonomy` = '{$pick_val}' AND tx.`taxonomy` IS NOT NULL"; |
172
|
|
|
break; |
173
|
|
|
case 'user': |
174
|
|
|
$pick_table = '@wp_users'; |
175
|
|
|
$pick_field_id = 'ID'; |
176
|
|
|
$pick_field_name = 'user_login'; |
177
|
|
|
break; |
178
|
|
|
case 'comment': |
179
|
|
|
$pick_table = '@wp_comments'; |
180
|
|
|
$pick_field_id = 'comment_ID'; |
181
|
|
|
$pick_field_name = 'comment_date'; |
182
|
|
|
$pick_where = "t.`comment_type` = '{$pick_val}'"; |
183
|
|
|
break; |
184
|
|
|
case 'table': |
185
|
|
|
$pick_table = "{$pick_val}"; |
186
|
|
|
$pick_field_id = 'id'; |
187
|
|
|
$pick_field_name = 'name'; |
188
|
|
|
break; |
189
|
|
|
}//end switch |
190
|
|
|
|
191
|
|
|
$sql = 'SELECT `related_item_id` FROM `@wp_podsrel` WHERE `item_id` = %d AND `field_id` = %d'; |
192
|
|
|
|
193
|
|
|
$sql = array( $sql, array( $id, $field['id'] ) ); |
194
|
|
|
|
195
|
|
|
$result = pods_query( $sql, $this ); |
196
|
|
|
|
197
|
|
|
foreach ( $result as $row ) { |
198
|
|
|
$selected_ids[] = $row->related_item_id; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
// Use default values for public forms |
202
|
|
|
if ( empty( $selected_ids ) && ! empty( $field['default'] ) ) { |
203
|
|
|
$default_ids = $field['default']; |
204
|
|
|
|
205
|
|
|
if ( ! is_array( $field['default'] ) ) { |
206
|
|
|
$default_ids = explode( ',', $default_ids ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
foreach ( $default_ids as $default_id ) { |
210
|
|
|
$default_id = pods_absint( $default_id ); |
211
|
|
|
|
212
|
|
|
if ( 0 < $default_id ) { |
213
|
|
|
$selected_ids[] = $default_id; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// If the PICK field is unique, get values already chosen |
219
|
|
|
$exclude = false; |
220
|
|
|
|
221
|
|
|
if ( 1 == $field['unique'] ) { |
222
|
|
|
$unique_where = ( empty( $id ) ) ? '' : ' AND `item_id` != %d'; |
223
|
|
|
|
224
|
|
|
$sql = "SELECT `related_item_id` FROM `@wp_podsrel` WHERE `field_id` = %d {$unique_where}"; |
225
|
|
|
|
226
|
|
|
$sql = array( $sql, array( $field['id'] ) ); |
227
|
|
|
|
228
|
|
|
if ( ! empty( $id ) ) { |
229
|
|
|
$sql[1][] = $id; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
$result = pods_query( $sql, $this ); |
233
|
|
|
|
234
|
|
|
if ( ! empty( $result ) ) { |
235
|
|
|
|
236
|
|
|
$exclude = array(); |
237
|
|
|
|
238
|
|
|
foreach ( $result as $row ) { |
239
|
|
|
$exclude[] = (int) $row->related_item_id; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$exclude = implode( ',', $exclude ); |
243
|
|
|
} |
244
|
|
|
}//end if |
245
|
|
|
|
246
|
|
|
if ( ! empty( $field['options']['pick_filter'] ) ) { |
247
|
|
|
$pick_where .= ' AND ' . $field['options']['pick_filter']; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
$params = array( |
251
|
|
|
'exclude' => $exclude, |
252
|
|
|
'selected_ids' => $selected_ids, |
253
|
|
|
'table' => $pick_table, |
254
|
|
|
'field_id' => $pick_field_id, |
255
|
|
|
'field_name' => $pick_field_name, |
256
|
|
|
'join' => $pick_join, |
257
|
|
|
'orderby' => $field['options']['pick_orderby'], |
258
|
|
|
'where' => $pick_where, |
259
|
|
|
); |
260
|
|
|
|
261
|
|
|
$this->obj->row[ $key ] = $this->get_dropdown_values( $params ); |
262
|
|
|
} else { |
263
|
|
|
// Set a default value if no value is entered |
264
|
|
|
if ( ! isset( $this->obj->row[ $key ] ) || ( null === $this->obj->row[ $key ] || false === $this->obj->row[ $key ] ) ) { |
265
|
|
|
if ( ! empty( $field['default'] ) ) { |
266
|
|
|
$this->obj->row[ $key ] = $field['default']; |
267
|
|
|
} else { |
268
|
|
|
$this->obj->row[ $key ] = null; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
}//end if |
272
|
|
|
|
273
|
|
|
$this->obj->build_field_html( $field ); |
274
|
|
|
}//end foreach |
275
|
|
|
|
276
|
|
|
$uri_hash = wp_hash( $_SERVER['REQUEST_URI'] ); |
277
|
|
|
|
278
|
|
|
$save_button_atts = array( |
279
|
|
|
'type' => 'button', |
280
|
|
|
'class' => 'button btn_save', |
281
|
|
|
'value' => $label, |
282
|
|
|
'onclick' => 'saveForm(1)', |
283
|
|
|
); |
284
|
|
|
|
285
|
|
|
$save_button_atts = apply_filters( 'pods_showform_save_button_atts', $save_button_atts, $this ); |
286
|
|
|
$atts = ''; |
287
|
|
|
|
288
|
|
|
foreach ( $save_button_atts as $att => $value ) { |
289
|
|
|
$atts .= ' ' . esc_attr( $att ) . '="' . esc_attr( $value ) . '"'; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
$save_button = '<input ' . $atts . '/>'; |
293
|
|
|
?> |
294
|
|
|
<div> |
295
|
|
|
<input type="hidden" class="form num id" value="<?php echo esc_attr( $id ); ?>" /> |
296
|
|
|
<input type="hidden" class="form txt pod" value="<?php echo esc_attr( $pod ); ?>" /> |
297
|
|
|
<input type="hidden" class="form txt pod_id" value="<?php echo esc_attr( $pod_id ); ?>" /> |
298
|
|
|
<input type="hidden" class="form txt form_count" value="1" /> |
299
|
|
|
<input type="hidden" class="form txt token" value="<?php echo esc_attr( pods_generate_key( $pod, $uri_hash, $public_fields, 1 ) ); ?>" /> |
300
|
|
|
<input type="hidden" class="form txt uri_hash" value="<?php echo esc_attr( $uri_hash ); ?>" /> |
301
|
|
|
<?php echo apply_filters( 'pods_showform_save_button', $save_button, $save_button_atts, $this ); ?> |
302
|
|
|
</div> |
303
|
|
|
<?php |
304
|
|
|
do_action( 'pods_showform_post', $pod_id, $public_fields, $label, $this ); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Get pod or category drop-down values |
309
|
|
|
* |
310
|
|
|
* @param array $params |
311
|
|
|
* |
312
|
|
|
* @return array |
313
|
|
|
*/ |
314
|
|
|
public function get_dropdown_values( $params ) { |
315
|
|
|
|
316
|
|
|
if ( Pod::$deprecated_notice ) { |
317
|
|
|
pods_deprecated( 'Pods::get_dropdown_values', '2.0' ); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
global $wpdb; |
|
|
|
|
321
|
|
|
|
322
|
|
|
$params = (object) $params; |
323
|
|
|
|
324
|
|
|
$params->orderby = empty( $params->orderby ) ? '' : ' ORDER BY ' . $params->orderby; |
325
|
|
|
$params->join = empty( $params->join ) ? '' : ' LEFT JOIN ' . $params->join; |
326
|
|
|
|
327
|
|
|
$where = ( false !== $params->exclude ) ? "WHERE `t`.term_id NOT IN ({$params->exclude})" : ''; |
328
|
|
|
|
329
|
|
|
if ( ! empty( $params->pick_filter ) ) { |
330
|
|
|
$where .= ( empty( $where ) ? ' WHERE ' : ' AND ' ) . $params->pick_filter; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
if ( ! empty( $params->where ) ) { |
334
|
|
|
$where .= ( empty( $where ) ? ' WHERE ' : ' AND ' ) . $params->where; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
$sql = " |
338
|
|
|
SELECT |
339
|
|
|
`t`.`{$params->field_id}` AS `id`, |
340
|
|
|
`t`.`{$params->field_name}` AS `name` |
341
|
|
|
FROM `{$params->table}` AS `t` |
342
|
|
|
{$params->join} |
343
|
|
|
{$where} |
344
|
|
|
{$params->orderby} |
345
|
|
|
"; |
346
|
|
|
|
347
|
|
|
// override with custom dropdown values |
348
|
|
|
$sql = apply_filters( 'pods_get_dropdown_values', $sql, $params, $this ); |
349
|
|
|
|
350
|
|
|
$val = array(); |
351
|
|
|
$result = pods_query( $sql ); |
352
|
|
|
|
353
|
|
|
foreach ( $result as $row ) { |
354
|
|
|
$row = get_object_vars( $row ); |
355
|
|
|
$row['active'] = false; |
356
|
|
|
|
357
|
|
|
if ( ! empty( $params->selected_ids ) ) { |
358
|
|
|
$row['active'] = in_array( $row['id'], $params->selected_ids ); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
$val[] = $row; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
return $val; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Build public input form |
369
|
|
|
* |
370
|
|
|
* @deprecated deprecated since 2.0 |
371
|
|
|
* |
372
|
|
|
* @param null $fields |
373
|
|
|
* @param string $label |
374
|
|
|
* @param null $thankyou_url |
375
|
|
|
*/ |
376
|
|
|
public function publicForm( $fields = null, $label = 'Save Changes', $thankyou_url = null ) { |
|
|
|
|
377
|
|
|
|
378
|
|
|
if ( Pod::$deprecated_notice ) { |
379
|
|
|
pods_deprecated( 'Pods::publicForm', '2.0', 'Pods::form' ); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
if ( ! empty( $fields ) ) { |
383
|
|
|
// Just update field name here, form() will handle the rest |
384
|
|
|
foreach ( $fields as $k => $field ) { |
385
|
|
|
$name = $k; |
386
|
|
|
|
387
|
|
|
if ( ! is_array( $field ) ) { |
388
|
|
|
$name = $field; |
389
|
|
|
$field = array(); |
390
|
|
|
} elseif ( isset( $field['name'] ) ) { |
391
|
|
|
$name = $field['name']; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
if ( in_array( |
395
|
|
|
$name, array( |
396
|
|
|
'created', |
397
|
|
|
'modified', |
398
|
|
|
'author', |
399
|
|
|
), true |
400
|
|
|
) && isset( $this->obj->fields[ $name . '2' ] ) ) { |
401
|
|
|
$name .= '2'; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
$field['name'] = $name; |
405
|
|
|
|
406
|
|
|
$fields[ $k ] = $field; |
407
|
|
|
}//end foreach |
408
|
|
|
}//end if |
409
|
|
|
|
410
|
|
|
echo $this->obj->form( $fields, $label, $thankyou_url ); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Build HTML for a single field |
415
|
|
|
* |
416
|
|
|
* @deprecated deprecated since 2.0 |
417
|
|
|
* |
418
|
|
|
* @param array $field Field data. |
419
|
|
|
*/ |
420
|
|
|
public function build_field_html( $field ) { |
421
|
|
|
|
422
|
|
|
if ( Pod::$deprecated_notice ) { |
423
|
|
|
pods_deprecated( 'Pods::build_field_html', '2.0' ); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
include PODS_DIR . 'deprecated/input_fields.php'; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* Fetch a row of results from the DB |
431
|
|
|
* |
432
|
|
|
* @since 1.2.0 |
433
|
|
|
* @deprecated deprecated since 2.0 |
434
|
|
|
*/ |
435
|
|
|
public function fetchRecord() { |
|
|
|
|
436
|
|
|
|
437
|
|
|
if ( Pod::$deprecated_notice ) { |
438
|
|
|
pods_deprecated( 'Pods::fetchRecord', '2.0', 'Pods::fetch' ); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
return $this->obj->fetch(); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Return a field's value(s) |
446
|
|
|
* |
447
|
|
|
* @param string $name The field name |
448
|
|
|
* @param string $orderby (optional) The orderby string, for PICK fields |
|
|
|
|
449
|
|
|
* |
450
|
|
|
* @since 1.2.0 |
451
|
|
|
* @deprecated deprecated since version 2.0 |
452
|
|
|
* @return array|mixed |
453
|
|
|
*/ |
454
|
|
|
public function get_field( $name, $orderby = null ) { |
455
|
|
|
|
456
|
|
|
if ( Pod::$deprecated_notice ) { |
457
|
|
|
pods_deprecated( 'Pods::get_field', '2.0', 'Pods::field' ); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
$value = $this->obj->field( |
461
|
|
|
array( |
462
|
|
|
'name' => $name, |
463
|
|
|
'orderby' => $orderby, |
464
|
|
|
'deprecated' => true, |
465
|
|
|
) |
466
|
|
|
); |
467
|
|
|
|
468
|
|
|
if ( is_array( $value ) && ! empty( $value ) ) { |
469
|
|
|
if ( false === strpos( $name, '.' ) && ! isset( $value[0] ) ) { |
470
|
|
|
$value = array( $value ); |
471
|
|
|
} elseif ( false !== strpos( $name, '.' ) && 1 == count( $value ) ) { |
472
|
|
|
// fix for single tableless fields |
473
|
|
|
$value = current( $value ); |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
return $value; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* Get the current item's pod ID from its datatype ID and tbl_row_id |
482
|
|
|
* |
483
|
|
|
* @return int The ID from the wp_pod table |
484
|
|
|
* @since 1.2.0 |
485
|
|
|
* @deprecated deprecated since version 2.0 |
486
|
|
|
*/ |
487
|
|
|
public function get_pod_id() { |
488
|
|
|
|
489
|
|
|
if ( Pod::$deprecated_notice ) { |
490
|
|
|
pods_deprecated( 'Pods::get_pod_id', '2.0' ); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
if ( ! empty( $this->obj->row ) ) { |
494
|
|
|
return $this->obj->row[ $this->obj->data->field_id ]; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
return false; |
|
|
|
|
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* Search and filter records |
502
|
|
|
* |
503
|
|
|
* @since 1.x |
504
|
|
|
* @deprecated deprecated since version 2.0 |
505
|
|
|
* |
506
|
|
|
* @param null $orderby |
507
|
|
|
* @param int $rows_per_page |
508
|
|
|
* @param null $where |
509
|
|
|
* @param null $sql |
510
|
|
|
* |
511
|
|
|
* @return |
512
|
|
|
*/ |
513
|
|
|
public function findRecords( $orderby = null, $rows_per_page = 15, $where = null, $sql = null ) { |
|
|
|
|
514
|
|
|
|
515
|
|
|
if ( Pod::$deprecated_notice ) { |
516
|
|
|
pods_deprecated( 'Pods::findRecords', '2.0', 'Pods::find' ); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
$find = array( |
520
|
|
|
' p.created', |
521
|
|
|
'`p`.`created`', |
522
|
|
|
'`p`.created', |
523
|
|
|
' p.`created`', |
524
|
|
|
' p.modified', |
525
|
|
|
'`p`.`modified`', |
526
|
|
|
'`p`.modified', |
527
|
|
|
' p.`modified`', |
528
|
|
|
' p.id', |
529
|
|
|
'`p`.`id`', |
530
|
|
|
'`p`.id', |
531
|
|
|
' p.`id`', |
532
|
|
|
' p.pod_id', |
533
|
|
|
'`p`.`pod_id`', |
534
|
|
|
'`p`.pod_id', |
535
|
|
|
' p.`pod_id`', |
536
|
|
|
); |
537
|
|
|
|
538
|
|
|
$replace = array( |
539
|
|
|
' t.created', |
540
|
|
|
'`t`.`created`', |
541
|
|
|
'`t`.created', |
542
|
|
|
' t.`created`', |
543
|
|
|
' t.modified', |
544
|
|
|
'`t`.`modified`', |
545
|
|
|
'`t`.modified', |
546
|
|
|
' t.`modified`', |
547
|
|
|
' t.id', |
548
|
|
|
'`t`.`id`', |
549
|
|
|
'`t`.id', |
550
|
|
|
' t.`id`', |
551
|
|
|
' t.id', |
552
|
|
|
'`t`.`id`', |
553
|
|
|
'`t`.id', |
554
|
|
|
' t.`id`', |
555
|
|
|
); |
556
|
|
|
|
557
|
|
|
$params = array( |
558
|
|
|
'where' => $where, |
559
|
|
|
'orderby' => "`t`.`{$this->obj->data->field_id}` DESC", |
560
|
|
|
'limit' => (int) $rows_per_page, |
561
|
|
|
'page' => $this->obj->page, |
562
|
|
|
'search' => $this->obj->search, |
563
|
|
|
'search_across' => true, |
564
|
|
|
'search_across_picks' => false, |
565
|
|
|
'sql' => $sql, |
566
|
|
|
); |
567
|
|
|
|
568
|
|
|
if ( is_array( $orderby ) ) { |
569
|
|
|
$params = array_merge( $params, $orderby ); |
570
|
|
|
} elseif ( ! empty( $orderby ) ) { |
571
|
|
|
$params['orderby'] = $orderby; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
$params['where'] = trim( str_replace( $find, $replace, ' ' . $params['where'] ) ); |
575
|
|
|
$params['orderby'] = trim( str_replace( $find, $replace, ' ' . $params['orderby'] ) ); |
576
|
|
|
|
577
|
|
|
$params = (object) $params; |
578
|
|
|
|
579
|
|
|
$this->obj->limit = $params->limit; |
580
|
|
|
$this->obj->page = $params->page; |
581
|
|
|
$this->obj->search = $params->search; |
582
|
|
|
|
583
|
|
|
return $this->obj->find( $params ); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Return a single record |
588
|
|
|
* |
589
|
|
|
* @since 1.x |
590
|
|
|
* @deprecated deprecated since version 2.0 |
591
|
|
|
* |
592
|
|
|
* @param int $id Item ID. |
593
|
|
|
* |
594
|
|
|
* @return |
595
|
|
|
*/ |
596
|
|
|
public function getRecordById( $id ) { |
|
|
|
|
597
|
|
|
|
598
|
|
|
if ( Pod::$deprecated_notice ) { |
599
|
|
|
pods_deprecated( 'Pods::getRecordById', '2.0', 'Pods::fetch_item' ); |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
return $this->obj->fetch_item( $id ); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* Fetch the total row count |
607
|
|
|
* |
608
|
|
|
* @deprecated deprecated since version 2.0 |
609
|
|
|
*/ |
610
|
|
|
public function getTotalRows() { |
|
|
|
|
611
|
|
|
|
612
|
|
|
if ( Pod::$deprecated_notice ) { |
613
|
|
|
pods_deprecated( 'Pods::getTotalRows', '2.0', 'Pods::total_found' ); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
return $this->obj->total_found(); |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* (Re)set the MySQL result pointer |
621
|
|
|
* |
622
|
|
|
* @deprecated deprecated since version 2.0 |
623
|
|
|
* |
624
|
|
|
* @param int $row_number |
625
|
|
|
* |
626
|
|
|
* @return |
627
|
|
|
*/ |
628
|
|
|
public function resetPointer( $row_number = 0 ) { |
|
|
|
|
629
|
|
|
|
630
|
|
|
if ( Pod::$deprecated_notice ) { |
631
|
|
|
pods_deprecated( 'Pods::resetPointer', '2.0', 'Pods::reset' ); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
return $this->obj->reset( $row_number ); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* Display the pagination controls |
639
|
|
|
* |
640
|
|
|
* @deprecated deprecated since 2.0 |
641
|
|
|
* |
642
|
|
|
* @param string $label |
643
|
|
|
*/ |
644
|
|
|
public function getPagination( $label = 'Go to page:' ) { |
|
|
|
|
645
|
|
|
|
646
|
|
|
if ( Pod::$deprecated_notice ) { |
647
|
|
|
pods_deprecated( 'Pods::getPagination', '2.0', 'Pods::pagination' ); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
echo $this->obj->pagination( |
651
|
|
|
array( |
652
|
|
|
'type' => 'advanced', |
653
|
|
|
'label' => $label, |
654
|
|
|
) |
655
|
|
|
); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* Display the list filters |
660
|
|
|
* |
661
|
|
|
* @deprecated deprecated since 2.0 |
662
|
|
|
* |
663
|
|
|
* @param null $filters |
664
|
|
|
* @param string $label |
665
|
|
|
* @param string $action |
666
|
|
|
*/ |
667
|
|
|
public function getFilters( $filters = null, $label = 'Filter', $action = '' ) { |
|
|
|
|
668
|
|
|
|
669
|
|
|
if ( Pod::$deprecated_notice ) { |
670
|
|
|
pods_deprecated( 'Pods::getFilters', '2.0', 'Pods::filters' ); |
671
|
|
|
} |
672
|
|
|
|
673
|
|
|
$params = array( |
674
|
|
|
'fields' => $filters, |
675
|
|
|
'label' => $label, |
676
|
|
|
'action' => $action, |
677
|
|
|
); |
678
|
|
|
|
679
|
|
|
if ( is_array( $filters ) ) { |
680
|
|
|
$params = array_merge( $params, $filters ); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
echo $this->obj->filters( $params ); |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
/** |
687
|
|
|
* Run a helper within a Pod Page or WP Template |
688
|
|
|
* |
689
|
|
|
* @param string $helper_name Helper name. |
690
|
|
|
* @param null|string|array $value Field value. |
691
|
|
|
* @param null|string $name Field name. |
692
|
|
|
* |
693
|
|
|
* @return mixed Anything returned by the helper |
694
|
|
|
* @internal param string $helper The helper name |
695
|
|
|
* |
696
|
|
|
* @since 1.2.0 |
697
|
|
|
* @deprecated deprecated since version 2.0 |
698
|
|
|
*/ |
699
|
|
|
public function pod_helper( $helper_name, $value = null, $name = null ) { |
700
|
|
|
|
701
|
|
|
if ( Pod::$deprecated_notice ) { |
702
|
|
|
pods_deprecated( 'Pods::pod_helper', '2.0', 'Pods::helper' ); |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
$params = array( |
706
|
|
|
'helper' => $helper_name, |
707
|
|
|
'value' => $value, |
708
|
|
|
'name' => $name, |
709
|
|
|
'deprecated' => true, |
710
|
|
|
); |
711
|
|
|
|
712
|
|
|
return $this->obj->helper( $params ); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
/** |
716
|
|
|
* Display the page template |
717
|
|
|
* |
718
|
|
|
* @deprecated deprecated since version 2.0 |
719
|
|
|
* |
720
|
|
|
* @param string $template_name Template name. |
721
|
|
|
* @param null|string $code Template code override. |
722
|
|
|
* |
723
|
|
|
* @return |
724
|
|
|
*/ |
725
|
|
|
public function showTemplate( $template_name, $code = null ) { |
|
|
|
|
726
|
|
|
|
727
|
|
|
if ( Pod::$deprecated_notice ) { |
728
|
|
|
pods_deprecated( 'Pods::showTemplate', '2.0', 'Pods::template' ); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
return $this->obj->template( $template_name, $code, true ); |
732
|
|
|
} |
733
|
|
|
} |
734
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.