// Normalize

This commit is contained in:
rMalie committed 2012-01-25 16:48:14 +00:00
1 parent 22b0bd937d
commit 2ca3b2b029
5 files changed
+55 -43

No files matched your search

+9 -10
View File
@@ -59,11 +59,11 @@ class AdminHomeControllerCore extends AdminController
{ {
$stat = stat(dirname(__FILE__).'/../../.htaccess'); $stat = stat(dirname(__FILE__).'/../../.htaccess');
$dateUpdHtaccess = Db::getInstance()->getValue('SELECT date_upd FROM '._DB_PREFIX_.'configuration WHERE name = "PS_HTACCESS_CACHE_CONTROL"'); $dateUpdHtaccess = Db::getInstance()->getValue('SELECT date_upd FROM '._DB_PREFIX_.'configuration WHERE name = "PS_HTACCESS_CACHE_CONTROL"');
if (Configuration::get('PS_HTACCESS_CACHE_CONTROL') AND strtotime($dateUpdHtaccess) > $stat['mtime']) if (Configuration::get('PS_HTACCESS_CACHE_CONTROL') && strtotime($dateUpdHtaccess) > $stat['mtime'])
$htaccessOptimized = 1; $htaccessOptimized = 1;
$dateUpdate = Configuration::get('PS_LAST_SHOP_UPDATE'); $dateUpdate = Configuration::get('PS_LAST_SHOP_UPDATE');
if ($dateUpdate AND strtotime($dateUpdate) > $stat['mtime']) if ($dateUpdate && strtotime($dateUpdate) > $stat['mtime'])
$htaccessAfterUpdate = 0; $htaccessAfterUpdate = 0;
} }
$indexRebuiltAfterUpdate = 0; $indexRebuiltAfterUpdate = 0;
@@ -77,10 +77,10 @@ class AdminHomeControllerCore extends AdminController
if (Configuration::get('PS_SMARTY_CACHE')) if (Configuration::get('PS_SMARTY_CACHE'))
++$smartyOptimized; ++$smartyOptimized;
$cccOptimized = Configuration::get('PS_CSS_THEME_CACHE') $cccOptimized = Configuration::get('PS_CSS_THEME_CACHE');
+ Configuration::get('PS_JS_THEME_CACHE') $cccOptimized += Configuration::get('PS_JS_THEME_CACHE');
+ Configuration::get('PS_HTML_THEME_COMPRESSION') $cccOptimized += Configuration::get('PS_HTML_THEME_COMPRESSION');
+ Configuration::get('PS_JS_HTML_THEME_COMPRESSION'); $cccOptimized += Configuration::get('PS_JS_HTML_THEME_COMPRESSION');
if ($cccOptimized == 4) if ($cccOptimized == 4)
$cccOptimized = 2; $cccOptimized = 2;
else else
@@ -162,7 +162,7 @@ class AdminHomeControllerCore extends AdminController
protected function warnDomainName() protected function warnDomainName()
{ {
if ($_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN') AND $_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN_SSL')) if ($_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN') && $_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN_SSL'))
$this->displayWarning($this->l('You are currently connected with the following domain name:').' <span style="color: #CC0000;">'.$_SERVER['HTTP_HOST'].'</span><br />'. $this->displayWarning($this->l('You are currently connected with the following domain name:').' <span style="color: #CC0000;">'.$_SERVER['HTTP_HOST'].'</span><br />'.
$this->l('This one is different from the main shop domain name set in "Preferences > SEO & URLs":').' <span style="color: #CC0000;">'.Configuration::get('PS_SHOP_DOMAIN').'</span><br /> $this->l('This one is different from the main shop domain name set in "Preferences > SEO & URLs":').' <span style="color: #CC0000;">'.Configuration::get('PS_SHOP_DOMAIN').'</span><br />
<a href="index.php?tab=AdminMeta&token='.Tools::getAdminTokenLite('AdminMeta').'#SEO%20%26%20URLs">'. <a href="index.php?tab=AdminMeta&token='.Tools::getAdminTokenLite('AdminMeta').'#SEO%20%26%20URLs">'.
@@ -351,7 +351,7 @@ class AdminHomeControllerCore extends AdminController
$orders = Order::getOrdersWithInformations(10); $orders = Order::getOrdersWithInformations(10);
$i = 0; $i = 0;
foreach ($orders AS $order) foreach ($orders as $order)
{ {
$currency = Currency::getCurrency((int)$order['id_currency']); $currency = Currency::getCurrency((int)$order['id_currency']);
$content .= ' $content .= '
@@ -545,8 +545,7 @@ class AdminHomeControllerCore extends AdminController
{ {
$upgrade = new Upgrader(true); $upgrade = new Upgrader(true);
// if this information is outdated, the version will be checked after page loading // if this information is outdated, the version will be checked after page loading
if (Configuration::get('PS_LAST_VERSION_CHECK') if (Configuration::get('PS_LAST_VERSION_CHECK') < time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS))
< time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS))
$tpl_vars['refresh_check_version'] = 1; $tpl_vars['refresh_check_version'] = 1;
} }
+35 -21
View File
@@ -286,7 +286,7 @@ class AdminImagesControllerCore extends AdminController
protected function _childValidation() protected function _childValidation()
{ {
if (!Tools::getValue('id_image_type') AND Validate::isImageTypeName($typeName = Tools::getValue('name')) AND ImageType::typeAlreadyExists($typeName)) if (!Tools::getValue('id_image_type') && Validate::isImageTypeName($typeName = Tools::getValue('name')) && ImageType::typeAlreadyExists($typeName))
$this->errors[] = Tools::displayError('This name already exists.'); $this->errors[] = Tools::displayError('This name already exists.');
} }
@@ -322,9 +322,9 @@ class AdminImagesControllerCore extends AdminController
if (!is_dir($dir)) if (!is_dir($dir))
return false; return false;
$toDel = scandir($dir); $toDel = scandir($dir);
foreach ($toDel AS $d) foreach ($toDel as $d)
foreach ($type AS $imageType) foreach ($type as $imageType)
if (preg_match('/^[0-9]+\-'.($product ? '[0-9]+\-' : '').$imageType['name'].'\.jpg$/', $d) OR preg_match('/^([[:lower:]]{2})\-default\-(.*)\.jpg$/', $d)) if (preg_match('/^[0-9]+\-'.($product ? '[0-9]+\-' : '').$imageType['name'].'\.jpg$/', $d) || preg_match('/^([[:lower:]]{2})\-default\-(.*)\.jpg$/', $d))
if (file_exists($dir.$d)) if (file_exists($dir.$d))
unlink($dir.$d); unlink($dir.$d);
@@ -332,15 +332,15 @@ class AdminImagesControllerCore extends AdminController
if ($product) if ($product)
{ {
$productsImages = Image::getAllImages(); $productsImages = Image::getAllImages();
foreach ($productsImages AS $k => $image) foreach ($productsImages as $image)
{ {
$imageObj = new Image($image['id_image']); $imageObj = new Image($image['id_image']);
$imageObj->id_product = $image['id_product']; $imageObj->id_product = $image['id_product'];
if (file_exists($dir.$imageObj->getImgFolder())) if (file_exists($dir.$imageObj->getImgFolder()))
{ {
$toDel = scandir($dir.$imageObj->getImgFolder()); $toDel = scandir($dir.$imageObj->getImgFolder());
foreach ($toDel AS $d) foreach ($toDel as $d)
foreach ($type AS $imageType) foreach ($type as $imageType)
if (preg_match('/^[0-9]+\-'.$imageType['name'].'\.jpg$/', $d)) if (preg_match('/^[0-9]+\-'.$imageType['name'].'\.jpg$/', $d))
if (file_exists($dir.$imageObj->getImgFolder().$d)) if (file_exists($dir.$imageObj->getImgFolder().$d))
unlink($dir.$imageObj->getImgFolder().$d); unlink($dir.$imageObj->getImgFolder().$d);
@@ -349,7 +349,14 @@ class AdminImagesControllerCore extends AdminController
} }
} }
// Regenerate images /**
* Regenerate images
*
* @param $dir
* @param $type
* @param bool $productsImages
* @return bool|string
*/
protected function _regenerateNewImages($dir, $type, $productsImages = false) protected function _regenerateNewImages($dir, $type, $productsImages = false)
{ {
if (!is_dir($dir)) if (!is_dir($dir))
@@ -358,9 +365,9 @@ class AdminImagesControllerCore extends AdminController
$toRegen = scandir($dir); $toRegen = scandir($dir);
if (!$productsImages) if (!$productsImages)
{ {
foreach ($toRegen AS $image) foreach ($toRegen as $image)
if (preg_match('/^[0-9]*\.jpg$/', $image)) if (preg_match('/^[0-9]*\.jpg$/', $image))
foreach ($type AS $k => $imageType) foreach ($type as $k => $imageType)
{ {
// Customizable writing dir // Customizable writing dir
$newDir = $dir; $newDir = $dir;
@@ -378,11 +385,11 @@ class AdminImagesControllerCore extends AdminController
else else
{ {
$productsImages = Image::getAllImages(); $productsImages = Image::getAllImages();
foreach ($productsImages AS $k => $image) foreach ($productsImages as $image)
{ {
$imageObj = new Image($image['id_image']); $imageObj = new Image($image['id_image']);
if (file_exists($dir.$imageObj->getExistingImgPath().'.jpg')) if (file_exists($dir.$imageObj->getExistingImgPath().'.jpg'))
foreach ($type AS $k => $imageType) foreach ($type as $imageType)
{ {
if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg')) if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg'))
if (!ImageManager::resize($dir.$imageObj->getExistingImgPath().'.jpg', $dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height']))) if (!ImageManager::resize($dir.$imageObj->getExistingImgPath().'.jpg', $dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])))
@@ -396,13 +403,20 @@ class AdminImagesControllerCore extends AdminController
return $errors; return $errors;
} }
// Regenerate no-pictures images /**
* Regenerate no-pictures images
*
* @param $dir
* @param $type
* @param $languages
* @return bool
*/
protected function _regenerateNoPictureImages($dir, $type, $languages) protected function _regenerateNoPictureImages($dir, $type, $languages)
{ {
$errors = false; $errors = false;
foreach ($type AS $k => $imageType) foreach ($type as $imageType)
{ {
foreach ($languages AS $language) foreach ($languages as $language)
{ {
$file = $dir.$language['iso_code'].'.jpg'; $file = $dir.$language['iso_code'].'.jpg';
if (!file_exists($file)) if (!file_exists($file))
@@ -415,7 +429,7 @@ class AdminImagesControllerCore extends AdminController
return $errors; return $errors;
} }
// Hook watermark optimization /* Hook watermark optimization */
protected function _regenerateWatermark($dir) protected function _regenerateWatermark($dir)
{ {
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
@@ -433,7 +447,7 @@ class AdminImagesControllerCore extends AdminController
if (file_exists($dir.$imageObj->getExistingImgPath().'.jpg')) if (file_exists($dir.$imageObj->getExistingImgPath().'.jpg'))
foreach ($result as $module) foreach ($result as $module)
{ {
if ($moduleInstance = Module::getInstanceByName($module['name']) AND is_callable(array($moduleInstance, 'hookwatermark'))) if ($moduleInstance = Module::getInstanceByName($module['name']) && is_callable(array($moduleInstance, 'hookwatermark')))
call_user_func(array($moduleInstance, 'hookwatermark'), array('id_image' => $imageObj->id, 'id_product' => $imageObj->id_product)); call_user_func(array($moduleInstance, 'hookwatermark'), array('id_image' => $imageObj->id, 'id_product' => $imageObj->id_product));
if (time() - $this->start_time > $this->max_execution_time - 4) // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server if (time() - $this->start_time > $this->max_execution_time - 4) // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
return 'timeout'; return 'timeout';
@@ -460,7 +474,7 @@ class AdminImagesControllerCore extends AdminController
); );
// Launching generation process // Launching generation process
foreach ($process AS $k => $proc) foreach ($process as $proc)
{ {
if ($type != 'all' && $type != $proc['type']) if ($type != 'all' && $type != $proc['type'])
continue; continue;
@@ -471,7 +485,7 @@ class AdminImagesControllerCore extends AdminController
{ {
$format = strval(Tools::getValue('format_'.$type)); $format = strval(Tools::getValue('format_'.$type));
if ($format != 'all') if ($format != 'all')
foreach ($formats AS $k => $form) foreach ($formats as $k => $form)
if ($form['id_image_type'] != $format) if ($form['id_image_type'] != $format)
unset($formats[$k]); unset($formats[$k]);
} }
@@ -492,7 +506,7 @@ class AdminImagesControllerCore extends AdminController
$this->errors[] = Tools::displayError('Cannot write no-picture image to').' ('.$proc['type'].') '.Tools::displayError('images folder. Please check the folder\'s writing permissions.'); $this->errors[] = Tools::displayError('Cannot write no-picture image to').' ('.$proc['type'].') '.Tools::displayError('images folder. Please check the folder\'s writing permissions.');
} }
} }
return (sizeof($this->errors) > 0 ? false : true); return (count($this->errors) > 0 ? false : true);
} }
/** /**
@@ -523,7 +537,7 @@ class AdminImagesControllerCore extends AdminController
else if ($result === false) else if ($result === false)
$this->errors[] = Tools::displayError('Error: some or all images could not be moved.'); $this->errors[] = Tools::displayError('Error: some or all images could not be moved.');
} }
return (sizeof($this->errors) > 0 ? false : true); return (count($this->errors) > 0 ? false : true);
} }
public function initContent() public function initContent()
@@ -503,7 +503,7 @@ class AdminLanguagesControllerCore extends AdminController
// Get all iso code available // Get all iso code available
$lang_packs = Tools::file_get_contents('http://api.prestashop.com/download/lang_packs/get_language_pack.php?version='.(string)$_GET['ps_version'].'&iso_lang='.(string)$_GET['iso_lang']); $lang_packs = Tools::file_get_contents('http://api.prestashop.com/download/lang_packs/get_language_pack.php?version='.(string)$_GET['ps_version'].'&iso_lang='.(string)$_GET['iso_lang']);
if ($lang_packs !== '' && Tools::jsonDecode($lang_packs) !== NULL) if ($lang_packs !== '' && Tools::jsonDecode($lang_packs) !== null)
{ {
$this->status = 'ok'; $this->status = 'ok';
$this->content = $lang_packs; $this->content = $lang_packs;
+6 -7
View File
@@ -50,7 +50,7 @@ class AdminLoginControllerCore extends AdminController
public function initContent() public function initContent()
{ {
if ((empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off') AND Configuration::get('PS_SSL_ENABLED')) if ((empty($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off') && Configuration::get('PS_SSL_ENABLED'))
{ {
// You can uncomment these lines if you want to force https even from localhost and automatically redirect // You can uncomment these lines if you want to force https even from localhost and automatically redirect
// header('HTTP/1.1 301 Moved Permanently'); // header('HTTP/1.1 301 Moved Permanently');
@@ -71,15 +71,14 @@ class AdminLoginControllerCore extends AdminController
if (file_exists(_PS_ADMIN_DIR_.'/../install') || file_exists(_PS_ADMIN_DIR_.'/../admin') if (file_exists(_PS_ADMIN_DIR_.'/../install') || file_exists(_PS_ADMIN_DIR_.'/../admin')
|| (file_exists(_PS_ADMIN_DIR_.'/../install-new') && (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)) || (file_exists(_PS_ADMIN_DIR_.'/../install-new') && (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)))
)
$this->context->smarty->assign( $this->context->smarty->assign(
array( array(
'randomNb' => rand(100, 999), 'randomNb' => rand(100, 999),
'wrong_folder_name' => true) 'wrong_folder_name' => true)
); );
if ($nbErrors = sizeof($this->errors)) if ($nbErrors = count($this->errors))
$this->context->smarty->assign( $this->context->smarty->assign(
array( array(
'errors' => $this->errors, 'errors' => $this->errors,
@@ -132,7 +131,7 @@ class AdminLoginControllerCore extends AdminController
else if (!Validate::isPasswd($passwd)) else if (!Validate::isPasswd($passwd))
$this->errors[] = Tools::displayError('Invalid password'); $this->errors[] = Tools::displayError('Invalid password');
if (!sizeof($this->errors)) if (!count($this->errors))
{ {
/* Seeking for employee */ /* Seeking for employee */
$employee = new Employee(); $employee = new Employee();
@@ -181,7 +180,7 @@ class AdminLoginControllerCore extends AdminController
else else
{ {
$employee = new Employee(); $employee = new Employee();
if (!$employee->getByemail($email) OR !$employee) if (!$employee->getByemail($email) || !$employee)
$this->errors[] = Tools::displayError('This account does not exist'); $this->errors[] = Tools::displayError('This account does not exist');
else if ((strtotime($employee->last_passwd_gen.'+'.Configuration::get('PS_PASSWD_TIME_BACK').' minutes') - time()) > 0) else if ((strtotime($employee->last_passwd_gen.'+'.Configuration::get('PS_PASSWD_TIME_BACK').' minutes') - time()) > 0)
$this->errors[] = Tools::displayError('You can regenerate your password only every').' '.Configuration::get('PS_PASSWD_TIME_BACK').' '.Tools::displayError('minute(s)'); $this->errors[] = Tools::displayError('You can regenerate your password only every').' '.Configuration::get('PS_PASSWD_TIME_BACK').' '.Tools::displayError('minute(s)');
@@ -189,7 +188,7 @@ class AdminLoginControllerCore extends AdminController
if (_PS_MODE_DEMO_) if (_PS_MODE_DEMO_)
$errors[] = Tools::displayError('This functionnality has been disabled.'); $errors[] = Tools::displayError('This functionnality has been disabled.');
if(!sizeof($this->errors)) if (!count($this->errors))
{ {
$pwd = Tools::passwdGen(); $pwd = Tools::passwdGen();
$employee->passwd = md5(pSQL(_COOKIE_KEY_.$pwd)); $employee->passwd = md5(pSQL(_COOKIE_KEY_.$pwd));
+4 -4
View File
@@ -188,11 +188,11 @@ class AdminMetaControllerCore extends AdminController
} }
else else
{ // index.php can have empty rewrite rule { // index.php can have empty rewrite rule
$defaultLangIsValidated = !Tools::getValue('url_rewrite_'.$default_language) OR Validate::isLinkRewrite(Tools::getValue('url_rewrite_'.$default_language)); $defaultLangIsValidated = !Tools::getValue('url_rewrite_'.$default_language) || Validate::isLinkRewrite(Tools::getValue('url_rewrite_'.$default_language));
$englishLangIsValidated = !Tools::getValue('url_rewrite_1') OR Validate::isLinkRewrite(Tools::getValue('url_rewrite_1')); $englishLangIsValidated = !Tools::getValue('url_rewrite_1') || Validate::isLinkRewrite(Tools::getValue('url_rewrite_1'));
} }
if (!$defaultLangIsValidated AND !$englishLangIsValidated) if (!$defaultLangIsValidated && !$englishLangIsValidated)
{ {
$this->errors[] = Tools::displayError('Url rewrite field must be filled at least in default or english language.'); $this->errors[] = Tools::displayError('Url rewrite field must be filled at least in default or english language.');
return false; return false;
@@ -214,7 +214,7 @@ class AdminMetaControllerCore extends AdminController
return parent::postProcess(); return parent::postProcess();
} }
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false) public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = false)
{ {
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID(true)); parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID(true));
} }