Yet another small update.
[iDB.git] / inc / misc / functions.php
blob8dc8dc50da6d7f7ee536856d897e1807a5c78e07
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.
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-2011 iDB Support - http://idb.berlios.de/
12 Copyright 2004-2011 Game Maker 2k - http://gamemaker2k.org/
14 $FileInfo: functions.php - Last Update: 03/01/2011 SVN 625 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="functions.php"||$File3Name=="/functions.php") {
18 require('index.php');
19 exit(); }
20 // Check the file names
21 function CheckFile($FileName) {
22 $File3Name = basename($_SERVER['SCRIPT_NAME']);
23 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
24 require('index.php');
25 exit(); }
26 return null; }
27 function CheckFiles($FileName) {
28 $File3Name = basename($_SERVER['SCRIPT_NAME']);
29 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
30 return true; } }
31 CheckFile("functions.php");
32 require($SettDir['misc']."compression.php");
33 if($Settings['sqltype']=="mysql") {
34 require($SettDir['sql']."mysql.php"); }
35 if($Settings['sqltype']=="mysqli") {
36 require($SettDir['sql']."mysqli.php"); }
37 if($Settings['sqltype']=="pgsql") {
38 require($SettDir['sql']."pgsql.php"); }
39 if($Settings['sqltype']=="sqlite") {
40 require($SettDir['sql']."sqlite.php"); }
41 require($SettDir['misc']."useragents.php");
42 /*
43 if ($_GET['act']=="DeleteSession") { session_destroy(); }
44 if ($_GET['act']=="ResetSession") { session_unset(); }
45 if ($_GET['act']=="NewSessionID") { session_regenerate_id(); }
46 if ($_GET['act']=="PHPInfo") { phpinfo(); exit(); }
47 if ($_GET['act']=="phpinfo") { phpinfo(); exit(); }
48 if ($_GET['act']=="PHPCredits") { phpcredits(); exit(); }
49 if ($_GET['act']=="phpcredits") { phpcredits(); exit(); }
51 // Renee Marilyn Sabonis is the best ever. ^_^
52 $Names['RS'] = "Renee Sabonis";
53 define("_renee_", $Names['RS']);
54 $CD2k_Loves="Renee Sabonis"; $I_Love="Renee Sabonis";
55 // Change the title and gzip page
56 function change_title($new_title,$use_gzip="off",$gzip_type="gzip") {
57 global $Settings;
58 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
59 $output = ob_get_clean();
60 $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title>", $output);
61 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
62 $SessName = session_name();
63 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
64 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
65 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
66 if($use_gzip!="on") {
67 echo $output; }
68 if($use_gzip=="on") {
69 if($gzip_type=="gzip") {
70 $goutput = gzencode($output); }
71 if($gzip_type=="deflate") {
72 $goutput = gzcompress($output); }
73 echo $goutput; } }
74 // Fix amp => (&) to &amp; and gzip page
75 function fix_amp($use_gzip="off",$gzip_type="gzip") {
76 global $Settings;
77 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
78 $output = ob_get_clean();
79 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
80 $SessName = session_name();
81 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
82 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
83 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
84 if($use_gzip!="on") {
85 echo $output; }
86 if($use_gzip=="on") {
87 if($gzip_type=="gzip") {
88 $goutput = gzencode($output); }
89 if($gzip_type=="deflate") {
90 $goutput = gzcompress($output); }
91 echo $goutput; } }
92 $Names['RJ'] = "Rene Johnson";
93 define("_rene_", $Names['RJ']);
94 // GZip page for faster download
95 function gzip_page($use_gzip="off",$gzip_type="gzip") {
96 global $Settings;
97 $output = ob_get_clean();
98 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
99 if($use_gzip!="on") {
100 echo $output; }
101 if($use_gzip=="on") {
102 if($gzip_type=="gzip") {
103 $goutput = gzencode($output); }
104 if($gzip_type=="deflate") {
105 $goutput = gzcompress($output); }
106 echo $goutput; } }
107 $foo="bar"; $$foo="foo";
108 $Names['KSP'] = "Kazuki Suzuki Przyborowski";
109 define("_kazuki_", $Names['KSP']);
110 // Kill bad vars for some functions
111 function killbadvars($varname) {
112 $badphp1 = array('$'); $badphp2 = array(null);
113 $varname = str_replace($badphp1, $badphp2, $varname);
114 $varname = preg_replace("/(_SERVER|_ENV|_COOKIE|_SESSION)/i", null, $varname);
115 $varname = preg_replace("/(_GET|_POST|_FILES|_REQUEST|GLOBALS)/i", null, $varname);
116 $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
117 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
118 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
119 return $varname; }
120 // Trying to fix this bug. ^_^
121 // http://xforce.iss.net/xforce/xfdb/49697
122 if(!isset($Settings['DefaultTheme'])) {
123 $Settings['DefaultTheme'] = "iDB"; }
124 // Change the text to icons(smileys)
125 function text2icons($Text,$sqlt,$link=null) {
126 global $SQLStat;
127 if(!isset($link)) { $link = $SQLStat; }
128 $reneequery=sql_pre_query("SELECT * FROM \"".$sqlt."smileys\"", array(null));
129 $reneeresult=sql_query($reneequery,$link);
130 $reneenum=sql_num_rows($reneeresult);
131 $renees=0;
132 while ($renees < $reneenum) {
133 $FileName=sql_result($reneeresult,$renees,"FileName");
134 $SmileName=sql_result($reneeresult,$renees,"SmileName");
135 $SmileText=sql_result($reneeresult,$renees,"SmileText");
136 $SmileDirectory=sql_result($reneeresult,$renees,"Directory");
137 $ShowSmile=sql_result($reneeresult,$renees,"Display");
138 $ReplaceType=sql_result($reneeresult,$renees,"ReplaceCI");
139 if($ReplaceType=="on") { $ReplaceType = "yes"; }
140 if($ReplaceType=="off") { $ReplaceType = "no"; }
141 if($ReplaceType!="yes"||$ReplaceType!="no") { $ReplaceType = "no"; }
142 $Smile1 = $SmileText;
143 $Smile2 = '<img src="'.$SmileDirectory.''.$FileName.'" style="vertical-align: middle; border: 0px;" title="'.$SmileName.'" alt="'.$SmileName.'" />';
144 if($ReplaceType=="no") {
145 $Text = str_replace($Smile1, $Smile2, $Text); }
146 if($ReplaceType=="yes") {
147 $Smile1 = preg_quote($SmileText,"/");
148 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
149 ++$renees; } return $Text; }
150 // Removes the bad stuff
151 function remove_bad_entities($Text) {
152 //HTML Entities Dec Version
153 $Text = preg_replace("/&#8238;/isU","",$Text);
154 $Text = preg_replace("/&#8194;/isU","",$Text);
155 $Text = preg_replace("/&#8195;/isU","",$Text);
156 $Text = preg_replace("/&#8201;/isU","",$Text);
157 $Text = preg_replace("/&#8204;/isU","",$Text);
158 $Text = preg_replace("/&#8205;/isU","",$Text);
159 $Text = preg_replace("/&#8206;/isU","",$Text);
160 $Text = preg_replace("/&#8207;/isU","",$Text);
161 //HTML Entities Hex Version
162 $Text = preg_replace("/&#x202e;/isU","",$Text);
163 $Text = preg_replace("/&#x2002;/isU","",$Text);
164 $Text = preg_replace("/&#x2003;/isU","",$Text);
165 $Text = preg_replace("/&#x2009;/isU","",$Text);
166 $Text = preg_replace("/&#x200c;/isU","",$Text);
167 $Text = preg_replace("/&#x200d;/isU","",$Text);
168 $Text = preg_replace("/&#x200e;/isU","",$Text);
169 $Text = preg_replace("/&#x200f;/isU","",$Text);
170 //HTML Entities Name Version
171 $Text = preg_replace("/&ensp;/isU","",$Text);
172 $Text = preg_replace("/&emsp;/isU","",$Text);
173 $Text = preg_replace("/&thinsp;/isU","",$Text);
174 $Text = preg_replace("/&zwnj;/isU","",$Text);
175 $Text = preg_replace("/&zwj;/isU","",$Text);
176 $Text = preg_replace("/&lrm;/isU","",$Text);
177 $Text = preg_replace("/&rlm;/isU","",$Text);
178 return $Text; }
179 // Remove the bad stuff
180 function remove_spaces($Text) {
181 $Text = preg_replace("/(^\t+|\t+$)/","",$Text);
182 $Text = preg_replace("/(^\n+|\n+$)/","",$Text);
183 $Text = preg_replace("/(^\r+|\r+$)/","",$Text);
184 $Text = preg_replace("/(\r|\n|\t)+/"," ",$Text);
185 $Text = preg_replace("/\s\s+/"," ",$Text);
186 $Text = preg_replace("/(^\s+|\s+$)/","",$Text);
187 $Text = remove_bad_entities($Text);
188 return $Text; }
189 // Fix some chars
190 function fixbamps($text) {
191 $fixamps1 = array("&amp;copy;","&amp;reg;","&amp;trade;","&amp;quot;","&amp;amp;","&amp;lt;","&amp;gt;","&amp;(a|e|i|o|u|y)acute;","&amp;(a|e|i|o|u)grave;","&amp;(a|e|i|o|u)circ;","&amp;(a|e|i|o|u|y)uml;","&amp;(a|o|n)tilde;","&amp;aring;","&amp;aelig;","&amp;ccedil;","&amp;eth;","&amp;oslash;","&amp;szlig;","&amp;thorn;");
192 $fixamps2 = array("&copy;","&reg;","&trade;","&quot;","&amp;","&lt;","&gt;","&\\1acute;","&\\1grave;","&\\1circ;","&\\1uml;","&\\1tilde;","&aring;","&aelig;","&ccedil;","&eth;","&oslash;","&szlig;","&thorn;");
193 $ampnum = count($fixamps1); $ampi=0;
194 while ($ampi < $ampnum) {
195 $text = preg_replace("/".$fixamps1[$ampi]."/i", $fixamps2[$ampi], $text);
196 ++$ampi; }
197 $text = preg_replace("/&amp;#(x[a-f0-9]+|[0-9]+);/i", "&#$1;", $text);
198 return $text; }
199 $Names['K'] = "Katarzyna";
200 define("_katarzyna_", $Names['K']);
201 $utshour = $dayconv['hour'];
202 $utsminute = $dayconv['minute'];
203 // Change Time Stamp to a readable time
204 function GMTimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
205 global $utshour,$utsminute;
206 $dstake = null;
207 if(!is_numeric($minoffset)) { $minoffset = "00"; }
208 $ts_array = explode(":",$offset);
209 if(count($ts_array)!=2) {
210 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
211 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
212 $offset = $ts_array[0].":".$ts_array[1]; }
213 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
214 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
215 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
216 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
217 //$tsa['minute'] = $tsa['minute'] + $minoffset;
218 if($dst!="on"&&$dst!="off") { $dst = "off"; }
219 if($dst=="on") { if($dstake!="done") {
220 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
221 $utimestamp = $tsa['hour'] * $utshour;
222 $utimestamp = $utimestamp + $tsa['minute'] * $utsminute;
223 $utimestamp = $utimestamp + $minoffset * $utsminute;
224 $timestamp = $timestamp + $utimestamp;
225 return date($format,$timestamp); }
226 $Names['SB'] = "Stephanie Braun";
227 define("_stephanie_", $Names['SB']);
228 // Change Time Stamp to a readable time
229 function TimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
230 return GMTimeChange($format,$timestamp,$offset,$minoffset,$dst); }
231 // Make a GMT Time Stamp
232 function GMTimeStamp() {
233 $GMTHour = gmdate("H");
234 $GMTMinute = gmdate("i");
235 $GMTSecond = gmdate("s");
236 $GMTMonth = gmdate("n");
237 $GMTDay = gmdate("d");
238 $GMTYear = gmdate("Y");
239 return mktime($GMTHour,$GMTMinute,$GMTSecond,$GMTMonth,$GMTDay,$GMTYear); }
240 // Make a GMT Time Stamp alt version
241 function GMTimeStampS() { return time() - date('Z', time()); }
242 // Get GMT Time
243 function GMTimeGet($format,$offset,$minoffset=null,$dst=null) {
244 return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); }
245 // Get GMT Time alt version
246 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
247 global $utshour,$utsminute;
248 $dstake = null;
249 if(!is_numeric($offset)) { $offset = "0"; }
250 if(!is_numeric($minoffset)) { $minoffset = "00"; }
251 $ts_array = explode(":",$offset);
252 if(count($ts_array)!=2) {
253 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
254 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
255 $offset = $ts_array[0].":".$ts_array[1]; }
256 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
257 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
258 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
259 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
260 //$tsa['minute'] = $tsa['minute'] + $minoffset;
261 if($dst!="on"&&$dst!="off") { $dst = "off"; }
262 if($dst=="on") { if($dstake!="done") {
263 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
264 $utimestamp = $tsa['hour'] * $utshour;
265 $utimestamp = $utimestamp + $tsa['minute'] * $utsminute;
266 $utimestamp = $utimestamp + $minoffset * $utsminute;
267 $timestamp = $timestamp + $utimestamp;
268 return date($format,mktime()+$timestamp); }
269 $Names['StB'] = "Stevie Braun";
270 define("_stevie_", $Names['StB']);
271 // Get Server offset
272 function GetSeverZone() {
273 $TestHour1 = date("H");
274 @putenv("OTZ=".getenv("TZ"));
275 @putenv("TZ=GMT");
276 $TestHour2 = date("H");
277 @putenv("TZ=".getenv("OTZ"));
278 $TestHour3 = $TestHour1-$TestHour2;
279 return $TestHour3; }
280 // Get Server offset alt version
281 function SeverOffSet() {
282 $TestHour1 = date("H");
283 $TestHour2 = gmdate("H");
284 $TestHour3 = $TestHour1-$TestHour2;
285 return $TestHour3; }
286 // Get Server offset new version
287 function SeverOffSetNew() {
288 return gmdate("g",mktime(0,date("Z"))); }
289 function gmtime() { return time() - (int) date('Z'); }
290 // Acts like highlight_file();
291 function file_get_source($filename,$return = FALSE) {
292 $phpsrc = file_get_contents($filename);
293 $phpsrcs = highlight_string($phpsrc,$return);
294 return $phpsrcs; }
295 // Also acts like highlight_file(); but valid xhtml
296 function valid_get_source($filename) {
297 $phpsrcs = file_get_source($filename,TRUE);
298 // Change font tag to span tag for valid xhtml
299 $phpsrcs = preg_replace("/\<font color=\"(.*?)\"\>/i", "<span style=\"color: \\1;\">", $phpsrcs);
300 $phpsrcs = preg_replace("/\<\/font>/i", "</span>", $phpsrcs);
301 return $phpsrcs; }
302 // Check to see if the user is hidden/shy/timid. >_> | ^_^ | <_<
303 function GetUserName($idu,$sqlt,$link=null) { $UsersName = null;
304 global $SQLStat;
305 if(!isset($link)) { $link = $SQLStat; }
306 $gunquery = sql_pre_query("SELECT * FROM \"".$sqlt."members\" WHERE \"id\"=%i LIMIT 1", array($idu));
307 $gunresult=sql_query($gunquery,$link);
308 $gunnum=sql_num_rows($gunresult);
309 // I'm now hidden from you. ^_^ | <_< I cant find you.
310 $UsersHidden = "yes";
311 if($gunnum>0){
312 $UsersName=sql_result($gunresult,0,"Name");
313 // Am i still hidden. o_O <_< I can see you.
314 $UsersHidden=sql_result($gunresult,0,"HiddenMember"); }
315 sql_free_result($gunresult);
316 $UsersInfo['Name'] = $UsersName;
317 $UsersInfo['Hidden'] = $UsersHidden;
318 return $UsersInfo; }
319 if(!function_exists('hash_hmac')) {
320 function hash_hmac($algo, $data, $key, $raw_output = false) {
321 $blocksize = 64;
322 if (strlen($key)>$blocksize) {
323 if (function_exists('hash')) {
324 $key=pack('H*',hash($hash, $key)); }
325 if (!function_exists('hash')) {
326 $key=pack('H*',$hash($key)); } }
327 $key=str_pad($key, $blocksize, chr(0x00));
328 $ipad=str_repeat(chr(0x36),$blocksize);
329 $opad=str_repeat(chr(0x5c),$blocksize);
330 return hash($algo, ($key^$opad).pack('H*',hash($algo, ($key^$ipad).$data))); } }
331 if(!function_exists('hash')) {
332 function hash($algo, $data, $raw_output = false) {
333 if($algo!="md5"&&$algo!="sha1") { $algo = "md5"; }
334 return $algo($data); } }
335 if(!function_exists('hash_algos')) {
336 function hash_algos() {
337 return array(0 => "md5", 1 => "sha1"); } }
338 // hmac hash function
339 function hmac($data,$key,$hash='sha1',$blocksize=64) {
340 if (!function_exists('hash_hmac')) {
341 if (strlen($key)>$blocksize) {
342 if (function_exists('hash')) {
343 $key=pack('H*',hash($hash, $key)); }
344 if (!function_exists('hash')) {
345 $key=pack('H*',$hash($key)); } }
346 $key=str_pad($key, $blocksize, chr(0x00));
347 $ipad=str_repeat(chr(0x36),$blocksize);
348 $opad=str_repeat(chr(0x5c),$blocksize);
349 if (function_exists('hash')) {
350 return hash($hash, ($key^$opad).pack('H*',hash($hash, ($key^$ipad).$data))); }
351 if (!function_exists('hash')) {
352 return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); } }
353 if (function_exists('hash_hmac')) {
354 return hash_hmac($hash,$data,$key); } }
355 // b64hmac hash function
356 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
357 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
358 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
359 // b64hmac rot13 hash function
360 function b64e_rot13_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
361 $data = str_rot13($data);
362 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
363 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
364 // salt hmac hash function
365 function salt_hmac($size1=6,$size2=12) {
366 $hprand = rand($size1,$size2); $i = 0; $hpass = "";
367 while ($i < $hprand) {
368 $hspsrand = rand(1,2);
369 if($hspsrand!=1&&$hspsrand!=2) { $hspsrand=1; }
370 if($hspsrand==1) { $hpass .= chr(rand(48,57)); }
371 /* if($hspsrand==2) { $hpass .= chr(rand(65,70)); } */
372 if($hspsrand==2) { $hpass .= chr(rand(97,102)); }
373 ++$i; } return $hpass; }
374 /* is_empty by M at http://us2.php.net/manual/en/function.empty.php#74093 */
375 function is_empty($var) {
376 if (((is_null($var) || rtrim($var) == "") &&
377 $var !== false) || (is_array($var) && empty($var))) {
378 return true; } else { return false; } }
379 // PHP 5 hash algorithms to functions :o
380 if(function_exists('hash')&&function_exists('hash_algos')) {
381 if(in_array("md2",hash_algos())) {
382 function md2($data) { return hash("md2",$data); } }
383 if(in_array("md4",hash_algos())) {
384 function md4($data) { return hash("md4",$data); } }
385 if(in_array("sha224",hash_algos())) {
386 function sha224($data) { return hash("sha224",$data); } }
387 if(in_array("sha256",hash_algos())) {
388 function sha256($data) { return hash("sha256",$data); } }
389 if(in_array("sha384",hash_algos())) {
390 function sha384($data) { return hash("sha384",$data); } }
391 if(in_array("sha512",hash_algos())) {
392 function sha512($data) { return hash("sha512",$data); } }
393 if(in_array("ripemd128",hash_algos())) {
394 function ripemd128($data) { return hash("ripemd128",$data); } }
395 if(in_array("ripemd160",hash_algos())) {
396 function ripemd160($data) { return hash("ripemd160",$data); } }
397 if(in_array("ripemd256",hash_algos())) {
398 function ripemd256($data) { return hash("ripemd256",$data); } }
399 if(in_array("ripemd512",hash_algos())) {
400 function ripemd320($data) { return hash("ripemd320",$data); } }
401 if(in_array("salsa10",hash_algos())) {
402 function salsa10($data) { return hash("salsa10",$data); } }
403 if(in_array("salsa20",hash_algos())) {
404 function salsa20($data) { return hash("salsa20",$data); } }
405 if(in_array("snefru",hash_algos())) {
406 function snefru($data) { return hash("snefru",$data); } }
407 if(in_array("snefru256",hash_algos())) {
408 function snefru256($data) { return hash("snefru256",$data); } }
409 if(in_array("gost",hash_algos())) {
410 function gost($data) { return hash("gost",$data); } } }
411 // Try and convert IPB 2.0.0 style passwords to iDB style passwords
412 function hash2xkey($data,$key,$hash1='md5',$hash2='md5') {
413 return $hash1($hash2($key).$hash2($data)); }
414 // Hash two times with md5 and sha1 for DF2k
415 function PassHash2x($Text) {
416 $Text = md5($Text);
417 $Text = sha1($Text);
418 return $Text; }
419 // Hash two times with hmac-md5 and hmac-sha1
420 function PassHash2x2($data,$key,$extdata,$blocksize=64) {
421 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
422 $Text = hmac($data,$key,"md5").$extdata;
423 $Text = hmac($Text,$key,"sha1").$extdata;
424 return base64_encode($Text); }
425 function cp($infile,$outfile,$mode="w") {
426 $contents = file_get_contents($infile);
427 $cpfp = fopen($outfile,$mode);
428 fwrite($cpfp, $contents);
429 fclose($cpfp);
430 return true; }
431 /* str_ireplace for PHP below ver. 5 updated //
432 // by Kazuki Przyborowski - Cool Dude 2k //
433 // and upaded by Kazuki Przyborowski again */
434 if(!function_exists('str_ireplace')) {
435 function str_ireplace($search,$replace,$subject) {
436 if(!is_array($search)&&is_array($replace)) {
437 $search = array($search); }
438 if(is_array($search)&&!is_array($replace)) {
439 $replace = array($replace); }
440 if(is_array($search)&&is_array($replace)) {
441 $sc=count($search); $rc=count($replace); $sn=0;
442 if($sc!=$rc) { return false; }
443 while ($sc > $sn) {
444 $search[$sn] = preg_quote($search[$sn], "/");
445 $subject = preg_replace("/".$search[$sn]."/i", $replace[$sn], $subject);
446 ++$sn; } }
447 if(!is_array($search)&&!is_array($replace)) {
448 $search = preg_quote($search, "/");
449 $subject = preg_replace("/".$search."/i", $replace, $subject); }
450 return $subject; } }
451 /* Adds httponly to PHP below Ver. 5.2.0 //
452 // by Kazuki Przyborowski - Cool Dude 2k */
453 function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,$secure=false,$httponly=false) {
454 $mkcookie = null; $expireGMT = null;
455 if(!isset($name)) {
456 output_error("Error: You need to enter a name for cookie.",E_USER_ERROR);
457 return false; }
458 if(!isset($expire)) {
459 output_error("Error: You need to enter a time for cookie to expire.",E_USER_ERROR);
460 return false; }
461 $expireGMT = gmdate("D, d-M-Y H:i:s \G\M\T", $expire);
462 if(!isset($value)) { $value = null; }
463 if(!isset($httponly)||$httponly==false) {
464 setcookie($name, $value, $expire, $path, $domain, $secure); return true; }
465 if(version_compare(PHP_VERSION,"5.2.0",">=")&&$httponly==true) {
466 setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); return true; }
467 if(version_compare(PHP_VERSION,"5.2.0","<")&&$httponly==true) {
468 $mkcookie = "Set-Cookie: ".rawurlencode($name)."=".rawurlencode($value);
469 $mkcookie = $mkcookie."; expires=".$expireGMT;
470 if(isset($path)&&$path!=null) { $mkcookie = $mkcookie."; path=".$path; }
471 if(isset($domain)&&$domain!=null) { $mkcookie = $mkcookie."; domain=".$domain; }
472 if(isset($secure)&&$secure===true) { $mkcookie = $mkcookie."; secure"; }
473 if(isset($httponly)&&$httponly===true) { $mkcookie = $mkcookie."; HttpOnly"; }
474 header($mkcookie, false); return true; } }
475 $foobar="fubar"; $$foobar="foobar";
476 // Debug info
477 function dump_included_files($type="var_dump") {
478 if(!isset($type)) { $type = "var_dump"; }
479 if($type=="print_r") { return print_r(get_included_files()); }
480 if($type=="var_dump") { return var_dump(get_included_files()); }
481 if($type=="var_export") { return var_export(get_included_files()); } }
482 function count_included_files() { return count(get_included_files()); }
483 function dump_extensions($type="var_dump") {
484 if(!isset($type)) { $type = "var_dump"; }
485 if($type=="print_r") { return print_r(get_loaded_extensions()); }
486 if($type=="var_dump") { return var_dump(get_loaded_extensions()); }
487 if($type=="var_export") { return var_export(get_loaded_extensions()); } }
488 function count_extensions() { return count(get_loaded_extensions()); }