OSDN Git Service

Revorted some changes. :P
[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: 11/23/2009 SVN 358 - 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,$hash = 'sha1',$prefix = '') 
69   {
70     if($useold===true&&$mtrand===false) {
71         $chars = uniqid($hash(rand()),$more_entropy); }
72     if($useold===false&&$mtrand===false) {
73         $chars = $hash(uniqid(rand(),$more_entropy)); }
74     if($useold===true&&$mtrand===true) {
75         $chars = uniqid($hash(mt_rand()),$more_entropy); }
76     if($useold===false&&$mtrand===true) {
77         $chars = $hash(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     $i = 0;
91     for($i=0; isset($vars[$i]); $i++) {
92         $l = $i + 1;
93         if(!isset($vars[$i])) { $vars[$i] = null; }
94         if(!isset($vars[$l])) { $vars[$l] = null; }
95         $result[$vars[$i]]=unserialize($vars[$l]);
96         $i++; }
97         if(!isset($result)) { $result = null; }
98     return $result;
99 }
100 // Make the Query String if we are not useing &=
101 function qstring($qstr=";",$qsep="=")
102 { $_GET = array(); $_GET = null;
103 if (!isset($_SERVER['QUERY_STRING'])) {
104 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
105 ini_get("arg_separator.input", $qstr);
106 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
107 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
108 $qsnum = count($preqs); $qsi = 0;
109 while ($qsi < $qsnum) {
110 $preqst = explode($qsep,$preqs[$qsi],2);
111 $fix1 = array(" ",'$'); $fix2  = array("_","_");
112 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
113 $preqst[0] = killbadvars($preqst[0]);
114 if($preqst[0]!=null) {
115 $_GET[$preqst[0]] = $preqst[1]; }
116 ++$qsi; } return true; }
117 if($_SERVER['PATH_INFO']==null) {
118         if(getenv('PATH_INFO')!=null&&getenv('PATH_INFO')!="1") {
119 $_SERVER['PATH_INFO'] = getenv('PATH_INFO'); }
120 if(getenv('PATH_INFO')==null) {
121 $myscript = $_SERVER["SCRIPT_NAME"];
122 $myphpath = $_SERVER["PHP_SELF"];
123 $mypathinfo = str_replace($myscript, "", $myphpath);
124 putenv("PATH_INFO=".$mypathinfo); } }
125 // Change raw post data to POST array
126 // Not sure why I made but alwell. :P 
127 function parse_post_data()
128 { $_POST = array(); $_POST = null;
129 $postdata = file_get_contents("php://input");
130 if (!isset($postdata)) { $postdata = null; }
131 $postdata = urldecode($postdata);
132 $preqs = explode("&",$postdata);
133 $qsnum = count($preqs); $qsi = 0;
134 while ($qsi < $qsnum) {
135 $preqst = explode("=",$preqs[$qsi],2);
136 $fix1 = array(" ",'$'); $fix2  = array("_","_");
137 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
138 $preqst[0] = killbadvars($preqst[0]);
139 if($preqst[0]!=null) {
140 $_POST[$preqst[0]] = $preqst[1]; }
141 ++$qsi; } return true; }
142 // Change Path info to Get Vars :
143 function mrstring() {
144 $urlvar = explode('/',$_SERVER['PATH_INFO']);
145 $num=count($urlvar); $i=1;
146 while ($i < $num) {
147 //$urlvar[$i] = urldecode($urlvar[$i]);
148 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
149 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
150 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
151 $fix1 = array(" ",'$'); $fix2  = array("_","_");
152 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
153 $urlvar[$i] = killbadvars($urlvar[$i]);
154         $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
155 ++$i; ++$i; } return true; }
156 // Redirect to another file with ether timed or nontimed redirect
157 function redirect($type,$file,$time=0,$url=null,$dbsr=true) {
158 if($type!="location"&&$type!="refresh") { $type=="location"; }
159 if($url!=null) { $file = $url.$file; }
160 if($dbsr===true) { $file = str_replace("//", "/", $file); }
161 if($type=="refresh") { header("Refresh: ".$time."; URL=".$file); }
162 if($type=="location") { session_write_close(); 
163 header("Location: ".$file); } return true; }
164 function redirects($type,$url,$time=0) {
165 if($type!="location"&&$type!="refresh") { $type=="location"; }
166 if($type=="refresh") { header("Refresh: ".$time."; URL=".$url); }
167 if($type=="location") { header("Location: ".$url); } return true; }
168 // Make xhtml tags
169 function html_tag_make($name="br",$emptytag=true,$attbvar=null,$attbval=null,$extratest=null) {
170         $var_num = count($attbvar); $value_num = count($attbval);
171         if($var_num!=$value_num) { 
172                 trigger_error("Erorr Number of Var and Values dont match!",E_USER_ERROR);
173         return false; } $i = 0;
174         while ($i < $var_num) {
175         if($i==0) { $mytag = "<".$name." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
176         if($i>=1) { $mytag = $mytag." ".$attbvar[$i]."=\"".$attbval[$i]."\""; }
177         if($i==$var_num-1) { 
178         if($emptytag===false) { $mytag = $mytag.">"; }
179         if($emptytag===true) { $mytag = $mytag." />"; } }       ++$i; }
180         if($attbvar==null&&$attbval==null) { $mytag = "<".$name;
181         if($emptytag===true) { $mytag = $mytag." />"; }
182         if($emptytag===false) { $mytag = $mytag.">"; } }
183         if($emptytag===false&&$extratest!=null) { 
184         $mytag = $mytag.$extratest; $mytag = $mytag."</".$name.">"; } 
185         return $mytag; }
186 // Start a xml document
187 function xml_tag_make($type,$attbs,$retval=false) {
188         $renee1 = explode("&",$attbs);
189         $reneenum=count($renee1);
190         $reneei=0; $attblist = null;
191         while ($reneei < $reneenum) {
192         $renee2 = explode("=",$renee1[$reneei]);
193         if($renee2[0]!=null||$renee2[1]!=null) {
194         $attblist = $attblist.' '.$renee2[0].'="'.$renee2[1].'"'; }
195         ++$reneei; }
196         if($retval!==false&&$retval!==true) { $retval=false; }
197         if($retval===false) {
198         echo '<?'.$type.$attblist.'?>'."\n"; }
199         if($retval===true) {
200         return '<?'.$type.$attblist.'?>'."\n"; } }
201 // Start a xml document (old version)
202 function xml_doc_start($ver,$encode,$retval=false) {
203         if($retval===false) {
204         echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
205         if($retval===true) {
206         return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
207 $icharset = $Settings['charset'];
208 $debug_on = false;
209 if(isset($_GET['debug'])) {
210 if($_GET['debug']=="true"||
211         $_GET['debug']=="on") {
212 $debug_on = true; } }
213 // Make a url with query string
214 function url_maker($file="index",$ext=".php",$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
215 global $sidurls, $icharset, $debug_on;
216 $fileurl = null; if(!isset($ext)) { $ext = null; }
217 if($ext==null) { $ext = ".php"; } 
218 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
219 $file = $file.$ext;
220 if($sidurls=="on"&&$qstr!="/") { 
221         if(defined('SID')) {
222 if($qvarstr==null) { $qvarstr = SID; }
223 if($qvarstr!=null) { $qvarstr = SID."&".$qvarstr; } } }
224 if($debug_on===true) {
225 if($qvarstr==null) { $qvarstr = "debug=on"; }
226 if($qvarstr!=null) { $qvarstr = $qvarstr."&debug=on"; } }
227 if($qvarstr==null) { $fileurl = $file; }
228 if($fixhtml===true) {
229 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
230 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
231 if($prexqstr!=null) { 
232 $rene1 = explode("&",$prexqstr);
233 $renenum=count($rene1);
234 $renei=0;
235 $reneqstr = "index.php?";
236 if($qstr!="/") { $fileurl = $file."?"; }
237 if($qstr=="/") { $fileurl = $file."/"; }
238 while ($renei < $renenum) {
239         $rene2 = explode("=",$rene1[$renei]);
240         if(!isset($rene2[0])) { $rene2[0] = null; }
241         $rene2[1] = urlencode($rene2[1]);
242         if(!isset($rene2[0])) { $rene2[0] = null; }
243         $rene2[1] = urlencode($rene2[1]);
244         if($qstr!="/") {
245         $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
246         if($qstr=="/") {
247         $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
248         $reneis = $renei + 1;
249         if($qstr!="/") {
250         if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
251         ++$renei; } }
252 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
253 if($qvarstr!=null) { 
254 if($prexqstr==null) {
255 if($qstr!="/") { $fileurl = $file."?"; }
256 if($qstr=="/") { $fileurl = $file."/"; } }
257 $cind1 = explode("&",$qvarstr);
258 $cindnum=count($cind1);
259 $cindi=0;
260 $cindqstr = "index.php?";
261 while ($cindi < $cindnum) {
262         $cind2 = explode("=",$cind1[$cindi]);
263         if(!isset($cind2[0])) { $cind2[0] = null; }
264         $cind2[0] = urlencode($cind2[0]);
265         if(!isset($cind2[1])) { $cind2[1] = null; }
266         $cind2[1] = urlencode($cind2[1]);
267         if($qstr!="/") {
268         $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
269         if($qstr=="/") {
270         $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
271         $cindis = $cindi + 1;
272         if($qstr!="/") {
273         if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
274         ++$cindi; } }
275 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
276 if($exqstr!=null) { 
277 if($qvarstr==null&&$prexqstr==null) {
278 if($qstr!="/") { $fileurl = $file."?"; }
279 if($qstr=="/") { $fileurl = $file."/"; } }
280 $sand1 = explode("&",$exqstr);
281 $sanum=count($sand1);
282 $sandi=0;
283 $sandqstr = "index.php?";
284 while ($sandi < $sanum) {
285         $sand2 = explode("=",$sand1[$sandi]);
286         if(!isset($sand2[0])) { $sand2[0] = null; }
287         $sand2[0] = urlencode($sand2[0]);
288         if(!isset($sand2[1])) { $sand2[1] = null; }
289         $sand2[1] = urlencode($sand2[1]);
290         if($qstr!="/") {
291         $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
292         if($qstr=="/") {
293         $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
294         $sandis = $sandi + 1;
295         if($qstr!="/") {
296         if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
297         ++$sandi; } }
298 return $fileurl; }
299 $thisdir = dirname(realpath("Preindex.php"))."/";
300 // Get the Query String
301 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
302 { $pregqstr = preg_quote($qstr,"/");
303 $pregqsep = preg_quote($qsep,"/");
304 $oqstr = $qstr; $oqsep = $qsep;
305 if($fixhtml===true||$fixhtml==null) {
306 $qstr = htmlentities($qstr, ENT_QUOTES, $icharset);
307 $qsep = htmlentities($qsep, ENT_QUOTES, $icharset); }
308 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
309 $BoardQuery = "?".$OldBoardQuery;
310 return $BoardQuery; }
311 ?>