23 if (!defined(
'DISPLAY_XPM4_ERRORS')) define(
'DISPLAY_XPM4_ERRORS',
true);
25 if (!function_exists(
'debug_backtrace')) {
26 function debug_backtrace() {
27 return array(0 => array(
'class' =>
'unknown',
'type' =>
'unknown',
'function' =>
'unknown',
'file' => __FILE__,
'line' => __LINE__));
34 return (is_array($debug) && isset($debug[0][
'class'], $debug[0][
'type'], $debug[0][
'function'], $debug[0][
'file'], $debug[0][
'line']));
38 list($usec, $sec) = explode(
' ', microtime());
39 return ((
float)$usec + (
float)$sec);
43 return (strtoupper(substr(PHP_OS, 0, 3)) ===
'WIN');
47 if (defined(
'LOG_XPM4_ERRORS')) {
48 if (is_string(LOG_XPM4_ERRORS) && is_string($msg) && is_bool($strip)) {
49 if (is_array($arr = unserialize(LOG_XPM4_ERRORS)) && isset($arr[
'type']) && is_int($arr[
'type']) && ($arr[
'type'] == 0 || $arr[
'type'] == 1 || $arr[
'type'] == 3)) {
50 $msg =
"\r\n".
'['.date(
'm-d-Y H:i:s').
'] XPM4 '.($strip ? str_replace(array(
'<br />',
'<b>',
'</b>',
"\r\n"),
'', $msg) : $msg);
51 if ($arr[
'type'] == 0) error_log($msg);
52 else if ($arr[
'type'] == 1 && isset($arr[
'destination'], $arr[
'headers']) &&
53 is_string($arr[
'destination']) && strlen(trim($arr[
'destination'])) > 5 && count(explode(
'@', $arr[
'destination'])) == 2 &&
54 is_string($arr[
'headers']) && strlen(trim($arr[
'headers'])) > 3) {
55 error_log($msg, 1, trim($arr[
'destination']), trim($arr[
'headers']));
56 }
else if ($arr[
'type'] == 3 && isset($arr[
'destination']) && is_string($arr[
'destination']) && strlen(trim($arr[
'destination'])) > 1) {
57 error_log($msg, 3, trim($arr[
'destination']));
58 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error(
'invalid LOG_XPM4_ERRORS constant value', E_USER_WARNING);
59 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error(
'invalid LOG_XPM4_ERRORS constant type', E_USER_WARNING);
60 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error(
'invalid parameter(s) type', E_USER_WARNING);
64 function trace($debug, $message = null, $level = 1, $ret =
false) {
65 if (
FUNC4::is_debug($debug) && is_string($message) && ($level == 0 || $level == 1 || $level == 2)) {
66 if ($level == 0)
$mess =
'Error';
67 else if ($level == 1)
$mess =
'Warning';
68 else if ($level == 2)
$mess =
'Notice';
69 $emsg =
'<br /><b>'.$mess.
'</b>: '.$message.
70 ' on '.strtoupper($debug[0][
'class']).$debug[0][
'type'].$debug[0][
'function'].
'()'.
71 ' in <b>'.$debug[0][
'file'].
'</b> on line <b>'.$debug[0][
'line'].
'</b><br />'.
"\r\n";
78 $emsg =
'invalid debug parameters';
81 if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error($emsg, E_USER_ERROR);
83 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error($emsg, E_USER_WARNING);
88 function str_clear($str = null, $addrep = null, $debug = null) {
91 $rep = array(
"\r",
"\n",
"\t");
92 if (!is_string($str)) $err[] =
'invalid argument type';
93 if ($addrep == null) $addrep = array();
94 if (is_array($addrep)) {
95 if (count($addrep) > 0) {
96 foreach ($addrep as $strrep) {
97 if (is_string($strrep) && $strrep !=
'') $rep[] = $strrep;
99 $err[] =
'invalid array value';
104 }
else $err[] =
'invalid array type';
105 if (count($err) == 0)
return ($str ==
'') ?
'' : str_replace($rep,
'', $str);
109 function is_alpha($str = null, $num =
true, $add =
'', $debug = null) {
112 if (!is_string($str)) $err[] =
'invalid argument type';
113 if (!is_bool($num)) $err[] =
'invalid numeric type';
114 if (!is_string($add)) $err[] =
'invalid additional type';
115 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
118 $lst =
'abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ'.$add;
119 if ($num) $lst .=
'1234567890';
120 $len1 = strlen($str);
121 $len2 = strlen($lst);
123 for ($i = 0; $i < $len1; $i++) {
125 for ($j = 0; $j < $len2; $j++) {
126 if ($lst{$j} == $str{$i}) {
144 if (!is_string($str)) $err[] =
'invalid hostname type';
145 if (!is_bool($addr)) $err[] =
'invalid address type';
146 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
150 if (count($exphost1 = explode(
'.', $str)) > 1 && !(strstr($str,
'.-') || strstr($str,
'-.'))) {
152 foreach ($exphost1 as $expstr1) {
153 if ($expstr1 ==
'') {
159 foreach (($exphost2 = explode(
'-', $str)) as $expstr2) {
160 if ($expstr2 ==
'') {
166 $ext = $exphost1[count($exphost1)-1];
168 if ($set && $len >= 2 && $len <= 6 &&
FUNC4::is_alpha($ext,
false)) $ret =
true;
171 return ($ret && $addr && gethostbyname($str) == $str) ?
false : $ret;
175 function is_ipv4($str = null, $debug = null) {
177 if (is_string($str))
return (trim($str) !=
'' && ip2long($str) && count(explode(
'.', $str)) === 4);
181 function getmxrr_win($hostname = null, &$mxhosts, $debug = null) {
184 if (!is_string($hostname))
FUNC4::trace($debug,
'invalid hostname type');
186 $hostname = strtolower($hostname);
188 $retstr = exec(
'nslookup -type=mx '.$hostname, $retarr);
189 if ($retstr && count($retarr) > 0) {
190 foreach ($retarr as $line) {
191 if (preg_match(
'/.*mail exchanger = (.*)/', $line, $matches)) $mxhosts[] = $matches[1];
194 }
else FUNC4::trace($debug,
'invalid hostname value', 1);
195 return (count($mxhosts) > 0);
199 function is_mail($addr = null, $vermx =
false, $debug = null) {
202 if (!is_string($addr)) $err[] =
'invalid address type';
203 if (!is_bool($vermx)) $err[] =
'invalid MX type';
204 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
207 if ($ret && $vermx) {
217 if (!is_string($name))
FUNC4::trace($debug,
'invalid filename type');
221 if ($name ==
'')
return FUNC4::trace($debug,
'invalid filename value', 1);
223 $ret =
'application/octet-stream';
225 'z' =>
'application/x-compress',
226 'xls' =>
'application/x-excel',
227 'gtar' =>
'application/x-gtar',
228 'gz' =>
'application/x-gzip',
229 'cgi' =>
'application/x-httpd-cgi',
230 'php' =>
'application/x-httpd-php',
231 'js' =>
'application/x-javascript',
232 'swf' =>
'application/x-shockwave-flash',
233 'tar' =>
'application/x-tar',
234 'tgz' =>
'application/x-tar',
235 'tcl' =>
'application/x-tcl',
236 'src' =>
'application/x-wais-source',
237 'zip' =>
'application/zip',
238 'kar' =>
'audio/midi',
239 'mid' =>
'audio/midi',
240 'midi' =>
'audio/midi',
241 'mp2' =>
'audio/mpeg',
242 'mp3' =>
'audio/mpeg',
243 'mpga' =>
'audio/mpeg',
244 'ram' =>
'audio/x-pn-realaudio',
245 'rm' =>
'audio/x-pn-realaudio',
246 'rpm' =>
'audio/x-pn-realaudio-plugin',
247 'wav' =>
'audio/x-wav',
248 'bmp' =>
'image/bmp',
249 'fif' =>
'image/fif',
250 'gif' =>
'image/gif',
251 'ief' =>
'image/ief',
252 'jpe' =>
'image/jpeg',
253 'jpeg' =>
'image/jpeg',
254 'jpg' =>
'image/jpeg',
255 'png' =>
'image/png',
256 'tif' =>
'image/tiff',
257 'tiff' =>
'image/tiff',
259 'htm' =>
'text/html',
260 'html' =>
'text/html',
261 'txt' =>
'text/plain',
262 'rtx' =>
'text/richtext',
263 'vcf' =>
'text/x-vcard',
266 'mpe' =>
'video/mpeg',
267 'mpeg' =>
'video/mpeg',
268 'mpg' =>
'video/mpeg',
269 'mov' =>
'video/quicktime',
270 'qt' =>
'video/quicktime',
271 'asf' =>
'video/x-ms-asf',
272 'asx' =>
'video/x-ms-asf',
273 'avi' =>
'video/x-msvideo',
274 'vrml' =>
'x-world/x-vrml',
275 'wrl' =>
'x-world/x-vrml');
276 if (count($exp = explode(
'.', $name)) >= 2) {
277 $ext = strtolower($exp[count($exp)-1]);
278 if (trim($exp[count($exp)-2]) !=
'' && isset($arr[$ext])) $ret = $arr[$ext];