diff --git a/functions/global_functions.php b/functions/global_functions.php index 252b23c943df83a545e41578efb8d4582a64390b..d1b400fa974fb487cbd8fab41b20d87998c45bcc 100644 --- a/functions/global_functions.php +++ b/functions/global_functions.php @@ -18,89 +18,6 @@ function disable_php_errors() { ini_set('display_startup_errors', 0); } -/** - * Supported in PHP 5 >= 5.6.0 - * A timing safe equals comparison more info here: http://blog.ircmaxell.com/2014/11/its-all-about-time.html. - */ -if(!function_exists('hash_equals')) { - function hash_equals($safeString, $userString) { - $safeLen = strlen($safeString); - $userLen = strlen($userString); - - if ($userLen != $safeLen) { return false; } - - $result = 0; - for ($i = 0; $i < $userLen; ++$i) { - $result |= (ord($safeString[$i]) ^ ord($userString[$i])); - } - // They are only identical strings if $result is exactly 0... - return $result === 0; - } -} - -/** - * Supported in PHP 5 >= 5.6.0 - * ldap_escape — Escape a string for use in an LDAP filter or DN - */ -if (!function_exists('ldap_escape')) { - if (!defined('LDAP_ESCAPE_FILTER')) { - define('LDAP_ESCAPE_FILTER', 1); - } - if (!defined('LDAP_ESCAPE_DN')) { - define('LDAP_ESCAPE_DN', 2); - } - function ldap_escape($value, $ignore = null, $flags = 0) { - if (!is_string($value) || strlen($value) == 0) - return ''; - - $search = []; - $replace = []; - - if ($flags & LDAP_ESCAPE_FILTER) { - $search = array_merge($search, ['\\', '*', '(', ')', "\x00"]); - } - if ($flags & LDAP_ESCAPE_DN) { - $search = array_merge($search, ['\\', ',', '=', '+', '<', '>', ';', '"', '#', "\r"]); - } - - $search = array_unique($search); - - if (empty($search)) { - $v = []; - foreach (str_split($value) as $s) { - $v[] = sprintf('\\%02x', ord($s)); - } - $value = implode($v); - } - - foreach ($search as $s) { - $replace[] = sprintf('\\%02x', ord($s)); - } - - return str_replace($search, $replace, $value); - } -} - -/** - * Supported in PHP 5 >= 5.5.0 - * For older php versions make sure that function "json_last_error_msg" exist and create it if not -*/ -if (!function_exists('json_last_error_msg')) { - function json_last_error_msg() { - static $ERRORS = [ - JSON_ERROR_NONE => 'No error', - JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', - JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)', - JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', - JSON_ERROR_SYNTAX => 'Syntax error', - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' - ]; - - $error = json_last_error(); - return isset($ERRORS[$error]) ? $ERRORS[$error] : 'Unknown error'; - } -} - /** * create links function *