pANAAO@"M@0ANA8kAXA8ɌAewritingSettings === null) { $psRewritingSettings = (int) Configuration::get('PS_REWRITING_SETTINGS', null, null, $idShop); } if (!$context) { $context = Context::getContext(); } if ((!$this->allow && in_array($idShop, [$context->shop->id, null])) || !Language::isMultiLanguageActivated($idShop) || !$psRewritingSettings) { return ''; } if (!$idLang) { $idLang = $context->language->id; } return Language::getIsoById($idLang) . '/'; } /** * @param int|null $idShop * @param bool|null $ssl * @param bool $relativeProtocol * * @return string */ public function getBaseLink($idShop = null, $ssl = null, $relativeProtocol = false) { if (null === $ssl) { $ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE')); } if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && $idShop !== null) { $shop = new Shop($idShop); } else { $shop = Context::getContext()->shop; } if ($relativeProtocol) { $base = '//' . ($ssl && $this->ssl_enable ? $shop->domain_ssl : $shop->domain); } else { $base = (($ssl && $this->ssl_enable) ? 'https://' . $shop->domain_ssl : 'http://' . $shop->domain); } return $base . $shop->getBaseURI(); } /** * Clean url http://website.com/admin_dir/foo => foo * Remove index.php? * Remove last char if it's ? or & * Remove token if exists. * * @param string $url * * @return string */ public static function getQuickLink($url) { $legacyEnvironment = stripos($url, 'controller'); $patterns = [ '#' . Context::getContext()->link->getBaseLink() . '#', '#' . basename(_PS_ADMIN_DIR_) . '/#', '/index.php/', '/_?token=[a-zA-Z0-9\_]+/', ]; // If __PS_BASE_URI__ = '/', it destroys urls when is 'product/new' or 'modules/manage' (vhost for example) if ('/' !== __PS_BASE_URI__) { $patterns[] = '#' . __PS_BASE_URI__ . '#'; } $url = preg_replace($patterns, '', $url); $url = trim($url, '?&/'); return 'index.php' . (!empty($legacyEnvironment) ? '?' : '/') . $url; } /** * Check if url match with current url. * * @param string $url * * @return bool */ public function matchQuickLink($url) { $quickLink = $this->getQuickLink($url); return $quickLink === ($this->getQuickLink($_SERVER['REQUEST_URI'])); } /** * @param array $params * * @return string * * @throws \InvalidArgumentException */ public static function getUrlSmarty($params) { $context = Context::getContext(); if (!isset($params['params'])) { $params['params'] = []; } if (isset($params['id'])) { $entity = str_replace('-', '_', $params['entity']); $id = ['id_' . $entity => $params['id']]; $params['params'] = array_merge($id, $params['params']); } $default = [ 'id_lang' => $context->language->id, 'id_shop' => null, 'alias' => null, 'ssl' => null, 'relative_protocol' => true, 'with_id_in_anchor' => false, 'extra_params' => [], 'add_anchor' => true, ]; $params = array_merge($default, $params); $urlParameters = http_build_query($params['params']); switch ($params['entity']) { case 'supplier': $link = $context->link->getSupplierLink( new Supplier($params['id'], $params['id_lang']), $para, __( 'Invalid cookie format.' ) ); } return $parts; } /** * Generates the recovery mode cookie value. * * The cookie is a base64 encoded string with the following format: * * recovery_mode|iat|rand|signature * * Where "recovery_mode" is a constant string, * iat is the time the cookie was generated at, * rand is a randomly generated password that is also used as a session identifier * and signature is an hmac of the preceding 3 parts. * * @since 5.2.0 * * @return string Generated cookie content. */ private function generate_cookie() { $to_sign = sprintf( 'recovery_mode|%s|%s', time(), wp_generate_password( 20, false ) ); $signed = $this->recovery_mode_hash( $to_sign ); return base64_encode( sprintf( '%s|%s', $to_sign, $signed ) ); } /** * Gets a form of `wp_hash()` specific to Recovery Mode. * * We cannot use `wp_hash()` because it is defined in `pluggable.php` which is not loaded until after plugins are loaded, * which is too late to verify the recovery mode cookie. * * This tries to use the `AUTH` salts first, but if they aren't valid specific salts will be generated and stored. * * @since 5.2.0 * * @param string $data Data to hash. * @return string|false The hashed $data, or false on failure. */ private function recovery_mode_hash( $data ) { if ( ! defined( 'AUTH_KEY' ) || AUTH_KEY === 'put your unique phrase here' ) { $auth_key = get_site_option( 'recovery_mode_auth_key' ); if ( ! $auth_key ) { if ( ! function_exists( 'wp_generate_password' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } $auth_key = wp_generate_password( 64, true, true ); update_site_option( 'recovery_mode_auth_key', $auth_key ); } } else { $auth_key = AUTH_KEY; } if ( ! defined( 'AUTH_SALT' ) || AUTH_SALT === 'put your unique phrase here' || AUTH_SALT === $auth_key ) { $auth_salt = get_site_option( 'recovery_mode_auth_salt' ); if ( ! $auth_salt ) { if ( ! function_exists( 'wp_generate_password' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } $auth_salt = wp_generate_password( 64, true, true ); update_site_option( 'recovery_mode_auth_salt', $auth_salt ); } } else { $auth_salt = AUTH_SALT; } $secret = $auth_key . $auth_salt; return hash_hmac( 'sha1', $data, $secret ); } }