protected function _prepareHook($params) { $languages = Language::getLanguages(true, $this->context->shop->id); if (!count($languages)) { return false; } $link = new Link(); if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { $default_rewrite = array(); if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int) Tools::getValue('id_product'))) { $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']); } } if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int) Tools::getValue('id_category'))) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } } if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int) Tools::getValue('id_cms')) || ($id_cms_category = (int) Tools::getValue('id_cms_category')))) { $rewrite_infos = isset($id_cms) && !isset($id_cms_category) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category); foreach ($rewrite_infos as $infos) { $arr_link = isset($id_cms) && !isset($id_cms_category) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } } $this->smarty->assign('lang_rewrite_urls', $default_rewrite); } return true; }
public function preProcess() { if ($id_category = (int) Tools::getValue('id_category')) { $this->category = new Category($id_category, self::$cookie->id_lang); } if (!Validate::isLoadedObject($this->category)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } else { // Automatically redirect to the canonical URL if the current in is the right one // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain $currentURL = self::$link->getCategoryLink($this->category); $currentURL = preg_replace('/[?&].*$/', '', $currentURL); if (!preg_match('/^' . Tools::pRegexp($currentURL, '/') . '([&?].*)?$/', Tools::getProtocol() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); if (defined('_PS_MODE_DEV_') and _PS_MODE_DEV_) { die('[Debug] This page has moved<br />Please use the following URL instead: <a href="' . $currentURL . '">' . $currentURL . '</a>'); } Tools::redirectLink($currentURL); } } parent::preProcess(); if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { if ($id_category = (int) Tools::getValue('id_category')) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); $default_rewrite = array(); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = self::$link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } self::$smarty->assign('lang_rewrite_urls', $default_rewrite); } } }
/** * Returns module content for header * * @param array $params Parameters * @return string Content */ public function hookTop($params) { global $smarty; $languages = Language::getLanguages(); if (!count($languages)) { return; } $link = new Link(); if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { $default_rewrite = array(); $phpSelf = isset($_SERVER['PHP_SELF']) ? substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)) : ''; if ($phpSelf == 'product.php' and $id_product = (int) Tools::getValue('id_product')) { $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']); } } if ($phpSelf == 'category.php' and $id_category = (int) Tools::getValue('id_category')) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } } if ($phpSelf == 'cms.php' and ($id_cms = (int) Tools::getValue('id_cms') or $id_cms_category = (int) Tools::getValue('id_cms_category'))) { $rewrite_infos = (isset($id_cms) and !isset($id_cms_category)) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category); foreach ($rewrite_infos as $infos) { $arr_link = (isset($id_cms) and !isset($id_cms_category)) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], NULL, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } } if (count($default_rewrite)) { $smarty->assign('lang_rewrite_urls', $default_rewrite); } } $smarty->assign('languages', $languages); return $this->display(__FILE__, 'blocklanguages.tpl'); }
function frontGetModuleContents($module, $cacheKey = '') { if (!$this->isCached('pagelink.' . $module['layout'] . '.tpl', Tools::encrypt($cacheKey))) { $contents = array(); $langId = $this->context->language->id; $shopId = $this->context->shop->id; $items = Db::getInstance()->executeS("Select r.*, rl.name, rl.link \n\t\t\t\tFrom " . _DB_PREFIX_ . "pagelink_item AS r \n\t\t\t\tInner Join " . _DB_PREFIX_ . "pagelink_item_lang AS rl On r.id = rl.menuitem_id \n\t\t\t\tWhere r.parent_id = 0 AND r.module_id = " . $module['id'] . " AND r.status = 1 AND rl.id_lang = " . $langId . " Order By r.ordering"); if ($items) { foreach ($items as &$item) { $icon = $this->getImageSrc($item['icon'], true); $item['icon_type'] = $icon->type; $item['full_path'] = $icon->img; if ($item['link_type'] == 'PAG-authentication') { if ($this->context->customer->logged) { $item['link'] = $this->context->link->getPageLink('index', true, NULL, "mylogout"); $item['name'] = $this->l('Sign out'); $item['custom_class'] = 'nav-logout'; } else { $item['link'] = $this->frontGenerationUrl($item['link_type'], $item['link']); } } elseif ($item['link_type'] == 'PRODUCT-0') { $item['link'] = $this->frontGenerationUrl('PRD-' . $item['product_id'], $item['link']); } elseif ($item['link_type'] == 'CURRENCY-BOX') { $item['currencies'] = array('name' => $this->context->currency->name, 'iso_code' => $this->context->currency->iso_code, 'sign' => $this->context->currency->sign); } elseif ($item['link_type'] == 'LANGUAGE-BOX') { $languages = Language::getLanguages(true, $this->context->shop->id); if (count($languages) > 0) { $link = new Link(); if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { $default_rewrite = array(); if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int) Tools::getValue('id_product'))) { $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']); } } if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int) Tools::getValue('id_category'))) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } } if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int) Tools::getValue('id_cms')) || ($id_cms_category = (int) Tools::getValue('id_cms_category')))) { $rewrite_infos = isset($id_cms) && !isset($id_cms_category) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category); foreach ($rewrite_infos as $infos) { $arr_link = isset($id_cms) && !isset($id_cms_category) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } } $this->smarty->assign(array('lang_rewrite_urls' => $default_rewrite, 'lang_name' => $this->context->language->name, 'lang_iso_code' => $this->context->language->iso_code)); } } } else { $item['link'] = $this->frontGenerationUrl($item['link_type'], $item['link']); } $item['submenus'] = $this->frontGetSubMenus($module['id'], $item['id']); } } $this->context->smarty->assign(array('module_layout' => $module['layout'], 'display_name' => $module['display_name'], 'custom_class' => $module['custom_class'], 'name' => $module['name'], 'menuContents' => $items)); } return $this->display(__FILE__, 'pagelink.' . $module['layout'] . '.tpl', Tools::encrypt($cacheKey)); }
public function hookTop($params) { if (!$this->active) { return; } $languages = Language::getLanguages(); if (!count($languages)) { return; } if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { $default_rewrite = array(); $phpSelf = isset($_SERVER['PHP_SELF']) ? substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)) : ''; if ($phpSelf == 'product.php' and $id_product = (int) Tools::getValue('id_product')) { $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $this->context->link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']); } } if ($phpSelf == 'category.php' and $id_category = (int) Tools::getValue('id_category')) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $this->context->link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } } if ($phpSelf == 'cms.php' and ($id_cms = (int) Tools::getValue('id_cms') or $id_cms_category = (int) Tools::getValue('id_cms_category'))) { $rewrite_infos = (isset($id_cms) and !isset($id_cms_category)) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category); foreach ($rewrite_infos as $infos) { $arr_link = (isset($id_cms) and !isset($id_cms_category)) ? $this->context->link->getCMSLink($id_cms, $infos['link_rewrite'], NULL, $infos['id_lang']) : $this->context->link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } } if (count($default_rewrite)) { $this->context->smarty->assign('lang_rewrite_urls', $default_rewrite); } } $this->assignContentVars($params); $this->context->smarty->assign(array('cart' => $this->context->cart, 'cart_qties' => $this->context->cart->nbProducts(), 'logged' => $this->context->customer->isLogged(), 'customerName' => $this->context->cookie->logged ? $this->context->cookie->customer_firstname . ' ' . $this->context->cookie->customer_lastname : false, 'firstName' => $this->context->cookie->logged ? $this->context->cookie->customer_firstname : false, 'lastName' => $this->context->cookie->logged ? $this->context->cookie->customer_lastname : false, 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order', 'languages' => $languages)); return $this->display(__FILE__, 'responsivetopbar.tpl'); }
public function preProcess() { if ($id_category = (int) Tools::getValue('id_category')) { $this->productSort(); if ($this->category->id != 1) { $brand_id = Tools::getValue('brand'); $this->category = new Category($id_category, self::$cookie->id_lang); $nbProducts = 0; $this->n = (int) Configuration::get('PS_PRODUCTS_PER_PAGE'); $this->p = abs((int) Tools::getValue('p', 1)); try { global $cart, $cookie; $id_country = (int) Country::getDefaultCountryId(); if ($cart->id_address_delivery) { $address = new Address($cart->id_address_delivery); if ($address->id_country) { $id_country = $address->id_country; } elseif (isset($cookie->id_country)) { $id_country = (int) $cookie->id_country; } } self::$smarty->assign('price_tax_country', $id_country); $products = SolrSearch::getCategoryProducts($id_category, $brand_id, $nbProducts); } catch (Exception $e) { self::$smarty->assign('fetch_error', 1); } $this->pagination((int) $nbProducts); self::$smarty->assign('nb_products', (int) $nbProducts); $this->cat_page_products = $products; } } if (!Validate::isLoadedObject($this->category)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } else { // Automatically redirect to the canonical URL if the current in is the right one // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain $currentURL = self::$link->getCategoryLink($this->category); $currentURL = preg_replace('/[?&].*$/', '', $currentURL); if (!preg_match('/^' . Tools::pRegexp($currentURL, '/') . '([&?].*)?$/', Tools::getProtocol() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); if (defined('_PS_MODE_DEV_') and _PS_MODE_DEV_) { die('[Debug] This page has moved<br />Please use the following URL instead: <a href="' . $currentURL . '">' . $currentURL . '</a>'); } Tools::redirectLink($currentURL); } } parent::preProcess(); if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { if ($id_category = (int) Tools::getValue('id_category')) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); $default_rewrite = array(); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = self::$link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } self::$smarty->assign('lang_rewrite_urls', $default_rewrite); } } }