Esempio n. 1
0
 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_cms = (int) Tools::getValue('id_cms')) {
         $this->cms = new CMS($id_cms, self::$cookie->id_lang);
     } elseif ($id_cms_category = (int) Tools::getValue('id_cms_category')) {
         $this->cms_category = new CMSCategory($id_cms_category, self::$cookie->id_lang);
     }
     // 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
     if ($this->cms and $canonicalURL = self::$link->getCMSLink($this->cms)) {
         if (!preg_match('/^' . Tools::pRegexp($canonicalURL, '/') . '([&?].*)?$/', 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="' . $canonicalURL . '">' . $canonicalURL . '</a>');
             }
             Tools::redirectLink($canonicalURL);
         }
     }
     if ($this->cms_category and $canonicalURL = self::$link->getCMSCategoryLink($this->cms_category)) {
         if (!preg_match('/^' . Tools::pRegexp($canonicalURL, '/') . '([&?].*)?$/', Tools::getProtocol() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) {
             header('HTTP/1.0 301 Moved');
             if (_PS_MODE_DEV_) {
                 die('[Debug] This page has moved<br />Please use the following URL instead: <a href="' . $canonicalURL . '">' . $canonicalURL . '</a>');
             }
             Tools::redirectLink($canonicalURL);
         }
     }
     parent::preProcess();
     /* assignCase (1 = CMS page, 2 = CMS category) */
     if (Validate::isLoadedObject($this->cms) and ($this->cms->active or Tools::getValue('adtoken') == Tools::encrypt('PreviewCMS' . $this->cms->id) and file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php'))) {
         $this->assignCase = 1;
     } elseif (Validate::isLoadedObject($this->cms_category)) {
         $this->assignCase = 2;
     } else {
         Tools::redirect('404.php');
     }
     if ((int) Configuration::get('PS_REWRITING_SETTINGS')) {
         $rewrite_infos = (isset($id_cms) and !isset($id_cms_category)) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category);
         $default_rewrite = array();
         foreach ($rewrite_infos as $infos) {
             $arr_link = (isset($id_cms) and !isset($id_cms_category)) ? self::$link->getCMSLink($id_cms, $infos['link_rewrite'], $this->ssl, $infos['id_lang']) : self::$link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']);
             $default_rewrite[$infos['id_lang']] = $arr_link;
         }
         self::$smarty->assign('lang_rewrite_urls', $default_rewrite);
     }
 }
