OSDN Git Service

Some more runtime errors fixed. (PHP Notice errors)
[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-2007 Cool Dude 2k - http://intdb.sourceforge.net/
12     Copyright 2004-2007 Game Maker 2k - http://upload.idb.s1.jcink.com/
13
14     $FileInfo: function.php - Last Update: 06/14/2007 SVN 23 - 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));
24 @ini_set("arg_separator.input",$Settings['qstr']);
25 @ini_set("arg_separator",htmlentities($Settings['qstr'], ENT_QUOTES)); }
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 if(dirname($_SERVER['SCRIPT_NAME'])!="."||
31         dirname($_SERVER['SCRIPT_NAME'])!=null) {
32 $basedir = dirname($_SERVER['SCRIPT_NAME'])."/"; }
33 if($basedir==null||$basedir==".") {
34 if(dirname($_SERVER['SCRIPT_NAME'])=="."||
35         dirname($_SERVER['SCRIPT_NAME'])==null) {
36 $basedir = dirname($_SERVER['PHP_SELF'])."/"; } }
37 if($basedir=="\/") { $basedir="/"; }
38 $basedir = str_replace("//", "/", $basedir);
39 if($Settings['fixbasedir']!=null&&$Settings['fixbasedir']!="") {
40                 $basedir = $Settings['fixbasedir']; }
41 $BaseURL = $basedir;
42 // Get our Host Name and Referer URL's Host Name
43 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
44 $REFERERurl = parse_url($_SERVER['HTTP_REFERER']);
45 if(!isset($REFERERurl['host'])) { $REFERERurl['host'] = null; }
46 $URL['REFERER'] = $REFERERurl['host'];
47 $URL['HOST'] = $_SERVER["SERVER_NAME"];
48 $REFERERurl = null; unset($REFERERurl);
49 function qstring($qstr=";",$qsep="=")
50 { $_GET = null; $_GET = array();
51 if (!isset($_SERVER['QUERY_STRING'])) {
52 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); }
53 @ini_get("arg_separator.input", $qstr);
54 $_SERVER['QUERY_STRING'] = urldecode($_SERVER['QUERY_STRING']);
55 $preqs = explode($qstr,$_SERVER["QUERY_STRING"]);
56 $qsnum = count($preqs); $qsi = 0;
57 while ($qsi < $qsnum) {
58 $preqst = explode($qsep,$preqs[$qsi],2);
59 $fix1 = array(" ",'$'); $fix2  = array("_","_");
60 $preqst[0] = str_replace($fix1, $fix2, $preqst[0]);
61 $preqst[0] = killbadvars($preqst[0]);
62 if($preqst[0]!=null) {
63 $_GET[$preqst[0]] = $preqst[1]; }
64 ++$qsi; } return true; }
65 if($_SERVER['PATH_INFO']==null) {
66         if(@getenv('PATH_INFO')!=null&&@getenv('PATH_INFO')!="1") {
67 $_SERVER['PATH_INFO'] = @getenv('PATH_INFO'); }
68 if(@getenv('PATH_INFO')==null) {
69 $myscript = $_SERVER["SCRIPT_NAME"];
70 $myphpath = $_SERVER["PHP_SELF"];
71 $mypathinfo = str_replace($myscript, "", $myphpath);
72 @putenv("PATH_INFO=".$mypathinfo); } }
73 function mrstring() {
74 $urlvar = explode('/',$_SERVER['PATH_INFO']);
75 $num=count($urlvar); $i=1;
76 while ($i <= $num) {
77 //$urlvar[$i] = urldecode($urlvar[$i]);
78 if(!isset($_GET[$urlvar[$i]])) { $_GET[$urlvar[$i]] = null; }
79 if(!isset($urlvar[$i])) { $urlvar[$i] = null; }
80 if($_GET[$urlvar[$i]]==null&&$urlvar[$i]!=null) {
81 $fix1 = array(" ",'$'); $fix2  = array("_","_");
82 $urlvar[$i] = str_replace($fix1, $fix2, $urlvar[$i]);
83 $urlvar[$i] = killbadvars($urlvar[$i]);
84         $_GET[$urlvar[$i]] = $urlvar[$i+1]; }
85 ++$i; ++$i; } return true; }
86 function redirect($type,$file,$time=0,$url=null,$dbsr=true)
87 {
88 if($type!="location"&&
89         $type!="refresh") {
90         $type=="location"; }
91 if($url!=null) {
92 $file = $url.$file; }
93 if($dbsr==true) {
94 $file = str_replace("//", "/", $file); }
95 if($type=="refresh") {
96 header("Refresh: ".$time."; URL=".$file); }
97 if($type=="location") {
98 @session_write_close();
99 header("Location: ".$file); }
100 return true; }
101 function url_maker($file,$ext,$qvarstr=null,$qstr=";",$qsep="=",$prexqstr=null,$exqstr=null,$fixhtml=true) {
102 $fileurl = null;
103 if($ext==null) { $ext = ".php"; } 
104 if($ext=="noext"||$ext=="no ext"||$ext=="no+ext") { $ext = null; }
105 $file = $file.$ext;
106 if($qvarstr==null) { $fileurl = $file; }
107 if($fixhtml==true) {
108 $qstr = htmlentities($qstr, ENT_QUOTES);
109 $qsep = htmlentities($qsep, ENT_QUOTES); }
110 if($prexqstr!=null) { 
111 $rene1 = explode("&",$prexqstr);
112 $renenum=count($rene1);
113 $renei=0;
114 $reneqstr = "index.php?";
115 if($qstr!="/") { $fileurl = $file."?"; }
116 if($qstr=="/") { $fileurl = $file."/"; }
117 while ($renei < $renenum) {
118         $rene2 = explode("=",$rene1[$renei]);
119         $rene2[0] = urlencode($rene2[0]);
120         $rene2[1] = urlencode($rene2[1]);
121         if($qstr!="/") {
122         $fileurl = $fileurl.$rene2[0].$qsep.$rene2[1]; }
123         if($qstr=="/") {
124         $fileurl = $fileurl.$rene2[0]."/".$rene2[1]."/"; }
125         $reneis = $renei + 1;
126         if($qstr!="/") {
127         if($reneis < $renenum) { $fileurl = $fileurl.$qstr; } }
128         ++$renei; } }
129 if($qvarstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
130 if($qvarstr!=null) { 
131 if($prexqstr==null) {
132 if($qstr!="/") { $fileurl = $file."?"; }
133 if($qstr=="/") { $fileurl = $file."/"; } }
134 $cind1 = explode("&",$qvarstr);
135 $cindnum=count($cind1);
136 $cindi=0;
137 $cindqstr = "index.php?";
138 while ($cindi < $cindnum) {
139         $cind2 = explode("=",$cind1[$cindi]);
140         $cind2[0] = urlencode($cind2[0]);
141         $cind2[1] = urlencode($cind2[1]);
142         if($qstr!="/") {
143         $fileurl = $fileurl.$cind2[0].$qsep.$cind2[1]; }
144         if($qstr=="/") {
145         $fileurl = $fileurl.$cind2[0]."/".$cind2[1]."/"; }
146         $cindis = $cindi + 1;
147         if($qstr!="/") {
148         if($cindis < $cindnum) { $fileurl = $fileurl.$qstr; } }
149         ++$cindi; } }
150 if($exqstr!=null&&$qstr!="/") { $fileurl = $fileurl.$qstr; }
151 if($exqstr!=null) { 
152 if($qvarstr==null&&$prexqstr==null) {
153 if($qstr!="/") { $fileurl = $file."?"; }
154 if($qstr=="/") { $fileurl = $file."/"; } }
155 $sand1 = explode("&",$exqstr);
156 $sanum=count($sand1);
157 $sandi=0;
158 $sandqstr = "index.php?";
159 while ($sandi < $sanum) {
160         $sand2 = explode("=",$sand1[$sandi]);
161         $sand2[0] = urlencode($sand2[0]);
162         $sand2[1] = urlencode($sand2[1]);
163         if($qstr!="/") {
164         $fileurl = $fileurl.$sand2[0].$qsep.$sand2[1]; }
165         if($qstr=="/") {
166         $fileurl = $fileurl.$sand2[0]."/".$sand2[1]."/"; }
167         $sandis = $sandi + 1;
168         if($qstr!="/") {
169         if($sandis < $sanum) { $fileurl = $fileurl.$qstr; } }
170         ++$sandi; } }
171 return $fileurl; }
172 $thisdir = dirname(realpath("Preindex.php"))."/";
173 function GetQueryStr($qstr=";",$qsep="=",$fixhtml=true)
174 { $pregqstr = preg_quote($qstr,"/");
175 $pregqsep = preg_quote($qsep,"/");
176 $oqstr = $qstr; $oqsep = $qsep;
177 if($fixhtml==true||$fixhtml==null) {
178 $qstr = htmlentities($qstr, ENT_QUOTES);
179 $qsep = htmlentities($qsep, ENT_QUOTES); }
180 $OldBoardQuery = preg_replace("/".$pregqstr."/isxS", $qstr, $_SERVER['QUERY_STRING']);
181 $BoardQuery = "?".$OldBoardQuery;
182 return $BoardQuery; }
183 ?>