[+] Add a route system to personalize rewrited URL
This commit is contained in:
+24
-9
@@ -149,6 +149,9 @@ abstract class AdminTabCore
|
||||
|
||||
/** @var bool Redirect or not ater a creation */
|
||||
protected $_redirect = true;
|
||||
|
||||
/** @var bool If false, don't add form tags in options forms */
|
||||
protected $formOptions = true;
|
||||
|
||||
protected $_languages = NULL;
|
||||
protected $_defaultFormLanguage = NULL;
|
||||
@@ -1666,28 +1669,39 @@ abstract class AdminTabCore
|
||||
|
||||
/**
|
||||
* Options lists
|
||||
*
|
||||
* @param array $fieldsOptions Since 1.5.0
|
||||
* @param string $optionTitle Since 1.5.0
|
||||
*/
|
||||
public function displayOptionsList()
|
||||
public function displayOptionsList($fieldsOptions = null, $optionTitle = null, $optionDescription = null)
|
||||
{
|
||||
if (!isset($this->_fieldsOptions) OR !sizeof($this->_fieldsOptions))
|
||||
if (is_null($fieldsOptions))
|
||||
$fieldsOptions = $this->_fieldsOptions;
|
||||
|
||||
if (is_null($optionTitle))
|
||||
$optionTitle = $this->optionTitle;
|
||||
|
||||
if (!isset($fieldsOptions) OR !sizeof($fieldsOptions))
|
||||
return false;
|
||||
|
||||
$defaultLanguage = (int)$this->context->language->id;
|
||||
$this->_languages = Language::getLanguages(false);
|
||||
$tab = Tab::getTab($defaultLanguage, $this->id);
|
||||
echo '<br /><br />';
|
||||
echo (isset($this->optionTitle) ? '<h2>'.$this->optionTitle.'</h2>' : '');
|
||||
echo (isset($optionTitle) ? '<h2>'.$optionTitle.'</h2>' : '');
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
id_language = Number('.$defaultLanguage.');
|
||||
</script>
|
||||
<form action="'.self::$currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">
|
||||
'.(($this->formOptions) ? '<form action="'.self::$currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">' : '').'
|
||||
<fieldset>';
|
||||
echo (isset($this->optionTitle) ? '<legend>
|
||||
echo (isset($optionTitle) ? '<legend>
|
||||
<img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" />'
|
||||
.$this->optionTitle.'</legend>' : '');
|
||||
.$optionTitle.'</legend>' : '');
|
||||
if ($optionDescription)
|
||||
echo '<p class="optionsDescription">'.$optionDescription.'</p>';
|
||||
|
||||
foreach ($this->_fieldsOptions AS $key => $field)
|
||||
foreach ($fieldsOptions AS $key => $field)
|
||||
{
|
||||
$val = Tools::getValue($key, Configuration::get($key));
|
||||
if ($field['type'] != 'textLang')
|
||||
@@ -1767,8 +1781,9 @@ abstract class AdminTabCore
|
||||
<input type="submit" value="'.$this->l(' Save ').'" name="submitOptions'.$this->table.'" class="button" />
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="hidden" name="token" value="'.$this->token.'" />
|
||||
</form>';
|
||||
<input type="hidden" name="token" value="'.$this->token.'" />';
|
||||
if ($this->formOptions)
|
||||
echo '</form>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+118
-51
@@ -43,31 +43,70 @@ class DispatcherCore
|
||||
public $defaultRoutes = array(
|
||||
'product_rule' => array(
|
||||
'controller' => 'product',
|
||||
'rule' => '{number:id_product}-{text}.html',
|
||||
'rule' => '{category:/}{id}-{rewrite}{-:ean13}.html',
|
||||
'keywords' => array(
|
||||
'id' => array('regexp' => '[0-9]+', 'param' => 'id_product'),
|
||||
'rewrite' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'ean13' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'category' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'reference' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_keywords' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'manufacturer' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'supplier' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'price' => array('regexp' => '[0-9\.,]*'),
|
||||
'tags' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
),
|
||||
),
|
||||
'category_rule' => array(
|
||||
'controller' => 'category',
|
||||
'rule' => '{number:id_category}-{text}',
|
||||
),
|
||||
'product_rule2' => array(
|
||||
'controller' => 'product',
|
||||
'rule' => '{text1}/{number:id_product}-{text2}.html',
|
||||
'rule' => '{id}-{rewrite}',
|
||||
'keywords' => array(
|
||||
'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'),
|
||||
'rewrite' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_keywords' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
),
|
||||
),
|
||||
'supplier_rule' => array(
|
||||
'controller' => 'supplier',
|
||||
'rule' => '{number:id_supplier}__{text}',
|
||||
'rule' => '{id}__{rewrite}',
|
||||
'keywords' => array(
|
||||
'id' => array('regexp' => '[0-9]+', 'param' => 'id_supplier'),
|
||||
'rewrite' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_keywords' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
),
|
||||
),
|
||||
'manufacturer_rule' => array(
|
||||
'controller' => 'manufacturer',
|
||||
'rule' => '{number:id_manufacturer}_{text}',
|
||||
'rule' => '{id}_{rewrite}',
|
||||
'keywords' => array(
|
||||
'id' => array('regexp' => '[0-9]+', 'param' => 'id_manufacturer'),
|
||||
'rewrite' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_keywords' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
),
|
||||
),
|
||||
'cms_rule' => array(
|
||||
'controller' => 'cms',
|
||||
'rule' => 'content/{number:id_cms}-{text}',
|
||||
'rule' => 'content/{id}-{rewrite}',
|
||||
'keywords' => array(
|
||||
'id' => array('regexp' => '[0-9]+', 'param' => 'id_cms'),
|
||||
'rewrite' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_keywords' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
),
|
||||
),
|
||||
'cms_category_rule' => array(
|
||||
'controller' => 'cms',
|
||||
'rule' => 'content/category/{number:id_cms_category}-{text}',
|
||||
'rule' => 'content/category/{id}-{rewrite}',
|
||||
'keywords' => array(
|
||||
'id' => array('regexp' => '[0-9]+', 'param' => 'id_cms_category'),
|
||||
'rewrite' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_keywords' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -85,16 +124,6 @@ class DispatcherCore
|
||||
*/
|
||||
protected $routes = array();
|
||||
|
||||
/**
|
||||
* List of allowed keywords in routes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $keywords = array(
|
||||
'number' => '[0-9]+',
|
||||
'text' => '[a-zA-Z0-9-]*',
|
||||
);
|
||||
|
||||
/**
|
||||
* Current controller name
|
||||
*
|
||||
@@ -173,7 +202,7 @@ class DispatcherCore
|
||||
{
|
||||
$context = Context::getContext();
|
||||
foreach ($this->defaultRoutes as $id => $route)
|
||||
$this->addRoute($id, $route['rule'], $route['controller']);
|
||||
$this->addRoute($id, $route['rule'], $route['controller'], $route['keywords']);
|
||||
|
||||
if ($this->useRoutes)
|
||||
{
|
||||
@@ -198,7 +227,7 @@ class DispatcherCore
|
||||
// Load custom routes
|
||||
foreach ($this->defaultRoutes as $routeID => $routeData)
|
||||
if ($customRoute = Configuration::get('PS_ROUTE_'.$routeID))
|
||||
$this->addRoute($routeID, $customRoute, $routeData['controller']);
|
||||
$this->addRoute($routeID, $customRoute, $routeData['controller'], $routeData['keywords']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,44 +237,74 @@ class DispatcherCore
|
||||
* @param string $rule Url rule
|
||||
* @param string $controller Controller to call if request uri match the rule
|
||||
*/
|
||||
public function addRoute($routeID, $rule, $controller)
|
||||
{
|
||||
public function addRoute($routeID, $rule, $controller, $keywords = array())
|
||||
{
|
||||
$regexp = preg_quote($rule, '#');
|
||||
$required = array();
|
||||
preg_match_all('#\\\{('.implode('|', array_keys($this->keywords)).')[0-9]*(\\\:([a-z0-9_]+))?\\\}#', $regexp, $m);
|
||||
for ($i = 0, $total = count($m[0]); $i < $total; $i++)
|
||||
if ($m[3][$i])
|
||||
if ($keywords)
|
||||
{
|
||||
$transformKeywords = array();
|
||||
preg_match_all('#\\\{(([^{}]+)\\\:)?('.implode('|', array_keys($keywords)).')(\\\:([^{}]+))?\\\}#', $regexp, $m);
|
||||
for ($i = 0, $total = count($m[0]); $i < $total; $i++)
|
||||
{
|
||||
$regexp = str_replace($m[0][$i], '(?P<'.$m[3][$i].'>'.$this->keywords[$m[1][$i]].')', $regexp);
|
||||
$required[$m[3][$i]] = $m[1][$i];
|
||||
$prepend = $m[2][$i];
|
||||
$keyword = $m[3][$i];
|
||||
$append = $m[5][$i];
|
||||
$transformKeywords[$keyword] = array(
|
||||
'required' => isset($keywords[$keyword]['param']),
|
||||
'prepend' => stripslashes($prepend),
|
||||
'append' => stripslashes($append),
|
||||
);
|
||||
|
||||
if (isset($keywords[$keyword]['param']))
|
||||
$regexp = str_replace($m[0][$i], (($prepend) ? '('.$prepend.')?' : '').'(?P<'.$keywords[$keyword]['param'].'>'.$keywords[$keyword]['regexp'].')'.(($append) ? '('.$append.')?' : ''), $regexp);
|
||||
else
|
||||
$regexp = str_replace($m[0][$i], (($prepend) ? '('.$prepend.')?' : '').'('.$keywords[$keyword]['regexp'].')'.(($append) ? '('.$append.')?' : ''), $regexp);
|
||||
|
||||
}
|
||||
else
|
||||
$regexp = str_replace($m[0][$i], '('.$this->keywords[$m[1][$i]].')', $regexp);
|
||||
$keywords = $transformKeywords;
|
||||
}
|
||||
|
||||
$regexp = '#^/'.$regexp.'#';
|
||||
$this->routes[$routeID] = array(
|
||||
'rule' => $rule,
|
||||
'regexp' => $regexp,
|
||||
'controller' => $controller,
|
||||
'required' => $required,
|
||||
'keywords' => $keywords,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a keyword is written in a route rule
|
||||
*
|
||||
* @param string $routeID
|
||||
* @param string $keyword
|
||||
* @return bool
|
||||
*/
|
||||
public function hasKeyword($routeID, $keyword)
|
||||
{
|
||||
if (!isset($this->routes[$routeID]))
|
||||
return false;
|
||||
|
||||
return preg_match('#\{([^{}]+:)?'.preg_quote($keyword, '#').'(:[^{}])?\}#', $this->routes[$routeID]['rule']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a route rule contain all required keywords of default route definition
|
||||
*
|
||||
* @param string $routeID
|
||||
* @param string $rule Rule to verify
|
||||
* @param array $errors List of missing keywords
|
||||
*/
|
||||
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;
|
||||
|
||||
foreach ($this->defaultRoutes[$routeID]['keywords'] as $keyword => $data)
|
||||
if (isset($data['param']) && !preg_match('#\{([^{}]+:)?'.$keyword.'(:[^{}])?\}#', $rule))
|
||||
$errors[] = $keyword;
|
||||
|
||||
return (count($errors)) ? false : true;
|
||||
}
|
||||
|
||||
@@ -267,13 +326,16 @@ class DispatcherCore
|
||||
return 'index.php?controller='.$routeID.(($query) ? '&'.$query : '');
|
||||
}
|
||||
$route = $this->routes[$routeID];
|
||||
|
||||
|
||||
// Check required fields
|
||||
$queryParams = array();
|
||||
foreach (array_keys($route['required']) as $key)
|
||||
foreach ($route['keywords'] as $key => $data)
|
||||
{
|
||||
if (!$data['required'])
|
||||
continue;
|
||||
|
||||
if (!array_key_exists($key, $params))
|
||||
die("Dispatcher::createUrl() miss required parameter '$key'");
|
||||
die("Dispatcher::createUrl() miss required parameter '$key' for route '$routeID'");
|
||||
$queryParams[$key] = $params[$key];
|
||||
}
|
||||
|
||||
@@ -282,11 +344,17 @@ class DispatcherCore
|
||||
{
|
||||
$url = $route['rule'];
|
||||
foreach ($params as $key => $value)
|
||||
if (isset($route['required'][$key]))
|
||||
$url = str_replace('{'.$route['required'][$key].':'.$key.'}', $params[$key], $url);
|
||||
{
|
||||
if (!isset($route['keywords'][$key]))
|
||||
continue;
|
||||
$data = $route['keywords'][$key];
|
||||
if ($params[$key])
|
||||
$replace = $route['keywords'][$key]['prepend'].$params[$key].$route['keywords'][$key]['append'];
|
||||
else
|
||||
$url = str_replace('{'.$key.'}', $value, $url);
|
||||
$url = preg_replace('#\{[a-z0-9]+(:[a-z0-9_]+)?\}#', '', $url);
|
||||
$replace = '';
|
||||
$url = preg_replace('#\{([^{}]+:)?'.$key.'(:[^{}])?\}#', $replace, $url);
|
||||
}
|
||||
$url = preg_replace('#\{([^{}]+:)?[a-z0-9_]+?(:[^{}])?\}#', '', $url);
|
||||
}
|
||||
// Build a classic url index.php?controller=foo&...
|
||||
else
|
||||
@@ -336,7 +404,6 @@ class DispatcherCore
|
||||
$_GET[$k] = $v;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->controller = $controller;
|
||||
}
|
||||
// Default mode, take controller from url
|
||||
|
||||
+112
-89
@@ -62,98 +62,113 @@ class LinkCore
|
||||
/**
|
||||
* 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 mixed $product Product object (can be an ID product, but deprecated)
|
||||
* @param string $alias Deprecated
|
||||
* @param string $category Deprecated
|
||||
* @param string $ean13 Deprecated
|
||||
* @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)
|
||||
public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
$dispatcher = Dispatcher::getInstance();
|
||||
$url = _PS_BASE_URL_.__PS_BASE_URI__;
|
||||
|
||||
if (!$id_lang)
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
|
||||
// @todo use specific method ?
|
||||
if ($id_shop && ($shop = Shop::getShop($id_shop)))
|
||||
$url = 'http://'.$shop['domain'].'/'.$shop['uri'];
|
||||
$url .= $this->getLangLink($id_lang);
|
||||
|
||||
if (!is_object($product))
|
||||
$product = new Product($product, false, $id_lang);
|
||||
|
||||
if (is_object($id_product))
|
||||
{
|
||||
$product = clone($id_product);
|
||||
$id_product = $product->id;
|
||||
$category = $product->category;
|
||||
$alias = $product->link_rewrite;
|
||||
$ean13 = $product->ean13;
|
||||
}
|
||||
// Set available keywords
|
||||
$params = array();
|
||||
$params['id'] = $product->id;
|
||||
$params['rewrite'] = $product->link_rewrite;
|
||||
$params['ean13'] = $product->ean13;
|
||||
$params['category'] = $product->category;
|
||||
$params['meta_keywords'] = Tools::str2url($product->meta_keywords);
|
||||
$params['meta_title'] = Tools::str2url($product->meta_title);
|
||||
|
||||
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.Dispatcher::getInstance()->createUrl('product_rule', array(
|
||||
'id_product' => $id_product,
|
||||
'text' => (($alias) ? $alias : '').(($ean13) ? '-'.$ean13 : ''),
|
||||
), ($alias && $this->allow));
|
||||
if ($dispatcher->hasKeyword('product_rule', 'manufacturer'))
|
||||
$params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
|
||||
|
||||
if ($dispatcher->hasKeyword('product_rule', 'supplier'))
|
||||
$params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier));
|
||||
|
||||
if ($dispatcher->hasKeyword('product_rule', 'price'))
|
||||
$params['supplier'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, NULL, 6, NULL, false, true, 1, false, NULL, NULL, NULL, $product->specificPrice);
|
||||
|
||||
if ($dispatcher->hasKeyword('product_rule', 'tags'))
|
||||
$params['tags'] = Tools::str2url($product->getTags($id_lang));
|
||||
|
||||
return $url.$dispatcher->createUrl('product_rule', $params, $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 mixed $category Category object (can be an ID category, but deprecated)
|
||||
* @param string $alias Deprecated
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
*/
|
||||
public function getCategoryLink($id_category, $alias = NULL, $id_lang = NULL)
|
||||
public function getCategoryLink($category, $alias = NULL, $id_lang = NULL)
|
||||
{
|
||||
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
|
||||
if (is_object($id_category))
|
||||
{
|
||||
$category = clone($id_category);
|
||||
$id_category = $category->id;
|
||||
$alias = $category->link_rewrite;
|
||||
}
|
||||
if (!$id_lang)
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('category_rule', array(
|
||||
'id_category' => $id_category,
|
||||
'text' => ($alias) ? $alias : '',
|
||||
), ($alias && $this->allow));
|
||||
if (!is_object($category))
|
||||
$category = new Category($category, $id_lang);
|
||||
|
||||
// Set available keywords
|
||||
$params = array();
|
||||
$params['id'] = $category->id;
|
||||
$params['rewrite'] = $category->link_rewrite;
|
||||
$params['meta_keywords'] = Tools::str2url($category->meta_keywords);
|
||||
$params['meta_title'] = Tools::str2url($category->meta_title);
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('category_rule', $params, $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 mixed $category CMSCategory object (can be an ID category, but deprecated)
|
||||
* @param string $alias Deprecated
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
*/
|
||||
public function getCMSCategoryLink($id_category, $alias = NULL, $id_lang = NULL)
|
||||
public function getCMSCategoryLink($category, $alias = NULL, $id_lang = NULL)
|
||||
{
|
||||
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
|
||||
if (is_object($id_category))
|
||||
{
|
||||
$category = clone($id_category);
|
||||
$id_category = $category->id;
|
||||
$alias = $category->link_rewrite;
|
||||
}
|
||||
if (!$id_lang)
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('cms_category_rule', array(
|
||||
'id_cms_category' => $id_category,
|
||||
'text' => ($alias) ? $alias : '',
|
||||
), ($alias && $this->allow));
|
||||
if (!is_object($category))
|
||||
$category = new CMSCategory($category, $id_lang);
|
||||
|
||||
// Set available keywords
|
||||
$params = array();
|
||||
$params['id'] = $category->id;
|
||||
$params['rewrite'] = $category->link_rewrite;
|
||||
$params['meta_keywords'] = Tools::str2url($category->meta_keywords);
|
||||
$params['meta_title'] = Tools::str2url($category->meta_title);
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('cms_category_rule', $params, $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 mixed $cms CMS object (can be an ID CMS, but deprecated)
|
||||
* @param string $alias Deprecated
|
||||
* @param bool $ssl
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
@@ -162,67 +177,74 @@ class LinkCore
|
||||
{
|
||||
$base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true));
|
||||
$url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang);
|
||||
if (!$id_lang)
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
|
||||
if (is_object($cms))
|
||||
{
|
||||
$id_cms = $cms->id;
|
||||
$alias = $cms->link_rewrite;
|
||||
}
|
||||
else
|
||||
$id_cms = $cms;
|
||||
if (!is_object($cms))
|
||||
$cms = new CMS($cms, $id_lang);
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('cms_rule', array(
|
||||
'id_cms' => $id_cms,
|
||||
'text' => ($alias) ? $alias : '',
|
||||
), ($alias && $this->allow));
|
||||
// Set available keywords
|
||||
$params = array();
|
||||
$params['id'] = $cms->id;
|
||||
$params['rewrite'] = $cms->link_rewrite;
|
||||
$params['meta_keywords'] = Tools::str2url($cms->meta_keywords);
|
||||
$params['meta_title'] = Tools::str2url($cms->meta_title);
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('cms_rule', $params, $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 mixed $supplier Supplier object (can be an ID supplier, but deprecated)
|
||||
* @param string $alias Deprecated
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
*/
|
||||
public function getSupplierLink($id_supplier, $alias = NULL, $id_lang = NULL)
|
||||
public function getSupplierLink($supplier, $alias = NULL, $id_lang = NULL)
|
||||
{
|
||||
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
|
||||
if (is_object($id_supplier))
|
||||
{
|
||||
$supplier = clone($id_supplier);
|
||||
$id_supplier = $supplier->id;
|
||||
$alias = $supplier->link_rewrite;
|
||||
}
|
||||
if (!$id_lang)
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('supplier_rule', array(
|
||||
'id_supplier' => $id_supplier,
|
||||
'text' => ($alias) ? $alias : '',
|
||||
), ($alias && $this->allow));
|
||||
if (!is_object($supplier))
|
||||
$supplier = new Supplier($supplier, $id_lang);
|
||||
|
||||
// Set available keywords
|
||||
$params = array();
|
||||
$params['id'] = $supplier->id;
|
||||
$params['rewrite'] = $supplier->link_rewrite;
|
||||
$params['meta_keywords'] = Tools::str2url($supplier->meta_keywords);
|
||||
$params['meta_title'] = Tools::str2url($supplier->meta_title);
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('supplier_rule', $params, $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 mixed $manufacturer Manufacturer object (can be an ID supplier, but deprecated)
|
||||
* @param string $alias Deprecated
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
*/
|
||||
public function getManufacturerLink($id_manufacturer, $alias = NULL, $id_lang = NULL)
|
||||
public function getManufacturerLink($manufacturer, $alias = NULL, $id_lang = NULL)
|
||||
{
|
||||
$url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
|
||||
if (is_object($id_manufacturer))
|
||||
{
|
||||
$manufacturer = clone($id_manufacturer);
|
||||
$id_manufacturer = $manufacturer->id;
|
||||
$alias = $manufacturer->link_rewrite;
|
||||
}
|
||||
if (!$id_lang)
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', array(
|
||||
'id_manufacturer' => $id_manufacturer,
|
||||
'text' => ($alias) ? $alias : '',
|
||||
), ($alias && $this->allow));
|
||||
if (!is_object($manufacturer))
|
||||
$manufacturer = new Manufacturer($manufacturer, $id_lang);
|
||||
|
||||
// Set available keywords
|
||||
$params = array();
|
||||
$params['id'] = $manufacturer->id;
|
||||
$params['rewrite'] = $manufacturer->link_rewrite;
|
||||
$params['meta_keywords'] = Tools::str2url($manufacturer->meta_keywords);
|
||||
$params['meta_title'] = Tools::str2url($manufacturer->meta_title);
|
||||
|
||||
return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $params, $this->allow);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,6 +301,7 @@ class LinkCore
|
||||
|
||||
if (!$id_lang)
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
|
||||
if (is_array($request))
|
||||
{
|
||||
unset($request['controller']);
|
||||
|
||||
@@ -184,6 +184,8 @@ class ProductCore extends ObjectModel
|
||||
|
||||
/*** @var array Tags */
|
||||
public $tags;
|
||||
|
||||
public $isFullyLoaded = false;
|
||||
|
||||
protected $langMultiShop = true;
|
||||
|
||||
@@ -300,6 +302,7 @@ class ProductCore extends ObjectModel
|
||||
|
||||
if ($full AND $this->id)
|
||||
{
|
||||
$this->isFullyLoaded = $full;
|
||||
$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
|
||||
$this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer);
|
||||
$this->supplier_name = Supplier::getNameById((int)$this->id_supplier);
|
||||
@@ -2691,8 +2694,12 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function getTags($id_lang)
|
||||
{
|
||||
if (!$this->isFullyLoaded && is_null($this->tags))
|
||||
$this->tags = Tag::getProductTags($this->id);
|
||||
|
||||
if (!($this->tags AND key_exists($id_lang, $this->tags)))
|
||||
return '';
|
||||
|
||||
$result = '';
|
||||
foreach ($this->tags[$id_lang] AS $tagName)
|
||||
$result .= $tagName.', ';
|
||||
|
||||
Reference in New Issue
Block a user