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