]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/compat.php
Wordpress 2.3.3
[autoinstalls/wordpress.git] / wp-includes / compat.php
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         ob_end_clean();
48         return $code;
49 }
50
51 /* compatibility with PHP versions older than 4.3 */
52 if ( !function_exists('file_get_contents') ) {
53         function file_get_contents( $file ) {
54                 $file = file($file);
55                 return !$file ? false : implode('', $file);
56         }
57 }
58
59 if (!defined('CASE_LOWER')) {
60                 define('CASE_LOWER', 0);
61 }
62
63 if (!defined('CASE_UPPER')) {
64                 define('CASE_UPPER', 1);
65 }
66
67
68 /**
69  * Replace array_change_key_case()
70  *
71  * @category    PHP
72  * @package     PHP_Compat
73  * @link        http://php.net/function.array_change_key_case
74  * @author      Stephan Schmidt <schst@php.net>
75  * @author      Aidan Lister <aidan@php.net>
76  * @version     $Revision: 6070 $
77  * @since       PHP 4.2.0
78  * @require     PHP 4.0.0 (user_error)
79  */
80 if (!function_exists('array_change_key_case')) {
81                 function array_change_key_case($input, $case = CASE_LOWER)
82                 {
83                                 if (!is_array($input)) {
84                                                 user_error('array_change_key_case(): The argument should be an array',
85                                                                 E_USER_WARNING);
86                                                 return false;
87                                 }
88
89                                 $output   = array ();
90                                 $keys     = array_keys($input);
91                                 $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper';
92
93                                 foreach ($keys as $key) {
94                                                 $output[$casefunc($key)] = $input[$key];
95                                 }
96
97                                 return $output;
98                 }
99 }
100
101 if (!function_exists('http_build_query')) {
102         function http_build_query($data, $prefix=null, $sep=null) {
103                 return _http_build_query($data, $prefix, $sep);
104         }
105 }
106
107 // from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
108 function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
109         $ret = array();
110
111         foreach ( (array) $data as $k => $v ) {
112                 if ( $urlencode)
113                         $k = urlencode($k);
114                 if ( is_int($k) && $prefix != null )
115                         $k = $prefix.$k;
116                 if ( !empty($key) )
117                         $k = $key . '%5B' . $k . '%5D';
118                 if ( $v === NULL )
119                         continue;
120                 elseif ( $v === FALSE )
121                         $v = '0';
122
123                 if ( is_array($v) || is_object($v) )
124                         array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
125                 elseif ( $urlencode )
126                         array_push($ret, $k.'='.urlencode($v));
127                 else
128                         array_push($ret, $k.'='.$v);
129         }
130
131         if ( NULL === $sep )
132                 $sep = ini_get('arg_separator.output');
133
134         return implode($sep, $ret);
135 }
136
137 if ( !function_exists('_') ) {
138         function _($string) {
139                 return $string;
140         }
141 }
142
143 // Added in PHP 5.0
144 if (!function_exists('stripos')) {
145         function stripos($haystack, $needle, $offset = 0) {
146                 return strpos(strtolower($haystack), strtolower($needle), $offset);
147         }
148 }
149
150 ?>