Esempio n. 3
0
 /**
  * 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');
 }
Esempio n. 4
0
 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));
 }
Esempio n. 5
0
 private function autoCatch($page_name, $id_lang, $id_shop)
 {
     $uri_var = $this->formatLink($_SERVER['REQUEST_URI']);
     $cache_enabled = (bool) Configuration::get('MGRT_URLCACHE');
     $cache_name = 'MR2_' . $id_shop . '_' . Tools::str2url($uri_var);
     $cache_file = $this->cache_folder . md5($cache_name);
     // Better checking this before
     if ($cache_enabled === true && is_writable(_PS_CACHE_DIR_) && file_exists($this->cache_folder)) {
         $time_cache = (int) Configuration::get('MGRT_CACHETIME');
         if (file_exists($cache_file) && filemtime($cache_file) > time() - $time_cache * 60) {
             // Checked, can go ahead
             return;
         } else {
             try {
                 file_put_contents($cache_file, 'checked', LOCK_EX);
             } catch (Exception $e) {
                 PrestaShopLogger::addLog('Redirect Cache folder not writable, please check your modules folder permissions.');
             }
         }
     }
     $link = new Link();
     $db = Db::getInstance();
     $force_ssl = Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE');
     $full_uri = 'http' . ($force_ssl === true ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     if ($full_uri == $link->getPageLink('404')) {
         // nothing to stare
         return;
     }
     if ($page_name == 'pagenotfound') {
         // Check if similar redirect exist, tryig to avoid duplicates
         $exist = $db->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'redirect r WHERE r.old = "' . pSQL($uri_var) . '"');
         if (!empty($uri_var) && empty($exist)) {
             // Let's log it
             $redirect = new Redirect();
             $redirect->old = trim($uri_var);
             $redirect->new = '/';
             $redirect->type = '301';
             $redirect->regex = false;
             $redirect->active = (bool) Configuration::get('MGRT_AUTOACTIVE');
             $redirect->add();
             // Multishop
             $db->execute('INSERT INTO `' . _DB_PREFIX_ . 'redirect_shop` (`id_redirect`, `id_shop`) VALUES (' . (int) $redirect->id . ',' . (int) $id_shop . ')');
             // Update counter
             $t = (int) Configuration::get('MGRT_COUNTER');
             Configuration::updateValue('MGRT_COUNTER', $t + 1);
         }
         if (!empty($exist)) {
             // Test exist in current shop, if not adding it
             $exist_shop = $db->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'redirect_shop WHERE id_shop = ' . (int) $id_shop . ' AND id_redirect = ' . (int) $exist['id_redirect']);
             if (empty($exist_shop)) {
                 $db->execute('INSERT INTO `' . _DB_PREFIX_ . 'redirect_shop` (`id_redirect`, `id_shop`) VALUES (' . (int) $exist['id_redirect'] . ',' . (int) $id_shop . ')');
             }
         }
     } else {
         // We try to find some concordance in available pages
         // considering link rewrite and manipulated url structures
         $rewrite = Tools::isSubmit('rewrite') ? Tools::getValue('rewrite') : null;
         if (empty($rewrite)) {
             $id = Tools::getValue('id_' . $page_name) ? (int) Tools::getValue('id_' . $page_name) : null;
             switch ($page_name) {
                 case 'manufacturer':
                     if (!empty($id)) {
                         $manufacturer = new Manufacturer($id, $id_lang);
                         $rewrite = $manufacturer->link_rewrite;
                     }
                     break;
                 case 'supplier':
                     if (!empty($id)) {
                         $supplier = new Supplier($id, $id_lang);
                         $rewrite = $supplier->link_rewrite;
                     }
                     break;
                 case 'cms':
                     if (!empty($id)) {
                         $link_rewrite = CMS::getUrlRewriteInformations($id);
                     }
                     if (isset($link_rewrite[$id_lang])) {
                         $rewrite = $link_rewrite[$id_lang]['link_rewrite'];
                     }
                     break;
                 case 'product':
                     if (!empty($id)) {
                         $product = new Product($id, false, $id_lang);
                         $rewrite = $product->link_rewrite;
                     }
                     break;
                 case 'category':
                     if (!empty($id)) {
                         $category = new Category($id, $id_lang, $id_shop);
                         $rewrite = $category->link_rewrite;
                     }
                     break;
                 case 'cms_category':
                     if (!empty($id)) {
                         $rewrite = CMSCategory::getLinkRewrite($id, $id_lang);
                     }
                     break;
                 default:
                     // UFO or Module ? Hard to find an equivalent.
                     if (strpos('module', $page_name)) {
                         $rewrite = $page_name;
                     } else {
                         $rewrite = $uri_var;
                     }
                     break;
             }
         }
         if (!empty($rewrite)) {
             // Preparing string
             $rewrite = str_replace('/', '-', $rewrite);
             $a = explode('-', $rewrite);
             $b = array();
             // Filtering, 3 words search maximum, with 3 letter minimum
             foreach ($a as $v) {
                 if (Tools::strlen($v) > 2) {
                     $b[] = $v;
                 }
                 if (count($b) > 2) {
                     break;
                 }
             }
             if (!empty($b)) {
                 $search = implode('%', $b);
                 $exist = $db->executeS('SELECT r.id_redirect FROM ' . _DB_PREFIX_ . 'redirect r, ' . _DB_PREFIX_ . 'redirect_shop rs WHERE rs.id_redirect = r.id_redirect AND rs.id_shop = ' . (int) $id_shop . ' AND r.regex = 0 AND r.old LIKE "/%' . pSQL($search) . '"');
                 if (!empty($exist)) {
                     // Filling unactive empty settled redirect with new best match value
                     foreach ($exist as $value) {
                         $db->execute('UPDATE ' . _DB_PREFIX_ . 'redirect SET new = "' . pSQL($uri_var) . '" WHERE id_redirect = ' . (int) $value['id_redirect']);
                     }
                 }
             }
         }
     }
 }
 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');
 }