From 0b914a39c79c9b3120193e97c7427e7201fbe62e Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 22 Sep 2015 18:10:31 +0200 Subject: [PATCH] Added a declaration of the function 'hex2bin' for the users that has a PHP version <5.4 --- pandora_console/include/functions.php | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 1a16689b99..da76ed5e91 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2485,4 +2485,39 @@ function get_percentile($percentile, $array) { return $result; } + +if (!function_exists('hex2bin')) { + function hex2bin($data) { + static $old; + if ($old === null) { + $old = version_compare(PHP_VERSION, '5.2', '<'); + } + $isobj = false; + if (is_scalar($data) || (($isobj = is_object($data)) && method_exists($data, '__toString'))) { + if ($isobj && $old) { + ob_start(); + echo $data; + $data = ob_get_clean(); + } + else { + $data = (string) $data; + } + } + else { + trigger_error(__FUNCTION__.'() expects parameter 1 to be string, ' . gettype($data) . ' given', E_USER_WARNING); + return;//null in this case + } + $len = strlen($data); + if ($len % 2) { + trigger_error(__FUNCTION__.'(): Hexadecimal input string must have an even length', E_USER_WARNING); + return false; + } + if (strspn($data, '0123456789abcdefABCDEF') != $len) { + trigger_error(__FUNCTION__.'(): Input string must be hexadecimal string', E_USER_WARNING); + return false; + } + return pack('H*', $data); + } +} + ?>