[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: compatibility.php 3 2006-05-27 04:59:07Z user $ 4 5 osCMax Power E-Commerce 6 http://oscdox.com 7 8 Copyright 2006 osCMax 9 10 Released under the GNU General Public License 11 */ 12 13 //// 14 // Recursively handle magic_quotes_gpc turned off. 15 // This is due to the possibility of have an array in 16 // $HTTP_xxx_VARS 17 // Ie, products attributes 18 function do_magic_quotes_gpc(&$ar) { 19 if (!is_array($ar)) return false; 20 21 reset($ar); 22 while (list($key, $value) = each($ar)) { 23 if (is_array($ar[$key])) { 24 do_magic_quotes_gpc($ar[$key]); 25 } else { 26 $ar[$key] = addslashes($value); 27 } 28 } 29 reset($ar); 30 } 31 32 if (PHP_VERSION >= 4.1) { 33 $HTTP_GET_VARS =& $_GET; 34 $HTTP_POST_VARS =& $_POST; 35 $HTTP_COOKIE_VARS =& $_COOKIE; 36 $HTTP_SESSION_VARS =& $_SESSION; 37 $HTTP_POST_FILES =& $_FILES; 38 $HTTP_SERVER_VARS =& $_SERVER; 39 } else { 40 if (!is_array($HTTP_GET_VARS)) $HTTP_GET_VARS = array(); 41 if (!is_array($HTTP_POST_VARS)) $HTTP_POST_VARS = array(); 42 if (!is_array($HTTP_COOKIE_VARS)) $HTTP_COOKIE_VARS = array(); 43 } 44 45 // handle magic_quotes_gpc turned off. 46 if (!get_magic_quotes_gpc()) { 47 do_magic_quotes_gpc($HTTP_GET_VARS); 48 do_magic_quotes_gpc($HTTP_POST_VARS); 49 do_magic_quotes_gpc($HTTP_COOKIE_VARS); 50 } 51 52 if (!function_exists('is_numeric')) { 53 function is_numeric($param) { 54 return ereg("^[0-9]{1,50}.?[0-9]{0,50}$", $param); 55 } 56 } 57 58 if (!function_exists('is_uploaded_file')) { 59 function is_uploaded_file($filename) { 60 if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { 61 $tmp_file = dirname(tempnam('', '')); 62 } 63 64 if (strchr($tmp_file, '/')) { 65 if (substr($tmp_file, -1) != '/') $tmp_file .= '/'; 66 } elseif (strchr($tmp_file, '\\')) { 67 if (substr($tmp_file, -1) != '\\') $tmp_file .= '\\'; 68 } 69 70 return file_exists($tmp_file . basename($filename)); 71 } 72 } 73 74 if (!function_exists('move_uploaded_file')) { 75 function move_uploaded_file($file, $target) { 76 return copy($file, $target); 77 } 78 } 79 80 if (!function_exists('checkdnsrr')) { 81 function checkdnsrr($host, $type) { 82 if(tep_not_null($host) && tep_not_null($type)) { 83 @exec("nslookup -type=$type $host", $output); 84 while(list($k, $line) = each($output)) { 85 if(eregi("^$host", $line)) { 86 return true; 87 } 88 } 89 } 90 return false; 91 } 92 } 93 94 if (!function_exists('in_array')) { 95 function in_array($lookup_value, $lookup_array) { 96 reset($lookup_array); 97 while (list($key, $value) = each($lookup_array)) { 98 if ($value == $lookup_value) return true; 99 } 100 101 return false; 102 } 103 } 104 105 if (!function_exists('array_merge')) { 106 function array_merge($array1, $array2, $array3 = '') { 107 if ($array3 == '') $array3 = array(); 108 109 while (list($key, $val) = each($array1)) $array_merged[$key] = $val; 110 while (list($key, $val) = each($array2)) $array_merged[$key] = $val; 111 112 if (sizeof($array3) > 0) while (list($key, $val) = each($array3)) $array_merged[$key] = $val; 113 114 return (array)$array_merged; 115 } 116 } 117 118 if (!function_exists('array_shift')) { 119 function array_shift(&$array) { 120 $i = 0; 121 $shifted_array = array(); 122 reset($array); 123 while (list($key, $value) = each($array)) { 124 if ($i > 0) { 125 $shifted_array[$key] = $value; 126 } else { 127 $return = $array[$key]; 128 } 129 $i++; 130 } 131 $array = $shifted_array; 132 133 return $return; 134 } 135 } 136 137 if (!function_exists('array_reverse')) { 138 function array_reverse($array) { 139 $reversed_array = array(); 140 141 for ($i=sizeof($array)-1; $i>=0; $i--) { 142 $reversed_array[] = $array[$i]; 143 } 144 145 return $reversed_array; 146 } 147 } 148 149 if (!function_exists('array_slice')) { 150 function array_slice($array, $offset, $length = '0') { 151 $length = abs($length); 152 153 if ($length == 0) { 154 $high = sizeof($array); 155 } else { 156 $high = $offset+$length; 157 } 158 159 for ($i=$offset; $i<$high; $i++) { 160 $new_array[$i-$offset] = $array[$i]; 161 } 162 163 return $new_array; 164 } 165 } 166 /* 167 * http_build_query() natively supported from PHP 5.0 168 * From Pear::PHP_Compat 169 */ 170 171 if ( !function_exists('http_build_query') && (PHP_VERSION >= 4)) { 172 function http_build_query($formdata, $numeric_prefix = null, $arg_separator = null) { 173 // If $formdata is an object, convert it to an array 174 if ( is_object($formdata) ) { 175 $formdata = get_object_vars($formdata); 176 } 177 178 // Check we have an array to work with 179 if ( !is_array($formdata) || !empty($formdata) ) { 180 return false; 181 } 182 183 // Argument seperator 184 if ( empty($arg_separator) ) { 185 $arg_separator = ini_get('arg_separator.output'); 186 187 if ( empty($arg_separator) ) { 188 $arg_separator = '&'; 189 } 190 } 191 192 // Start building the query 193 $tmp = array(); 194 195 foreach ( $formdata as $key => $val ) { 196 if ( is_null($val) ) { 197 continue; 198 } 199 200 if ( is_integer($key) && ( $numeric_prefix != null ) ) { 201 $key = $numeric_prefix . $key; 202 } 203 204 if ( is_scalar($val) ) { 205 array_push($tmp, urlencode($key) . '=' . urlencode($val)); 206 continue; 207 } 208 209 // If the value is an array, recursively parse it 210 if ( is_array($val) || is_object($val) ) { 211 array_push($tmp, http_build_query_helper($val, urlencode($key), $arg_separator)); 212 continue; 213 } 214 215 // The value is a resource 216 return null; 217 } 218 219 return implode($arg_separator, $tmp); 220 } 221 222 // Helper function 223 function http_build_query_helper($array, $name, $arg_separator) { 224 $tmp = array(); 225 226 foreach ( $array as $key => $value ) { 227 if ( is_array($value) ) { 228 array_push($tmp, http_build_query_helper($value, sprintf('%s[%s]', $name, $key), $arg_separator)); 229 } elseif ( is_scalar($value) ) { 230 array_push($tmp, sprintf('%s[%s]=%s', $name, urlencode($key), urlencode($value))); 231 } elseif ( is_object($value) ) { 232 array_push($tmp, http_build_query_helper(get_object_vars($value), sprintf('%s[%s]', $name, $key), $arg_separator)); 233 } 234 } 235 236 return implode($arg_separator, $tmp); 237 } 238 } 239 /* 240 * stripos() natively supported from PHP 5.0 241 * From Pear::PHP_Compat 242 */ 243 244 if (!function_exists('stripos')) { 245 function stripos($haystack, $needle, $offset = null) { 246 $fix = 0; 247 248 if (!is_null($offset)) { 249 if ($offset > 0) { 250 $haystack = substr($haystack, $offset, strlen($haystack) - $offset); 251 $fix = $offset; 252 } 253 } 254 255 $segments = explode(strtolower($needle), strtolower($haystack), 2); 256 257 // Check there was a match 258 if (count($segments) == 1) { 259 return false; 260 } 261 262 $position = strlen($segments[0]) + $fix; 263 264 return $position; 265 } 266 } 267 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |