OSDN Git Service

Small bug.
[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-2011 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2011 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: function.php - Last Update: 07/20/2011 SVN 723 - 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 /* Change Some PHP Settings Fix the & to &amp;
24 if($Settings['use_iniset']==true&&$Settings['qstr']!="/") {
25 ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
26 ini_set("arg_separator.input",$Settings['qstr']);
27 ini_set("arg_separator",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset'])); }
28 //$basepath = pathinfo($_SERVER['REQUEST_URI']);
29 if(dirname($_SERVER['REQUEST_URI'])!="."||
30         dirname($_SERVER['REQUEST_URI'])!=null) {
31 $basedir = dirname($_SERVER['REQUEST_URI'])."/"; }*/
32 // Get the base dir name
33 /*if(dirname($_SERVER['SCRIPT_NAME'])!="."||
34         dirname($_SERVER['SCRIPT_NAME'])!=null) {
35 $basedir = dirname($_SERVER['SCRIPT_NAME'])."/"; }
36 if($basedir==null||$basedir==".") {
37 if(dirname($_SERVER['SCRIPT_NAME'])=="."||
38         dirname($_SERVER['SCRIPT_NAME'])==null) {
39 $basedir = dirname($_SERVER['PHP_SELF'])."/"; } }
40 if($basedir=="\/") { $basedir="/"; }
41 $basedir = str_replace("//", "/", $basedir);*/
42 if($Settings['qstr']!="/") {
43 $iDBURLCHK = $Settings['idburl']; }
44 if($Settings['qstr']=="/") {
45 $iDBURLCHK = preg_replace("/\/$/","",$Settings['idburl']); }
46 $basecheck = parse_url($iDBURLCHK);
47 $basedir = $basecheck['path'];
48 $cbasedir = $basedir;
49 $rbasedir = $basedir;
50 if($Settings['fixbasedir']!=null&&$Settings['fixbasedir']!="off") {
51                 $basedir = $Settings['fixbasedir']; }
52 if($Settings['fixcookiedir']!=null&&$Settings['fixcookiedir']!="") {
53                 $cbasedir = $Settings['fixcookiedir']; }
54 if($Settings['fixredirectdir']!=null) {
55                 $rbasedir = $Settings['fixredirectdir']; }
56 $BaseURL = $basedir;
57 // Get our Host Name and Referer URL's Host Name
58 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
59 $REFERERurl = parse_url($_SERVER['HTTP_REFERER']);
60 if(!isset($REFERERurl['host'])) { $REFERERurl['host'] = null; }
61 $URL['REFERER'] = $REFERERurl['host'];
62 $URL['HOST'] = $basecheck['host'];
63 $REFERERurl = null;
64 // Function made by Howard Yeend
65 // http://php.net/manual/en/function.trigger-error.php#92016
66 // http://www.puremango.co.uk/
67 function output_error($message, $level=E_USER_ERROR) {
68     $caller = next(debug_backtrace());
69     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); }
70         $Names['D'] = "Dagmara";
71 define("_dagmara_", $Names['D']);
72 // http://us.php.net/manual/en/function.uniqid.php#94959
73 /**
74   * Generates an UUID
75   * 
76   * @author     Andrew Moore
77   * @url        http://us.php.net/manual/en/function.uniqid.php#94959
78   */
79 function uuid($uuidver = "v4", $rndty = "rand", $namespace = null, $name = null) {
80 if($uuidver!="v3"&&$uuidver!="v4"&&$uuidver!="v5") { $uuidver = "v4"; }
81 if($uuidver=="v4") {
82     return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
83       $rndty(0, 0xffff), $rndty(0, 0xffff),
84       $rndty(0, 0xffff),
85       $rndty(0, 0x0fff) | 0x4000,
86       $rndty(0, 0x3fff) | 0x8000,
87       $rndty(0, 0xffff), $rndty(0, 0xffff), $rndty(0, 0xffff) ); }
88 if($uuidver=="v3"||$uuidver=="v5") {
89         if($namespace===null) {
90         $namespace = uuid("v4",$rndty); }
91     $nhex = str_replace(array('-','{','}'), '', $namespace);
92     $nstr = '';
93     for($i = 0; $i < strlen($nhex); $i+=2) {
94       if(isset($nhex[$i+1])) {
95           $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); }
96       if(!isset($nhex[$i+1])) {
97           $nstr .= chr(hexdec($nhex[$i])); }
98     }
99         if($name===null) { $name = salt_hmac(); }
100     // Calculate hash value
101         if($uuidver=="v3") {
102         $uuidverid = 0x3000;
103         if (function_exists('hash')) {
104         $hash = hash("md5", $nstr . $name); }
105         if (!function_exists('hash')) {
106         $hash = md5($nstr . $name); } }
107         if($uuidver=="v5") {
108         $uuidverid = 0x5000;
109         if (function_exists('hash')) {
110         $hash = hash("sha1", $nstr . $name); }
111         if (!function_exists('hash')) {
112         $hash = sha1($nstr . $name); } }
113     return sprintf('%08s-%04s-%04x-%04x-%12s',
114       substr($hash, 0, 8),
115       substr($hash, 8, 4),
116       (hexdec(substr($hash, 12, 4)) & 0x0fff) | $uuidverid,
117       (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
118       substr($hash, 20, 12) ); } }
119 function rand_uuid($rndty = "rand", $namespace = null, $name = null) {
120 $rand_array = array(1 => "v3", 2 => "v4", 3 => "v5");
121 if($name===null) { $name = salt_hmac(); }
122 $my_uuid = $rand_array[$rndty(1,3)];
123 if($my_uuid=="v4") { return uuid("v4",$rndty); }
124 if($my_uuid=="v3"||$my_uuid=="v5") {
125 return uuid($my_uuid,$rndty,$name); } }
126 // unserialize sessions variables
127 // By: jason@joeymail.net
128 // URL: http://us2.php.net/manual/en/function.session-decode.php#101687
129 function unserialize_session($data)
130 {
131     if(  strlen( $data) == 0)
132     {
133         return array();
134     }
135     // match all the session keys and offsets
136     preg_match_all('/(^|;|\})([a-zA-Z0-9_]+)\|/i', $data, $matchesarray, PREG_OFFSET_CAPTURE);
137     $returnArray = array();
138     $lastOffset = null;
139     $currentKey = '';
140     foreach ( $matchesarray[2] as $value )
141     {
142         $offset = $value[1];
143         if(!is_null( $lastOffset))
144         {
145             $valueText = substr($data, $lastOffset, $offset - $lastOffset );
146             $returnArray[$currentKey] = unserialize($valueText);
147         }
148         $currentKey = $value[0];
149         $lastOffset = $offset + strlen( $currentKey )+1;
150     }
151     $valueText = substr($data, $lastOffset );
152     $returnArray[$currentKey] = unserialize($valueText);
153     return $returnArray;
154 }
155 // Make the Query String if we are not useing &=
156 function qstring($qstr=";",$qsep="=")
157 { $_GET = array(); $_GET = null;
158 if (!isset($_SERVER['QUERY_STRING'])) {
159 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
160 ini_set("arg_separator.input", $qstr);
161 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
162 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
163 $qsnum = count($preqs); $qsi = 0;
164 while ($qsi < $qsnum) {
165 $preqst = explode($qsep,$preqs[$qsi],2);
166 $fix1 = array(" ",'$'); $fix2  = array("_","_");
167 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
168 $preqst[0] = killbadvars($preqst[0]);
169 if($preqst[0]!=null) {
170 $_GET[$preqst[0]] = $preqst[1]; }
171 ++$qsi; } return true; }
172 if($Settings['qstr']!="&"&&
173         $Settings['qstr']!="/") {
174 qstring($Settings['qstr'],$Settings['qsep']); 
175 if(!isset($_GET['page'])) { $_GET['page'] = null; }
176 if(!isset($_GET['act'])) { $_GET['act'] = null; }
177 if(!isset($_POST['act'])) { $_POST['act'] = null; }
178 if(!isset($_GET['id'])) { $_GET['id'] = null; } 
179 if(!isset($_GET['debug'])) { $_GET['debug'] = "false"; }
180 if(!isset($_GET['post'])) { $_GET['post'] = null; }
181 if(!isset($_POST['License'])) { $_POST['License'] = null; } }
182 if($_SERVER['PATH_INFO']==null) {
183         if(getenv('PATH_INFO')!=null&&getenv('PATH_INFO')!="1") {
184 $_SERVER['PATH_INFO'] = getenv('PATH_INFO'); }
185 if(getenv('PATH_INFO')==null) {
186 $myscript = $_SERVER["SCRIPT_NAME"];
187 $myphpath = $_SERVER["PHP_SELF"];
188 $mypathinfo = str_replace($myscript, "", $myphpath);
189 @putenv("PATH_INFO=".$mypathinfo); } }
190 // Change raw post data to POST array
191 // Not sure why I made but alwell. :P 
192 function parse_post_data()
193 { $_POST = array(); $_POST = null;
194 $postdata = file_get_contents("php://input");
195 if (!isset($postdata)) { $postdata = null; }
196 $postdata = urldecode($postdata);
197 $preqs = explode("&",$postdata);
198 $qsnum = count($preqs); $qsi = 0;
199 while ($qsi < $qsnum) {
200 $preqst = explode("=",$preqs[$qsi],2);
201 $fix1 = array(" ",'$'); $fix2  = array("_","_");
202 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
203 $preqst[0] = killbadvars($preqst[0]);
204 if($preqst[0]!=null) {
205 $_POST[$preqst[0]] = $preqst[1]; }
206 ++$qsi; } return true; }
207 // Change Path info to Get Vars :
208 function mrstring() {
209 $urlvar = explode('/',$_SERVER['PATH_INFO']);
210 $num=count($urlvar); $i=1;
211 while ($i < $num) {
212 //$urlvar[$i] = urldecode($urlvar[$i]);
213 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
214 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
215 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
216 $fix1 = array(" ",'$'); $fix2  = array("_","_");
217 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
218 $urlvar[$i] = killbadvars($urlvar[$i]);
219         $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
220 ++$i; ++$i; } return true; }
221 // Redirect to another file with ether timed or nontimed redirect
222 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
223 if($type!="location"&&$type!="refresh") { $type=="location"; }
224 if($url!=null) { $file = $url.$file; }
225 if($dbsr===true) { $file = str_replace("//", "/", $file); }
226 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
227 if($type=="location") { session_write_close(); 
228 header("Location: ".$file); } return true; }
229 function redirects($type,$url,$time=0) {
230 if($type!="location"&&$type!="refresh") { $type=="location"; }
231 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
232 if($type=="location") { idb_log_maker(302,"-"); }
233 if($type=="location") { header("Location: ".$url); } return true; }
234 // Make xhtml tags
235 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
236         $var_num = count($attbvar); $value_num = count($attbval);
237         if($var_num!=$value_num) { 
238                 output_error("Erorr Number of Var and Values dont match!",E_USER_ERROR);
239         return false; } $i = 0;
240         while ($i < $var_num) {
241         if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
242         if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
243         if($i==$var_num-1) { 
244         if($emptytag===false) { $mytag = $mytag.">"; }
245         if($emptytag===true) { $mytag = $mytag." />"; } }       ++$i; }
246         if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
247         if($emptytag===true) { $mytag = $mytag." />"; }
248         if($emptytag===false) { $mytag = $mytag.">"; } }
249         if($emptytag===false&&$extratest!=null) { 
250         $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; } 
251         return $mytag; }
252 // Start a xml document
253 function xml_tag_make($type,$attbs,$retval=false) {
254         $renee1 = explode("&",$attbs);
255         $reneenum=count($renee1);
256         $reneei=0; $attblist = null;
257         while ($reneei < $reneenum) {
258         $renee2 = explode("=",$renee1[$reneei]);
259         if($renee2[0]!=null||$renee2[1]!=null) {
260         $attblist = $attblist.' '.$renee2[0].'="'.$renee2[1].'"'; }
261         ++$reneei; }
262         if($retval!==false&&$retval!==true) { $retval=false; }
263         if($retval===false) {
264         echo '<?'.$type.$attblist.'?>'."\n"; }
265         if($retval===true) {
266         return '<?'.$type.$attblist.'?>'."\n"; } }
267 // Start a xml document (old version)
268 function xml_doc_start($ver,$encode,$retval=false) {
269         if($retval===false) {
270         echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
271         if($retval===true) {
272         return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
273 $icharset = $Settings['charset'];
274 $debug_on = false;
275 if(isset($_GET['debug'])) {
276 if($_GET['debug']=="true"||
277         $_GET['debug']=="on") {
278 $debug_on = true; } }
279 $BoardURL = $Settings['idburl'];
280 // Change URLs to Links
281 function pre_url2link($matches) {
282 global $BoardURL; $opennew = true;
283 $burlCHCK = parse_url($BoardURL);
284 $urlCHCK = parse_url($matches[0]);
285 if($urlCHCK['host']==$burlCHCK['host']) {
286         $opennew = false; }
287 $outurl = $urlCHCK['scheme']."://";
288 if(isset($urlCHCK['user'])) {
289 $outurl = $outurl.$urlCHCK['user'];
290 if(isset($urlCHCK['pass'])) {
291 $outurl = $outurl.":".$urlCHCK['pass']; }
292 $outurl = $outurl."@"; }
293 $outurl = $outurl.$urlCHCK['host'];
294 if(isset($urlCHCK['path'])) {
295 $outurl = $outurl.$urlCHCK['path']; }
296 if(!isset($urlCHCK['path'])) {
297 $outurl = $outurl."/"; }
298 if(isset($urlCHCK['query'])) {
299 $urlCHCK['query'] = str_replace(" ", "+", $urlCHCK['query']);
300 $outurl = $outurl."?".$urlCHCK['query']; }
301 if(isset($urlCHCK['fragment'])) {
302 $urlCHCK['fragment'] = str_replace(" ", "+", $urlCHCK['fragment']);
303 $outurl = $outurl."#".$urlCHCK['fragment']; }
304 if($opennew===true) {
305 $outlink = "<a onclick=\"window.open(this.href); return false;\" href=\"".$outurl."\">".$outurl."</a>"; }
306 if($opennew===false) {
307 $outlink = "<a href=\"".$outurl."\">".$outurl."</a>"; }
308 return $outlink; }
309 function url2link($string) {
310 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); }
311 function urlcheck($string) {
312 global $BoardURL;
313 $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); 
314 if(isset($urlcheck[0][0])) { $url = $urlcheck[0][0]; }
315 if(!isset($urlcheck[0][0])) { $url = $BoardURL; }
316 return $url; }
317 //Check to make sure theme exists
318 $BoardTheme = $Settings['DefaultTheme'];
319 $ThemeDir = $SettDir['themes'];
320 function chack_themes($theme) {
321 global $BoardTheme,$ThemeDir;
322 if(!isset($theme)) { $theme = null; }
323 if(preg_match("/([a-zA-Z]+)\:/isU",$theme)) {
324         $theme = $BoardTheme; }
325 if(!preg_match("/^[a-z0-9]+$/isU",$theme)) {
326         $theme = $BoardTheme; }
327 require('settings.php');
328 $ckskindir = dirname(realpath("settings.php"))."/".$ThemeDir;
329 if ($handle = opendir($ckskindir)) { $dirnum = null;
330    while (false !== ($ckfile = readdir($handle))) {
331            if ($dirnum==null) { $dirnum = 0; }
332            if (is_dir($ckskindir.$ckfile)&&file_exists($ckskindir.$ckfile."/info.php")) {
333                    if ($ckfile != "." && $ckfile != "..") {
334            //include($ckskindir.$ckfile."/info.php");
335        $cktheme[$dirnum] =  $ckfile;
336            ++$dirnum; } } }
337    closedir($handle); asort($cktheme); }
338 $theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
339 if(!in_array($theme,$cktheme)||strlen($theme)>26) {
340         $theme = $BoardTheme; } return $theme; }
341 // Make a url with query string
342 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
343 global $sidurls, $icharset, $debug_on;
344 $fileurl = null; if(!isset($ext)) { $ext = null; }
345 if($ext==null) { $ext = ".php"; } 
346 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
347 $file = $file.$ext;
348 if($sidurls=="on"&&$qstr!="/") { 
349         if(defined('SID')) {
350 if($qvarstr==null) { $qvarstr = SID; }
351 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
352 if($debug_on===true) {
353 if($qvarstr==null) { $qvarstr = "debug=on"; }
354 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
355 if($qvarstr==null) { $fileurl = $file; }
356 if($fixhtml===true) {
357 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
358 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
359 if($prexqstr!=null) { 
360 $rene1 = explode("&",$prexqstr);
361 $renenum=count($rene1);
362 $renei=0;
363 $reneqstr = "index.php?";
364 if($qstr!="/") { $fileurl = $file."?"; }
365 if($qstr=="/") { $fileurl = $file."/"; }
366 while ($renei < $renenum) {
367         $rene2 = explode("=",$rene1[$renei]);
368         if(!isset($rene2[0])) { $rene2[0] = null; }
369         $rene2[1] = urlencode($rene2[1]);
370         if(!isset($rene2[0])) { $rene2[0] = null; }
371         $rene2[1] = urlencode($rene2[1]);
372         if($qstr!="/") {
373         $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
374         if($qstr=="/") {
375         $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
376         $reneis = $renei + 1;
377         if($qstr!="/") {
378         if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
379         ++$renei; } }
380 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
381 if($qvarstr!=null) { 
382 if($prexqstr==null) {
383 if($qstr!="/") { $fileurl = $file."?"; }
384 if($qstr=="/") { $fileurl = $file."/"; } }
385 $cind1 = explode("&",$qvarstr);
386 $cindnum=count($cind1);
387 $cindi=0;
388 $cindqstr = "index.php?";
389 while ($cindi < $cindnum) {
390         $cind2 = explode("=",$cind1[$cindi]);
391         if(!isset($cind2[0])) { $cind2[0] = null; }
392         $cind2[0] = urlencode($cind2[0]);
393         if(!isset($cind2[1])) { $cind2[1] = null; }
394         $cind2[1] = urlencode($cind2[1]);
395         if($qstr!="/") {
396         $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
397         if($qstr=="/") {
398         $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
399         $cindis = $cindi + 1;
400         if($qstr!="/") {
401         if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
402         ++$cindi; } }
403 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
404 if($exqstr!=null) { 
405 if($qvarstr==null&&$prexqstr==null) {
406 if($qstr!="/") { $fileurl = $file."?"; }
407 if($qstr=="/") { $fileurl = $file."/"; } }
408 $sand1 = explode("&",$exqstr);
409 $sanum=count($sand1);
410 $sandi=0;
411 $sandqstr = "index.php?";
412 while ($sandi < $sanum) {
413         $sand2 = explode("=",$sand1[$sandi]);
414         if(!isset($sand2[0])) { $sand2[0] = null; }
415         $sand2[0] = urlencode($sand2[0]);
416         if(!isset($sand2[1])) { $sand2[1] = null; }
417         $sand2[1] = urlencode($sand2[1]);
418         if($qstr!="/") {
419         $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
420         if($qstr=="/") {
421         $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
422         $sandis = $sandi + 1;
423         if($qstr!="/") {
424         if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
425         ++$sandi; } }
426 return $fileurl; }
427 $thisdir = dirname(realpath("Preindex.php"))."/";
428 // Get the Query String
429 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
430 { $pregqstr = preg_quote($qstr,"/");
431 $pregqsep = preg_quote($qsep,"/");
432 $oqstr = $qstr; $oqsep = $qsep;
433 if($fixhtml===true||$fixhtml==null) {
434 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
435 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
436 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
437 $BoardQuery = "?".$OldBoardQuery;
438 return $BoardQuery; }
439 function get_server_values($matches) {
440         $return_text = "-";
441         if(isset($_SERVER[$matches[1]])) { $return_text = $_SERVER[$matches[1]]; }
442         if(!isset($_SERVER[$matches[1]])) { $return_text = "-"; }
443         return $return_text; }
444 function get_cookie_values($matches) {
445         $return_text = null;
446         if(isset($_COOKIE[$matches[1]])) { $return_text = $_COOKIE[$matches[1]]; }
447         if(!isset($_COOKIE[$matches[1]])) { $return_text = null; }
448         return $return_text; }
449 function get_env_values($matches) {
450         $return_text = getenv($matches[1]);
451         if(!isset($return_text)) { $return_text = "-"; }
452         return $return_text; }
453 function get_setting_values($matches) {
454         global $Settings;
455         $return_text = null;
456         $matches[1] = str_replace("sqlpass", "sqluser", $matches[1]);
457         if(isset($Settings[$matches[1]])) { $return_text = $Settings[$matches[1]]; }
458         if(!isset($Settings[$matches[1]])) { $return_text = null; }
459         return $return_text; }
460 function get_time($matches) {
461         return date(convert_strftime($matches[1])); }
462 function convert_strftime($strftime) {
463 $strftime = str_replace("%%", "{percent\}p", $strftime);
464 $strftime = str_replace("%a", "D", $strftime);
465 $strftime = str_replace("%A", "l", $strftime);
466 $strftime = str_replace("%d", "d", $strftime);
467 $strftime = str_replace("%e", "j", $strftime);
468 $strftime = str_replace("%j", "z", $strftime);
469 $strftime = str_replace("%u", "w", $strftime);
470 $strftime = str_replace("%w", "w", $strftime);
471 $strftime = str_replace("%U", "W", $strftime);
472 $strftime = str_replace("%V", "W", $strftime);
473 $strftime = str_replace("%W", "W", $strftime);
474 $strftime = str_replace("%b", "M", $strftime);
475 $strftime = str_replace("%B", "F", $strftime);
476 $strftime = str_replace("%h", "M", $strftime);
477 $strftime = str_replace("%m", "m", $strftime);
478 $strftime = str_replace("%g", "y", $strftime);
479 $strftime = str_replace("%G", "Y", $strftime);
480 $strftime = str_replace("%y", "y", $strftime);
481 $strftime = str_replace("%Y", "Y", $strftime);
482 $strftime = str_replace("%H", "H", $strftime);
483 $strftime = str_replace("%I", "h", $strftime);
484 $strftime = str_replace("%l", "g", $strftime);
485 $strftime = str_replace("%M", "i", $strftime);
486 $strftime = str_replace("%p", "A", $strftime);
487 $strftime = str_replace("%P", "a", $strftime);
488 $strftime = str_replace("%r", "h:i:s A", $strftime);
489 $strftime = str_replace("%R", "H:i", $strftime);
490 $strftime = str_replace("%S", "s", $strftime);
491 $strftime = str_replace("%T", "H:i:s", $strftime);
492 $strftime = str_replace("%X", "H:i:s", $strftime);
493 $strftime = str_replace("%z", "O", $strftime);
494 $strftime = str_replace("%Z", "O", $strftime);
495 $strftime = str_replace("%c", "D M j H:i:s Y", $strftime);
496 $strftime = str_replace("%D", "m/d/y", $strftime);
497 $strftime = str_replace("%F", "Y-m-d", $strftime);
498 $strftime = str_replace("%x", "m/d/y", $strftime);
499 $strftime = str_replace("%n", "\n", $strftime);
500 $strftime = str_replace("%t", "\t", $strftime);
501 $logtxt = preg_replace("/\{percent\}p/s", "%", $logtxt);
502 return $strftime; }
503 function apache_log_maker($logtxt,$logfile=null,$status=200,$contentsize="-",$headersize=0) {
504 global $Settings;
505 if(!isset($_SERVER['HTTP_REFERER'])) { $URL_REFERER = "-"; }
506 if(isset($_SERVER['HTTP_REFERER'])) { $URL_REFERER = $_SERVER['HTTP_REFERER']; }
507 if(!isset($_SERVER['PHP_AUTH_USER'])) { $AUTH_USER = "-"; }
508 if(isset($_SERVER['PHP_AUTH_USER'])) { $AUTH_USER = $_SERVER['PHP_AUTH_USER']; }
509 $LOG_QUERY_STRING = "";
510 if($_SERVER["QUERY_STRING"]!=="") {
511 $LOG_QUERY_STRING = "?".$_SERVER["QUERY_STRING"]; }
512 $oldcontentsize = $contentsize;
513 if($oldcontentsize=="-") { $oldcontentsize = 0; }
514 if($contentsize===0) { $contentsize = "-"; }
515 if($contentsize=="-"&&$headersize!==0) { $fullsitesize = $headersize; }
516 if($contentsize!="-"&&$headersize!==0) { $fullsitesize = $contentsize + $headersize; }
517 if($status=="302") { $contentsize = "-"; }
518 $HTTP_REQUEST_LINE = $_SERVER["REQUEST_METHOD"]." ".$_SERVER["REQUEST_URI"]." ".$_SERVER["SERVER_PROTOCOL"];
519 $logtxt = preg_replace("/%%/s", "{percent}p", $logtxt);
520 $logtxt = preg_replace("/%([\<\>]*?)a/s", $_SERVER['REMOTE_ADDR'], $logtxt);
521 $logtxt = preg_replace("/%([\<\>]*?)A/s", $_SERVER["SERVER_ADDR"], $logtxt);
522 $logtxt = preg_replace("/%([\<\>]*?)B/s", $oldcontentsize, $logtxt);
523 $logtxt = preg_replace("/%([\<\>]*?)b/s", $contentsize, $logtxt);
524 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}C/s", "get_cookie_values", $logtxt);
525 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}e/s", "get_env_values", $logtxt);
526 $logtxt = preg_replace("/%([\<\>]*?)f/s", $_SERVER["SCRIPT_FILENAME"], $logtxt);
527 $logtxt = preg_replace("/%([\<\>]*?)h/s", $_SERVER['REMOTE_ADDR'], $logtxt);
528 $logtxt = preg_replace("/%([\<\>]*?)H/s", $_SERVER["SERVER_PROTOCOL"], $logtxt);
529 $logtxt = preg_replace("/%([\<\>]*?)\{Referer\}i/s", $URL_REFERER, $logtxt);
530 $logtxt = preg_replace("/%([\<\>]*?)\{User-Agent\}i/s", $_SERVER["HTTP_USER_AGENT"], $logtxt);
531 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}i/s", "get_server_values", $logtxt);
532 $logtxt = preg_replace("/%([\<\>]*?)l/s", "-", $logtxt);
533 $logtxt = preg_replace("/%([\<\>]*?)m/s", $_SERVER["REQUEST_METHOD"], $logtxt);
534 $logtxt = preg_replace("/%([\<\>]*?)p/s", $_SERVER["SERVER_PORT"], $logtxt);
535 $logtxt = preg_replace("/%([\<\>]*?)q/s", $LOG_QUERY_STRING, $logtxt);
536 $logtxt = preg_replace("/%([\<\>]*?)r/s", $HTTP_REQUEST_LINE, $logtxt);
537 $logtxt = preg_replace("/%([\<\>]*?)s/s", $status, $logtxt);
538 $logtxt = preg_replace("/%([\<\>]*?)t/s", "[".date("d/M/Y:H:i:s O")."]", $logtxt);
539 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}t/s", "get_time", $logtxt);
540 $logtxt = preg_replace("/%([\<\>]*?)u/s", $AUTH_USER, $logtxt);
541 $logtxt = preg_replace("/%([\<\>]*?)U/s", $_SERVER["PHP_SELF"], $logtxt);
542 $logtxt = preg_replace("/%([\<\>]*?)v/s", $_SERVER["SERVER_NAME"], $logtxt);
543 $logtxt = preg_replace("/%([\<\>]*?)V/s", $_SERVER["SERVER_NAME"], $logtxt);
544 // Not what it should be but PHP dose not have variable to get Apache ServerName config value. :( 
545 $logtxt = preg_replace("/%([\<\>]*?)O/s", $fullsitesize, $logtxt);
546 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}s/s", "get_setting_values", $logtxt);
547 $logtxt = preg_replace("/\{percent\}p/s", "%", $logtxt);
548 if(isset($logfile)&&$logfile!==null) {
549         $fp = fopen($logfile, "a+");
550         $logtxtnew = $logtxt."\r\n";
551         fwrite($fp, $logtxtnew, strlen($logtxtnew));
552         fclose($fp); }
553 return $logtxt; }
554 function idb_log_maker($status=200,$contentsize="-") {
555 global $Settings,$SettDir;
556 if(!isset($Settings['log_http_request'])) {
557         $Settings['log_http_request'] = "off"; }
558 if(!isset($Settings['log_config_format'])) {
559         $Settings['log_config_format'] = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""; }
560 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']=="on"&&
561         $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
562 return apache_log_maker($Settings['log_config_format'], $SettDir['logs'].$Settings['sqltable'].date("YW").".log", $status, $contentsize, strlen(implode("\r\n",headers_list())."\r\n\r\n")); }
563 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']!="on"&&
564         $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
565 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}t", "/")."/s", "get_time", $Settings['log_http_request']);
566 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}s", "/")."/s", "get_setting_values", $Settings['log_http_request']);
567 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")); } }
568 ?>