-
Notifications
You must be signed in to change notification settings - Fork 221
/
compatibility.php
184 lines (158 loc) · 4.65 KB
/
compatibility.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2007 osCommerce
Released under the GNU General Public License
*/
////
// Recursively handle magic_quotes_gpc turned off.
// This is due to the possibility of have an array in
// $HTTP_xxx_VARS
// Ie, products attributes
function do_magic_quotes_gpc(&$ar) {
if (!is_array($ar)) return false;
reset($ar);
while (list($key, $value) = each($ar)) {
if (is_array($ar[$key])) {
do_magic_quotes_gpc($ar[$key]);
} else {
$ar[$key] = addslashes($value);
}
}
reset($ar);
}
if (PHP_VERSION >= 4.1) {
$HTTP_GET_VARS =& $_GET;
$HTTP_POST_VARS =& $_POST;
$HTTP_COOKIE_VARS =& $_COOKIE;
$HTTP_SESSION_VARS =& $_SESSION;
$HTTP_POST_FILES =& $_FILES;
$HTTP_SERVER_VARS =& $_SERVER;
} else {
if (!is_array($HTTP_GET_VARS)) $HTTP_GET_VARS = array();
if (!is_array($HTTP_POST_VARS)) $HTTP_POST_VARS = array();
if (!is_array($HTTP_COOKIE_VARS)) $HTTP_COOKIE_VARS = array();
}
// handle magic_quotes_gpc turned off.
if (!get_magic_quotes_gpc()) {
do_magic_quotes_gpc($HTTP_GET_VARS);
do_magic_quotes_gpc($HTTP_POST_VARS);
do_magic_quotes_gpc($HTTP_COOKIE_VARS);
}
// set default timezone if none exists (PHP 5.3 throws an E_WARNING)
if ((strlen(ini_get('date.timezone')) < 1) && function_exists('date_default_timezone_set')) {
date_default_timezone_set(@date_default_timezone_get());
}
if (!function_exists('array_splice')) {
function array_splice(&$array, $maximum) {
if (sizeof($array) >= $maximum) {
for ($i=0; $i<$maximum; $i++) {
$new_array[$i] = $array[$i];
}
$array = $new_array;
}
}
}
if (!function_exists('in_array')) {
function in_array($lookup_value, $lookup_array) {
reset($lookup_array);
while (list($key, $value) = each($lookup_array)) {
if ($value == $lookup_value) return true;
}
return false;
}
}
if (!function_exists('array_reverse')) {
function array_reverse($array) {
for ($i=0, $n=sizeof($array); $i<$n; $i++) $array_reversed[$i] = $array[($n-$i-1)];
return $array_reversed;
}
}
if (!function_exists('constant')) {
function constant($constant) {
eval("\$temp=$constant;");
return $temp;
}
}
if (!function_exists('is_null')) {
function is_null($value) {
if (is_array($value)) {
if (sizeof($value) > 0) {
return false;
} else {
return true;
}
} else {
if (($value != '') && ($value != 'NULL') && (strlen(trim($value)) > 0)) {
return false;
} else {
return true;
}
}
}
}
if (!function_exists('array_merge')) {
function array_merge($array1, $array2, $array3 = '') {
if (empty($array3) && !is_array($array3)) $array3 = array();
while (list($key, $val) = each($array1)) $array_merged[$key] = $val;
while (list($key, $val) = each($array2)) $array_merged[$key] = $val;
if (sizeof($array3) > 0) while (list($key, $val) = each($array3)) $array_merged[$key] = $val;
return (array) $array_merged;
}
}
if (!function_exists('is_numeric')) {
function is_numeric($param) {
return ereg('^[0-9]{1,50}.?[0-9]{0,50}$', $param);
}
}
if (!function_exists('array_slice')) {
function array_slice($array, $offset, $length = 0) {
if ($offset < 0 ) {
$offset = sizeof($array) + $offset;
}
$length = ((!$length) ? sizeof($array) : (($length < 0) ? sizeof($array) - $length : $length + $offset));
for ($i = $offset; $i<$length; $i++) {
$tmp[] = $array[$i];
}
return $tmp;
}
}
if (!function_exists('array_map')) {
function array_map($callback, $array) {
if (is_array($array)) {
$_new_array = array();
reset($array);
while (list($key, $value) = each($array)) {
$_new_array[$key] = array_map($callback, $array[$key]);
}
return $_new_array;
} else {
return $callback($array);
}
}
}
if (!function_exists('str_repeat')) {
function str_repeat($string, $number) {
$repeat = '';
for ($i=0; $i<$number; $i++) {
$repeat .= $string;
}
return $repeat;
}
}
if (!function_exists('checkdnsrr')) {
function checkdnsrr($host, $type) {
if(tep_not_null($host) && tep_not_null($type)) {
@exec("nslookup -type=$type $host", $output);
while(list($k, $line) = each($output)) {
if(eregi("^$host", $line)) {
return true;
}
}
}
return false;
}
}
?>