// Merge -> revision 7941

This commit is contained in:
rMalie
2011-08-08 16:01:47 +00:00
parent d3c2a56f21
commit c61b127f66
16 changed files with 200 additions and 65 deletions
+28 -19
View File
@@ -27,35 +27,44 @@
class CmsControllerCore extends FrontController
{
public $php_self = 'cms';
public $assignCase;
public $cms;
public $cms_category;
public function canonicalRedirection()
{
// 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 (Configuration::get('PS_CANONICAL_REDIRECT'))
{
if (Validate::isLoadedObject($this->cms) AND $canonicalURL = $this->context->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 (_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 (Validate::isLoadedObject($this->cms_category) AND $canonicalURL = $this->context->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);
}
}
}
public function preProcess()
{
if ($id_cms = (int)Tools::getValue('id_cms'))
$this->cms = new CMS($id_cms, $this->context->language->id);
elseif ($id_cms_category = (int)Tools::getValue('id_cms_category'))
$this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id);
// 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 = $this->context->link->getCMSLink($this->cms))
if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', 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 = $this->context->link->getCMSCategoryLink($this->cms_category))
if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', 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);
}
$this->canonicalRedirection();
parent::preProcess();
+23 -13
View File
@@ -27,6 +27,7 @@
class CategoryControllerCore extends FrontController
{
public $php_self = 'category';
protected $category;
public function setMedia()
@@ -47,6 +48,27 @@ class CategoryControllerCore extends FrontController
parent::displayHeader();
$this->productSort();
}
public function canonicalRedirection()
{
if (Configuration::get('PS_CANONICAL_REDIRECT'))
{
// 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 (Validate::isLoadedObject($this->category))
{
$currentURL = $this->context->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);
}
}
}
}
public function preProcess()
{
@@ -58,19 +80,7 @@ class CategoryControllerCore extends FrontController
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 = $this->context->link->getCategoryLink($this->category);
$currentURL = preg_replace('/[?&].*$/', '', $currentURL);
if (!preg_match('/^'.Tools::pRegexp($currentURL, '/').'([&?].*)?$/i', 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);
}
}
$this->canonicalRedirection();
parent::preProcess();
}
+45 -21
View File
@@ -27,6 +27,7 @@
class ManufacturerControllerCore extends FrontController
{
public $php_self = 'manufacturer';
protected $manufacturer;
public function setMedia()
@@ -35,48 +36,71 @@ class ManufacturerControllerCore extends FrontController
$this->addCSS(_THEME_CSS_DIR_.'product_list.css');
}
public function process()
public function canonicalRedirection()
{
if (Validate::isLoadedObject($this->manufacturer))
{
$canonicalURL = $this->context->link->getManufacturerLink($this->manufacturer);
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);
}
}
}
public function preProcess()
{
if ($id_manufacturer = Tools::getValue('id_manufacturer'))
{
$this->manufacturer = new Manufacturer((int)$id_manufacturer, $this->context->language->id);
if (Validate::isLoadedObject($this->manufacturer) AND $this->manufacturer->active AND $this->manufacturer->isAssociatedToGroupShop())
{
$nbProducts = $this->manufacturer->getProducts($id_manufacturer, NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$nbProducts);
$this->context->smarty->assign(array(
'nb_products' => $nbProducts,
'products' => $this->manufacturer->getProducts($id_manufacturer, $this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay),
'path' => ($this->manufacturer->active ? Tools::safeOutput($this->manufacturer->name) : ''),
'manufacturer' => $this->manufacturer));
}
else
if (!Validate::isLoadedObject($this->manufacturer) OR !$this->manufacturer->active || !$this->manufacturer->isAssociatedToGroupShop())
{
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
$this->errors[] = Tools::displayError('Manufacturer does not exist.');
}
else
$this->canonicalRedirection();
}
parent::preProcess();
}
public function process()
{
if (Validate::isLoadedObject($this->manufacturer) AND $this->manufacturer->active AND $this->manufacturer->isAssociatedToGroupShop())
{
$nbProducts = $this->manufacturer->getProducts($this->manufacturer->id, NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$nbProducts);
$this->context->smarty->assign(array(
'nb_products' => $nbProducts,
'products' => $this->manufacturer->getProducts($this->manufacturer->id, $this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay),
'path' => ($this->manufacturer->active ? Tools::safeOutput($this->manufacturer->name) : ''),
'manufacturer' => $this->manufacturer));
}
else
{
if (Configuration::get('PS_DISPLAY_SUPPLIERS'))
{
$id_current_group_shop = $this->context->shop->getGroupID();
$data = call_user_func(array('Manufacturer', 'getManufacturers'), true, $this->context->language->id, true, false, false, false, $id_current_group_shop);
$data = Manufacturer::getManufacturers(true, $this->context->language->id, true, false, false, false, $id_current_group_shop);
$nbProducts = count($data);
$this->pagination($nbProducts);
$data = call_user_func(array('Manufacturer', 'getManufacturers'), true, $this->context->language->id, true, $this->p, $this->n, false, $id_current_group_shop);
$manufacturers = Manufacturer::getManufacturers(true, (int)self::$cookie->id_lang, true, $this->p, $this->n, false, $id_current_group_shop);
$imgDir = _PS_MANU_IMG_DIR_;
foreach ($data AS &$item)
$item['image'] = (!file_exists($imgDir.'/'.$item['id_manufacturer'].'-medium.jpg')) ?
$this->context->language->iso_code.'-default' : $item['id_manufacturer'];
$row['image'] = (!file_exists(_PS_MANU_IMG_DIR_.'/'.$row['id_manufacturer'].'-medium.jpg')) ? $this->context->language->iso_code.'-default' : $row['id_manufacturer'];
$this->context->smarty->assign(array(
'pages_nb' => ceil($nbProducts / (int)($this->n)),
'nbManufacturers' => $nbProducts,
'mediumSize' => Image::getSize('medium'),
'manufacturers' => $data,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'pages_nb' => ceil($nbProducts / (int)($this->n)),
'nbManufacturers' => $nbProducts,
'mediumSize' => Image::getSize('medium'),
'manufacturers' => $data,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
));
}
else
+6
View File
@@ -31,6 +31,12 @@ class StoresControllerCore extends FrontController
public function preProcess()
{
if(!extension_loaded('Dom'))
{
$this->errors[] = Tools::displayError('Dom extension is not loaded.');
$smarty->assign('errors', $this->errors);
}
$simplifiedStoreLocator = Configuration::get('PS_STORES_SIMPLIFIED');
$distanceUnit = Configuration::get('PS_DISTANCE_UNIT');
if (!in_array($distanceUnit, array('km', 'mi')))
+3
View File
@@ -39,6 +39,8 @@ class SupplierControllerCore extends FrontController
public function canonicalRedirection()
{
if (Configuration::get('PS_CANONICAL_REDIRECT'))
{
if (Validate::isLoadedObject($this->supplier))
{
$canonicalURL = self::$link->getSupplierLink($this->supplier);
@@ -51,6 +53,7 @@ class SupplierControllerCore extends FrontController
}
}
}
}
public function preProcess()
{