diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 5c7197243..dcbac0524 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/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 3918d00c2..717dccf54 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -44,7 +44,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') || @@ -55,8 +66,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; @@ -65,6 +74,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')) @@ -135,93 +152,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'); }