1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @package Pods\Deprecated |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
// JSON support |
11
|
|
|
if ( !function_exists( 'json_encode' ) ) { |
12
|
|
|
require_once( ABSPATH . '/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php' ); |
13
|
|
|
|
14
|
|
|
function json_encode ($str) { |
15
|
|
|
$json = new Moxiecode_JSON(); |
16
|
|
|
return $json->encode($str); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function json_decode ($str) { |
20
|
|
|
$json = new Moxiecode_JSON(); |
21
|
|
|
return $json->decode($str); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// WP 3.4.x support |
26
|
|
|
if ( !function_exists( 'wp_send_json' ) ) { |
27
|
|
|
function wp_send_json ( $response ) { |
28
|
|
|
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
29
|
|
|
echo json_encode( $response ); |
30
|
|
|
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
31
|
|
|
wp_die(); |
32
|
|
|
else |
33
|
|
|
die; |
|
|
|
|
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get the full URL of the current page |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
* @since 1.9.6 |
42
|
|
|
* |
43
|
|
|
* @deprecated 2.3 |
44
|
|
|
*/ |
45
|
|
|
if ( !function_exists( 'get_current_url' ) ) { |
46
|
|
|
/** |
47
|
|
|
* @return mixed|void |
48
|
|
|
*/ |
49
|
|
|
function get_current_url() { |
50
|
|
|
$url = pods_current_url(); |
51
|
|
|
|
52
|
|
|
return apply_filters( 'get_current_url', $url ); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Mapping function to new function name (following normalization of function names from pod_ to pods_) |
58
|
|
|
* |
59
|
|
|
* @since 1.x |
60
|
|
|
* @deprecated deprecated since version 2.0 |
61
|
|
|
* |
62
|
|
|
* @return array|bool|mixed|null|void Result of the query |
63
|
|
|
*/ |
64
|
|
|
function pod_query ($sql, $error = 'SQL failed', $results_error = null, $no_results_error = null) { |
65
|
|
|
pods_deprecated('pod_query', '2.0', 'pods_query'); |
66
|
|
|
global $wpdb; |
|
|
|
|
67
|
|
|
|
68
|
|
|
$sql = trim($sql); |
69
|
|
|
|
70
|
|
|
// Using @wp_users is deprecated! use $wpdb->users instead! |
71
|
|
|
$sql = str_replace( '@wp_pod_tbl_', $wpdb->prefix . 'pods_', $sql ); |
72
|
|
|
$sql = str_replace( '@wp_users', $wpdb->users, $sql ); |
73
|
|
|
$sql = str_replace( '@wp_', $wpdb->prefix, $sql ); |
74
|
|
|
$sql = str_replace( '{prefix}', '@wp_', $sql ); |
75
|
|
|
|
76
|
|
|
$sql = apply_filters( 'pod_query', $sql, $error, $results_error, $no_results_error ); |
77
|
|
|
|
78
|
|
|
$result = pods_query( $sql, $error, $results_error, $no_results_error ); |
79
|
|
|
|
80
|
|
|
$result = apply_filters('pod_query_return', $result, $sql, $error, $results_error, $no_results_error); |
81
|
|
|
|
82
|
|
|
return $result; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Include and Init the Pods class |
87
|
|
|
* |
88
|
|
|
* @since 1.x |
89
|
|
|
* @deprecated deprecated since version 2.0 |
90
|
|
|
* @package Pods\Deprecated |
91
|
|
|
*/ |
92
|
|
|
class Pod |
93
|
|
|
{ |
94
|
|
|
private $new; |
95
|
|
|
|
96
|
|
|
public static $deprecated_notice = true; |
97
|
|
|
|
98
|
|
|
public $body_classes; |
99
|
|
|
|
100
|
|
|
public $ui = array(); |
101
|
|
|
|
102
|
|
|
public $meta = array(); |
103
|
|
|
|
104
|
|
|
public $meta_properties = array(); |
105
|
|
|
|
106
|
|
|
public $meta_extra = ''; |
107
|
|
|
|
108
|
|
|
function __construct ($type = null, $id = null) { |
|
|
|
|
109
|
|
|
if ( self::$deprecated_notice ) { |
110
|
|
|
pods_deprecated( 'PodAPI (class)', '2.0', 'pods_api (function)' ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
pods_deprecated('Pod (class)', '2.0', 'pods (function)'); |
114
|
|
|
|
115
|
|
|
$this->new = pods( $type, $id ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Handle variables that have been deprecated |
120
|
|
|
* |
121
|
|
|
* @since 2.0 |
122
|
|
|
*/ |
123
|
|
|
public function __get ( $name ) { |
124
|
|
|
$name = (string) $name; |
125
|
|
|
|
126
|
|
|
if ( 'data' == $name ) { |
127
|
|
|
if ( self::$deprecated_notice ) { |
128
|
|
|
pods_deprecated( "Pods->{$name}", '2.0', "Pods->row()" ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$var = $this->new->row(); |
132
|
|
|
} |
133
|
|
|
elseif ( '_data' == $name ) |
134
|
|
|
$var = $this->new->data; |
135
|
|
|
elseif ( 'total' == $name ) { |
136
|
|
|
if ( self::$deprecated_notice ) { |
137
|
|
|
pods_deprecated( "Pods->{$name}", '2.0', "Pods->total()" ); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$var = $this->new->total(); |
141
|
|
|
} |
142
|
|
|
elseif ( 'total_rows' == $name ) { |
143
|
|
|
if ( self::$deprecated_notice ) { |
144
|
|
|
pods_deprecated( "Pods->{$name}", '2.0', "Pods->total_found()" ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$var = $this->new->total_found(); |
148
|
|
|
} |
149
|
|
|
elseif ( 'zebra' == $name ) { |
150
|
|
|
if ( self::$deprecated_notice ) { |
151
|
|
|
pods_deprecated( "Pods->{$name}", '2.0', "Pods->zebra()" ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$var = $this->new->zebra(); |
155
|
|
|
} |
156
|
|
|
else |
157
|
|
|
$var = $this->new->{$name}; |
158
|
|
|
|
159
|
|
|
return $var; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Handle variables that have been deprecated |
164
|
|
|
* |
165
|
|
|
* @since 2.0 |
166
|
|
|
*/ |
167
|
|
|
public function __set ( $name, $value ) { |
168
|
|
|
$name = (string) $name; |
169
|
|
|
|
170
|
|
|
$this->new->{$name} = $value; |
171
|
|
|
|
172
|
|
|
return $value; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Handle methods that have been deprecated |
177
|
|
|
* |
178
|
|
|
* @since 2.0 |
179
|
|
|
*/ |
180
|
|
|
public function __call ( $name, $args ) { |
181
|
|
|
$name = (string) $name; |
182
|
|
|
|
183
|
|
|
return call_user_func_array( array( $this->new, $name ), $args ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Handle variables that have been deprecated |
188
|
|
|
* |
189
|
|
|
* @since 2.0 |
190
|
|
|
*/ |
191
|
|
|
public function __isset ( $name ) { |
192
|
|
|
$name = (string) $name; |
193
|
|
|
|
194
|
|
|
if ( in_array( $name, array( '_data', 'data', 'total', 'total_rows', 'zebra' ) ) ) |
195
|
|
|
return true; |
196
|
|
|
elseif ( in_array( $name, array( 'meta', 'meta_properties', 'meta_extra' ) ) ) |
197
|
|
|
return true; |
198
|
|
|
else |
199
|
|
|
return isset( $this->new->{$name} ); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Include and Init the PodsAPI class |
205
|
|
|
* |
206
|
|
|
* @since 1.x |
207
|
|
|
* @deprecated deprecated since version 2.0 |
208
|
|
|
* @package Pods\Deprecated |
209
|
|
|
*/ |
210
|
|
|
class PodAPI |
211
|
|
|
{ |
212
|
|
|
private $new; |
213
|
|
|
|
214
|
|
|
public static $deprecated_notice = true; |
215
|
|
|
|
216
|
|
|
function __construct ( $type = null, $format = null ) { |
|
|
|
|
217
|
|
|
if ( self::$deprecated_notice ) { |
218
|
|
|
pods_deprecated( 'PodAPI (class)', '2.0', 'pods_api (function)' ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
$this->new = pods_api( $type, $format ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Handle variables that have been deprecated |
226
|
|
|
* |
227
|
|
|
* @since 2.0 |
228
|
|
|
*/ |
229
|
|
|
public function __get ( $name ) { |
230
|
|
|
$name = (string) $name; |
231
|
|
|
|
232
|
|
|
$var = $this->new->{$name}; |
233
|
|
|
|
234
|
|
|
return $var; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Handle methods that have been deprecated |
239
|
|
|
* |
240
|
|
|
* @since 2.0 |
241
|
|
|
*/ |
242
|
|
|
public function __call ( $name, $args ) { |
243
|
|
|
$name = (string) $name; |
244
|
|
|
|
245
|
|
|
return call_user_func_array( array( $this->new, $name ), $args ); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Include and Init the PodsUI class |
251
|
|
|
* |
252
|
|
|
* @since 2.0 |
253
|
|
|
* @deprecated deprecated since version 2.0 |
254
|
|
|
*/ |
255
|
|
|
function pods_ui_manage ($obj) { |
256
|
|
|
pods_deprecated('pods_ui_manage', '2.0', 'pods_ui'); |
257
|
|
|
|
258
|
|
|
return pods_ui($obj, true); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Limit Access based on Field Value |
264
|
|
|
* |
265
|
|
|
* @since 1.x |
266
|
|
|
* @deprecated deprecated since version 2.0 |
267
|
|
|
*/ |
268
|
|
|
function pods_ui_access ($object, $access, $what) { |
|
|
|
|
269
|
|
|
pods_deprecated('pods_ui_access', '2.0'); |
270
|
|
|
if (is_array($access)) { |
271
|
|
|
foreach ($access as $field => $match) { |
272
|
|
|
if (is_array($match)) { |
273
|
|
|
$okay = false; |
274
|
|
|
foreach ($match as $the_field => $the_match) { |
275
|
|
|
if ($object->get_field($the_field) == $the_match) |
276
|
|
|
$okay = true; |
277
|
|
|
} |
278
|
|
|
if (false === $okay) |
279
|
|
|
return false; |
280
|
|
|
} |
281
|
|
|
elseif ($object->get_field($field) != $match) |
282
|
|
|
return false; |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
return true; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Return a GET, POST, COOKIE, SESSION, or URI string segment |
290
|
|
|
* |
291
|
|
|
* @param mixed $key The variable name or URI segment position |
292
|
|
|
* @param string $type (optional) "uri", "get", "post", "request", "server", "session", or "cookie" |
293
|
|
|
* @return string The requested value, or null |
294
|
|
|
* @since 1.6.2 |
295
|
|
|
* @deprecated deprecated since version 2.0 |
296
|
|
|
*/ |
297
|
|
|
function pods_url_variable ($key = 'last', $type = 'url') { |
298
|
|
|
$output = apply_filters('pods_url_variable', pods_var($key, $type), $key, $type); |
299
|
|
|
return $output; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Generate form key - INTERNAL USE |
304
|
|
|
* |
305
|
|
|
* @since 1.2.0 |
306
|
|
|
* @deprecated deprecated since version 2.0 |
307
|
|
|
*/ |
308
|
|
|
function pods_generate_key( $datatype, $uri_hash, $columns, $form_count = 1 ) { |
309
|
|
|
$token = wp_create_nonce( 'pods-form-' . $datatype . '-' . (int) $form_count . '-' . $uri_hash . '-' . json_encode( $columns ) ); |
310
|
|
|
$token = apply_filters( 'pods_generate_key', $token, $datatype, $uri_hash, $columns, (int) $form_count ); |
311
|
|
|
$_SESSION[ 'pods_form_' . $token ] = $columns; |
312
|
|
|
return $token; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Validate form key - INTERNAL USE |
317
|
|
|
* |
318
|
|
|
* @since 1.2.0 |
319
|
|
|
* @deprecated deprecated since version 2.0 |
320
|
|
|
*/ |
321
|
|
|
function pods_validate_key( $token, $datatype, $uri_hash, $columns = null, $form_count = 1 ) { |
322
|
|
|
if ( null === $columns && !empty( $_SESSION ) && isset( $_SESSION[ 'pods_form_' . $token ] ) ) |
323
|
|
|
$columns = $_SESSION[ 'pods_form_' . $token ]; |
324
|
|
|
$success = false; |
325
|
|
|
if ( false !== wp_verify_nonce( $token, 'pods-form-' . $datatype . '-' . (int) $form_count . '-' . $uri_hash . '-' . json_encode( $columns ) ) ) |
326
|
|
|
$success = $columns; |
327
|
|
|
return apply_filters( 'pods_validate_key', $success, $token, $datatype, $uri_hash, $columns, (int) $form_count ); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Output a message in the WP Dashboard UI |
332
|
|
|
* |
333
|
|
|
* @param string $message |
334
|
|
|
* @param bool $error Whether or not it is an error message |
335
|
|
|
* |
336
|
|
|
* @return bool |
337
|
|
|
* |
338
|
|
|
* @since 1.12 |
339
|
|
|
* @deprcated 2.3 |
340
|
|
|
*/ |
341
|
|
|
function pods_ui_message ( $message, $error = false ) { |
342
|
|
|
pods_deprecated( "pods_message", '2.3' ); |
343
|
|
|
|
344
|
|
|
pods_message( $message, ( $error ? 'error' : 'notice' ) ); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Output an error in the WP Dashboard UI |
349
|
|
|
* |
350
|
|
|
* @param string $message |
351
|
|
|
* |
352
|
|
|
* @return bool |
353
|
|
|
* |
354
|
|
|
* @since 1.12 |
355
|
|
|
* @deprcated 2.3 |
356
|
|
|
*/ |
357
|
|
|
function pods_ui_error ( $message ) { |
358
|
|
|
pods_deprecated( "pods_message", '2.3' ); |
359
|
|
|
|
360
|
|
|
pods_message( $message, 'error' ); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Get a Point value from a Pods Version number |
365
|
|
|
* |
366
|
|
|
* @since 1.10.1 |
367
|
|
|
* @deprcated 2.3 |
368
|
|
|
*/ |
369
|
|
|
function pods_point_to_version ( $point ) { |
370
|
|
|
$version_tmp = explode( '.', $point ); |
371
|
|
|
$version = ''; |
372
|
|
|
|
373
|
|
|
for ( $x = 0; $x < 3; $x++ ) { // 3 points max - MAJOR.MINOR.PATCH |
374
|
|
|
if ( !isset( $version_tmp[ $x ] ) || strlen( $version_tmp[ $x ] ) < 1 ) |
375
|
|
|
$version_tmp[ $x ] = '000'; |
376
|
|
|
|
377
|
|
|
$version_temp = str_split( $version_tmp[ $x ] ); |
378
|
|
|
|
379
|
|
|
if ( 3 == count( $version_temp ) ) |
380
|
|
|
$version .= $version_tmp[ $x ]; |
381
|
|
|
elseif ( 2 == count( $version_temp ) ) |
382
|
|
|
$version .= '0' . $version_tmp[ $x ]; |
383
|
|
|
elseif ( 1 == count( $version_temp ) ) |
384
|
|
|
$version .= '00' . $version_tmp[ $x ]; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
$version = (int) $version; |
388
|
|
|
|
389
|
|
|
return $version; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Get a Point value from a Pods Version number |
394
|
|
|
* |
395
|
|
|
* @since 1.10 |
396
|
|
|
* @deprcated 2.3 |
397
|
|
|
*/ |
398
|
|
|
function pods_version_to_point ( $version ) { |
399
|
|
|
$point_tmp = $version; |
400
|
|
|
|
401
|
|
|
if ( strlen( $point_tmp ) < 9 ) { |
402
|
|
|
if ( 8 == strlen( $point_tmp ) ) |
403
|
|
|
$point_tmp = '0' . $point_tmp; |
404
|
|
|
|
405
|
|
|
if ( 7 == strlen( $point_tmp ) ) |
406
|
|
|
$point_tmp = '00' . $point_tmp; |
407
|
|
|
|
408
|
|
|
if ( 3 == strlen( $version ) ) // older versions prior to 1.9.9 |
409
|
|
|
return implode( '.', str_split( $version ) ); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
$point_tmp = str_split( $point_tmp, 3 ); |
413
|
|
|
$point = array(); |
414
|
|
|
|
415
|
|
|
foreach ( $point_tmp as $the_point ) { |
416
|
|
|
$point[] = (int) $the_point; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
$point = implode( '.', $point ); |
420
|
|
|
|
421
|
|
|
return $point; |
422
|
|
|
} |
423
|
|
|
|
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.