// Move and refacto Tools::getMetaTags(), Tools::getHomeMetaTags() and Tools::completeMetaTags() to Meta class

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14938 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2012-04-27 08:46:52 +00:00
parent cd2f333d6e
commit d1e8a28f2b
4 changed files with 292 additions and 194 deletions
+233 -6
View File
@@ -45,7 +45,7 @@ class MetaCore extends ObjectModel
'fields' => array( 'fields' => array(
'page' => array('type' => self::TYPE_STRING, 'validate' => 'isFileName', 'required' => true, 'size' => 64), 'page' => array('type' => self::TYPE_STRING, 'validate' => 'isFileName', 'required' => true, 'size' => 64),
// Lang fields /* Lang fields */
'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
@@ -105,11 +105,8 @@ class MetaCore extends ObjectModel
} }
public static function getMetaByPage($page, $id_lang, Context $context = null) public static function getMetaByPage($page, $id_lang)
{ {
if (!$context)
$context = Context::getContext();
$sql = 'SELECT * $sql = 'SELECT *
FROM '._DB_PREFIX_.'meta m FROM '._DB_PREFIX_.'meta m
LEFT JOIN '._DB_PREFIX_.'meta_lang ml on (m.id_meta = ml.id_meta) LEFT JOIN '._DB_PREFIX_.'meta_lang ml on (m.id_meta = ml.id_meta)
@@ -163,5 +160,235 @@ class MetaCore extends ObjectModel
AND id_lang = '.(int)$new_id_lang.' AND id_lang = '.(int)$new_id_lang.'
AND id_shop = '.Context::getContext()->shop->id); AND id_shop = '.Context::getContext()->shop->id);
} }
}
/**
* @since 1.5.0
*/
public static function getMetaTags($id_lang, $page_name, $title = '')
{
global $maintenance;
if (!(isset($maintenance) && (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))))
{
if ($id_product = Tools::getValue('id_product'))
return Meta::getProductMetas($id_product, $id_lang, $page_name);
else if ($id_category = Tools::getValue('id_category'))
return Meta::getCategoryMetas($id_category, $id_lang, $page_name, $title);
else if ($id_manufacturer = Tools::getValue('id_manufacturer'))
return Meta::getManufacturerMetas($id_manufacturer, $id_lang, $page_name);
else if ($id_supplier = Tools::getValue('id_supplier'))
return Meta::getSupplierMetas($id_supplier, $id_lang, $page_name);
else if ($id_cms = Tools::getValue('id_cms'))
return Meta::getCmsMetas($id_cms, $id_lang, $page_name);
else if ($id_cms_category = Tools::getValue('id_cms_category'))
return Meta::getCmsCategoryMetas($id_cms_category, $id_lang, $page_name);
}
return Meta::getHomeMetaTags($id_lang, $page_name);
}
/**
* Get meta tags for a given page
*
* @since 1.5.0
* @param int $id_lang
* @param string $page_name
* @return array Meta tags
*/
public static function getHomeMetas($id_lang, $page_name)
{
$metas = Meta::getMetaByPage($page_name, $id_lang);
$ret['meta_title'] = (isset($metas['title']) && $metas['title']) ? $metas['title'].' - '.Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME');
$ret['meta_description'] = (isset($metas['description']) && $metas['description']) ? $metas['description'] : '';
$ret['meta_keywords'] = (isset($metas['keywords']) && $metas['keywords']) ? $metas['keywords'] : '';
return $ret;
}
/**
* Get product meta tags
*
* @since 1.5.0
* @param int $id_product
* @param int $id_lang
* @param string $page_name
* @return array
*/
public static function getProductMetas($id_product, $id_lang, $page_name)
{
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description_short`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`'.Shop::addSqlRestrictionOnLang('pl').')
'.Shop::addSqlAssociation('product', 'p').'
WHERE pl.id_lang = '.(int)$id_lang.'
AND pl.id_product = '.(int)$id_product.'
AND product_shop.active = 1';
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['description_short']);
return Meta::completeMetaTags($row, $row['name']);
}
return Meta::getHomeMetas($id_lang, $page_name);
}
/**
* Get category meta tags
*
* @since 1.5.0
* @param int $id_category
* @param int $id_lang
* @param string $page_name
* @return array
*/
public static function getCategoryMetas($id_category, $id_lang, $page_name, $title = '')
{
if (!empty($title))
$title = ' - '.$title;
$page_number = (int)Tools::getValue('p');
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
FROM `'._DB_PREFIX_.'category_lang` cl
WHERE cl.`id_lang` = '.(int)$id_lang.'
AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl');
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['description']);
// Paginate title
if (!empty($row['meta_title']))
$row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
else
$row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
if (!empty($title))
$row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
return Meta::completeMetaTags($row, $row['name']);
}
return Meta::getHomeMetas($id_lang, $page_name);
}
/**
* Get manufacturer meta tags
*
* @since 1.5.0
* @param int $id_manufacturer
* @param int $id_lang
* @param string $page_name
* @return array
*/
public static function getManufacturerMetas($id_manufacturer, $id_lang, $page_name)
{
$page_number = (int)Tools::getValue('p');
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'manufacturer_lang` ml
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (ml.`id_manufacturer` = m.`id_manufacturer`)
WHERE ml.id_lang = '.(int)$id_lang.'
AND ml.id_manufacturer = '.(int)$id_manufacturer;
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['meta_description']);
$row['meta_title'] .= $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '');
$row['meta_title'] .= ' - '.Configuration::get('PS_SHOP_NAME');
return Meta::completeMetaTags($row, $row['meta_title']);
}
return Meta::getHomeMetas($id_lang, $page_name);
}
/**
* Get supplier meta tags
*
* @since 1.5.0
* @param int $id_supplier
* @param int $id_lang
* @param string $page_name
* @return array
*/
public static function getSupplierMetas($id_supplier, $id_lang, $page_name)
{
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'supplier_lang` sl
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (sl.`id_supplier` = s.`id_supplier`)
WHERE sl.id_lang = '.(int)$id_lang.'
AND sl.id_supplier = '.(int)$id_supplier;
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['meta_description']);
if (!empty($row['meta_title']))
$row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
return Meta::completeMetaTags($row, $row['name']);
}
return Meta::getHomeMetas($id_lang, $page_name);
}
/**
* Get CMS meta tags
*
* @since 1.5.0
* @param int $id_cms
* @param int $id_lang
* @param string $page_name
* @return array
*/
public static function getCmsMetas($id_cms, $id_lang, $page_name)
{
$sql = 'SELECT `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'cms_lang`
WHERE id_lang = '.(int)$id_lang.'
AND id_cms = '.(int)$id_cms;
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
{
$row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
return Meta::completeMetaTags($row, $row['meta_title']);
}
return Meta::getHomeMetas($id_lang, $page_name);
}
/**
* Get CMS category meta tags
*
* @since 1.5.0
* @param int $id_cms_category
* @param int $id_lang
* @param string $page_name
* @return array
*/
public static function getCmsCategoryMetas($id_cms_category, $id_lang, $page_name)
{
$sql = 'SELECT `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'cms_category_lang`
WHERE id_lang = '.(int)$id_lang.'
AND id_cms_category = '.(int)$id_cms_category;
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
{
$row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
return Meta::completeMetaTags($row, $row['meta_title']);
}
return Meta::getHomeMetas($id_lang, $page_name);
}
/**
* @since 1.5.0
*/
public static function completeMetaTags($meta_tags, $default_value, Context $context = null)
{
if (!$context)
$context = Context::getContext();
if (empty($meta_tags['meta_title']))
$meta_tags['meta_title'] = $default_value.' - '.Configuration::get('PS_SHOP_NAME');
if (empty($meta_tags['meta_description']))
$meta_tags['meta_description'] = Configuration::get('PS_META_DESCRIPTION', $context->language->id) ? Configuration::get('PS_META_DESCRIPTION', $context->language->id) : '';
if (empty($meta_tags['meta_keywords']))
$meta_tags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', $context->language->id) ? Configuration::get('PS_META_KEYWORDS', $context->language->id) : '';
return $meta_tags;
}
}
+14 -148
View File
@@ -744,164 +744,30 @@ class ToolsCore
} }
/** /**
* Get meta tages for a given page * @deprecated 1.5.0
* */
* @param integer $id_lang Language id
* @return array Meta tags
*/
public static function getMetaTags($id_lang, $page_name, $title = '') public static function getMetaTags($id_lang, $page_name, $title = '')
{ {
global $maintenance; Tools::displayAsDeprecated();
return Meta::getMetaTags($id_lang, $page_name, $title);
if (!(isset($maintenance) && (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))))
{
/* Products specifics meta tags */
if ($id_product = Tools::getValue('id_product'))
{
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description_short`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`'.Shop::addSqlRestrictionOnLang('pl').')
'.Shop::addSqlAssociation('product', 'p').'
WHERE pl.id_lang = '.(int)$id_lang.'
AND pl.id_product = '.(int)$id_product.'
AND product_shop.active = 1';
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if ($row)
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['description_short']);
return Tools::completeMetaTags($row, $row['name']);
}
}
/* Categories specifics meta tags */
else if ($id_category = Tools::getValue('id_category'))
{
if (!empty($title))
$title = ' - '.$title;
$page_number = (int)Tools::getValue('p');
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
FROM `'._DB_PREFIX_.'category_lang` cl
WHERE cl.`id_lang` = '.(int)($id_lang).' AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl'));
if ($row)
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['description']);
// Paginate title
if (!empty($row['meta_title']))
$row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
else
$row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
if (!empty($title))
$row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
return Tools::completeMetaTags($row, $row['name']);
}
}
/* Manufacturers specifics meta tags */
else if ($id_manufacturer = Tools::getValue('id_manufacturer'))
{
$page_number = (int)Tools::getValue('p');
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'manufacturer_lang` ml
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (ml.`id_manufacturer` = m.`id_manufacturer`)
WHERE ml.id_lang = '.(int)($id_lang).' AND ml.id_manufacturer = '.(int)($id_manufacturer));
if ($row)
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['meta_description']);
$row['meta_title'] .= $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '');
$row['meta_title'] .= ' - '.Configuration::get('PS_SHOP_NAME');
return Tools::completeMetaTags($row, $row['meta_title']);
}
}
/* Suppliers specifics meta tags */
else if ($id_supplier = Tools::getValue('id_supplier'))
{
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'supplier_lang` sl
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (sl.`id_supplier` = s.`id_supplier`)
WHERE sl.id_lang = '.(int)($id_lang).' AND sl.id_supplier = '.(int)($id_supplier));
if ($row)
{
if (empty($row['meta_description']))
$row['meta_description'] = strip_tags($row['meta_description']);
if (!empty($row['meta_title']))
$row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
return Tools::completeMetaTags($row, $row['name']);
}
}
/* CMS specifics meta tags */
else if ($id_cms = Tools::getValue('id_cms'))
{
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'cms_lang`
WHERE id_lang = '.(int)($id_lang).' AND id_cms = '.(int)($id_cms));
if ($row)
{
$row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
return Tools::completeMetaTags($row, $row['meta_title']);
}
}
/* CMS category specifics meta tags */
else if ($id_cms = Tools::getValue('id_cms_category'))
{
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `meta_title`, `meta_description`, `meta_keywords`
FROM `'._DB_PREFIX_.'cms_category_lang`
WHERE id_lang = '.(int)($id_lang).' AND id_cms_category = '.(int)($id_cms));
if ($row)
{
$row['meta_title'] = $row['meta_title'].' - '.Configuration::get('PS_SHOP_NAME');
return Tools::completeMetaTags($row, $row['meta_title']);
}
}
}
/* Default meta tags */
return Tools::getHomeMetaTags($id_lang, $page_name);
} }
/** /**
* Get meta tags for a given page * @deprecated 1.5.0
* */
* @param integer $id_lang Language id
* @return array Meta tags
*/
public static function getHomeMetaTags($id_lang, $page_name) public static function getHomeMetaTags($id_lang, $page_name)
{ {
/* Metas-tags */ Tools::displayAsDeprecated();
$metas = Meta::getMetaByPage($page_name, $id_lang); return Meta::getHomeMetas($id_lang, $page_name);
$ret['meta_title'] = (isset($metas['title']) && $metas['title']) ? $metas['title'].' - '.Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME');
$ret['meta_description'] = (isset($metas['description']) && $metas['description']) ? $metas['description'] : '';
$ret['meta_keywords'] = (isset($metas['keywords']) && $metas['keywords']) ? $metas['keywords'] : '';
return $ret;
} }
/**
public static function completeMetaTags($metaTags, $defaultValue, Context $context = null) * @deprecated 1.5.0
*/
public static function completeMetaTags($meta_tags, $default_value, Context $context = null)
{ {
if (!$context) Tools::displayAsDeprecated();
$context = Context::getContext(); return Meta::completeMetaTags($meta_tags, $default_value, $context);
if (empty($metaTags['meta_title']))
$metaTags['meta_title'] = $defaultValue.' - '.Configuration::get('PS_SHOP_NAME');
if (empty($metaTags['meta_description']))
$metaTags['meta_description'] = Configuration::get('PS_META_DESCRIPTION', $context->language->id) ? Configuration::get('PS_META_DESCRIPTION', $context->language->id) : '';
if (empty($metaTags['meta_keywords']))
$metaTags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', $context->language->id) ? Configuration::get('PS_META_KEYWORDS', $context->language->id) : '';
return $metaTags;
} }
/** /**
+1 -1
View File
@@ -272,7 +272,7 @@ class FrontControllerCore extends Controller
$page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name; $page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name;
} }
$this->context->smarty->assign(Tools::getMetaTags($this->context->language->id, $page_name)); $this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
$this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); $this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
/* Breadcrumb */ /* Breadcrumb */
+44 -39
View File
@@ -1215,8 +1215,9 @@ class BlockLayered extends Module
{ {
if (!empty($val['title'])) if (!empty($val['title']))
$val['title'] = $val['title'].' '; $val['title'] = $val['title'].' ';
foreach ($val['values'] as $value) { foreach ($val['values'] as $value)
{
$title .= $category_title.' '.$val['title'].$value.' - '; $title .= $category_title.' '.$val['title'].$value.' - ';
$description .= $category_title.' '.$val['title'].$value.', '; $description .= $category_title.' '.$val['title'].$value.', ';
$keywords .= $val['title'].$value.', '; $keywords .= $val['title'].$value.', ';
@@ -1227,8 +1228,11 @@ class BlockLayered extends Module
// Title attributes (ex: <attr1> <value1>/<value2>, <attr2> <value1>) // Title attributes (ex: <attr1> <value1>/<value2>, <attr2> <value1>)
$description = strtolower(rtrim(substr($description, 0, -2))); $description = strtolower(rtrim(substr($description, 0, -2)));
// kewords attributes (ex: <attr1> <value1>, <attr1> <value2>, <attr2> <value1>) // kewords attributes (ex: <attr1> <value1>, <attr1> <value2>, <attr2> <value1>)
$category_metas = Tools::getMetaTags($id_lang, '', $title); if (version_compare(_PS_VERSION_, '1.5', '>'))
$category_metas = Meta::getMetaTags($id_lang, '', $title);
else
$category_metas = Tools::getMetaTags($id_lang, '', $title);
if (!empty($title)) if (!empty($title))
{ {
$smarty->assign('meta_title', ucfirst(substr($category_metas['meta_title'], 3))); $smarty->assign('meta_title', ucfirst(substr($category_metas['meta_title'], 3)));
@@ -1236,12 +1240,12 @@ class BlockLayered extends Module
} }
else else
$smarty->assign('meta_title', $category_metas['meta_title']); $smarty->assign('meta_title', $category_metas['meta_title']);
$keywords = substr(strtolower($keywords), 0, 1000); $keywords = substr(strtolower($keywords), 0, 1000);
if (!empty($keywords)) if (!empty($keywords))
$smarty->assign('meta_keywords', rtrim($category_title.', '.$keywords.', '.$category_metas['meta_keywords'], ', ')); $smarty->assign('meta_keywords', rtrim($category_title.', '.$keywords.', '.$category_metas['meta_keywords'], ', '));
if (version_compare(_PS_VERSION_,'1.5','>')) if (version_compare(_PS_VERSION_, '1.5', '>'))
{ {
$this->context->controller->addJS(($this->_path).'blocklayered.js'); $this->context->controller->addJS(($this->_path).'blocklayered.js');
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js'); $this->context->controller->addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js');
@@ -1257,9 +1261,9 @@ class BlockLayered extends Module
Tools::addCSS(($this->_path).'blocklayered.css', 'all'); Tools::addCSS(($this->_path).'blocklayered.css', 'all');
Tools::addJS(_PS_JS_DIR_.'jquery/jquery.scrollTo-1.4.2-min.js'); Tools::addJS(_PS_JS_DIR_.'jquery/jquery.scrollTo-1.4.2-min.js');
} }
$filters = $this->getSelectedFilters(); $filters = $this->getSelectedFilters();
// Get non indexable attributes // Get non indexable attributes
$attribute_group_list = Db::getInstance()->executeS('SELECT id_attribute_group FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE indexable = 0'); $attribute_group_list = Db::getInstance()->executeS('SELECT id_attribute_group FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE indexable = 0');
// Get non indexable features // Get non indexable features
@@ -1267,7 +1271,7 @@ class BlockLayered extends Module
$attributes = array(); $attributes = array();
$features = array(); $features = array();
$blacklist = array('weight', 'price'); $blacklist = array('weight', 'price');
if (!Configuration::get('PS_LAYERED_FILTER_INDEX_CDT')) if (!Configuration::get('PS_LAYERED_FILTER_INDEX_CDT'))
$blacklist[] = 'condition'; $blacklist[] = 'condition';
@@ -1275,16 +1279,17 @@ class BlockLayered extends Module
$blacklist[] = 'quantity'; $blacklist[] = 'quantity';
if (!Configuration::get('PS_LAYERED_FILTER_INDEX_MNF')) if (!Configuration::get('PS_LAYERED_FILTER_INDEX_MNF'))
$blacklist[] = 'manufacturer'; $blacklist[] = 'manufacturer';
foreach ($filters as $type => $val) foreach ($filters as $type => $val)
{ {
switch($type) switch ($type)
{ {
case 'id_attribute_group': case 'id_attribute_group':
foreach ($val as $attr) foreach ($val as $attr)
{ {
$attr_id = preg_replace('/_\d+$/', '', $attr); $attr_id = preg_replace('/_\d+$/', '', $attr);
if (in_array($attr_id, $attributes) || in_array(array('id_attribute_group' => $attr_id), $attribute_group_list)) { if (in_array($attr_id, $attributes) || in_array(array('id_attribute_group' => $attr_id), $attribute_group_list))
{
$smarty->assign('nobots', true); $smarty->assign('nobots', true);
$smarty->assign('nofollow', true); $smarty->assign('nofollow', true);
return; return;
@@ -1296,7 +1301,8 @@ class BlockLayered extends Module
foreach ($val as $feat) foreach ($val as $feat)
{ {
$feat_id = preg_replace('/_\d+$/', '', $feat); $feat_id = preg_replace('/_\d+$/', '', $feat);
if (in_array($feat_id, $features) || in_array(array('id_feature' => $feat_id), $feature_list)) { if (in_array($feat_id, $features) || in_array(array('id_feature' => $feat_id), $feature_list))
{
$smarty->assign('nobots', true); $smarty->assign('nobots', true);
$smarty->assign('nofollow', true); $smarty->assign('nofollow', true);
return; return;
@@ -1321,7 +1327,7 @@ class BlockLayered extends Module
} }
} }
} }
public function hookFooter($params) public function hookFooter($params)
{ {
if (basename($_SERVER['PHP_SELF']) == 'category.php') if (basename($_SERVER['PHP_SELF']) == 'category.php')
@@ -1389,7 +1395,7 @@ class BlockLayered extends Module
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)Tools::getValue('id_layered_filter')); Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)Tools::getValue('id_layered_filter'));
$this->buildLayeredCategories(); $this->buildLayeredCategories();
} }
if (Tools::getValue('scope') == 1) if (Tools::getValue('scope') == 1)
{ {
Db::getInstance()->execute('TRUNCATE TABLE '._DB_PREFIX_.'layered_filter'); Db::getInstance()->execute('TRUNCATE TABLE '._DB_PREFIX_.'layered_filter');
@@ -1397,13 +1403,13 @@ class BlockLayered extends Module
foreach ($categories as $category) foreach ($categories as $category)
$_POST['categoryBox'][] = (int)$category['id_category']; $_POST['categoryBox'][] = (int)$category['id_category'];
} }
if (version_compare(_PS_VERSION_,'1.5','>')) if (version_compare(_PS_VERSION_, '1.5', '>'))
{ {
$id_layered_filter = (int)$_POST['id_layered_filter']; $id_layered_filter = (int)$_POST['id_layered_filter'];
if (!$id_layered_filter) if (!$id_layered_filter)
$id_layered_filter = (int)Db::getInstance()->Insert_ID(); $id_layered_filter = (int)Db::getInstance()->Insert_ID();
$shop_list = array(); $shop_list = array();
if (isset($_POST['checkBoxShopAsso_layered_filter'])) if (isset($_POST['checkBoxShopAsso_layered_filter']))
{ {
@@ -1421,19 +1427,19 @@ class BlockLayered extends Module
} }
else else
$shop_list = array(0); $shop_list = array(0);
if (count($_POST['categoryBox'])) if (count($_POST['categoryBox']))
{ {
/* Clean categoryBox before use */ /* Clean categoryBox before use */
if (isset($_POST['categoryBox']) && is_array($_POST['categoryBox'])) if (isset($_POST['categoryBox']) && is_array($_POST['categoryBox']))
foreach ($_POST['categoryBox'] as &$category_box_tmp) foreach ($_POST['categoryBox'] as &$category_box_tmp)
$category_box_tmp = (int)$category_box_tmp; $category_box_tmp = (int)$category_box_tmp;
$filter_values = array(); $filter_values = array();
foreach ($_POST['categoryBox'] as $idc) foreach ($_POST['categoryBox'] as $idc)
$filter_values['categories'][] = (int)$idc; $filter_values['categories'][] = (int)$idc;
$filter_values['shop_list'] = $shop_list; $filter_values['shop_list'] = $shop_list;
$values = false; $values = false;
foreach ($_POST['categoryBox'] as $id_category_layered) foreach ($_POST['categoryBox'] as $id_category_layered)
{ {
@@ -1447,16 +1453,15 @@ class BlockLayered extends Module
$type = Tools::getValue($key.'_filter_type'); $type = Tools::getValue($key.'_filter_type');
if (Tools::getValue($key.'_filter_show_limit')) if (Tools::getValue($key.'_filter_show_limit'))
$limit = Tools::getValue($key.'_filter_show_limit'); $limit = Tools::getValue($key.'_filter_show_limit');
$filter_values[$key] = array( $filter_values[$key] = array(
'filter_type' => (int)$type, 'filter_type' => (int)$type,
'filter_show_limit' => (int)$limit 'filter_show_limit' => (int)$limit
); );
} }
} }
if (version_compare(_PS_VERSION_, '1.5', '>'))
if (version_compare(_PS_VERSION_,'1.5','>'))
{ {
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter_shop WHERE `id_layered_filter` = '.(int)$id_layered_filter); Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter_shop WHERE `id_layered_filter` = '.(int)$id_layered_filter);
if (isset($assos)) if (isset($assos))
@@ -1464,7 +1469,7 @@ class BlockLayered extends Module
Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'layered_filter_shop (`id_layered_filter`, `id_shop`) Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'layered_filter_shop (`id_layered_filter`, `id_shop`)
VALUES('.$id_layered_filter.', '.(int)$asso['id_shop'].')'); VALUES('.$id_layered_filter.', '.(int)$asso['id_shop'].')');
} }
$values_to_insert = array( $values_to_insert = array(
'name' => pSQL(Tools::getValue('layered_tpl_name')), 'name' => pSQL(Tools::getValue('layered_tpl_name')),
'filters' => pSQL(serialize($filter_values)), 'filters' => pSQL(serialize($filter_values)),
@@ -1472,7 +1477,7 @@ class BlockLayered extends Module
'date_add' => date('Y-m-d H:i:s')); 'date_add' => date('Y-m-d H:i:s'));
if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter'])
$values_to_insert['id_layered_filter'] = (int)Tools::getValue('id_layered_filter'); $values_to_insert['id_layered_filter'] = (int)Tools::getValue('id_layered_filter');
Db::getInstance()->autoExecute(_DB_PREFIX_.'layered_filter', $values_to_insert, 'INSERT'); Db::getInstance()->autoExecute(_DB_PREFIX_.'layered_filter', $values_to_insert, 'INSERT');
$this->buildLayeredCategories(); $this->buildLayeredCategories();
@@ -1492,7 +1497,7 @@ class BlockLayered extends Module
Configuration::updateValue('PS_LAYERED_FILTER_INDEX_QTY', (int)Tools::getValue('ps_layered_filter_index_availability')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_QTY', (int)Tools::getValue('ps_layered_filter_index_availability'));
Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CDT', (int)Tools::getValue('ps_layered_filter_index_condition')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CDT', (int)Tools::getValue('ps_layered_filter_index_condition'));
Configuration::updateValue('PS_LAYERED_FILTER_INDEX_MNF', (int)Tools::getValue('ps_layered_filter_index_manufacturer')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_MNF', (int)Tools::getValue('ps_layered_filter_index_manufacturer'));
$html .= ' $html .= '
<div class="conf">'. <div class="conf">'.
(version_compare(_PS_VERSION_,'1.5','>') ? '' : '<img src="../img/admin/ok2.png" alt="" />').$this->l('Settings saved successfully').' (version_compare(_PS_VERSION_,'1.5','>') ? '' : '<img src="../img/admin/ok2.png" alt="" />').$this->l('Settings saved successfully').'
@@ -1509,7 +1514,7 @@ class BlockLayered extends Module
{ {
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$_GET['id_layered_filter'].' LIMIT 1'); Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$_GET['id_layered_filter'].' LIMIT 1');
$this->buildLayeredCategories(); $this->buildLayeredCategories();
$html .= ' $html .= '
<div class="conf">'.(version_compare(_PS_VERSION_,'1.5','>') ? '' : '<img src="../img/admin/ok2.png" alt="" />').' <div class="conf">'.(version_compare(_PS_VERSION_,'1.5','>') ? '' : '<img src="../img/admin/ok2.png" alt="" />').'
'.$this->l('Filter template deleted, categories updated (reverted to default Filter template).').' '.$this->l('Filter template deleted, categories updated (reverted to default Filter template).').'
@@ -1523,7 +1528,7 @@ class BlockLayered extends Module
</div>'; </div>';
} }
} }
$html .= ' $html .= '
<div id="ajax-message-ok" class="conf ajax-message" style="display: none"> <div id="ajax-message-ok" class="conf ajax-message" style="display: none">
'.(version_compare(_PS_VERSION_,'1.5','>') ? '' : '<img src="../img/admin/ok2.png" alt="" />').'<span class="message"></span> '.(version_compare(_PS_VERSION_,'1.5','>') ? '' : '<img src="../img/admin/ok2.png" alt="" />').'<span class="message"></span>
@@ -1536,8 +1541,8 @@ class BlockLayered extends Module
<legend><img src="../img/admin/cog.gif" alt="" />'.$this->l('Indexes and caches').'</legend> <legend><img src="../img/admin/cog.gif" alt="" />'.$this->l('Indexes and caches').'</legend>
<span id="indexing-warning" style="display: none; color:red; font-weight: bold">'.$this->l('Indexing is in progress. Please do not leave this page').'<br/><br/></span>'; <span id="indexing-warning" style="display: none; color:red; font-weight: bold">'.$this->l('Indexing is in progress. Please do not leave this page').'<br/><br/></span>';
if (version_compare(_PS_VERSION_,'1.5','<') &&!Configuration::get('PS_LAYERED_INDEXED') if (version_compare(_PS_VERSION_, '1.5', '<') &&!Configuration::get('PS_LAYERED_INDEXED')
|| version_compare(_PS_VERSION_,'1.5','>') && !Configuration::getGlobalValue('PS_LAYERED_INDEXED')) || version_compare(_PS_VERSION_, '1.5', '>') && !Configuration::getGlobalValue('PS_LAYERED_INDEXED'))
$html .= ' $html .= '
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
@@ -1550,12 +1555,12 @@ class BlockLayered extends Module
foreach (Db::getInstance()->executeS('SELECT id_category FROM `'._DB_PREFIX_.'category`') as $category) foreach (Db::getInstance()->executeS('SELECT id_category FROM `'._DB_PREFIX_.'category`') as $category)
if ($category['id_category'] != 1) if ($category['id_category'] != 1)
$category_ist[] = $category['id_category']; $category_ist[] = $category['id_category'];
if (Tools::usingSecureMode()) if (Tools::usingSecureMode())
$domain = Tools::getShopDomainSsl(true); $domain = Tools::getShopDomainSsl(true);
else else
$domain = Tools::getShopDomain(true); $domain = Tools::getShopDomain(true);
$html .= ' $html .= '
<a class="bold ajaxcall-recurcive" <a class="bold ajaxcall-recurcive"
style="width: 250px; text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px" style="width: 250px; text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px"
@@ -1713,7 +1718,7 @@ class BlockLayered extends Module
<br /> <br />
<fieldset class="width4"> <fieldset class="width4">
<legend><img src="../img/admin/cog.gif" alt="" />'.$this->l('Existing filter templates').'</legend>'; <legend><img src="../img/admin/cog.gif" alt="" />'.$this->l('Existing filter templates').'</legend>';
$filters_templates = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM '._DB_PREFIX_.'layered_filter ORDER BY date_add DESC'); $filters_templates = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM '._DB_PREFIX_.'layered_filter ORDER BY date_add DESC');
if (count($filters_templates)) if (count($filters_templates))
{ {
@@ -1726,7 +1731,7 @@ class BlockLayered extends Module
<th>'.$this->l('Created on').'</th> <th>'.$this->l('Created on').'</th>
<th>'.$this->l('Actions').'</th> <th>'.$this->l('Actions').'</th>
</tr>'; </tr>';
foreach ($filters_templates as $filters_template) foreach ($filters_templates as $filters_template)
{ {
/* Clean request URI first */ /* Clean request URI first */
@@ -1747,13 +1752,13 @@ class BlockLayered extends Module
</td> </td>
</tr>'; </tr>';
} }
$html .= ' $html .= '
</table>'; </table>';
} }
else else
$html .= $this->l('No filter template found.'); $html .= $this->l('No filter template found.');
$html .= ' $html .= '
</fieldset><br /> </fieldset><br />
<fieldset class="width4"> <fieldset class="width4">