OSDN Git Service

Add files via upload
[idb/iDB.git.git] / inc / function.php
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.
5
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.
10
11     Copyright 2004-2019 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12     Copyright 2004-2019 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
13
14     $FileInfo: function.php - Last Update: 4/8/2022 SVN 947 - Author: cooldude2k $
15 */
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/
31  */
32 function fix_magic_quotes()
33 {
34    if (get_magic_quotes_gpc()) {
35       $func = create_function(
36          '&$val, $key',
37          'if(!is_numeric($val)) {$val = stripslashes($val);}'
38       );
39       array_walk_recursive($_GET, $func);
40       array_walk_recursive($_POST, $func);
41       array_walk_recursive($_COOKIE, $func);
42    }
43    return true;
44 }
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         $Names['D'] = "Dagmara";
97 define("_dagmara_", $Names['D']);
98 // By s rotondo90 at gmail com at https://www.php.net/manual/en/function.random-int.php#119670
99 if (!function_exists('random_int')) {
100     function random_int($min, $max) {
101         if (!function_exists('mcrypt_create_iv')) {
102             trigger_error(
103                 'mcrypt must be loaded for random_int to work', 
104                 E_USER_WARNING
105             );
106             return null;
107         }
108         
109         if (!is_int($min) || !is_int($max)) {
110             trigger_error('$min and $max must be integer values', E_USER_NOTICE);
111             $min = (int)$min;
112             $max = (int)$max;
113         }
114         
115         if ($min > $max) {
116             trigger_error('$max can\'t be lesser than $min', E_USER_WARNING);
117             return null;
118         }
119         
120         $range = $counter = $max - $min;
121         $bits = 1;
122         
123         while ($counter >>= 1) {
124             ++$bits;
125         }
126         
127         $bytes = (int)max(ceil($bits/8), 1);
128         $bitmask = pow(2, $bits) - 1;
129
130         if ($bitmask >= PHP_INT_MAX) {
131             $bitmask = PHP_INT_MAX;
132         }
133
134         do {
135             $result = hexdec(
136                 bin2hex(
137                     mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
138                 )
139             ) & $bitmask;
140         } while ($result > $range);
141
142         return $result + $min;
143     }
144 }
145 // http://us.php.net/manual/en/function.uniqid.php#94959
146 /**
147   * Generates an UUID
148   * 
149   * @author     Andrew Moore
150   * @url        http://us.php.net/manual/en/function.uniqid.php#94959
151   */
152 function uuid_old($uuidver = "v4", $rndty = "rand", $namespace = null, $name = null) {
153 if($uuidver!="v3"&&$uuidver!="v4"&&$uuidver!="v5") { $uuidver = "v4"; }
154 if($uuidver=="v4") {
155     return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
156       $rndty(0, 0xffff), $rndty(0, 0xffff),
157       $rndty(0, 0xffff),
158       $rndty(0, 0x0fff) | 0x4000,
159       $rndty(0, 0x3fff) | 0x8000,
160       $rndty(0, 0xffff), $rndty(0, 0xffff), $rndty(0, 0xffff) ); }
161 if($uuidver=="v3"||$uuidver=="v5") {
162         if($namespace===null) {
163         $namespace = uuid_old("v4",$rndty); }
164     $nhex = str_replace(array('-','{','}'), '', $namespace);
165     $nstr = '';
166     for($i = 0; $i < strlen($nhex); $i+=2) {
167       if(isset($nhex[$i+1])) {
168           $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); }
169       if(!isset($nhex[$i+1])) {
170           $nstr .= chr(hexdec($nhex[$i])); }
171     }
172         if($name===null) { $name = salt_hmac(); }
173     // Calculate hash value
174         if($uuidver=="v3") {
175         $uuidverid = 0x3000;
176         if (function_exists('hash')) {
177         $hash = hash("md5", $nstr . $name); }
178         if (!function_exists('hash')) {
179         $hash = md5($nstr . $name); } }
180         if($uuidver=="v5") {
181         $uuidverid = 0x5000;
182         if (function_exists('hash')) {
183         $hash = hash("sha1", $nstr . $name); }
184         if (!function_exists('hash')) {
185         $hash = sha1($nstr . $name); } }
186     return sprintf('%08s-%04s-%04x-%04x-%12s',
187       substr($hash, 0, 8),
188       substr($hash, 8, 4),
189       (hexdec(substr($hash, 12, 4)) & 0x0fff) | $uuidverid,
190       (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
191       substr($hash, 20, 12) ); } }
192 class UUID {
193   public static function v3($namespace, $name) {
194     if(!self::is_valid($namespace)) return false;
195
196     // Get hexadecimal components of namespace
197     $nhex = str_replace(array('-','{','}'), '', $namespace);
198
199     // Binary Value
200     $nstr = '';
201
202     // Convert Namespace UUID to bits
203     for($i = 0; $i < strlen($nhex); $i+=2) {
204       $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
205     }
206
207     // Calculate hash value
208     $hash = md5($nstr . $name);
209
210     return sprintf('%08s-%04s-%04x-%04x-%12s',
211
212       // 32 bits for "time_low"
213       substr($hash, 0, 8),
214
215       // 16 bits for "time_mid"
216       substr($hash, 8, 4),
217
218       // 16 bits for "time_hi_and_version",
219       // four most significant bits holds version number 3
220       (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
221
222       // 16 bits, 8 bits for "clk_seq_hi_res",
223       // 8 bits for "clk_seq_low",
224       // two most significant bits holds zero and one for variant DCE1.1
225       (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
226
227       // 48 bits for "node"
228       substr($hash, 20, 12)
229     );
230   }
231
232   public static function v4() {
233     return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
234
235       // 32 bits for "time_low"
236       mt_rand(0, 0xffff), mt_rand(0, 0xffff),
237
238       // 16 bits for "time_mid"
239       mt_rand(0, 0xffff),
240
241       // 16 bits for "time_hi_and_version",
242       // four most significant bits holds version number 4
243       mt_rand(0, 0x0fff) | 0x4000,
244
245       // 16 bits, 8 bits for "clk_seq_hi_res",
246       // 8 bits for "clk_seq_low",
247       // two most significant bits holds zero and one for variant DCE1.1
248       mt_rand(0, 0x3fff) | 0x8000,
249
250       // 48 bits for "node"
251       mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
252     );
253   }
254
255   public static function v5($namespace, $name) {
256     if(!self::is_valid($namespace)) return false;
257
258     // Get hexadecimal components of namespace
259     $nhex = str_replace(array('-','{','}'), '', $namespace);
260
261     // Binary Value
262     $nstr = '';
263
264     // Convert Namespace UUID to bits
265     for($i = 0; $i < strlen($nhex); $i+=2) {
266       $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
267     }
268
269     // Calculate hash value
270     $hash = sha1($nstr . $name);
271
272     return sprintf('%08s-%04s-%04x-%04x-%12s',
273
274       // 32 bits for "time_low"
275       substr($hash, 0, 8),
276
277       // 16 bits for "time_mid"
278       substr($hash, 8, 4),
279
280       // 16 bits for "time_hi_and_version",
281       // four most significant bits holds version number 5
282       (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
283
284       // 16 bits, 8 bits for "clk_seq_hi_res",
285       // 8 bits for "clk_seq_low",
286       // two most significant bits holds zero and one for variant DCE1.1
287       (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
288
289       // 48 bits for "node"
290       substr($hash, 20, 12)
291     );
292   }
293
294   public static function is_valid($uuid) {
295     return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
296                       '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
297   }
298 }
299 function uuid($uuidver = "v4", $rndty = "rand", $namespace = null, $name = null) {
300  if($uuidver!="v3"&&$uuidver!="v4"&&$uuidver!="v5") { $uuidver = "v4"; }
301  if($uuidver=="v3") { return UUID::v3(UUID::v4(), salt_hmac()); }
302  if($uuidver=="v3") { return UUID::v4(); }
303  if($uuidver=="v3") { return UUID::v5(UUID::v4(), salt_hmac()); }
304  return false; }
305 // By info at raymondrodgers dot com at https://www.php.net/manual/en/function.random-int.php#118636
306 function generateUUIDv4()
307 {
308     if(version_compare(PHP_VERSION,'7.0.0', '<') )
309     {
310         return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
311         
312         // 32 bits for "time_low"
313         mt_rand(0, 0xffff), mt_rand(0, 0xffff),
314         
315         // 16 bits for "time_mid"
316         mt_rand(0, 0xffff),
317         
318         // 16 bits for "time_hi_and_version",
319         // four most significant bits holds version number 4
320         mt_rand(0, 0x0fff) | 0x4000,
321         
322         // 16 bits, 8 bits for "clk_seq_hi_res",
323         // 8 bits for "clk_seq_low",
324         // two most significant bits holds zero and one for variant DCE1.1
325         mt_rand(0, 0x3fff) | 0x8000,
326         
327         // 48 bits for "node"
328         mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
329         );
330     }
331     else
332     {
333         return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
334         
335         // 32 bits for "time_low"
336         random_int(0, 0xffff), random_int(0, 0xffff),
337         
338         // 16 bits for "time_mid"
339         random_int(0, 0xffff),
340         
341         // 16 bits for "time_hi_and_version",
342         // four most significant bits holds version number 4
343         random_int(0, 0x0fff) | 0x4000,
344         
345         // 16 bits, 8 bits for "clk_seq_hi_res",
346         // 8 bits for "clk_seq_low",
347         // two most significant bits holds zero and one for variant DCE1.1
348         random_int(0, 0x3fff) | 0x8000,
349         
350         // 48 bits for "node"
351         random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff)
352         );
353     }
354 }
355 function rand_uuid_old($rndty = "rand", $namespace = null, $name = null) {
356 $rand_array = array(1 => "v3", 2 => "v4", 3 => "v5");
357 if($name===null) { $name = salt_hmac(); }
358 $my_uuid = $rand_array[$rndty(1,3)];
359 if($my_uuid=="v4") { return uuid_old("v4",$rndty); }
360 if($my_uuid=="v3"||$my_uuid=="v5") {
361 return uuid_old($my_uuid,$rndty,$name); } }
362 function rand_uuid($rndty = "rand", $namespace = null, $name = null) {
363 $rand_array = array(1 => "v3", 2 => "v4", 3 => "v5");
364 if($name===null) { $name = salt_hmac(); }
365 $my_uuid = $rand_array[$rndty(1,3)];
366 if($my_uuid=="v4") { return uuid("v4",$rndty); }
367 if($my_uuid=="v3"||$my_uuid=="v5") {
368 return uuid($my_uuid,$rndty,$name); } }
369 // unserialize sessions variables
370 // By: jason@joeymail.net
371 // URL: http://us2.php.net/manual/en/function.session-decode.php#101687
372 function unserialize_session($data)
373 {
374     if(  strlen( $data) == 0)
375     {
376         return array();
377     }
378     // match all the session keys and offsets
379     preg_match_all('/(^|;|\})([a-zA-Z0-9_]+)\|/i', $data, $matchesarray, PREG_OFFSET_CAPTURE);
380     $returnArray = array();
381     $lastOffset = null;
382     $currentKey = '';
383     foreach ( $matchesarray[2] as $value )
384     {
385         $offset = $value[1];
386         if(!is_null( $lastOffset))
387         {
388             $valueText = substr($data, $lastOffset, $offset - $lastOffset );
389             $returnArray[$currentKey] = unserialize($valueText);
390         }
391         $currentKey = $value[0];
392         $lastOffset = $offset + strlen( $currentKey )+1;
393     }
394     $valueText = substr($data, $lastOffset );
395     $returnArray[$currentKey] = unserialize($valueText);
396     return $returnArray;
397 }
398 // Make the Query String if we are not useing &=
399 function qstring($qstr=";",$qsep="=")
400 { $_GET = array(); $_GET = null;
401 if (!isset($_SERVER['QUERY_STRING'])) {
402 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
403 ini_set("arg_separator.input", $qstr);
404 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
405 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
406 $qsnum = count($preqs); $qsi = 0;
407 while ($qsi < $qsnum) {
408 $preqst = explode($qsep,$preqs[$qsi],2);
409 $fix1 = array(" ",'$'); $fix2  = array("_","_");
410 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
411 $preqst[0] = killbadvars($preqst[0]);
412 if($preqst[0]!=null) {
413 $_GET[$preqst[0]] = $preqst[1]; }
414 ++$qsi; } return true; }
415 if($Settings['qstr']!="&"&&
416         $Settings['qstr']!="/") {
417 qstring($Settings['qstr'],$Settings['qsep']); 
418 if(!isset($_GET['page'])) { $_GET['page'] = null; }
419 if(!isset($_GET['act'])) { $_GET['act'] = null; }
420 if(!isset($_POST['act'])) { $_POST['act'] = null; }
421 if(!isset($_GET['id'])) { $_GET['id'] = null; } 
422 if(!isset($_GET['debug'])) { $_GET['debug'] = "false"; }
423 if(!isset($_GET['post'])) { $_GET['post'] = null; }
424 if(!isset($_POST['License'])) { $_POST['License'] = null; } }
425 if(isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO']==null) {
426         if(getenv('PATH_INFO')!=null&&getenv('PATH_INFO')!="1") {
427 $_SERVER['PATH_INFO'] = getenv('PATH_INFO'); }
428 if(getenv('PATH_INFO')==null) {
429 $myscript = $_SERVER["SCRIPT_NAME"];
430 $myphpath = $_SERVER["PHP_SELF"];
431 $mypathinfo = str_replace($myscript, "", $myphpath);
432 @putenv("PATH_INFO=".$mypathinfo); } }
433 // Change raw post data to POST array
434 // Not sure why I made but alwell. :P 
435 function parse_post_data()
436 { $_POST = array(); $_POST = null;
437 $postdata = file_get_contents("php://input");
438 if (!isset($postdata)) { $postdata = null; }
439 $postdata = urldecode($postdata);
440 $preqs = explode("&",$postdata);
441 $qsnum = count($preqs); $qsi = 0;
442 while ($qsi < $qsnum) {
443 $preqst = explode("=",$preqs[$qsi],2);
444 $fix1 = array(" ",'$'); $fix2  = array("_","_");
445 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
446 $preqst[0] = killbadvars($preqst[0]);
447 if($preqst[0]!=null) {
448 $_POST[$preqst[0]] = $preqst[1]; }
449 ++$qsi; } return true; }
450 // Change Path info to Get Vars :
451 function mrstring() {
452 $urlvar = explode('/',$_SERVER['PATH_INFO']);
453 $num=count($urlvar); $i=1;
454 while ($i < $num) {
455 //$urlvar[$i] = urldecode($urlvar[$i]);
456 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
457 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
458 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
459 $fix1 = array(" ",'$'); $fix2  = array("_","_");
460 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
461 $urlvar[$i] = killbadvars($urlvar[$i]);
462         $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
463 ++$i; ++$i; } return true; }
464 // Redirect to another file with ether timed or nontimed redirect
465 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
466 if($type!="location"&&$type!="refresh") { $type=="location"; }
467 if($url!=null) { $file = $url.$file; }
468 if($dbsr===true) { $file = str_replace("//", "/", $file); }
469 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
470 if($type=="location") { session_write_close(); 
471 header("Location: ".$file); } return true; }
472 function redirects($type,$url,$time=0) {
473 if($type!="location"&&$type!="refresh") { $type=="location"; }
474 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
475 if($type=="location") { idb_log_maker(302,"-"); }
476 if($type=="location") { header("Location: ".$url); } return true; }
477 // Make xhtml tags
478 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
479         $var_num = count($attbvar); $value_num = count($attbval);
480         if($var_num!=$value_num) { 
481                 output_error("Erorr Number of Var and Values dont match!",E_USER_ERROR);
482         return false; } $i = 0;
483         while ($i < $var_num) {
484         if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
485         if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
486         if($i==$var_num-1) { 
487         if($emptytag===false) { $mytag = $mytag.">"; }
488         if($emptytag===true) { $mytag = $mytag." />"; } }       ++$i; }
489         if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
490         if($emptytag===true) { $mytag = $mytag." />"; }
491         if($emptytag===false) { $mytag = $mytag.">"; } }
492         if($emptytag===false&&$extratest!=null) { 
493         $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; } 
494         return $mytag; }
495 // Start a xml document
496 function xml_tag_make($type,$attbs,$retval=false) {
497         $melanie1 = explode("&",$attbs);
498         $melanienum=count($melanie1);
499         $melaniei=0; $attblist = null;
500         while ($melaniei < $melanienum) {
501         $melanie2 = explode("=",$melanie1[$melaniei]);
502         if($melanie2[0]!=null||$melanie2[1]!=null) {
503         $attblist = $attblist.' '.$melanie2[0].'="'.$melanie2[1].'"'; }
504         ++$melaniei; }
505         if($retval!==false&&$retval!==true) { $retval=false; }
506         if($retval===false) {
507         echo '<?'.$type.$attblist.'?>'."\n"; }
508         if($retval===true) {
509         return '<?'.$type.$attblist.'?>'."\n"; } }
510 // Start a xml document (old version)
511 function xml_doc_start($ver,$encode,$retval=false) {
512         if($retval===false) {
513         echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
514         if($retval===true) {
515         return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
516 $icharset = $Settings['charset'];
517 $debug_on = false;
518 if(isset($_GET['debug'])) {
519 if($_GET['debug']=="true"||
520         $_GET['debug']=="on") {
521 $debug_on = true; } }
522 $BoardURL = $Settings['idburl'];
523 // Change URLs to Links
524 function pre_url2link($matches) {
525 global $BoardURL; $opennew = true;
526 $burlCHCK = parse_url($BoardURL);
527 $urlCHCK = parse_url($matches[0]);
528 if($urlCHCK['host']==$burlCHCK['host']) {
529         $opennew = false; }
530 $outurl = $urlCHCK['scheme']."://";
531 if(isset($urlCHCK['user'])) {
532 $outurl = $outurl.$urlCHCK['user'];
533 if(isset($urlCHCK['pass'])) {
534 $outurl = $outurl.":".$urlCHCK['pass']; }
535 $outurl = $outurl."@"; }
536 $outurl = $outurl.$urlCHCK['host'];
537 if(isset($urlCHCK['path'])) {
538 $outurl = $outurl.$urlCHCK['path']; }
539 if(!isset($urlCHCK['path'])) {
540 $outurl = $outurl."/"; }
541 if(isset($urlCHCK['query'])) {
542 $urlCHCK['query'] = str_replace(" ", "+", $urlCHCK['query']);
543 $outurl = $outurl."?".$urlCHCK['query']; }
544 if(isset($urlCHCK['fragment'])) {
545 $urlCHCK['fragment'] = str_replace(" ", "+", $urlCHCK['fragment']);
546 $outurl = $outurl."#".$urlCHCK['fragment']; }
547 if($opennew===true) {
548 $outlink = "<a onclick=\"window.open(this.href); return false;\" href=\"".$outurl."\">".$outurl."</a>"; }
549 if($opennew===false) {
550 $outlink = "<a href=\"".$outurl."\">".$outurl."</a>"; }
551 return $outlink; }
552 function url2link($string) {
553 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); }
554 function urlcheck($string) {
555 global $BoardURL;
556 $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); 
557 if(isset($urlcheck[0][0])) { $url = $urlcheck[0][0]; }
558 if(!isset($urlcheck[0][0])) { $url = $BoardURL; }
559 return $url; }
560 //Check to make sure theme exists
561 $BoardTheme = $Settings['DefaultTheme'];
562 $ThemeDir = $SettDir['themes'];
563 function chack_themes($theme) {
564 global $BoardTheme,$ThemeDir;
565 if(!isset($theme)) { $theme = null; }
566 if(preg_match("/([a-zA-Z]+)\:/isU",$theme)) {
567         $theme = $BoardTheme; }
568 if(!preg_match("/^[a-z0-9]+$/isU",$theme)) {
569         $theme = $BoardTheme; }
570 require('settings.php');
571 $ckskindir = dirname(realpath("settings.php"))."/".$ThemeDir;
572 if ($handle = opendir($ckskindir)) { $dirnum = null;
573    while (false !== ($ckfile = readdir($handle))) {
574            if ($dirnum==null) { $dirnum = 0; }
575            if (is_dir($ckskindir.$ckfile)&&file_exists($ckskindir.$ckfile."/info.php")) {
576                    if ($ckfile != "." && $ckfile != "..") {
577            //require($ckskindir.$ckfile."/info.php");
578        $cktheme[$dirnum] =  $ckfile;
579            ++$dirnum; } } }
580    closedir($handle); asort($cktheme); }
581 $theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
582 if(!in_array($theme,$cktheme)||strlen($theme)>26) {
583         $theme = $BoardTheme; } return $theme; }
584 // Make a url with query string
585 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
586 global $sidurls, $icharset, $debug_on;
587 $fileurl = null; if(!isset($ext)) { $ext = null; }
588 if($ext==null) { $ext = ".php"; } 
589 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
590 $file = $file.$ext;
591 if($sidurls=="on"&&$qstr!="/") { 
592         if(defined('SID')) {
593 if($qvarstr==null) { $qvarstr = SID; }
594 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
595 if($debug_on===true) {
596 if($qvarstr==null) { $qvarstr = "debug=on"; }
597 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
598 if($qvarstr==null) { $fileurl = $file; }
599 if($fixhtml===true) {
600 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
601 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
602 if($prexqstr!=null) { 
603 $rene1 = explode("&",$prexqstr);
604 $renenum=count($rene1);
605 $renei=0;
606 $reneqstr = "index.php?";
607 if($qstr!="/") { $fileurl = $file."?"; }
608 if($qstr=="/") { $fileurl = $file."/"; }
609 while ($renei < $renenum) {
610         $rene2 = explode("=",$rene1[$renei]);
611         if(!isset($rene2[0])) { $rene2[0] = null; }
612         $rene2[1] = urlencode($rene2[1]);
613         if(!isset($rene2[0])) { $rene2[0] = null; }
614         $rene2[1] = urlencode($rene2[1]);
615         if($qstr!="/") {
616         $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
617         if($qstr=="/") {
618         $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
619         $reneis = $renei + 1;
620         if($qstr!="/") {
621         if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
622         ++$renei; } }
623 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
624 if($qvarstr!=null) { 
625 if($prexqstr==null) {
626 if($qstr!="/") { $fileurl = $file."?"; }
627 if($qstr=="/") { $fileurl = $file."/"; } }
628 $cind1 = explode("&",$qvarstr);
629 $cindnum=count($cind1);
630 $cindi=0;
631 $cindqstr = "index.php?";
632 while ($cindi < $cindnum) {
633         $cind2 = explode("=",$cind1[$cindi]);
634         if(!isset($cind2[0])) { $cind2[0] = null; }
635         $cind2[0] = urlencode($cind2[0]);
636         if(!isset($cind2[1])) { $cind2[1] = null; }
637         $cind2[1] = urlencode($cind2[1]);
638         if($qstr!="/") {
639         $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
640         if($qstr=="/") {
641         $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
642         $cindis = $cindi + 1;
643         if($qstr!="/") {
644         if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
645         ++$cindi; } }
646 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
647 if($exqstr!=null) { 
648 if($qvarstr==null&&$prexqstr==null) {
649 if($qstr!="/") { $fileurl = $file."?"; }
650 if($qstr=="/") { $fileurl = $file."/"; } }
651 $sand1 = explode("&",$exqstr);
652 $sanum=count($sand1);
653 $sandi=0;
654 $sandqstr = "index.php?";
655 while ($sandi < $sanum) {
656         $sand2 = explode("=",$sand1[$sandi]);
657         if(!isset($sand2[0])) { $sand2[0] = null; }
658         $sand2[0] = urlencode($sand2[0]);
659         if(!isset($sand2[1])) { $sand2[1] = null; }
660         $sand2[1] = urlencode($sand2[1]);
661         if($qstr!="/") {
662         $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
663         if($qstr=="/") {
664         $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
665         $sandis = $sandi + 1;
666         if($qstr!="/") {
667         if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
668         ++$sandi; } }
669 return $fileurl; }
670 $thisdir = dirname(realpath("Preindex.php"))."/";
671 // Get the Query String
672 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
673 { $pregqstr = preg_quote($qstr,"/");
674 $pregqsep = preg_quote($qsep,"/");
675 $oqstr = $qstr; $oqsep = $qsep;
676 if($fixhtml===true||$fixhtml==null) {
677 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
678 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
679 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
680 $BoardQuery = "?".$OldBoardQuery;
681 return $BoardQuery; }
682 function log_fix_quotes($logtxt) {
683         $logtxt = str_replace("\"", "\\\"", $logtxt);
684         $logtxt = str_replace("'", "", $logtxt);
685         return $logtxt; }
686 function get_server_values($matches) {
687         $return_text = "-";
688         if(isset($_SERVER[$matches[1]])) { $return_text = $_SERVER[$matches[1]]; }
689         if(!isset($_SERVER[$matches[1]])) { $return_text = "-"; }
690         return $return_text; }
691 function get_cookie_values($matches) {
692         $return_text = null;
693         if(isset($_COOKIE[$matches[1]])) { $return_text = $_COOKIE[$matches[1]]; }
694         if(!isset($_COOKIE[$matches[1]])) { $return_text = null; }
695         return $return_text; }
696 function get_env_values($matches) {
697         $return_text = getenv($matches[1]);
698         if(!isset($return_text)) { $return_text = "-"; }
699         return $return_text; }
700 function get_setting_values($matches) {
701         global $Settings;
702         $return_text = null;
703         $matches[1] = str_replace("sqlpass", "sqluser", $matches[1]);
704         if(isset($Settings[$matches[1]])) { $return_text = $Settings[$matches[1]]; }
705         if(!isset($Settings[$matches[1]])) { $return_text = null; }
706         return $return_text; }
707 function log_fix_get_server_values($matches) {
708         return log_fix_quotes(get_server_values($matches)); }
709 function log_fix_get_cookie_values($matches) {
710         return log_fix_quotes(get_cookie_values($matches)); }
711 function log_fix_get_env_values($matches) {
712         return log_fix_quotes(get_env_values($matches)); }
713 function log_fix_get_setting_values($matches) {
714         return log_fix_quotes(get_setting_values($matches)); }
715 function get_time($matches) {
716         return date(convert_strftime($matches[1])); }
717 function convert_strftime($strftime) {
718 $strftime = str_replace("%%", "{percent\}p", $strftime);
719 $strftime = str_replace("%a", "D", $strftime);
720 $strftime = str_replace("%A", "l", $strftime);
721 $strftime = str_replace("%d", "d", $strftime);
722 $strftime = str_replace("%e", "j", $strftime);
723 $strftime = str_replace("%j", "z", $strftime);
724 $strftime = str_replace("%u", "w", $strftime);
725 $strftime = str_replace("%w", "w", $strftime);
726 $strftime = str_replace("%U", "W", $strftime);
727 $strftime = str_replace("%V", "W", $strftime);
728 $strftime = str_replace("%W", "W", $strftime);
729 $strftime = str_replace("%b", "M", $strftime);
730 $strftime = str_replace("%B", "F", $strftime);
731 $strftime = str_replace("%h", "M", $strftime);
732 $strftime = str_replace("%m", "m", $strftime);
733 $strftime = str_replace("%g", "y", $strftime);
734 $strftime = str_replace("%G", "Y", $strftime);
735 $strftime = str_replace("%y", "y", $strftime);
736 $strftime = str_replace("%Y", "Y", $strftime);
737 $strftime = str_replace("%H", "H", $strftime);
738 $strftime = str_replace("%I", "h", $strftime);
739 $strftime = str_replace("%l", "g", $strftime);
740 $strftime = str_replace("%M", "i", $strftime);
741 $strftime = str_replace("%p", "A", $strftime);
742 $strftime = str_replace("%P", "a", $strftime);
743 $strftime = str_replace("%r", "h:i:s A", $strftime);
744 $strftime = str_replace("%R", "H:i", $strftime);
745 $strftime = str_replace("%S", "s", $strftime);
746 $strftime = str_replace("%T", "H:i:s", $strftime);
747 $strftime = str_replace("%X", "H:i:s", $strftime);
748 $strftime = str_replace("%z", "O", $strftime);
749 $strftime = str_replace("%Z", "O", $strftime);
750 $strftime = str_replace("%c", "D M j H:i:s Y", $strftime);
751 $strftime = str_replace("%D", "m/d/y", $strftime);
752 $strftime = str_replace("%F", "Y-m-d", $strftime);
753 $strftime = str_replace("%x", "m/d/y", $strftime);
754 $strftime = str_replace("%n", "\n", $strftime);
755 $strftime = str_replace("%t", "\t", $strftime);
756 $strftime = preg_replace("/\{percent\}p/s", "%", $strftime);
757 return $strftime; }
758 function apache_log_maker($logtxt,$logfile=null,$status=200,$contentsize="-",$headersize=0) {
759 global $Settings;
760 if(isset($Settings['DefaultTimeZone'])) {
761 $servtz = new DateTimeZone($Settings['DefaultTimeZone']); }
762 if(!isset($Settings['DefaultTimeZone'])) {
763 $servtz = new DateTimeZone(date_default_timezone_get()); }
764 $servcurtime = new DateTime();
765 $servcurtime->setTimezone($servtz);
766 if(!isset($_SERVER['HTTP_REFERER'])) { $LOG_URL_REFERER = "-"; }
767 if(isset($_SERVER['HTTP_REFERER'])) { $LOG_URL_REFERER = $_SERVER['HTTP_REFERER']; }
768 if($LOG_URL_REFERER==""||$LOG_URL_REFERER==null) { $LOG_URL_REFERER = "-"; }
769 if(trim($LOG_URL_REFERER, "\x00..\x1F") == "") { $LOG_URL_REFERER = "-"; }
770 $LOG_URL_REFERER = log_fix_quotes($LOG_URL_REFERER);
771 if(!isset($_SERVER['PHP_AUTH_USER'])) { $LOG_AUTH_USER = "-"; }
772 if(isset($_SERVER['PHP_AUTH_USER'])) { $LOG_AUTH_USER = $_SERVER['PHP_AUTH_USER']; }
773 if($LOG_AUTH_USER==""||$LOG_AUTH_USER==null) { $LOG_AUTH_USER = "-"; }
774 if(trim($LOG_AUTH_USER, "\x00..\x1F") == "") { $LOG_AUTH_USER = "-"; }
775 $LOG_AUTH_USER = log_fix_quotes($LOG_AUTH_USER);
776 if(!isset($_SERVER["HTTP_USER_AGENT"])) { $LOG_USER_AGENT = "-"; }
777 if(isset($_SERVER["HTTP_USER_AGENT"])) { $LOG_USER_AGENT = $_SERVER["HTTP_USER_AGENT"]; }
778 if($LOG_USER_AGENT==""||$LOG_USER_AGENT==null) { $LOG_USER_AGENT = "-"; }
779 if(trim($LOG_USER_AGENT, "\x00..\x1F") == "") { $LOG_USER_AGENT = "-"; }
780 $LOG_USER_AGENT = log_fix_quotes($LOG_USER_AGENT);
781 $LogMemName = "-";
782 if(!isset($_SESSION['MemberName'])) {
783         $_SESSION['MemberName'] = null; }
784 if($_SESSION['MemberName']===null) {
785         $LogMemName = "-"; }
786 if(isset($_SESSION['MemberName'])&&$_SESSION['MemberName']!==null) {
787         $LogMemName = $_SESSION['MemberName']; }
788 if(trim($LogMemName, "\x00..\x1F") == "") { $LogMemName = "-"; }
789 $LogMemName = log_fix_quotes($LogMemName);
790 $LogMemID = "-";
791 if(!isset($_SESSION['UserID'])) {
792         $_SESSION['UserID'] = 0; }
793 if($_SESSION['UserID']===null||$_SESSION['UserID']===0) {
794         $LogMemID = "-"; }
795 if(isset($_SESSION['UserID'])&&$_SESSION['UserID']!==null&&$_SESSION['UserID']!==0) {
796         $LogMemID = $_SESSION['UserID']; }
797 if(trim($LogMemID, "\x00..\x1F") == "") { $LogMemID = "-"; }
798 $LogMemID = log_fix_quotes($LogMemID);
799 $LogGroupName = "-";
800 if(!isset($_SESSION['UserGroup'])) {
801         $LogGroupName = "-"; }
802 if(isset($_SESSION['UserGroup'])&&$_SESSION['UserGroup']===null) {
803         $LogGroupName = "-"; }
804 if(isset($_SESSION['UserGroup'])&&$_SESSION['UserGroup']!==null) {
805         $LogGroupName = $_SESSION['UserGroup']; }
806 if(trim($LogGroupName, "\x00..\x1F") == "") { $LogGroupName = "-"; }
807 $LogGroupName = log_fix_quotes($LogGroupName);
808 $LogGroupID = "-";
809 if(!isset($_SESSION['UserGroupID'])) {
810         $LogGroupID = "-"; }
811 if(isset($_SESSION['UserGroupID'])&&$_SESSION['UserGroupID']===null) {
812         $LogGroupID = "-"; }
813 if(isset($_SESSION['UserGroupID'])&&$_SESSION['UserGroupID']!==null) {
814         $LogGroupID = $_SESSION['UserGroupID']; }
815 if(trim($LogGroupID, "\x00..\x1F") == "") { $LogGroupID = "-"; }
816 $LogGroupID = log_fix_quotes($LogGroupID);
817 $LOG_QUERY_STRING = "";
818 if($_SERVER["QUERY_STRING"]!=="") {
819 $LOG_QUERY_STRING = "?".$_SERVER["QUERY_STRING"]; }
820 if(trim($LOG_QUERY_STRING, "\x00..\x1F") == "") { $LOG_QUERY_STRING = ""; }
821 $LOG_QUERY_STRING = log_fix_quotes($LOG_QUERY_STRING);
822 $oldcontentsize = $contentsize;
823 if($oldcontentsize=="-") { $oldcontentsize = 0; }
824 if($contentsize===0) { $contentsize = "-"; }
825 if($contentsize=="-"&&$headersize!==0) { $fullsitesize = $headersize; }
826 if($contentsize!="-"&&$headersize!==0) { $fullsitesize = $contentsize + $headersize; }
827 if($status=="302") { $contentsize = "-"; }
828 $HTTP_REQUEST_LINE = $_SERVER["REQUEST_METHOD"]." ".$_SERVER["REQUEST_URI"]." ".$_SERVER["SERVER_PROTOCOL"];
829 $HTTP_REQUEST_LINE = log_fix_quotes($HTTP_REQUEST_LINE);
830 $logtxt = preg_replace("/%%/s", "{percent}p", $logtxt);
831 $logtxt = preg_replace("/%([\<\>]*?)a/s", $_SERVER['REMOTE_ADDR'], $logtxt);
832 $logtxt = preg_replace("/%([\<\>]*?)A/s", $_SERVER["SERVER_ADDR"], $logtxt);
833 $logtxt = preg_replace("/%([\<\>]*?)B/s", $oldcontentsize, $logtxt);
834 $logtxt = preg_replace("/%([\<\>]*?)b/s", $contentsize, $logtxt);
835 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}C/s", "get_cookie_values", $logtxt);
836 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}e/s", "get_env_values", $logtxt);
837 $logtxt = preg_replace("/%([\<\>]*?)f/s", log_fix_quotes($_SERVER["SCRIPT_FILENAME"]), $logtxt);
838 $logtxt = preg_replace("/%([\<\>]*?)h/s", $_SERVER['REMOTE_ADDR'], $logtxt);
839 $logtxt = preg_replace("/%([\<\>]*?)H/s", $_SERVER["SERVER_PROTOCOL"], $logtxt);
840 $logtxt = preg_replace("/%([\<\>]*?)\{Referer\}i/s", $LOG_URL_REFERER, $logtxt);
841 $logtxt = preg_replace("/%([\<\>]*?)\{User-Agent\}i/s", $LOG_USER_AGENT, $logtxt);
842 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}i/s", "get_server_values", $logtxt);
843 $logtxt = preg_replace("/%([\<\>]*?)l/s", "-", $logtxt);
844 $logtxt = preg_replace("/%([\<\>]*?)m/s", $_SERVER["REQUEST_METHOD"], $logtxt);
845 $logtxt = preg_replace("/%([\<\>]*?)p/s", $_SERVER["SERVER_PORT"], $logtxt);
846 $logtxt = preg_replace("/%([\<\>]*?)q/s", $LOG_QUERY_STRING, $logtxt);
847 $logtxt = preg_replace("/%([\<\>]*?)r/s", $HTTP_REQUEST_LINE, $logtxt);
848 $logtxt = preg_replace("/%([\<\>]*?)s/s", $status, $logtxt);
849 $logtxt = preg_replace("/%([\<\>]*?)t/s", "[".$servcurtime->format("d/M/Y:H:i:s O")."]", $logtxt);
850 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}t/s", "get_time", $logtxt);
851 $logtxt = preg_replace("/%([\<\>]*?)u/s", $LOG_AUTH_USER, $logtxt);
852 $logtxt = preg_replace("/%([\<\>]*?)U/s", log_fix_quotes($_SERVER["PHP_SELF"]), $logtxt);
853 $logtxt = preg_replace("/%([\<\>]*?)v/s", $_SERVER["SERVER_NAME"], $logtxt);
854 $logtxt = preg_replace("/%([\<\>]*?)V/s", $_SERVER["SERVER_NAME"], $logtxt);
855 // Not what it should be but PHP dose not have variable to get Apache ServerName config value. :( 
856 $logtxt = preg_replace("/%([\<\>]*?)O/s", $fullsitesize, $logtxt);
857 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}s/s", "get_setting_values", $logtxt);
858 $logtxt = preg_replace("/\%\{UserName\}m/s", $LogMemName, $logtxt);
859 $logtxt = preg_replace("/\%\{MemberName\}m/s", $LogMemName, $logtxt);
860 $logtxt = preg_replace("/\%\{UserID\}m/s", $LogMemID, $logtxt);
861 $logtxt = preg_replace("/\%\{MemberID\}m/s", $LogMemID, $logtxt);
862 $logtxt = preg_replace("/\%\{UserGroup\}m/s", $LogGroupName, $logtxt);
863 $logtxt = preg_replace("/\%\{MemberGroup\}m/s", $LogGroupName, $logtxt);
864 $logtxt = preg_replace("/\%\{UserGroupID\}m/s", $LogGroupID, $logtxt);
865 $logtxt = preg_replace("/\%\{MemberGroupID\}m/s", $LogGroupID, $logtxt);
866 $logtxt = preg_replace("/\{percent\}p/s", "%", $logtxt);
867 if(isset($logfile)&&$logfile!==null) {
868         $fp = fopen($logfile, "a+");
869         if (flock($fp, LOCK_EX)) {
870                 $logtxtnew = $logtxt."\r\n";
871                 fwrite($fp, $logtxtnew, strlen($logtxtnew)); 
872                 flock($fp, LOCK_UN); }
873         fclose($fp); 
874         @chmod($logfile, 0666); }
875 return $logtxt; }
876 function idb_log_maker($status=200,$contentsize="-") {
877 global $Settings,$SettDir;
878 if(isset($Settings['DefaultTimeZone'])) {
879 $servtz = new DateTimeZone($Settings['DefaultTimeZone']); }
880 if(!isset($Settings['DefaultTimeZone'])) {
881 $servtz = new DateTimeZone(date_default_timezone_get()); }
882 $servcurtime = new DateTime();
883 $servcurtime->setTimezone($servtz);
884 if(!isset($Settings['log_http_request'])) {
885         $Settings['log_http_request'] = "off"; }
886 if(!isset($Settings['log_config_format'])) {
887         $Settings['log_config_format'] = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""; }
888 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']=="on"&&
889         $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
890 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")); }
891 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']!="on"&&
892         $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
893 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}t", "/")."/s", "get_time", $Settings['log_http_request']);
894 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}s", "/")."/s", "get_setting_values", $Settings['log_http_request']);
895 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")); } }
896 ?>