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-2008 Cool Dude 2k - http://idb.berlios.de/
12 Copyright 2004-2008 Game Maker 2k - http://intdb.sourceforge.net/
14 $FileInfo: function.php - Last Update: 6/11/2009 SVN 263 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="function.php"||$File3Name=="/function.php") {
20 require_once($SettDir['misc'].'functions.php');
21 /* Change Some PHP Settings Fix the & to &
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);
41 if($Settings['fixbasedir']!=null&&$Settings['fixbasedir']!="off") {
42 $basedir = $Settings['fixbasedir']; }
43 if($Settings['fixcookiedir']!=null&&$Settings['fixcookiedir']!="") {
44 $cbasedir = $Settings['fixcookiedir']; }
46 // Get our Host Name and Referer URL's Host Name
47 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
48 $REFERERurl = parse_url($_SERVER['HTTP_REFERER']);
49 if(!isset($REFERERurl['host'])) { $REFERERurl['host'] = null; }
50 $URL['REFERER'] = $REFERERurl['host'];
51 $URL['HOST'] = $_SERVER["SERVER_NAME"];
53 // http://www.ajaxray.com/blog/2008/02/06/php-uuid-generator-function/
57 * @author Anis uddin Ahmad <admin@ajaxray.com>
58 * @param string an optional prefix
59 * @return string the formatted uuid
61 function uuid($useold = false,$more_entropy = false,$mtrand = false,$prefix = '')
63 if($useold===true&&$mtrand===false) {
64 $chars = uniqid(md5(rand()),$more_entropy); }
65 if($useold===false&&$mtrand===false) {
66 $chars = md5(uniqid(rand(),$more_entropy)); }
67 if($useold===true&&$mtrand===true) {
68 $chars = uniqid(md5(mt_rand()),$more_entropy); }
69 if($useold===false&&$mtrand===true) {
70 $chars = md5(uniqid(mt_rand(),$more_entropy)); }
71 $uuid = substr($chars,0,8) . '-';
72 $uuid .= substr($chars,8,4) . '-';
73 $uuid .= substr($chars,12,4) . '-';
74 $uuid .= substr($chars,16,4) . '-';
75 $uuid .= substr($chars,20,12);
76 if(isset($prefix)) { return $prefix . $uuid; }
77 if(!isset($prefix)) { return $uuid; }
79 // Make the Query String if we are not useing &=
80 function qstring($qstr=";",$qsep="=")
81 { $_GET = null; $_GET = array();
82 if (!isset($_SERVER['QUERY_STRING'])) {
83 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
84 @ini_get("arg_separator.input", $qstr);
85 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
86 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
87 $qsnum = count($preqs); $qsi = 0;
88 while ($qsi < $qsnum) {
89 $preqst = explode($qsep,$preqs[$qsi],2);
90 $fix1 = array(" ",'$'); $fix2 = array("_","_");
91 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
92 $preqst[0] = killbadvars($preqst[0]);
93 if($preqst[0]!=null) {
94 $_GET[$preqst[0]] = $preqst[1]; }
95 ++$qsi; } return true; }
96 if($_SERVER['PATH_INFO']==null) {
97 if(@getenv('PATH_INFO')!=null&&@getenv('PATH_INFO')!="1") {
98 $_SERVER['PATH_INFO'] = @getenv('PATH_INFO'); }
99 if(@getenv('PATH_INFO')==null) {
100 $myscript = $_SERVER["SCRIPT_NAME"];
101 $myphpath = $_SERVER["PHP_SELF"];
102 $mypathinfo = str_replace($myscript, "", $myphpath);
103 @putenv("PATH_INFO=".$mypathinfo); } }
104 // Change Path info to Get Vars :
105 function mrstring() {
106 $urlvar = explode('/',$_SERVER['PATH_INFO']);
107 $num=count($urlvar); $i=1;
109 //$urlvar[$i] = urldecode($urlvar[$i]);
110 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
111 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
112 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
113 $fix1 = array(" ",'$'); $fix2 = array("_","_");
114 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
115 $urlvar[$i] = killbadvars($urlvar[$i]);
116 $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
117 ++$i; ++$i; } return true; }
118 // Redirect to another file with ether timed or nontimed redirect
119 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
120 if($type!="location"&&$type!="refresh") { $type=="location"; }
121 if($url!=null) { $file = $url.$file; }
122 if($dbsr===true) { $file = str_replace("//", "/", $file); }
123 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
124 if($type=="location") { @session_write_close();
125 header("Location: ".$file); } return true; }
126 function redirects($type,$url,$time=0) {
127 if($type!="location"&&$type!="refresh") { $type=="location"; }
128 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
129 if($type=="location") { header("Location: ".$url); } return true; }
131 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
132 $var_num = count($attbvar); $value_num = count($attbval);
133 if($var_num!=$value_num) {
134 echo "Erorr Number of Var and Values dont match!";
135 return false; } $i = 0;
136 while ($i < $var_num) {
137 if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
138 if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
140 if($emptytag===false) { $mytag = $mytag.">"; }
141 if($emptytag===true) { $mytag = $mytag." />"; } } ++$i; }
142 if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
143 if($emptytag===true) { $mytag = $mytag." />"; }
144 if($emptytag===false) { $mytag = $mytag.">"; } }
145 if($emptytag===false&&$extratest!=null) {
146 $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; }
148 // Start a xml document
149 function xml_tag_make($type,$attbs,$retval=false) {
150 $renee1 = explode("&",$attbs);
151 $reneenum=count($renee1);
152 $reneei=0; $attblist = null;
153 while ($reneei < $reneenum) {
154 $renee2 = explode("=",$renee1[$reneei]);
155 if($renee2[0]!=null||$renee2[1]!=null) {
156 $attblist = $attblist.' '.$renee2[0].'="'.$renee2[1].'"'; }
158 if($retval!==false&&$retval!==true) { $retval=false; }
159 if($retval===false) {
160 echo '<?'.$type.$attblist.'?>'."\n"; }
162 return '<?'.$type.$attblist.'?>'."\n"; } }
163 // Start a xml document (old version)
164 function xml_doc_start($ver,$encode,$retval=false) {
165 if($retval===false) {
166 echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
168 return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
169 $icharset = $Settings['charset'];
172 if(isset($_GET['debug'])) {
173 if($_GET['debug']=="true"||
174 $_GET['debug']=="on") {
175 $debug_on = true; } }
176 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
177 global $sidurls, $icharset, $debug_on;
178 $fileurl = null; if(!isset($ext)) { $ext = null; }
179 if($ext==null) { $ext = ".php"; }
180 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
182 if($sidurls=="on"&&$qstr!="/") {
184 if($qvarstr==null) { $qvarstr = SID; }
185 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
186 if($debug_on===true) {
187 if($qvarstr==null) { $qvarstr = "debug=on"; }
188 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
189 if($qvarstr==null) { $fileurl = $file; }
190 if($fixhtml===true) {
191 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
192 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
193 if($prexqstr!=null) {
194 $rene1 = explode("&",$prexqstr);
195 $renenum=count($rene1);
197 $reneqstr = "index.php?";
198 if($qstr!="/") { $fileurl = $file."?"; }
199 if($qstr=="/") { $fileurl = $file."/"; }
200 while ($renei < $renenum) {
201 $rene2 = explode("=",$rene1[$renei]);
202 if(!isset($rene2[0])) { $rene2[0] = null; }
203 $rene2[1] = urlencode($rene2[1]);
204 if(!isset($rene2[0])) { $rene2[0] = null; }
205 $rene2[1] = urlencode($rene2[1]);
207 $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
209 $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
210 $reneis = $renei + 1;
212 if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
214 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
216 if($prexqstr==null) {
217 if($qstr!="/") { $fileurl = $file."?"; }
218 if($qstr=="/") { $fileurl = $file."/"; } }
219 $cind1 = explode("&",$qvarstr);
220 $cindnum=count($cind1);
222 $cindqstr = "index.php?";
223 while ($cindi < $cindnum) {
224 $cind2 = explode("=",$cind1[$cindi]);
225 if(!isset($cind2[0])) { $cind2[0] = null; }
226 $cind2[0] = urlencode($cind2[0]);
227 if(!isset($cind2[1])) { $cind2[1] = null; }
228 $cind2[1] = urlencode($cind2[1]);
230 $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
232 $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
233 $cindis = $cindi + 1;
235 if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
237 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
239 if($qvarstr==null&&$prexqstr==null) {
240 if($qstr!="/") { $fileurl = $file."?"; }
241 if($qstr=="/") { $fileurl = $file."/"; } }
242 $sand1 = explode("&",$exqstr);
243 $sanum=count($sand1);
245 $sandqstr = "index.php?";
246 while ($sandi < $sanum) {
247 $sand2 = explode("=",$sand1[$sandi]);
248 if(!isset($sand2[0])) { $sand2[0] = null; }
249 $sand2[0] = urlencode($sand2[0]);
250 if(!isset($sand2[1])) { $sand2[1] = null; }
251 $sand2[1] = urlencode($sand2[1]);
253 $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
255 $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
256 $sandis = $sandi + 1;
258 if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
261 $thisdir = dirname(realpath("Preindex.php"))."/";
262 // Get the Query String
263 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
264 { $pregqstr = preg_quote($qstr,"/");
265 $pregqsep = preg_quote($qsep,"/");
266 $oqstr = $qstr; $oqsep = $qsep;
267 if($fixhtml===true||$fixhtml==null) {
268 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
269 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
270 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
271 $BoardQuery = "?".$OldBoardQuery;
272 return $BoardQuery; }