Small update/bug fix. :o
[iDB.git] / inc / function.php
blobcfaff66d069b5ff874a2337c9fb89d7586ceac4d
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-2011 iDB Support - http://idb.berlios.de/
12 Copyright 2004-2011 Game Maker 2k - http://gamemaker2k.org/
14 $FileInfo: function.php - Last Update: 06/29/2011 SVN 688 - 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 /* 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
76 * @author Andrew Moore
77 * @url http://us.php.net/manual/en/function.uniqid.php#94959
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])); }
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 function unserialize_session($data) {
128 $vars=preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff^|]*)\|/',
129 $data,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
130 $i = 0;
131 for($i=0; isset($vars[$i]); $i++) {
132 $l = $i + 1;
133 if(!isset($vars[$i])) { $vars[$i] = null; }
134 if(!isset($vars[$l])) { $vars[$l] = null; }
135 $result[$vars[$i]]=unserialize($vars[$l]);
136 $i++; }
137 if(!isset($result)) { $result = null; }
138 return $result;
140 // Make the Query String if we are not useing &=
141 function qstring($qstr=";",$qsep="=")
142 { $_GET = array(); $_GET = null;
143 if (!isset($_SERVER['QUERY_STRING'])) {
144 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
145 ini_set("arg_separator.input", $qstr);
146 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
147 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
148 $qsnum = count($preqs); $qsi = 0;
149 while ($qsi < $qsnum) {
150 $preqst = explode($qsep,$preqs[$qsi],2);
151 $fix1 = array(" ",'$'); $fix2 = array("_","_");
152 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
153 $preqst[0] = killbadvars($preqst[0]);
154 if($preqst[0]!=null) {
155 $_GET[$preqst[0]] = $preqst[1]; }
156 ++$qsi; } return true; }
157 if($Settings['qstr']!="&"&&
158 $Settings['qstr']!="/") {
159 qstring($Settings['qstr'],$Settings['qsep']);
160 if(!isset($_GET['page'])) { $_GET['page'] = null; }
161 if(!isset($_GET['act'])) { $_GET['act'] = null; }
162 if(!isset($_POST['act'])) { $_POST['act'] = null; }
163 if(!isset($_GET['id'])) { $_GET['id'] = null; }
164 if(!isset($_GET['debug'])) { $_GET['debug'] = "false"; }
165 if(!isset($_GET['post'])) { $_GET['post'] = null; }
166 if(!isset($_POST['License'])) { $_POST['License'] = null; } }
167 if($_SERVER['PATH_INFO']==null) {
168 if(getenv('PATH_INFO')!=null&&getenv('PATH_INFO')!="1") {
169 $_SERVER['PATH_INFO'] = getenv('PATH_INFO'); }
170 if(getenv('PATH_INFO')==null) {
171 $myscript = $_SERVER["SCRIPT_NAME"];
172 $myphpath = $_SERVER["PHP_SELF"];
173 $mypathinfo = str_replace($myscript, "", $myphpath);
174 @putenv("PATH_INFO=".$mypathinfo); } }
175 // Change raw post data to POST array
176 // Not sure why I made but alwell. :P
177 function parse_post_data()
178 { $_POST = array(); $_POST = null;
179 $postdata = file_get_contents("php://input");
180 if (!isset($postdata)) { $postdata = null; }
181 $postdata = urldecode($postdata);
182 $preqs = explode("&",$postdata);
183 $qsnum = count($preqs); $qsi = 0;
184 while ($qsi < $qsnum) {
185 $preqst = explode("=",$preqs[$qsi],2);
186 $fix1 = array(" ",'$'); $fix2 = array("_","_");
187 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
188 $preqst[0] = killbadvars($preqst[0]);
189 if($preqst[0]!=null) {
190 $_POST[$preqst[0]] = $preqst[1]; }
191 ++$qsi; } return true; }
192 // Change Path info to Get Vars :
193 function mrstring() {
194 $urlvar = explode('/',$_SERVER['PATH_INFO']);
195 $num=count($urlvar); $i=1;
196 while ($i < $num) {
197 //$urlvar[$i] = urldecode($urlvar[$i]);
198 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
199 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
200 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
201 $fix1 = array(" ",'$'); $fix2 = array("_","_");
202 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
203 $urlvar[$i] = killbadvars($urlvar[$i]);
204 $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
205 ++$i; ++$i; } return true; }
206 // Redirect to another file with ether timed or nontimed redirect
207 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
208 if($type!="location"&&$type!="refresh") { $type=="location"; }
209 if($url!=null) { $file = $url.$file; }
210 if($dbsr===true) { $file = str_replace("//", "/", $file); }
211 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
212 if($type=="location") { session_write_close();
213 header("Location: ".$file); } return true; }
214 function redirects($type,$url,$time=0) {
215 if($type!="location"&&$type!="refresh") { $type=="location"; }
216 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
217 if($type=="location") { idb_log_maker(302,"-"); }
218 if($type=="location") { header("Location: ".$url); } return true; }
219 // Make xhtml tags
220 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
221 $var_num = count($attbvar); $value_num = count($attbval);
222 if($var_num!=$value_num) {
223 output_error("Erorr Number of Var and Values dont match!",E_USER_ERROR);
224 return false; } $i = 0;
225 while ($i < $var_num) {
226 if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
227 if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
228 if($i==$var_num-1) {
229 if($emptytag===false) { $mytag = $mytag.">"; }
230 if($emptytag===true) { $mytag = $mytag." />"; } } ++$i; }
231 if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
232 if($emptytag===true) { $mytag = $mytag." />"; }
233 if($emptytag===false) { $mytag = $mytag.">"; } }
234 if($emptytag===false&&$extratest!=null) {
235 $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; }
236 return $mytag; }
237 // Start a xml document
238 function xml_tag_make($type,$attbs,$retval=false) {
239 $renee1 = explode("&",$attbs);
240 $reneenum=count($renee1);
241 $reneei=0; $attblist = null;
242 while ($reneei < $reneenum) {
243 $renee2 = explode("=",$renee1[$reneei]);
244 if($renee2[0]!=null||$renee2[1]!=null) {
245 $attblist = $attblist.' '.$renee2[0].'="'.$renee2[1].'"'; }
246 ++$reneei; }
247 if($retval!==false&&$retval!==true) { $retval=false; }
248 if($retval===false) {
249 echo '<?'.$type.$attblist.'?>'."\n"; }
250 if($retval===true) {
251 return '<?'.$type.$attblist.'?>'."\n"; } }
252 // Start a xml document (old version)
253 function xml_doc_start($ver,$encode,$retval=false) {
254 if($retval===false) {
255 echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
256 if($retval===true) {
257 return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
258 $icharset = $Settings['charset'];
259 $debug_on = false;
260 if(isset($_GET['debug'])) {
261 if($_GET['debug']=="true"||
262 $_GET['debug']=="on") {
263 $debug_on = true; } }
264 $BoardURL = $Settings['idburl'];
265 // Change URLs to Links
266 function pre_url2link($matches) {
267 global $BoardURL; $opennew = true;
268 $burlCHCK = parse_url($BoardURL);
269 $urlCHCK = parse_url($matches[0]);
270 if($urlCHCK['host']==$burlCHCK['host']) {
271 $opennew = false; }
272 $outurl = $urlCHCK['scheme']."://";
273 if(isset($urlCHCK['user'])) {
274 $outurl = $outurl.$urlCHCK['user'];
275 if(isset($urlCHCK['pass'])) {
276 $outurl = $outurl.":".$urlCHCK['pass']; }
277 $outurl = $outurl."@"; }
278 $outurl = $outurl.$urlCHCK['host'];
279 if(isset($urlCHCK['path'])) {
280 $outurl = $outurl.$urlCHCK['path']; }
281 if(!isset($urlCHCK['path'])) {
282 $outurl = $outurl."/"; }
283 if(isset($urlCHCK['query'])) {
284 $urlCHCK['query'] = str_replace(" ", "+", $urlCHCK['query']);
285 $outurl = $outurl."?".$urlCHCK['query']; }
286 if(isset($urlCHCK['fragment'])) {
287 $urlCHCK['fragment'] = str_replace(" ", "+", $urlCHCK['fragment']);
288 $outurl = $outurl."#".$urlCHCK['fragment']; }
289 if($opennew===true) {
290 $outlink = "<a onclick=\"window.open(this.href); return false;\" href=\"".$outurl."\">".$outurl."</a>"; }
291 if($opennew===false) {
292 $outlink = "<a href=\"".$outurl."\">".$outurl."</a>"; }
293 return $outlink; }
294 function url2link($string) {
295 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); }
296 function urlcheck($string) {
297 global $BoardURL;
298 $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);
299 if(isset($urlcheck[0][0])) { $url = $urlcheck[0][0]; }
300 if(!isset($urlcheck[0][0])) { $url = $BoardURL; }
301 return $url; }
302 //Check to make sure theme exists
303 $BoardTheme = $Settings['DefaultTheme'];
304 $ThemeDir = $SettDir['themes'];
305 function chack_themes($theme) {
306 global $BoardTheme,$ThemeDir;
307 if(!isset($theme)) { $theme = null; }
308 if(preg_match("/([a-zA-Z]+)\:/isU",$theme)) {
309 $theme = $BoardTheme; }
310 if(!preg_match("/^[a-z0-9]+$/isU",$theme)) {
311 $theme = $BoardTheme; }
312 require('settings.php');
313 $ckskindir = dirname(realpath("settings.php"))."/".$ThemeDir;
314 if ($handle = opendir($ckskindir)) { $dirnum = null;
315 while (false !== ($ckfile = readdir($handle))) {
316 if ($dirnum==null) { $dirnum = 0; }
317 if (file_exists($ckskindir.$ckfile."/info.php")) {
318 if ($ckfile != "." && $ckfile != "..") {
319 //include($ckskindir.$ckfile."/info.php");
320 $cktheme[$dirnum] = $ckfile;
321 ++$dirnum; } } }
322 closedir($handle); asort($cktheme); }
323 $theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
324 if(!in_array($theme,$cktheme)||strlen($theme)>26) {
325 $theme = $BoardTheme; } return $theme; }
326 // Make a url with query string
327 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
328 global $sidurls, $icharset, $debug_on;
329 $fileurl = null; if(!isset($ext)) { $ext = null; }
330 if($ext==null) { $ext = ".php"; }
331 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
332 $file = $file.$ext;
333 if($sidurls=="on"&&$qstr!="/") {
334 if(defined('SID')) {
335 if($qvarstr==null) { $qvarstr = SID; }
336 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
337 if($debug_on===true) {
338 if($qvarstr==null) { $qvarstr = "debug=on"; }
339 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
340 if($qvarstr==null) { $fileurl = $file; }
341 if($fixhtml===true) {
342 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
343 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
344 if($prexqstr!=null) {
345 $rene1 = explode("&",$prexqstr);
346 $renenum=count($rene1);
347 $renei=0;
348 $reneqstr = "index.php?";
349 if($qstr!="/") { $fileurl = $file."?"; }
350 if($qstr=="/") { $fileurl = $file."/"; }
351 while ($renei < $renenum) {
352 $rene2 = explode("=",$rene1[$renei]);
353 if(!isset($rene2[0])) { $rene2[0] = null; }
354 $rene2[1] = urlencode($rene2[1]);
355 if(!isset($rene2[0])) { $rene2[0] = null; }
356 $rene2[1] = urlencode($rene2[1]);
357 if($qstr!="/") {
358 $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
359 if($qstr=="/") {
360 $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
361 $reneis = $renei + 1;
362 if($qstr!="/") {
363 if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
364 ++$renei; } }
365 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
366 if($qvarstr!=null) {
367 if($prexqstr==null) {
368 if($qstr!="/") { $fileurl = $file."?"; }
369 if($qstr=="/") { $fileurl = $file."/"; } }
370 $cind1 = explode("&",$qvarstr);
371 $cindnum=count($cind1);
372 $cindi=0;
373 $cindqstr = "index.php?";
374 while ($cindi < $cindnum) {
375 $cind2 = explode("=",$cind1[$cindi]);
376 if(!isset($cind2[0])) { $cind2[0] = null; }
377 $cind2[0] = urlencode($cind2[0]);
378 if(!isset($cind2[1])) { $cind2[1] = null; }
379 $cind2[1] = urlencode($cind2[1]);
380 if($qstr!="/") {
381 $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
382 if($qstr=="/") {
383 $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
384 $cindis = $cindi + 1;
385 if($qstr!="/") {
386 if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
387 ++$cindi; } }
388 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
389 if($exqstr!=null) {
390 if($qvarstr==null&&$prexqstr==null) {
391 if($qstr!="/") { $fileurl = $file."?"; }
392 if($qstr=="/") { $fileurl = $file."/"; } }
393 $sand1 = explode("&",$exqstr);
394 $sanum=count($sand1);
395 $sandi=0;
396 $sandqstr = "index.php?";
397 while ($sandi < $sanum) {
398 $sand2 = explode("=",$sand1[$sandi]);
399 if(!isset($sand2[0])) { $sand2[0] = null; }
400 $sand2[0] = urlencode($sand2[0]);
401 if(!isset($sand2[1])) { $sand2[1] = null; }
402 $sand2[1] = urlencode($sand2[1]);
403 if($qstr!="/") {
404 $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
405 if($qstr=="/") {
406 $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
407 $sandis = $sandi + 1;
408 if($qstr!="/") {
409 if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
410 ++$sandi; } }
411 return $fileurl; }
412 $thisdir = dirname(realpath("Preindex.php"))."/";
413 // Get the Query String
414 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
415 { $pregqstr = preg_quote($qstr,"/");
416 $pregqsep = preg_quote($qsep,"/");
417 $oqstr = $qstr; $oqsep = $qsep;
418 if($fixhtml===true||$fixhtml==null) {
419 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
420 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
421 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
422 $BoardQuery = "?".$OldBoardQuery;
423 return $BoardQuery; }
424 function get_server_values($matches) {
425 $return_text = "-";
426 if(isset($_SERVER[$matches[1]])) { $return_text = $_SERVER[$matches[1]]; }
427 if(!isset($_SERVER[$matches[1]])) { $return_text = "-"; }
428 return $return_text; }
429 function get_cookie_values($matches) {
430 $return_text = null;
431 if(isset($_COOKIE[$matches[1]])) { $return_text = $_COOKIE[$matches[1]]; }
432 if(!isset($_COOKIE[$matches[1]])) { $return_text = null; }
433 return $return_text; }
434 function get_env_values($matches) {
435 $return_text = getenv($matches[1]);
436 if(!isset($return_text)) { $return_text = "-"; }
437 return $return_text; }
438 function get_setting_values($matches) {
439 global $Settings;
440 $return_text = null;
441 $matches[1] = str_replace("sqlpass", "sqluser", $matches[1]);
442 if(isset($Settings[$matches[1]])) { $return_text = $Settings[$matches[1]]; }
443 if(!isset($Settings[$matches[1]])) { $return_text = null; }
444 return $return_text; }
445 function get_time($matches) {
446 return date(convert_strftime($matches[1])); }
447 function convert_strftime($strftime) {
448 $strftime = str_replace("%%", "{percent\}p", $strftime);
449 $strftime = str_replace("%a", "D", $strftime);
450 $strftime = str_replace("%A", "l", $strftime);
451 $strftime = str_replace("%d", "d", $strftime);
452 $strftime = str_replace("%e", "j", $strftime);
453 $strftime = str_replace("%j", "z", $strftime);
454 $strftime = str_replace("%u", "w", $strftime);
455 $strftime = str_replace("%w", "w", $strftime);
456 $strftime = str_replace("%U", "W", $strftime);
457 $strftime = str_replace("%V", "W", $strftime);
458 $strftime = str_replace("%W", "W", $strftime);
459 $strftime = str_replace("%b", "M", $strftime);
460 $strftime = str_replace("%B", "F", $strftime);
461 $strftime = str_replace("%h", "M", $strftime);
462 $strftime = str_replace("%m", "m", $strftime);
463 $strftime = str_replace("%g", "y", $strftime);
464 $strftime = str_replace("%G", "Y", $strftime);
465 $strftime = str_replace("%y", "y", $strftime);
466 $strftime = str_replace("%Y", "Y", $strftime);
467 $strftime = str_replace("%H", "H", $strftime);
468 $strftime = str_replace("%I", "h", $strftime);
469 $strftime = str_replace("%l", "g", $strftime);
470 $strftime = str_replace("%M", "i", $strftime);
471 $strftime = str_replace("%p", "A", $strftime);
472 $strftime = str_replace("%P", "a", $strftime);
473 $strftime = str_replace("%r", "h:i:s A", $strftime);
474 $strftime = str_replace("%R", "H:i", $strftime);
475 $strftime = str_replace("%S", "s", $strftime);
476 $strftime = str_replace("%T", "H:i:s", $strftime);
477 $strftime = str_replace("%X", "H:i:s", $strftime);
478 $strftime = str_replace("%z", "O", $strftime);
479 $strftime = str_replace("%Z", "O", $strftime);
480 $strftime = str_replace("%c", "D M j H:i:s Y", $strftime);
481 $strftime = str_replace("%D", "m/d/y", $strftime);
482 $strftime = str_replace("%F", "Y-m-d", $strftime);
483 $strftime = str_replace("%x", "m/d/y", $strftime);
484 $strftime = str_replace("%n", "\n", $strftime);
485 $strftime = str_replace("%t", "\t", $strftime);
486 $logtxt = preg_replace("/\{percent\}p/s", "%", $logtxt);
487 return $strftime; }
488 function apache_log_maker($logtxt,$logfile=null,$status=200,$contentsize="-",$headersize=0) {
489 global $Settings;
490 if(!isset($_SERVER['HTTP_REFERER'])) { $URL_REFERER = "-"; }
491 if(isset($_SERVER['HTTP_REFERER'])) { $URL_REFERER = $_SERVER['HTTP_REFERER']; }
492 if(!isset($_SERVER['PHP_AUTH_USER'])) { $AUTH_USER = "-"; }
493 if(isset($_SERVER['PHP_AUTH_USER'])) { $AUTH_USER = $_SERVER['PHP_AUTH_USER']; }
494 $LOG_QUERY_STRING = "";
495 if($_SERVER["QUERY_STRING"]!=="") {
496 $LOG_QUERY_STRING = "?".$_SERVER["QUERY_STRING"]; }
497 $oldcontentsize = $contentsize;
498 if($oldcontentsize=="-") { $oldcontentsize = 0; }
499 if($contentsize===0) { $contentsize = "-"; }
500 if($contentsize=="-"&&$headersize!==0) { $fullsitesize = $headersize; }
501 if($contentsize!="-"&&$headersize!==0) { $fullsitesize = $contentsize + $headersize; }
502 $HTTP_REQUEST_LINE = $_SERVER["REQUEST_METHOD"]." ".$_SERVER["REQUEST_URI"]." ".$_SERVER["SERVER_PROTOCOL"];
503 $logtxt = preg_replace("/%%/s", "{percent}p", $logtxt);
504 $logtxt = preg_replace("/%([\<\>]*?)a/s", $_SERVER['REMOTE_ADDR'], $logtxt);
505 $logtxt = preg_replace("/%([\<\>]*?)A/s", $_SERVER["SERVER_ADDR"], $logtxt);
506 $logtxt = preg_replace("/%([\<\>]*?)B/s", $oldcontentsize, $logtxt);
507 $logtxt = preg_replace("/%([\<\>]*?)b/s", $contentsize, $logtxt);
508 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}C/s", "get_env_values", $logtxt);
509 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}e/s", "get_env_values", $logtxt);
510 $logtxt = preg_replace("/%([\<\>]*?)f/s", $_SERVER["SCRIPT_FILENAME"], $logtxt);
511 $logtxt = preg_replace("/%([\<\>]*?)h/s", $_SERVER['REMOTE_ADDR'], $logtxt);
512 $logtxt = preg_replace("/%([\<\>]*?)H/s", $_SERVER["SERVER_PROTOCOL"], $logtxt);
513 $logtxt = preg_replace("/%([\<\>]*?)\{Referer\}i/s", $URL_REFERER, $logtxt);
514 $logtxt = preg_replace("/%([\<\>]*?)\{User-Agent\}i/s", $_SERVER["HTTP_USER_AGENT"], $logtxt);
515 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}i/s", "get_server_values", $logtxt);
516 $logtxt = preg_replace("/%([\<\>]*?)l/s", "-", $logtxt);
517 $logtxt = preg_replace("/%([\<\>]*?)m/s", $_SERVER["REQUEST_METHOD"], $logtxt);
518 $logtxt = preg_replace("/%([\<\>]*?)p/s", $_SERVER["SERVER_PORT"], $logtxt);
519 $logtxt = preg_replace("/%([\<\>]*?)q/s", $LOG_QUERY_STRING, $logtxt);
520 $logtxt = preg_replace("/%([\<\>]*?)r/s", $HTTP_REQUEST_LINE, $logtxt);
521 $logtxt = preg_replace("/%([\<\>]*?)s/s", $status, $logtxt);
522 $logtxt = preg_replace("/%([\<\>]*?)t/s", "[".date("d/M/Y:H:i:s O")."]", $logtxt);
523 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}t/s", "get_time", $logtxt);
524 $logtxt = preg_replace("/%([\<\>]*?)u/s", $AUTH_USER, $logtxt);
525 $logtxt = preg_replace("/%([\<\>]*?)U/s", $_SERVER["PHP_SELF"], $logtxt);
526 $logtxt = preg_replace("/%([\<\>]*?)v/s", $_SERVER["SERVER_NAME"], $logtxt);
527 $logtxt = preg_replace("/%([\<\>]*?)V/s", $_SERVER["SERVER_NAME"], $logtxt);
528 // Not what it should be but PHP dose not have variable to get Apache ServerName config value. :(
529 $logtxt = preg_replace("/%([\<\>]*?)O/s", $fullsitesize, $logtxt);
530 $logtxt = preg_replace_callback("/%([\<\>]*?)\{([^\}]*)\}s/s", "get_setting_values", $logtxt);
531 $logtxt = preg_replace("/\{percent\}p/s", "%", $logtxt);
532 if(isset($logfile)&&$logfile!==null) {
533 $fp = fopen($logfile, "a+");
534 $logtxtnew = $logtxt."\r\n";
535 fwrite($fp, $logtxtnew, strlen($logtxtnew));
536 fclose($fp); }
537 return $logtxt; }
538 function idb_log_maker($status=200,$contentsize="-") {
539 global $Settings,$SettDir;
540 if(!isset($Settings['log_http_request'])) {
541 $Settings['log_http_request'] = "off"; }
542 if(!isset($Settings['log_config_format'])) {
543 $Settings['log_config_format'] = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""; }
544 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']=="on"&&
545 $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
546 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")); }
547 if(isset($Settings['log_http_request'])&&$Settings['log_http_request']!="on"&&
548 $Settings['log_http_request']!==null&&$Settings['log_http_request']!="off") {
549 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}t", "/")."/s", "get_time", $Settings['log_http_request']);
550 $Settings['log_http_request'] = preg_replace_callback("/".preg_quote("%{", "/")."([^\}]*)".preg_quote("}s", "/")."/s", "get_setting_values", $Settings['log_http_request']);
551 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")); } }