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