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-2007 Cool Dude 2k - http://intdb.sourceforge.net/
12 Copyright 2004-2007 Game Maker 2k - http://upload.idb.s1.jcink.com/
14 $FileInfo: functions.php - Last Update: 07/13/2007 SVN 42 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="functions.php"||$File3Name=="/functions.php") {
20 // Check the file names
21 function CheckFile($FileName) {
22 $File3Name = basename($_SERVER['SCRIPT_NAME']);
23 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
27 function CheckFiles($FileName) {
28 $File3Name = basename($_SERVER['SCRIPT_NAME']);
29 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
31 CheckFile("functions.php");
32 require($SettDir['misc']."compression.php");
33 if ($_GET['act']=="DeleteSession") { @session_destroy(); }
34 if ($_GET['act']=="ResetSession") { @session_unset(); }
35 if ($_GET['act']=="NewSessionID") { @session_regenerate_id(); }
37 if ($_GET['act']=="PHPInfo") { @phpinfo(); exit(); }
38 if ($_GET['act']=="phpinfo") { @phpinfo(); exit(); }
39 if ($_GET['act']=="PHPCredits") { @phpcredits(); exit(); }
40 if ($_GET['act']=="phpcredits") { @phpcredits(); exit(); }
41 */// Connect to mysql database
42 function ConnectMysql($sqlhost,$sqluser,$sqlpass,$sqldb) {
43 $StatSQL = @mysql_connect($sqlhost,$sqluser,$sqlpass);
44 $StatBase = @mysql_select_db($sqldb);
45 if (!$StatSQL) { return false; }
46 if (!$StatBase) { return false; }
48 $Names['RS'] = "Renee Sabonis";
49 define("_renee_", $Names['RS']);
50 // Change the title and gzip page
51 function change_title($new_title,$use_gzip="off",$gzip_type="gzip") {
53 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
54 $output = @ob_get_clean();
55 $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title>", $output);
56 /* Change Some PHP Settings Fix the &PHPSESSID to &PHPSESSID */
57 $SessName = @session_name();
58 $output = preg_replace("/&PHPSESSID/", "&PHPSESSID", $output);
59 $qstrcode = htmlentities($Settings['qstr']);
60 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
64 if($gzip_type=="gzip") {
65 $goutput = gzencode($output); }
66 if($gzip_type=="deflate") {
67 $goutput = gzcompress($output); }
69 // Fix amp => (&) to & and gzip page
70 function fix_amp($use_gzip="off",$gzip_type="gzip") {
72 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
73 $output = @ob_get_clean();
74 /* Change Some PHP Settings Fix the &PHPSESSID to &PHPSESSID */
75 $SessName = @session_name();
76 $output = preg_replace("/&PHPSESSID/", "&PHPSESSID", $output);
77 $qstrcode = htmlentities($Settings['qstr']);
78 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
82 if($gzip_type=="gzip") {
83 $goutput = gzencode($output); }
84 if($gzip_type=="deflate") {
85 $goutput = gzcompress($output); }
87 $output = @ob_get_clean();
88 $Names['RJ'] = "René Johnson";
89 define("_rene_", $Names['RJ']);
90 // GZip page for faster download
91 function gzip_page($use_gzip="off",$gzip_type="gzip") {
93 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
97 if($gzip_type=="gzip") {
98 $goutput = gzencode($output); }
99 if($gzip_type=="deflate") {
100 $goutput = gzcompress($output); }
102 $foo="bar"; $$foo="foo";
103 // SafeSQL Lite Source Code by Cool Dude 2k
104 // Make SQL Query's safe
105 function query($query_string,$query_vars) {
106 $query_array = array(array("%i","%I","%F","%S"),array("%d","%d","%f","%s"));
107 $query_string = str_replace($query_array[0], $query_array[1], $query_string);
108 if (get_magic_quotes_gpc()) {
109 $query_vars = array_map("stripslashes", $query_vars); }
110 $query_vars = array_map("mysql_real_escape_string", $query_vars);
111 $query_val = $query_vars;
112 $query_num = count($query_val);
114 while ($query_i < $query_num) {
115 $query_is = $query_i+1;
116 $query_val[$query_is] = $query_vars[$query_i];
118 $query_val[0] = $query_string;
119 return call_user_func_array("sprintf",$query_val); }
120 // Kill bad vars for some functions
121 function killbadvars($varname) {
122 $badphp1 = array('$'); $badphp2 = array(null);
123 $varname = str_replace($badphp1, $badphp2, $varname);
124 $varname = preg_replace("/(_SERVER|_ENV|_COOKIE|_SESSION)/i", null, $varname);
125 $varname = preg_replace("/(_GET|_POST|_FILES|_REQUEST|GLOBALS)/i", null, $varname);
126 $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
127 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
128 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
130 // Change the text to icons(smileys)
131 function text2icons($Text,$sqlt) {
133 $reneequery=query("select * from `".$sqlt."smileys`", array(null));
134 $reneeresult=mysql_query($reneequery);
135 $reneenum=mysql_num_rows($reneeresult);
137 while ($renees < $reneenum) {
138 $FileName=mysql_result($reneeresult,$renees,"FileName");
139 $SmileName=mysql_result($reneeresult,$renees,"SmileName");
140 $SmileText=mysql_result($reneeresult,$renees,"SmileText");
141 $SmileDirectory=mysql_result($reneeresult,$renees,"Directory");
142 $ShowSmile=mysql_result($reneeresult,$renees,"Show");
143 $ReplaceType=mysql_result($reneeresult,$renees,"ReplaceCI");
144 if($ReplaceType=="on") { $ReplaceType = "yes"; }
145 if($ReplaceType=="off") { $ReplaceType = "no"; }
146 if($ReplaceType!="yes"||$ReplaceType!="no") { $ReplaceType = "no"; }
147 $Smile1 = $SmileText;
148 $Smile2 = '<img src="'.$SmileDirectory.''.$FileName.'" style="vertical-align: middle; border: 0px;" title="'.$SmileName.'" alt="'.$SmileName.'" />';
149 if($ReplaceType=="no") {
150 $Text = str_replace($Smile1, $Smile2, $Text); }
151 if($ReplaceType=="yes") {
152 $Smile1 = preg_quote($SmileText,"/");
153 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
154 ++$renees; } return $Text; }
155 // Remove the bad stuff
156 function remove_spaces($Text) {
157 $Text = preg_replace("/(^\t+|\t+$)/","",$Text);
158 $Text = preg_replace("/(^\n+|\n+$)/","",$Text);
159 $Text = preg_replace("/(^\r+|\r+$)/","",$Text);
160 $Text = preg_replace("/(\r|\n|\t)+/"," ",$Text);
161 $Text = preg_replace("/\s\s+/"," ",$Text);
162 $Text = preg_replace("/(^\s+|\s+$)/","",$Text);
165 function fixbamps($text) {
166 $fixamps1 = array("&copy;","&reg;","&trade;","&quot;","&amp;","&lt;","&gt;","&(a|e|i|o|u|y)acute;","&(a|e|i|o|u)grave;","&(a|e|i|o|u)circ;","&(a|e|i|o|u|y)uml;","&(a|o|n)tilde;","&aring;","&aelig;","&ccedil;","&eth;","&oslash;","&szlig;","&thorn;");
167 $fixamps2 = array("©","®","™",""","&","<",">","&\\1acute;","&\\1grave;","&\\1circ;","&\\1uml;","&\\1tilde;","å","æ","ç","ð","ø","ß","þ");
168 $ampnum = count($fixamps1); $ampi=0;
169 while ($ampi < $ampnum) {
170 $text = preg_replace("/".$fixamps1[$ampi]."/i", $fixamps2[$ampi], $text);
172 $text = preg_replace("/&#(x[a-f0-9]+|[0-9]+);/i", "&#$1;", $text);
174 // Get next id for stuff
175 function getnextid($tablepre,$table) {
176 $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
177 $getnextidr = mysql_query($getnextidq);
178 $getnextid = mysql_fetch_assoc($getnextidr);
179 return $getnextid['Auto_increment'];
180 @mysql_free_result($getnextidr); }
181 $Names['RSA'] = "Rachel Sabonis";
182 define("_rachel_", $Names['RSA']);
183 // Redirect to another file with ether timed or nontimed redirect
184 function redirects($type,$url,$time=0) {
185 if($type!="location"&&
188 if($type=="refresh") {
189 header("Refresh: ".$time."; URL=".$url); }
190 if($type=="location") {
191 header("Location: ".$url); }
193 // Start a xml document
194 function xml_tag_make($type,$attbs,$retval=false) {
195 $renee1 = explode("&",$attbs);
196 $reneenum=count($renee1);
197 $reneei=0; $attblist = null;
198 while ($reneei < $reneenum) {
199 $renee2 = explode("=",$renee1[$reneei]);
200 if($renee2[0]!=null||$renee2[1]!=null) {
201 $attblist = $attblist.' '.$renee2[0].'="'.$renee2[1].'"'; }
203 if($retval!=false&&$retval!=true) { $retval=false; }
205 echo '<?'.$type.$attblist.'?>'."\n"; }
207 return '<?'.$type.$attblist.'?>'."\n"; } }
208 // Start a xml document (old version)
209 function xml_doc_start($ver,$encode,$retval=false) {
211 echo xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); }
213 return xml_tag_make('xml','version='.$ver.'&encoding='.$encode,true); } }
214 // Change Time Stamp to a readable time
215 function GMTimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
216 $TCHour = date("H",$timestamp);
217 $TCMinute = date("i",$timestamp);
218 $TCSecond = date("s",$timestamp);
219 $TCMonth = date("n",$timestamp);
220 $TCDay = date("d",$timestamp);
221 $TCYear = date("Y",$timestamp);
222 unset($dstake); $dstake = null;
223 if(!is_numeric($minoffset)) { $minoffset = "00"; }
224 $ts_array = explode(":",$offset);
225 if(count($ts_array)!=2) {
226 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
227 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
228 $offset = $ts_array[0].":".$ts_array[1]; }
229 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
230 if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
231 if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
232 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
233 if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
234 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
235 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
236 //$tsa['minute'] = $tsa['minute'] + $minoffset;
237 if($dst!="on"&&$dst!="off") { $dst = "off"; }
238 if($dst=="on") { if($dstake!="done") {
239 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
240 $TCHour = $TCHour + $tsa['hour'];
241 $TCMinute = $TCMinute + $tsa['minute'];
242 return date($format,mktime($TCHour,$TCMinute,$TCSecond,$TCMonth,$TCDay,$TCYear)); }
243 $Names['CK'] = "Christine";
244 define("_christine_", $Names['CK']);
245 // Change Time Stamp to a readable time
246 function TimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
247 return GMTimeChange($format,$timestamp,$offset,$minoffset,$dst); }
248 // Make a GMT Time Stamp
249 function GMTimeStamp() {
250 $GMTHour = gmdate("H");
251 $GMTMinute = gmdate("i");
252 $GMTSecond = gmdate("s");
253 $GMTMonth = gmdate("n");
254 $GMTDay = gmdate("d");
255 $GMTYear = gmdate("Y");
256 return mktime($GMTHour,$GMTMinute,$GMTSecond,$GMTMonth,$GMTDay,$GMTYear); }
257 function GMTimeStampS() { return time() - date('Z', time()); }
258 function GMTimeGet($format,$offset,$minoffset=null,$dst=null) {
259 return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); }
260 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
261 unset($dstake); $dstake = null;
262 if(!is_numeric($offset)) { $offset = "0"; }
263 if(!is_numeric($minoffset)) { $minoffset = "00"; }
264 $ts_array = explode(":",$offset);
265 if(count($ts_array)!=2) {
266 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
267 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
268 $offset = $ts_array[0].":".$ts_array[1]; }
269 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
270 if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
271 if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
272 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
273 if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
274 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
275 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
276 //$tsa['minute'] = $tsa['minute'] + $minoffset;
277 if($dst!="on"&&$dst!="off") { $dst = "off"; }
278 if($dst=="on") { if($dstake!="done") {
279 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
280 return date($format,mktime(gmdate('h')+$tsa['hour'],gmdate('i')+$tsa['minute'],gmdate('s'),gmdate('n'),gmdate('j'),gmdate('Y'))); }
282 function GetSeverZone() {
283 $TestHour1 = date("H");
284 @putenv("OTZ=".@getenv("TZ"));
286 $TestHour2 = date("H");
287 @putenv("TZ=".@getenv("OTZ"));
288 $TestHour3 = $TestHour1-$TestHour2;
290 function SeverOffSet() {
291 $TestHour1 = date("H");
292 $TestHour2 = gmdate("H");
293 $TestHour3 = $TestHour1-$TestHour2;
295 function SeverOffSetNew() {
296 return gmdate("g",mktime(0,date("Z"))); }
297 function gmtime() { return time() - (int) date('Z'); }
298 function file_get_source($filename,$return = FALSE) {
299 // Acts like highlight_file();
300 $phpsrc = file_get_contents($filename);
301 $phpsrcs = highlight_string($phpsrc,$return);
303 function valid_get_source($filename) {
304 $phpsrcs = file_get_source($filename,TRUE);
305 // Change font tag to span tag for valid xhtml
306 $phpsrcs = preg_replace("/\<font color=\"(.*?)\"\>/i", "<span style=\"color: \\1;\">", $phpsrcs);
307 $phpsrcs = preg_replace("/\<\/font>/i", "</span>", $phpsrcs);
309 function GetUserName($idu,$sqlt) {
310 $gunquery = query("select * from `".$sqlt."members` where `id`=%i", array($idu));
311 $gunresult=mysql_query($gunquery);
312 $gunnum=mysql_num_rows($gunresult);
314 $UsersName=mysql_result($gunresult,$gunnum-1,"Name"); }
315 @mysql_free_result($gunresult);
317 // hmac hash function
318 function hmac($data,$key,$hash='sha1',$blocksize=64) {
319 if (strlen($key)>$blocksize) {
320 $key=pack('H*',$hash($key)); }
321 $key=str_pad($key, $blocksize, chr(0x00));
322 $ipad=str_repeat(chr(0x36),$blocksize);
323 $opad=str_repeat(chr(0x5c),$blocksize);
324 return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); }
325 // b64hmac hash function
326 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
327 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
328 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
329 // salt hmac hash function
330 function salt_hmac($size1=4,$size2=6) {
331 $hprand = rand(4,6); $i = 0; $hpass = "";
332 while ($i < $hprand) {
333 $hspsrand = rand(1,2);
334 if($hspsrand!=1&&$hspsrand!=2) { $hspsrand=1; }
335 if($hspsrand==1) { $hpass .= chr(rand(48,57)); }
336 if($hspsrand==2) { $hpass .= chr(rand(65,70)); }
337 ++$i; } return $hpass; }
338 /* is_empty by M at http://us2.php.net/manual/en/function.empty.php#74093 */
339 function is_empty($var) {
340 if (((is_null($var) || rtrim($var) == "") &&
341 $var !== false) || (is_array($var) && empty($var))) {
342 return true; } else { return false; } }
343 // Hash two times with md5 and sha1
344 function PassHash2x($Text) {
348 // Hash two times with hmac-md5 and hmac-sha1
349 function PassHash2x2($data,$key,$extdata,$blocksize=64) {
350 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
351 $Text = hmac($data,$key,"md5").$extdata;
352 $Text = hmac($Text,$key,"sha1").$extdata;
353 return base64_encode($Text); }
354 function cp($infile,$outfile,$mode="w") {
355 $contents = file_get_contents($infile);
356 $cpfp = fopen($outfile,$mode);
357 fwrite($cpfp, $contents);
360 /* str_ireplace for PHP below ver. 5 updated //
361 // by René Johnson - Cool Dude 2k //
362 // and upaded by René Johnson again */
363 if(!function_exists('str_ireplace')) {
364 function str_ireplace($search,$replace,$subject) {
365 if(!is_array($search)&&is_array($replace)) {
366 $search = array($search); }
367 if(is_array($search)&&!is_array($replace)) {
368 $replace = array($replace); }
369 if(is_array($search)&&is_array($replace)) {
370 $sc=count($search); $rc=count($replace); $sn=0;
371 if($sc!=$rc) { return false; }
373 $search[$sn] = preg_quote($search[$sn], "/");
374 $subject = preg_replace("/".$search[$sn]."/i", $replace[$sn], $subject);
376 if(!is_array($search)&&!is_array($replace)) {
377 $search = preg_quote($search, "/");
378 $subject = preg_replace("/".$search."/i", $replace, $subject); }
380 $foobar="fubar"; $$foobar="foobar";
382 function dump_included_files() { return var_dump(get_included_files()); }
383 function count_included_files() { return count(get_included_files()); }
384 function dump_extensions() { return var_dump(get_loaded_extensions()); }
385 function count_extensions() { return count(get_loaded_extensions()); }