[-] MO : Watermark - Bug Fixed #PSCFV-2770 - Watermark is not working

This commit is contained in:
fBrignoli
2012-07-25 09:30:56 +00:00
parent 93d7b7176d
commit f93f913cfb
2 changed files with 17 additions and 10 deletions
+5 -3
View File
@@ -524,7 +524,7 @@ class AdminImagesControllerCore extends AdminController
SELECT m.`name` FROM `'._DB_PREFIX_.'module` m SELECT m.`name` FROM `'._DB_PREFIX_.'module` m
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \'watermark\' AND m.`active` = 1'); WHERE h.`name` = \'actionWatermark\' AND m.`active` = 1');
if ($result && count($result)) if ($result && count($result))
{ {
@@ -535,8 +535,10 @@ 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']) && is_callable(array($moduleInstance, 'hookwatermark'))) $moduleInstance = Module::getInstanceByName($module['name']);
call_user_func(array($moduleInstance, 'hookwatermark'), array('id_image' => $imageObj->id, 'id_product' => $imageObj->id_product)); if ($moduleInstance && is_callable(array($moduleInstance, 'hookActionWatermark')))
call_user_func(array($moduleInstance, 'hookActionWatermark'), 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';
} }
+11 -6
View File
@@ -44,7 +44,7 @@ class Watermark extends Module
{ {
$this->name = 'watermark'; $this->name = 'watermark';
$this->tab = 'administration'; $this->tab = 'administration';
$this->version = '0.2'; $this->version = '0.3';
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
parent::__construct(); parent::__construct();
@@ -213,7 +213,7 @@ class Watermark extends Module
{ {
$this->_html = '<h2>'.$this->displayName.'</h2>'; $this->_html = '<h2>'.$this->displayName.'</h2>';
if (!empty($_POST)) if (Tools::isSubmit('btnSubmit'))
{ {
$this->_postValidation(); $this->_postValidation();
if (!count($this->_postErrors)) if (!count($this->_postErrors))
@@ -230,14 +230,19 @@ class Watermark extends Module
return $this->_html; return $this->_html;
} }
/* we assume here only jpg files */ // Retrocompatibility
public function hookwatermark($params) public function hookwatermark($params)
{
$this->hookActionWatermark($params);
}
public function hookActionWatermark($params)
{ {
$image = new Image($params['id_image']); $image = new Image($params['id_image']);
$image->id_product = $params['id_product']; $image->id_product = $params['id_product'];
$file = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-watermark.jpg'; $file = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-watermark.jpg';
$str_shop = '-'.(int)$this->context->shop->id; $str_shop = '-'.(int)$this->context->shop->id;
if (Shop::getContext() != Shop::CONTEXT_SHOP || !Tools::file_exists_cache(dirname(__FILE__).'/watermark'.$str_shop.'.gif')) if (Shop::getContext() != Shop::CONTEXT_SHOP || !Tools::file_exists_cache(dirname(__FILE__).'/watermark'.$str_shop.'.gif'))
$str_shop = ''; $str_shop = '';
@@ -247,8 +252,8 @@ class Watermark extends Module
//go through file formats defined for watermark and resize them //go through file formats defined for watermark and resize them
foreach ($this->imageTypes as $imageType) foreach ($this->imageTypes as $imageType)
{ {
$newFile = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg'; $newFile = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg';
if (!ImageManager::resize($file, $newFile, (int)$imageType['width'], (int)$imageType['height'])) if (!ImageManager::resize($file, $newFile, (int)$imageType['width'], (int)$imageType['height']))
$return = false; $return = false;
} }
return $return; return $return;