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; }
/** * 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'); }
public static function getRecurseCategory($id_lang = _USER_ID_LANG_, $current = 1, $active = 1, $links = 0) { $category = Db::getInstance()->getRow(' SELECT c.`id_cms_category`, c.`id_parent`, c.`level_depth`, cl.`name`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'cms_category` c JOIN `' . _DB_PREFIX_ . 'cms_category_lang` cl ON c.`id_cms_category` = cl.`id_cms_category` WHERE c.`id_cms_category` = ' . (int) $current . ' AND `id_lang` = ' . (int) $id_lang); $result = Db::getInstance()->ExecuteS(' SELECT c.`id_cms_category` FROM `' . _DB_PREFIX_ . 'cms_category` c WHERE c.`id_parent` = ' . (int) $current . ($active ? ' AND c.`active` = 1' : '')); foreach ($result as $row) { $category['children'][] = self::getRecurseCategory($id_lang, $row['id_cms_category'], $active, $links); } $category['cms'] = Db::getInstance()->ExecuteS(' SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'cms` c JOIN `' . _DB_PREFIX_ . 'cms_lang` cl ON c.`id_cms` = cl.`id_cms` WHERE `id_cms_category` = ' . (int) $current . ' AND cl.`id_lang` = ' . (int) $id_lang . ($active ? ' AND c.`active` = 1' : '') . ' ORDER BY c.`position`'); if ($links == 1) { $link = new Link(); $category['link'] = $link->getCMSCategoryLink($current, $category['link_rewrite']); foreach ($category['cms'] as $key => $cms) { $category['cms'][$key]['link'] = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']); } } return $category; }
public static function getCMStitles($location) { global $cookie; $cmsCategories = Db::getInstance()->ExecuteS(' SELECT bc.`id_cms_block`, bc.`id_cms_category`, bc.`display_store`, ccl.`link_rewrite`, ccl.`name` category_name, bcl.`name` block_name FROM `' . _DB_PREFIX_ . 'cms_block` bc INNER JOIN `' . _DB_PREFIX_ . 'cms_category_lang` ccl ON (bc.`id_cms_category` = ccl.`id_cms_category`) INNER JOIN `' . _DB_PREFIX_ . 'cms_block_lang` bcl ON (bc.`id_cms_block` = bcl.`id_cms_block`) WHERE bc.`location` = ' . (int) $location . ' AND ccl.`id_lang` = ' . (int) $cookie->id_lang . ' AND bcl.`id_lang` = ' . (int) $cookie->id_lang . ' ORDER BY `position`'); $content = array(); $link = new Link(); if (is_array($cmsCategories) and sizeof($cmsCategories)) { foreach ($cmsCategories as $cmsCategory) { $key = (int) $cmsCategory['id_cms_block']; $content[$key]['display_store'] = $cmsCategory['display_store']; $content[$key]['cms'] = Db::getInstance()->ExecuteS(' SELECT cl.`id_cms`, cl.`meta_title`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'cms_block_page` bcp INNER JOIN `' . _DB_PREFIX_ . 'cms_lang` cl ON (bcp.`id_cms` = cl.`id_cms`) INNER JOIN `' . _DB_PREFIX_ . 'cms` c ON (bcp.`id_cms` = c.`id_cms`) WHERE bcp.`id_cms_block` = ' . (int) $cmsCategory['id_cms_block'] . ' AND cl.`id_lang` = ' . (int) $cookie->id_lang . ' AND bcp.`is_category` = 0 AND c.`active` = 1 ORDER BY `position`'); $links = array(); if (sizeof($content[$key]['cms'])) { foreach ($content[$key]['cms'] as $row) { $row['link'] = $link->getCMSLink((int) $row['id_cms'], $row['link_rewrite']); $links[] = $row; } } $content[$key]['cms'] = $links; $content[$key]['categories'] = Db::getInstance()->ExecuteS(' SELECT bcp.`id_cms`, cl.`name`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'cms_block_page` bcp INNER JOIN `' . _DB_PREFIX_ . 'cms_category_lang` cl ON (bcp.`id_cms` = cl.`id_cms_category`) WHERE bcp.`id_cms_block` = ' . (int) $cmsCategory['id_cms_block'] . ' AND cl.`id_lang` = ' . (int) $cookie->id_lang . ' AND bcp.`is_category` = 1'); $links = array(); if (sizeof($content[$key]['categories'])) { foreach ($content[$key]['categories'] as $row) { $row['link'] = $link->getCMSCategoryLink((int) $row['id_cms'], $row['link_rewrite']); $links[] = $row; } } $content[$key]['categories'] = $links; $content[$key]['name'] = $cmsCategory['block_name']; $content[$key]['category_link'] = $link->getCMSCategoryLink((int) $cmsCategory['id_cms_category'], $cmsCategory['link_rewrite']); $content[$key]['category_name'] = $cmsCategory['category_name']; } } return $content; }
private function makeMenu() { global $cookie, $page_name; $curr_level = 1; foreach ($this->getMenuItems() as $key => $item) { extract($item); if ($depth > $curr_level) { $this->_menu .= '<ul>'; } if ($depth == $curr_level && $key != 0) { $this->_menu .= '</li>'; } if ($depth < $curr_level) { $this->_menu .= str_repeat('</li></ul>', $curr_level - $depth) . '</li>'; } $curr_level = $depth; switch ($type) { case 'CAT': $this->getCategory($id_ref, $cookie->id_lang); break; case 'PRD': $selected = $page_name == 'product' && Tools::getValue('id_product') == $id_ref ? ' class="sfHover"' : ''; $product = new Product($id_ref, true, $cookie->id_lang); if (!is_null($product->id)) { $this->_menu .= '<li' . $selected . '><a href="' . $product->getLink() . '"><span>' . $product->name . '</span></a>' . PHP_EOL; } break; case 'CCS': $selected = $page_name == 'cms' && Tools::getValue('id_cms_category') == $id_ref ? ' class="sfHover"' : ''; $_this_cat = new CMSCategory($id_ref, $cookie->id_lang); $link = new Link(); $this->_menu .= '<li' . $selected . '><a href="' . $link->getCMSCategoryLink($_this_cat->id, $_this_cat->link_rewrite) . '"><span>' . htmlentities($_this_cat->name) . ' </span></a>' . PHP_EOL; break; case 'CMS': $selected = $page_name == 'cms' && Tools::getValue('id_cms') == $id_ref ? ' class="sfHover"' : ''; $cms = CMS::getLinks($cookie->id_lang, array($id_ref)); if (count($cms)) { $this->_menu .= '<li' . $selected . '><a href="' . $cms[0]['link'] . '"><span>' . htmlentities($cms[0]['meta_title']) . '</span></a>' . PHP_EOL; } break; case 'MAN': $selected = $page_name == 'manufacturer' && Tools::getValue('id_manufacturer') == $id_ref ? ' class="sfHover"' : ''; $manufacturer = new Manufacturer($id_ref, $cookie->id_lang); if (!is_null($manufacturer->id)) { if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) { $manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name, false); } else { $manufacturer->link_rewrite = 0; } $link = new Link(); $this->_menu .= '<li' . $selected . '><a href="' . $link->getManufacturerLink($id_ref, $manufacturer->link_rewrite) . '">' . $manufacturer->name . '</a>' . PHP_EOL; } break; case 'SUP': $selected = $page_name == 'supplier' && Tools::getValue('id_supplier') == $id_ref ? ' class="sfHover"' : ''; $supplier = new Supplier($id_ref, $cookie->id_lang); if (!is_null($supplier->id)) { $link = new Link(); $this->_menu .= '<li' . $selected . '><a href="' . $link->getSupplierLink($id_ref, $supplier->link_rewrite) . '"><span>' . $supplier->name . '</span></a>' . PHP_EOL; } break; case 'LNK': $link = WPMenuTopLinks::get($id_ref, $cookie->id_lang); if (count($link)) { $this->_menu .= '<li><a href="' . $link[0]['link'] . '"' . ($link[0]['new_window'] ? ' target="_blank"' : '') . '><span>' . $link[0]['label'] . '</span></a>' . PHP_EOL; } break; } } $this->_menu .= str_repeat('</li></ul>', $curr_level - 1) . '</li>'; }
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 hookActionObjectUpdateAfter($params) { if (isset($params['object']) && !empty($params['object'])) { $object = $params['object']; $type = get_class($object); if (!in_array($type, array('Product', 'Manufacturer', 'Supplier', 'Category', 'CMS', 'CMSCategory'))) { // Ok not our job return; } $shops = $this->getShopsIds(); $link = new Link(); $redirect_list = array(); // Incremental way, it's a bugfix, for supplier for example $shop_urls = array(); $shop_urls[] = 'https:'; $shop_urls[] = 'http:'; foreach ($shops as $id_shop) { $shop = new ShopUrl($id_shop); $shop_urls[] = str_replace(array('http://', 'https://'), '', $shop->getURL(true)); $shop_urls[] = str_replace(array('http://', 'https://'), '', $shop->getURL(false)); } $shop_urls = array_unique($shop_urls); foreach ($shops as $id_shop) { // foreach langs, foreach shops ... $langs = Language::getLanguages(false, $id_shop, true); foreach ($langs as $id_lang) { switch ($type) { case 'Manufacturer': $old_link = $link->getManufacturerLink($object, null, null, null, $id_lang, $id_shop); break; case 'Supplier': $old_link = $link->getSupplierLink($object, null, null, null, $id_lang, $id_shop); break; case 'CMS': $old_link = $link->getCMSLink($object, null, null, $id_lang, $id_shop); break; case 'Product': $old_link = $link->getProductLink($object, null, null, null, $id_lang, $id_shop); break; case 'Category': $old_link = $link->getCategoryLink($object, null, $id_lang, null, $id_shop); break; case 'CMSCategory': $old_link = $link->getCMSCategoryLink($object, null, $id_lang, $id_shop); break; default: // UFO break; } // Escape shops urls, it's a multishop relative approach $old = str_replace($shop_urls, '', $old_link); $old = '/' . ltrim($old, '/'); // Avoid duplicates, simplify complex mapings $md5 = md5($old); if (!isset($redirect_list[$md5])) { $redirect_list[$md5]['old'] = $old; $redirect_list[$md5]['shops'][] = $id_shop; } elseif (!in_array($id_shop, $redirect_list[$md5]['shops'])) { $redirect_list[$md5]['shops'][] = $id_shop; } } } if (!empty($redirect_list)) { foreach ($redirect_list as $redirect) { foreach ($redirect['shops'] as $id_shop) { $this->checkConflict($redirect['old'], $id_shop); } } } } }