customer) ? $context->customer->id : 0; $customer_passwd = isset($context->customer) ? $context->customer->passwd : ''; $script_name = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : ''; return self::hash($customer_id . $customer_passwd . $script_name); } else { $customer_id = isset($context->customer) ? $context->customer->id : 0; $customer_passwd = isset($context->customer) ? $context->customer->passwd : ''; return self::hash($customer_id . $customer_passwd . $page); } } /** * Get admin token */ public static function getAdminToken($string) { return !empty($string) ? self::hash($string) : false; } /** * Get admin token lite */ public static function getAdminTokenLite($tab, $context = null) { if (!$context) { $context = Context::getContext(); } $employee_id = isset($context->employee) ? $context->employee->id : 0; return self::getAdminToken($tab . $employee_id); } /** * Get admin token for Smarty */ public static function getAdminTokenLiteSmarty($params) { $context = Context::getContext(); $employee_id = isset($context->employee) ? $context->employee->id : 0; return self::getAdminToken($params['tab'] . $employee_id); } /** * Get admin URL */ public static function getAdminUrl($url = null, $entities = false) { $link = self::getHttpHost(true) . '/admin/'; if (isset($url)) { $link .= ($entities ? self::htmlentitiesUTF8($url) : $url); } return $link; } /** * Get admin image URL */ public static function getAdminImageUrl($image = null, $entities = false) { return self::getAdminUrl('img/' . $image, $entities); } // ===== STRING FUNCTIONS ===== /** * Convert string to URL-friendly format */ public static function str2url($str) { $str = strtolower($str); $str = preg_replace('/[^a-z0-9\s-]/', '', $str); $str = preg_replace('/[\s-]+/', '-', $str); $str = trim($str, '-'); return $str; } /** * Replace accented characters */ public static function replaceAccentedChars($str) { $search = ['à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ']; $replace = ['a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'th', 'y']; return str_replace($search, $replace, $str); } /** * Truncate string */ public static function truncate($str, $max_length, $suffix = '...') { if (self::strlen($str) <= $max_length) { return $str; } return substr($str, 0, $max_length - self::strlen($suffix)) . $suffix; } /** * String length with encoding */ public static function strlen($str, $encoding = 'UTF-8') { return mb_strlen($str, $encoding); } /** * String to lower */ public static function strtolower($str) { return mb_strtolower($str, 'UTF-8'); } /** * String to upper */ public static function strtoupper($str) { return mb_strtoupper($str, 'UTF-8'); } /** * Substring with encoding */ public static function substr($str, $start, $length = false, $encoding = 'UTF-8') { if ($length === false) { return mb_substr($str, $start, null, $encoding); } return mb_substr($str, $start, $length, $encoding); } /** * String position */ public static function strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { return mb_strpos($str, $find, $offset, $encoding); } /** * String reverse position */ public static function strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { return mb_strrpos($str, $find, $offset, $encoding); } /** * Uppercase first */ public static function ucfirst($str) { return mb_strtoupper(mb_substr($str, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($str, 1, null, 'UTF-8'); } /** * Uppercase words */ public static function ucwords($str) { return mb_convert_case($str, MB_CASE_TITLE, 'UTF-8'); } // ===== UTILITY FUNCTIONS ===== /** * Check if form is submitted */ public static function isSubmit($submit) { return isset($_POST[$submit]) || isset($_GET[$submit]) || isset($_REQUEST[$submit]); } /** * Get value from POST/GET */ public static function getValue($key, $default_value = false) { if (!isset($key) || empty($key)) { return false; } $ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $default_value)); if (is_string($ret)) { return stripslashes(urldecode(preg_replace('/((\%5C0+)|(\%00+)|(\%08+)|(\%09+)|(\%0A+)|(\%0B+)|(\%0C+)|(\%0D+)|(\%0E+)|(\%0F+))/i', '', $ret))); } return $ret; } /** * Get all values */ public static function getAllValues() { return $_POST + $_GET; } /** * Check if value is set */ public static function getIsset($key) { return isset($_POST[$key]) || isset($_GET[$key]) || isset($_REQUEST[$key]); } /** * Safe output */ public static function safeOutput($string, $html = false) { if (!$html) { $string = strip_tags($string); } return $string; } /** * HTML entities UTF8 */ public static function htmlentitiesUTF8($string, $type = ENT_QUOTES) { return htmlentities($string, $type, 'UTF-8'); } /** * HTML entities decode UTF8 */ public static function htmlentitiesDecodeUTF8($string) { return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); } /** * Get HTTP host */ public static function getHttpHost($http = false, $entities = false, $ignore_port = false) { $host = (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']); if ($ignore_port && $pos = strpos($host, ':')) { $host = substr($host, 0, $pos); } if ($entities) { $host = htmlspecialchars($host, ENT_COMPAT, 'UTF-8'); } if ($http) { $host = self::getCurrentUrlProtocolPrefix() . $host; } return $host; } /** * Get current URL protocol prefix */ public static function getCurrentUrlProtocolPrefix() { if (self::usingSecureMode()) { return 'https://'; } return 'http://'; } /** * Check if using secure mode */ public static function usingSecureMode() { return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'; } /** * Get remote address */ public static function getRemoteAddr() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) { if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')) { $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); return trim($ips[0]); } else { return $_SERVER['HTTP_X_FORWARDED_FOR']; } } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP']) { return $_SERVER['HTTP_CLIENT_IP']; } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR']) { return $_SERVER['REMOTE_ADDR']; } return ''; } /** * Redirect */ public static function redirect($url, $base_uri = '/', $link = null, $headers = null) { if (!preg_match('@^https?://@i', $url)) { if (strpos($url, $base_uri) === 0) { $url = substr($url, strlen($base_uri)); } $url = $base_uri . $url; } if ($headers) { if (!is_array($headers)) { $headers = [$headers]; } foreach ($headers as $header) { header($header); } } header('Location: ' . $url); exit; } /** * Redirect admin */ public static function redirectAdmin($url) { header('Location: ' . $url); exit; } /** * Display error */ public static function displayError($errorMessage = null, $htmlentities = null, $context = null) { if ($htmlentities === null) { $htmlentities = true; } if ($errorMessage === null) { $errorMessage = 'Fatal error'; } if ($htmlentities) { $errorMessage = htmlentities($errorMessage, ENT_COMPAT, 'UTF-8'); } echo '
';
print_r($object);
echo '