root/tags/2.0.9/wp-includes/functions-compat.php

Revision 3771, 2.6 kB (checked in by ryan, 3 years ago)

Backport nonces and pluggable cookies.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 /* Functions missing from older PHP versions */
4
5
6 /* Added in PHP 4.2.0 */
7
8 if (!function_exists('floatval')) {
9     function floatval($string) {
10         return ((float) $string);
11     }
12 }
13
14 if (!function_exists('is_a')) {
15     function is_a($object, $class) {
16         // by Aidan Lister <aidan@php.net>
17         if (get_class($object) == strtolower($class)) {
18             return true;
19         } else {
20             return is_subclass_of($object, $class);
21         }
22     }
23 }
24
25 if (!function_exists('ob_clean')) {
26     function ob_clean() {
27         // by Aidan Lister <aidan@php.net>
28         if (@ob_end_clean()) {
29             return ob_start();
30         }
31         return false;
32     }
33 }
34
35
36 /* Added in PHP 4.3.0 */
37
38 function printr($var, $do_not_echo = false) {
39     // from php.net/print_r user contributed notes
40     ob_start();
41     print_r($var);
42     $code htmlentities(ob_get_contents());
43     ob_clean();
44     if (!$do_not_echo) {
45       echo "<pre>$code</pre>";
46     }
47     return $code;
48 }
49
50 /* compatibility with PHP versions older than 4.3 */
51 if ( !function_exists('file_get_contents') ) {
52     function file_get_contents( $file ) {
53         $file = file($file);
54         return !$file ? false : implode('', $file);
55     }
56 }
57
58 if (!defined('CASE_LOWER')) {
59     define('CASE_LOWER', 0);
60 }
61
62 if (!defined('CASE_UPPER')) {
63     define('CASE_UPPER', 1);
64 }
65
66
67 /**
68  * Replace array_change_key_case()
69  *
70  * @category    PHP
71  * @package     PHP_Compat
72  * @link        http://php.net/function.array_change_key_case
73  * @author      Stephan Schmidt <schst@php.net>
74  * @author      Aidan Lister <aidan@php.net>
75  * @version     $Revision$
76  * @since       PHP 4.2.0
77  * @require     PHP 4.0.0 (user_error)
78  */
79 if (!function_exists('array_change_key_case')) {
80     function array_change_key_case($input, $case = CASE_LOWER)
81     {
82         if (!is_array($input)) {
83             user_error('array_change_key_case(): The argument should be an array',
84                 E_USER_WARNING);
85             return false;
86         }
87
88         $output   = array ();
89         $keys     = array_keys($input);
90         $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper';
91
92         foreach ($keys as $key) {
93             $output[$casefunc($key)] = $input[$key];
94         }
95
96         return $output;
97     }
98 }
99
100 // From php.net
101 if(!function_exists('http_build_query')) {
102    function http_build_query( $formdata, $numeric_prefix = null, $key = null ) {
103        $res = array();
104        foreach ((array)$formdata as $k=>$v) {
105            $tmp_key = urlencode(is_int($k) ? $numeric_prefix.$k : $k);
106            if ($key) $tmp_key = $key.'['.$tmp_key.']';
107            $res[] = ( ( is_array($v) || is_object($v) ) ? http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) );
108        }
109        $separator = ini_get('arg_separator.output');
110        return implode($separator, $res);
111    }
112 }
113 ?>
114
Note: See TracBrowser for help on using the browser.