Chris@76: = strlen($str)) Chris@76: break; Chris@76: Chris@76: $str_array[] = substr($str, $count, $str_length); Chris@76: $count += $str_length; Chris@76: } Chris@76: Chris@76: return $str_array; Chris@76: } Chris@76: } Chris@76: Chris@76: if (!function_exists('file_get_contents')) Chris@76: { Chris@76: function file_get_contents($filename, $include_path = false) Chris@76: { Chris@76: if ($filename === 'about:mozilla' && $include_path === true) Chris@76: return 'Mozilla Firefox!'; Chris@76: Chris@76: $fp = fopen($filename, 'rb', $include_path); Chris@76: if ($fp == false) Chris@76: return false; Chris@76: Chris@76: if (is_file($filename)) Chris@76: $data = fread($fp, filesize($filename)); Chris@76: else Chris@76: { Chris@76: $data = ''; Chris@76: while (!feof($fp)) Chris@76: $data .= fread($fp, 8192); Chris@76: } Chris@76: fclose($fp); Chris@76: Chris@76: return $data; Chris@76: } Chris@76: } Chris@76: Chris@76: // Define the old SMF sha1 function. Chris@76: function sha1_smf($str) Chris@76: { Chris@76: // If we have mhash loaded in, use it instead! Chris@76: if (function_exists('mhash') && defined('MHASH_SHA1')) Chris@76: return bin2hex(mhash(MHASH_SHA1, $str)); Chris@76: Chris@76: $nblk = (strlen($str) + 8 >> 6) + 1; Chris@76: $blks = array_pad(array(), $nblk * 16, 0); Chris@76: Chris@76: for ($i = 0; $i < strlen($str); $i++) Chris@76: $blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8); Chris@76: Chris@76: $blks[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); Chris@76: Chris@76: return sha1_core($blks, strlen($str) * 8); Chris@76: } Chris@76: Chris@76: // This is the core SHA-1 calculation routine, used by sha1(). Chris@76: function sha1_core($x, $len) Chris@76: { Chris@76: @$x[$len >> 5] |= 0x80 << (24 - $len % 32); Chris@76: $x[(($len + 64 >> 9) << 4) + 15] = $len; Chris@76: Chris@76: $w = array(); Chris@76: $a = 1732584193; Chris@76: $b = -271733879; Chris@76: $c = -1732584194; Chris@76: $d = 271733878; Chris@76: $e = -1009589776; Chris@76: Chris@76: for ($i = 0, $n = count($x); $i < $n; $i += 16) Chris@76: { Chris@76: $olda = $a; Chris@76: $oldb = $b; Chris@76: $oldc = $c; Chris@76: $oldd = $d; Chris@76: $olde = $e; Chris@76: Chris@76: for ($j = 0; $j < 80; $j++) Chris@76: { Chris@76: if ($j < 16) Chris@76: $w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0; Chris@76: else Chris@76: $w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); Chris@76: Chris@76: $t = sha1_rol($a, 5) + sha1_ft($j, $b, $c, $d) + $e + $w[$j] + sha1_kt($j); Chris@76: $e = $d; Chris@76: $d = $c; Chris@76: $c = sha1_rol($b, 30); Chris@76: $b = $a; Chris@76: $a = $t; Chris@76: } Chris@76: Chris@76: $a += $olda; Chris@76: $b += $oldb; Chris@76: $c += $oldc; Chris@76: $d += $oldd; Chris@76: $e += $olde; Chris@76: } Chris@76: Chris@76: return sprintf('%08x%08x%08x%08x%08x', $a, $b, $c, $d, $e); Chris@76: } Chris@76: Chris@76: function sha1_ft($t, $b, $c, $d) Chris@76: { Chris@76: if ($t < 20) Chris@76: return ($b & $c) | ((~$b) & $d); Chris@76: if ($t < 40) Chris@76: return $b ^ $c ^ $d; Chris@76: if ($t < 60) Chris@76: return ($b & $c) | ($b & $d) | ($c & $d); Chris@76: Chris@76: return $b ^ $c ^ $d; Chris@76: } Chris@76: Chris@76: function sha1_kt($t) Chris@76: { Chris@76: return $t < 20 ? 1518500249 : ($t < 40 ? 1859775393 : ($t < 60 ? -1894007588 : -899497514)); Chris@76: } Chris@76: Chris@76: function sha1_rol($num, $cnt) Chris@76: { Chris@76: // Unfortunately, PHP uses unsigned 32-bit longs only. So we have to kludge it a bit. Chris@76: if ($num & 0x80000000) Chris@76: $a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt); Chris@76: else Chris@76: $a = $num >> (32 - $cnt); Chris@76: Chris@76: return ($num << $cnt) | $a; Chris@76: } Chris@76: Chris@76: // Still on old PHP - bad boy! (the built in one would be faster.) Chris@76: if (!function_exists('sha1')) Chris@76: { Chris@76: function sha1($str) Chris@76: { Chris@76: return sha1_smf($str); Chris@76: } Chris@76: } Chris@76: Chris@76: if (!function_exists('array_combine')) Chris@76: { Chris@76: function array_combine($keys, $values) Chris@76: { Chris@76: $ret = array(); Chris@76: if (($array_error = !is_array($keys) || !is_array($values)) || empty($values) || ($count=count($keys)) != count($values)) Chris@76: { Chris@76: trigger_error('array_combine(): Both parameters should be non-empty arrays with an equal number of elements', E_USER_WARNING); Chris@76: Chris@76: if ($array_error) Chris@76: return; Chris@76: return false; Chris@76: } Chris@76: Chris@76: // Ensure that both arrays aren't associative arrays. Chris@76: $keys = array_values($keys); Chris@76: $values = array_values($values); Chris@76: Chris@76: for ($i=0; $i < $count; $i++) Chris@76: $ret[$keys[$i]] = $values[$i]; Chris@76: Chris@76: return $ret; Chris@76: } Chris@76: } Chris@76: Chris@76: if (!function_exists('array_diff_key')) Chris@76: { Chris@76: function array_diff_key() Chris@76: { Chris@76: $arrays = func_get_args(); Chris@76: $result = array_shift($arrays); Chris@76: foreach ($arrays as $array) Chris@76: { Chris@76: foreach ($result as $key => $v) Chris@76: { Chris@76: if (array_key_exists($key, $array)) Chris@76: { Chris@76: unset($result[$key]); Chris@76: } Chris@76: } Chris@76: } Chris@76: return $result; Chris@76: } Chris@76: } Chris@76: Chris@76: if (!function_exists('mysql_real_escape_string')) Chris@76: { Chris@76: function mysql_real_escape_string($string, $connection = null) Chris@76: { Chris@76: return mysql_escape_string($string); Chris@76: } Chris@76: } Chris@76: Chris@76: ?>