OSDN Git Service

Small bug fix.
[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-2010 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2010 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: function.php - Last Update: 06/13/2010 SVN 526 - 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 /* Change Some PHP Settings Fix the & to &amp;
22 if($Settings['use_iniset']==true&&$Settings['qstr']!="/") {
23 ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
24 ini_set("arg_separator.input",$Settings['qstr']);
25 ini_set("arg_separator",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset'])); }
26 //$basepath = pathinfo($_SERVER['REQUEST_URI']);
27 if(dirname($_SERVER['REQUEST_URI'])!="."||
28         dirname($_SERVER['REQUEST_URI'])!=null) {
29 $basedir = dirname($_SERVER['REQUEST_URI'])."/"; }*/
30 // Get the base dir name
31 /*if(dirname($_SERVER['SCRIPT_NAME'])!="."||
32         dirname($_SERVER['SCRIPT_NAME'])!=null) {
33 $basedir = dirname($_SERVER['SCRIPT_NAME'])."/"; }
34 if($basedir==null||$basedir==".") {
35 if(dirname($_SERVER['SCRIPT_NAME'])=="."||
36         dirname($_SERVER['SCRIPT_NAME'])==null) {
37 $basedir = dirname($_SERVER['PHP_SELF'])."/"; } }
38 if($basedir=="\/") { $basedir="/"; }
39 $basedir = str_replace("//", "/", $basedir);*/
40 if($Settings['qstr']!="/") {
41 $iDBURLCHK = $Settings['idburl']; }
42 if($Settings['qstr']=="/") {
43 $iDBURLCHK = preg_replace("/\/$/","",$Settings['idburl']); }
44 $basecheck = parse_url($iDBURLCHK);
45 $basedir = $basecheck['path'];
46 $cbasedir = $basedir;
47 $rbasedir = $basedir;
48 if($Settings['fixbasedir']!=null&&$Settings['fixbasedir']!="off") {
49                 $basedir = $Settings['fixbasedir']; }
50 if($Settings['fixcookiedir']!=null&&$Settings['fixcookiedir']!="") {
51                 $cbasedir = $Settings['fixcookiedir']; }
52 if($Settings['fixredirectdir']!=null) {
53                 $rbasedir = $Settings['fixredirectdir']; }
54 $BaseURL = $basedir;
55 // Get our Host Name and Referer URL's Host Name
56 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
57 $REFERERurl = parse_url($_SERVER['HTTP_REFERER']);
58 if(!isset($REFERERurl['host'])) { $REFERERurl['host'] = null; }
59 $URL['REFERER'] = $REFERERurl['host'];
60 $URL['HOST'] = $basecheck['host'];
61 $REFERERurl = null;
62 // Function made by Howard Yeend
63 // http://php.net/manual/en/function.trigger-error.php#92016
64 // http://www.puremango.co.uk/
65 function output_error($message, $level=E_USER_ERROR) {
66     $caller = next(debug_backtrace());
67     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); }
68 // http://us.php.net/manual/en/function.uniqid.php#94959
69 /**
70   * Generates an UUID
71   * 
72   * @author     Andrew Moore
73   * @url        http://us.php.net/manual/en/function.uniqid.php#94959
74   */
75 function uuid($uuidver = "v4", $rndty = "rand", $namespace = null, $name = null) {
76 if($uuidver!="v3"&&$uuidver!="v4"&&$uuidver!="v5") { $uuidver = "v4"; }
77 if($uuidver=="v4") {
78     return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
79       $rndty(0, 0xffff), $rndty(0, 0xffff),
80       $rndty(0, 0xffff),
81       $rndty(0, 0x0fff) | 0x4000,
82       $rndty(0, 0x3fff) | 0x8000,
83       $rndty(0, 0xffff), $rndty(0, 0xffff), $rndty(0, 0xffff) ); }
84 if($uuidver=="v3"||$uuidver=="v5") {
85         if($namespace===null) {
86         $namespace = uuid("v4",$rndty); }
87     $nhex = str_replace(array('-','{','}'), '', $namespace);
88     $nstr = '';
89     for($i = 0; $i < strlen($nhex); $i+=2) {
90       if(isset($nhex[$i+1])) {
91           $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); }
92       if(!isset($nhex[$i+1])) {
93           $nstr .= chr(hexdec($nhex[$i])); }
94     }
95         if($name===null) { $name = salt_hmac(); }
96     // Calculate hash value
97         if($uuidver=="v3") {
98         $uuidverid = 0x3000;
99         if (function_exists('hash')) {
100         $hash = hash("md5", $nstr . $name); }
101         if (!function_exists('hash')) {
102         $hash = md5($nstr . $name); } }
103         if($uuidver=="v5") {
104         $uuidverid = 0x5000;
105         if (function_exists('hash')) {
106         $hash = hash("sha1", $nstr . $name); }
107         if (!function_exists('hash')) {
108         $hash = sha1($nstr . $name); } }
109     return sprintf('%08s-%04s-%04x-%04x-%12s',
110       substr($hash, 0, 8),
111       substr($hash, 8, 4),
112       (hexdec(substr($hash, 12, 4)) & 0x0fff) | $uuidverid,
113       (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
114       substr($hash, 20, 12) ); } }
115 function rand_uuid($rndty = "rand", $namespace = null, $name = null) {
116 $rand_array = array(1 => "v3", 2 => "v4", 3 => "v5");
117 if($name===null) { $name = salt_hmac(); }
118 $my_uuid = $rand_array[$rndty(1,3)];
119 if($my_uuid=="v4") { return uuid("v4",$rndty); }
120 if($my_uuid=="v3"||$my_uuid=="v5") {
121 return uuid($my_uuid,$rndty,$name); } }
122 // unserialize sessions variables
123 function unserialize_session($data) {
124     $vars=preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff^|]*)\|/',
125               $data,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
126     $i = 0;
127     for($i=0; isset($vars[$i]); $i++) {
128         $l = $i + 1;
129         if(!isset($vars[$i])) { $vars[$i] = null; }
130         if(!isset($vars[$l])) { $vars[$l] = null; }
131         $result[$vars[$i]]=unserialize($vars[$l]);
132         $i++; }
133         if(!isset($result)) { $result = null; }
134     return $result;
135 }
136 // User Agent Checker
137 function user_agent_check($user_agent) {
138 if (preg_match("/".preg_quote("ia_archiver")."/i", $user_agent)) {
139     return "Alexa"; }
140 if (preg_match("/".preg_quote("AltaVista")."/i", $user_agent)) {
141     return "AltaVista"; }
142 if (preg_match("/".preg_quote("Ask Jeeves")."/i", $user_agent)) {
143     return "Ask Jeeves"; }
144 if (preg_match("/".preg_quote("Baiduspider")."/i", $user_agent)) {
145     return "Baidu"; }
146 if (preg_match("/".preg_quote("msnbot")."/i", $user_agent)) {
147     return "Bing"; }
148 if (preg_match("/".preg_quote("CSE HTML Validator")."/i", $user_agent)) {
149     return "CSE HTML Validator"; }
150 if (preg_match("/".preg_quote("discobot")."/i", $user_agent)) {
151     return "DiscoveryEngine"; }
152 if (preg_match("/".preg_quote("Exabot")."/i", $user_agent)) {
153     return "Exabot"; }
154 if (preg_match("/".preg_quote("Googlebot")."/i", $user_agent)) {
155     return "Google"; }
156 if (preg_match("|".preg_quote("HTML/XML Validator","|")."|i", $user_agent)) {
157     return "HTML/XML Validator"; }
158 if (preg_match("/".preg_quote("Lycos")."/i", $user_agent)) {
159     return "Lycos"; }
160 if (preg_match("/".preg_quote("montastic-webmonitor")."/i", $user_agent)) {
161     return "Montastic"; }
162 if (preg_match("/".preg_quote("Sosospider")."/i", $user_agent)) {
163     return "Soso"; }
164 if (preg_match("/".preg_quote("Speedy Spider")."/i", $user_agent)) {
165     return "Speedy"; }
166 if (preg_match("/".preg_quote("TotalValidator")."/i", $user_agent)) {
167     return "Total Validator"; }
168 if (preg_match("/".preg_quote("Yahoo")."/i", $user_agent)) {
169     return "Yahoo"; }
170 if (preg_match("/".preg_quote("Yandex")."/i", $user_agent)) {
171     return "Yandex"; }
172 if (preg_match("/".preg_quote("FeedValidator")."/i", $user_agent)) {
173     return "W3C Validator"; }
174 if (preg_match("/".preg_quote("W3C_CSS_Validator")."/i", $user_agent)) {
175     return "W3C Validator"; }
176 if (preg_match("/".preg_quote("W3C_Validator")."/i", $user_agent)) {
177     return "W3C Validator"; }
178 if (preg_match("/".preg_quote("W3C-checklink")."/i", $user_agent)) {
179     return "W3C Checklink"; }
180 if (preg_match("/".preg_quote("WDG_SiteValidator")."/i", $user_agent)) {
181     return "WDG Validator"; }
182 if (preg_match("/".preg_quote("WDG_Validator")."/i", $user_agent)) {
183     return "WDG Validator"; }
184         return false; }
185 // Make the Query String if we are not useing &=
186 function qstring($qstr=";",$qsep="=")
187 { $_GET = array(); $_GET = null;
188 if (!isset($_SERVER['QUERY_STRING'])) {
189 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
190 ini_get("arg_separator.input", $qstr);
191 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
192 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
193 $qsnum = count($preqs); $qsi = 0;
194 while ($qsi < $qsnum) {
195 $preqst = explode($qsep,$preqs[$qsi],2);
196 $fix1 = array(" ",'$'); $fix2  = array("_","_");
197 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
198 $preqst[0] = killbadvars($preqst[0]);
199 if($preqst[0]!=null) {
200 $_GET[$preqst[0]] = $preqst[1]; }
201 ++$qsi; } return true; }
202 if($_SERVER['PATH_INFO']==null) {
203         if(getenv('PATH_INFO')!=null&&getenv('PATH_INFO')!="1") {
204 $_SERVER['PATH_INFO'] = getenv('PATH_INFO'); }
205 if(getenv('PATH_INFO')==null) {
206 $myscript = $_SERVER["SCRIPT_NAME"];
207 $myphpath = $_SERVER["PHP_SELF"];
208 $mypathinfo = str_replace($myscript, "", $myphpath);
209 @putenv("PATH_INFO=".$mypathinfo); } }
210 // Change raw post data to POST array
211 // Not sure why I made but alwell. :P 
212 function parse_post_data()
213 { $_POST = array(); $_POST = null;
214 $postdata = file_get_contents("php://input");
215 if (!isset($postdata)) { $postdata = null; }
216 $postdata = urldecode($postdata);
217 $preqs = explode("&",$postdata);
218 $qsnum = count($preqs); $qsi = 0;
219 while ($qsi < $qsnum) {
220 $preqst = explode("=",$preqs[$qsi],2);
221 $fix1 = array(" ",'$'); $fix2  = array("_","_");
222 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
223 $preqst[0] = killbadvars($preqst[0]);
224 if($preqst[0]!=null) {
225 $_POST[$preqst[0]] = $preqst[1]; }
226 ++$qsi; } return true; }
227 // Change Path info to Get Vars :
228 function mrstring() {
229 $urlvar = explode('/',$_SERVER['PATH_INFO']);
230 $num=count($urlvar); $i=1;
231 while ($i < $num) {
232 //$urlvar[$i] = urldecode($urlvar[$i]);
233 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
234 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
235 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
236 $fix1 = array(" ",'$'); $fix2  = array("_","_");
237 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
238 $urlvar[$i] = killbadvars($urlvar[$i]);
239         $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
240 ++$i; ++$i; } return true; }
241 // Redirect to another file with ether timed or nontimed redirect
242 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
243 if($type!="location"&&$type!="refresh") { $type=="location"; }
244 if($url!=null) { $file = $url.$file; }
245 if($dbsr===true) { $file = str_replace("//", "/", $file); }
246 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
247 if($type=="location") { session_write_close(); 
248 header("Location: ".$file); } return true; }
249 function redirects($type,$url,$time=0) {
250 if($type!="location"&&$type!="refresh") { $type=="location"; }
251 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
252 if($type=="location") { header("Location: ".$url); } return true; }
253 // Make xhtml tags
254 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
255         $var_num = count($attbvar); $value_num = count($attbval);
256         if($var_num!=$value_num) { 
257                 output_error("Erorr Number of Var and Values dont match!",E_USER_ERROR);
258         return false; } $i = 0;
259         while ($i < $var_num) {
260         if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
261         if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
262         if($i==$var_num-1) { 
263         if($emptytag===false) { $mytag = $mytag.">"; }
264         if($emptytag===true) { $mytag = $mytag." />"; } }       ++$i; }
265         if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
266         if($emptytag===true) { $mytag = $mytag." />"; }
267         if($emptytag===false) { $mytag = $mytag.">"; } }
268         if($emptytag===false&&$extratest!=null) { 
269         $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; } 
270         return $mytag; }
271 // Start a xml document
272 function xml_tag_make($type,$attbs,$retval=false) {
273         $renee1 = explode("&",$attbs);
274         $reneenum=count($renee1);
275         $reneei=0; $attblist = null;
276         while ($reneei < $reneenum) {
277         $renee2 = explode("=",$renee1[$reneei]);
278         if($renee2[0]!=null||$renee2[1]!=null) {
279         $attblist = $attblist.' '.$renee2[0].'="'.$renee2[1].'"'; }
280         ++$reneei; }
281         if($retval!==false&&$retval!==true) { $retval=false; }
282         if($retval===false) {
283         echo '<?'.$type.$attblist.'?>'."\n"; }
284         if($retval===true) {
285         return '<?'.$type.$attblist.'?>'."\n"; } }
286 // Start a xml document (old version)
287 function xml_doc_start($ver,$encode,$retval=false) {
288         if($retval===false) {
289         echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
290         if($retval===true) {
291         return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
292 $icharset = $Settings['charset'];
293 $debug_on = false;
294 if(isset($_GET['debug'])) {
295 if($_GET['debug']=="true"||
296         $_GET['debug']=="on") {
297 $debug_on = true; } }
298 $BoardURL = $Settings['idburl'];
299 // Change URLs to Links
300 function pre_url2link($matches) {
301 global $BoardURL; $opennew = true;
302 $burlCHCK = parse_url($BoardURL);
303 $urlCHCK = parse_url($matches[0]);
304 if($urlCHCK['host']==$burlCHCK['host']) {
305         $opennew = false; }
306 $outurl = $urlCHCK['scheme']."://";
307 if(isset($urlCHCK['user'])) {
308 $outurl = $outurl.$urlCHCK['user'];
309 if(isset($urlCHCK['pass'])) {
310 $outurl = $outurl.":".$urlCHCK['pass']; }
311 $outurl = $outurl."@"; }
312 $outurl = $outurl.$urlCHCK['host'];
313 if(isset($urlCHCK['path'])) {
314 $outurl = $outurl.$urlCHCK['path']; }
315 if(!isset($urlCHCK['path'])) {
316 $outurl = $outurl."/"; }
317 if(isset($urlCHCK['query'])) {
318 $urlCHCK['query'] = str_replace(" ", "+", $urlCHCK['query']);
319 $outurl = $outurl."?".$urlCHCK['query']; }
320 if(isset($urlCHCK['fragment'])) {
321 $urlCHCK['fragment'] = str_replace(" ", "+", $urlCHCK['fragment']);
322 $outurl = $outurl."#".$urlCHCK['fragment']; }
323 if($opennew===true) {
324 $outlink = "<a onclick=\"window.open(this.href); return false;\" href=\"".$outurl."\">".$outurl."</a>"; }
325 if($opennew===false) {
326 $outlink = "<a href=\"".$outurl."\">".$outurl."</a>"; }
327 return $outlink; }
328 function url2link($string) {
329 return preg_replace_callback("/([a-zA-Z]+)\:\/\/([a-z0-9\-\.]+)(\:[0-9]+)?\/([A-Za-z0-9\.\/%\?\-_;]+)?(\?)?([A-Za-z0-9\.\/%&=\?\-_;]+)?(\#)?([A-Za-z0-9\.\/%&=\?\-_;]+)?/is", "pre_url2link", $string); }
330 function urlcheck($string) {
331 global $BoardURL;
332 $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); 
333 if(isset($urlcheck[0][0])) { $url = $urlcheck[0][0]; }
334 if(!isset($urlcheck[0][0])) { $url = $BoardURL; }
335 return $url; }
336 //Check to make sure theme exists
337 $BoardTheme = $Settings['DefaultTheme'];
338 $ThemeDir = $SettDir['themes'];
339 function chack_themes($theme) {
340 global $BoardTheme,$ThemeDir;
341 if(!isset($theme)) { $theme = null; }
342 if(preg_match("/([a-zA-Z]+)\:/isU",$theme)) {
343         $theme = $BoardTheme; }
344 if(!preg_match("/^[a-z0-9]+$/isU",$theme)) {
345         $theme = $BoardTheme; }
346 require('settings.php');
347 $ckskindir = dirname(realpath("settings.php"))."/".$ThemeDir;
348 if ($handle = opendir($ckskindir)) { $dirnum = null;
349    while (false !== ($ckfile = readdir($handle))) {
350            if ($dirnum==null) { $dirnum = 0; }
351            if (file_exists($ckskindir.$ckfile."/info.php")) {
352                    if ($ckfile != "." && $ckfile != "..") {
353            //include($ckskindir.$ckfile."/info.php");
354        $cktheme[$dirnum] =  $ckfile;
355            ++$dirnum; } } }
356    closedir($handle); asort($cktheme); }
357 $theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
358 if(!in_array($theme,$cktheme)||strlen($theme)>26) {
359         $theme = $BoardTheme; } return $theme; }
360 // Make a url with query string
361 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
362 global $sidurls, $icharset, $debug_on;
363 $fileurl = null; if(!isset($ext)) { $ext = null; }
364 if($ext==null) { $ext = ".php"; } 
365 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
366 $file = $file.$ext;
367 if($sidurls=="on"&&$qstr!="/") { 
368         if(defined('SID')) {
369 if($qvarstr==null) { $qvarstr = SID; }
370 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
371 if($debug_on===true) {
372 if($qvarstr==null) { $qvarstr = "debug=on"; }
373 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
374 if($qvarstr==null) { $fileurl = $file; }
375 if($fixhtml===true) {
376 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
377 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
378 if($prexqstr!=null) { 
379 $rene1 = explode("&",$prexqstr);
380 $renenum=count($rene1);
381 $renei=0;
382 $reneqstr = "index.php?";
383 if($qstr!="/") { $fileurl = $file."?"; }
384 if($qstr=="/") { $fileurl = $file."/"; }
385 while ($renei < $renenum) {
386         $rene2 = explode("=",$rene1[$renei]);
387         if(!isset($rene2[0])) { $rene2[0] = null; }
388         $rene2[1] = urlencode($rene2[1]);
389         if(!isset($rene2[0])) { $rene2[0] = null; }
390         $rene2[1] = urlencode($rene2[1]);
391         if($qstr!="/") {
392         $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
393         if($qstr=="/") {
394         $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
395         $reneis = $renei + 1;
396         if($qstr!="/") {
397         if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
398         ++$renei; } }
399 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
400 if($qvarstr!=null) { 
401 if($prexqstr==null) {
402 if($qstr!="/") { $fileurl = $file."?"; }
403 if($qstr=="/") { $fileurl = $file."/"; } }
404 $cind1 = explode("&",$qvarstr);
405 $cindnum=count($cind1);
406 $cindi=0;
407 $cindqstr = "index.php?";
408 while ($cindi < $cindnum) {
409         $cind2 = explode("=",$cind1[$cindi]);
410         if(!isset($cind2[0])) { $cind2[0] = null; }
411         $cind2[0] = urlencode($cind2[0]);
412         if(!isset($cind2[1])) { $cind2[1] = null; }
413         $cind2[1] = urlencode($cind2[1]);
414         if($qstr!="/") {
415         $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
416         if($qstr=="/") {
417         $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
418         $cindis = $cindi + 1;
419         if($qstr!="/") {
420         if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
421         ++$cindi; } }
422 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
423 if($exqstr!=null) { 
424 if($qvarstr==null&&$prexqstr==null) {
425 if($qstr!="/") { $fileurl = $file."?"; }
426 if($qstr=="/") { $fileurl = $file."/"; } }
427 $sand1 = explode("&",$exqstr);
428 $sanum=count($sand1);
429 $sandi=0;
430 $sandqstr = "index.php?";
431 while ($sandi < $sanum) {
432         $sand2 = explode("=",$sand1[$sandi]);
433         if(!isset($sand2[0])) { $sand2[0] = null; }
434         $sand2[0] = urlencode($sand2[0]);
435         if(!isset($sand2[1])) { $sand2[1] = null; }
436         $sand2[1] = urlencode($sand2[1]);
437         if($qstr!="/") {
438         $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
439         if($qstr=="/") {
440         $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
441         $sandis = $sandi + 1;
442         if($qstr!="/") {
443         if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
444         ++$sandi; } }
445 return $fileurl; }
446 $thisdir = dirname(realpath("Preindex.php"))."/";
447 // Get the Query String
448 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
449 { $pregqstr = preg_quote($qstr,"/");
450 $pregqsep = preg_quote($qsep,"/");
451 $oqstr = $qstr; $oqsep = $qsep;
452 if($fixhtml===true||$fixhtml==null) {
453 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
454 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
455 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
456 $BoardQuery = "?".$OldBoardQuery;
457 return $BoardQuery; }
458 ?>