From d0a6228017a6fd74e83713d712ea9001f4dd2b9c Mon Sep 17 00:00:00 2001 From: rMalie Date: Mon, 14 May 2012 14:16:54 +0000 Subject: [PATCH] // Revert revision 15263 --- classes/Dispatcher.php | 51 ++++++++++++++++-------------------------- classes/Link.php | 4 ++-- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index 55aa886ef..5667238d2 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -179,8 +179,6 @@ class DispatcherCore */ protected $front_controller = self::FC_FRONT; - protected $loaded_languages = array(); - /** * Get current instance of dispatcher (singleton) * @@ -352,6 +350,7 @@ class DispatcherCore */ protected function loadRoutes() { + $context = Context::getContext(); foreach ($this->default_routes as $id => $route) $this->addRoute( $id, @@ -364,7 +363,23 @@ class DispatcherCore if ($this->use_routes) { // Load routes from meta table - $this->loadLangRoutes(Context::getContext()->language->id); + $sql = 'SELECT m.page, ml.url_rewrite + FROM `'._DB_PREFIX_.'meta` m + LEFT JOIN `'._DB_PREFIX_.'meta_lang` ml ON (m.id_meta = ml.id_meta'.Shop::addSqlRestrictionOnLang('ml').') + WHERE id_lang = '.(int)$context->language->id.' + ORDER BY LENGTH(ml.url_rewrite) DESC'; + if ($results = Db::getInstance()->executeS($sql)) + foreach ($results as $row) + { + if ($row['url_rewrite']) + $this->addRoute($row['page'], $row['url_rewrite'], $row['page']); + else + $this->empty_route = array( + 'routeID' => $row['page'], + 'rule' => $row['url_rewrite'], + 'controller' => $row['page'], + ); + } // Load custom routes foreach ($this->default_routes as $route_id => $route_data) @@ -379,30 +394,6 @@ class DispatcherCore } } - public function loadLangRoutes($id_lang) - { - if (in_array($id_lang, $this->loaded_languages)) - $this->loaded_languages[] = $id_lang; - - $sql = 'SELECT m.page, ml.url_rewrite - FROM `'._DB_PREFIX_.'meta` m - LEFT JOIN `'._DB_PREFIX_.'meta_lang` ml ON (m.id_meta = ml.id_meta'.Shop::addSqlRestrictionOnLang('ml').') - WHERE id_lang = '.(int)$id_lang.' - ORDER BY LENGTH(ml.url_rewrite) DESC'; - if ($results = Db::getInstance()->executeS($sql)) - foreach ($results as $row) - { - if ($row['url_rewrite']) - $this->addRoute(str_replace('-', '', $row['page']).'_'.$id_lang, $row['url_rewrite'], $row['page']); - else - $this->empty_route = array( - 'routeID' => $row['page'].'_'.$id_lang, - 'rule' => $row['url_rewrite'], - 'controller' => $row['page'], - ); - } - } - /** * * @param string $id Name of the route (need to be uniq, a second route with same name will override the first) @@ -507,12 +498,8 @@ class DispatcherCore * @param bool $use_routes If false, don't use to create this url * @param string $anchor Optional anchor to add at the end of this url */ - public function createUrl($route_id, array $params = array(), $use_routes = true, $anchor = '', $id_lang = null) + public function createUrl($route_id, array $params = array(), $use_routes = true, $anchor = '') { - if (!$id_lang) - $id_lang = Context::getContext()->language->id; - $this->loadLangRoutes($id_lang); - if (!isset($this->routes[$route_id])) { $query = http_build_query($params, '', '&'); diff --git a/classes/Link.php b/classes/Link.php index b9c45e3a0..9cf98db54 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -385,7 +385,7 @@ class LinkCore */ public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null, $request_url_encode = false) { - $controller = str_replace(array('-', '.php'), '', $controller); + $controller = str_replace('.php', '', $controller); if (!$id_lang) $id_lang = (int)Context::getContext()->language->id; @@ -400,7 +400,7 @@ class LinkCore } unset($request['controller']); - $uri_path = Dispatcher::getInstance()->createUrl($controller.'_'.$id_lang, $request, true, '', $id_lang); + $uri_path = Dispatcher::getInstance()->createUrl($controller, $request); $url = ($ssl && Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true); $url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/');