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