OSDN Git Service

Update functions.php
[idb/iDB.git.git] / inc / misc / functions.php
index 0616f2e..ef64c79 100644 (file)
@@ -8,10 +8,10 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     Revised BSD License for more details.
 
-    Copyright 2004-2017 iDB Support - http://idb.berlios.de/
-    Copyright 2004-2017 Game Maker 2k - http://gamemaker2k.org/
+    Copyright 2004-2019 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
+    Copyright 2004-2019 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
 
-    $FileInfo: functions.php - Last Update: 01/26/2017 SVN 810 - Author: cooldude2k $
+    $FileInfo: functions.php - Last Update: 08/07/2019 SVN 909 - Author: cooldude2k $
 */
 $File3Name = basename($_SERVER['SCRIPT_NAME']);
 if ($File3Name=="functions.php"||$File3Name=="/functions.php") {
@@ -73,6 +73,9 @@ if(!isset($urlstatus)||!is_numeric($urlstatus)) { $urlstatus = 200; }
 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
 $output = trim(ob_get_clean());
 $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title>", $output);
+$new_title_html = htmlentities($new_title, ENT_QUOTES, $Settings['charset']);
+$output = preg_replace("/<meta property=\"og:title\" content=\"(.*?)\" \/>/i", "<meta property=\"og:title\" content=\"".$new_title_html."\" />", $output);
+$output = preg_replace("/<meta property=\"twitter:title\" content=\"(.*?)\" \/>/i", "<meta property=\"twitter:title\" content=\"".$new_title_html."\" />", $output);
 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
 $SessName = session_name();
 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
@@ -162,17 +165,17 @@ if(!isset($Settings['DefaultTheme'])) {
 function text2icons($Text,$sqlt,$link=null) {
 global $SQLStat;
 if(!isset($link)) { $link = $SQLStat; }
-$reneequery=sql_pre_query("SELECT * FROM \"".$sqlt."smileys\"", array(null));
-$reneeresult=sql_query($reneequery,$link);
-$reneenum=sql_num_rows($reneeresult);
-$renees=0;
-while ($renees < $reneenum) {
-$FileName=sql_result($reneeresult,$renees,"FileName");
-$SmileName=sql_result($reneeresult,$renees,"SmileName");
-$SmileText=sql_result($reneeresult,$renees,"SmileText");
-$SmileDirectory=sql_result($reneeresult,$renees,"Directory");
-$ShowSmile=sql_result($reneeresult,$renees,"Display");
-$ReplaceType=sql_result($reneeresult,$renees,"ReplaceCI");
+$melaniequery=sql_pre_query("SELECT * FROM \"".$sqlt."smileys\"", array(null));
+$melanieresult=sql_query($melaniequery,$link);
+$melanienum=sql_num_rows($melanieresult);
+$melanies=0;
+while ($melanies < $melanienum) {
+$FileName=sql_result($melanieresult,$melanies,"FileName");
+$SmileName=sql_result($melanieresult,$melanies,"SmileName");
+$SmileText=sql_result($melanieresult,$melanies,"SmileText");
+$SmileDirectory=sql_result($melanieresult,$melanies,"Directory");
+$ShowSmile=sql_result($melanieresult,$melanies,"Display");
+$ReplaceType=sql_result($melanieresult,$melanies,"ReplaceCI");
 if($ReplaceType=="on") { $ReplaceType = "yes"; }
 if($ReplaceType=="off") { $ReplaceType = "no"; }
 if($ReplaceType!="yes"||$ReplaceType!="no") { $ReplaceType = "no"; }
@@ -183,7 +186,7 @@ $Text = str_replace($Smile1, $Smile2, $Text); }
 if($ReplaceType=="yes") {
        $Smile1 = preg_quote($SmileText,"/");
 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
-++$renees; } return $Text; }
+++$melanies; } return $Text; }
 // Removes the bad stuff
 function remove_bad_entities($Text) {
 //HTML Entities Dec Version
@@ -352,27 +355,43 @@ sql_free_result($gunresult);
 $UsersInfo['Name'] = $UsersName;
 $UsersInfo['Hidden'] = $UsersHidden;
 return $UsersInfo; }
+if(!function_exists('hash')) {
+function hash($algo, $data, $raw_output = false) {
+if($algo!="md5"&&$algo!="sha1") { $algo = "md5"; }
+return $algo($data); } }
+if(!function_exists('hash_algos')) {
+function hash_algos() {
+return array(0 => "md5", 1 => "sha1"); } }
 if(!function_exists('hash_hmac')) {
-function hash_hmac($algo, $data, $key, $raw_output = false) {
+function hash_hmac($hash, $data, $key, $raw_output = false) {
+  if($hash=="sha3-224") { $hash = "sha3224"; }
+  if($hash=="sha3-256") { $hash = "sha3256"; }
+  if($hash=="sha3-384") { $hash = "sha3384"; }
+  if($hash=="sha3-512") { $hash = "sha3512"; }
   $blocksize = 64;
   if (strlen($key)>$blocksize) {
   if (function_exists('hash')) {
+  if($hash=="sha3224") { $hash = "sha3-224"; }
+  if($hash=="sha3256") { $hash = "sha3-256"; }
+  if($hash=="sha3384") { $hash = "sha3-384"; }
+  if($hash=="sha3512") { $hash = "sha3-512"; }
   $key=pack('H*',hash($hash, $key)); }
   if (!function_exists('hash')) {
   $key=pack('H*',$hash($key)); } }
   $key=str_pad($key, $blocksize, chr(0x00));
   $ipad=str_repeat(chr(0x36),$blocksize);
   $opad=str_repeat(chr(0x5c),$blocksize);
-  return hash($algo, ($key^$opad).pack('H*',hash($algo, ($key^$ipad).$data))); } }
-if(!function_exists('hash')) {
-function hash($algo, $data, $raw_output = false) {
-if($algo!="md5"&&$algo!="sha1") { $algo = "md5"; }
-return $algo($data); } }
-if(!function_exists('hash_algos')) {
-function hash_algos() {
-return array(0 => "md5", 1 => "sha1"); } }
+  if($hash=="sha3224") { $hash = "sha3-224"; }
+  if($hash=="sha3256") { $hash = "sha3-256"; }
+  if($hash=="sha3384") { $hash = "sha3-384"; }
+  if($hash=="sha3512") { $hash = "sha3-512"; }
+  return hash($hash, ($key^$opad).pack('H*',hash($hash, ($key^$ipad).$data))); } }
 // hmac hash function
 function hmac($data,$key,$hash='sha1',$blocksize=64) {
+  if($hash=="sha3-224") { $hash = "sha3224"; }
+  if($hash=="sha3-256") { $hash = "sha3256"; }
+  if($hash=="sha3-384") { $hash = "sha3384"; }
+  if($hash=="sha3-512") { $hash = "sha3512"; }
   if (!function_exists('hash_hmac')) {
   if (strlen($key)>$blocksize) {
   if (function_exists('hash')) {
@@ -383,10 +402,18 @@ function hmac($data,$key,$hash='sha1',$blocksize=64) {
   $ipad=str_repeat(chr(0x36),$blocksize);
   $opad=str_repeat(chr(0x5c),$blocksize);
   if (function_exists('hash')) {
+  if($hash=="sha3224") { $hash = "sha3-224"; }
+  if($hash=="sha3256") { $hash = "sha3-256"; }
+  if($hash=="sha3384") { $hash = "sha3-384"; }
+  if($hash=="sha3512") { $hash = "sha3-512"; }
   return hash($hash, ($key^$opad).pack('H*',hash($hash, ($key^$ipad).$data))); }
   if (!function_exists('hash')) {
   return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); } }
   if (function_exists('hash_hmac')) { 
+  if($hash=="sha3224") { $hash = "sha3-224"; }
+  if($hash=="sha3256") { $hash = "sha3-256"; }
+  if($hash=="sha3384") { $hash = "sha3-384"; }
+  if($hash=="sha3512") { $hash = "sha3-512"; }
   return hash_hmac($hash,$data,$key); } }
 // b64hmac hash function
 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
@@ -430,6 +457,14 @@ if(in_array("sha384",hash_algos())&&!function_exists("sha384")) {
 function sha384($data) { return hash("sha384",$data); } }
 if(in_array("sha512",hash_algos())&&!function_exists("sha512")) { 
 function sha512($data) { return hash("sha512",$data); } }
+if(in_array("sha3-224",hash_algos())&&!function_exists("sha3224")) { 
+function sha3224($data) { return hash("sha3-224",$data); } }
+if(in_array("sha3-256",hash_algos())&&!function_exists("sha3256")) { 
+function sha3256($data) { return hash("sha3-256",$data); } }
+if(in_array("sha3-384",hash_algos())&&!function_exists("sha3384")) { 
+function sha3384($data) { return hash("sha3-384",$data); } }
+if(in_array("sha3-512",hash_algos())&&!function_exists("sha3512")) { 
+function sha3512($data) { return hash("sha3-512",$data); } }
 if(in_array("ripemd128",hash_algos())&&!function_exists("ripemd128")) { 
 function ripemd128($data) { return hash("ripemd128",$data); } }
 if(in_array("ripemd160",hash_algos())&&!function_exists("ripemd160")) { 
@@ -472,6 +507,26 @@ function neo_b64e_rot13_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
 if(!function_exists('password_hash')) { 
 function bcrypt($data) { return password_hash($data,PASSWORD_BCRYPT); } }
 
+/* is_empty by s rotondo90 at gmail com at https://www.php.net/manual/en/function.hash-equals.php#119576*/
+if(!function_exists('hash_equals')) {
+    function hash_equals($known_string, $user_string) {
+        $ret = 0;
+       
+        if (strlen($known_string) !== strlen($user_string)) {
+            $user_string = $known_string;
+            $ret = 1;
+        }
+       
+        $res = $known_string ^ $user_string;
+       
+        for ($i = strlen($res) - 1; $i >= 0; --$i) {
+            $ret |= ord($res[$i]);
+        }
+       
+        return !$ret;
+    }
+}
+
 /* str_ireplace for PHP below ver. 5 updated // 
 //       by Kazuki Przyborowski - Cool Dude 2k      //
 //      and upaded by Kazuki Przyborowski again     */
@@ -530,4 +585,11 @@ function dump_extensions($type="var_dump") {
        if($type=="var_dump") { return var_dump(get_loaded_extensions()); }
        if($type=="var_export") { return var_export(get_loaded_extensions()); } }
 function count_extensions() {  return count(get_loaded_extensions()); }
+// human_filesize by evgenij at kostanay dot kz 
+// URL: https://www.php.net/manual/en/function.filesize.php#120250
+function human_filesize($bytes, $decimals = 2) {
+    $factor = floor((strlen($bytes) - 1) / 3);
+    if ($factor > 0) $sz = 'KMGT';
+    return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$sz[$factor - 1] . 'B';
+}
 ?>