Quick Search:

View

Revision:

Diff

Diff from 1838 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/oscommerce2/trunk/catalog/admin/includes/functions/compatibility.php

Annotated File View

hpdl
477
1 <?php
2 /*
hpdl
1739
3   $Id: compatibility.php 1838 2008-12-12 10:54:24Z hpdl $
hpdl
477
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1583
8   Copyright (c) 2007 osCommerce
hpdl
477
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
hpdl
1589
21     reset($ar);
hpdl
477
22     while (list($key, $value) = each($ar)) {
hpdl
706
23       if (is_array($ar[$key])) {
24         do_magic_quotes_gpc($ar[$key]);
hpdl
477
25       } else {
26         $ar[$key] = addslashes($value);
27       }
28     }
hpdl
1589
29     reset($ar);
hpdl
477
30   }
31
hpdl
1583
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;
hpdl
1599
37     $HTTP_POST_FILES =& $_FILES;
hpdl
1583
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   }
hpdl
477
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)) {
hpdl
1838
83         @exec("nslookup -type=" . escapeshellarg($type) . " " . escapeshellarg($host), $output);
hpdl
477
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   }
hpdl
1610
166
167 /*
168  * http_build_query() natively supported from PHP 5.0
169  * From Pear::PHP_Compat
170  */
171
172   if ( !function_exists('http_build_query') && (PHP_VERSION >= 4)) {
173     function http_build_query($formdata, $numeric_prefix = null, $arg_separator = null) {
174 // If $formdata is an object, convert it to an array
175       if ( is_object($formdata) ) {
176         $formdata = get_object_vars($formdata);
177       }
178
179 // Check we have an array to work with
180       if ( !is_array($formdata) || !empty($formdata) ) {
181         return false;
182       }
183
184 // Argument seperator
185       if ( empty($arg_separator) ) {
186         $arg_separator = ini_get('arg_separator.output');
187
188         if ( empty($arg_separator) ) {
hpdl
1748
189           $arg_separator = '&';
hpdl
1610
190         }
191       }
192
193 // Start building the query
194       $tmp = array();
195
196       foreach ( $formdata as $key => $val ) {
197         if ( is_null($val) ) {
198           continue;
199         }
200
201         if ( is_integer($key) && ( $numeric_prefix != null ) ) {
202           $key = $numeric_prefix . $key;
203         }
204
205         if ( is_scalar($val) ) {
206           array_push($tmp, urlencode($key) . '=' . urlencode($val));
207           continue;
208         }
209
210 // If the value is an array, recursively parse it
211         if ( is_array($val) || is_object($val) ) {
212           array_push($tmp, http_build_query_helper($val, urlencode($key), $arg_separator));
213           continue;
214         }
215
216 // The value is a resource
217         return null;
218       }
219
hpdl
1748
220       return implode($arg_separator, $tmp);
hpdl
1610
221     }
222
223 // Helper function
224     function http_build_query_helper($array, $name, $arg_separator) {
225       $tmp = array();
226
227       foreach ( $array as $key => $value ) {
228         if ( is_array($value) ) {
229           array_push($tmp, http_build_query_helper($value, sprintf('%s[%s]', $name, $key), $arg_separator));
230         } elseif ( is_scalar($value) ) {
231           array_push($tmp, sprintf('%s[%s]=%s', $name, urlencode($key), urlencode($value)));
232         } elseif ( is_object($value) ) {
233           array_push($tmp, http_build_query_helper(get_object_vars($value), sprintf('%s[%s]', $name, $key), $arg_separator));
234         }
235       }
236
237       return implode($arg_separator, $tmp);
238     }
239   }
hpdl
1829
240
241 /*
242  * stripos() natively supported from PHP 5.0
243  * From Pear::PHP_Compat
244  */
245
246   if (!function_exists('stripos')) {
247     function stripos($haystack, $needle, $offset = null) {
248       $fix = 0;
249
250       if (!is_null($offset)) {
251         if ($offset > 0) {
252           $haystack = substr($haystack, $offset, strlen($haystack) - $offset);
253           $fix = $offset;
254         }
255       }
256
257       $segments = explode(strtolower($needle), strtolower($haystack), 2);
258
259 // Check there was a match
260       if (count($segments) == 1) {
261         return false;
262       }
263
264       $position = strlen($segments[0]) + $fix;
265
266       return $position;
267     }
268   }
hpdl
477
269 ?>