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-2019 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2019 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: functions.php - Last Update: 08/07/2019 SVN 909 - 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']=="sqlite3") {
50 require($SettDir['sql']."sqlite3.php"); }
51 if($Settings['sqltype']=="cubrid") {
52 require($SettDir['sql']."cubrid.php"); }
53 require($SettDir['misc']."useragents.php");
54 require($SettDir['misc']."password.php");
56 if ($_GET['act']=="DeleteSession") { session_destroy(); }
57 if ($_GET['act']=="ResetSession") { session_unset(); }
58 if ($_GET['act']=="NewSessionID") { session_regenerate_id(); }
59 if ($_GET['act']=="PHPInfo") { phpinfo(); exit(); }
60 if ($_GET['act']=="phpinfo") { phpinfo(); exit(); }
61 if ($_GET['act']=="PHPCredits") { phpcredits(); exit(); }
62 if ($_GET['act']=="phpcredits") { phpcredits(); exit(); }
64 function header_protocol($header) {
65 if(isset($_SERVER['SERVER_PROTOCOL'])&&strstr($_SERVER['SERVER_PROTOCOL'],"/1.0")) {
66 return "HTTP/1.0 ".$header; }
68 return "HTTP/1.1 ".$header; } }
69 // Change the title and gzip page
70 function change_title($new_title,$use_gzip="off",$gzip_type="gzip") {
71 global $Settings,$urlstatus;
72 if(!isset($urlstatus)||!is_numeric($urlstatus)) { $urlstatus = 200; }
73 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
74 $output = trim(ob_get_clean());
75 $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title>", $output);
76 $new_title_html = htmlentities($new_title, ENT_QUOTES, $Settings['charset']);
77 $output = preg_replace("/<meta property=\"og:title\" content=\"(.*?)\" \/>/i", "<meta property=\"og:title\" content=\"".$new_title_html."\" />", $output);
78 $output = preg_replace("/<meta property=\"twitter:title\" content=\"(.*?)\" \/>/i", "<meta property=\"twitter:title\" content=\"".$new_title_html."\" />", $output);
79 /* Change Some PHP Settings Fix the &PHPSESSID to &PHPSESSID */
80 $SessName = session_name();
81 $output = preg_replace("/&PHPSESSID/", "&PHPSESSID", $output);
82 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
83 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
85 if($Settings['send_pagesize']=="on") {
86 @header("Content-Length: ".decoct(strlen($output)));
87 @header("Content-MD5: ".base64_encode(md5($output))); }
88 idb_log_maker($urlstatus,strlen($output));
91 if($gzip_type=="gzip") {
92 $goutput = gzencode($output); }
93 if($gzip_type=="deflate") {
94 $goutput = gzcompress($output); }
95 if($Settings['send_pagesize']=="on") {
96 @header("Content-Length: ".decoct(strlen($goutput)));
97 @header("Content-MD5: ".base64_encode(md5($goutput))); }
98 idb_log_maker($urlstatus,strlen($goutput));
100 // Fix amp => (&) to & and gzip page
101 function fix_amp($use_gzip="off",$gzip_type="gzip") {
102 global $Settings,$urlstatus;
103 if(!isset($urlstatus)||!is_numeric($urlstatus)) { $urlstatus = 200; }
104 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
105 $output = trim(ob_get_clean());
106 /* Change Some PHP Settings Fix the &PHPSESSID to &PHPSESSID */
107 $SessName = session_name();
108 $output = preg_replace("/&PHPSESSID/", "&PHPSESSID", $output);
109 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
110 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
111 if($use_gzip!="on") {
112 if($Settings['send_pagesize']=="on") {
113 @header("Content-Length: ".decoct(strlen($output)));
114 @header("Content-MD5: ".base64_encode(md5($output))); }
115 idb_log_maker($urlstatus,strlen($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 if($Settings['send_pagesize']=="on") {
123 @header("Content-Length: ".decoct(strlen($goutput)));
124 @header("Content-MD5: ".base64_encode(md5($goutput))); }
125 idb_log_maker($urlstatus,strlen($goutput));
127 // GZip page for faster download
128 function gzip_page($use_gzip="off",$gzip_type="gzip") {
129 global $Settings,$urlstatus;
130 if(!isset($urlstatus)||!is_numeric($urlstatus)) { $urlstatus = 200; }
131 $output = trim(ob_get_clean());
132 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
133 if($use_gzip!="on") {
134 if($Settings['send_pagesize']=="on") {
135 @header("Content-Length: ".decoct(strlen($output)));
136 @header("Content-MD5: ".base64_encode(md5($output))); }
137 idb_log_maker($urlstatus,strlen($output));
139 if($use_gzip=="on") {
140 if($gzip_type=="gzip") {
141 $goutput = gzencode($output); }
142 if($gzip_type=="deflate") {
143 $goutput = gzcompress($output); }
144 if($Settings['send_pagesize']=="on") {
145 @header("Content-Length: ".decoct(strlen($goutput)));
146 @header("Content-MD5: ".base64_encode(md5($goutput))); }
147 idb_log_maker($urlstatus,strlen($goutput));
149 $foo="bar"; $$foo="foo";
150 // Kill bad vars for some functions
151 function killbadvars($varname) {
152 $badphp1 = array('$'); $badphp2 = array(null);
153 $varname = str_replace($badphp1, $badphp2, $varname);
154 $varname = preg_replace("/(_SERVER|_ENV|_COOKIE|_SESSION)/i", null, $varname);
155 $varname = preg_replace("/(_GET|_POST|_FILES|_REQUEST|GLOBALS)/i", null, $varname);
156 $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
157 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
158 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
160 // Trying to fix this bug. ^_^
161 // http://xforce.iss.net/xforce/xfdb/49697
162 if(!isset($Settings['DefaultTheme'])) {
163 $Settings['DefaultTheme'] = "iDB"; }
164 // Change the text to icons(smileys)
165 function text2icons($Text,$sqlt,$link=null) {
167 if(!isset($link)) { $link = $SQLStat; }
168 $melaniequery=sql_pre_query("SELECT * FROM \"".$sqlt."smileys\"", array(null));
169 $melanieresult=sql_query($melaniequery,$link);
170 $melanienum=sql_num_rows($melanieresult);
172 while ($melanies < $melanienum) {
173 $FileName=sql_result($melanieresult,$melanies,"FileName");
174 $SmileName=sql_result($melanieresult,$melanies,"SmileName");
175 $SmileText=sql_result($melanieresult,$melanies,"SmileText");
176 $SmileDirectory=sql_result($melanieresult,$melanies,"Directory");
177 $ShowSmile=sql_result($melanieresult,$melanies,"Display");
178 $ReplaceType=sql_result($melanieresult,$melanies,"ReplaceCI");
179 if($ReplaceType=="on") { $ReplaceType = "yes"; }
180 if($ReplaceType=="off") { $ReplaceType = "no"; }
181 if($ReplaceType!="yes"||$ReplaceType!="no") { $ReplaceType = "no"; }
182 $Smile1 = $SmileText;
183 $Smile2 = '<img src="'.$SmileDirectory.''.$FileName.'" style="vertical-align: middle; border: 0px;" title="'.$SmileName.'" alt="'.$SmileName.'" />';
184 if($ReplaceType=="no") {
185 $Text = str_replace($Smile1, $Smile2, $Text); }
186 if($ReplaceType=="yes") {
187 $Smile1 = preg_quote($SmileText,"/");
188 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
189 ++$melanies; } return $Text; }
190 // Removes the bad stuff
191 function remove_bad_entities($Text) {
192 //HTML Entities Dec Version
193 $Text = preg_replace("/‮/isU","",$Text);
194 $Text = preg_replace("/ /isU","",$Text);
195 $Text = preg_replace("/ /isU","",$Text);
196 $Text = preg_replace("/ /isU","",$Text);
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 //HTML Entities Hex Version
202 $Text = preg_replace("/‮/isU","",$Text);
203 $Text = preg_replace("/ /isU","",$Text);
204 $Text = preg_replace("/ /isU","",$Text);
205 $Text = preg_replace("/ /isU","",$Text);
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 //HTML Entities Name Version
211 $Text = preg_replace("/ /isU","",$Text);
212 $Text = preg_replace("/ /isU","",$Text);
213 $Text = preg_replace("/ /isU","",$Text);
214 $Text = preg_replace("/‌/isU","",$Text);
215 $Text = preg_replace("/‍/isU","",$Text);
216 $Text = preg_replace("/‎/isU","",$Text);
217 $Text = preg_replace("/‏/isU","",$Text);
219 // Remove the bad stuff
220 function remove_spaces($Text) {
221 $Text = preg_replace("/(^\t+|\t+$)/","",$Text);
222 $Text = preg_replace("/(^\n+|\n+$)/","",$Text);
223 $Text = preg_replace("/(^\r+|\r+$)/","",$Text);
224 $Text = preg_replace("/(\r|\n|\t)+/"," ",$Text);
225 $Text = preg_replace("/\s\s+/"," ",$Text);
226 $Text = preg_replace("/(^\s+|\s+$)/","",$Text);
227 $Text = trim($Text, "\x00..\x1F");
228 $Text = remove_bad_entities($Text);
231 function fixbamps($text) {
232 $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;");
233 $fixamps2 = array("©","®","™",""","&","<",">","&\\1acute;","&\\1grave;","&\\1circ;","&\\1uml;","&\\1tilde;","å","æ","ç","ð","ø","ß","þ");
234 $ampnum = count($fixamps1); $ampi=0;
235 while ($ampi < $ampnum) {
236 $text = preg_replace("/".$fixamps1[$ampi]."/i", $fixamps2[$ampi], $text);
238 $text = preg_replace("/&#(x[a-f0-9]+|[0-9]+);/i", "&#$1;", $text);
240 $utshour = $dayconv['hour'];
241 $utsminute = $dayconv['minute'];
242 // Change Time Stamp to a readable time
243 function GMTimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
244 global $utshour,$utsminute;
246 if(!is_numeric($minoffset)) { $minoffset = "00"; }
247 $ts_array = explode(":",$offset);
248 if(count($ts_array)!=2) {
249 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
250 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
251 $offset = $ts_array[0].":".$ts_array[1]; }
252 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
253 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
254 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
255 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
256 //$tsa['minute'] = $tsa['minute'] + $minoffset;
257 if($dst!="on"&&$dst!="off") { $dst = "off"; }
258 if($dst=="on") { if($dstake!="done") {
259 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
260 $utimestamp = $tsa['hour'] * $utshour;
261 $utimestamp = $utimestamp + $tsa['minute'] * $utsminute;
262 $utimestamp = $utimestamp + $minoffset * $utsminute;
263 $timestamp = $timestamp + $utimestamp;
264 return date($format,$timestamp); }
265 // Change Time Stamp to a readable time
266 function TimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
267 return GMTimeChange($format,$timestamp,$offset,$minoffset,$dst); }
268 // Make a GMT Time Stamp
269 function GMTimeStamp() {
270 $GMTHour = gmdate("H");
271 $GMTMinute = gmdate("i");
272 $GMTSecond = gmdate("s");
273 $GMTMonth = gmdate("n");
274 $GMTDay = gmdate("d");
275 $GMTYear = gmdate("Y");
276 return mktime($GMTHour,$GMTMinute,$GMTSecond,$GMTMonth,$GMTDay,$GMTYear); }
277 // Make a GMT Time Stamp alt version
278 function GMTimeStampS() { return time() - date('Z', time()); }
280 function GMTimeGet($format,$offset,$minoffset=null,$dst=null,$taddon=null) {
281 if(!is_numeric($taddon)) { $taddon = null; }
283 return GMTimeChange($format,GMTimeStamp()+$taddon,$offset,$minoffset,$dst); }
285 return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); } }
286 // Get GMT Time alt version
287 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
288 global $utshour,$utsminute;
290 if(!is_numeric($offset)) { $offset = "0"; }
291 if(!is_numeric($minoffset)) { $minoffset = "00"; }
292 $ts_array = explode(":",$offset);
293 if(count($ts_array)!=2) {
294 if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
295 if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
296 $offset = $ts_array[0].":".$ts_array[1]; }
297 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
298 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
299 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
300 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
301 //$tsa['minute'] = $tsa['minute'] + $minoffset;
302 if($dst!="on"&&$dst!="off") { $dst = "off"; }
303 if($dst=="on") { if($dstake!="done") {
304 $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
305 $utimestamp = $tsa['hour'] * $utshour;
306 $utimestamp = $utimestamp + $tsa['minute'] * $utsminute;
307 $utimestamp = $utimestamp + $minoffset * $utsminute;
308 $timestamp = $timestamp + $utimestamp;
309 return date($format,mktime()+$timestamp); }
311 function GetSeverZone() {
312 $TestHour1 = date("H");
313 @putenv("OTZ=".getenv("TZ"));
315 $TestHour2 = date("H");
316 @putenv("TZ=".getenv("OTZ"));
317 $TestHour3 = $TestHour1-$TestHour2;
319 // Get Server offset alt version
320 function SeverOffSet() {
321 $TestHour1 = date("H");
322 $TestHour2 = gmdate("H");
323 $TestHour3 = $TestHour1-$TestHour2;
325 // Get Server offset new version
326 function SeverOffSetNew() {
327 return gmdate("g",mktime(0,date("Z"))); }
328 function gmtime() { return time() - (int) date('Z'); }
329 // Acts like highlight_file();
330 function file_get_source($filename,$return = FALSE) {
331 $phpsrc = file_get_contents($filename);
332 $phpsrcs = highlight_string($phpsrc,$return);
334 // Also acts like highlight_file(); but valid xhtml
335 function valid_get_source($filename) {
336 $phpsrcs = file_get_source($filename,TRUE);
337 // Change font tag to span tag for valid xhtml
338 $phpsrcs = preg_replace("/\<font color=\"(.*?)\"\>/i", "<span style=\"color: \\1;\">", $phpsrcs);
339 $phpsrcs = preg_replace("/\<\/font>/i", "</span>", $phpsrcs);
341 // Check to see if the user is hidden/shy/timid. >_> | ^_^ | <_<
342 function GetUserName($idu,$sqlt,$link=null) { $UsersName = null;
344 if(!isset($link)) { $link = $SQLStat; }
345 $gunquery = sql_pre_query("SELECT * FROM \"".$sqlt."members\" WHERE \"id\"=%i LIMIT 1", array($idu));
346 $gunresult=sql_query($gunquery,$link);
347 $gunnum=sql_num_rows($gunresult);
348 // I'm now hidden from you. ^_^ | <_< I cant find you.
349 $UsersHidden = "yes";
351 $UsersName=sql_result($gunresult,0,"Name");
352 // Am i still hidden. o_O <_< I can see you.
353 $UsersHidden=sql_result($gunresult,0,"HiddenMember"); }
354 sql_free_result($gunresult);
355 $UsersInfo['Name'] = $UsersName;
356 $UsersInfo['Hidden'] = $UsersHidden;
358 if(!function_exists('hash')) {
359 function hash($algo, $data, $raw_output = false) {
360 if($algo!="md5"&&$algo!="sha1") { $algo = "md5"; }
361 return $algo($data); } }
362 if(!function_exists('hash_algos')) {
363 function hash_algos() {
364 return array(0 => "md5", 1 => "sha1"); } }
365 if(!function_exists('hash_hmac')) {
366 function hash_hmac($hash, $data, $key, $raw_output = false) {
367 if($hash=="sha3-224") { $hash = "sha3224"; }
368 if($hash=="sha3-256") { $hash = "sha3256"; }
369 if($hash=="sha3-384") { $hash = "sha3384"; }
370 if($hash=="sha3-512") { $hash = "sha3512"; }
372 if (strlen($key)>$blocksize) {
373 if (function_exists('hash')) {
374 if($hash=="sha3224") { $hash = "sha3-224"; }
375 if($hash=="sha3256") { $hash = "sha3-256"; }
376 if($hash=="sha3384") { $hash = "sha3-384"; }
377 if($hash=="sha3512") { $hash = "sha3-512"; }
378 $key=pack('H*',hash($hash, $key)); }
379 if (!function_exists('hash')) {
380 $key=pack('H*',$hash($key)); } }
381 $key=str_pad($key, $blocksize, chr(0x00));
382 $ipad=str_repeat(chr(0x36),$blocksize);
383 $opad=str_repeat(chr(0x5c),$blocksize);
384 if($hash=="sha3224") { $hash = "sha3-224"; }
385 if($hash=="sha3256") { $hash = "sha3-256"; }
386 if($hash=="sha3384") { $hash = "sha3-384"; }
387 if($hash=="sha3512") { $hash = "sha3-512"; }
388 return hash($hash, ($key^$opad).pack('H*',hash($hash, ($key^$ipad).$data))); } }
389 // hmac hash function
390 function hmac($data,$key,$hash='sha1',$blocksize=64) {
391 if($hash=="sha3-224") { $hash = "sha3224"; }
392 if($hash=="sha3-256") { $hash = "sha3256"; }
393 if($hash=="sha3-384") { $hash = "sha3384"; }
394 if($hash=="sha3-512") { $hash = "sha3512"; }
395 if (!function_exists('hash_hmac')) {
396 if (strlen($key)>$blocksize) {
397 if (function_exists('hash')) {
398 $key=pack('H*',hash($hash, $key)); }
399 if (!function_exists('hash')) {
400 $key=pack('H*',$hash($key)); } }
401 $key=str_pad($key, $blocksize, chr(0x00));
402 $ipad=str_repeat(chr(0x36),$blocksize);
403 $opad=str_repeat(chr(0x5c),$blocksize);
404 if (function_exists('hash')) {
405 if($hash=="sha3224") { $hash = "sha3-224"; }
406 if($hash=="sha3256") { $hash = "sha3-256"; }
407 if($hash=="sha3384") { $hash = "sha3-384"; }
408 if($hash=="sha3512") { $hash = "sha3-512"; }
409 return hash($hash, ($key^$opad).pack('H*',hash($hash, ($key^$ipad).$data))); }
410 if (!function_exists('hash')) {
411 return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); } }
412 if (function_exists('hash_hmac')) {
413 if($hash=="sha3224") { $hash = "sha3-224"; }
414 if($hash=="sha3256") { $hash = "sha3-256"; }
415 if($hash=="sha3384") { $hash = "sha3-384"; }
416 if($hash=="sha3512") { $hash = "sha3-512"; }
417 return hash_hmac($hash,$data,$key); } }
418 // b64hmac hash function
419 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
420 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
421 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
422 // b64hmac rot13 hash function
423 function b64e_rot13_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
424 $data = str_rot13($data);
425 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
426 return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
427 // salt hmac hash function
428 function salt_hmac($size1=6,$size2=12) {
429 $hprand = rand($size1,$size2); $i = 0; $hpass = "";
430 while ($i < $hprand) {
431 $hspsrand = rand(1,2);
432 if($hspsrand!=1&&$hspsrand!=2) { $hspsrand=1; }
433 if($hspsrand==1) { $hpass .= chr(rand(48,57)); }
434 /* if($hspsrand==2) { $hpass .= chr(rand(65,70)); } */
435 if($hspsrand==2) { $hpass .= chr(rand(97,102)); }
436 ++$i; } return $hpass; }
437 /* is_empty by M at http://us2.php.net/manual/en/function.empty.php#74093 */
438 function is_empty($var) {
439 if (((is_null($var) || rtrim($var) == "") &&
440 $var !== false) || (is_array($var) && empty($var))) {
441 return true; } else { return false; } }
442 // PHP 5 hash algorithms to functions :o
443 if(function_exists('hash')&&function_exists('hash_algos')) {
444 if(in_array("md2",hash_algos())&&!function_exists("md2")) {
445 function md2($data) { return hash("md2",$data); } }
446 if(in_array("md4",hash_algos())&&!function_exists("md4")) {
447 function md4($data) { return hash("md4",$data); } }
448 if(in_array("md5",hash_algos())&&!function_exists("md5")) {
449 function md5($data) { return hash("md5",$data); } }
450 if(in_array("sha1",hash_algos())&&!function_exists("sha1")) {
451 function sha1($data) { return hash("sha1",$data); } }
452 if(in_array("sha224",hash_algos())&&!function_exists("sha224")) {
453 function sha224($data) { return hash("sha224",$data); } }
454 if(in_array("sha256",hash_algos())&&!function_exists("sha256")) {
455 function sha256($data) { return hash("sha256",$data); } }
456 if(in_array("sha384",hash_algos())&&!function_exists("sha384")) {
457 function sha384($data) { return hash("sha384",$data); } }
458 if(in_array("sha512",hash_algos())&&!function_exists("sha512")) {
459 function sha512($data) { return hash("sha512",$data); } }
460 if(in_array("sha3-224",hash_algos())&&!function_exists("sha3224")) {
461 function sha3224($data) { return hash("sha3-224",$data); } }
462 if(in_array("sha3-256",hash_algos())&&!function_exists("sha3256")) {
463 function sha3256($data) { return hash("sha3-256",$data); } }
464 if(in_array("sha3-384",hash_algos())&&!function_exists("sha3384")) {
465 function sha3384($data) { return hash("sha3-384",$data); } }
466 if(in_array("sha3-512",hash_algos())&&!function_exists("sha3512")) {
467 function sha3512($data) { return hash("sha3-512",$data); } }
468 if(in_array("ripemd128",hash_algos())&&!function_exists("ripemd128")) {
469 function ripemd128($data) { return hash("ripemd128",$data); } }
470 if(in_array("ripemd160",hash_algos())&&!function_exists("ripemd160")) {
471 function ripemd160($data) { return hash("ripemd160",$data); } }
472 if(in_array("ripemd256",hash_algos())&&!function_exists("ripemd256")) {
473 function ripemd256($data) { return hash("ripemd256",$data); } }
474 if(in_array("ripemd512",hash_algos())&&!function_exists("ripemd512")) {
475 function ripemd320($data) { return hash("ripemd320",$data); } } }
476 // Try and convert IPB 2.0.0 style passwords to iDB style passwords
477 function hash2xkey($data,$key,$hash1='md5',$hash2='md5') {
478 return $hash1($hash2($key).$hash2($data)); }
479 // Hash two times with md5 and sha1 for DF2k
480 function PassHash2x($Text) {
484 // Hash two times with hmac-md5 and hmac-sha1
485 function PassHash2x2($data,$key,$extdata,$blocksize=64) {
486 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
487 $Text = hmac($data,$key,"md5").$extdata;
488 $Text = hmac($Text,$key,"sha1").$extdata;
489 return base64_encode($Text); }
490 function cp($infile,$outfile,$mode="w") {
491 $contents = file_get_contents($infile);
492 $cpfp = fopen($outfile,$mode);
493 fwrite($cpfp, $contents);
497 // b64hmac hash function
498 function neo_b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
499 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
500 return base64_encode(password_hash($data.$extdata, PASSWORD_BCRYPT)); }
501 // b64hmac rot13 hash function
502 function neo_b64e_rot13_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
503 $data = str_rot13($data);
504 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
505 return base64_encode(password_hash($data.$extdata, PASSWORD_BCRYPT)); }
507 if(!function_exists('password_hash')) {
508 function bcrypt($data) { return password_hash($data,PASSWORD_BCRYPT); } }
510 /* is_empty by s rotondo90 at gmail com at https://www.php.net/manual/en/function.hash-equals.php#119576*/
511 if(!function_exists('hash_equals')) {
512 function hash_equals($known_string, $user_string) {
515 if (strlen($known_string) !== strlen($user_string)) {
516 $user_string = $known_string;
520 $res = $known_string ^ $user_string;
522 for ($i = strlen($res) - 1; $i >= 0; --$i) {
523 $ret |= ord($res[$i]);
530 /* str_ireplace for PHP below ver. 5 updated //
531 // by Kazuki Przyborowski - Cool Dude 2k //
532 // and upaded by Kazuki Przyborowski again */
533 if(!function_exists('str_ireplace')) {
534 function str_ireplace($search,$replace,$subject) {
535 if(!is_array($search)&&is_array($replace)) {
536 $search = array($search); }
537 if(is_array($search)&&!is_array($replace)) {
538 $replace = array($replace); }
539 if(is_array($search)&&is_array($replace)) {
540 $sc=count($search); $rc=count($replace); $sn=0;
541 if($sc!=$rc) { return false; }
543 $search[$sn] = preg_quote($search[$sn], "/");
544 $subject = preg_replace("/".$search[$sn]."/i", $replace[$sn], $subject);
546 if(!is_array($search)&&!is_array($replace)) {
547 $search = preg_quote($search, "/");
548 $subject = preg_replace("/".$search."/i", $replace, $subject); }
550 /* Adds httponly to PHP below Ver. 5.2.0 //
551 // by Kazuki Przyborowski - Cool Dude 2k */
552 function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,$secure=false,$httponly=false) {
553 $mkcookie = null; $expireGMT = null;
555 output_error("Error: You need to enter a name for cookie.",E_USER_ERROR);
557 if(!isset($expire)) {
558 output_error("Error: You need to enter a time for cookie to expire.",E_USER_ERROR);
560 $expireGMT = gmdate("D, d-M-Y H:i:s \G\M\T", $expire);
561 if(!isset($value)) { $value = null; }
562 if(!isset($httponly)||$httponly==false) {
563 setcookie($name, $value, $expire, $path, $domain, $secure); return true; }
564 if(version_compare(PHP_VERSION,"5.2.0",">=")&&$httponly==true) {
565 setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); return true; }
566 if(version_compare(PHP_VERSION,"5.2.0","<")&&$httponly==true) {
567 $mkcookie = "Set-Cookie: ".rawurlencode($name)."=".rawurlencode($value);
568 $mkcookie = $mkcookie."; expires=".$expireGMT;
569 if(isset($path)&&$path!=null) { $mkcookie = $mkcookie."; path=".$path; }
570 if(isset($domain)&&$domain!=null) { $mkcookie = $mkcookie."; domain=".$domain; }
571 if(isset($secure)&&$secure===true) { $mkcookie = $mkcookie."; secure"; }
572 if(isset($httponly)&&$httponly===true) { $mkcookie = $mkcookie."; HttpOnly"; }
573 header($mkcookie, false); return true; } }
574 $foobar="fubar"; $$foobar="foobar";
576 function dump_included_files($type="var_dump") {
577 if(!isset($type)) { $type = "var_dump"; }
578 if($type=="print_r") { return print_r(get_included_files()); }
579 if($type=="var_dump") { return var_dump(get_included_files()); }
580 if($type=="var_export") { return var_export(get_included_files()); } }
581 function count_included_files() { return count(get_included_files()); }
582 function dump_extensions($type="var_dump") {
583 if(!isset($type)) { $type = "var_dump"; }
584 if($type=="print_r") { return print_r(get_loaded_extensions()); }
585 if($type=="var_dump") { return var_dump(get_loaded_extensions()); }
586 if($type=="var_export") { return var_export(get_loaded_extensions()); } }
587 function count_extensions() { return count(get_loaded_extensions()); }
588 // human_filesize by evgenij at kostanay dot kz
589 // URL: https://www.php.net/manual/en/function.filesize.php#120250
590 function human_filesize($bytes, $decimals = 2) {
591 $factor = floor((strlen($bytes) - 1) / 3);
592 if ($factor > 0) $sz = 'KMGT';
593 return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$sz[$factor - 1] . 'B';