Update killglobals.php
[iDB.git] / inc / function.php
bloba7ff857b1bdff02df84a2ef84702d496b824fa65
1 <?php
2 /*
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2023 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2023 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: function.php - Last Update: 6/22/2023 SVN 984 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="function.php"||$File3Name=="/function.php") {
18 require('index.php');
19 exit(); }
20 require_once($SettDir['misc'].'functions.php');
21 require_once($SettDir['misc'].'ibbcode.php');
22 require_once($SettDir['misc'].'iuntar.php');
23 /* In php 6 and up the function get_magic_quotes_gpc dose not exist.
24 here we make a fake version that always sends false out. :P */
25 if(!function_exists('get_magic_quotes_gpc')) {
26 function get_magic_quotes_gpc() { return false; } }
27 /**
28 * Undo the damage of magic_quotes_gpc if in effect
29 * @return bool
30 * @link http://www.charles-reace.com/blog/2010/07/13/undoing-magic-quotes/
32 function fix_magic_quotes()
34 if (get_magic_quotes_gpc()) {
35 $func = create_function(
36 '&$val, $key',
37 'if(!is_numeric($val)) {$val = stripslashes($val);}'
39 array_walk_recursive($_GET, $func);
40 array_walk_recursive($_POST, $func);
41 array_walk_recursive($_COOKIE, $func);
43 return true;
45 fix_magic_quotes();
46 /* Change Some PHP Settings Fix the & to &amp;
47 if($Settings['use_iniset']==true&&$Settings['qstr']!="/") {
48 ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
49 ini_set("arg_separator.input",$Settings['qstr']);
50 ini_set("arg_separator",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset'])); }
51 //$basepath = pathinfo($_SERVER['REQUEST_URI']);
52 if(dirname($_SERVER['REQUEST_URI'])!="."||
53 dirname($_SERVER['REQUEST_URI'])!=null) {
54 $basedir = dirname($_SERVER['REQUEST_URI'])."/"; }*/
55 // Get the base dir name
56 /*if(dirname($_SERVER['SCRIPT_NAME'])!="."||
57 dirname($_SERVER['SCRIPT_NAME'])!=null) {
58 $basedir = dirname($_SERVER['SCRIPT_NAME'])."/"; }
59 if($basedir==null||$basedir==".") {
60 if(dirname($_SERVER['SCRIPT_NAME'])=="."||
61 dirname($_SERVER['SCRIPT_NAME'])==null) {
62 $basedir = dirname($_SERVER['PHP_SELF'])."/"; } }
63 if($basedir=="\/") { $basedir="/"; }
64 $basedir = str_replace("//", "/", $basedir);*/
65 if($Settings['qstr']!="/") {
66 $iDBURLCHK = $Settings['idburl']; }
67 if($Settings['qstr']=="/") {
68 $iDBURLCHK = preg_replace("/\/$/","",$Settings['idburl']); }
69 $basecheck = parse_url($iDBURLCHK);
70 $basedir = $basecheck['path'];
71 $cbasedir = $basedir;
72 $rbasedir = $basedir;
73 if($Settings['fixbasedir']!=null&&$Settings['fixbasedir']!="off") {
74 $basedir = $Settings['fixbasedir']; }
75 if($Settings['fixcookiedir']!=null&&$Settings['fixcookiedir']!="") {
76 $cbasedir = $Settings['fixcookiedir']; }
77 if($Settings['fixredirectdir']!=null) {
78 $rbasedir = $Settings['fixredirectdir']; }
79 $BaseURL = $basedir;
80 // Get our Host Name and Referer URL's Host Name
81 if(!isset($_SERVER['HTTP_REFERER'])) {
82 $REFERERurl = null;
83 $_SERVER['HTTP_REFERER'] = null; }
84 if(isset($_SERVER['HTTP_REFERER'])) {
85 $REFERERurl = parse_url($_SERVER['HTTP_REFERER']); }
86 if(!isset($REFERERurl['host'])) { $REFERERurl['host'] = null; }
87 $URL['REFERER'] = $REFERERurl['host'];
88 $URL['HOST'] = $basecheck['host'];
89 $REFERERurl = null;
90 // Function made by Howard Yeend
91 // http://php.net/manual/en/function.trigger-error.php#92016
92 // http://www.puremango.co.uk/
93 function output_error($message, $level=E_USER_ERROR) {
94 $caller = next(debug_backtrace());
95 trigger_error($message.' in <strong>'.$caller['function'].'</strong> called from <strong>'.$caller['file'].'</strong> on line <strong>'.$caller['line'].'</strong>'."\n<br />error handler", $level); }
96 // By s rotondo90 at gmail com at https://www.php.net/manual/en/function.random-int.php#119670
97 if (!function_exists('random_int')) {
98 function random_int($min, $max) {
99 if (!function_exists('mcrypt_create_iv')) {
100 trigger_error(
101 'mcrypt must be loaded for random_int to work',
102 E_USER_WARNING
104 return null;
107 if (!is_int($min) || !is_int($max)) {
108 trigger_error('$min and $max must be integer values', E_USER_NOTICE);
109 $min = (int)$min;
110 $max = (int)$max;
113 if ($min > $max) {
114 trigger_error('$max can\'t be lesser than $min', E_USER_WARNING);
115 return null;
118 $range = $counter = $max - $min;
119 $bits = 1;
121 while ($counter >>= 1) {
122 ++$bits;
125 $bytes = (int)max(ceil($bits/8), 1);
126 $bitmask = pow(2, $bits) - 1;
128 if ($bitmask >= PHP_INT_MAX) {
129 $bitmask = PHP_INT_MAX;
132 do {
133 $result = hexdec(
134 bin2hex(
135 mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
137 ) & $bitmask;
138 } while ($result > $range);
140 return $result + $min;
143 // http://us.php.net/manual/en/function.uniqid.php#94959
145 * Generates an UUID
147 * @author Andrew Moore
148 * @url http://us.php.net/manual/en/function.uniqid.php#94959
150 function uuid_old($uuidver = "v4", $rndty = "rand", $namespace = null, $name = null) {
151 if($uuidver!="v3"&&$uuidver!="v4"&&$uuidver!="v5") { $uuidver = "v4"; }
152 if($uuidver=="v4") {
153 return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
154 $rndty(0, 0xffff), $rndty(0, 0xffff),
155 $rndty(0, 0xffff),
156 $rndty(0, 0x0fff) | 0x4000,
157 $rndty(0, 0x3fff) | 0x8000,
158 $rndty(0, 0xffff), $rndty(0, 0xffff), $rndty(0, 0xffff) ); }
159 if($uuidver=="v3"||$uuidver=="v5") {
160 if($namespace===null) {
161 $namespace = uuid_old("v4",$rndty); }
162 $nhex = str_replace(array('-','{','}'), '', $namespace);
163 $nstr = '';
164 for($i = 0; $i < strlen($nhex); $i+=2) {
165 if(isset($nhex[$i+1])) {
166 $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); }
167 if(!isset($nhex[$i+1])) {
168 $nstr .= chr(hexdec($nhex[$i])); }
170 if($name===null) { $name = salt_hmac(); }
171 // Calculate hash value
172 if($uuidver=="v3") {
173 $uuidverid = 0x3000;
174 if (function_exists('hash')) {
175 $hash = hash("md5", $nstr . $name); }
176 if (!function_exists('hash')) {
177 $hash = md5($nstr . $name); } }
178 if($uuidver=="v5") {
179 $uuidverid = 0x5000;
180 if (function_exists('hash')) {
181 $hash = hash("sha1", $nstr . $name); }
182 if (!function_exists('hash')) {
183 $hash = sha1($nstr . $name); } }
184 return sprintf('%08s-%04s-%04x-%04x-%12s',
185 substr($hash, 0, 8),
186 substr($hash, 8, 4),
187 (hexdec(substr($hash, 12, 4)) & 0x0fff) | $uuidverid,
188 (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
189 substr($hash, 20, 12) ); } }
190 class UUID {
191 public static function v3($namespace, $name) {
192 if(!self::is_valid($namespace)) return false;
194 // Get hexadecimal components of namespace
195 $nhex = str_replace(array('-','{','}'), '', $namespace);
197 // Binary Value
198 $nstr = '';
200 // Convert Namespace UUID to bits
201 for($i = 0; $i < strlen($nhex); $i+=2) {
202 $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
205 // Calculate hash value
206 $hash = md5($nstr . $name);
208 return sprintf('%08s-%04s-%04x-%04x-%12s',
210 // 32 bits for "time_low"
211 substr($hash, 0, 8),
213 // 16 bits for "time_mid"
214 substr($hash, 8, 4),
216 // 16 bits for "time_hi_and_version",
217 // four most significant bits holds version number 3
218 (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
220 // 16 bits, 8 bits for "clk_seq_hi_res",
221 // 8 bits for "clk_seq_low",
222 // two most significant bits holds zero and one for variant DCE1.1
223 (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
225 // 48 bits for "node"
226 substr($hash, 20, 12)
230 public static function v4() {
231 return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
233 // 32 bits for "time_low"
234 mt_rand(0, 0xffff), mt_rand(0, 0xffff),
236 // 16 bits for "time_mid"
237 mt_rand(0, 0xffff),
239 // 16 bits for "time_hi_and_version",
240 // four most significant bits holds version number 4
241 mt_rand(0, 0x0fff) | 0x4000,
243 // 16 bits, 8 bits for "clk_seq_hi_res",
244 // 8 bits for "clk_seq_low",
245 // two most significant bits holds zero and one for variant DCE1.1
246 mt_rand(0, 0x3fff) | 0x8000,
248 // 48 bits for "node"
249 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
253 public static function v5($namespace, $name) {
254 if(!self::is_valid($namespace)) return false;
256 // Get hexadecimal components of namespace
257 $nhex = str_replace(array('-','{','}'), '', $namespace);
259 // Binary Value
260 $nstr = '';
262 // Convert Namespace UUID to bits
263 for($i = 0; $i < strlen($nhex); $i+=2) {
264 $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
267 // Calculate hash value
268 $hash = sha1($nstr . $name);
270 return sprintf('%08s-%04s-%04x-%04x-%12s',
272 // 32 bits for "time_low"
273 substr($hash, 0, 8),
275 // 16 bits for "time_mid"
276 substr($hash, 8, 4),
278 // 16 bits for "time_hi_and_version",
279 // four most significant bits holds version number 5
280 (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
282 // 16 bits, 8 bits for "clk_seq_hi_res",
283 // 8 bits for "clk_seq_low",
284 // two most significant bits holds zero and one for variant DCE1.1
285 (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
287 // 48 bits for "node"
288 substr($hash, 20, 12)
292 public static function is_valid($uuid) {
293 return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
294 '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
297 function uuid($uuidver = "v4", $rndty = "rand", $namespace = null, $name = null) {
298 if($uuidver!="v3"&&$uuidver!="v4"&&$uuidver!="v5") { $uuidver = "v4"; }
299 if($uuidver=="v3") { return UUID::v3(UUID::v4(), salt_hmac()); }
300 if($uuidver=="v3") { return UUID::v4(); }
301 if($uuidver=="v3") { return UUID::v5(UUID::v4(), salt_hmac()); }
302 return false; }
303 // By info at raymondrodgers dot com at https://www.php.net/manual/en/function.random-int.php#118636
304 function generateUUIDv4()
306 if(version_compare(PHP_VERSION,'7.0.0', '<') )
308 return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
310 // 32 bits for "time_low"
311 mt_rand(0, 0xffff), mt_rand(0, 0xffff),
313 // 16 bits for "time_mid"
314 mt_rand(0, 0xffff),
316 // 16 bits for "time_hi_and_version",
317 // four most significant bits holds version number 4
318 mt_rand(0, 0x0fff) | 0x4000,
320 // 16 bits, 8 bits for "clk_seq_hi_res",
321 // 8 bits for "clk_seq_low",
322 // two most significant bits holds zero and one for variant DCE1.1
323 mt_rand(0, 0x3fff) | 0x8000,
325 // 48 bits for "node"
326 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
329 else
331 return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
333 // 32 bits for "time_low"
334 random_int(0, 0xffff), random_int(0, 0xffff),
336 // 16 bits for "time_mid"
337 random_int(0, 0xffff),
339 // 16 bits for "time_hi_and_version",
340 // four most significant bits holds version number 4
341 random_int(0, 0x0fff) | 0x4000,
343 // 16 bits, 8 bits for "clk_seq_hi_res",
344 // 8 bits for "clk_seq_low",
345 // two most significant bits holds zero and one for variant DCE1.1
346 random_int(0, 0x3fff) | 0x8000,
348 // 48 bits for "node"
349 random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff)
353 function rand_uuid_old($rndty = "rand", $namespace = null, $name = null) {
354 $rand_array = array(1 => "v3", 2 => "v4", 3 => "v5");
355 if($name===null) { $name = salt_hmac(); }
356 $my_uuid = $rand_array[$rndty(1,3)];
357 if($my_uuid=="v4") { return uuid_old("v4",$rndty); }
358 if($my_uuid=="v3"||$my_uuid=="v5") {
359 return uuid_old($my_uuid,$rndty,$name); } }
360 function rand_uuid($rndty = "rand", $namespace = null, $name = null) {
361 $rand_array = array(1 => "v3", 2 => "v4", 3 => "v5");
362 if($name===null) { $name = salt_hmac(); }
363 $my_uuid = $rand_array[$rndty(1,3)];
364 if($my_uuid=="v4") { return uuid("v4",$rndty); }
365 if($my_uuid=="v3"||$my_uuid=="v5") {
366 return uuid($my_uuid,$rndty,$name); } }
367 // unserialize sessions variables
368 // By: jason@joeymail.net
369 // URL: http://us2.php.net/manual/en/function.session-decode.php#101687
370 function unserialize_session($data)
372 if( strlen( $data) == 0)
374 return array();
376 // match all the session keys and offsets
377 preg_match_all('/(^|;|\})([a-zA-Z0-9_]+)\|/i', $data, $matchesarray, PREG_OFFSET_CAPTURE);
378 $returnArray = array();
379 $lastOffset = null;
380 $currentKey = '';
381 foreach ( $matchesarray[2] as $value )
383 $offset = $value[1];
384 if(!is_null( $lastOffset))
386 $valueText = substr($data, $lastOffset, $offset - $lastOffset );
387 $returnArray[$currentKey] = unserialize($valueText);
389 $currentKey = $value[0];
390 $lastOffset = $offset + strlen( $currentKey )+1;
392 $valueText = substr($data, $lastOffset );
393 $returnArray[$currentKey] = unserialize($valueText);
394 return $returnArray;
396 // Make the Query String if we are not useing &=
397 function qstring($qstr=";",$qsep="=")
398 { $_GET = array(); $_GET = null;
399 if (!isset($_SERVER['QUERY_STRING'])) {
400 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
401 ini_set("arg_separator.input", $qstr);
402 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
403 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
404 $qsnum = count($preqs); $qsi = 0;
405 while ($qsi < $qsnum) {
406 $preqst = explode($qsep,$preqs[$qsi],2);
407 $fix1 = array(" ",'$'); $fix2 = array("_","_");
408 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
409 $preqst[0] = killbadvars($preqst[0]);
410 if($preqst[0]!=null) {
411 $_GET[$preqst[0]] = $preqst[1]; }
412 ++$qsi; } return true; }
413 if($Settings['qstr']!="&"&&
414 $Settings['qstr']!="/") {
415 qstring($Settings['qstr'],$Settings['qsep']);
416 if(!isset($_GET['page'])) { $_GET['page'] = null; }
417 if(!isset($_GET['act'])) { $_GET['act'] = null; }
418 if(!isset($_POST['act'])) { $_POST['act'] = null; }
419 if(!isset($_GET['id'])) { $_GET['id'] = null; }
420 if(!isset($_GET['debug'])) { $_GET['debug'] = "false"; }
421 if(!isset($_GET['post'])) { $_GET['post'] = null; }
422 if(!isset($_POST['License'])) { $_POST['License'] = null; } }
423 if(isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO']==null) {
424 if(getenv('PATH_INFO')!=null&&getenv('PATH_INFO')!="1") {
425 $_SERVER['PATH_INFO'] = getenv('PATH_INFO'); }
426 if(getenv('PATH_INFO')==null) {
427 $myscript = $_SERVER["SCRIPT_NAME"];
428 $myphpath = $_SERVER["PHP_SELF"];
429 $mypathinfo = str_replace($myscript, "", $myphpath);
430 @putenv("PATH_INFO=".$mypathinfo); } }
431 // Change raw post data to POST array
432 // Not sure why I made but alwell. :P
433 function parse_post_data()
434 { $_POST = array(); $_POST = null;
435 $postdata = file_get_contents("php://input");
436 if (!isset($postdata)) { $postdata = null; }
437 $postdata = urldecode($postdata);
438 $preqs = explode("&",$postdata);
439 $qsnum = count($preqs); $qsi = 0;
440 while ($qsi < $qsnum) {
441 $preqst = explode("=",$preqs[$qsi],2);
442 $fix1 = array(" ",'$'); $fix2 = array("_","_");
443 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
444 $preqst[0] = killbadvars($preqst[0]);
445 if($preqst[0]!=null) {
446 $_POST[$preqst[0]] = $preqst[1]; }
447 ++$qsi; } return true; }
448 // Change Path info to Get Vars :
449 function mrstring() {
450 if($_SERVER['PATH_INFO']==null) {
451 $urlvar = explode('/',$_SERVER['PATH_INFO']); }
452 else {
453 $urlvar = null; }
454 $num=count($urlvar); $i=1;
455 while ($i < $num) {
456 //$urlvar[$i] = urldecode($urlvar[$i]);
457 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
458 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
459 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
460 $fix1 = array(" ",'$'); $fix2 = array("_","_");
461 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
462 $urlvar[$i] = killbadvars($urlvar[$i]);
463 $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
464 ++$i; ++$i; } return true; }
465 // Redirect to another file with ether timed or nontimed redirect
466 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
467 if($type!="location"&&$type!="refresh") { $type=="location"; }
468 if($url!=null) { $file = $url.$file; }
469 if($dbsr===true) { $file = str_replace("//", "/", $file); }
470 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
471 if($type=="location") { session_write_close();
472 header("Location: ".$file); } return true; }
473 function redirects($type,$url,$time=0) {
474 if($type!="location"&&$type!="refresh") { $type=="location"; }
475 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
476 if($type=="location") { idb_log_maker(302,"-"); }
477 if($type=="location") { header("Location: ".$url); } return true; }
478 // Function to log the web access
479 function logWebAccess($logFile, $format = '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"')
481 // Get the necessary information from the $_SERVER superglobal array
482 $ip = $_SERVER['REMOTE_ADDR'];
483 $timestamp = date('d/M/Y:H:i:s O');
484 $method = $_SERVER['REQUEST_METHOD'];
485 $uri = $_SERVER['REQUEST_URI'];
486 $protocol = $_SERVER['SERVER_PROTOCOL'];
487 $status = http_response_code();
488 $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '-';
489 $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '-';
490 // Replace placeholders in the log format with actual values
491 $placeholders = array(
492 '%h' => $ip,
493 '%l' => '-',
494 '%u' => '-',
495 '%t' => "[$timestamp]",
496 '%r' => "$method $uri $protocol",
497 '%>s' => $status,
498 '%b' => '-',
499 '%{Referer}i' => $referer,
500 '%{User-Agent}i' => $userAgent,
502 $logEntry = strtr($format, $placeholders);
503 // Open the log file in append mode
504 $logFileHandle = fopen($logFile, 'a');
505 // Write the log entry to the file
506 fwrite($logFileHandle, $logEntry . PHP_EOL);
507 // Close the log file
508 fclose($logFileHandle);
510 // Make xhtml tags
511 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
512 $var_num = count($attbvar); $value_num = count($attbval);
513 if($var_num!=$value_num) {
514 output_error("Erorr Number of Var and Values dont match!",E_USER_ERROR);
515 return false; } $i = 0;
516 while ($i < $var_num) {
517 if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
518 if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
519 if($i==$var_num-1) {
520 if($emptytag===false) { $mytag = $mytag.">"; }
521 if($emptytag===true) { $mytag = $mytag." />"; } } ++$i; }
522 if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
523 if($emptytag===true) { $mytag = $mytag." />"; }
524 if($emptytag===false) { $mytag = $mytag.">"; } }
525 if($emptytag===false&&$extratest!=null) {
526 $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; }
527 return $mytag; }
528 // Start a xml document
529 function xml_tag_make($type,$attbs,$retval=false) {
530 $melanie1 = explode("&",$attbs);
531 $melanienum=count($melanie1);
532 $melaniei=0; $attblist = null;
533 while ($melaniei < $melanienum) {
534 $melanie2 = explode("=",$melanie1[$melaniei]);
535 if($melanie2[0]!=null||$melanie2[1]!=null) {
536 $attblist = $attblist.' '.$melanie2[0].'="'.$melanie2[1].'"'; }
537 ++$melaniei; }
538 if($retval!==false&&$retval!==true) { $retval=false; }
539 if($retval===false) {
540 echo '<?'.$type.$attblist.'?>'."\n"; }
541 if($retval===true) {
542 return '<?'.$type.$attblist.'?>'."\n"; } }
543 // Start a xml document (old version)
544 function xml_doc_start($ver,$encode,$retval=false) {
545 if($retval===false) {
546 echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
547 if($retval===true) {
548 return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
549 $icharset = $Settings['charset'];
550 $debug_on = false;
551 if(isset($_GET['debug'])) {
552 if($_GET['debug']=="true"||
553 $_GET['debug']=="on") {
554 $debug_on = true; } }
555 $BoardURL = $Settings['idburl'];
556 // Change URLs to Links
557 function pre_url2link($matches) {
558 global $BoardURL; $opennew = true;
559 $burlCHCK = parse_url($BoardURL);
560 $urlCHCK = parse_url($matches[0]);
561 if($urlCHCK['host']==$burlCHCK['host']) {
562 $opennew = false; }
563 $outurl = $urlCHCK['scheme']."://";
564 if(isset($urlCHCK['user'])) {
565 $outurl = $outurl.$urlCHCK['user'];
566 if(isset($urlCHCK['pass'])) {
567 $outurl = $outurl.":".$urlCHCK['pass']; }
568 $outurl = $outurl."@"; }
569 $outurl = $outurl.$urlCHCK['host'];
570 if(isset($urlCHCK['path'])) {
571 $outurl = $outurl.$urlCHCK['path']; }
572 if(!isset($urlCHCK['path'])) {
573 $outurl = $outurl."/"; }
574 if(isset($urlCHCK['query'])) {
575 $urlCHCK['query'] = str_replace(" ", "+", $urlCHCK['query']);
576 $outurl = $outurl."?".$urlCHCK['query']; }
577 if(isset($urlCHCK['fragment'])) {
578 $urlCHCK['fragment'] = str_replace(" ", "+", $urlCHCK['fragment']);
579 $outurl = $outurl."#".$urlCHCK['fragment']; }
580 if($opennew===true) {
581 $outlink = "<a onclick=\"window.open(this.href); return false;\" href=\"".$outurl."\">".$outurl."</a>"; }
582 if($opennew===false) {
583 $outlink = "<a href=\"".$outurl."\">".$outurl."</a>"; }
584 return $outlink; }
585 function url2link($string) {
586 return preg_replace_callback("/(?<![\">])\b([a-zA-Z]+)\:\/\/([a-z0-9\-\.@\:]+)(\:[0-9]+)?\/([A-Za-z0-9\.\/%\?\!\$\(\)\*\-_\:;,\+\@~]+)?(\?)?([A-Za-z0-9\.\/%&\=\?\!\$\(\)\*\-_\:;,\+\@~]+)?(\#)?([A-Za-z0-9\.\/%&\=\?\!\$\(\)\*\-_\:;,\+\@~]+)?/is", "pre_url2link", $string); }
587 function urlcheck($string) {
588 global $BoardURL;
589 $retnum = preg_match_all("/([a-zA-Z]+)\:\/\/([a-z0-9\-\.@\:]+)(\:[0-9]+)?\/([A-Za-z0-9\.\/%\?\!\$\(\)\*\-_\:;,\+\@~]+)?(\?)?([A-Za-z0-9\.\/%&\=\?\!\$\(\)\*\-_\:;,\+\@~]+)?(\#)?([A-Za-z0-9\.\/%&\=\?\!\$\(\)\*\-_\:;,\+\@~]+)?/is", $string, $urlcheck);
590 if(isset($urlcheck[0][0])) { $url = $urlcheck[0][0]; }
591 if(!isset($urlcheck[0][0])) { $url = $BoardURL; }
592 return $url; }
593 //Check to make sure theme exists
594 $BoardTheme = $Settings['DefaultTheme'];
595 $ThemeDir = $SettDir['themes'];
596 function chack_themes($theme) {
597 global $BoardTheme,$ThemeDir;
598 if(!isset($theme)) { $theme = null; }
599 if(preg_match("/([a-zA-Z]+)\:/isU",$theme)) {
600 $theme = $BoardTheme; }
601 if(!preg_match("/^[a-z0-9]+$/isU",$theme)) {
602 $theme = $BoardTheme; }
603 require('settings.php');
604 $ckskindir = dirname(realpath("settings.php"))."/".$ThemeDir;
605 if ($handle = opendir($ckskindir)) { $dirnum = null;
606 while (false !== ($ckfile = readdir($handle))) {
607 if ($dirnum==null) { $dirnum = 0; }
608 if (is_dir($ckskindir.$ckfile)&&file_exists($ckskindir.$ckfile."/info.php")) {
609 if ($ckfile != "." && $ckfile != "..") {
610 //require($ckskindir.$ckfile."/info.php");
611 $cktheme[$dirnum] = $ckfile;
612 ++$dirnum; } } }
613 closedir($handle); asort($cktheme); }
614 $theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
615 if(!in_array($theme,$cktheme)||strlen($theme)>26) {
616 $theme = $BoardTheme; } return $theme; }
617 // Make a url with query string
618 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
619 global $sidurls, $icharset, $debug_on;
620 $fileurl = null; if(!isset($ext)) { $ext = null; }
621 if($ext==null) { $ext = ".php"; }
622 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
623 $file = $file.$ext;
624 if($sidurls=="on"&&$qstr!="/") {
625 if(defined('SID')) {
626 if($qvarstr==null) { $qvarstr = SID; }
627 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
628 if($debug_on===true) {
629 if($qvarstr==null) { $qvarstr = "debug=on"; }
630 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
631 if($qvarstr==null) { $fileurl = $file; }
632 if($fixhtml===true) {
633 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
634 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
635 if($prexqstr!=null) {
636 $rene1 = explode("&",$prexqstr);
637 $renenum=count($rene1);
638 $renei=0;
639 $reneqstr = "index.php?";
640 if($qstr!="/") { $fileurl = $file."?"; }
641 if($qstr=="/") { $fileurl = $file."/"; }
642 while ($renei < $renenum) {
643 $rene2 = explode("=",$rene1[$renei]);
644 if(!isset($rene2[0])) { $rene2[0] = null; }
645 $rene2[1] = urlencode($rene2[1]);
646 if(!isset($rene2[0])) { $rene2[0] = null; }
647 $rene2[1] = urlencode($rene2[1]);
648 if($qstr!="/") {
649 $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
650 if($qstr=="/") {
651 $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
652 $reneis = $renei + 1;
653 if($qstr!="/") {
654 if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
655 ++$renei; } }
656 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
657 if($qvarstr!=null) {
658 if($prexqstr==null) {
659 if($qstr!="/") { $fileurl = $file."?"; }
660 if($qstr=="/") { $fileurl = $file."/"; } }
661 $cind1 = explode("&",$qvarstr);
662 $cindnum=count($cind1);
663 $cindi=0;
664 $cindqstr = "index.php?";
665 while ($cindi < $cindnum) {
666 $cind2 = explode("=",$cind1[$cindi]);
667 if(!isset($cind2[0])) { $cind2[0] = null; }
668 $cind2[0] = urlencode($cind2[0]);
669 if(!isset($cind2[1])) { $cind2[1] = null; }
670 $cind2[1] = urlencode($cind2[1]);
671 if($qstr!="/") {
672 $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
673 if($qstr=="/") {
674 $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
675 $cindis = $cindi + 1;
676 if($qstr!="/") {
677 if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
678 ++$cindi; } }
679 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
680 if($exqstr!=null) {
681 if($qvarstr==null&&$prexqstr==null) {
682 if($qstr!="/") { $fileurl = $file."?"; }
683 if($qstr=="/") { $fileurl = $file."/"; } }
684 $sand1 = explode("&",$exqstr);
685 $sanum=count($sand1);
686 $sandi=0;
687 $sandqstr = "index.php?";
688 while ($sandi < $sanum) {
689 $sand2 = explode("=",$sand1[$sandi]);
690 if(!isset($sand2[0])) { $sand2[0] = null; }
691 $sand2[0] = urlencode($sand2[0]);
692 if(!isset($sand2[1])) { $sand2[1] = null; }
693 $sand2[1] = urlencode($sand2[1]);
694 if($qstr!="/") {
695 $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
696 if($qstr=="/") {
697 $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
698 $sandis = $sandi + 1;
699 if($qstr!="/") {
700 if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
701 ++$sandi; } }
702 return $fileurl; }
703 $thisdir = dirname(realpath("Preindex.php"))."/";
704 // Get the Query String
705 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
706 { $pregqstr = preg_quote($qstr,"/");
707 $pregqsep = preg_quote($qsep,"/");
708 $oqstr = $qstr; $oqsep = $qsep;
709 if($fixhtml===true||$fixhtml==null) {
710 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
711 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
712 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
713 $BoardQuery = "?".$OldBoardQuery;
714 return $BoardQuery; }
715 function log_fix_quotes($logtxt) {
716 $logtxt = str_replace("\"", "\\\"", $logtxt);
717 $logtxt = str_replace("'", "", $logtxt);
718 return $logtxt; }
719 function get_server_values($matches) {
720 $return_text = "-";
721 if(isset($_SERVER[$matches[1]])) { $return_text = $_SERVER[$matches[1]]; }
722 if(!isset($_SERVER[$matches[1]])) { $return_text = "-"; }
723 return $return_text; }
724 function get_cookie_values($matches) {
725 $return_text = null;
726 if(isset($_COOKIE[$matches[1]])) { $return_text = $_COOKIE[$matches[1]]; }
727 if(!isset($_COOKIE[$matches[1]])) { $return_text = null; }
728 return $return_text; }
729 function get_env_values($matches) {
730 $return_text = getenv($matches[1]);
731 if(!isset($return_text)) { $return_text = "-"; }
732 return $return_text; }
733 function get_setting_values($matches) {
734 global $Settings;
735 $return_text = null;
736 $matches[1] = str_replace("sqlpass", "sqluser", $matches[1]);
737 if(isset($Settings[$matches[1]])) { $return_text = $Settings[$matches[1]]; }
738 if(!isset($Settings[$matches[1]])) { $return_text = null; }
739 return $return_text; }
740 function log_fix_get_server_values($matches) {
741 return log_fix_quotes(get_server_values($matches)); }
742 function log_fix_get_cookie_values($matches) {
743 return log_fix_quotes(get_cookie_values($matches)); }
744 function log_fix_get_env_values($matches) {
745 return log_fix_quotes(get_env_values($matches)); }
746 function log_fix_get_setting_values($matches) {
747 return log_fix_quotes(get_setting_values($matches)); }
748 function get_time($matches) {
749 return date(convert_strftime($matches[1])); }
750 function convert_strftime($strftime) {
751 $strftime = str_replace("%%", "{percent\}p", $strftime);
752 $strftime = str_replace("%a", "D", $strftime);
753 $strftime = str_replace("%A", "l", $strftime);
754 $strftime = str_replace("%d", "d", $strftime);
755 $strftime = str_replace("%e", "j", $strftime);
756 $strftime = str_replace("%j", "z", $strftime);
757 $strftime = str_replace("%u", "w", $strftime);
758 $strftime = str_replace("%w", "w", $strftime);
759 $strftime = str_replace("%U", "W", $strftime);
760 $strftime = str_replace("%V", "W", $strftime);
761 $strftime = str_replace("%W", "W", $strftime);
762 $strftime = str_replace("%b", "M", $strftime);
763 $strftime = str_replace("%B", "F", $strftime);
764 $strftime = str_replace("%h", "M", $strftime);
765 $strftime = str_replace("%m", "m", $strftime);
766 $strftime = str_replace("%g", "y", $strftime);
767 $strftime = str_replace("%G", "Y", $strftime);
768 $strftime = str_replace("%y", "y", $strftime);
769 $strftime = str_replace("%Y", "Y", $strftime);
770 $strftime = str_replace("%H", "H", $strftime);
771 $strftime = str_replace("%I", "h", $strftime);
772 $strftime = str_replace("%l", "g", $strftime);
773 $strftime = str_replace("%M", "i", $strftime);
774 $strftime = str_replace("%p", "A", $strftime);
775 $strftime = str_replace("%P", "a", $strftime);
776 $strftime = str_replace("%r", "h:i:s A", $strftime);
777 $strftime = str_replace("%R", "H:i", $strftime);
778 $strftime = str_replace("%S", "s", $strftime);
779 $strftime = str_replace("%T", "H:i:s", $strftime);
780 $strftime = str_replace("%X", "H:i:s", $strftime);
781 $strftime = str_replace("%z", "O", $strftime);
782 $strftime = str_replace("%Z", "O", $strftime);
783 $strftime = str_replace("%c", "D M j H:i:s Y", $strftime);
784 $strftime = str_replace("%D", "m/d/y", $strftime);
785 $strftime = str_replace("%F", "Y-m-d", $strftime);
786 $strftime = str_replace("%x", "m/d/y", $strftime);
787 $strftime = str_replace("%n", "\n", $strftime);
788 $strftime = str_replace("%t", "\t", $strftime);
789 $strftime = preg_replace("/\{percent\}p/s", "%", $strftime);
790 return $strftime; }
791 function apache_log_maker($logtxt,$logfile=null,$status=200,$contentsize="-",$headersize=0) {
792 global $Settings;
793 if(isset($Settings['DefaultTimeZone'])) {
794 $servtz = new DateTimeZone($Settings['DefaultTimeZone']); }
795 if(!isset($Settings['DefaultTimeZone'])) {
796 $servtz = new DateTimeZone(date_default_timezone_get()); }
797 $servcurtime = new DateTime();
798 $servcurtime->setTimezone($servtz);
799 if(!isset($_SERVER['HTTP_REFERER'])) { $LOG_URL_REFERER = "-"; }
800 if(isset($_SERVER['HTTP_REFERER'])) { $LOG_URL_REFERER = $_SERVER['HTTP_REFERER']; }
801 if($LOG_URL_REFERER==""||$LOG_URL_REFERER==null) { $LOG_URL_REFERER = "-"; }
802 if(trim($LOG_URL_REFERER, "\x00..\x1F") == "") { $LOG_URL_REFERER = "-"; }
803 $LOG_URL_REFERER = log_fix_quotes($LOG_URL_REFERER);
804 if(!isset($_SERVER['PHP_AUTH_USER'])) { $LOG_AUTH_USER = "-"; }
805 if(isset($_SERVER['PHP_AUTH_USER'])) { $LOG_AUTH_USER = $_SERVER['PHP_AUTH_USER']; }
806 if($LOG_AUTH_USER==""||$LOG_AUTH_USER==null) { $LOG_AUTH_USER = "-"; }
807 if(trim($LOG_AUTH_USER, "\x00..\x1F") == "") { $LOG_AUTH_USER = "-"; }
808 $LOG_AUTH_USER = log_fix_quotes($LOG_AUTH_USER);
809 if(!isset($_SERVER["HTTP_USER_AGENT"])) { $LOG_USER_AGENT = "-"; }
810 if(isset($_SERVER["HTTP_USER_AGENT"])) { $LOG_USER_AGENT = $_SERVER["HTTP_USER_AGENT"]; }
811 if($LOG_USER_AGENT==""||$LOG_USER_AGENT==null) { $LOG_USER_AGENT = "-"; }
812 if(trim($LOG_USER_AGENT, "\x00..\x1F") == "") { $LOG_USER_AGENT = "-"; }
813 $LOG_USER_AGENT = log_fix_quotes($LOG_USER_AGENT);
814 $LogMemName = "-";
815 if(!isset($_SESSION['MemberName'])) {
816 $_SESSION['MemberName'] = null; }
817 if($_SESSION['MemberName']===null) {
818 $LogMemName = "-"; }
819 if(isset($_SESSION['MemberName'])&&$_SESSION['MemberName']!==null) {
820 $LogMemName = $_SESSION['MemberName']; }
821 if(trim($LogMemName, "\x00..\x1F") == "") { $LogMemName = "-"; }
822 $LogMemName = log_fix_quotes($LogMemName);
823 $LogMemID = "-";
824 if(!isset($_SESSION['UserID'])) {
825 $_SESSION['UserID'] = 0; }
826 if($_SESSION['UserID']===null||$_SESSION['UserID']===0) {
827 $LogMemID = "-"; }
828 if(isset($_SESSION['UserID'])&&$_SESSION['UserID']!==null&&$_SESSION['UserID']!==0) {
829 $LogMemID = $_SESSION['UserID']; }
830 if(trim($LogMemID, "\x00..\x1F") == "") { $LogMemID = "-"; }
831 $LogMemID = log_fix_quotes($LogMemID);
832 $LogGroupName = "-";
833 if(!isset($_SESSION['UserGroup'])) {
834 $LogGroupName = "-"; }
835 if(isset($_SESSION['UserGroup'])&&$_SESSION['UserGroup']===null) {
836 $LogGroupName = "-"; }
837 if(isset($_SESSION['UserGroup'])&&$_SESSION['UserGroup']!==null) {
838 $LogGroupName = $_SESSION['UserGroup']; }
839 if(trim($LogGroupName, "\x00..\x1F") == "") { $LogGroupName = "-"; }
840 $LogGroupName = log_fix_quotes($LogGroupName);
841 $LogGroupID = "-";
842 if(!isset($_SESSION['UserGroupID'])) {
843 $LogGroupID = "-"; }
844 if(isset($_SESSION['UserGroupID'])&&$_SESSION['UserGroupID']===null) {
845 $LogGroupID = "-"; }
846 if(isset($_SESSION['UserGroupID'])&&$_SESSION['UserGroupID']!==null) {
847 $LogGroupID = $_SESSION['UserGroupID']; }
848 if(trim($LogGroupID, "\x00..\x1F") == "") { $LogGroupID = "-"; }
849 $LogGroupID = log_fix_quotes($LogGroupID);
850 $LOG_QUERY_STRING = "";
851 if($_SERVER["QUERY_STRING"]!=="") {
852 $LOG_QUERY_STRING = "?".$_SERVER["QUERY_STRING"]; }
853 if(trim($LOG_QUERY_STRING, "\x00..\x1F") == "") { $LOG_QUERY_STRING = ""; }
854 $LOG_QUERY_STRING = log_fix_quotes($LOG_QUERY_STRING);
855 $oldcontentsize = $contentsize;
856 if($oldcontentsize=="-") { $oldcontentsize = 0; }
857 if($contentsize===0) { $contentsize = "-"; }
858 if($contentsize=="-"&&$headersize!==0) { $fullsitesize = $headersize; }
859 if($contentsize!="-"&&$headersize!==0) { $fullsitesize = $contentsize + $headersize; }
860 if($status=="302") { $contentsize = "-"; }
861 $HTTP_REQUEST_LINE = $_SERVER["REQUEST_METHOD"]." ".$_SERVER["REQUEST_URI"]." ".$_SERVER["SERVER_PROTOCOL"];
862 $HTTP_REQUEST_LINE = log_fix_quotes($HTTP_REQUEST_LINE);
863 $logtxt = preg_replace("/%%/s", "{percent}p", $logtxt);
864 $logtxt = preg_replace("/%([\<\>]*?)a/s", $_SERVER['REMOTE_ADDR'], $logtxt);
865 $logtxt = preg_replace("/%([\<\>]*?)A/s", $_SERVER["SERVER_ADDR"], $logtxt);
866 $logtxt = preg_replace("/%([\<\>]*?)B/s", $oldcontentsize, $logtxt);
867 $logtxt = preg_replace("/%([\<\>]*?)b/s", $contentsize, $logtxt);
868 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}C/s", "get_cookie_values", $logtxt);
869 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}e/s", "get_env_values", $logtxt);
870 $logtxt = preg_replace("/%([\<\>]*?)f/s", log_fix_quotes($_SERVER["SCRIPT_FILENAME"]), $logtxt);
871 $logtxt = preg_replace("/%([\<\>]*?)h/s", $_SERVER['REMOTE_ADDR'], $logtxt);
872 $logtxt = preg_replace("/%([\<\>]*?)H/s", $_SERVER["SERVER_PROTOCOL"], $logtxt);
873 $logtxt = preg_replace("/%([\<\>]*?)\{Referer\}i/s", $LOG_URL_REFERER, $logtxt);
874 $logtxt = preg_replace("/%([\<\>]*?)\{User-Agent\}i/s", $LOG_USER_AGENT, $logtxt);
875 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}i/s", "get_server_values", $logtxt);
876 $logtxt = preg_replace("/%([\<\>]*?)l/s", "-", $logtxt);
877 $logtxt = preg_replace("/%([\<\>]*?)m/s", $_SERVER["REQUEST_METHOD"], $logtxt);
878 $logtxt = preg_replace("/%([\<\>]*?)p/s", $_SERVER["SERVER_PORT"], $logtxt);
879 $logtxt = preg_replace("/%([\<\>]*?)q/s", $LOG_QUERY_STRING, $logtxt);
880 $logtxt = preg_replace("/%([\<\>]*?)r/s", $HTTP_REQUEST_LINE, $logtxt);
881 $logtxt = preg_replace("/%([\<\>]*?)s/s", $status, $logtxt);
882 $logtxt = preg_replace("/%([\<\>]*?)t/s", "[".$servcurtime->format("d/M/Y:H:i:s O")."]", $logtxt);
883 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}t/s", "get_time", $logtxt);
884 $logtxt = preg_replace("/%([\<\>]*?)u/s", $LOG_AUTH_USER, $logtxt);
885 $logtxt = preg_replace("/%([\<\>]*?)U/s", log_fix_quotes($_SERVER["PHP_SELF"]), $logtxt);
886 $logtxt = preg_replace("/%([\<\>]*?)v/s", $_SERVER["SERVER_NAME"], $logtxt);
887 $logtxt = preg_replace("/%([\<\>]*?)V/s", $_SERVER["SERVER_NAME"], $logtxt);
888 // Not what it should be but PHP dose not have variable to get Apache ServerName config value. :(
889 $logtxt = preg_replace("/%([\<\>]*?)O/s", $fullsitesize, $logtxt);
890 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}s/s", "get_setting_values", $logtxt);
891 $logtxt = preg_replace("/\%\{UserName\}m/s", $LogMemName, $logtxt);
892 $logtxt = preg_replace("/\%\{MemberName\}m/s", $LogMemName, $logtxt);
893 $logtxt = preg_replace("/\%\{UserID\}m/s", $LogMemID, $logtxt);
894 $logtxt = preg_replace("/\%\{MemberID\}m/s", $LogMemID, $logtxt);
895 $logtxt = preg_replace("/\%\{UserGroup\}m/s", $LogGroupName, $logtxt);
896 $logtxt = preg_replace("/\%\{MemberGroup\}m/s", $LogGroupName, $logtxt);
897 $logtxt = preg_replace("/\%\{UserGroupID\}m/s", $LogGroupID, $logtxt);
898 $logtxt = preg_replace("/\%\{MemberGroupID\}m/s", $LogGroupID, $logtxt);
899 $logtxt = preg_replace("/\{percent\}p/s", "%", $logtxt);
900 if(isset($logfile)&&$logfile!==null) {
901 $fp = fopen($logfile, "a+");
902 if (flock($fp, LOCK_EX)) {
903 $logtxtnew = $logtxt."\r\n";
904 fwrite($fp, $logtxtnew, strlen($logtxtnew));
905 flock($fp, LOCK_UN); }
906 fclose($fp);
907 @chmod($logfile, 0666); }
908 return $logtxt; }
909 function idb_log_maker($status=200,$contentsize="-") {
910 global $Settings,$SettDir;
911 if(isset($Settings['DefaultTimeZone'])) {
912 $servtz = new DateTimeZone($Settings['DefaultTimeZone']); }
913 if(!isset($Settings['DefaultTimeZone'])) {
914 $servtz = new DateTimeZone(date_default_timezone_get()); }
915 $servcurtime = new DateTime();
916 $servcurtime->setTimezone($servtz);
917 if(!isset($Settings['log_http_request'])) {
918 $Settings['log_http_request'] = "off"; }
919 if(!isset($Settings['log_config_format'])) {
920 $Settings['log_config_format'] = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""; }
921 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']=="on"&&
922 $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
923 return apache_log_maker($Settings['log_config_format'], $SettDir['logs'].$Settings['sqltable'].$servcurtime->format("Ym").".log", $status, $contentsize, strlen(implode("\r\n",headers_list())."\r\n\r\n")); }
924 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']!="on"&&
925 $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
926 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}t", "/")."/s", "get_time", $Settings['log_http_request']);
927 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}s", "/")."/s", "get_setting_values", $Settings['log_http_request']);
928 return apache_log_maker($Settings['log_config_format'], $SettDir['logs'].$Settings['log_http_request'], $status, $contentsize, strlen(implode("\r\n",headers_list())."\r\n\r\n")); } }