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-2017 iDB Support - http://idb.berlios.de/
12 Copyright 2004-2017 Game Maker 2k - http://gamemaker2k.org/
14 $FileInfo: functions.php - Last Update: 01/26/2017 SVN 810 - 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($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 if($Settings['sqltype']=="cubrid") {
50 require($SettDir['sql']."cubrid.php"); }
51 require($SettDir['misc']."useragents.php");
52 require($SettDir['misc']."password.php");
54 if ($_GET['act']=="DeleteSession") { session_destroy(); }
55 if ($_GET['act']=="ResetSession") { session_unset(); }
56 if ($_GET['act']=="NewSessionID") { session_regenerate_id(); }
57 if ($_GET['act']=="PHPInfo") { phpinfo(); exit(); }
58 if ($_GET['act']=="phpinfo") { phpinfo(); exit(); }
59 if ($_GET['act']=="PHPCredits") { phpcredits(); exit(); }
60 if ($_GET['act']=="phpcredits") { phpcredits(); exit(); }
62 function header_protocol($header) {
63 if(isset($_SERVER['SERVER_PROTOCOL'])&&strstr($_SERVER['SERVER_PROTOCOL'],"/1.0")) {
64 return "HTTP/1.0 ".$header; }
66 return "HTTP/1.1 ".$header; } }
67 // Change the title and gzip page
68 function change_title($new_title,$use_gzip="off",$gzip_type="gzip") {
69 global $Settings,$urlstatus;
70 if(!isset($urlstatus)||!is_numeric($urlstatus)) { $urlstatus = 200; }
71 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
72 $output = trim(ob_get_clean());
73 $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title>", $output);
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'], ENT_QUOTES, $Settings['charset']);
78 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
80 if($Settings['send_pagesize']=="on") {
81 @header("Content-Length: ".decoct(strlen($output)));
82 @header("Content-MD5: ".base64_encode(md5($output))); }
83 idb_log_maker($urlstatus,strlen($output));
86 if($gzip_type=="gzip") {
87 $goutput = gzencode($output); }
88 if($gzip_type=="deflate") {
89 $goutput = gzcompress($output); }
90 if($Settings['send_pagesize']=="on") {
91 @header("Content-Length: ".decoct(strlen($goutput)));
92 @header("Content-MD5: ".base64_encode(md5($goutput))); }
93 idb_log_maker($urlstatus,strlen($goutput));
95 // Fix amp => (&) to & and gzip page
96 function fix_amp($use_gzip="off",$gzip_type="gzip") {
97 global $Settings,$urlstatus;
98 if(!isset($urlstatus)||!is_numeric($urlstatus)) { $urlstatus = 200; }
99 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
100 $output = trim(ob_get_clean());
101 /* Change Some PHP Settings Fix the &PHPSESSID to &PHPSESSID */
102 $SessName = session_name();
103 $output = preg_replace("/&PHPSESSID/", "&PHPSESSID", $output);
104 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
105 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
106 if($use_gzip!="on") {
107 if($Settings['send_pagesize']=="on") {
108 @header("Content-Length: ".decoct(strlen($output)));
109 @header("Content-MD5: ".base64_encode(md5($output))); }
110 idb_log_maker($urlstatus,strlen($output));
112 if($use_gzip=="on") {
113 if($gzip_type=="gzip") {
114 $goutput = gzencode($output); }
115 if($gzip_type=="deflate") {
116 $goutput = gzcompress($output); }
117 if($Settings['send_pagesize']=="on") {
118 @header("Content-Length: ".decoct(strlen($goutput)));
119 @header("Content-MD5: ".base64_encode(md5($goutput))); }
120 idb_log_maker($urlstatus,strlen($goutput));
122 // GZip page for faster download
123 function gzip_page($use_gzip="off",$gzip_type="gzip") {
124 global $Settings,$urlstatus;
125 if(!isset($urlstatus)||!is_numeric($urlstatus)) { $urlstatus = 200; }
126 $output = trim(ob_get_clean());
127 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
128 if($use_gzip!="on") {
129 if($Settings['send_pagesize']=="on") {
130 @header("Content-Length: ".decoct(strlen($output)));
131 @header("Content-MD5: ".base64_encode(md5($output))); }
132 idb_log_maker($urlstatus,strlen($output));
134 if($use_gzip=="on") {
135 if($gzip_type=="gzip") {
136 $goutput = gzencode($output); }
137 if($gzip_type=="deflate") {
138 $goutput = gzcompress($output); }
139 if($Settings['send_pagesize']=="on") {
140 @header("Content-Length: ".decoct(strlen($goutput)));
141 @header("Content-MD5: ".base64_encode(md5($goutput))); }
142 idb_log_maker($urlstatus,strlen($goutput));
144 $foo="bar"; $$foo="foo";
145 // Kill bad vars for some functions
146 function killbadvars($varname) {
147 $badphp1 = array('$'); $badphp2 = array(null);
148 $varname = str_replace($badphp1, $badphp2, $varname);
149 $varname = preg_replace("/(_SERVER|_ENV|_COOKIE|_SESSION)/i", null, $varname);
150 $varname = preg_replace("/(_GET|_POST|_FILES|_REQUEST|GLOBALS)/i", null, $varname);
151 $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
152 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
153 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
155 // Trying to fix this bug. ^_^
156 // http://xforce.iss.net/xforce/xfdb/49697
157 if(!isset($Settings['DefaultTheme'])) {
158 $Settings['DefaultTheme'] = "iDB"; }
159 // Change the text to icons(smileys)
160 function text2icons($Text,$sqlt,$link=null) {
162 if(!isset($link)) { $link = $SQLStat; }
163 $reneequery=sql_pre_query("SELECT * FROM \"".$sqlt."smileys\"", array(null));
164 $reneeresult=sql_query($reneequery,$link);
165 $reneenum=sql_num_rows($reneeresult);
167 while ($renees < $reneenum) {
168 $FileName=sql_result($reneeresult,$renees,"FileName");
169 $SmileName=sql_result($reneeresult,$renees,"SmileName");
170 $SmileText=sql_result($reneeresult,$renees,"SmileText");
171 $SmileDirectory=sql_result($reneeresult,$renees,"Directory");
172 $ShowSmile=sql_result($reneeresult,$renees,"Display");
173 $ReplaceType=sql_result($reneeresult,$renees,"ReplaceCI");
174 if($ReplaceType=="on") { $ReplaceType = "yes"; }
175 if($ReplaceType=="off") { $ReplaceType = "no"; }
176 if($ReplaceType!="yes"||$ReplaceType!="no") { $ReplaceType = "no"; }
177 $Smile1 = $SmileText;
178 $Smile2 = '<img src="'.$SmileDirectory.''.$FileName.'" style="vertical-align: middle; border: 0px;" title="'.$SmileName.'" alt="'.$SmileName.'" />';
179 if($ReplaceType=="no") {
180 $Text = str_replace($Smile1, $Smile2, $Text); }
181 if($ReplaceType=="yes") {
182 $Smile1 = preg_quote($SmileText,"/");
183 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
184 ++$renees; } return $Text; }
185 // Removes the bad stuff
186 function remove_bad_entities($Text) {
187 //HTML Entities Dec Version
188 $Text = preg_replace("/‮/isU","",$Text);
189 $Text = preg_replace("/ /isU","",$Text);
190 $Text = preg_replace("/ /isU","",$Text);
191 $Text = preg_replace("/ /isU","",$Text);
192 $Text = preg_replace("/‌/isU","",$Text);
193 $Text = preg_replace("/‍/isU","",$Text);
194 $Text = preg_replace("/‎/isU","",$Text);
195 $Text = preg_replace("/‏/isU","",$Text);
196 //HTML Entities Hex Version
197 $Text = preg_replace("/‮/isU","",$Text);
198 $Text = preg_replace("/ /isU","",$Text);
199 $Text = preg_replace("/ /isU","",$Text);
200 $Text = preg_replace("/ /isU","",$Text);
201 $Text = preg_replace("/‌/isU","",$Text);
202 $Text = preg_replace("/‍/isU","",$Text);
203 $Text = preg_replace("/‎/isU","",$Text);
204 $Text = preg_replace("/‏/isU","",$Text);
205 //HTML Entities Name Version
206 $Text = preg_replace("/ /isU","",$Text);
207 $Text = preg_replace("/ /isU","",$Text);
208 $Text = preg_replace("/ /isU","",$Text);
209 $Text = preg_replace("/‌/isU","",$Text);
210 $Text = preg_replace("/‍/isU","",$Text);
211 $Text = preg_replace("/‎/isU","",$Text);
212 $Text = preg_replace("/‏/isU","",$Text);
214 // Remove the bad stuff
215 function remove_spaces($Text) {
216 $Text = preg_replace("/(^\t+|\t+$)/","",$Text);
217 $Text = preg_replace("/(^\n+|\n+$)/","",$Text);
218 $Text = preg_replace("/(^\r+|\r+$)/","",$Text);
219 $Text = preg_replace("/(\r|\n|\t)+/"," ",$Text);
220 $Text = preg_replace("/\s\s+/"," ",$Text);
221 $Text = preg_replace("/(^\s+|\s+$)/","",$Text);
222 $Text = trim($Text, "\x00..\x1F");
223 $Text = remove_bad_entities($Text);
226 function fixbamps($text) {
227 $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;");
228 $fixamps2 = array("©","®","™",""","&","<",">","&\\1acute;","&\\1grave;","&\\1circ;","&\\1uml;","&\\1tilde;","å","æ","ç","ð","ø","ß","þ");
229 $ampnum = count($fixamps1); $ampi=0;
230 while ($ampi < $ampnum) {
231 $text = preg_replace("/".$fixamps1[$ampi]."/i", $fixamps2[$ampi], $text);
233 $text = preg_replace("/&#(x[a-f0-9]+|[0-9]+);/i", "&#$1;", $text);
235 $utshour = $dayconv['hour'];
236 $utsminute = $dayconv['minute'];
237 // Change Time Stamp to a readable time
238 function GMTimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
239 global $utshour,$utsminute;
241 if(!is_numeric($minoffset)) { $minoffset = "00"; }
242 $ts_array = explode(":",$offset);
243 if(count($ts_array)!=2) {
244 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
245 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
246 $offset = $ts_array[0].":".$ts_array[1]; }
247 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
248 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
249 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
250 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
251 //$tsa['minute'] = $tsa['minute'] + $minoffset;
252 if($dst!="on"&&$dst!="off") { $dst = "off"; }
253 if($dst=="on") { if($dstake!="done") {
254 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
255 $utimestamp = $tsa['hour'] * $utshour;
256 $utimestamp = $utimestamp + $tsa['minute'] * $utsminute;
257 $utimestamp = $utimestamp + $minoffset * $utsminute;
258 $timestamp = $timestamp + $utimestamp;
259 return date($format,$timestamp); }
260 // Change Time Stamp to a readable time
261 function TimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
262 return GMTimeChange($format,$timestamp,$offset,$minoffset,$dst); }
263 // Make a GMT Time Stamp
264 function GMTimeStamp() {
265 $GMTHour = gmdate("H");
266 $GMTMinute = gmdate("i");
267 $GMTSecond = gmdate("s");
268 $GMTMonth = gmdate("n");
269 $GMTDay = gmdate("d");
270 $GMTYear = gmdate("Y");
271 return mktime($GMTHour,$GMTMinute,$GMTSecond,$GMTMonth,$GMTDay,$GMTYear); }
272 // Make a GMT Time Stamp alt version
273 function GMTimeStampS() { return time() - date('Z', time()); }
275 function GMTimeGet($format,$offset,$minoffset=null,$dst=null,$taddon=null) {
276 if(!is_numeric($taddon)) { $taddon = null; }
278 return GMTimeChange($format,GMTimeStamp()+$taddon,$offset,$minoffset,$dst); }
280 return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); } }
281 // Get GMT Time alt version
282 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
283 global $utshour,$utsminute;
285 if(!is_numeric($offset)) { $offset = "0"; }
286 if(!is_numeric($minoffset)) { $minoffset = "00"; }
287 $ts_array = explode(":",$offset);
288 if(count($ts_array)!=2) {
289 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
290 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
291 $offset = $ts_array[0].":".$ts_array[1]; }
292 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
293 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
294 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
295 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
296 //$tsa['minute'] = $tsa['minute'] + $minoffset;
297 if($dst!="on"&&$dst!="off") { $dst = "off"; }
298 if($dst=="on") { if($dstake!="done") {
299 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
300 $utimestamp = $tsa['hour'] * $utshour;
301 $utimestamp = $utimestamp + $tsa['minute'] * $utsminute;
302 $utimestamp = $utimestamp + $minoffset * $utsminute;
303 $timestamp = $timestamp + $utimestamp;
304 return date($format,mktime()+$timestamp); }
306 function GetSeverZone() {
307 $TestHour1 = date("H");
308 @putenv("OTZ=".getenv("TZ"));
310 $TestHour2 = date("H");
311 @putenv("TZ=".getenv("OTZ"));
312 $TestHour3 = $TestHour1-$TestHour2;
314 // Get Server offset alt version
315 function SeverOffSet() {
316 $TestHour1 = date("H");
317 $TestHour2 = gmdate("H");
318 $TestHour3 = $TestHour1-$TestHour2;
320 // Get Server offset new version
321 function SeverOffSetNew() {
322 return gmdate("g",mktime(0,date("Z"))); }
323 function gmtime() { return time() - (int) date('Z'); }
324 // Acts like highlight_file();
325 function file_get_source($filename,$return = FALSE) {
326 $phpsrc = file_get_contents($filename);
327 $phpsrcs = highlight_string($phpsrc,$return);
329 // Also acts like highlight_file(); but valid xhtml
330 function valid_get_source($filename) {
331 $phpsrcs = file_get_source($filename,TRUE);
332 // Change font tag to span tag for valid xhtml
333 $phpsrcs = preg_replace("/\<font color=\"(.*?)\"\>/i", "<span style=\"color: \\1;\">", $phpsrcs);
334 $phpsrcs = preg_replace("/\<\/font>/i", "</span>", $phpsrcs);
336 // Check to see if the user is hidden/shy/timid. >_> | ^_^ | <_<
337 function GetUserName($idu,$sqlt,$link=null) { $UsersName = null;
339 if(!isset($link)) { $link = $SQLStat; }
340 $gunquery = sql_pre_query("SELECT * FROM \"".$sqlt."members\" WHERE \"id\"=%i LIMIT 1", array($idu));
341 $gunresult=sql_query($gunquery,$link);
342 $gunnum=sql_num_rows($gunresult);
343 // I'm now hidden from you. ^_^ | <_< I cant find you.
344 $UsersHidden = "yes";
346 $UsersName=sql_result($gunresult,0,"Name");
347 // Am i still hidden. o_O <_< I can see you.
348 $UsersHidden=sql_result($gunresult,0,"HiddenMember"); }
349 sql_free_result($gunresult);
350 $UsersInfo['Name'] = $UsersName;
351 $UsersInfo['Hidden'] = $UsersHidden;
353 if(!function_exists('hash_hmac')) {
354 function hash_hmac($algo, $data, $key, $raw_output = false) {
356 if (strlen($key)>$blocksize) {
357 if (function_exists('hash')) {
358 $key=pack('H*',hash($hash, $key)); }
359 if (!function_exists('hash')) {
360 $key=pack('H*',$hash($key)); } }
361 $key=str_pad($key, $blocksize, chr(0x00));
362 $ipad=str_repeat(chr(0x36),$blocksize);
363 $opad=str_repeat(chr(0x5c),$blocksize);
364 return hash($algo, ($key^$opad).pack('H*',hash($algo, ($key^$ipad).$data))); } }
365 if(!function_exists('hash')) {
366 function hash($algo, $data, $raw_output = false) {
367 if($algo!="md5"&&$algo!="sha1") { $algo = "md5"; }
368 return $algo($data); } }
369 if(!function_exists('hash_algos')) {
370 function hash_algos() {
371 return array(0 => "md5", 1 => "sha1"); } }
372 // hmac hash function
373 function hmac($data,$key,$hash='sha1',$blocksize=64) {
374 if (!function_exists('hash_hmac')) {
375 if (strlen($key)>$blocksize) {
376 if (function_exists('hash')) {
377 $key=pack('H*',hash($hash, $key)); }
378 if (!function_exists('hash')) {
379 $key=pack('H*',$hash($key)); } }
380 $key=str_pad($key, $blocksize, chr(0x00));
381 $ipad=str_repeat(chr(0x36),$blocksize);
382 $opad=str_repeat(chr(0x5c),$blocksize);
383 if (function_exists('hash')) {
384 return hash($hash, ($key^$opad).pack('H*',hash($hash, ($key^$ipad).$data))); }
385 if (!function_exists('hash')) {
386 return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); } }
387 if (function_exists('hash_hmac')) {
388 return hash_hmac($hash,$data,$key); } }
389 // b64hmac hash function
390 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
391 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
392 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
393 // b64hmac rot13 hash function
394 function b64e_rot13_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
395 $data = str_rot13($data);
396 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
397 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
398 // salt hmac hash function
399 function salt_hmac($size1=6,$size2=12) {
400 $hprand = rand($size1,$size2); $i = 0; $hpass = "";
401 while ($i < $hprand) {
402 $hspsrand = rand(1,2);
403 if($hspsrand!=1&&$hspsrand!=2) { $hspsrand=1; }
404 if($hspsrand==1) { $hpass .= chr(rand(48,57)); }
405 /* if($hspsrand==2) { $hpass .= chr(rand(65,70)); } */
406 if($hspsrand==2) { $hpass .= chr(rand(97,102)); }
407 ++$i; } return $hpass; }
408 /* is_empty by M at http://us2.php.net/manual/en/function.empty.php#74093 */
409 function is_empty($var) {
410 if (((is_null($var) || rtrim($var) == "") &&
411 $var !== false) || (is_array($var) && empty($var))) {
412 return true; } else { return false; } }
413 // PHP 5 hash algorithms to functions :o
414 if(function_exists('hash')&&function_exists('hash_algos')) {
415 if(in_array("md2",hash_algos())&&!function_exists("md2")) {
416 function md2($data) { return hash("md2",$data); } }
417 if(in_array("md4",hash_algos())&&!function_exists("md4")) {
418 function md4($data) { return hash("md4",$data); } }
419 if(in_array("md5",hash_algos())&&!function_exists("md5")) {
420 function md5($data) { return hash("md5",$data); } }
421 if(in_array("sha1",hash_algos())&&!function_exists("sha1")) {
422 function sha1($data) { return hash("sha1",$data); } }
423 if(in_array("sha224",hash_algos())&&!function_exists("sha224")) {
424 function sha224($data) { return hash("sha224",$data); } }
425 if(in_array("sha256",hash_algos())&&!function_exists("sha256")) {
426 function sha256($data) { return hash("sha256",$data); } }
427 if(in_array("sha384",hash_algos())&&!function_exists("sha384")) {
428 function sha384($data) { return hash("sha384",$data); } }
429 if(in_array("sha512",hash_algos())&&!function_exists("sha512")) {
430 function sha512($data) { return hash("sha512",$data); } }
431 if(in_array("ripemd128",hash_algos())&&!function_exists("ripemd128")) {
432 function ripemd128($data) { return hash("ripemd128",$data); } }
433 if(in_array("ripemd160",hash_algos())&&!function_exists("ripemd160")) {
434 function ripemd160($data) { return hash("ripemd160",$data); } }
435 if(in_array("ripemd256",hash_algos())&&!function_exists("ripemd256")) {
436 function ripemd256($data) { return hash("ripemd256",$data); } }
437 if(in_array("ripemd512",hash_algos())&&!function_exists("ripemd512")) {
438 function ripemd320($data) { return hash("ripemd320",$data); } } }
439 // Try and convert IPB 2.0.0 style passwords to iDB style passwords
440 function hash2xkey($data,$key,$hash1='md5',$hash2='md5') {
441 return $hash1($hash2($key).$hash2($data)); }
442 // Hash two times with md5 and sha1 for DF2k
443 function PassHash2x($Text) {
447 // Hash two times with hmac-md5 and hmac-sha1
448 function PassHash2x2($data,$key,$extdata,$blocksize=64) {
449 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
450 $Text = hmac($data,$key,"md5").$extdata;
451 $Text = hmac($Text,$key,"sha1").$extdata;
452 return base64_encode($Text); }
453 function cp($infile,$outfile,$mode="w") {
454 $contents = file_get_contents($infile);
455 $cpfp = fopen($outfile,$mode);
456 fwrite($cpfp, $contents);
460 // b64hmac hash function
461 function neo_b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
462 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
463 return base64_encode(password_hash($data.$extdata, PASSWORD_BCRYPT)); }
464 // b64hmac rot13 hash function
465 function neo_b64e_rot13_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
466 $data = str_rot13($data);
467 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
468 return base64_encode(password_hash($data.$extdata, PASSWORD_BCRYPT)); }
470 if(!function_exists('password_hash')) {
471 function bcrypt($data) { return password_hash($data,PASSWORD_BCRYPT); } }
473 /* str_ireplace for PHP below ver. 5 updated //
474 // by Kazuki Przyborowski - Cool Dude 2k //
475 // and upaded by Kazuki Przyborowski again */
476 if(!function_exists('str_ireplace')) {
477 function str_ireplace($search,$replace,$subject) {
478 if(!is_array($search)&&is_array($replace)) {
479 $search = array($search); }
480 if(is_array($search)&&!is_array($replace)) {
481 $replace = array($replace); }
482 if(is_array($search)&&is_array($replace)) {
483 $sc=count($search); $rc=count($replace); $sn=0;
484 if($sc!=$rc) { return false; }
486 $search[$sn] = preg_quote($search[$sn], "/");
487 $subject = preg_replace("/".$search[$sn]."/i", $replace[$sn], $subject);
489 if(!is_array($search)&&!is_array($replace)) {
490 $search = preg_quote($search, "/");
491 $subject = preg_replace("/".$search."/i", $replace, $subject); }
493 /* Adds httponly to PHP below Ver. 5.2.0 //
494 // by Kazuki Przyborowski - Cool Dude 2k */
495 function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,$secure=false,$httponly=false) {
496 $mkcookie = null; $expireGMT = null;
498 output_error("Error: You need to enter a name for cookie.",E_USER_ERROR);
500 if(!isset($expire)) {
501 output_error("Error: You need to enter a time for cookie to expire.",E_USER_ERROR);
503 $expireGMT = gmdate("D, d-M-Y H:i:s \G\M\T", $expire);
504 if(!isset($value)) { $value = null; }
505 if(!isset($httponly)||$httponly==false) {
506 setcookie($name, $value, $expire, $path, $domain, $secure); return true; }
507 if(version_compare(PHP_VERSION,"5.2.0",">=")&&$httponly==true) {
508 setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); return true; }
509 if(version_compare(PHP_VERSION,"5.2.0","<")&&$httponly==true) {
510 $mkcookie = "Set-Cookie: ".rawurlencode($name)."=".rawurlencode($value);
511 $mkcookie = $mkcookie."; expires=".$expireGMT;
512 if(isset($path)&&$path!=null) { $mkcookie = $mkcookie."; path=".$path; }
513 if(isset($domain)&&$domain!=null) { $mkcookie = $mkcookie."; domain=".$domain; }
514 if(isset($secure)&&$secure===true) { $mkcookie = $mkcookie."; secure"; }
515 if(isset($httponly)&&$httponly===true) { $mkcookie = $mkcookie."; HttpOnly"; }
516 header($mkcookie, false); return true; } }
517 $foobar="fubar"; $$foobar="foobar";
519 function dump_included_files($type="var_dump") {
520 if(!isset($type)) { $type = "var_dump"; }
521 if($type=="print_r") { return print_r(get_included_files()); }
522 if($type=="var_dump") { return var_dump(get_included_files()); }
523 if($type=="var_export") { return var_export(get_included_files()); } }
524 function count_included_files() { return count(get_included_files()); }
525 function dump_extensions($type="var_dump") {
526 if(!isset($type)) { $type = "var_dump"; }
527 if($type=="print_r") { return print_r(get_loaded_extensions()); }
528 if($type=="var_dump") { return var_dump(get_loaded_extensions()); }
529 if($type=="var_export") { return var_export(get_loaded_extensions()); } }
530 function count_extensions() { return count(get_loaded_extensions()); }