// Routes for dispatcher (part 5)

This commit is contained in:
rMalie
2011-08-03 07:53:59 +00:00
parent 2644d41f7d
commit a1a33de41b
5 changed files with 118 additions and 21 deletions
+4 -1
View File
@@ -1693,6 +1693,9 @@ abstract class AdminTabCore
if ($field['type'] != 'textLang')
if (!Validate::isCleanHtml($val))
$val = Configuration::get($key);
if (isset($field['defaultValue']) && !$val)
$val = $field['defaultValue'];
$isDisabled = (Shop::isMultiShopActivated() && isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType()) ? true : false;
@@ -2162,7 +2165,7 @@ EOF;
$method_name = 'updateOption'.Tools::toCamelCase($key, true);
if (method_exists($this, $method_name))
$this->$method_name(Tools::getValue($key));
if (isset($options['type']) && in_array($options['type'], array('textLang', 'textareaLang')))
else if (isset($options['type']) && in_array($options['type'], array('textLang', 'textareaLang')))
{
$list = array();
foreach ($languages as $language)
+25 -2
View File
@@ -40,7 +40,7 @@ class DispatcherCore
*
* @var array
*/
protected $defaultRoutes = array(
public $defaultRoutes = array(
'product_rule' => array(
'controller' => 'product',
'rule' => '{number:id_product}-{text}.html',
@@ -175,9 +175,9 @@ class DispatcherCore
foreach ($this->defaultRoutes as $id => $route)
$this->addRoute($id, $route['rule'], $route['controller']);
// Load routes from meta table
if ($this->useRoutes)
{
// Load routes from meta table
$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').')
@@ -194,6 +194,11 @@ class DispatcherCore
'controller' => $row['page'],
);
}
// Load custom routes
foreach ($this->defaultRoutes as $routeID => $routeData)
if ($customRoute = Configuration::get('PS_ROUTE_'.$routeID))
$this->addRoute($routeID, $customRoute, $routeData['controller']);
}
}
@@ -225,6 +230,24 @@ class DispatcherCore
'required' => $required,
);
}
public function validateRoute($routeID, $rule, &$errors = array())
{
$errors = array();
if (!isset($this->defaultRoutes[$routeID]))
return false;
$required = array();
preg_match_all('#\{('.implode('|', array_keys($this->keywords)).')[0-9]*:([a-z0-9_]+)\}#', $this->defaultRoutes[$routeID]['rule'], $m);
for ($i = 0, $total = count($m[0]); $i < $total; $i++)
$required[] = $m[2][$i];
foreach ($required as $requiredKey)
if (!preg_match('#\{('.implode('|', array_keys($this->keywords)).')[0-9]*:'.$requiredKey.'\}#', $rule))
$errors[] = $requiredKey;
return (count($errors)) ? false : true;
}
/**
* Create an url from
+1 -1
View File
@@ -393,7 +393,7 @@ class FrontControllerCore
{
// $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain
$canonicalURL = $link->getPageLink($this->php_self, $this->ssl, $this->context->language->id);
$canonicalURL = $this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id);
if (!Tools::getValue('ajax') && !preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/', (($this->ssl AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))
{
header('HTTP/1.0 301 Moved');