[*] FO : improve SEO and http error code
This commit is contained in:
@@ -150,6 +150,7 @@ abstract class ControllerCore
|
|||||||
$this->init();
|
$this->init();
|
||||||
if ($this->checkAccess())
|
if ($this->checkAccess())
|
||||||
{
|
{
|
||||||
|
|
||||||
// setMedia MUST be called before postProcess
|
// setMedia MUST be called before postProcess
|
||||||
if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className)))
|
if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className)))
|
||||||
$this->setMedia();
|
$this->setMedia();
|
||||||
|
|||||||
@@ -309,9 +309,20 @@ class AdminCmsControllerCore extends AdminController
|
|||||||
|
|
||||||
if (!$cms->active)
|
if (!$cms->active)
|
||||||
{
|
{
|
||||||
$admin_dir = dirname($_SERVER['PHP_SELF']);
|
$admin_dir = dirname($_SERVER['PHP_SELF']);
|
||||||
$admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
|
$admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
|
||||||
$preview_url .= $cms->active ? '' : '&adtoken='.Tools::getAdminTokenLite('AdminCmsContent').'&ad='.$admin_dir.'&id_employee='.(int)$this->context->employee->id;
|
|
||||||
|
$params = http_build_query(array(
|
||||||
|
'adtoken' => Tools::getAdminTokenLite('AdminCmsContent'),
|
||||||
|
'ad' => $admin_dir,
|
||||||
|
'id_employee' => (int)$this->context->employee->id)
|
||||||
|
);
|
||||||
|
if (Configuration::get('PS_REWRITING_SETTINGS'))
|
||||||
|
$params = '?'.$params;
|
||||||
|
else
|
||||||
|
$params = '&'.$params;
|
||||||
|
|
||||||
|
$preview_url .= $cms->active ? '' : $params;
|
||||||
}
|
}
|
||||||
Tools::redirectAdmin($preview_url);
|
Tools::redirectAdmin($preview_url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class CategoryControllerCore extends FrontController
|
|||||||
{
|
{
|
||||||
public $php_self = 'category';
|
public $php_self = 'category';
|
||||||
protected $category;
|
protected $category;
|
||||||
|
public $customer_access = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default medias for this controller
|
* Set default medias for this controller
|
||||||
@@ -52,6 +53,7 @@ class CategoryControllerCore extends FrontController
|
|||||||
|
|
||||||
public function canonicalRedirection($canonicalURL = '')
|
public function canonicalRedirection($canonicalURL = '')
|
||||||
{
|
{
|
||||||
|
return ;
|
||||||
if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop())
|
if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop())
|
||||||
{
|
{
|
||||||
$this->redirect_after = '404';
|
$this->redirect_after = '404';
|
||||||
@@ -76,15 +78,31 @@ class CategoryControllerCore extends FrontController
|
|||||||
$this->category = new Category($id_category, $this->context->language->id);
|
$this->category = new Category($id_category, $this->context->language->id);
|
||||||
|
|
||||||
parent::init();
|
parent::init();
|
||||||
|
//check if the category is active and return 404 error if is disable.
|
||||||
|
if (!$this->category->active)
|
||||||
|
{
|
||||||
|
header('HTTP/1.1 404 Not Found');
|
||||||
|
header('Status: 404 Not Found');
|
||||||
|
}
|
||||||
|
//check if category can be accessible by current customer and return 403 if not
|
||||||
if (!$this->category->checkAccess($this->context->customer->id))
|
if (!$this->category->checkAccess($this->context->customer->id))
|
||||||
|
{
|
||||||
|
header('HTTP/1.1 403 Forbidden');
|
||||||
|
header('Status: 403 Forbidden');
|
||||||
$this->errors[] = Tools::displayError('You do not have access to this category.');
|
$this->errors[] = Tools::displayError('You do not have access to this category.');
|
||||||
|
$this->customer_access = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initContent()
|
public function initContent()
|
||||||
{
|
{
|
||||||
parent::initContent();
|
parent::initContent();
|
||||||
|
|
||||||
|
$this->setTemplate(_PS_THEME_DIR_.'category.tpl');
|
||||||
|
|
||||||
|
if (!$this->customer_access)
|
||||||
|
return;
|
||||||
|
|
||||||
if (isset($this->context->cookie->id_compare))
|
if (isset($this->context->cookie->id_compare))
|
||||||
$this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare));
|
$this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare));
|
||||||
|
|
||||||
@@ -111,9 +129,6 @@ class CategoryControllerCore extends FrontController
|
|||||||
'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
|
'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
|
||||||
'suppliers' => Supplier::getSuppliers()
|
'suppliers' => Supplier::getSuppliers()
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
$this->setTemplate(_PS_THEME_DIR_.'category.tpl');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,16 +51,28 @@ class CmsControllerCore extends FrontController
|
|||||||
$this->cms = new CMS($id_cms, $this->context->language->id);
|
$this->cms = new CMS($id_cms, $this->context->language->id);
|
||||||
else if ($id_cms_category = (int)Tools::getValue('id_cms_category'))
|
else if ($id_cms_category = (int)Tools::getValue('id_cms_category'))
|
||||||
$this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id);
|
$this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id);
|
||||||
|
|
||||||
$this->canonicalRedirection();
|
$this->canonicalRedirection();
|
||||||
|
|
||||||
/* assignCase (1 = CMS page, 2 = CMS category) */
|
// assignCase (1 = CMS page, 2 = CMS category)
|
||||||
if (Validate::isLoadedObject($this->cms)
|
if (Validate::isLoadedObject($this->cms))
|
||||||
&& ($this->cms->isAssociatedToShop() && $this->cms->active || (Tools::getValue('adtoken') == Tools::getAdminToken('AdminCmsContent'.(int)Tab::getIdFromClassName('AdminCmsContent').(int)Tools::getValue('id_employee')))))
|
{
|
||||||
$this->assignCase = 1;
|
$adtoken = Tools::getAdminToken('AdminCmsContent'.(int)Tab::getIdFromClassName('AdminCmsContent').(int)Tools::getValue('id_employee'));
|
||||||
|
if (!$this->cms->isAssociatedToShop() || !$this->cms->active && Tools::getValue('adtoken') != $adtoken)
|
||||||
|
{
|
||||||
|
header('HTTP/1.1 404 Not Found');
|
||||||
|
header('Status: 404 Not Found');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->assignCase = 1;
|
||||||
|
}
|
||||||
else if (Validate::isLoadedObject($this->cms_category))
|
else if (Validate::isLoadedObject($this->cms_category))
|
||||||
$this->assignCase = 2;
|
$this->assignCase = 2;
|
||||||
else
|
else
|
||||||
Tools::redirect('index.php?controller=404');
|
{
|
||||||
|
header('HTTP/1.1 404 Not Found');
|
||||||
|
header('Status: 404 Not Found');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMedia()
|
public function setMedia()
|
||||||
@@ -87,7 +99,7 @@ class CmsControllerCore extends FrontController
|
|||||||
$this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID'));
|
$this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID'));
|
||||||
if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category)
|
if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category)
|
||||||
$path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS');
|
$path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS');
|
||||||
else
|
else if (isset($this->cms_category->meta_title))
|
||||||
$path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS');
|
$path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS');
|
||||||
if ($this->assignCase == 1)
|
if ($this->assignCase == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -67,6 +67,8 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{else}
|
{else}
|
||||||
{l s='This page does not exist.'}
|
<div class="error">
|
||||||
|
{l s='This page does not exist.'}
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<br />
|
<br />
|
||||||
Reference in New Issue
Block a user