// Routes for dispatcher (part 3)

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7743 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-07-26 16:47:41 +00:00
parent d05d16d399
commit c9ad75fe11
12 changed files with 344 additions and 216 deletions
+11 -16
View File
@@ -28,8 +28,9 @@
ob_start();
$timerStart = microtime(true);
$currentFileName = array_reverse(explode("/", $_SERVER['SCRIPT_NAME']));
$cookie = new Cookie('psAdmin', substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($currentFileName['0'])));
$context = Context::getContext();
$context->cookie = $cookie;
if (isset($_GET['logout']))
$cookie->logout();
@@ -45,21 +46,20 @@ if ($back = Tools::getValue('back'))
$currentIndex .= '&back='.urlencode($back);
AdminTab::$currentIndex = $currentIndex;
/* Server Params */
$protocol_link = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$protocol_content = (isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$link = new Link($protocol_link, $protocol_content);
define('_PS_BASE_URL_', Tools::getShopDomain(true));
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
$employee = new Employee($cookie->id_employee);
$cookie->id_lang = (int)$employee->id_lang;
$language = new Language($cookie->id_lang ? $cookie->id_lang : Configuration::get('PS_LANG_DEFAULT'));
$iso = $language->iso_code;
include(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
include(_PS_TRANSLATIONS_DIR_.$iso.'/fields.php');
include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php');
/* Server Params */
$protocol_link = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$protocol_content = (isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$link = new Link($protocol_link, $protocol_content);
$context->link = $link;
define('_PS_BASE_URL_', Tools::getShopDomain(true));
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
$path = dirname(__FILE__).'/themes/';
if (empty($employee->bo_theme) OR !file_exists($path.$employee->bo_theme.'/admin.css'))
{
@@ -88,11 +88,6 @@ if (Tools::isMultiShopActivated() && Tools::getValue('setShopContext') !== false
Tools::redirectAdmin($url['path'] . '?' . http_build_query($parseQuery));
}
$context = Context::getContext();
$context->employee = $employee;
$context->cookie = $cookie;
$context->link = $link;
$context->language = $language;
$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$context->country = $defaultCountry;
$context->shop = new Shop(Shop::getContextID());
+3 -3
View File
@@ -43,7 +43,7 @@ class AdminCMS extends AdminTab
$this->fieldsDisplay = array(
'id_cms' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'link_rewrite' => array('title' => $this->l('URL'), 'width' => 200),
'meta_title' => array('title' => $this->l('Title'), 'width' => 300),
'meta_title' => array('title' => $this->l('Title'), 'width' => 300, 'filter_key' => 'b!meta_title'),
'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'position', 'align' => 'center', 'position' => 'position'),
'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)
);
@@ -155,7 +155,7 @@ class AdminCMS extends AdminTab
if (Tools::isMultiShopActivated())
{
echo '<label>'.$this->l('Shop association:').'</label><div class="margin-form">';
$this->displayAssoShop();
$this->displayAssoShop('meta_title');
echo '</div>';
}
// SUBMIT
@@ -184,7 +184,7 @@ class AdminCMS extends AdminTab
$context = Context::getContext();
if (($id_cms_category = (int)Tools::getValue('id_cms_category')))
$currentIndex .= '&id_cms_category='.$id_cms_category;
self::$currentIndex .= '&id_cms_category='.$id_cms_category;
$this->getList($context->language->id, !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL);
if (!$id_cms_category)
+2 -1
View File
@@ -74,9 +74,10 @@ class AdminCMSCategories extends AdminTab
public function display($token = NULL)
{
$context = Context::getContext();
$id_cms_category = (int)(Tools::getValue('id_cms_category', 1));
$this->getList((int)($cookie->id_lang), !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL);
$this->getList((int)($context->cookie->id_lang), !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL);
echo '<h3>'.(!$this->_listTotal ? ($this->l('There are no subcategories')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('subcategories') : $this->l('subCMS Category')))).' '.$this->l('in CMS Category').' "'.stripslashes(CMSCategory::hideCMSCategoryPosition($this->_CMSCategory->getName())).'"</h3>';
echo '<a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminCMSContent&add'.$this->table.'&id_parent='.Tools::getValue('id_cms_category').'&token='.($token!=NULL ? $token : $this->token).'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new sub CMS Category').'</a>
+15 -15
View File
@@ -105,21 +105,21 @@ class AdminCMSContent extends AdminTab
}
else
{
$id_cms_category = (int)(Tools::getValue('id_cms_category'));
if (!$id_cms_category)
$id_cms_category = 1;
$cms_tabs = array('cms_category', 'cms');
// Cleaning links
$catBarIndex = $currentIndex;
foreach ($cms_tabs AS $tab)
if (Tools::getValue($tab.'Orderby') && Tools::getValue($tab.'Orderway'))
$catBarIndex = preg_replace('/&'.$tab.'Orderby=([a-z _]*)&'.$tab.'Orderway=([a-z]*)/i', '', $currentIndex);
echo '<div class="cat_bar"><span style="color: #3C8534;">'.$this->l('Current category').' :</span>&nbsp;&nbsp;&nbsp;'.getPath($catBarIndex, $id_cms_category,'','','cms').'</div>';
echo '<h2>'.$this->l('Categories').'</h2>';
$this->adminCMSCategories->display($this->token);
echo '<div style="margin:10px">&nbsp;</div>';
echo '<h2>'.$this->l('Pages in this category').'</h2>';
$this->adminCMS->display($this->token);
$id_cms_category = (int)(Tools::getValue('id_cms_category'));
if (!$id_cms_category)
$id_cms_category = 1;
$cms_tabs = array('cms_category', 'cms');
// Cleaning links
$catBarIndex = self::$currentIndex;
foreach ($cms_tabs AS $tab)
if (Tools::getValue($tab.'Orderby') && Tools::getValue($tab.'Orderway'))
$catBarIndex = preg_replace('/&'.$tab.'Orderby=([a-z _]*)&'.$tab.'Orderway=([a-z]*)/i', '', self::$currentIndex);
echo '<div class="cat_bar"><span style="color: #3C8534;">'.$this->l('Current category').' :</span>&nbsp;&nbsp;&nbsp;'.getPath($catBarIndex, $id_cms_category,'','','cms').'</div>';
echo '<h2>'.$this->l('Categories').'</h2>';
$this->adminCMSCategories->display($this->token);
echo '<div style="margin:10px">&nbsp;</div>';
echo '<h2>'.$this->l('Pages in this category').'</h2>';
$this->adminCMS->display($this->token);
}
}
+1 -1
View File
@@ -788,7 +788,7 @@ class AdminImport extends AdminTab
$specificPrice = new SpecificPrice();
$specificPrice->id_product = (int)($product->id);
// @todo multishop specific price import
$specificPrice->id_shop = $context->shop->getID();
$specificPrice->id_shop = $context->shop->getID(true);
$specificPrice->id_currency = 0;
$specificPrice->id_country = 0;
$specificPrice->id_group = 0;
+4 -1
View File
@@ -209,7 +209,7 @@ class CMSCategoryCore extends ObjectModel
$category['cms'] = Db::getInstance()->ExecuteS($sql);
if ($links == 1)
{
$category['link'] = $link->getCMSCategoryLink($current, $category['link_rewrite']);
$category['link'] = $context->link->getCMSCategoryLink($current, $category['link_rewrite']);
foreach($category['cms'] as $key => $cms)
$category['cms'][$key]['link'] = $context->link->getCMSLink($cms['id_cms'], $cms['link_rewrite']);
}
@@ -477,6 +477,9 @@ class CMSCategoryCore extends ObjectModel
public function getName($id_lang = NULL)
{
if (!$context)
$context = Context::getContext();
if (!$id_lang)
{
if (isset($this->name[Context::getContext()->language->id]))
+87 -34
View File
@@ -1,5 +1,33 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class DispatcherCore
{
/**
@@ -11,36 +39,36 @@ class DispatcherCore
* @var array
*/
protected $defaultRoutes = array(
'product' => array(
'product_rule' => array(
'controller' => 'product',
'rule' => '{number:id_product}-{word}.html',
'rule' => '{number:id_product}-{text}.html',
),
'category' => array(
'category_rule' => array(
'controller' => 'category',
'rule' => '{number:id_category}-{word}',
'rule' => '{number:id_category}-{text}',
),
'product_alt' => array(
'product_rule2' => array(
'controller' => 'product',
'rule' => '{word1}/{number:id_product}-{word2}.html',
'rule' => '{text1}/{number:id_product}-{text2}.html',
),
'supplier' => array(
'supplier_rule' => array(
'controller' => 'supplier',
'rule' => '{number:id_supplier}__{word}',
'rule' => '{number:id_supplier}__{text}',
),
'manufacturer' => array(
'manufacturer_rule' => array(
'controller' => 'manufacturer',
'rule' => '{number:id_manufacturer}_{word}',
'rule' => '{number:id_manufacturer}_{text}',
),
'cms' => array(
'cms_rule' => array(
'controller' => 'cms',
'rule' => 'content/{number:id_cms}-{word}',
'rule' => 'content/{number:id_cms}-{text}',
),
'cms_category' => array(
'cms_category_rule' => array(
'controller' => 'cms',
'rule' => 'content/category/{number:id_cms_category}-{word}',
'rule' => 'content/category/{number:id_cms_category}-{text}',
),
);
/**
* @var $useRoutes bool
*/
@@ -50,13 +78,13 @@ class DispatcherCore
* @var $routes array
*/
protected $routes = array();
/**
* @var array
*/
protected $keywords = array(
'number' => '[0-9]+',
'word' => '[a-zA-Z0-9-]*',
'text' => '[a-zA-Z0-9-]*',
);
/**
@@ -105,9 +133,21 @@ class DispatcherCore
*/
protected function loadRoutes()
{
$context = Context::getContext();
foreach ($this->defaultRoutes as $id => $route)
$this->addRoute($id, $route['rule'], $route['controller']);
// Load routes from meta table
if ($this->useRoutes)
foreach ($this->defaultRoutes as $id => $route)
$this->addRoute($id, $route['rule'], $route['controller']);
{
$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'.$context->shop->sqlLang('ml').')
WHERE id_lang = '.(int)$context->language->id;
if ($results = Db::getInstance()->ExecuteS($sql))
foreach ($results as $row)
$this->addRoute($row['page'], $row['url_rewrite'], $row['page']);
}
}
/**
@@ -138,6 +178,17 @@ class DispatcherCore
'required' => $required,
);
}
/**
* Check if a route is defined
*
* @param string $routeID
* @return bool
*/
public function routeExists($routeID)
{
return isset($this->routes[$routeID]);
}
/**
* Create an url from
@@ -152,7 +203,10 @@ class DispatcherCore
die('Dispatcher::createUrl() $params must be an array');
if (!isset($this->routes[$routeID]))
return '';
{
$query = http_build_query($params);
return 'index.php?controller='.$routeID.(($query) ? '&'.$query : '');
}
$route = $this->routes[$routeID];
// Check required fields
@@ -191,9 +245,19 @@ class DispatcherCore
{
if ($this->controller)
return $this->controller;
$controller = Tools::getValue('controller');
if (isset($controller) && preg_match('/^([0-9a-z_-]+)\?(.*)=(.*)$/Ui', $controller, $m))
{
$controller = $m[1];
if (isset($_GET['controller']))
$_GET[$m[2]] = $m[3];
else if (isset($_POST['controller']))
$_POST[$m[2]] = $m[3];
}
// Use routes ? (for url rewriting)
if ($this->useRoutes)
if ($this->useRoutes && !$controller)
{
// Get request uri (HTTP_X_REWRITE_URL is used by IIS)
if (isset($_SERVER['REQUEST_URI']))
@@ -219,19 +283,8 @@ class DispatcherCore
}
// Default mode, take controller from url
else
{
$controller = Tools::getValue('controller');
if (isset($controller) && preg_match('/^([0-9a-z_-]+)\?(.*)=(.*)$/Ui', $controller, $m))
{
$controller = $m[1];
if (isset($_GET['controller']))
$_GET[$m[2]] = $m[3];
else if (isset($_POST['controller']))
$_POST[$m[2]] = $m[3];
}
$this->controller = (!empty($controller)) ? $controller : 'index';
}
$this->controller = str_replace('-', '', strtolower($this->controller));
return $this->controller;
}
+20 -22
View File
@@ -96,11 +96,6 @@ class FrontControllerCore
$this->context = Context::getContext();
$protocol_link = (Configuration::get('PS_SSL_ENABLED') OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
$protocol_content = ((isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
$link = new Link($protocol_link, $protocol_content);
$this->context->link = $link;
$this->id_current_shop = Context::getContext()->shop->getID();
$this->id_current_group_shop = Context::getContext()->shop->getGroupID();
@@ -119,9 +114,26 @@ class FrontControllerCore
}
ob_start();
// Switch language if needed and init cookie language
if ($iso = Tools::getValue('isolang') AND Validate::isLanguageIsoCode($iso) AND ($id_lang = (int)(Language::getIdByIso($iso))))
$_GET['id_lang'] = $id_lang;
$cookie = new Cookie('ps');
$this->context->cookie = $cookie;
Tools::switchLanguage();
Tools::setCookieLanguage($cookie);
$currency = Tools::setCurrency($cookie);
if (Validate::isLoadedObject($currency))
$smarty->ps_currency = $currency;
if (!Validate::isLoadedObject($language = new Language($cookie->id_lang)))
$language = new Language(Configuration::get('PS_LANG_DEFAULT'));
$smarty->ps_language = $language;
$this->context->language = $language;
$protocol_link = (Configuration::get('PS_SSL_ENABLED') OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
$protocol_content = ((isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
$link = new Link($protocol_link, $protocol_content);
$this->context->link = $link;
if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
@@ -134,13 +146,6 @@ class FrontControllerCore
elseif (Configuration::get('PS_GEOLOCATION_ENABLED'))
if (($newDefault = $this->geolocationManagement($defaultCountry)) && Validate::isLoadedObject($newDefault))
$defaultCountry = $newDefault;
// Switch language if needed and init cookie language
if ($iso = Tools::getValue('isolang') AND Validate::isLanguageIsoCode($iso) AND ($id_lang = (int)(Language::getIdByIso($iso))))
$_GET['id_lang'] = $id_lang;
Tools::switchLanguage();
Tools::setCookieLanguage($cookie);
if (isset($_GET['logout']) OR ($cookie->logged AND Customer::isBanned((int)$cookie->id_customer)))
{
@@ -153,7 +158,6 @@ class FrontControllerCore
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
}
$currency = Tools::setCurrency($cookie);
$_MODULES = array();
/* Cart already exists */
if ((int)$cookie->id_cart)
@@ -224,13 +228,8 @@ class FrontControllerCore
setlocale(LC_CTYPE, $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_NUMERIC, 'en_US.UTF-8');
if (Validate::isLoadedObject($currency))
$smarty->ps_currency = $currency;
if (!Validate::isLoadedObject($language = new Language($cookie->id_lang)))
$language = new Language(Configuration::get('PS_LANG_DEFAULT'));
$smarty->ps_language = $language;
$this->context->language = $language;
/* get page name to display it in body id */
$pathinfo = pathinfo(__FILE__);
@@ -248,7 +247,6 @@ class FrontControllerCore
if (!defined('_PS_BASE_URL_SSL_'))
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
$link->preloadPageLinks();
$this->canonicalRedirection();
Product::initPricesComputation();
+152 -104
View File
@@ -47,104 +47,181 @@ class LinkCore
}
/**
* This function returns a link to delete a customization picture file
*
* @param mixed $product
* @param mixed $id_picture
* @return void
* Create a link to delete a product
*
* @param mixed $product ID of the product OR a Product object
* @param int $id_picture ID of the picture to delete
* @return string
*/
public function getProductDeletePictureLink($product, $id_picture){
if (is_object($product))
return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink().((isset($product->category) AND !empty($product->category) AND $product->category != 'home') ? $product->category.'/' : '').(int)$product->id.'-'.$product->link_rewrite.($product->ean13 ? '-'.$product->ean13 : '').'.html?deletePicture='.$id_picture) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=product&id_product='.(int)$product->id).'&amp;deletePicture='.$id_picture;
else
return _PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=product&id_product='.(int)$product.'&amp;deletePicture='.$id_picture;
public function getProductDeletePictureLink($product, $id_picture)
{
$url = $this->getProductLink($product);
return $url.((strpos($url, '?')) ? '&' : '?').'&deletePicture='.$id_picture;
}
/**
* Return the correct link for product/category/supplier/manufacturer
*
* @param mixed $id_OBJ Can be either the object or the ID only
* @param string $alias Friendly URL (only if $id_OBJ is the object)
* @return string link
*/
* Create a link to a product
*
* @param mixed $id_product ID of the product OR a Product object
* @param string $alias If $id_product is not a object, this argument is same as obj->link_rewrite
* @param string $category If $id_product is not a object, name of the product category
* @param string $ean13
* @param int $id_lang
* @param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart
* @return string
*/
public function getProductLink($id_product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null)
{
$url = _PS_BASE_URL_.__PS_BASE_URI__;
// @todo use specific method ?
if ($id_shop && ($shop = Shop::getShop($id_shop)))
$url = 'http://'.$shop['domain'].'/'.$shop['uri'];
$url = 'http://'.$shop['domain'].'/'.$shop['uri'].$this->getLangLink($id_lang);
if (is_object($id_product))
return ($this->allow == 1)?($url.$this->getLangLink((int)$id_lang).((isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home') ? $id_product->category.'/' : '').(int)$id_product->id.'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.$id_product->ean13 : '').'.html') :
($url.'index.php?controller=product&id_product='.(int)$id_product->id);
elseif ($alias)
return ($this->allow == 1)?($url.$this->getLangLink((int)$id_lang).(($category AND $category != 'home') ? ($category.'/') : '').(int)$id_product.'-'.$alias.($ean13 ? '-'.$ean13 : '').'.html') :
($url.'index.php?controller=product&id_product='.(int)$id_product);
{
$product = clone($id_product);
$id_product = $product->id;
$category = $product->category;
$alias = $product->link_rewrite;
$ean13 = $product->ean13;
}
if ($category AND $category != 'home')
return $url.Dispatcher::getInstance()->createUrl('product_rule2', array(
'id_product' => $id_product,
'text1' => $category,
'text2' => $alias.(($ean13) ? '-'.$ean13 : ''),
), ($alias && $this->allow));
else
return $url.'index.php?controller=product&id_product='.(int)$id_product;
return $url.Dispatcher::getInstance()->createUrl('product_rule', array(
'id_product' => $id_product,
'text' => (($alias) ? $alias : '').(($ean13) ? '-'.$ean13 : ''),
), ($alias && $this->allow));
}
/**
* Create a link to a category
*
* @param mixed $id_category ID of the category OR a Category object
* @param string $alias If $id_category is not a object, this argument is same as obj->link_rewrite
* @param int $id_lang
* @return string
*/
public function getCategoryLink($id_category, $alias = NULL, $id_lang = NULL)
{
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (is_object($id_category))
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_category->id).'-'.$id_category->link_rewrite) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=category&id_category='.(int)($id_category->id));
if ($alias)
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_category).'-'.$alias) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=category&id_category='.(int)($id_category));
return _PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=category&id_category='.(int)($id_category);
{
$category = clone($id_category);
$id_category = $category->id;
$alias = $category->link_rewrite;
}
return $url.Dispatcher::getInstance()->createUrl('category_rule', array(
'id_category' => $id_category,
'text' => ($alias) ? $alias : '',
), ($alias && $this->allow));
}
/**
* Create a link to a CMS category
*
* @param mixed $id_category ID of the category OR a CmsCategory object
* @param string $alias If $id_category is not a object, this argument is same as obj->link_rewrite
* @param int $id_lang
* @return string
*/
public function getCMSCategoryLink($id_category, $alias = NULL, $id_lang = NULL)
{
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (is_object($id_category))
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/category/'.(int)($id_category->id).'-'.$id_category->link_rewrite) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=cms&id_cms_category='.(int)($id_category->id));
if ($alias)
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/category/'.(int)($id_category).'-'.$alias) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=cms&id_cms_category='.(int)($id_category));
return _PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=cms&id_cms_category='.(int)($id_category);
{
$category = clone($id_category);
$id_category = $category->id;
$alias = $category->link_rewrite;
}
return $url.Dispatcher::getInstance()->createUrl('cms_category_rule', array(
'id_cms_category' => $id_category,
'text' => ($alias) ? $alias : '',
), ($alias && $this->allow));
}
/**
* Create a link to a CMS page
*
* @param mixed $cms ID of the CMS page OR a Cms object
* @param string $alias If $cms is not a object, this argument is same as obj->link_rewrite
* @param bool $ssl
* @param int $id_lang
* @return string
*/
public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = NULL)
{
$base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true));
$url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (is_object($cms))
{
return ($this->allow == 1) ?
($base.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/'.(int)($cms->id).'-'.$cms->link_rewrite) :
($base.__PS_BASE_URI__.'index.php?controller=cms&id_cms='.(int)($cms->id));
$id_cms = $cms->id;
$alias = $cms->link_rewrite;
}
else
$id_cms = $cms;
if ($alias)
return ($this->allow == 1) ? ($base.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/'.(int)($cms).'-'.$alias) :
($base.__PS_BASE_URI__.'index.php?controller=cms&id_cms='.(int)($cms));
return $base.__PS_BASE_URI__.'index.php?controller=cms&id_cms='.(int)($cms);
return $url.Dispatcher::getInstance()->createUrl('cms_rule', array(
'id_cms' => $id_cms,
'text' => ($alias) ? $alias : '',
), ($alias && $this->allow));
}
/**
* Create a link to a supplier
*
* @param mixed $id_supplier ID of the supplier page OR a Supplier object
* @param string $alias If $id_supplier is not a object, this argument is same as obj->link_rewrite
* @param int $id_lang
* @return string
*/
public function getSupplierLink($id_supplier, $alias = NULL, $id_lang = NULL)
{
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (is_object($id_supplier))
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_supplier->id).'__'.$id_supplier->link_rewrite) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=supplier&id_supplier='.(int)($id_supplier->id));
if ($alias)
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_supplier).'__'.$alias) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=supplier&id_supplier='.(int)($id_supplier));
return _PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=supplier&id_supplier='.(int)($id_supplier);
{
$supplier = clone($id_supplier);
$id_supplier = $supplier->id;
$alias = $supplier->link_rewrite;
}
return $url.Dispatcher::getInstance()->createUrl('supplier_rule', array(
'id_supplier' => $id_supplier,
'text' => ($alias) ? $alias : '',
), ($alias && $this->allow));
}
/**
* Create a link to a manufacturer
*
* @param mixed $id_manufacturer ID of the manufacturer page OR a Supplier object
* @param string $alias If $id_manufacturer is not a object, this argument is same as obj->link_rewrite
* @param int $id_lang
* @return string
*/
public function getManufacturerLink($id_manufacturer, $alias = NULL, $id_lang = NULL)
{
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (is_object($id_manufacturer))
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_manufacturer->id).'_'.$id_manufacturer->link_rewrite) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=manufacturer&id_manufacturer='.(int)($id_manufacturer->id));
if ($alias)
return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_manufacturer).'_'.$alias) :
(_PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=manufacturer&id_manufacturer='.(int)($id_manufacturer));
return _PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=manufacturer&id_manufacturer='.(int)($id_manufacturer);
{
$manufacturer = clone($id_manufacturer);
$id_manufacturer = $manufacturer->id;
$alias = $manufacturer->link_rewrite;
}
return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', array(
'id_manufacturer' => $id_manufacturer,
'text' => ($alias) ? $alias : '',
), ($alias && $this->allow));
}
/**
@@ -185,59 +262,30 @@ class LinkCore
return Tools::getProtocol().Tools::getMediaServer($filepath).$filepath;
}
public function preloadPageLinks(Context $context = null)
/**
* Create a simple link
*
* @param string $controller
* @param bool $ssl
* @param int $id_lang
* @param string $request
* @param Context $context
*/
public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null, Context $context = null)
{
$controller = str_replace('.php', '', $controller);
if (!$context)
$context = Context::getContext();
if ($this->allow != 1)
return;
$result = Db::getInstance()->ExecuteS('
SELECT page, url_rewrite
FROM `'._DB_PREFIX_.'meta` m
LEFT JOIN `'._DB_PREFIX_.'meta_lang` ml ON (m.id_meta = ml.id_meta)
WHERE id_lang = '.(int)$context->language->id);
foreach ($result as $row)
self::$cache['page'][$row['page'].'.php_'.$context->language->id] = $this->getLangLink($context->language->id).$row['url_rewrite'];
}
public function getPageLink($filename, $ssl = false, $id_lang = NULL, $request = NULL, Context $context = null)
{
if (!$context)
$context = Context::getContext();
if ($id_lang == NULL)
if (!$id_lang)
$id_lang = (int)$context->language->id;
if (array_key_exists($filename.'_'.$id_lang, self::$cache['page']) AND !empty(self::$cache['page'][$filename.'_'.$id_lang]))
$uri_path = self::$cache['page'][$filename.'_'.$id_lang];
else
{
if ($this->allow == 1)
{
$url_rewrite = '';
if ($filename != 'index')
{
$pagename = $filename;
$url_rewrite = Db::getInstance()->getValue('
SELECT url_rewrite
FROM `'._DB_PREFIX_.'meta` m
LEFT JOIN `'._DB_PREFIX_.'meta_lang` ml ON (m.id_meta = ml.id_meta)
WHERE id_lang = '.(int)$id_lang.' AND `page` = \''.pSQL($pagename).'\'');
$uri_path = $this->getLangLink((int)$id_lang).($url_rewrite ? $url_rewrite : $filename);
}
else
$uri_path = $this->getLangLink((int)$id_lang);
}
else
{
$uri_path = '';
if ($filename != 'index.php')
$uri_path = 'index.php?controller='.str_replace('.php', '', $filename);
}
self::$cache['page'][$filename.'_'.$id_lang] = $uri_path;
}
return (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true)).__PS_BASE_URI__.ltrim($uri_path, '/').($request ? (($this->allow ? '?' : '&').trim($request)) : '');
$uri_path = Dispatcher::getInstance()->createUrl($controller);
$url = ($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);
$url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/');
$url .= ($request ? (($this->allow ? '?' : '&').trim($request)) : '');
return $url;
}
public function getCatImageLink($name, $id_category, $type = null)
+19 -4
View File
@@ -186,15 +186,30 @@ class ShopCore extends ObjectModel
{
// Find current shop from URL
$db = Db::getInstance();
$sql = 'SELECT s.id_shop
$sql = 'SELECT s.id_shop, su.uri
FROM '._DB_PREFIX_.'shop_url su
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
WHERE su.domain=\''.pSQL(Tools::getHttpHost()).'\'
AND uri=\''.pSQL($uri).'\'
AND s.active = 1
AND s.deleted = 0';
if (!$id_shop = $db->getValue($sql))
$id_shop = (int)Db::getInstance()->getValue('SELECT value FROM '._DB_PREFIX_.'configuration WHERE name = \'PS_SHOP_DEFAULT\'');
$default = false;
if ($results = Db::getInstance()->executeS($sql))
foreach ($results as $row)
{
if (!$default)
$default = $row;
else if (!$row['uri'])
$default = $row;
if ($uri == $row['uri'])
{
$id_shop = $row['id_shop'];
break;
}
}
if (!$id_shop)
$id_shop = ($default) ? $default['id_shop'] : (int)Db::getInstance()->getValue('SELECT value FROM '._DB_PREFIX_.'configuration WHERE name = \'PS_SHOP_DEFAULT\'');
}
// Get instance of found shop
+3 -15
View File
@@ -90,6 +90,7 @@ class ToolsCore
*/
public static function redirectLink($url)
{
$context = Context::getContext();
if (!preg_match('@^https?://@i', $url))
{
if (strpos($url, __PS_BASE_URI__) !== FALSE && strpos($url, __PS_BASE_URI__) == 0)
@@ -1634,13 +1635,6 @@ class ToolsCore
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg [L]';
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'c/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$'] = 'img/c/$1$2.jpg [L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'index.php?controller=product&id_product=$1 [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)\-[a-zA-Z0-9-]*'] = 'index.php?controller=category&id_category=$1 [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'index.php?controller=product&id_product=$1 [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)__([a-zA-Z0-9-]*)'] = 'index.php?controller=supplier&id_supplier=$1 [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)_([a-zA-Z0-9-]*)'] = 'index.php?controller=manufacturer&id_manufacturer=$1 [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'content/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'index.php?controller=cms&id_cms=$1 [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'content/category/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'index.php?controller=cms&id_cms_category=$1 [QSA,L]';
if ($multilang)
{
@@ -1658,14 +1652,6 @@ class ToolsCore
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1-$2.jpg [L]';
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$'] = 'img/c/$1$2.jpg [L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'index.php?controller=product&id_product=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'index.php?controller=product&id_product=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)\-[a-zA-Z0-9-]*'] = 'index.php?controller=category&id_category=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)__([a-zA-Z0-9-]*)'] = 'index.php?controller=supplier&id_supplier=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)_([a-zA-Z0-9-]*)'] = 'index.php?controller=manufacturer&id_manufacturer=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'content/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'index.php?controller=cms&id_cms=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'content/category/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'index.php?controller=cms&id_cms_category=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
Language::loadLanguages();
$default_meta = Meta::getMetasByIdLang((int)Configuration::get('PS_LANG_DEFAULT'), new Shop($uri['id_shop']));
@@ -1712,6 +1698,8 @@ class ToolsCore
// fwrite($writeFd, $tab['RewriteRule']['comment']."\n");
// Webservice needs apache_mod_rewrite in order to work
fwrite($writeFd, 'RewriteRule ^api/?(.*)$ '.__PS_BASE_URI__."webservice/dispatcher.php?url=$1 [QSA,L]\n");
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\nRewriteCond %{REQUEST_FILENAME} -l [OR]\nRewriteCond %{REQUEST_FILENAME} -d\nRewriteRule ^.*$ - [NC,L]\nRewriteRule ^.*\$ index.php [NC,L]\n");
foreach ($domains AS $domain => $row)
{
foreach ($row AS $uri)
+27
View File
@@ -99,6 +99,33 @@ Language::loadLanguages();
/* Loading default country */
$defaultCountry = new Country((int)(Configuration::get('PS_COUNTRY_DEFAULT')), Configuration::get('PS_LANG_DEFAULT'));
/* Instantiate cookie */
if (defined('PS_ADMIN_DIR'))
{
$currentFileName = array_reverse(explode("/", $_SERVER['SCRIPT_NAME']));
$cookie = new Cookie('psAdmin', substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($currentFileName['0'])));
}
else
$cookie = new Cookie('ps');
Context::getContext()->cookie = $cookie;
/* Instantiate language */
if (defined('PS_ADMIN_DIR'))
{
$employee = new Employee($cookie->id_employee);
Context::getContext()->employee = $employee;
$cookie->id_lang = (int)$employee->id_lang;
$language = new Language($cookie->id_lang ? $cookie->id_lang : Configuration::get('PS_LANG_DEFAULT'));
}
else
{
if (!Validate::isLoadedObject($language = new Language($cookie->id_lang)))
$language = new Language(Configuration::get('PS_LANG_DEFAULT'));
}
Context::getContext()->language = $language;
/* It is not safe to rely on the system's timezone settings, and this would generate a PHP Strict Standards notice. */
if (function_exists('date_default_timezone_set'))
@date_default_timezone_set(Configuration::get('PS_TIMEZONE'));