OSDN Git Service

3064045069140c0b19f31d058fdacdb079c50f84
[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-2009 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2009 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: function.php - Last Update: 8/8/2009 SVN 299 - 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'].'sha256.php');
21 require_once($SettDir['misc'].'functions.php');
22 /* Change Some PHP Settings Fix the & to &amp;
23 if($Settings['use_iniset']==true&&$Settings['qstr']!="/") {
24 @ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
25 @ini_set("arg_separator.input",$Settings['qstr']);
26 @ini_set("arg_separator",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset'])); }
27 //$basepath = pathinfo($_SERVER['REQUEST_URI']);
28 if(dirname($_SERVER['REQUEST_URI'])!="."||
29         dirname($_SERVER['REQUEST_URI'])!=null) {
30 $basedir = dirname($_SERVER['REQUEST_URI'])."/"; }*/
31 // Get the base dir name
32 /*if(dirname($_SERVER['SCRIPT_NAME'])!="."||
33         dirname($_SERVER['SCRIPT_NAME'])!=null) {
34 $basedir = dirname($_SERVER['SCRIPT_NAME'])."/"; }
35 if($basedir==null||$basedir==".") {
36 if(dirname($_SERVER['SCRIPT_NAME'])=="."||
37         dirname($_SERVER['SCRIPT_NAME'])==null) {
38 $basedir = dirname($_SERVER['PHP_SELF'])."/"; } }
39 if($basedir=="\/") { $basedir="/"; }
40 $basedir = str_replace("//", "/", $basedir);*/
41 if($Settings['qstr']!="/") {
42 $iDBURLCHK = $Settings['idburl']; }
43 if($Settings['qstr']=="/") {
44 $iDBURLCHK = preg_replace("/\/$/","",$Settings['idburl']); }
45 $basecheck = parse_url($iDBURLCHK);
46 $basedir = $basecheck['path'];
47 $cbasedir = $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 $BaseURL = $basedir;
53 // Get our Host Name and Referer URL's Host Name
54 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
55 $REFERERurl = parse_url($_SERVER['HTTP_REFERER']);
56 if(!isset($REFERERurl['host'])) { $REFERERurl['host'] = null; }
57 $URL['REFERER'] = $REFERERurl['host'];
58 $URL['HOST'] = $basecheck['host'];
59 $REFERERurl = null;
60 // http://www.ajaxray.com/blog/2008/02/06/php-uuid-generator-function/
61 /**
62   * Generates an UUID
63   * 
64   * @author     Anis uddin Ahmad <admin@ajaxray.com>
65   * @param      string  an optional prefix
66   * @return     string  the formatted uuid
67   */
68   function uuid($useold = false,$more_entropy = false,$mtrand = false,$prefix = '') 
69   {
70     if($useold===true&&$mtrand===false) {
71         $chars = uniqid(md5(rand()),$more_entropy); }
72     if($useold===false&&$mtrand===false) {
73         $chars = md5(uniqid(rand(),$more_entropy)); }
74     if($useold===true&&$mtrand===true) {
75         $chars = uniqid(md5(mt_rand()),$more_entropy); }
76     if($useold===false&&$mtrand===true) {
77         $chars = md5(uniqid(mt_rand(),$more_entropy)); }
78     $uuid  = substr($chars,0,8) . '-';
79     $uuid .= substr($chars,8,4) . '-';
80     $uuid .= substr($chars,12,4) . '-';
81     $uuid .= substr($chars,16,4) . '-';
82     $uuid .= substr($chars,20,12);    
83     if(isset($prefix)) { return $prefix . $uuid; }
84     if(!isset($prefix)) { return $uuid; }
85   }
86 // unserialize sessions variables
87 function unserialize_session($data) {
88     $vars=preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff^|]*)\|/',
89               $data,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
90     for($i=0; $vars[$i]; $i++) $result[$vars[$i++]]=unserialize($vars[$i]);
91     return $result;
92 }
93 // Make the Query String if we are not useing &=
94 function qstring($qstr=";",$qsep="=")
95 { $_GET = null; $_GET = array();
96 if (!isset($_SERVER['QUERY_STRING'])) {
97 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
98 @ini_get("arg_separator.input", $qstr);
99 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
100 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
101 $qsnum = count($preqs); $qsi = 0;
102 while ($qsi < $qsnum) {
103 $preqst = explode($qsep,$preqs[$qsi],2);
104 $fix1 = array(" ",'$'); $fix2  = array("_","_");
105 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
106 $preqst[0] = killbadvars($preqst[0]);
107 if($preqst[0]!=null) {
108 $_GET[$preqst[0]] = $preqst[1]; }
109 ++$qsi; } return true; }
110 if($_SERVER['PATH_INFO']==null) {
111         if(@getenv('PATH_INFO')!=null&&@getenv('PATH_INFO')!="1") {
112 $_SERVER['PATH_INFO'] = @getenv('PATH_INFO'); }
113 if(@getenv('PATH_INFO')==null) {
114 $myscript = $_SERVER["SCRIPT_NAME"];
115 $myphpath = $_SERVER["PHP_SELF"];
116 $mypathinfo = str_replace($myscript, "", $myphpath);
117 @putenv("PATH_INFO=".$mypathinfo); } }
118 // Change Path info to Get Vars :
119 function mrstring() {
120 $urlvar = explode('/',$_SERVER['PATH_INFO']);
121 $num=count($urlvar); $i=1;
122 while ($i < $num) {
123 //$urlvar[$i] = urldecode($urlvar[$i]);
124 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
125 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
126 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
127 $fix1 = array(" ",'$'); $fix2  = array("_","_");
128 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
129 $urlvar[$i] = killbadvars($urlvar[$i]);
130         $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
131 ++$i; ++$i; } return true; }
132 // Redirect to another file with ether timed or nontimed redirect
133 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
134 if($type!="location"&&$type!="refresh") { $type=="location"; }
135 if($url!=null) { $file = $url.$file; }
136 if($dbsr===true) { $file = str_replace("//", "/", $file); }
137 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
138 if($type=="location") { @session_write_close(); 
139 header("Location: ".$file); } return true; }
140 function redirects($type,$url,$time=0) {
141 if($type!="location"&&$type!="refresh") { $type=="location"; }
142 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
143 if($type=="location") { header("Location: ".$url); } return true; }
144 // Make xhtml tags
145 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
146         $var_num = count($attbvar); $value_num = count($attbval);
147         if($var_num!=$value_num) { 
148                 echo "Erorr Number of Var and Values dont match!";
149         return false; } $i = 0;
150         while ($i < $var_num) {
151         if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
152         if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
153         if($i==$var_num-1) { 
154         if($emptytag===false) { $mytag = $mytag.">"; }
155         if($emptytag===true) { $mytag = $mytag." />"; } }       ++$i; }
156         if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
157         if($emptytag===true) { $mytag = $mytag." />"; }
158         if($emptytag===false) { $mytag = $mytag.">"; } }
159         if($emptytag===false&&$extratest!=null) { 
160         $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; } 
161         return $mytag; }
162 // Start a xml document
163 function xml_tag_make($type,$attbs,$retval=false) {
164         $renee1 = explode("&",$attbs);
165         $reneenum=count($renee1);
166         $reneei=0; $attblist = null;
167         while ($reneei < $reneenum) {
168         $renee2 = explode("=",$renee1[$reneei]);
169         if($renee2[0]!=null||$renee2[1]!=null) {
170         $attblist = $attblist.' '.$renee2[0].'="'.$renee2[1].'"'; }
171         ++$reneei; }
172         if($retval!==false&&$retval!==true) { $retval=false; }
173         if($retval===false) {
174         echo '<?'.$type.$attblist.'?>'."\n"; }
175         if($retval===true) {
176         return '<?'.$type.$attblist.'?>'."\n"; } }
177 // Start a xml document (old version)
178 function xml_doc_start($ver,$encode,$retval=false) {
179         if($retval===false) {
180         echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
181         if($retval===true) {
182         return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
183 $icharset = $Settings['charset'];
184 $debug_on = false;
185 if(isset($_GET['debug'])) {
186 if($_GET['debug']=="true"||
187         $_GET['debug']=="on") {
188 $debug_on = true; } }
189 // Make a url with query string
190 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
191 global $sidurls, $icharset, $debug_on;
192 $fileurl = null; if(!isset($ext)) { $ext = null; }
193 if($ext==null) { $ext = ".php"; } 
194 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
195 $file = $file.$ext;
196 if($sidurls=="on"&&$qstr!="/") { 
197         if(defined('SID')) {
198 if($qvarstr==null) { $qvarstr = SID; }
199 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
200 if($debug_on===true) {
201 if($qvarstr==null) { $qvarstr = "debug=on"; }
202 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
203 if($qvarstr==null) { $fileurl = $file; }
204 if($fixhtml===true) {
205 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
206 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
207 if($prexqstr!=null) { 
208 $rene1 = explode("&",$prexqstr);
209 $renenum=count($rene1);
210 $renei=0;
211 $reneqstr = "index.php?";
212 if($qstr!="/") { $fileurl = $file."?"; }
213 if($qstr=="/") { $fileurl = $file."/"; }
214 while ($renei < $renenum) {
215         $rene2 = explode("=",$rene1[$renei]);
216         if(!isset($rene2[0])) { $rene2[0] = null; }
217         $rene2[1] = urlencode($rene2[1]);
218         if(!isset($rene2[0])) { $rene2[0] = null; }
219         $rene2[1] = urlencode($rene2[1]);
220         if($qstr!="/") {
221         $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
222         if($qstr=="/") {
223         $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
224         $reneis = $renei + 1;
225         if($qstr!="/") {
226         if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
227         ++$renei; } }
228 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
229 if($qvarstr!=null) { 
230 if($prexqstr==null) {
231 if($qstr!="/") { $fileurl = $file."?"; }
232 if($qstr=="/") { $fileurl = $file."/"; } }
233 $cind1 = explode("&",$qvarstr);
234 $cindnum=count($cind1);
235 $cindi=0;
236 $cindqstr = "index.php?";
237 while ($cindi < $cindnum) {
238         $cind2 = explode("=",$cind1[$cindi]);
239         if(!isset($cind2[0])) { $cind2[0] = null; }
240         $cind2[0] = urlencode($cind2[0]);
241         if(!isset($cind2[1])) { $cind2[1] = null; }
242         $cind2[1] = urlencode($cind2[1]);
243         if($qstr!="/") {
244         $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
245         if($qstr=="/") {
246         $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
247         $cindis = $cindi + 1;
248         if($qstr!="/") {
249         if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
250         ++$cindi; } }
251 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
252 if($exqstr!=null) { 
253 if($qvarstr==null&&$prexqstr==null) {
254 if($qstr!="/") { $fileurl = $file."?"; }
255 if($qstr=="/") { $fileurl = $file."/"; } }
256 $sand1 = explode("&",$exqstr);
257 $sanum=count($sand1);
258 $sandi=0;
259 $sandqstr = "index.php?";
260 while ($sandi < $sanum) {
261         $sand2 = explode("=",$sand1[$sandi]);
262         if(!isset($sand2[0])) { $sand2[0] = null; }
263         $sand2[0] = urlencode($sand2[0]);
264         if(!isset($sand2[1])) { $sand2[1] = null; }
265         $sand2[1] = urlencode($sand2[1]);
266         if($qstr!="/") {
267         $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
268         if($qstr=="/") {
269         $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
270         $sandis = $sandi + 1;
271         if($qstr!="/") {
272         if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
273         ++$sandi; } }
274 return $fileurl; }
275 $thisdir = dirname(realpath("Preindex.php"))."/";
276 // Get the Query String
277 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
278 { $pregqstr = preg_quote($qstr,"/");
279 $pregqsep = preg_quote($qsep,"/");
280 $oqstr = $qstr; $oqsep = $qsep;
281 if($fixhtml===true||$fixhtml==null) {
282 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
283 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
284 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
285 $BoardQuery = "?".$OldBoardQuery;
286 return $BoardQuery; }
287 ?>