From 336e784ca51d9e2bc35b60cdc0f3f466caabba03 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Thu, 28 Nov 2013 15:32:19 +0100 Subject: [PATCH 1/9] [*] CORE : Throw Exception when no theme selected --- classes/exception/PrestaShopException.php | 5 +++-- config/config.inc.php | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/classes/exception/PrestaShopException.php b/classes/exception/PrestaShopException.php index 465bf0ddd..7cc56f203 100644 --- a/classes/exception/PrestaShopException.php +++ b/classes/exception/PrestaShopException.php @@ -66,14 +66,15 @@ class PrestaShopExceptionCore extends Exception echo ''.((isset($trace['class'])) ? $trace['class'] : '').((isset($trace['type'])) ? $trace['type'] : '').$trace['function'].''; echo ' - [line '.$current_line.' - '.$relative_file.']'; - if (count($trace['args'])) + if (isset($trace['args']) && count($trace['args'])) echo ' - ['.count($trace['args']).' Arguments]'; else echo ' - [0 Argument]'; if ($relative_file) $this->displayFileDebug($trace['file'], $trace['line'], $id); - $this->displayArgsDebug($trace['args'], $id); + if (isset($trace['args']) && count($trace['args'])) + $this->displayArgsDebug($trace['args'], $id); echo ''; } echo ''; diff --git a/config/config.inc.php b/config/config.inc.php index 763f3a135..2713c2a39 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -93,13 +93,15 @@ $context = Context::getContext(); try { $context->shop = Shop::initialize(); + if (Tools::isEmpty($theme_name = $context->shop->getTheme()) || !file_exists(_PS_ALL_THEMES_DIR_.$theme_name)) + throw new PrestaShopException('No theme selected'); } catch (PrestaShopException $e) { $e->displayMessage(); } -define('_THEME_NAME_', $context->shop->getTheme()); +define('_THEME_NAME_', $theme_name); define('__PS_BASE_URI__', $context->shop->getBaseURI()); /* Include all defines related to base uri and theme name */ From 726149038130792ca162b2a9f7b84cdb2583e96c Mon Sep 17 00:00:00 2001 From: Jerome Nadaud Date: Thu, 28 Nov 2013 15:35:17 +0100 Subject: [PATCH 2/9] // Fix Categories image problem --- .../themes/default/template/helpers/uploader/simple.tpl | 2 +- controllers/admin/AdminCategoriesController.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/admin-dev/themes/default/template/helpers/uploader/simple.tpl b/admin-dev/themes/default/template/helpers/uploader/simple.tpl index 8da9a642d..8d8bbd0b7 100644 --- a/admin-dev/themes/default/template/helpers/uploader/simple.tpl +++ b/admin-dev/themes/default/template/helpers/uploader/simple.tpl @@ -49,7 +49,7 @@ {else}
-
+
diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index de4877ab0..7acdccd79 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -477,9 +477,8 @@ class AdminCategoriesControllerCore extends AdminController 'display_image' => true, 'image' => $image_url ? $image_url : false, 'size' => $image_size, - 'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->id.'&token='.$this->token.'&deleteImage=1', + 'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->_category->id.'&token='.$this->token.'&deleteImage=1', 'hint' => $this->l('Upload a category logo from your computer.'), - 'col' => 4 ), array( 'type' => 'text', @@ -602,7 +601,7 @@ class AdminCategoriesControllerCore extends AdminController { if (!in_array($this->display, array('edit', 'add'))) $this->multishop_context_group = false; - if (Tools::isSubmit('forcedeleteImage') || (isset($_FILES['image']) && $_FILES['image']['size'] > 0)) + if (Tools::isSubmit('forcedeleteImage') || (isset($_FILES['image']) && $_FILES['image']['size'] > 0) || Tools::getValue('deleteImage')) { $this->processForceDeleteImage(); if (Tools::isSubmit('forcedeleteImage')) From d46feffcf18f4d0493646f7cba70532cabf257e0 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Thu, 28 Nov 2013 16:14:30 +0100 Subject: [PATCH 3/9] [*] CORE : Throw Exception when no theme selected only in front office --- classes/controller/FrontController.php | 2 +- config/config.inc.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index fee2d0924..3ad4f2e42 100644 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -162,7 +162,7 @@ class FrontControllerCore extends Controller /* Theme is missing */ if (!is_dir(_PS_THEME_DIR_)) - die(sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\')))); + throw new PrestaShopException((sprintf(Tools::displayError('Current theme unavailable "%s". Please check your theme directory name and permissions.'), basename(rtrim(_PS_THEME_DIR_, '/\\'))))); if (Configuration::get('PS_GEOLOCATION_ENABLED')) if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault)) diff --git a/config/config.inc.php b/config/config.inc.php index 2713c2a39..22d6f9ea3 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -93,14 +93,13 @@ $context = Context::getContext(); try { $context->shop = Shop::initialize(); - if (Tools::isEmpty($theme_name = $context->shop->getTheme()) || !file_exists(_PS_ALL_THEMES_DIR_.$theme_name)) - throw new PrestaShopException('No theme selected'); + if (Tools::isEmpty($theme_name = $context->shop->getTheme()) && !defined('_PS_ADMIN_DIR_')) + throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.')); } catch (PrestaShopException $e) { $e->displayMessage(); } - define('_THEME_NAME_', $theme_name); define('__PS_BASE_URI__', $context->shop->getBaseURI()); From 66947b53542c8a20979ceef96239869f581da284 Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Thu, 28 Nov 2013 17:38:05 +0100 Subject: [PATCH 4/9] //multiple small fix on carrier wizard --- .../carrier_wizard/helpers/form/form.tpl | 5 - .../helpers/form/form_ranges.tpl | 5 +- js/admin_carrier_wizard.js | 143 ++++++++++-------- 3 files changed, 87 insertions(+), 66 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl index f6ddbe690..7daee2ae5 100644 --- a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl @@ -59,14 +59,9 @@

+ +
diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index da1761cce..c65f0ce85 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -444,6 +444,120 @@ class AdminProductsControllerCore extends AdminController } } + public function ajaxProcessAddAttachment() + { + if (isset($_FILES['attachment_file'])) + { + if ((int)$_FILES['attachment_file']['error'] === 1) + { + $_FILES['attachment_file']['error'] = array(); + + $max_upload = (int)ini_get('upload_max_filesize'); + $max_post = (int)ini_get('post_max_size'); + $upload_mb = min($max_upload, $max_post); + $_FILES['attachment_file']['error'][] = sprintf( + $this->l('The file %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), + ''.$_FILES['attachment_file']['name'].' ', + ''.$upload_mb.'' + ); + } + + $_FILES['attachment_file']['error'] = array(); + + $is_attachment_name_valid = false; + $attachment_names = Tools::getValue('attachment_name'); + $attachment_descriptions = Tools::getValue('attachment_description'); + + if (!isset($attachment_names) || !$attachment_names) + $attachment_names = array(); + + if (!isset($attachment_descriptions) || !$attachment_descriptions) + $attachment_descriptions = array(); + + foreach ($attachment_names as $lang => $name) + { + if (Tools::strlen($name) > 0) + $is_attachment_name_valid = true; + + if (!Validate::isGenericName($name)) + $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid name for %s language'), Language::getLanguage((int)$lang)['name']); + elseif (Tools::strlen($name) > 32) + $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('The name for %1s language is too long (%2d chars max).'), Language::getLanguage((int)$lang)['name'], 32); + } + + foreach ($attachment_descriptions as $lang => $description) + if (!Validate::isCleanHtml($description)) + $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid description for %s language'), Language::getLanguage((int)$lang)['name']); + + if (!$is_attachment_name_valid) + $_FILES['attachment_file']['error'][] = Tools::displayError('An attachment name is required.'); + + if (empty($_FILES['attachment_file']['error'])) + { + if (is_uploaded_file($_FILES['attachment_file']['tmp_name'])) + { + if ($_FILES['attachment_file']['size'] > (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024)) + $_FILES['attachment_file']['error'][] = sprintf( + $this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'), + (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024), + number_format(($_FILES['attachment_file']['size'] / 1024), 2, '.', '') + ); + else + { + do $uniqid = sha1(microtime()); + while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid)); + if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid)) + $_FILES['attachment_file']['error'][] = $this->l('File copy failed'); + @unlink($_FILES['attachment_file']['tmp_name']); + } + } + else + $_FILES['attachment_file']['error'][] = Tools::displayError('The file is missing.'); + + if (empty($_FILES['attachment_file']['error']) && isset($uniqid)) + { + $attachment = new Attachment(); + + foreach ($attachment_names as $lang => $name) + $attachment->name[(int)$lang] = $name; + + foreach ($attachment_descriptions as $lang => $description) + $attachment->description[(int)$lang] = $description; + + $attachment->file = $uniqid; + $attachment->mime = $_FILES['attachment_file']['type']; + $attachment->file_name = $_FILES['attachment_file']['name']; + + if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) + $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file extension'); + if (!Validate::isGenericName($attachment->file_name)) + $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file name'); + if (Tools::strlen($attachment->file_name) > 128) + $_FILES['attachment_file']['error'][] = Tools::displayError('The file name is too long.'); + if (empty($this->errors)) + { + $res = $attachment->add(); + if (!$res) + $_FILES['attachment_file']['error'][] = Tools::displayError('This attachment was unable to be loaded into the database.'); + else + { + $_FILES['attachment_file']['id_attachment'] = $attachment->id; + $_FILES['attachment_file']['filename'] = $attachment->name[$this->context->employee->id_lang]; + $id_product = (int)Tools::getValue($this->identifier); + $res = $attachment->attachProduct($id_product); + if (!$res) + $_FILES['attachment_file']['error'][] = Tools::displayError('We were unable to associate this attachment to a product.'); + } + } + else + $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file'); + } + } + + die(Tools::jsonEncode($_FILES)); + } + } + /** * Upload new attachment * @@ -3472,7 +3586,8 @@ class AdminProductsControllerCore extends AdminController 'default_form_language' => (int)Configuration::get('PS_LANG_DEFAULT'), 'attachment_name' => $attachment_name, 'attachment_description' => $attachment_description, - 'PS_ATTACHMENT_MAXIMUM_SIZE' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') + 'PS_ATTACHMENT_MAXIMUM_SIZE' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE'), + 'post_max_size' => (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) )); } else @@ -3481,7 +3596,27 @@ class AdminProductsControllerCore extends AdminController else $this->displayWarning($this->l('You must save this product before adding attachements.')); - $this->tpl_form_vars['custom_form'] = $data->fetch(); + $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); + $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); + $bo_theme = ((Validate::isLoadedObject($this->context->employee) + && $this->context->employee->bo_theme) ? $this->context->employee->bo_theme : 'default'); + + if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR + .'template')) + $bo_theme = 'default'; + + $html = ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + + $this->tpl_form_vars['custom_form'] = $html.$data->fetch(); } public function initFormInformations($product)