23 if (!defined(
'DISPLAY_XPM4_ERRORS')) define(
'DISPLAY_XPM4_ERRORS',
true);
28 return (is_array($debug) && isset($debug[0][
'class'], $debug[0][
'type'], $debug[0][
'function'], $debug[0][
'file'], $debug[0][
'line']));
32 return microtime(
true);
36 return (strtoupper(substr(PHP_OS, 0, 3)) ===
'WIN');
39 static public function log_errors($msg = null, $strip =
false) {
40 if (defined(
'LOG_XPM4_ERRORS')) {
41 if (is_string(LOG_XPM4_ERRORS) && is_string($msg) && is_bool($strip)) {
42 if (is_array($arr = unserialize(LOG_XPM4_ERRORS)) && isset($arr[
'type']) && is_int($arr[
'type']) && ($arr[
'type'] == 0 || $arr[
'type'] == 1 || $arr[
'type'] == 3)) {
43 $msg =
"\r\n".
'['.date(
'm-d-Y H:i:s').
'] XPM4 '.($strip ? str_replace(array(
'<br />',
'<b>',
'</b>',
"\r\n"),
'', $msg) : $msg);
44 if ($arr[
'type'] == 0) error_log($msg);
45 else if ($arr[
'type'] == 1 && isset($arr[
'destination'], $arr[
'headers']) &&
46 is_string($arr[
'destination']) && strlen(trim($arr[
'destination'])) > 5 && count(explode(
'@', $arr[
'destination'])) == 2 &&
47 is_string($arr[
'headers']) && strlen(trim($arr[
'headers'])) > 3) {
48 error_log($msg, 1, trim($arr[
'destination']), trim($arr[
'headers']));
49 }
else if ($arr[
'type'] == 3 && isset($arr[
'destination']) && is_string($arr[
'destination']) && strlen(trim($arr[
'destination'])) > 1) {
50 error_log($msg, 3, trim($arr[
'destination']));
51 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error(
'invalid LOG_XPM4_ERRORS constant value', E_USER_WARNING);
52 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error(
'invalid LOG_XPM4_ERRORS constant type', E_USER_WARNING);
53 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error(
'invalid parameter(s) type', E_USER_WARNING);
57 static public function trace($debug, $message = null, $level = 1, $ret =
false) {
58 if (self::is_debug($debug) && is_string($message) && ($level == 0 || $level == 1 || $level == 2)) {
59 if ($level == 0)
$mess =
'Error';
60 else if ($level == 1)
$mess =
'Warning';
61 else if ($level == 2)
$mess =
'Notice';
62 $emsg =
'<br /><b>'.$mess.
'</b>: '.$message.
63 ' on '.strtoupper($debug[0][
'class']).$debug[0][
'type'].$debug[0][
'function'].
'()'.
64 ' in <b>'.$debug[0][
'file'].
'</b> on line <b>'.$debug[0][
'line'].
'</b><br />'.
"\r\n";
71 $emsg =
'invalid debug parameters';
74 if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error($emsg, E_USER_ERROR);
76 }
else if (defined(
'DISPLAY_XPM4_ERRORS') &&
DISPLAY_XPM4_ERRORS ==
true) trigger_error($emsg, E_USER_WARNING);
81 static public function str_clear($str = null, $addrep = null, $debug = null) {
82 if (!self::is_debug($debug)) $debug = debug_backtrace();
84 $rep = array(
"\r",
"\n",
"\t");
85 if (!is_string($str)) $err[] =
'invalid argument type';
86 if ($addrep == null) $addrep = array();
87 if (is_array($addrep)) {
88 if (count($addrep) > 0) {
89 foreach ($addrep as $strrep) {
90 if (is_string($strrep) && $strrep !=
'') $rep[] = $strrep;
92 $err[] =
'invalid array value';
97 }
else $err[] =
'invalid array type';
98 if (count($err) == 0)
return ($str ==
'') ?
'' : str_replace($rep,
'', $str);
102 static public function is_alpha($str = null, $num =
true, $add =
'', $debug = null) {
103 if (!self::is_debug($debug)) $debug = debug_backtrace();
105 if (!is_string($str)) $err[] =
'invalid argument type';
106 if (!is_bool($num)) $err[] =
'invalid numeric type';
107 if (!is_string($add)) $err[] =
'invalid additional type';
108 if (count($err) > 0)
self::trace($debug, implode(
', ', $err));
111 $lst =
'abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ'.$add;
112 if ($num) $lst .=
'1234567890';
113 $len1 = strlen($str);
114 $len2 = strlen($lst);
116 for ($i = 0; $i < $len1; $i++) {
118 for ($j = 0; $j < $len2; $j++) {
119 if ($lst{$j} == $str{$i}) {
134 static public function is_hostname($str = null, $addr =
false, $debug = null) {
135 if (!self::is_debug($debug)) $debug = debug_backtrace();
137 if (!is_string($str)) $err[] =
'invalid hostname type';
138 if (!is_bool($addr)) $err[] =
'invalid address type';
139 if (count($err) > 0)
self::trace($debug, implode(
', ', $err));
142 if (trim($str) !=
'' && self::is_alpha($str,
true,
'-.')) {
143 if (count($exphost1 = explode(
'.', $str)) > 1 && !(strstr($str,
'.-') || strstr($str,
'-.'))) {
145 foreach ($exphost1 as $expstr1) {
146 if ($expstr1 ==
'') {
152 foreach (($exphost2 = explode(
'-', $str)) as $expstr2) {
153 if ($expstr2 ==
'') {
159 $ext = $exphost1[count($exphost1)-1];
161 if ($set && $len >= 2 && $len <= 6 && self::is_alpha($ext,
false)) $ret =
true;
164 return ($ret && $addr && gethostbyname($str) == $str) ?
false : $ret;
168 static public function is_ipv4($str = null, $debug = null) {
169 if (!self::is_debug($debug)) $debug = debug_backtrace();
170 if (is_string($str))
return (trim($str) !=
'' && ip2long($str) && count(explode(
'.', $str)) === 4);
174 static public function getmxrr_win($hostname = null, &$mxhosts, $debug = null) {
175 if (!self::is_debug($debug)) $debug = debug_backtrace();
177 if (!is_string($hostname))
self::trace($debug,
'invalid hostname type');
179 $hostname = strtolower($hostname);
180 if (self::is_hostname($hostname,
true, $debug)) {
181 $retstr = exec(
'nslookup -type=mx '.$hostname, $retarr);
182 if ($retstr && count($retarr) > 0) {
183 foreach ($retarr as $line) {
184 if (preg_match(
'/.*mail exchanger = (.*)/', $line, $matches)) $mxhosts[] = $matches[1];
187 }
else self::trace($debug,
'invalid hostname value', 1);
188 return (count($mxhosts) > 0);
192 static public function is_mail($addr = null, $vermx =
false, $debug = null) {
193 if (!self::is_debug($debug)) $debug = debug_backtrace();
195 if (!is_string($addr)) $err[] =
'invalid address type';
196 if (!is_bool($vermx)) $err[] =
'invalid MX type';
197 if (count($err) > 0)
self::trace($debug, implode(
', ', $err));
200 if ($ret && $vermx) {
201 if (self::is_ipv4($exp[1])) $ret =
false;
208 static public function mime_type($name = null, $debug = null) {
209 if (!self::is_debug($debug)) $debug = debug_backtrace();
210 if (!is_string($name))
self::trace($debug,
'invalid filename type');
214 if ($name ==
'')
return self::trace($debug,
'invalid filename value', 1);
216 $ret =
'application/octet-stream';
218 'z' =>
'application/x-compress',
219 'xls' =>
'application/x-excel',
220 'gtar' =>
'application/x-gtar',
221 'gz' =>
'application/x-gzip',
222 'cgi' =>
'application/x-httpd-cgi',
223 'php' =>
'application/x-httpd-php',
224 'js' =>
'application/x-javascript',
225 'swf' =>
'application/x-shockwave-flash',
226 'tar' =>
'application/x-tar',
227 'tgz' =>
'application/x-tar',
228 'tcl' =>
'application/x-tcl',
229 'src' =>
'application/x-wais-source',
230 'zip' =>
'application/zip',
231 'kar' =>
'audio/midi',
232 'mid' =>
'audio/midi',
233 'midi' =>
'audio/midi',
234 'mp2' =>
'audio/mpeg',
235 'mp3' =>
'audio/mpeg',
236 'mpga' =>
'audio/mpeg',
237 'ram' =>
'audio/x-pn-realaudio',
238 'rm' =>
'audio/x-pn-realaudio',
239 'rpm' =>
'audio/x-pn-realaudio-plugin',
240 'wav' =>
'audio/x-wav',
241 'bmp' =>
'image/bmp',
242 'fif' =>
'image/fif',
243 'gif' =>
'image/gif',
244 'ief' =>
'image/ief',
245 'jpe' =>
'image/jpeg',
246 'jpeg' =>
'image/jpeg',
247 'jpg' =>
'image/jpeg',
248 'png' =>
'image/png',
249 'tif' =>
'image/tiff',
250 'tiff' =>
'image/tiff',
252 'htm' =>
'text/html',
253 'html' =>
'text/html',
254 'txt' =>
'text/plain',
255 'rtx' =>
'text/richtext',
256 'vcf' =>
'text/x-vcard',
259 'mpe' =>
'video/mpeg',
260 'mpeg' =>
'video/mpeg',
261 'mpg' =>
'video/mpeg',
262 'mov' =>
'video/quicktime',
263 'qt' =>
'video/quicktime',
264 'asf' =>
'video/x-ms-asf',
265 'asx' =>
'video/x-ms-asf',
266 'avi' =>
'video/x-msvideo',
267 'vrml' =>
'x-world/x-vrml',
268 'wrl' =>
'x-world/x-vrml');
269 if (count($exp = explode(
'.', $name)) >= 2) {
270 $ext = strtolower($exp[count($exp)-1]);
271 if (trim($exp[count($exp)-2]) !=
'' && isset($arr[$ext])) $ret = $arr[$ext];