diff --git a/admin-dev/themes/default/js/jquery.fileupload.js b/admin-dev/themes/default/js/jquery.fileupload.js index 16ebb1d95..a39958abb 100644 --- a/admin-dev/themes/default/js/jquery.fileupload.js +++ b/admin-dev/themes/default/js/jquery.fileupload.js @@ -562,6 +562,7 @@ var options = $.extend({}, this.options, data); this._initFormSettings(options); this._initDataSettings(options); + options.url = options.url+'&rand=' + new Date().getTime(); return options; }, diff --git a/admin-dev/themes/default/template/controllers/search/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/search/helpers/view/view.tpl index 406943226..e113b2fd3 100644 --- a/admin-dev/themes/default/template/controllers/search/helpers/view/view.tpl +++ b/admin-dev/themes/default/template/controllers/search/helpers/view/view.tpl @@ -29,7 +29,7 @@ $(function() { }); -{if !$nb_results} +{if !isset($nb_results) || !$nb_results}

{l s='There are no results matching your query "%s".' sprintf=$query}

{else}

diff --git a/admin-dev/themes/default/template/header.tpl b/admin-dev/themes/default/template/header.tpl index df67e525d..5d91b6780 100644 --- a/admin-dev/themes/default/template/header.tpl +++ b/admin-dev/themes/default/template/header.tpl @@ -71,7 +71,9 @@ var token_admin_customer_threads = '{getAdminToken tab='AdminCustomerThreads'}'; var currentIndex = '{$currentIndex|@addcslashes:'\''}'; var choose_language_translate = '{l s='Choose language' js=1}'; - var default_language = '{$default_language|addslashes}'; + var default_language = '{$default_language|intval}'; + var admin_modules_link = '{$link->getAdminLink("AdminModules")|addslashes}'; + var tab_modules_list = '{if isset($tab_modules_list) && $tab_modules_list}{$tab_modules_list|addslashes}{/if}'; {/if} {if isset($css_files)} @@ -111,7 +113,7 @@ - + {$shop_name} diff --git a/admin-dev/themes/default/template/helpers/list/list_header.tpl b/admin-dev/themes/default/template/helpers/list/list_header.tpl index d5552015d..10a3bf9b5 100644 --- a/admin-dev/themes/default/template/helpers/list/list_header.tpl +++ b/admin-dev/themes/default/template/helpers/list/list_header.tpl @@ -214,7 +214,7 @@ {$params.title} {/if} - {if (!isset($params.orderby) || $params.orderby) && !$simple_header} + {if (!isset($params.orderby) || $params.orderby) && !$simple_header && $show_filters} diff --git a/admin-dev/themes/default/template/helpers/uploader/ajax.tpl b/admin-dev/themes/default/template/helpers/uploader/ajax.tpl index 68a240124..e5ae31901 100644 --- a/admin-dev/themes/default/template/helpers/uploader/ajax.tpl +++ b/admin-dev/themes/default/template/helpers/uploader/ajax.tpl @@ -43,6 +43,18 @@ {/if} +{if isset($max_files) && $files|count >= $max_files} +
+
{l s='You have reached the limit (%s) of files to upload, please remove files to continue uploading' sprintf=$max_files}
+
+ +{else}
@@ -55,167 +67,138 @@
+ - \ No newline at end of file + {$id}_total_files++; + }).on('fileuploadprocessalways', function (e, data) { + var index = data.index, file = data.files[index]; + + if (file.error) { + $('#{$id}-errors').append('
'+file.name+' ('+humanizeSize(file.size)+') : '+file.error+'
').parent().show(); + $(data.context).find('button').trigger('click'); + } + }); + + $('#{$id}-add-button').on('click', function() { + $('#{$id}-success').html('').parent().hide(); + $('#{$id}-errors').html('').parent().hide(); + $('#{$id}-files-list').html('').parent().hide(); + {$id}_total_files = 0; + $('#{$id}').trigger('click'); + }); + }); + +{/if} \ No newline at end of file diff --git a/admin-dev/themes/default/template/helpers/uploader/simple.tpl b/admin-dev/themes/default/template/helpers/uploader/simple.tpl index e5f386a5a..0c1510d3e 100644 --- a/admin-dev/themes/default/template/helpers/uploader/simple.tpl +++ b/admin-dev/themes/default/template/helpers/uploader/simple.tpl @@ -50,6 +50,11 @@ {/if} +{if isset($max_files) && $files|count >= $max_files} +
+
{l s='You have reached the limit (%s) of files to upload, please remove files to continue uploading' sprintf=$max_files}
+
+{else}
@@ -72,10 +77,9 @@
- \ No newline at end of file + +{/if} \ No newline at end of file diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index 17acd932b..e6aab3c95 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -205,7 +205,13 @@ class DispatcherCore { $this->front_controller = self::FC_ADMIN; $this->controller_not_found = 'adminnotfound'; - $this->default_controller = 'admindashboard'; + if (isset(Context::getContext()->employee) && Validate::isLoadedObject(Context::getContext()->employee) && isset(Context::getContext()->employee->default_tab)) + { + $tab = new Tab((int)Context::getContext()->employee->default_tab); + $this->default_controller = $tab->class_name; + } + else + $this->default_controller = 'admindashboard'; } elseif (Tools::getValue('fc') == 'module') { diff --git a/classes/Uploader.php b/classes/Uploader.php index 8152dab70..c36036eea 100644 --- a/classes/Uploader.php +++ b/classes/Uploader.php @@ -48,9 +48,6 @@ class UploaderCore public function getAcceptTypes() { - if (!isset($this->_accept_types)) - $this->setAcceptTypes('/.+$/i'); - return $this->_accept_types; } @@ -101,6 +98,21 @@ class UploaderCore return $this; } + public function getPostMaxSizeBytes() { + $post_max_size = ini_get('post_max_size'); + $bytes = trim($post_max_size); + $last = strtolower($post_max_size[strlen($post_max_size) - 1]); + + switch ($last) + { + case 'g': $bytes *= 1024; + case 'm': $bytes *= 1024; + case 'k': $bytes *= 1024; + } + + return $bytes; + } + public function getSavePath() { if (!isset($this->_save_path)) @@ -134,8 +146,11 @@ class UploaderCore $this->files[] = $this->upload($tmp[$index]); } } - else + elseif ($upload) + { + $this->files[] = $this->upload($upload); + } return $this->files; } @@ -173,7 +188,7 @@ class UploaderCore protected function validate($file) { - $post_max_size = $this->_getPostMaxSizeBytes(); + $post_max_size = $this->getPostMaxSizeBytes(); if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size)) { @@ -181,7 +196,10 @@ class UploaderCore return false; } - if (!preg_match($this->getAcceptTypes(), $file['name'])) + $types = $this->getAcceptTypes(); + + //TODO check mime type. + if (isset($types) && !in_array(pathinfo($file['name'], PATHINFO_EXTENSION), $types)) { $file['error'] = Tools::displayError('Filetype not allowed'); return false; @@ -203,21 +221,6 @@ class UploaderCore return filesize($file_path); } - protected function _getPostMaxSizeBytes() { - $post_max_size = ini_get('post_max_size'); - $bytes = trim($post_max_size); - $last = strtolower($post_max_size[strlen($post_max_size) - 1]); - - switch ($last) - { - case 'g': $bytes *= 1024; - case 'm': $bytes *= 1024; - case 'k': $bytes *= 1024; - } - - return $bytes; - } - protected function _getServerVars($var) { return (isset($_SERVER[$var]) ? $_SERVER[$var] : ''); diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 552a7d8e6..16a1c5f9a 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -1502,7 +1502,7 @@ class AdminControllerCore extends Controller if (Validate::isLoadedObject($this->context->employee)) { $accesses = Profile::getProfileAccesses($this->context->employee->id_profile, 'class_name'); - + $default_tab = new Tab((int)Context::getContext()->employee->default_tab); /* Hooks are volontary out the initialize array (need those variables already assigned) */ $bo_color = empty($this->context->employee->bo_color) ? '#FFFFFF' : $this->context->employee->bo_color; $this->context->smarty->assign(array( @@ -1516,7 +1516,7 @@ class AdminControllerCore extends Controller 'show_new_customers' => Configuration::get('PS_SHOW_NEW_CUSTOMERS') && $accesses['AdminCustomers']['view'], 'show_new_messages' => Configuration::get('PS_SHOW_NEW_MESSAGES') && $accesses['AdminCustomerThreads']['view'], 'first_name' => Tools::substr($this->context->employee->firstname, 0, 1), - 'last_name' => htmlentities($this->context->employee->lastname, ENT_COMPAT, 'UTF-8'), + 'last_name' => Tools::safeOutput($this->context->employee->lastname), 'employee' => $this->context->employee, 'search_type' => Tools::getValue('bo_search_type'), 'bo_query' => Tools::safeOutput(Tools::stripslashes(Tools::getValue('bo_query'))), @@ -1529,9 +1529,13 @@ class AdminControllerCore extends Controller 'tabs' => $tabs, 'is_multishop' => $is_multishop, 'multishop_context' => $this->multishop_context, + 'default_tab_link' => $this->context->link->getAdminLink($default_tab->class_name), 'employee_avatar' => ImageManager::thumbnail($this->context->employee->getImage(), 'employee'.'_'.(int)$this->context->employee->id.'.'.$this->imageType, 150, $this->imageType, true, true) )); } + else + $this->context->smarty->assign('default_tab_link', $this->context->link->getAdminLink('AdminDashboard')); + $this->context->smarty->assign(array( 'img_dir' => _PS_IMG_, 'iso' => $this->context->language->iso_code, diff --git a/classes/helper/HelperForm.php b/classes/helper/HelperForm.php index f406e2ee9..0c8554a4a 100644 --- a/classes/helper/HelperForm.php +++ b/classes/helper/HelperForm.php @@ -118,6 +118,7 @@ class HelperFormCore extends Helper $uploader->setUrl(isset($params['url'])?$params['url']:null); $uploader->setMultiple(isset($params['multiple'])?$params['multiple']:false); $uploader->setUseAjax(isset($params['ajax'])?$params['ajax']:false); + $uploader->setMaxFiles(isset($params['max_files'])?$params['max_files']:null); if (isset($params['files']) && $params['files']) $uploader->setFiles($params['files']); @@ -139,7 +140,6 @@ class HelperFormCore extends Helper 'download_url' => isset($params['file'])?$params['file']:null ))); - $uploader->setThumb(isset($params['thumb'])?$params['thumb']:null); $uploader->setTitle(isset($params['title'])?$params['title']:null); diff --git a/classes/helper/HelperImageUploader.php b/classes/helper/HelperImageUploader.php index 830a6b92d..708d420f7 100644 --- a/classes/helper/HelperImageUploader.php +++ b/classes/helper/HelperImageUploader.php @@ -26,35 +26,25 @@ class HelperImageUploaderCore extends HelperUploader { - private $_temporary_path; - public function getMaxSize() { return (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'); } - public function setTemporaryPath($value) + public function getSavePath() { - $this->_temporary_path = $value; - } - - public function getTemporaryPath() - { - if (!isset($this->_temporary_path)) - $this->_temporary_path = _PS_TMP_IMG_DIR_; - - return $this->_normalizeDirectory($this->_temporary_path); + return $this->_normalizeDirectory(_PS_TMP_IMG_DIR_); } public function getFilePath($file_name = null) { //Force file path - return tempnam($this->getTemporaryPath(), $this->getUniqueFileName()); + return tempnam($this->getSavePath(), $this->getUniqueFileName()); } protected function validate($file) { - $post_max_size = $this->_getPostMaxSizeBytes(); + $post_max_size = $this->getPostMaxSizeBytes(); if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size)) { @@ -62,7 +52,10 @@ class HelperImageUploaderCore extends HelperUploader return false; } - if (!preg_match($this->getAcceptTypes(), $file['name'])) + $types = $this->getAcceptTypes(); + + //TODO check mime type. + if (isset($types) && !in_array(pathinfo($file['name'], PATHINFO_EXTENSION), $types)) { $file['error'] = Tools::displayError('Filetype not allowed'); return false; diff --git a/classes/helper/HelperOptions.php b/classes/helper/HelperOptions.php index 2a4b142d9..e17667357 100644 --- a/classes/helper/HelperOptions.php +++ b/classes/helper/HelperOptions.php @@ -104,6 +104,7 @@ class HelperOptionsCore extends Helper $uploader->setUrl(isset($field['url'])?$field['url']:null); $uploader->setMultiple(isset($field['multiple'])?$field['multiple']:false); $uploader->setUseAjax(isset($field['ajax'])?$field['ajax']:false); + $uploader->setMaxFiles(isset($field['max_files'])?$field['max_files']:null); if (isset($field['files']) && $field['files']) $uploader->setFiles($field['files']); diff --git a/classes/helper/HelperUploader.php b/classes/helper/HelperUploader.php index 276f08ba3..daea1b146 100644 --- a/classes/helper/HelperUploader.php +++ b/classes/helper/HelperUploader.php @@ -243,22 +243,28 @@ class HelperUploaderCore extends Uploader .'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js">'; $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; } else { $html = ''; $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath .'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js'); - //$context->controller->addJs('http://blueimp.github.io/JavaScript-Load-Image/js/load-image.min.js'); $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath .'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js'); $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath .'/themes/'.$bo_theme.'/js/jquery.fileupload.js'); - /*$context->controller->addJs(__PS_BASE_URI__.$admin_webpath - .'/themes/'.$bo_theme.'/js/jquery.fileupload-image.js');*/ - + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js'); + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js'); $this->getContext()->controller->addJs(__PS_BASE_URI__.'/js/vendor/spin.js'); $this->getContext()->controller->addJs(__PS_BASE_URI__.'/js/vendor/ladda.js'); } @@ -270,8 +276,6 @@ class HelperUploaderCore extends Uploader $this->getTemplateFile($this->getTemplate()), $this->getContext()->smarty ); - $max_files = $this->getMaxFiles(); - $template->assign(array( 'id' => $this->getId(), 'name' => $this->getName(), @@ -280,7 +284,8 @@ class HelperUploaderCore extends Uploader 'files' => $this->getFiles(), 'thumb' => $this->getThumb(), 'title' => $this->getTitle(), - 'max_files' => (isset($max_files) && $max_files > 0) ? ($max_files-count($this->getFiles())) : $max_files + 'max_files' => $this->getMaxFiles(), + 'post_max_size' => $this->getPostMaxSizeBytes() )); $html .= $template->fetch(); diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 89fa88165..6ee52154d 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -312,11 +312,6 @@ class AdminCategoriesControllerCore extends AdminController } } - public function ajaxProcessuploadThumbnailImages() - { - Hook::exec('actionBackOfficeCategory'); - } - public function initProcess() { if (Tools::isSubmit('add'.$this->table.'root')) @@ -616,9 +611,9 @@ class AdminCategoriesControllerCore extends AdminController Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminCategories').'&conf=7'); } - Hook::exec('actionBackOfficeCategoryRemoveThumbnail'); return parent::postProcess(); } + public function processForceDeleteImage() { $category = $this->loadObject(true); diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 95e1efd6e..e6480cdb6 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -199,6 +199,10 @@ class CategoryControllerCore extends FrontController // Pagination must be call after "getProducts" $this->pagination($this->nbProducts); + Hook::exec('actionProductListModifier', array( + 'nb_products' => &$this->nbProducts, + 'cat_products' => &$this->cat_products, + )); foreach ($this->cat_products as &$product) if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity'])) diff --git a/install-dev/data/xml/hook.xml b/install-dev/data/xml/hook.xml index ae69c546c..c434f6ad7 100644 --- a/install-dev/data/xml/hook.xml +++ b/install-dev/data/xml/hook.xml @@ -283,11 +283,5 @@ displayBackOfficeCategoryDisplay new elements in the Back Office, tab AdminCategoriesThis hook launches modules when the AdminCategories tab is displayed in the Back Office - - actionBackOfficeCategoryProcess new elements in the Back Office, tab AdminCategoriesThis hook process modules when the AdminCategories tab is displayed in the Back Office - - - actionBackOfficeCategoryRemoveThumbnailDelete elements in the Back Office, tab AdminCategoriesThis hook process modules when the AdminCategories tab call delete thumbnail - diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index a8ce9a01b..c96fd37d4 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -45,7 +45,18 @@ class BlockCategories extends Module public function install() { - if (!parent::install() || + // Prepare tab + $tab = new Tab(); + $tab->active = 1; + $tab->class_name = "AdminBlockCategories"; + $tab->name = array(); + foreach (Language::getLanguages(true) as $lang) + $tab->name[$lang['id_lang']] = 'BlockCategories'; + $tab->id_parent = -1; + $tab->module = $this->name; + + if (!$tab->add() || + !parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('footer') || !$this->registerHook('header') || @@ -56,8 +67,6 @@ class BlockCategories extends Module !$this->registerHook('actionAdminMetaControllerUpdate_optionsBefore') || !$this->registerHook('actionAdminLanguagesControllerStatusBefore') || !$this->registerHook('displayBackOfficeCategory') || - !$this->registerHook('actionBackOfficeCategory') || - !$this->registerHook('actionBackOfficeCategoryRemoveThumbnail') || !Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4) || !Configuration::updateValue('BLOCK_CATEG_DHTML', 1)) return false; @@ -66,6 +75,14 @@ class BlockCategories extends Module public function uninstall() { + $id_tab = (int)Tab::getIdFromClassName('AdminBlockCategories'); + + if ($id_tab) + { + $tab = new Tab($id_tab); + $tab->delete(); + } + if (!parent::uninstall() || !Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH') || !Configuration::deleteByName('BLOCK_CATEG_DHTML')) @@ -136,93 +153,18 @@ class BlockCategories extends Module { $files[$i]['type'] = HelperImageUploader::TYPE_IMAGE; $files[$i]['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$i.'_thumb.jpg', $this->context->controller->table.'_'.(int)$category->id.'-'.$i.'_thumb.jpg', 100, 'jpg', true, true); - $files[$i]['delete_url'] = Context::getContext()->link->getAdminLink('AdminCategories').'&deleteThumb='.$i.'&id_category='.(int)$category->id; + $files[$i]['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories').'&deleteThumb='.$i.'&id_category='.(int)$category->id; } } $helper = new HelperImageUploader(); $helper->setMultiple(true)->setUseAjax(true)->setName('thumbnail')->setFiles($files)->setMaxFiles(3)->setUrl( - Context::getContext()->link->getAdminLink('AdminCategories').'&ajax=1&id_category='.$category->id.'&action=uploadThumbnailImages'); + Context::getContext()->link->getAdminLink('AdminBlockCategories').'&ajax=1&id_category='.$category->id + .'&action=uploadThumbnailImages'); $this->smarty->assign('helper', $helper->render()); return $this->display(__FILE__, 'views/blockcategories_admin.tpl'); } - public function hookActionBackOfficeCategory($params) - { - $category = new Category((int)Tools::getValue('id_category')); - - if (isset($_FILES['thumbnail'])) - { - //Get total of image already present in directory - $files = scandir(_PS_CAT_IMG_DIR_); - $assigned_keys = array(); - $allowed_keys = array(0, 1, 2); - - foreach ($files as $file) { - $matches = array(); - - if (preg_match('/'.$category->id.'-([0-9])?_thumb.jpg/i', $file, $matches) === 1) - $assigned_keys[] = (int)$matches[1]; - } - - $available_keys = array_diff($allowed_keys, $assigned_keys); - $helper = new HelperImageUploader('files'); - $files = $helper->setName('thumbnail')->process(); - $total_errors = array(); - - if (count($available_keys) < count($files)) - { - $total_errors[] = sprintf(Tools::displayError('You cannot upload more than %s files'), count($available_keys)); - die(); - } - - foreach ($files as $key => &$file) - { - $id = array_shift($available_keys); - $errors = array(); - // Evaluate the memory required to resize the image: if it's too much, you can't resize it. - if (!ImageManager::checkImageMemoryLimit($file['save_path'])) - $errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. '); - // Copy new image - if (empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_ - .(int)Tools::getValue('id_category').'-'.$id.'_thumb.jpg')) - $errors[] = Tools::displayError('An error occurred while uploading the image.'); - - if (count($errors)) - $total_errors = array_merge($total_errors, $errors); - - unlink($file['save_path']); - //Necesary to prevent hacking - unset($file['save_path']); - - //Add image preview and delete url - $file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$id.'_thumb.jpg', - $this->context->controller->table.'_'.(int)$category->id.'-'.$id.'_thumb.jpg', 100, 'jpg', true, true); - $file['delete_url'] = Context::getContext()->link->getAdminLink('AdminCategories').'&deleteThumb=' - .$id.'&id_category='.(int)$category->id; - $id++; - } - - if (count($total_errors)) - $this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors); - - die(Tools::jsonEncode(array('thumbnail' => $files))); - } - } - - public function hookActionBackOfficeCategoryRemoveThumbnail() - { - if (($id_thumb = Tools::getValue('deleteThumb', false)) !== false) - { - if (file_exists(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg') - && !unlink(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg')) - $this->context->controller->errors[] = Tools::displayError('Error while delete'); - - Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminCategories').'&id_category=' - .(int)Tools::getValue('id_category').'&updatecategory'); - } - } - public function hookLeftColumn($params) { $category = false; diff --git a/modules/blockcategories/controllers/admin/AdminBlockCategoriesController.php b/modules/blockcategories/controllers/admin/AdminBlockCategoriesController.php new file mode 100644 index 000000000..ea6eddc41 --- /dev/null +++ b/modules/blockcategories/controllers/admin/AdminBlockCategoriesController.php @@ -0,0 +1,108 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +/** + * @since 1.6.0 + */ +class AdminBlockCategoriesController extends ModuleAdminController +{ + public function postProcess() + { + if (($id_thumb = Tools::getValue('deleteThumb', false)) !== false) + { + if (file_exists(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg') + && !unlink(_PS_CAT_IMG_DIR_.(int)Tools::getValue('id_category').'-'.(int)$id_thumb.'_thumb.jpg')) + $this->context->controller->errors[] = Tools::displayError('Error while delete'); + + Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminCategories').'&id_category=' + .(int)Tools::getValue('id_category').'&updatecategory'); + } + + parent::postProcess(); + } + + public function ajaxProcessuploadThumbnailImages() + { + $category = new Category((int)Tools::getValue('id_category')); + + if (isset($_FILES['thumbnail'])) + { + //Get total of image already present in directory + $files = scandir(_PS_CAT_IMG_DIR_); + $assigned_keys = array(); + $allowed_keys = array(0, 1, 2); + + foreach ($files as $file) { + $matches = array(); + + if (preg_match('/'.$category->id.'-([0-9])?_thumb.jpg/i', $file, $matches) === 1) + $assigned_keys[] = (int)$matches[1]; + } + + $available_keys = array_diff($allowed_keys, $assigned_keys); + $helper = new HelperImageUploader('thumbnail'); + $files = $helper->process(); + $total_errors = array(); + + if (count($available_keys) < count($files)) + { + $total_errors[] = sprintf(Tools::displayError('You cannot upload more than %s files'), count($available_keys)); + die(); + } + + foreach ($files as $key => &$file) + { + $id = array_shift($available_keys); + $errors = array(); + // Evaluate the memory required to resize the image: if it's too much, you can't resize it. + if (!ImageManager::checkImageMemoryLimit($file['save_path'])) + $errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. '); + // Copy new image + if (empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_ + .(int)Tools::getValue('id_category').'-'.$id.'_thumb.jpg')) + $errors[] = Tools::displayError('An error occurred while uploading the image.'); + + if (count($errors)) + $total_errors = array_merge($total_errors, $errors); + + unlink($file['save_path']); + //Necesary to prevent hacking + unset($file['save_path']); + + //Add image preview and delete url + $file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_.(int)$category->id.'-'.$id.'_thumb.jpg', + $this->context->controller->table.'_'.(int)$category->id.'-'.$id.'_thumb.jpg', 100, 'jpg', true, true); + $file['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories').'&deleteThumb=' + .$id.'&id_category='.(int)$category->id.'&updatecategory'; + } + + if (count($total_errors)) + $this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors); + + die(Tools::jsonEncode(array('thumbnail' => $files))); + } + } +} diff --git a/modules/blockcategories/controllers/admin/index.php b/modules/blockcategories/controllers/admin/index.php new file mode 100644 index 000000000..3f6561f72 --- /dev/null +++ b/modules/blockcategories/controllers/admin/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; \ No newline at end of file diff --git a/modules/blockcategories/controllers/index.php b/modules/blockcategories/controllers/index.php new file mode 100644 index 000000000..3f6561f72 --- /dev/null +++ b/modules/blockcategories/controllers/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; \ No newline at end of file diff --git a/modules/blockcategories/upgrade/install-2.1.php b/modules/blockcategories/upgrade/install-2.1.php index d5caac5cf..ace16ef68 100644 --- a/modules/blockcategories/upgrade/install-2.1.php +++ b/modules/blockcategories/upgrade/install-2.1.php @@ -5,6 +5,5 @@ if (!defined('_PS_VERSION_')) function upgrade_module_2_1($object) { - return ($object->registerHook('displayBackOfficeCategory') && $object->registerHook('actionBackOfficeCategory') - && $object->registerHook('actionBackOfficeCategoryRemoveThumbnail')); + return $object->registerHook('displayBackOfficeCategory'); } diff --git a/themes/default-bootstrap/product-list.tpl b/themes/default-bootstrap/product-list.tpl index 415bf80dd..2b514b6ea 100644 --- a/themes/default-bootstrap/product-list.tpl +++ b/themes/default-bootstrap/product-list.tpl @@ -22,13 +22,8 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} - {if isset($products)} - {*define numbers of product per line in other page for desktop*} - {if $page_name !='index' && $page_name !='product'} {assign var='nbItemsPerLine' value=3} {assign var='nbItemsPerLineTablet' value=2} @@ -122,9 +117,7 @@ {/if}
- + {hook h='displayProductListFunctionalButtons' product=$product} {if isset($comparator_max_item) && $comparator_max_item}