// Normalize

This commit is contained in:
rMalie
2012-01-24 17:30:33 +00:00
parent e63c477ec5
commit d2ae1b632a
22 changed files with 288 additions and 294 deletions
+50 -51
View File
@@ -27,46 +27,46 @@
class CMSCategoryCore extends ObjectModel class CMSCategoryCore extends ObjectModel
{ {
public $id; public $id;
/** @var integer CMSCategory ID */ /** @var integer CMSCategory ID */
public $id_cms_category; public $id_cms_category;
/** @var string Name */ /** @var string Name */
public $name; public $name;
/** @var boolean Status for display */ /** @var boolean Status for display */
public $active = 1; public $active = 1;
/** @var string Description */ /** @var string Description */
public $description; public $description;
/** @var integer Parent CMSCategory ID */ /** @var integer Parent CMSCategory ID */
public $id_parent; public $id_parent;
/** @var integer category position */ /** @var integer category position */
public $position; public $position;
/** @var integer Parents number */ /** @var integer Parents number */
public $level_depth; public $level_depth;
/** @var string string used in rewrited URL */ /** @var string string used in rewrited URL */
public $link_rewrite; public $link_rewrite;
/** @var string Meta title */ /** @var string Meta title */
public $meta_title; public $meta_title;
/** @var string Meta keywords */ /** @var string Meta keywords */
public $meta_keywords; public $meta_keywords;
/** @var string Meta description */ /** @var string Meta description */
public $meta_description; public $meta_description;
/** @var string Object creation date */ /** @var string Object creation date */
public $date_add; public $date_add;
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
protected static $_links = array(); protected static $_links = array();
@@ -95,7 +95,7 @@ class CMSCategoryCore extends ObjectModel
), ),
); );
public function __construct($id_cms_category = NULL, $id_lang = NULL) public function __construct($id_cms_category = null, $id_lang = null)
{ {
parent::__construct($id_cms_category, $id_lang); parent::__construct($id_cms_category, $id_lang);
} }
@@ -104,7 +104,7 @@ class CMSCategoryCore extends ObjectModel
{ {
$this->position = CMSCategory::getLastPosition((int)$this->id_parent); $this->position = CMSCategory::getLastPosition((int)$this->id_parent);
$this->level_depth = $this->calcLevelDepth(); $this->level_depth = $this->calcLevelDepth();
foreach ($this->name AS $k => $value) foreach ($this->name as $k => $value)
if (preg_match('/^[1-9]\./', $value)) if (preg_match('/^[1-9]\./', $value))
$this->name[$k] = '0'.$value; $this->name[$k] = '0'.$value;
$ret = parent::add($autodate); $ret = parent::add($autodate);
@@ -115,7 +115,7 @@ class CMSCategoryCore extends ObjectModel
public function update($nullValues = false) public function update($nullValues = false)
{ {
$this->level_depth = $this->calcLevelDepth(); $this->level_depth = $this->calcLevelDepth();
foreach ($this->name AS $k => $value) foreach ($this->name as $k => $value)
if (preg_match('/^[1-9]\./', $value)) if (preg_match('/^[1-9]\./', $value))
$this->name[$k] = '0'.$value; $this->name[$k] = '0'.$value;
return parent::update(); return parent::update();
@@ -131,7 +131,7 @@ class CMSCategoryCore extends ObjectModel
* *
* @return array Subcategories lite tree * @return array Subcategories lite tree
*/ */
function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $id_lang = NULL, $excludedIdsArray = NULL, Link $link = null) public function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $id_lang = null, $excludedIdsArray = null, Link $link = null)
{ {
if (!$link) if (!$link)
$link = Context::getContext()->link; $link = Context::getContext()->link;
@@ -139,16 +139,17 @@ class CMSCategoryCore extends ObjectModel
if (is_null($id_lang)) if (is_null($id_lang))
$id_lang = Context::getContext()->language->id; $id_lang = Context::getContext()->language->id;
//recursivity for subcategories // recursivity for subcategories
$children = array(); $children = array();
if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($id_lang, true) AND sizeof($subcats)) $subcats = $this->getSubCategories($id_lang, true);
if (($maxDepth == 0 || $currentDepth < $maxDepth) && $subcats && count($subcats))
foreach ($subcats as &$subcat) foreach ($subcats as &$subcat)
{ {
if (!$subcat['id_cms_category']) if (!$subcat['id_cms_category'])
break; break;
elseif ( !is_array($excludedIdsArray) || !in_array($subcat['id_cms_category'], $excludedIdsArray) ) elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_cms_category'], $excludedIdsArray))
{ {
$categ = new CMSCategory($subcat['id_cms_category'] ,$id_lang); $categ = new CMSCategory($subcat['id_cms_category'], $id_lang);
$categ->name = CMSCategory::hideCMSCategoryPosition($categ->name); $categ->name = CMSCategory::hideCMSCategoryPosition($categ->name);
$children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $id_lang, $excludedIdsArray); $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $id_lang, $excludedIdsArray);
} }
@@ -163,7 +164,7 @@ class CMSCategoryCore extends ObjectModel
); );
} }
static public function getRecurseCategory($id_lang = null, $current = 1, $active = 1, $links = 0, Link $link = null, Shop $shop = null) public static function getRecurseCategory($id_lang = null, $current = 1, $active = 1, $links = 0, Link $link = null, Shop $shop = null)
{ {
if (!$link) if (!$link)
$link = Context::getContext()->link; $link = Context::getContext()->link;
@@ -199,7 +200,7 @@ class CMSCategoryCore extends ObjectModel
if ($links == 1) if ($links == 1)
{ {
$category['link'] = $link->getCMSCategoryLink($current, $category['link_rewrite']); $category['link'] = $link->getCMSCategoryLink($current, $category['link_rewrite']);
foreach($category['cms'] as $key => $cms) foreach ($category['cms'] as $key => $cms)
$category['cms'][$key]['link'] = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']); $category['cms'][$key]['link'] = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']);
} }
return $category; return $category;
@@ -212,13 +213,11 @@ class CMSCategoryCore extends ObjectModel
if ($is_html == 0) if ($is_html == 0)
echo $html; echo $html;
if (isset($categories[$id_cms_category])) if (isset($categories[$id_cms_category]))
foreach (array_keys($categories[$id_cms_category]) AS $key) foreach (array_keys($categories[$id_cms_category]) as $key)
$html .= CMSCategory::recurseCMSCategory($categories, $categories[$id_cms_category][$key], $key, $id_selected, $is_html); $html .= CMSCategory::recurseCMSCategory($categories, $categories[$id_cms_category][$key], $key, $id_selected, $is_html);
return $html; return $html;
} }
/** /**
* Recursively add specified CMSCategory childs to $toDelete array * Recursively add specified CMSCategory childs to $toDelete array
* *
@@ -227,14 +226,14 @@ class CMSCategoryCore extends ObjectModel
*/ */
protected function recursiveDelete(&$toDelete, $id_cms_category) protected function recursiveDelete(&$toDelete, $id_cms_category)
{ {
if (!is_array($toDelete) OR !$id_cms_category) if (!is_array($toDelete) || !$id_cms_category)
die(Tools::displayError()); die(Tools::displayError());
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
SELECT `id_cms_category` SELECT `id_cms_category`
FROM `'._DB_PREFIX_.'cms_category` FROM `'._DB_PREFIX_.'cms_category`
WHERE `id_parent` = '.(int)($id_cms_category)); WHERE `id_parent` = '.(int)($id_cms_category));
foreach ($result AS $row) foreach ($result as $row)
{ {
$toDelete[] = (int)($row['id_cms_category']); $toDelete[] = (int)($row['id_cms_category']);
$this->recursiveDelete($toDelete, (int)($row['id_cms_category'])); $this->recursiveDelete($toDelete, (int)($row['id_cms_category']));
@@ -253,7 +252,7 @@ class CMSCategoryCore extends ObjectModel
$toDelete = array_unique($toDelete); $toDelete = array_unique($toDelete);
/* Delete CMS Category and its child from database */ /* Delete CMS Category and its child from database */
$list = sizeof($toDelete) > 1 ? implode(',', $toDelete) : (int)($this->id); $list = count($toDelete) > 1 ? implode(',', $toDelete) : (int)($this->id);
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cms_category` WHERE `id_cms_category` IN ('.$list.')'); Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cms_category` WHERE `id_cms_category` IN ('.$list.')');
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cms_category_lang` WHERE `id_cms_category` IN ('.$list.')'); Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cms_category_lang` WHERE `id_cms_category` IN ('.$list.')');
@@ -281,7 +280,7 @@ class CMSCategoryCore extends ObjectModel
public function deleteSelection($categories) public function deleteSelection($categories)
{ {
$return = 1; $return = 1;
foreach ($categories AS $id_category_cms) foreach ($categories as $id_category_cms)
{ {
$category_cms = new CMSCategory((int)($id_category_cms)); $category_cms = new CMSCategory((int)($id_category_cms));
$return &= $category_cms->delete(); $return &= $category_cms->delete();
@@ -326,7 +325,7 @@ class CMSCategoryCore extends ObjectModel
return $result; return $result;
$categories = array(); $categories = array();
foreach ($result AS $row) foreach ($result as $row)
$categories[$row['id_parent']][$row['id_cms_category']]['infos'] = $row; $categories[$row['id_parent']][$row['id_cms_category']]['infos'] = $row;
return $categories; return $categories;
} }
@@ -362,11 +361,9 @@ class CMSCategoryCore extends ObjectModel
GROUP BY c.`id_cms_category` GROUP BY c.`id_cms_category`
ORDER BY `name` ASC'); ORDER BY `name` ASC');
/* Modify SQL result */ // Modify SQL result
foreach ($result AS &$row) foreach ($result as &$row)
{
$row['name'] = CMSCategory::hideCMSCategoryPosition($row['name']); $row['name'] = CMSCategory::hideCMSCategoryPosition($row['name']);
}
return $result; return $result;
} }
@@ -409,7 +406,7 @@ class CMSCategoryCore extends ObjectModel
/* Modify SQL result */ /* Modify SQL result */
$resultsArray = array(); $resultsArray = array();
foreach ($result AS $row) foreach ($result as $row)
{ {
$row['name'] = CMSCategory::hideCMSCategoryPosition($row['name']); $row['name'] = CMSCategory::hideCMSCategoryPosition($row['name']);
$resultsArray[] = $row; $resultsArray[] = $row;
@@ -441,7 +438,7 @@ class CMSCategoryCore extends ObjectModel
public static function getLinkRewrite($id_cms_category, $id_lang) public static function getLinkRewrite($id_cms_category, $id_lang)
{ {
if (!Validate::isUnsignedId($id_cms_category) OR !Validate::isUnsignedId($id_lang)) if (!Validate::isUnsignedId($id_cms_category) || !Validate::isUnsignedId($id_lang))
return false; return false;
if (isset(self::$_links[$id_cms_category.'-'.$id_lang])) if (isset(self::$_links[$id_cms_category.'-'.$id_lang]))
@@ -464,7 +461,7 @@ class CMSCategoryCore extends ObjectModel
return $link->getCMSCategoryLink($this->id, $this->link_rewrite); return $link->getCMSCategoryLink($this->id, $this->link_rewrite);
} }
public function getName($id_lang = NULL) public function getName($id_lang = null)
{ {
$context = Context::getContext(); $context = Context::getContext();
@@ -547,7 +544,7 @@ class CMSCategoryCore extends ObjectModel
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
$categories[] = $result[0]; $categories[] = $result[0];
if(!$result OR $result[0]['id_parent'] == 1) if (!$result || $result[0]['id_parent'] == 1)
return $categories; return $categories;
$idCurrent = $result[0]['id_parent']; $idCurrent = $result[0]['id_parent'];
} }
@@ -562,8 +559,8 @@ class CMSCategoryCore extends ObjectModel
ORDER BY cp.`position` ASC' ORDER BY cp.`position` ASC'
)) ))
return false; return false;
foreach ($res AS $category) foreach ($res as $category)
if ((int)($category['id_cms_category']) == (int)($this->id)) if ((int)$category['id_cms_category'] == (int)$this->id)
$movedCategory = $category; $movedCategory = $category;
if (!isset($movedCategory) || !isset($position)) if (!isset($movedCategory) || !isset($position))
@@ -575,14 +572,14 @@ class CMSCategoryCore extends ObjectModel
SET `position`= `position` '.($way ? '- 1' : '+ 1').' SET `position`= `position` '.($way ? '- 1' : '+ 1').'
WHERE `position` WHERE `position`
'.($way '.($way
? '> '.(int)($movedCategory['position']).' AND `position` <= '.(int)($position) ? '> '.(int)($movedCategory['position']).' AND `position` <= '.(int)$position
: '< '.(int)($movedCategory['position']).' AND `position` >= '.(int)($position)).' : '< '.(int)($movedCategory['position']).' AND `position` >= '.(int)$position).'
AND `id_parent`='.(int)($movedCategory['id_parent'])) AND `id_parent`='.(int)($movedCategory['id_parent']))
AND Db::getInstance()->execute(' && Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'cms_category` UPDATE `'._DB_PREFIX_.'cms_category`
SET `position` = '.(int)($position).' SET `position` = '.(int)$position.'
WHERE `id_parent` = '.(int)($movedCategory['id_parent']).' WHERE `id_parent` = '.(int)$movedCategory['id_parent'].'
AND `id_cms_category`='.(int)($movedCategory['id_cms_category']))); AND `id_cms_category`='.(int)$movedCategory['id_cms_category']));
} }
public static function cleanPositions($id_category_parent) public static function cleanPositions($id_category_parent)
@@ -592,8 +589,9 @@ class CMSCategoryCore extends ObjectModel
FROM `'._DB_PREFIX_.'cms_category` FROM `'._DB_PREFIX_.'cms_category`
WHERE `id_parent` = '.(int)($id_category_parent).' WHERE `id_parent` = '.(int)($id_category_parent).'
ORDER BY `position`'); ORDER BY `position`');
$sizeof = sizeof($result); $sizeof = count($result);
for ($i = 0; $i < $sizeof; ++$i){ for ($i = 0; $i < $sizeof; ++$i)
{
$sql = ' $sql = '
UPDATE `'._DB_PREFIX_.'cms_category` UPDATE `'._DB_PREFIX_.'cms_category`
SET `position` = '.(int)($i).' SET `position` = '.(int)($i).'
@@ -608,7 +606,8 @@ class CMSCategoryCore extends ObjectModel
{ {
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'cms_category` WHERE `id_parent` = '.(int)($id_category_parent))); return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'cms_category` WHERE `id_parent` = '.(int)($id_category_parent)));
} }
public static function getUrlRewriteInformations($id_category)
public static function getUrlRewriteInformations($id_category)
{ {
$sql = ' $sql = '
SELECT l.`id_lang`, c.`link_rewrite` SELECT l.`id_lang`, c.`link_rewrite`
+3 -5
View File
@@ -90,18 +90,16 @@ class CombinationCore extends ObjectModel
public function delete() public function delete()
{ {
if (!parent::delete() OR $this->deleteAssociations() === false) if (!parent::delete() || $this->deleteAssociations() === false)
return false; return false;
return true; return true;
} }
public function deleteAssociations() public function deleteAssociations()
{ {
if ( if (Db::getInstance()->execute('
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
WHERE `id_product_attribute` = '.(int)($this->id)) === false WHERE `id_product_attribute` = '.(int)$this->id) === false)
)
return false; return false;
return true; return true;
} }
+1 -1
View File
@@ -63,7 +63,7 @@ class CompareProductCore extends ObjectModel
$compareProducts = null; $compareProducts = null;
if ($results) if ($results)
foreach($results as $result) foreach ($results as $result)
$compareProducts[] = $result['id_product']; $compareProducts[] = $result['id_product'];
return $compareProducts; return $compareProducts;
+15 -15
View File
@@ -27,22 +27,22 @@
class ConfigurationCore extends ObjectModel class ConfigurationCore extends ObjectModel
{ {
public $id; public $id;
/** @var string Key */ /** @var string Key */
public $name; public $name;
public $id_group_shop; public $id_group_shop;
public $id_shop; public $id_shop;
/** @var string Value */ /** @var string Value */
public $value; public $value;
/** @var string Object creation date */ /** @var string Object creation date */
public $date_add; public $date_add;
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
/** /**
* @see ObjectModel::$definition * @see ObjectModel::$definition
@@ -104,7 +104,7 @@ class ConfigurationCore extends ObjectModel
/** /**
* Load all configuration data * Load all configuration data
*/ */
static public function loadConfiguration() public static function loadConfiguration()
{ {
self::$_CONF = array(); self::$_CONF = array();
$sql = 'SELECT c.`name`, cl.`id_lang`, IF(cl.`id_lang` IS NULL, c.`value`, cl.`value`) AS value, c.id_group_shop, c.id_shop $sql = 'SELECT c.`name`, cl.`id_lang`, IF(cl.`id_lang` IS NULL, c.`value`, cl.`value`) AS value, c.id_group_shop, c.id_shop
@@ -136,7 +136,7 @@ class ConfigurationCore extends ObjectModel
* @param integer $id_lang Language ID * @param integer $id_lang Language ID
* @return string Value * @return string Value
*/ */
static public function get($key, $langID = NULL, $shopGroupID = NULL, $shopID = NULL) public static function get($key, $langID = null, $shopGroupID = null, $shopID = null)
{ {
Configuration::getShopFromContext($shopGroupID, $shopID); Configuration::getShopFromContext($shopGroupID, $shopID);
$langID = (int)$langID; $langID = (int)$langID;
@@ -156,7 +156,7 @@ class ConfigurationCore extends ObjectModel
return false; return false;
} }
static public function getGlobalValue($key, $langID = NULL) public static function getGlobalValue($key, $langID = null)
{ {
return Configuration::get($key, $langID, 0, 0); return Configuration::get($key, $langID, 0, 0);
} }
@@ -169,7 +169,7 @@ class ConfigurationCore extends ObjectModel
* @param int $shopID * @param int $shopID
* @return array Values in multiple languages * @return array Values in multiple languages
*/ */
static public function getInt($key, $id_group_shop = NULL, $id_shop = NULL) public static function getInt($key, $id_group_shop = null, $id_shop = null)
{ {
$languages = Language::getLanguages(); $languages = Language::getLanguages();
$resultsArray = array(); $resultsArray = array();
@@ -185,7 +185,7 @@ class ConfigurationCore extends ObjectModel
* @param integer $id_lang Language ID * @param integer $id_lang Language ID
* @return array Values * @return array Values
*/ */
static public function getMultiple($keys, $langID = NULL, $shopGroupID = NULL, $shopID = NULL) public static function getMultiple($keys, $langID = null, $shopGroupID = null, $shopID = null)
{ {
if (!is_array($keys)) if (!is_array($keys))
throw new PrestaShopException('keys var is not an array'); throw new PrestaShopException('keys var is not an array');
@@ -226,7 +226,7 @@ class ConfigurationCore extends ObjectModel
* @param int $shopGroupID * @param int $shopGroupID
* @param int $shopID * @param int $shopID
*/ */
static public function set($key, $values, $id_group_shop = NULL, $id_shop = NULL) public static function set($key, $values, $id_group_shop = null, $id_shop = null)
{ {
if (!Validate::isConfigName($key)) if (!Validate::isConfigName($key))
die(Tools::displayError()); die(Tools::displayError());
@@ -254,7 +254,7 @@ class ConfigurationCore extends ObjectModel
* @param bool $html * @param bool $html
* @return bool * @return bool
*/ */
static public function updateGlobalValue($key, $values, $html = false) public static function updateGlobalValue($key, $values, $html = false)
{ {
return Configuration::updateValue($key, $values, $html, 0, 0); return Configuration::updateValue($key, $values, $html, 0, 0);
} }
@@ -269,7 +269,7 @@ class ConfigurationCore extends ObjectModel
* @param int $shopID * @param int $shopID
* @return boolean Update result * @return boolean Update result
*/ */
static public function updateValue($key, $values, $html = false, $shopGroupID = null, $shopID = null) public static function updateValue($key, $values, $html = false, $shopGroupID = null, $shopID = null)
{ {
if (!Validate::isConfigName($key)) if (!Validate::isConfigName($key))
die(Tools::displayError()); die(Tools::displayError());
+3 -4
View File
@@ -72,7 +72,6 @@ class ConfigurationTestCore
*/ */
public static function getDefaultTestsOp() public static function getDefaultTestsOp()
{ {
return array( return array(
'fopen' => false, 'fopen' => false,
'register_globals' => false, 'register_globals' => false,
@@ -127,7 +126,7 @@ class ConfigurationTestCore
public static function test_upload() public static function test_upload()
{ {
return ini_get('file_uploads'); return ini_get('file_uploads');
} }
public static function test_fopen() public static function test_fopen()
@@ -163,7 +162,7 @@ class ConfigurationTestCore
public static function test_dir($relative_dir, $recursive = false) public static function test_dir($relative_dir, $recursive = false)
{ {
$dir = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.ltrim($relative_dir, '/'); $dir = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.ltrim($relative_dir, '/');
if (!file_exists($dir) OR !$dh = opendir($dir)) if (!file_exists($dir) || !$dh = opendir($dir))
return false; return false;
$dummy = rtrim($dir, '/').'/'.uniqid(); $dummy = rtrim($dir, '/').'/'.uniqid();
if (@file_put_contents($dummy, 'test')) if (@file_put_contents($dummy, 'test'))
@@ -188,7 +187,7 @@ class ConfigurationTestCore
public static function test_file($file_relative) public static function test_file($file_relative)
{ {
$file = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$file_relative; $file = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$file_relative;
return (file_exists($file) AND is_writable($file)); return (file_exists($file) && is_writable($file));
} }
public static function test_config_dir($dir) public static function test_config_dir($dir)
+4 -4
View File
@@ -59,18 +59,18 @@ class ConnectionsSourceCore extends ObjectModel
{ {
if (!$cookie) if (!$cookie)
$cookie = Context::getContext()->cookie; $cookie = Context::getContext()->cookie;
if (!isset($cookie->id_connections) OR !Validate::isUnsignedId($cookie->id_connections)) if (!isset($cookie->id_connections) || !Validate::isUnsignedId($cookie->id_connections))
return false; return false;
if (!isset($_SERVER['HTTP_REFERER']) AND !Configuration::get('TRACKING_DIRECT_TRAFFIC')) if (!isset($_SERVER['HTTP_REFERER']) && !Configuration::get('TRACKING_DIRECT_TRAFFIC'))
return false; return false;
$source = new ConnectionsSource(); $source = new ConnectionsSource();
if (isset($_SERVER['HTTP_REFERER']) AND Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER'])) if (isset($_SERVER['HTTP_REFERER']) && Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER']))
{ {
$parsed = parse_url($_SERVER['HTTP_REFERER']); $parsed = parse_url($_SERVER['HTTP_REFERER']);
$parsed_host = parse_url(Tools::getProtocol().Tools::getHttpHost(false, false).__PS_BASE_URI__); $parsed_host = parse_url(Tools::getProtocol().Tools::getHttpHost(false, false).__PS_BASE_URI__);
if ((preg_replace('/^www./', '', $parsed['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false))) if ((preg_replace('/^www./', '', $parsed['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false)))
AND !strncmp($parsed['path'], $parsed_host['path'], strlen(__PS_BASE_URI__))) && !strncmp($parsed['path'], $parsed_host['path'], strlen(__PS_BASE_URI__)))
return false; return false;
if (Validate::isAbsoluteUrl(strval($_SERVER['HTTP_REFERER']))) if (Validate::isAbsoluteUrl(strval($_SERVER['HTTP_REFERER'])))
{ {
+6 -6
View File
@@ -233,9 +233,9 @@ abstract class ControllerCore
public function addCSS($css_uri, $css_media_type = 'all') public function addCSS($css_uri, $css_media_type = 'all')
{ {
if (is_array($css_uri)) if (is_array($css_uri))
foreach($css_uri as $css_file => $media) foreach ($css_uri as $css_file => $media)
{ {
if (is_string($css_file) AND strlen($css_file) > 1) if (is_string($css_file) && strlen($css_file) > 1)
{ {
$css_path = Media::getCSSPath($css_file, $media); $css_path = Media::getCSSPath($css_file, $media);
if ($css_path) if ($css_path)
@@ -248,7 +248,7 @@ abstract class ControllerCore
$this->css_files = array_merge($css_path, $this->css_files); $this->css_files = array_merge($css_path, $this->css_files);
} }
} }
else if (is_string($css_uri) AND strlen($css_uri) > 1) else if (is_string($css_uri) && strlen($css_uri) > 1)
{ {
$css_path = Media::getCSSPath($css_uri, $css_media_type); $css_path = Media::getCSSPath($css_uri, $css_media_type);
if ($css_path) if ($css_path)
@@ -265,7 +265,7 @@ abstract class ControllerCore
public function addJS($js_uri) public function addJS($js_uri)
{ {
if (is_array($js_uri)) if (is_array($js_uri))
foreach($js_uri as $js_file) foreach ($js_uri as $js_file)
{ {
$js_path = Media::getJSPath($js_file); $js_path = Media::getJSPath($js_file);
if ($js_path) if ($js_path)
@@ -300,7 +300,7 @@ abstract class ControllerCore
{ {
$ui_path = array(); $ui_path = array();
if (is_array($component)) if (is_array($component))
foreach($component as $ui) foreach ($component as $ui)
$ui_path = Media::getJqueryUIPath($ui, $theme, $check_dependencies); $ui_path = Media::getJqueryUIPath($ui, $theme, $check_dependencies);
else else
$ui_path = Media::getJqueryUIPath($component, $theme, $check_dependencies); $ui_path = Media::getJqueryUIPath($component, $theme, $check_dependencies);
@@ -320,7 +320,7 @@ abstract class ControllerCore
$plugin_path = array(); $plugin_path = array();
if (is_array($name)) if (is_array($name))
{ {
foreach($name as $plugin) foreach ($name as $plugin)
{ {
$plugin_path = Media::getJqueryPluginPath($plugin, $folder); $plugin_path = Media::getJqueryPluginPath($plugin, $folder);
$this->addJS($plugin_path['js']); $this->addJS($plugin_path['js']);
+9 -10
View File
@@ -123,18 +123,17 @@ class CurrencyCore extends ObjectModel
* @param int|string $iso_code int for iso code number string for iso code * @param int|string $iso_code int for iso code number string for iso code
* @return boolean * @return boolean
*/ */
public static function exists ($iso_code) public static function exists($iso_code)
{ {
if(is_int($iso_code)) if (is_int($iso_code))
$id_currency_exists = Currency::getIdByIsoCodeNum($iso_code); $id_currency_exists = Currency::getIdByIsoCodeNum($iso_code);
else else
$id_currency_exists = Currency::getIdByIsoCode($iso_code); $id_currency_exists = Currency::getIdByIsoCode($iso_code);
if ($id_currency_exists){ if ($id_currency_exists)
return true; return true;
} else { else
return false; return false;
}
} }
public function deleteSelection($selection) public function deleteSelection($selection)
@@ -173,7 +172,7 @@ class CurrencyCore extends ObjectModel
* @param string $side left or right * @param string $side left or right
* @return string formated sign * @return string formated sign
*/ */
public function getSign($side=NULL) public function getSign($side = null)
{ {
if (!$side) if (!$side)
return $this->sign; return $this->sign;
@@ -296,7 +295,7 @@ class CurrencyCore extends ObjectModel
$conversion_rate = 1; $conversion_rate = 1;
if ($defaultCurrency->iso_code != $isoCodeSource) if ($defaultCurrency->iso_code != $isoCodeSource)
{ {
foreach ($data->currency AS $currency) foreach ($data->currency as $currency)
if ($currency['iso_code'] == $defaultCurrency->iso_code) if ($currency['iso_code'] == $defaultCurrency->iso_code)
{ {
$conversion_rate = round((float)$currency['rate'], 6); $conversion_rate = round((float)$currency['rate'], 6);
@@ -312,15 +311,15 @@ class CurrencyCore extends ObjectModel
$rate = 1; $rate = 1;
else else
{ {
foreach ($data->currency AS $obj) foreach ($data->currency as $obj)
if ($this->iso_code == strval($obj['iso_code'])) if ($this->iso_code == strval($obj['iso_code']))
{ {
$rate = (float) $obj['rate']; $rate = (float)$obj['rate'];
break; break;
} }
} }
$this->conversion_rate = round($rate / $conversion_rate, 6); $this->conversion_rate = round($rate / $conversion_rate, 6);
} }
$this->update(); $this->update();
} }
+10 -10
View File
@@ -730,19 +730,19 @@ class CustomerCore extends ObjectModel
public function getOutstanding() public function getOutstanding()
{ {
$query = new DbQuery(); $query = new DbQuery();
$query->select('SUM(oi.total_paid_tax_incl)') $query->select('SUM(oi.total_paid_tax_incl)');
->from('order_invoice', 'oi') $query->from('order_invoice', 'oi');
->leftJoin('orders', 'o', 'oi.id_order = o.id_order') $query->leftJoin('orders', 'o', 'oi.id_order = o.id_order');
->groupBy('o.id_customer') $query->groupBy('o.id_customer');
->where('o.id_customer = '.(int)$this->id); $query->where('o.id_customer = '.(int)$this->id);
$total_paid = (float)Db::getInstance()->getValue($query->build()); $total_paid = (float)Db::getInstance()->getValue($query->build());
$query = new DbQuery(); $query = new DbQuery();
$query->select('SUM(op.amount)') $query->select('SUM(op.amount)');
->from('order_payment', 'op') $query->from('order_payment', 'op');
->leftJoin('orders', 'o', 'op.id_order = o.id_order') $query->leftJoin('orders', 'o', 'op.id_order = o.id_order');
->groupBy('o.id_customer') $query->groupBy('o.id_customer');
->where('o.id_customer = '.(int)$this->id); $query->where('o.id_customer = '.(int)$this->id);
$total_rest = (float)Db::getInstance()->getValue($query->build()); $total_rest = (float)Db::getInstance()->getValue($query->build());
return $total_paid - $total_rest; return $total_paid - $total_rest;
+9 -9
View File
@@ -36,7 +36,7 @@ class CustomizationCore
WHERE ore.`id_order` = '.(int)($id_order).' AND ord.`id_customization` != 0')) === false) WHERE ore.`id_order` = '.(int)($id_order).' AND ord.`id_customization` != 0')) === false)
return false; return false;
$customizations = array(); $customizations = array();
foreach ($result AS $row) foreach ($result as $row)
$customizations[(int)($row['id_customization'])] = $row; $customizations[(int)($row['id_customization'])] = $row;
return $customizations; return $customizations;
} }
@@ -46,7 +46,7 @@ class CustomizationCore
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT `id_customization`, `quantity` FROM `'._DB_PREFIX_.'customization` WHERE `id_cart` = '.(int)($id_cart))) if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT `id_customization`, `quantity` FROM `'._DB_PREFIX_.'customization` WHERE `id_cart` = '.(int)($id_cart)))
return false; return false;
$customizations = array(); $customizations = array();
foreach ($result AS $row) foreach ($result as $row)
$customizations[(int)($row['id_customization'])] = $row; $customizations[(int)($row['id_customization'])] = $row;
return $customizations; return $customizations;
} }
@@ -54,8 +54,8 @@ class CustomizationCore
public static function countCustomizationQuantityByProduct($customizations) public static function countCustomizationQuantityByProduct($customizations)
{ {
$total = array(); $total = array();
foreach ($customizations AS $customization) foreach ($customizations as $customization)
$total[(int)($customization['id_order_detail'])] = !isset($total[(int)($customization['id_order_detail'])]) ? (int)($customization['quantity']) : $total[(int)($customization['id_order_detail'])] + (int)($customization['quantity']); $total[(int)$customization['id_order_detail']] = !isset($total[(int)$customization['id_order_detail']]) ? (int)$customization['quantity'] : $total[(int)$customization['id_order_detail']] + (int)$customization['quantity'];
return $total; return $total;
} }
@@ -79,7 +79,7 @@ class CustomizationCore
$quantities = array(); $quantities = array();
$in_values = ''; $in_values = '';
foreach($ids_customizations as $key => $id_customization) foreach ($ids_customizations as $key => $id_customization)
{ {
if ($key > 0) $in_values .= ','; if ($key > 0) $in_values .= ',';
$in_values .= (int)($id_customization); $in_values .= (int)($id_customization);
@@ -87,12 +87,12 @@ class CustomizationCore
if (!empty($in_values)) if (!empty($in_values))
{ {
$results = Db::getInstance()->executeS( $results = Db::getInstance()->executeS(
'SELECT `id_customization`, `id_product`, `quantity`, `quantity_refunded`, `quantity_returned` 'SELECT `id_customization`, `id_product`, `quantity`, `quantity_refunded`, `quantity_returned`
FROM `'._DB_PREFIX_.'customization` FROM `'._DB_PREFIX_.'customization`
WHERE `id_customization` IN ('.$in_values.')'); WHERE `id_customization` IN ('.$in_values.')');
foreach($results as $row) foreach ($results as $row)
$quantities[$row['id_customization']] = $row; $quantities[$row['id_customization']] = $row;
} }
@@ -103,14 +103,14 @@ class CustomizationCore
{ {
$quantity = array(); $quantity = array();
$results = Db::getInstance()->executeS(' $results = Db::getInstance()->executeS('
SELECT `id_product`, `id_product_attribute`, SUM(`quantity`) AS quantity SELECT `id_product`, `id_product_attribute`, SUM(`quantity`) AS quantity
FROM `'._DB_PREFIX_.'customization` FROM `'._DB_PREFIX_.'customization`
WHERE `id_cart` = '.(int)$id_cart.' WHERE `id_cart` = '.(int)$id_cart.'
GROUP BY `id_cart`, `id_product`, `id_product_attribute` GROUP BY `id_cart`, `id_product`, `id_product_attribute`
'); ');
foreach($results as $row) foreach ($results as $row)
$quantity[$row['id_product']][$row['product_attribute_id']] = $row['quantity']; $quantity[$row['id_product']][$row['product_attribute_id']] = $row['quantity'];
return $quantity; return $quantity;
+1 -1
View File
@@ -48,7 +48,7 @@ class DateRangeCore extends ObjectModel
SELECT `id_date_range`, `time_end` SELECT `id_date_range`, `time_end`
FROM `'._DB_PREFIX_.'date_range` FROM `'._DB_PREFIX_.'date_range`
WHERE `time_end` = (SELECT MAX(`time_end`) FROM `'._DB_PREFIX_.'date_range`)'); WHERE `time_end` = (SELECT MAX(`time_end`) FROM `'._DB_PREFIX_.'date_range`)');
if (!$result['id_date_range'] OR strtotime($result['time_end']) < strtotime(date('Y-m-d H:i:s'))) if (!$result['id_date_range'] || strtotime($result['time_end']) < strtotime(date('Y-m-d H:i:s')))
{ {
// The default range is set to 1 day less 1 second (in seconds) // The default range is set to 1 day less 1 second (in seconds)
$rangeSize = 86399; $rangeSize = 86399;
+3 -3
View File
@@ -128,7 +128,7 @@ class DiscountCore extends CartRule
$obj = $this->parent; $obj = $this->parent;
if (in_array($method, array('add', 'update', 'getIdByName', 'getCustomerDiscounts', 'getValue', 'discountExists', 'createOrderDiscount', 'getVouchersToCartDisplay'))) if (in_array($method, array('add', 'update', 'getIdByName', 'getCustomerDiscounts', 'getValue', 'discountExists', 'createOrderDiscount', 'getVouchersToCartDisplay')))
$obj = $this; $obj = $this;
return call_user_func_array(array(obj, $method), $args); return call_user_func_array(array($obj, $method), $args);
} }
/** /**
@@ -163,8 +163,8 @@ class DiscountCore extends CartRule
* @deprecated 1.5.0.1 * @deprecated 1.5.0.1
*/ */
public static function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $hasStock = false, Cart $cart = null) public static function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $hasStock = false, Cart $cart = null)
{ {
return parent::getCustomerCartRules($id_lang, $id_customer, $active, $includeGenericOnes, $hasStock, $cart); return parent::getCustomerCartRules($id_lang, $id_customer, $active, $includeGenericOnes, $hasStock, $cart);
} }
/** /**
+36 -38
View File
@@ -105,13 +105,13 @@ class FrontControllerCore extends Controller
$css_files = $this->css_files; $css_files = $this->css_files;
$js_files = $this->js_files; $js_files = $this->js_files;
if ($this->ssl AND !Tools::usingSecureMode() AND Configuration::get('PS_SSL_ENABLED')) if ($this->ssl && !Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED'))
{ {
header('HTTP/1.1 301 Moved Permanently'); header('HTTP/1.1 301 Moved Permanently');
header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']); header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
exit(); exit();
} }
else if (Configuration::get('PS_SSL_ENABLED') AND Tools::usingSecureMode() AND !($this->ssl)) else if (Configuration::get('PS_SSL_ENABLED') && Tools::usingSecureMode() && !($this->ssl))
{ {
header('HTTP/1.1 301 Moved Permanently'); header('HTTP/1.1 301 Moved Permanently');
header('Location: '.Tools::getShopDomain(true).$_SERVER['REQUEST_URI']); header('Location: '.Tools::getShopDomain(true).$_SERVER['REQUEST_URI']);
@@ -134,15 +134,15 @@ class FrontControllerCore extends Controller
ob_start(); ob_start();
// Switch language if needed and init cookie language // Switch language if needed and init cookie language
if ($iso = Tools::getValue('isolang') AND Validate::isLanguageIsoCode($iso) AND ($id_lang = (int)(Language::getIdByIso($iso)))) if ($iso = Tools::getValue('isolang') && Validate::isLanguageIsoCode($iso) && ($id_lang = (int)(Language::getIdByIso($iso))))
$_GET['id_lang'] = $id_lang; $_GET['id_lang'] = $id_lang;
Tools::switchLanguage(); Tools::switchLanguage();
Tools::setCookieLanguage($this->context->cookie); Tools::setCookieLanguage($this->context->cookie);
$currency = Tools::setCurrency($this->context->cookie); $currency = Tools::setCurrency($this->context->cookie);
$protocol_link = (Configuration::get('PS_SSL_ENABLED') OR Tools::usingSecureMode()) ? 'https://' : 'http://'; $protocol_link = (Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode()) ? 'https://' : 'http://';
$useSSL = ((isset($this->ssl) AND $this->ssl AND Configuration::get('PS_SSL_ENABLED')) OR Tools::usingSecureMode()) ? true : false; $useSSL = ((isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false;
$protocol_content = ($useSSL) ? 'https://' : 'http://'; $protocol_content = ($useSSL) ? 'https://' : 'http://';
$link = new Link($protocol_link, $protocol_content); $link = new Link($protocol_link, $protocol_content);
$this->context->link = $link; $this->context->link = $link;
@@ -150,31 +150,31 @@ class FrontControllerCore extends Controller
if ($id_cart = (int)$this->recoverCart()) if ($id_cart = (int)$this->recoverCart())
$this->context->cookie->id_cart = (int)$id_cart; $this->context->cookie->id_cart = (int)$id_cart;
if ($this->auth AND !$this->context->customer->isLogged($this->guestAllowed)) if ($this->auth && !$this->context->customer->isLogged($this->guestAllowed))
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : '')); Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
/* Theme is missing or maintenance */ /* Theme is missing or maintenance */
if (!is_dir(_PS_THEME_DIR_)) if (!is_dir(_PS_THEME_DIR_))
die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.')); die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' AND !(int)(Configuration::get('PS_SHOP_ENABLE'))) elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' && !(int)(Configuration::get('PS_SHOP_ENABLE')))
$this->maintenance = true; $this->maintenance = true;
elseif (Configuration::get('PS_GEOLOCATION_ENABLED')) elseif (Configuration::get('PS_GEOLOCATION_ENABLED'))
if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault)) if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault))
$this->context->country = $newDefault; $this->context->country = $newDefault;
if (isset($_GET['logout']) OR ($this->context->customer->logged AND Customer::isBanned($this->context->customer->id))) if (isset($_GET['logout']) || ($this->context->customer->logged && Customer::isBanned($this->context->customer->id)))
{ {
$this->context->customer->logout(); $this->context->customer->logout();
// Login information have changed, so we check if the cart rules still apply // Login information have changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart(); CartRule::autoRemoveFromCart();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL); Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
} }
elseif (isset($_GET['mylogout'])) elseif (isset($_GET['mylogout']))
{ {
$this->context->customer->mylogout(); $this->context->customer->mylogout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL); Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
} }
$_MODULES = array(); $_MODULES = array();
@@ -186,13 +186,13 @@ class FrontControllerCore extends Controller
if ($cart->OrderExists()) if ($cart->OrderExists())
unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS); unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
/* Delete product of cart, if user can't make an order from his country */ /* Delete product of cart, if user can't make an order from his country */
elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) AND elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) &&
!in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) AND !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) &&
$cart->nbProducts() AND intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 AND $cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 &&
!FrontController::isInWhitelistForGeolocation()) !FrontController::isInWhitelistForGeolocation())
unset($this->context->cookie->id_cart, $cart); unset($this->context->cookie->id_cart, $cart);
// update cart values // update cart values
elseif ($this->context->cookie->id_customer != $cart->id_customer OR $this->context->cookie->id_lang != $cart->id_lang OR $currency->id != $cart->id_currency) elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency)
{ {
if ($this->context->cookie->id_customer) if ($this->context->cookie->id_customer)
$cart->id_customer = (int)($this->context->cookie->id_customer); $cart->id_customer = (int)($this->context->cookie->id_customer);
@@ -220,7 +220,7 @@ class FrontControllerCore extends Controller
} }
} }
if (!isset($cart) OR !$cart->id) if (!isset($cart) || !$cart->id)
{ {
$cart = new Cart(); $cart = new Cart();
$cart->id_lang = (int)($this->context->cookie->id_lang); $cart->id_lang = (int)($this->context->cookie->id_lang);
@@ -313,7 +313,7 @@ class FrontControllerCore extends Controller
'display_tax_label' => (bool)$display_tax_label, 'display_tax_label' => (bool)$display_tax_label,
'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'), 'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'), 'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') OR !(bool)Group::getCurrent()->show_prices, 'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') || !(bool)Group::getCurrent()->show_prices,
'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE') 'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE')
)); ));
@@ -341,7 +341,7 @@ class FrontControllerCore extends Controller
); );
foreach ($assignArray as $assignKey => $assignValue) foreach ($assignArray as $assignKey => $assignValue)
if (substr($assignValue, 0, 1) == '/' OR $protocol_content == 'https://') if (substr($assignValue, 0, 1) == '/' || $protocol_content == 'https://')
$this->context->smarty->assign($assignKey, $protocol_content.Tools::getMediaServer($assignValue).$assignValue); $this->context->smarty->assign($assignKey, $protocol_content.Tools::getMediaServer($assignValue).$assignValue);
else else
$this->context->smarty->assign($assignKey, $assignValue); $this->context->smarty->assign($assignKey, $assignValue);
@@ -363,7 +363,7 @@ class FrontControllerCore extends Controller
$this->displayRestrictedCountryPage(); $this->displayRestrictedCountryPage();
//live edit //live edit
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_))) if (Tools::isSubmit('live_edit') && $ad = Tools::getValue('ad') && (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
if (!is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$ad)) if (!is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$ad))
die(Tools::displayError()); die(Tools::displayError());
@@ -373,11 +373,11 @@ class FrontControllerCore extends Controller
// Customer wasn't defined at all // Customer wasn't defined at all
$customer = new StdClass(); $customer = new StdClass();
if($this->context->cookie->id_country) if ($this->context->cookie->id_country)
$customer->geoloc_id_country = (int)$this->context->cookie->id_country; $customer->geoloc_id_country = (int)$this->context->cookie->id_country;
if($this->context->cookie->id_state) if ($this->context->cookie->id_state)
$customer->geoloc_id_state = (int)$this->context->cookie->id_state; $customer->geoloc_id_state = (int)$this->context->cookie->id_state;
if($this->context->cookie->postcode) if ($this->context->cookie->postcode)
$customer->geoloc_postcode = (int)$this->context->cookie->postcode; $customer->geoloc_postcode = (int)$this->context->cookie->postcode;
$this->context->cart = $cart; $this->context->cart = $cart;
@@ -425,7 +425,7 @@ class FrontControllerCore extends Controller
Tools::displayAsDeprecated(); Tools::displayAsDeprecated();
$this->initHeader(); $this->initHeader();
$hook_header = Hook::exec('displayHeader'); $hook_header = Hook::exec('displayHeader');
if ((Configuration::get('PS_CSS_THEME_CACHE') OR Configuration::get('PS_JS_THEME_CACHE')) AND is_writable(_PS_THEME_DIR_.'cache')) if ((Configuration::get('PS_CSS_THEME_CACHE') || Configuration::get('PS_JS_THEME_CACHE')) && is_writable(_PS_THEME_DIR_.'cache'))
{ {
// CSS compressor management // CSS compressor management
if (Configuration::get('PS_CSS_THEME_CACHE')) if (Configuration::get('PS_CSS_THEME_CACHE'))
@@ -481,7 +481,7 @@ class FrontControllerCore extends Controller
Tools::safePostVars(); Tools::safePostVars();
// assign css_files and js_files at the very last time // assign css_files and js_files at the very last time
if ((Configuration::get('PS_CSS_THEME_CACHE') OR Configuration::get('PS_JS_THEME_CACHE')) AND is_writable(_PS_THEME_DIR_.'cache')) if ((Configuration::get('PS_CSS_THEME_CACHE') || Configuration::get('PS_JS_THEME_CACHE')) && is_writable(_PS_THEME_DIR_.'cache'))
{ {
// CSS compressor management // CSS compressor management
if (Configuration::get('PS_CSS_THEME_CACHE')) if (Configuration::get('PS_CSS_THEME_CACHE'))
@@ -523,7 +523,7 @@ class FrontControllerCore extends Controller
$this->context->smarty->display(_PS_THEME_DIR_.'footer.tpl'); $this->context->smarty->display(_PS_THEME_DIR_.'footer.tpl');
// live edit // live edit
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_))) if (Tools::isSubmit('live_edit') && $ad = Tools::getValue('ad') && (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
{ {
$this->context->smarty->assign(array('ad' => $ad, 'live_edit' => true)); $this->context->smarty->assign(array('ad' => $ad, 'live_edit' => true));
$this->context->smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl'); $this->context->smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl');
@@ -572,7 +572,7 @@ class FrontControllerCore extends Controller
$strParams = ((strpos($canonicalURL, '?') === false) ? '?' : '&').implode('&', $params); $strParams = ((strpos($canonicalURL, '?') === false) ? '?' : '&').implode('&', $params);
header('HTTP/1.0 301 Moved'); header('HTTP/1.0 301 Moved');
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $_SERVER['REQUEST_URI'] != __PS_BASE_URI__) if (defined('_PS_MODE_DEV_') && _PS_MODE_DEV_ && $_SERVER['REQUEST_URI'] != __PS_BASE_URI__)
die('[Debug] This page has moved<br />Please use the following URL instead: <a href="'.$canonicalURL.$strParams.'">'.$canonicalURL.$strParams.'</a>'); die('[Debug] This page has moved<br />Please use the following URL instead: <a href="'.$canonicalURL.$strParams.'">'.$canonicalURL.$strParams.'</a>');
Tools::redirectLink($canonicalURL.$strParams); Tools::redirectLink($canonicalURL.$strParams);
} }
@@ -585,7 +585,7 @@ class FrontControllerCore extends Controller
/* Check if Maxmind Database exists */ /* Check if Maxmind Database exists */
if (file_exists(_PS_GEOIP_DIR_.'GeoLiteCity.dat')) if (file_exists(_PS_GEOIP_DIR_.'GeoLiteCity.dat'))
{ {
if (!isset($this->context->cookie->iso_code_country) OR (isset($this->context->cookie->iso_code_country) AND !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))))) if (!isset($this->context->cookie->iso_code_country) || (isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))))
{ {
include_once(_PS_GEOIP_DIR_.'geoipcity.inc'); include_once(_PS_GEOIP_DIR_.'geoipcity.inc');
include_once(_PS_GEOIP_DIR_.'geoipregionvars.php'); include_once(_PS_GEOIP_DIR_.'geoipregionvars.php');
@@ -616,9 +616,9 @@ class FrontControllerCore extends Controller
if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country))))
{ {
/* Update defaultCountry */ /* Update defaultCountry */
if($defaultCountry->iso_code != $this->context->cookie->iso_code_country) if ($defaultCountry->iso_code != $this->context->cookie->iso_code_country)
$defaultCountry = new Country($id_country); $defaultCountry = new Country($id_country);
if (isset($hasBeenSet) AND $hasBeenSet) if (isset($hasBeenSet) && $hasBeenSet)
$this->context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id); $this->context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id);
return $defaultCountry; return $defaultCountry;
} }
@@ -644,12 +644,12 @@ class FrontControllerCore extends Controller
$this->addjqueryPlugin('easing'); $this->addjqueryPlugin('easing');
$this->addJS(_PS_JS_DIR_.'tools.js'); $this->addJS(_PS_JS_DIR_.'tools.js');
if (Tools::isSubmit('live_edit') AND Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_))) if (Tools::isSubmit('live_edit') && Tools::getValue('ad') && (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
{ {
$this->addJqueryUI('ui.sortable'); $this->addJqueryUI('ui.sortable');
$this->addjqueryPlugin('fancybox'); $this->addjqueryPlugin('fancybox');
$this->addJS(_PS_JS_DIR_.'hookLiveEdit.js'); $this->addJS(_PS_JS_DIR_.'hookLiveEdit.js');
$this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css', 'all'); //TODO $this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css', 'all'); // @TODO
} }
if ($this->context->language->is_rtl) if ($this->context->language->is_rtl)
$this->addCSS(_THEME_CSS_DIR_.'rtl.css'); $this->addCSS(_THEME_CSS_DIR_.'rtl.css');
@@ -683,10 +683,9 @@ class FrontControllerCore extends Controller
public function getLiveEditFooter() public function getLiveEditFooter()
{ {
if (Tools::isSubmit('live_edit') if (Tools::isSubmit('live_edit')
&& ($ad = Tools::getValue('ad')) && ($ad = Tools::getValue('ad'))
&& (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)) && (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
)
{ {
$data = $this->context->smarty->createData(); $data = $this->context->smarty->createData();
$data->assign(array( $data->assign(array(
@@ -739,7 +738,7 @@ class FrontControllerCore extends Controller
// Clean duplicate values // Clean duplicate values
$nArray = array_unique($nArray); $nArray = array_unique($nArray);
asort($nArray); asort($nArray);
$this->n = abs((int)(Tools::getValue('n', ((isset($this->context->cookie->nb_item_per_page) AND $this->context->cookie->nb_item_per_page >= 10) ? $this->context->cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')))))); $this->n = abs((int)(Tools::getValue('n', ((isset($this->context->cookie->nb_item_per_page) && $this->context->cookie->nb_item_per_page >= 10) ? $this->context->cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE'))))));
$this->p = abs((int)(Tools::getValue('p', 1))); $this->p = abs((int)(Tools::getValue('p', 1)));
$current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']); $current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
@@ -751,7 +750,7 @@ class FrontControllerCore extends Controller
if ($this->p < 0) if ($this->p < 0)
$this->p = 0; $this->p = 0;
if (isset($this->context->cookie->nb_item_per_page) AND $this->n != $this->context->cookie->nb_item_per_page AND in_array($this->n, $nArray)) if (isset($this->context->cookie->nb_item_per_page) && $this->n != $this->context->cookie->nb_item_per_page && in_array($this->n, $nArray))
$this->context->cookie->nb_item_per_page = $this->n; $this->context->cookie->nb_item_per_page = $this->n;
if ($this->p > ($nbProducts / $this->n)) if ($this->p > ($nbProducts / $this->n))
@@ -802,7 +801,7 @@ class FrontControllerCore extends Controller
$allowed = false; $allowed = false;
$userIp = Tools::getRemoteAddr(); $userIp = Tools::getRemoteAddr();
$ips = explode(';', Configuration::get('PS_GEOLOCATION_WHITELIST')); $ips = explode(';', Configuration::get('PS_GEOLOCATION_WHITELIST'));
if (is_array($ips) && sizeof($ips)) if (is_array($ips) && count($ips))
foreach ($ips as $ip) foreach ($ips as $ip)
if (!empty($ip) && strpos($userIp, $ip) === 0) if (!empty($ip) && strpos($userIp, $ip) === 0)
$allowed = true; $allowed = true;
@@ -875,7 +874,7 @@ class FrontControllerCore extends Controller
if (Validate::isLoadedObject($cart)) if (Validate::isLoadedObject($cart))
{ {
$customer = new Customer((int)$cart->id_customer); $customer = new Customer((int)$cart->id_customer);
if(Validate::isLoadedObject($customer)) if (Validate::isLoadedObject($customer))
{ {
$this->context->cookie->id_customer = (int)$customer->id; $this->context->cookie->id_customer = (int)$customer->id;
$this->context->cookie->customer_lastname = $customer->lastname; $this->context->cookie->customer_lastname = $customer->lastname;
@@ -884,7 +883,6 @@ class FrontControllerCore extends Controller
$this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->is_guest = $customer->isGuest();
$this->context->cookie->passwd = $customer->passwd; $this->context->cookie->passwd = $customer->passwd;
$this->context->cookie->email = $customer->email; $this->context->cookie->email = $customer->email;
$this->context->cookie->checkedTOS = true;
return $id_cart; return $id_cart;
} }
} }
+7 -7
View File
@@ -104,8 +104,8 @@ class GroupReductionCore extends ObjectModel
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT p.`id_product` SELECT p.`id_product`
FROM `'._DB_PREFIX_.'product` p FROM `'._DB_PREFIX_.'product` p
WHERE p.`id_category_default` = '.(int)$this->id_category WHERE p.`id_category_default` = '.(int)$this->id_category,
, false); false);
$ids = array(); $ids = array();
foreach ($products as $product) foreach ($products as $product)
@@ -154,8 +154,8 @@ class GroupReductionCore extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT gr.`id_group` as id_group, gr.`reduction` as reduction SELECT gr.`id_group` as id_group, gr.`reduction` as reduction
FROM `'._DB_PREFIX_.'group_reduction` gr FROM `'._DB_PREFIX_.'group_reduction` gr
WHERE `id_category` = '.(int)$id_category WHERE `id_category` = '.(int)$id_category,
, false); false);
} }
public static function getGroupReductionByCategoryId($id_category) public static function getGroupReductionByCategoryId($id_category)
@@ -163,13 +163,13 @@ class GroupReductionCore extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT gr.`id_group_reduction` as id_group_reduction SELECT gr.`id_group_reduction` as id_group_reduction
FROM `'._DB_PREFIX_.'group_reduction` gr FROM `'._DB_PREFIX_.'group_reduction` gr
WHERE `id_category` = '.(int)$id_category WHERE `id_category` = '.(int)$id_category,
, false); false);
} }
public static function setProductReduction($id_product, $id_group, $id_category, $reduction) public static function setProductReduction($id_product, $id_group, $id_category, $reduction)
{ {
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT pgr.`id_product`, pgr.`id_group`, pgr.`reduction` SELECT pgr.`id_product`, pgr.`id_group`, pgr.`reduction`
FROM `'._DB_PREFIX_.'product_group_reduction_cache` pgr FROM `'._DB_PREFIX_.'product_group_reduction_cache` pgr
WHERE pgr.`id_product` = '.(int)$id_product WHERE pgr.`id_product` = '.(int)$id_product
+6 -6
View File
@@ -72,7 +72,7 @@ class GuestCore extends ObjectModel
), ),
); );
function userAgent() public function userAgent()
{ {
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
@@ -96,7 +96,7 @@ class GuestCore extends ObjectModel
} }
// Only the first language is returned // Only the first language is returned
return (sizeof($langsArray) ? key($langsArray) : ''); return (count($langsArray) ? key($langsArray) : '');
} }
protected function getBrowser($userAgent) protected function getBrowser($userAgent)
@@ -121,7 +121,7 @@ class GuestCore extends ObjectModel
return $result['id_web_browser']; return $result['id_web_browser'];
} }
return NULL; return null;
} }
protected function getOs($userAgent) protected function getOs($userAgent)
@@ -142,7 +142,7 @@ class GuestCore extends ObjectModel
return $result['id_operating_system']; return $result['id_operating_system'];
} }
return NULL; return null;
} }
public static function getFromCustomer($id_customer) public static function getFromCustomer($id_customer)
@@ -177,9 +177,9 @@ class GuestCore extends ObjectModel
public static function setNewGuest($cookie) public static function setNewGuest($cookie)
{ {
$guest = new Guest(isset($cookie->id_customer) ? Guest::getFromCustomer((int)($cookie->id_customer)) : NULL); $guest = new Guest(isset($cookie->id_customer) ? Guest::getFromCustomer((int)($cookie->id_customer)) : null);
$guest->userAgent(); $guest->userAgent();
if ($guest->id_operating_system OR $guest->id_web_browser) if ($guest->id_operating_system || $guest->id_web_browser)
{ {
$guest->save(); $guest->save();
$cookie->id_guest = (int)($guest->id); $cookie->id_guest = (int)($guest->id);
+2 -2
View File
@@ -83,12 +83,12 @@ class HelpAccessCore
$res = @file_get_contents($url, 0, $ctx); $res = @file_get_contents($url, 0, $ctx);
$infos = preg_split('/\|/', $res); $infos = preg_split('/\|/', $res);
if (sizeof($infos) > 0) if (count($infos) > 0)
{ {
$version = trim($infos[0]); $version = trim($infos[0]);
if (!empty($version)) if (!empty($version))
{ {
if (sizeof($infos) > 1) if (count($infos) > 1)
$tooltip = trim($infos[1]); $tooltip = trim($infos[1]);
} }
} }
+3 -3
View File
@@ -411,7 +411,7 @@ font-style:italic;"><img style="padding-right:5px;" src="'._MODULE_DIR_.$moduleI
$newOS = new OrderState((int)($newOrderStatusId), $order->id_lang); $newOS = new OrderState((int)($newOrderStatusId), $order->id_lang);
$return = ((int)($newOS->id) == Configuration::get('PS_OS_PAYMENT')) ? Hook::exec('paymentConfirm', array('id_order' => (int)($order->id))) : true; $return = ((int)($newOS->id) == Configuration::get('PS_OS_PAYMENT')) ? Hook::exec('paymentConfirm', array('id_order' => (int)($order->id))) : true;
$return = Hook::exec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) AND $return; $return = Hook::exec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) && $return;
return $return; return $return;
} }
@@ -459,7 +459,7 @@ font-style:italic;"><img style="padding-right:5px;" src="'._MODULE_DIR_.$moduleI
public static function paymentReturn($id_order, $id_module) public static function paymentReturn($id_order, $id_module)
{ {
Tools::displayAsDeprecated(); Tools::displayAsDeprecated();
if (Validate::isUnsignedId($id_order) AND Validate::isUnsignedId($id_module)) if (Validate::isUnsignedId($id_order) && Validate::isUnsignedId($id_module))
{ {
$params = array(); $params = array();
$order = new Order((int)($id_order)); $order = new Order((int)($id_order));
@@ -485,7 +485,7 @@ font-style:italic;"><img style="padding-right:5px;" src="'._MODULE_DIR_.$moduleI
public static function PDFInvoice($pdf, $id_order) public static function PDFInvoice($pdf, $id_order)
{ {
Tools::displayAsDeprecated(); Tools::displayAsDeprecated();
if (!is_object($pdf) OR !Validate::isUnsignedId($id_order)) if (!is_object($pdf) || !Validate::isUnsignedId($id_order))
return false; return false;
return Hook::exec('PDFInvoice', array('pdf' => $pdf, 'id_order' => $id_order)); return Hook::exec('PDFInvoice', array('pdf' => $pdf, 'id_order' => $id_order));
} }
+12 -12
View File
@@ -27,34 +27,34 @@
class ImageTypeCore extends ObjectModel class ImageTypeCore extends ObjectModel
{ {
public $id; public $id;
/** @var string Name */ /** @var string Name */
public $name; public $name;
/** @var integer Width */ /** @var integer Width */
public $width; public $width;
/** @var integer Height */ /** @var integer Height */
public $height; public $height;
/** @var boolean Apply to products */ /** @var boolean Apply to products */
public $products; public $products;
/** @var integer Apply to categories */ /** @var integer Apply to categories */
public $categories; public $categories;
/** @var integer Apply to manufacturers */ /** @var integer Apply to manufacturers */
public $manufacturers; public $manufacturers;
/** @var integer Apply to suppliers */ /** @var integer Apply to suppliers */
public $suppliers; public $suppliers;
/** @var integer Apply to scenes */ /** @var integer Apply to scenes */
public $scenes; public $scenes;
/** @var integer Apply to store */ /** @var integer Apply to store */
public $stores; public $stores;
/** /**
* @see ObjectModel::$definition * @see ObjectModel::$definition
@@ -88,7 +88,7 @@ class ImageTypeCore extends ObjectModel
* @param string|null Image type * @param string|null Image type
* @return array Image type definitions * @return array Image type definitions
*/ */
public static function getImagesTypes($type = NULL, $id_theme = false) public static function getImagesTypes($type = null, $id_theme = false)
{ {
if (!isset(self::$images_types_cache[$type.($id_theme ? '-'.$id_theme : '')])) if (!isset(self::$images_types_cache[$type.($id_theme ? '-'.$id_theme : '')]))
{ {
@@ -96,7 +96,7 @@ class ImageTypeCore extends ObjectModel
if ($id_theme) if ($id_theme)
$where .= ' AND id_theme='.(int)$id_theme; $where .= ' AND id_theme='.(int)$id_theme;
if (!empty($type)) if (!empty($type))
$where .= ' AND ' . pSQL($type) . ' = 1 '; $where .= ' AND '.pSQL($type).' = 1 ';
$query = 'SELECT * FROM `'._DB_PREFIX_.'image_type`'.$where.' ORDER BY `name` ASC'; $query = 'SELECT * FROM `'._DB_PREFIX_.'image_type`'.$where.' ORDER BY `name` ASC';
self::$images_types_cache[$type] = Db::getInstance()->executeS($query); self::$images_types_cache[$type] = Db::getInstance()->executeS($query);
+6 -6
View File
@@ -14,7 +14,7 @@
abstract class ImportModuleCore extends Module abstract class ImportModuleCore extends Module
{ {
protected $_link = NULL; protected $_link = null;
public $server; public $server;
@@ -30,17 +30,17 @@ abstract class ImportModuleCore extends Module
public function __destruct() public function __destruct()
{ {
if($this->_link) if ($this->_link)
@mysql_close($this->_link); @mysql_close($this->_link);
} }
protected function initDatabaseConnection() protected function initDatabaseConnection()
{ {
if ($this->_link != NULL) if ($this->_link != null)
return $this->_link; return $this->_link;
if ($this->_link = mysql_connect($this->server, $this->user, $this->passwd, true)) if ($this->_link = mysql_connect($this->server, $this->user, $this->passwd, true))
{ {
if(!mysql_select_db($this->database, $this->_link)) if (!mysql_select_db($this->database, $this->_link))
die(Tools::displayError('The database selection cannot be made.')); die(Tools::displayError('The database selection cannot be made.'));
if (!mysql_query('SET NAMES \'utf8\'', $this->_link)) if (!mysql_query('SET NAMES \'utf8\'', $this->_link))
die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.')); die(Tools::displayError('PrestaShop Fatal error: no utf-8 support. Please check your server configuration.'));
@@ -71,7 +71,7 @@ abstract class ImportModuleCore extends Module
{ {
$this->initDatabaseConnection(); $this->initDatabaseConnection();
$result = $this->executeS($query); $result = $this->executeS($query);
if (!sizeof($result)) if (!count($result))
return 0; return 0;
else else
return array_shift($result[0]); return array_shift($result[0]);
@@ -81,7 +81,7 @@ abstract class ImportModuleCore extends Module
{ {
$modules = Module::getModulesOnDisk(true); $modules = Module::getModulesOnDisk(true);
foreach ($modules as $key => $module) foreach ($modules as $key => $module)
if(get_parent_class($module) != 'ImportModule') if (get_parent_class($module) != 'ImportModule')
unset($modules[$key]); unset($modules[$key]);
return $modules; return $modules;
} }
+53 -54
View File
@@ -27,28 +27,28 @@
class LanguageCore extends ObjectModel class LanguageCore extends ObjectModel
{ {
public $id; public $id;
/** @var string Name */ /** @var string Name */
public $name; public $name;
/** @var string 2-letter iso code */ /** @var string 2-letter iso code */
public $iso_code; public $iso_code;
/** @var string 5-letter iso code */ /** @var string 5-letter iso code */
public $language_code; public $language_code;
/** @var string date format http://http://php.net/manual/en/function.date.php with the date only */ /** @var string date format http://http://php.net/manual/en/function.date.php with the date only */
public $date_format_lite = 'Y-m-d'; public $date_format_lite = 'Y-m-d';
/** @var string date format http://http://php.net/manual/en/function.date.php with hours and minutes */ /** @var string date format http://http://php.net/manual/en/function.date.php with hours and minutes */
public $date_format_full = 'Y-m-d H:i:s'; public $date_format_full = 'Y-m-d H:i:s';
/** @var bool true if this language is right to left language */ /** @var bool true if this language is right to left language */
public $is_rtl = false; public $is_rtl = false;
/** @var boolean Status */ /** @var boolean Status */
public $active = true; public $active = true;
/** /**
* @see ObjectModel::$definition * @see ObjectModel::$definition
@@ -85,7 +85,7 @@ class LanguageCore extends ObjectModel
'pdf' => '_LANGPDF', 'pdf' => '_LANGPDF',
); );
public function __construct($id = NULL, $id_lang = NULL) public function __construct($id = null, $id_lang = null)
{ {
parent::__construct($id); parent::__construct($id);
} }
@@ -125,7 +125,7 @@ class LanguageCore extends ObjectModel
*/ */
public function moveToIso($newIso) public function moveToIso($newIso)
{ {
if($newIso == $this->iso_code) if ($newIso == $this->iso_code)
return true; return true;
if (file_exists(_PS_TRANSLATIONS_DIR_.$this->iso_code)) if (file_exists(_PS_TRANSLATIONS_DIR_.$this->iso_code))
@@ -173,7 +173,7 @@ class LanguageCore extends ObjectModel
if (empty($themes)) if (empty($themes))
{ {
$installed_themes = Theme::getThemes(); $installed_themes = Theme::getThemes();
foreach($installed_themes as $theme) foreach ($installed_themes as $theme)
$themes[$theme->directory] = array('name' => $theme->name); $themes[$theme->directory] = array('name' => $theme->name);
} }
return $themes; return $themes;
@@ -233,7 +233,7 @@ class LanguageCore extends ObjectModel
if (empty($iso_from)) if (empty($iso_from))
die(Tools::displayError()); die(Tools::displayError());
$copy = ($iso_to AND $theme_to) ? true : false; $copy = ($iso_to && $theme_to) ? true : false;
$lPath_from = _PS_TRANSLATIONS_DIR_.(string)$iso_from.'/'; $lPath_from = _PS_TRANSLATIONS_DIR_.(string)$iso_from.'/';
$tPath_from = _PS_ROOT_DIR_.'/themes/'.(string)$theme_from.'/'; $tPath_from = _PS_ROOT_DIR_.'/themes/'.(string)$theme_from.'/';
@@ -246,8 +246,8 @@ class LanguageCore extends ObjectModel
$mPath_to = _PS_MAIL_DIR_.(string)$iso_to.'/'; $mPath_to = _PS_MAIL_DIR_.(string)$iso_to.'/';
} }
$lFiles = array('admin'.'.php', 'errors'.'.php', 'fields'.'.php', 'pdf'.'.php'); $lFiles = array('admin.php', 'errors.php', 'fields.php', 'pdf.php');
$mFiles = array('account.html', 'account.txt', 'bankwire.html', 'bankwire.txt', $mFiles = array('account.html', 'account.txt', 'bankwire.html', 'bankwire.txt',
'cheque.html', 'cheque.txt', 'contact.html', 'contact.txt', 'contact_form.html', 'cheque.html', 'cheque.txt', 'contact.html', 'contact.txt', 'contact_form.html',
'contact_form.txt', 'credit_slip.html', 'credit_slip.txt', 'download_product.html', 'contact_form.txt', 'credit_slip.html', 'credit_slip.txt', 'download_product.html',
'download_product.txt', 'download-product.tpl', 'employee_password.html', 'employee_password.txt', 'download_product.txt', 'download-product.tpl', 'employee_password.html', 'employee_password.txt',
@@ -273,10 +273,10 @@ class LanguageCore extends ObjectModel
// to an other theme for the same language, // to an other theme for the same language,
// it's avoid to copy Translations, Mails files // it's avoid to copy Translations, Mails files
// and modules files which are not override by theme. // and modules files which are not override by theme.
if (!$copy OR $iso_from != $iso_to) if (!$copy || $iso_from != $iso_to)
{ {
// Translations files // Translations files
if (!$check OR ($check AND (string)$iso_from != 'en')) if (!$check || ($check && (string)$iso_from != 'en'))
foreach ($lFiles as $file) foreach ($lFiles as $file)
$files_tr[$lPath_from.$file] = ($copy ? $lPath_to.$file : ++$number); $files_tr[$lPath_from.$file] = ($copy ? $lPath_to.$file : ++$number);
if ($select == 'tr') if ($select == 'tr')
@@ -284,7 +284,7 @@ class LanguageCore extends ObjectModel
$files = array_merge($files, $files_tr); $files = array_merge($files, $files_tr);
// Mail files // Mail files
if (!$check OR ($check AND (string)$iso_from != 'en')) if (!$check || ($check && (string)$iso_from != 'en'))
$files_mail[$mPath_from.'lang.php'] = ($copy ? $mPath_to.'lang.php' : ++$number); $files_mail[$mPath_from.'lang.php'] = ($copy ? $mPath_to.'lang.php' : ++$number);
foreach ($mFiles as $file) foreach ($mFiles as $file)
$files_mail[$mPath_from.$file] = ($copy ? $mPath_to.$file : ++$number); $files_mail[$mPath_from.$file] = ($copy ? $mPath_to.$file : ++$number);
@@ -309,7 +309,7 @@ class LanguageCore extends ObjectModel
{ {
$dirFiles = scandir($modMailDirFrom); $dirFiles = scandir($modMailDirFrom);
foreach ($dirFiles as $file) foreach ($dirFiles as $file)
if (file_exists($modMailDirFrom.'/'.$file) AND $file != '.' AND $file != '..' AND $file != '.svn') if (file_exists($modMailDirFrom.'/'.$file) && $file != '.' && $file != '..' && $file != '.svn')
$files_modules[$modMailDirFrom.'/'.$file] = ($copy ? $modMailDirTo.'/'.$file : ++$number); $files_modules[$modMailDirFrom.'/'.$file] = ($copy ? $modMailDirTo.'/'.$file : ++$number);
} }
} }
@@ -318,18 +318,16 @@ class LanguageCore extends ObjectModel
$files = array_merge($files, $files_modules); $files = array_merge($files, $files_modules);
} }
} }
else if ($select == 'mail' OR $select == 'tr') else if ($select == 'mail' || $select == 'tr')
{
return $files; return $files;
}
// Theme files // Theme files
if (!$check OR ($check AND (string)$iso_from != 'en')) if (!$check || ($check && (string)$iso_from != 'en'))
{ {
$files_theme[$tPath_from.'lang/'.(string)$iso_from.'.php'] = ($copy ? $tPath_to.'lang/'.(string)$iso_to.'.php' : ++$number); $files_theme[$tPath_from.'lang/'.(string)$iso_from.'.php'] = ($copy ? $tPath_to.'lang/'.(string)$iso_to.'.php' : ++$number);
$module_theme_files = (file_exists($tPath_from.'modules/') ? scandir($tPath_from.'modules/') : array()); $module_theme_files = (file_exists($tPath_from.'modules/') ? scandir($tPath_from.'modules/') : array());
foreach ($module_theme_files as $module) foreach ($module_theme_files as $module)
if ($module !== '.' AND $module != '..' AND $module !== '.svn' AND file_exists($tPath_from.'modules/'.$module.'/'.(string)$iso_from.'.php')) if ($module !== '.' && $module != '..' && $module !== '.svn' && file_exists($tPath_from.'modules/'.$module.'/'.(string)$iso_from.'.php'))
$files_theme[$tPath_from.'modules/'.$module.'/'.(string)$iso_from.'.php'] = ($copy ? $tPath_to.'modules/'.$module.'/'.(string)$iso_to.'.php' : ++$number); $files_theme[$tPath_from.'modules/'.$module.'/'.(string)$iso_from.'.php'] = ($copy ? $tPath_to.'modules/'.$module.'/'.(string)$iso_to.'.php' : ++$number);
} }
if ($select == 'theme') if ($select == 'theme')
@@ -350,29 +348,30 @@ class LanguageCore extends ObjectModel
$tables = Db::getInstance()->executeS('SHOW TABLES LIKE \''._DB_PREFIX_.'%_lang\' '); $tables = Db::getInstance()->executeS('SHOW TABLES LIKE \''._DB_PREFIX_.'%_lang\' ');
$langTables = array(); $langTables = array();
foreach($tables as $table) foreach ($tables as $table)
foreach($table as $t) foreach ($table as $t)
if ($t != _DB_PREFIX_.'configuration_lang') if ($t != _DB_PREFIX_.'configuration_lang')
$langTables[] = $t; $langTables[] = $t;
Db::getInstance()->execute('SET @id_lang_default = (SELECT c.`value` FROM `'._DB_PREFIX_.'configuration` c WHERE c.`name` = \'PS_LANG_DEFAULT\' LIMIT 1)'); Db::getInstance()->execute('SET @id_lang_default = (SELECT c.`value` FROM `'._DB_PREFIX_.'configuration` c WHERE c.`name` = \'PS_LANG_DEFAULT\' LIMIT 1)');
$return = true; $return = true;
foreach($langTables as $name) foreach ($langTables as $name)
{ {
$fields = ''; $fields = '';
$columns = Db::getInstance()->executeS('SHOW COLUMNS FROM `'.$name.'`'); $columns = Db::getInstance()->executeS('SHOW COLUMNS FROM `'.$name.'`');
foreach($columns as $column) foreach ($columns as $column)
$fields .= $column['Field'].', '; $fields .= $column['Field'].', ';
$fields = rtrim($fields, ', '); $fields = rtrim($fields, ', ');
preg_match('#^'.preg_quote(_DB_PREFIX_).'(.+)_lang$#i', $name, $m); preg_match('#^'.preg_quote(_DB_PREFIX_).'(.+)_lang$#i', $name, $m);
$identifier = 'id_'.$m[1]; $identifier = 'id_'.$m[1];
$sql = 'INSERT IGNORE INTO `'.$name.'` ('.$fields.') (SELECT '; $sql = 'INSERT IGNORE INTO `'.$name.'` ('.$fields.') (SELECT ';
foreach($columns as $column) { foreach ($columns as $column)
if ($identifier != $column['Field'] and $column['Field'] != 'id_lang') {
if ($identifier != $column['Field'] && $column['Field'] != 'id_lang')
$sql .= '(SELECT `'.$column['Field'].'` FROM `'.$name.'` tl WHERE tl.`id_lang` = @id_lang_default AND tl.`'.$identifier.'` = `'.str_replace('_lang', '', $name).'`.`'.$identifier.'`), '; $sql .= '(SELECT `'.$column['Field'].'` FROM `'.$name.'` tl WHERE tl.`id_lang` = @id_lang_default AND tl.`'.$identifier.'` = `'.str_replace('_lang', '', $name).'`.`'.$identifier.'`), ';
else else
$sql.= '`'.$column['Field'].'`, '; $sql .= '`'.$column['Field'].'`, ';
} }
$sql = rtrim($sql, ', '); $sql = rtrim($sql, ', ');
$sql .= ' FROM `'._DB_PREFIX_.'lang` CROSS JOIN `'.str_replace('_lang', '', $name).'`) ;'; $sql .= ' FROM `'._DB_PREFIX_.'lang` CROSS JOIN `'.str_replace('_lang', '', $name).'`) ;';
@@ -407,16 +406,16 @@ class LanguageCore extends ObjectModel
// Database translations deletion // Database translations deletion
$result = Db::getInstance()->executeS('SHOW TABLES FROM `'._DB_NAME_.'`'); $result = Db::getInstance()->executeS('SHOW TABLES FROM `'._DB_NAME_.'`');
foreach ($result AS $row) foreach ($result as $row)
if (preg_match('/_lang/', $row['Tables_in_'._DB_NAME_])) if (preg_match('/_lang/', $row['Tables_in_'._DB_NAME_]))
if (!Db::getInstance()->execute('DELETE FROM `'.$row['Tables_in_'._DB_NAME_].'` WHERE `id_lang` = '.(int)($this->id))) if (!Db::getInstance()->execute('DELETE FROM `'.$row['Tables_in_'._DB_NAME_].'` WHERE `id_lang` = '.(int)$this->id))
return false; return false;
// Delete tags // Delete tags
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'tag WHERE id_lang = '.(int)($this->id)); Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'tag WHERE id_lang = '.(int)$this->id);
// Delete search words // Delete search words
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'search_word WHERE id_lang = '.(int)($this->id)); Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'search_word WHERE id_lang = '.(int)$this->id);
// Files deletion // Files deletion
foreach (Language::getFilesList($this->iso_code, _THEME_NAME_, false, false, false, true, true) as $key => $file) foreach (Language::getFilesList($this->iso_code, _THEME_NAME_, false, false, false, true, true) as $key => $file)
@@ -430,7 +429,7 @@ class LanguageCore extends ObjectModel
if (count($files) <= 2) if (count($files) <= 2)
Language::recurseDeleteDir(_PS_MODULE_DIR_.$mod.'/mails/'); Language::recurseDeleteDir(_PS_MODULE_DIR_.$mod.'/mails/');
if(file_exists(_PS_MODULE_DIR_.$mod.'/'.$this->iso_code.'.php')) if (file_exists(_PS_MODULE_DIR_.$mod.'/'.$this->iso_code.'.php'))
{ {
unlink(_PS_MODULE_DIR_.$mod.'/'.$this->iso_code.'.php'); unlink(_PS_MODULE_DIR_.$mod.'/'.$this->iso_code.'.php');
$files = @scandir(_PS_MODULE_DIR_.$mod); $files = @scandir(_PS_MODULE_DIR_.$mod);
@@ -449,8 +448,8 @@ class LanguageCore extends ObjectModel
// delete images // delete images
$files_copy = array('/en.jpg', '/en-default-thickbox.jpg', '/en-default-home.jpg', '/en-default-large.jpg', '/en-default-medium.jpg', '/en-default-small.jpg', '/en-default-large_scene.jpg'); $files_copy = array('/en.jpg', '/en-default-thickbox.jpg', '/en-default-home.jpg', '/en-default-large.jpg', '/en-default-medium.jpg', '/en-default-small.jpg', '/en-default-large_scene.jpg');
$tos = array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_); $tos = array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_);
foreach($tos AS $to) foreach ($tos as $to)
foreach($files_copy AS $file) foreach ($files_copy as $file)
{ {
$name = str_replace('/en', ''.$this->iso_code, $file); $name = str_replace('/en', ''.$this->iso_code, $file);
@@ -473,7 +472,7 @@ class LanguageCore extends ObjectModel
foreach ($selection as $id) foreach ($selection as $id)
{ {
$this->id = (int)($id); $this->id = (int)($id);
$result = $result AND $this->delete(); $result = $result && $this->delete();
} }
Tools::generateHtaccess(); Tools::generateHtaccess();
@@ -492,9 +491,9 @@ class LanguageCore extends ObjectModel
Language::loadLanguages(); Language::loadLanguages();
$languages = array(); $languages = array();
foreach (self::$_LANGUAGES AS $language) foreach (self::$_LANGUAGES as $language)
{ {
if ($active AND !$language['active'] OR ($id_shop AND !isset($language['shops'][(int)$id_shop]))) if ($active && !$language['active'] || ($id_shop && !isset($language['shops'][(int)$id_shop])))
continue; continue;
$languages[] = $language; $languages[] = $language;
} }
@@ -557,19 +556,19 @@ class LanguageCore extends ObjectModel
public static function copyLanguageData($from, $to) public static function copyLanguageData($from, $to)
{ {
$result = Db::getInstance()->executeS('SHOW TABLES FROM `'._DB_NAME_.'`'); $result = Db::getInstance()->executeS('SHOW TABLES FROM `'._DB_NAME_.'`');
foreach ($result AS $row) foreach ($result as $row)
if (preg_match('/_lang/', $row['Tables_in_'._DB_NAME_]) AND $row['Tables_in_'._DB_NAME_] != _DB_PREFIX_.'lang') if (preg_match('/_lang/', $row['Tables_in_'._DB_NAME_]) && $row['Tables_in_'._DB_NAME_] != _DB_PREFIX_.'lang')
{ {
$result2 = Db::getInstance()->executeS('SELECT * FROM `'.$row['Tables_in_'._DB_NAME_].'` WHERE `id_lang` = '.(int)($from)); $result2 = Db::getInstance()->executeS('SELECT * FROM `'.$row['Tables_in_'._DB_NAME_].'` WHERE `id_lang` = '.(int)$from);
if (!sizeof($result2)) if (!count($result2))
continue; continue;
Db::getInstance()->execute('DELETE FROM `'.$row['Tables_in_'._DB_NAME_].'` WHERE `id_lang` = '.(int)($to)); Db::getInstance()->execute('DELETE FROM `'.$row['Tables_in_'._DB_NAME_].'` WHERE `id_lang` = '.(int)$to);
$query = 'INSERT INTO `'.$row['Tables_in_'._DB_NAME_].'` VALUES '; $query = 'INSERT INTO `'.$row['Tables_in_'._DB_NAME_].'` VALUES ';
foreach ($result2 AS $row2) foreach ($result2 as $row2)
{ {
$query .= '('; $query .= '(';
$row2['id_lang'] = $to; $row2['id_lang'] = $to;
foreach ($row2 AS $field) foreach ($row2 as $field)
$query .= '\''.pSQL($field, true).'\','; $query .= '\''.pSQL($field, true).'\',';
$query = rtrim($query, ',').'),'; $query = rtrim($query, ',').'),';
} }
@@ -591,7 +590,7 @@ class LanguageCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'lang_shop` ls ON (l.id_lang = ls.id_lang)'; LEFT JOIN `'._DB_PREFIX_.'lang_shop` ls ON (l.id_lang = ls.id_lang)';
$result = Db::getInstance()->executeS($sql); $result = Db::getInstance()->executeS($sql);
foreach ($result AS $row) foreach ($result as $row)
{ {
if (!isset(self::$_LANGUAGES[(int)$row['id_lang']])) if (!isset(self::$_LANGUAGES[(int)$row['id_lang']]))
self::$_LANGUAGES[(int)$row['id_lang']] = $row; self::$_LANGUAGES[(int)$row['id_lang']] = $row;
@@ -613,7 +612,7 @@ class LanguageCore extends ObjectModel
return true; return true;
else else
{ {
if(@fsockopen('api.prestashop.com', 80)) if (@fsockopen('api.prestashop.com', 80))
{ {
$lang = new Language(); $lang = new Language();
$lang->iso_code = $iso_code; $lang->iso_code = $iso_code;
@@ -626,14 +625,14 @@ class LanguageCore extends ObjectModel
&& isset($lang_pack->iso_code)) && isset($lang_pack->iso_code))
$lang->name = $lang_pack->name; $lang->name = $lang_pack->name;
} }
if (!$lang->name OR !$lang->add()) if (!$lang->name || !$lang->add())
return false; return false;
$insert_id = (int)($lang->id); $insert_id = (int)$lang->id;
if ($lang_pack) if ($lang_pack)
{ {
$flag = Tools::file_get_contents('http://api.prestashop.com/download/lang_packs/flags/jpeg/'.$iso_code.'.jpg'); $flag = Tools::file_get_contents('http://api.prestashop.com/download/lang_packs/flags/jpeg/'.$iso_code.'.jpg');
if ($flag != NULL && !preg_match('/<body>/', $flag)) if ($flag != null && !preg_match('/<body>/', $flag))
{ {
$file = fopen(dirname(__FILE__).'/../img/l/'.$insert_id.'.jpg', 'w'); $file = fopen(dirname(__FILE__).'/../img/l/'.$insert_id.'.jpg', 'w');
if ($file) if ($file)
@@ -652,8 +651,8 @@ class LanguageCore extends ObjectModel
$files_copy = array('/en.jpg', '/en-default-thickbox.jpg', '/en-default-home.jpg', '/en-default-large.jpg', '/en-default-medium.jpg', '/en-default-small.jpg', '/en-default-large_scene.jpg'); $files_copy = array('/en.jpg', '/en-default-thickbox.jpg', '/en-default-home.jpg', '/en-default-large.jpg', '/en-default-medium.jpg', '/en-default-small.jpg', '/en-default-large_scene.jpg');
$tos = array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_); $tos = array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_);
foreach($tos AS $to) foreach ($tos as $to)
foreach($files_copy AS $file) foreach ($files_copy as $file)
{ {
$name = str_replace('/en', '/'.$iso_code, $file); $name = str_replace('/en', '/'.$iso_code, $file);
copy(dirname(__FILE__).'/../img/l'.$file, $to.$name); copy(dirname(__FILE__).'/../img/l'.$file, $to.$name);
+12 -12
View File
@@ -196,7 +196,7 @@ class LinkCore
*/ */
public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null) public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null)
{ {
$base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true)); $base = (($ssl && Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true));
if (!$id_lang) if (!$id_lang)
$id_lang = Context::getContext()->language->id; $id_lang = Context::getContext()->language->id;
@@ -369,7 +369,7 @@ class LinkCore
unset($request['controller']); unset($request['controller']);
$uri_path = Dispatcher::getInstance()->createUrl($controller, $request); $uri_path = Dispatcher::getInstance()->createUrl($controller, $request);
$url = ($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true); $url = ($ssl && Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);
$url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/'); $url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/');
return $url; return $url;
@@ -412,7 +412,7 @@ class LinkCore
public function goPage($url, $p) public function goPage($url, $p)
{ {
return $url.($p == 1 ? '' : (!strstr($url, '?') ? '?' : '&amp;').'p='.(int)($p)); return $url.($p == 1 ? '' : (!strstr($url, '?') ? '?' : '&amp;').'p='.(int)$p);
} }
public function getPaginationLink($type, $id_object, $nb = false, $sort = false, $pagination = false, $array = false) public function getPaginationLink($type, $id_object, $nb = false, $sort = false, $pagination = false, $array = false)
@@ -426,9 +426,9 @@ class LinkCore
$url = $this->getPageLink(basename($url)); $url = $this->getPageLink(basename($url));
} }
$vars = (!$array) ? '' : array(); $vars = (!$array) ? '' : array();
$varsNb = array('n', 'search_query'); $vars_nb = array('n', 'search_query');
$varsSort = array('orderby', 'orderway'); $vars_sort = array('orderby', 'orderway');
$varsPagination = array('p'); $vars_pagination = array('p');
$n = 0; $n = 0;
foreach ($_GET as $k => $value) foreach ($_GET as $k => $value)
@@ -436,10 +436,10 @@ class LinkCore
{ {
if (Configuration::get('PS_REWRITING_SETTINGS') && ($k == 'isolang' || $k == 'id_lang')) if (Configuration::get('PS_REWRITING_SETTINGS') && ($k == 'isolang' || $k == 'id_lang'))
continue; continue;
$ifNb = (!$nb || ($nb && !in_array($k, $varsNb))); $if_nb = (!$nb || ($nb && !in_array($k, $vars_nb)));
$ifSort = (!$sort || ($sort && !in_array($k, $varsSort))); $if_sort = (!$sort || ($sort && !in_array($k, $vars_sort)));
$ifPagination = (!$pagination || ($pagination && !in_array($k, $varsPagination))); $if_pagination = (!$pagination || ($pagination && !in_array($k, $vars_pagination)));
if ($ifNb && $ifSort && $ifPagination && !is_array($value)) if ($if_nb && $if_sort && $if_pagination && !is_array($value))
!$array ? ($vars .= ((!$n++ && ($this->allow == 1 || $url == $this->url)) ? '?' : '&').urlencode($k).'='.urlencode($value)) : ($vars[urlencode($k)] = urlencode($value)); !$array ? ($vars .= ((!$n++ && ($this->allow == 1 || $url == $this->url)) ? '?' : '&').urlencode($k).'='.urlencode($value)) : ($vars[urlencode($k)] = urlencode($value));
} }
if (!$array) if (!$array)
@@ -455,11 +455,11 @@ class LinkCore
return $url.(!strstr($url, '?') ? '?' : '&').'orderby='.urlencode($orderby).'&orderway='.urlencode($orderway); return $url.(!strstr($url, '?') ? '?' : '&').'orderby='.urlencode($orderby).'&orderway='.urlencode($orderway);
} }
protected function getLangLink($id_lang = NULL, Context $context = null) protected function getLangLink($id_lang = null, Context $context = null)
{ {
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
if (!$this->allow OR !Language::isMultiLanguageActivated()) if (!$this->allow || !Language::isMultiLanguageActivated())
return ''; return '';
if (!$id_lang) if (!$id_lang)
+37 -35
View File
@@ -34,15 +34,15 @@ class LocalizationPackCore
protected $iso_code_lang; protected $iso_code_lang;
protected $iso_currency; protected $iso_currency;
protected $_errors = array(); protected $_errors = array();
public function loadLocalisationPack($file, $selection, $install_mode = false) public function loadLocalisationPack($file, $selection, $install_mode = false)
{ {
if (!$xml = simplexml_load_string($file)) if (!$xml = simplexml_load_string($file))
return false; return false;
$mainAttributes = $xml->attributes(); $main_attributes = $xml->attributes();
$this->name = strval($mainAttributes['name']); $this->name = (string)$main_attributes['name'];
$this->version = strval($mainAttributes['version']); $this->version = (string)$main_attributes['version'];
if (empty($selection)) if (empty($selection))
{ {
$res = true; $res = true;
@@ -54,13 +54,13 @@ class LocalizationPackCore
$res &= $this->installModules($xml); $res &= $this->installModules($xml);
$res &= $this->updateDefaultGroupDisplayMethod($xml); $res &= $this->updateDefaultGroupDisplayMethod($xml);
if (!defined('_PS_MODE_DEV_') OR !_PS_MODE_DEV_) if (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)
$res &= $this->_installLanguages($xml, $install_mode); $res &= $this->_installLanguages($xml, $install_mode);
if ($res AND isset($this->iso_code_lang)) if ($res && isset($this->iso_code_lang))
Configuration::updateValue('PS_LANG_DEFAULT', (int)Language::getIdByIso($this->iso_code_lang)); Configuration::updateValue('PS_LANG_DEFAULT', (int)Language::getIdByIso($this->iso_code_lang));
if ($install_mode AND $res AND isset($this->iso_currency)) if ($install_mode && $res && isset($this->iso_currency))
{ {
$res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int)Currency::getIdByIsoCode($this->iso_currency)); $res &= Configuration::updateValue('PS_CURRENCY_DEFAULT', (int)Currency::getIdByIsoCode($this->iso_currency));
Currency::refreshCurrencies(); Currency::refreshCurrencies();
@@ -68,8 +68,8 @@ class LocalizationPackCore
return $res; return $res;
} }
foreach ($selection AS $selected) foreach ($selection as $selected)
if (!Validate::isLocalizationPackSelection($selected) OR !$this->{'_install'.ucfirst($selected)}($xml)) if (!Validate::isLocalizationPackSelection($selected) || !$this->{'_install'.ucfirst($selected)}($xml))
return false; return false;
return true; return true;
@@ -149,8 +149,8 @@ class LocalizationPackCore
if (Tax::getTaxIdByName($attributes['name'])) if (Tax::getTaxIdByName($attributes['name']))
continue; continue;
$tax = new Tax(); $tax = new Tax();
$tax->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = strval($attributes['name']); $tax->name[(int)Configuration::get('PS_LANG_DEFAULT')] = (string)$attributes['name'];
$tax->rate = (float)($attributes['rate']); $tax->rate = (float)$attributes['rate'];
$tax->active = 1; $tax->active = 1;
if (!$tax->validateFields()) if (!$tax->validateFields())
@@ -161,7 +161,7 @@ class LocalizationPackCore
if (!$tax->add()) if (!$tax->add())
{ {
$this->_errors[] = Tools::displayError('An error occurred while importing the tax: ').strval($attributes['name']); $this->_errors[] = Tools::displayError('An error occurred while importing the tax: ').(string)$attributes['name'];
return false; return false;
} }
@@ -238,26 +238,27 @@ class LocalizationPackCore
{ {
if (isset($xml->currencies->currency)) if (isset($xml->currencies->currency))
{ {
if (!$feed = Tools::simplexml_load_file('http://api.prestashop.com/xml/currencies.xml') AND !$feed = @simplexml_load_file(dirname(__FILE__).'/../localization/currencies.xml')) if (!$feed = Tools::simplexml_load_file('http://api.prestashop.com/xml/currencies.xml')
&& !$feed = @simplexml_load_file(dirname(__FILE__).'/../localization/currencies.xml'))
{ {
$this->_errors[] = Tools::displayError('Cannot parse the currencies XML feed.'); $this->_errors[] = Tools::displayError('Cannot parse the currencies XML feed.');
return false; return false;
} }
foreach ($xml->currencies->currency AS $data) foreach ($xml->currencies->currency as $data)
{ {
$attributes = $data->attributes(); $attributes = $data->attributes();
if(Currency::exists($attributes['iso_code'])) if (Currency::exists($attributes['iso_code']))
continue; continue;
$currency = new Currency(); $currency = new Currency();
$currency->name = strval($attributes['name']); $currency->name = (string)$attributes['name'];
$currency->iso_code = strval($attributes['iso_code']); $currency->iso_code = (string)$attributes['iso_code'];
$currency->iso_code_num = (int)($attributes['iso_code_num']); $currency->iso_code_num = (int)$attributes['iso_code_num'];
$currency->sign = strval($attributes['sign']); $currency->sign = (string)$attributes['sign'];
$currency->blank = (int)($attributes['blank']); $currency->blank = (int)$attributes['blank'];
$currency->conversion_rate = 1; // This value will be updated if the store is online $currency->conversion_rate = 1; // This value will be updated if the store is online
$currency->format = (int)($attributes['format']); $currency->format = (int)$attributes['format'];
$currency->decimals = (int)($attributes['decimals']); $currency->decimals = (int)$attributes['decimals'];
$currency->active = $install_mode; $currency->active = $install_mode;
if (!$currency->validateFields()) if (!$currency->validateFields())
{ {
@@ -278,7 +279,7 @@ class LocalizationPackCore
Currency::refreshCurrencies(); Currency::refreshCurrencies();
if (!sizeof($this->_errors) AND $install_mode AND isset($attributes['iso_code']) AND sizeof($xml->currencies->currency) == 1) if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->currencies->currency) == 1)
$this->iso_currency = $attributes['iso_code']; $this->iso_currency = $attributes['iso_code'];
} }
@@ -289,19 +290,20 @@ class LocalizationPackCore
{ {
$attributes = array(); $attributes = array();
if (isset($xml->languages->language)) if (isset($xml->languages->language))
foreach ($xml->languages->language AS $data) foreach ($xml->languages->language as $data)
{ {
$attributes = $data->attributes(); $attributes = $data->attributes();
if (Language::getIdByIso($attributes['iso_code'])) if (Language::getIdByIso($attributes['iso_code']))
continue; continue;
$native_lang = Language::getLanguages(); $native_lang = Language::getLanguages();
$native_iso_code = array(); $native_iso_code = array();
foreach ($native_lang AS $lang) foreach ($native_lang as $lang)
$native_iso_code[] = $lang['iso_code']; $native_iso_code[] = $lang['iso_code'];
if ((in_array((string)$attributes['iso_code'], $native_iso_code) AND !$install_mode) OR !in_array((string)$attributes['iso_code'], $native_iso_code)) if ((in_array((string)$attributes['iso_code'], $native_iso_code) && !$install_mode)
|| !in_array((string)$attributes['iso_code'], $native_iso_code))
$errno = 0; $errno = 0;
$errstr = ''; $errstr = '';
if(@fsockopen('api.prestashop.com', 80, $errno, $errstr, 10)) if (@fsockopen('api.prestashop.com', 80, $errno, $errstr, 10))
{ {
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://api.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$attributes['iso_code']))) if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://api.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$attributes['iso_code'])))
{ {
@@ -338,7 +340,7 @@ class LocalizationPackCore
} }
// change the default language if there is only one language in the localization pack // change the default language if there is only one language in the localization pack
if (!sizeof($this->_errors) AND $install_mode AND isset($attributes['iso_code']) AND sizeof($xml->languages->language) == 1) if (!count($this->_errors) && $install_mode && isset($attributes['iso_code']) && count($xml->languages->language) == 1)
$this->iso_code_lang = $attributes['iso_code']; $this->iso_code_lang = $attributes['iso_code'];
return true; return true;
@@ -348,7 +350,7 @@ class LocalizationPackCore
{ {
$varNames = array('weight' => 'PS_WEIGHT_UNIT', 'volume' => 'PS_VOLUME_UNIT', 'short_distance' => 'PS_DIMENSION_UNIT', 'base_distance' => 'PS_BASE_DISTANCE_UNIT', 'long_distance' => 'PS_DISTANCE_UNIT'); $varNames = array('weight' => 'PS_WEIGHT_UNIT', 'volume' => 'PS_VOLUME_UNIT', 'short_distance' => 'PS_DIMENSION_UNIT', 'base_distance' => 'PS_BASE_DISTANCE_UNIT', 'long_distance' => 'PS_DISTANCE_UNIT');
if (isset($xml->units->unit)) if (isset($xml->units->unit))
foreach ($xml->units->unit AS $data) foreach ($xml->units->unit as $data)
{ {
$attributes = $data->attributes(); $attributes = $data->attributes();
if (!isset($varNames[strval($attributes['type'])])) if (!isset($varNames[strval($attributes['type'])]))
@@ -373,7 +375,7 @@ class LocalizationPackCore
protected function installModules($xml) protected function installModules($xml)
{ {
if (isset($xml->modules)) if (isset($xml->modules))
foreach($xml->modules->module as $data) foreach ($xml->modules->module as $data)
{ {
$attributes = $data->attributes(); $attributes = $data->attributes();
$name = (string)$attributes['name']; $name = (string)$attributes['name'];
@@ -385,17 +387,17 @@ class LocalizationPackCore
{ {
if (!Module::isInstalled($name)) if (!Module::isInstalled($name))
if (!$module->install()) if (!$module->install())
$this->_errors[] = Tools::displayError('An error has occured during the module installation: '). $name; $this->_errors[] = Tools::displayError('An error has occured during the module installation: ').$name;
} }
else else
if (Module::isInstalled($name)) if (Module::isInstalled($name))
if (!$module->uninstall()) if (!$module->uninstall())
$this->_errors[] = Tools::displayError('An error has occured during the module uninstall: '). $name; $this->_errors[] = Tools::displayError('An error has occured during the module uninstall: ').$name;
unset($module); unset($module);
} }
else else
$this->_errors[] = Tools::displayError('An error has occured, this module doesnt exists: '). $name; $this->_errors[] = Tools::displayError('An error has occured, this module doesnt exists: ').$name;
} }
return true; return true;
@@ -409,14 +411,14 @@ class LocalizationPackCore
protected function installConfiguration($xml) protected function installConfiguration($xml)
{ {
if (isset($xml->configurations)) if (isset($xml->configurations))
foreach($xml->configurations->configuration as $data) foreach ($xml->configurations->configuration as $data)
{ {
$attributes = $data->attributes(); $attributes = $data->attributes();
$name = (string)$attributes['name']; $name = (string)$attributes['name'];
if (isset($name) && isset($attributes['value']) && Configuration::get($name) !== false) if (isset($name) && isset($attributes['value']) && Configuration::get($name) !== false)
if (!Configuration::updateValue($name, (string)$attributes['value'])) if (!Configuration::updateValue($name, (string)$attributes['value']))
$this->_errors[] = Tools::displayError('An error has occured during the configuration setup: '. $name); $this->_errors[] = Tools::displayError('An error has occured during the configuration setup: '.$name);
} }
return true; return true;