/** * Redirects the user to the module admin url if the current user is logged in as an admin in the back office. * If the url cannot be found, then show the 404 page. * * @param array $query_params */ protected function redirectToModuleAdmin(array $query_params) { $admin_url = Nosto::helper('nosto_tagging/config')->getAdminUrl(); if (!empty($admin_url)) { $admin_url = NostoHttpRequest::replaceQueryParamsInUrl($query_params, $admin_url); Tools::redirect($admin_url, ''); die; } $this->notFound(); }
/** * Builds a page url for the language and shop. * * We created our own method due to the existing one in `LinkCore` behaving differently across PS versions. * * @param string $controller the controller name. * @param int|null $id_lang the language ID (falls back on current context if not set). * @param int|null $id_shop the shop ID (falls back on current context if not set). * @param array $params additional params to add to the url. * @return string the page url. */ public function getPageUrl($controller, $id_lang = null, $id_shop = null, array $params = array()) { if (is_null($id_lang)) { $id_lang = (int) Context::getContext()->language->id; } if (is_null($id_shop)) { $id_shop = (int) Context::getContext()->shop->id; } if (version_compare(_PS_VERSION_, '1.5.0.0') === -1 || version_compare(_PS_VERSION_, '1.5.5.0') >= 0) { /** @var LinkCore $link */ $link = new Link(); $url = $link->getPageLink($controller, true, $id_lang, null, false, $id_shop); } else { // For PS versions 1.5.0.0 - 1.5.4.1 we always hard-code the urls to be in non-friendly format and fetch // the shops base url ourselves. This is a workaround to all the bugs related to url building in these // PS versions. $query_params = array('controller' => Tools::strReplaceFirst('.php', '', $controller), 'id_lang' => $id_lang); $url = $this->getBaseUrl($id_shop) . 'index.php?' . http_build_query($query_params); } if ((int) Configuration::get('PS_REWRITING_SETTINGS') === 0) { $params['id_lang'] = $id_lang; } return NostoHttpRequest::replaceQueryParamsInUrl($params, $url); }
/** * Replaces or adds a query parameters to a url. * * @param array $params the query params to replace. * @param string $url the url. * @return string the updated url. */ public function replaceQueryParamsInUrl(array $params, $url) { return \NostoHttpRequest::replaceQueryParamsInUrl($params, $url); }