From d9fa602cc389c86ab75f189fc6a8a1fae359cf07 Mon Sep 17 00:00:00 2001 From: fBrignoli Date: Fri, 5 Aug 2011 14:49:18 +0000 Subject: [PATCH] [~] Hook::get replaced by Hook::getIdByName --- classes/Hook.php | 83 ++++++---- modules/moneybookers/moneybookers.php | 51 +++--- modules/shopimporter/shopimporter.php | 79 +++++----- modules/themeinstallator/themeinstallator.php | 147 +++++++++--------- modules/treepodia/treepodia.php | 18 +-- modules/trustedshops/trustedshops.php | 2 +- 6 files changed, 202 insertions(+), 178 deletions(-) diff --git a/classes/Hook.php b/classes/Hook.php index 1a95d98a3..7838393fc 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -1,6 +1,6 @@ 32); protected $fieldsValidate = array('name' => 'isHookName'); - + protected $table = 'hook'; protected $identifier = 'id_hook'; - + static $preloadModulesFromHooks = null; - + public function getFields() { - parent::validateFields(); + parent::validateFields(); $fields['name'] = pSQL($this->name); return $fields; } - + /** * Return hook ID from name - * + * * @param string $hookName Hook name * @return integer Hook ID + * + * @deprecated since 1.5 */ static public function get($hookName) { + Tools::displayAsDeprecated(); if (!Validate::isHookName($hookName)) die(Tools::displayError()); - + $result = Db::getInstance()->getRow(' SELECT `id_hook`, `name` - FROM `'._DB_PREFIX_.'hook` + FROM `'._DB_PREFIX_.'hook` WHERE `name` = \''.pSQL($hookName).'\''); - + return ($result ? $result['id_hook'] : false); } - + + /** + * Return hook ID from name + * + * @param string $hook_name Hook name + * @return integer Hook ID + */ + public static function getIdByName($hook_name) + { + if (!Validate::isHookName($hook_name)) + die(Tools::displayError()); + + $result = Db::getInstance()->getRow(' + SELECT `id_hook`, `name` + FROM `'._DB_PREFIX_.'hook` + WHERE `name` = \''.pSQL($hook_name).'\''); + + return ($result ? $result['id_hook'] : false); + } + static public function getHooks($position = false) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' @@ -105,7 +127,7 @@ class HookCore extends ObjectModel ); } } - + static public function getModulesFromHook($hookID, $moduleID = null) { Hook::preloadModulesFromHooks(); @@ -115,7 +137,7 @@ class HookCore extends ObjectModel return (isset($list[$moduleID])) ? array($list[$moduleID]) : array(); return $list; } - + static public function newOrder($cart, $order, $customer, $currency, $orderStatus) { return Module::hookExec('newOrder', array( @@ -135,7 +157,7 @@ class HookCore extends ObjectModel $return = Module::hookExec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) AND $return; return $return; } - + static public function postUpdateOrderStatus($newOrderStatusId, $id_order) { $order = new Order((int)($id_order)); @@ -146,7 +168,7 @@ class HookCore extends ObjectModel /** * Called when quantity of a product is updated. - * + * * @param Product * @param Order */ @@ -154,37 +176,37 @@ class HookCore extends ObjectModel { return Module::hookExec('updateQuantity', array('product' => $product, 'order' => $order)); } - + static public function productFooter($product, $category) { return Module::hookExec('productFooter', array('product' => $product, 'category' => $category)); } - + static public function productOutOfStock($product) { return Module::hookExec('productOutOfStock', array('product' => $product)); } - + static public function addProduct($product) { return Module::hookExec('addProduct', array('product' => $product)); } - + static public function updateProduct($product) { return Module::hookExec('updateProduct', array('product' => $product)); } - + static public function deleteProduct($product) { return Module::hookExec('deleteProduct', array('product' => $product)); } - + static public function updateProductAttribute($id_product_attribute) { return Module::hookExec('updateProductAttribute', array('id_product_attribute' => $id_product_attribute)); } - + static public function orderConfirmation($id_order) { if (Validate::isUnsignedId($id_order)) @@ -192,20 +214,20 @@ class HookCore extends ObjectModel $params = array(); $order = new Order((int)$id_order); $currency = new Currency((int)$order->id_currency); - + if (Validate::isLoadedObject($order)) { $params['total_to_pay'] = $order->total_paid; $params['currency'] = $currency->sign; $params['objOrder'] = $order; $params['currencyObj'] = $currency; - + return Module::hookExec('orderConfirmation', $params); } } return false; } - + static public function paymentReturn($id_order, $id_module) { if (Validate::isUnsignedId($id_order) AND Validate::isUnsignedId($id_module)) @@ -213,14 +235,14 @@ class HookCore extends ObjectModel $params = array(); $order = new Order((int)($id_order)); $currency = new Currency((int)($order->id_currency)); - + if (Validate::isLoadedObject($order)) { $params['total_to_pay'] = $order->total_paid; $params['currency'] = $currency->sign; $params['objOrder'] = $order; $params['currencyObj'] = $currency; - + return Module::hookExec('paymentReturn', $params, (int)($id_module)); } } @@ -233,7 +255,7 @@ class HookCore extends ObjectModel return false; return Module::hookExec('PDFInvoice', array('pdf' => $pdf, 'id_order' => $id_order)); } - + static public function backBeforePayment($module) { $params['module'] = strval($module); @@ -241,7 +263,7 @@ class HookCore extends ObjectModel return false; return Module::hookExec('backBeforePayment', $params); } - + static public function updateCarrier($id_carrier, $carrier) { if (!Validate::isUnsignedId($id_carrier) OR !is_object($carrier)) @@ -250,4 +272,3 @@ class HookCore extends ObjectModel } } - diff --git a/modules/moneybookers/moneybookers.php b/modules/moneybookers/moneybookers.php index 62d8a5493..c910912af 100644 --- a/modules/moneybookers/moneybookers.php +++ b/modules/moneybookers/moneybookers.php @@ -1,6 +1,6 @@ registerHook('payment') OR + if (!parent::install() OR + !$this->registerHook('payment') OR !$this->registerHook('paymentReturn')) return false; Configuration::updateValue('MB_HIDE_LOGIN', 1); @@ -157,28 +157,28 @@ class MoneyBookers extends PaymentModule 'max_redirects' => 10, 'timeout' => $timeout, 'header' => array( - 'Accept-language: en', + 'Accept-language: en', 'Cookie: foo=bar'))); - + if (is_callable('curl_init') && ($ch = curl_init())) { curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); - + $content = curl_exec($ch); curl_close($ch); } else { - // Check availability of the context options + // Check availability of the context options if (!is_array($contextOptions) || !count($contextOptions)) $contextOptions = $defaultContextOptions; - + // Create a stream context $stream_context = stream_context_create($contextOptions); - + if (($fp = @fopen($url, $mode, false, $stream_context))) { $content = fgets($fp, 4096); @@ -187,7 +187,7 @@ class MoneyBookers extends PaymentModule else if (!($content = @file_get_contents($url, false, $stream_context))) if (($fp = @fsockopen($url, 80, $errnom, $errstr, $timeout))) { - preg_match('@^(?:http://)?([^/]+)@i', $url, $matches); + preg_match('@^(?:http://)?([^/]+)@i', $url, $matches); $host = $matches[1]; $out = "GET / HTTP/1.1\r\n"; $out .= "Host: ".$host."\r\n"; @@ -218,7 +218,7 @@ class MoneyBookers extends PaymentModule if (isset($_POST['mb_email_to_validate']) && !empty($_POST['mb_email_to_validate'])) { - try + try { $url = 'http://moneybookers.prestashop.com/email_check.php?email='.$_POST['mb_email_to_validate'].'&url=http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__; $content = $this->_fetchWebContent($url); @@ -237,7 +237,7 @@ class MoneyBookers extends PaymentModule } } catch(Exception $e) - { + { $errors[] = $this->l('Unable to contact activation server, please try again later.'); } } @@ -317,13 +317,13 @@ class MoneyBookers extends PaymentModule { foreach(array('leftColumn', 'rightColumn') as $hookName) if ($this->isRegisteredInHook($hookName)) - $this->unregisterHook(Hook::get($hookName)); + $this->unregisterHook(Hook::getIdByName($hookName)); if (Tools::getValue('logo_position') == self::LEFT_COLUMN) $this->registerHook('leftColumn'); else if (Tools::getValue('logo_position') == self::RIGHT_COLUMN) $this->registerHook('rightColumn'); } - + /* Display errors */ if (sizeof($errors)) { @@ -351,9 +351,9 @@ class MoneyBookers extends PaymentModule self::DISABLE => $this->l('Disable'), self::LEFT_COLUMN => $this->l('Left Column'), self::RIGHT_COLUMN => $this->l('Right Column')); - - $currentLogoBlockPosition = ($this->isRegisteredInHook('leftColumn')) ? self::LEFT_COLUMN : - (($this->isRegisteredInHook('rightColumn')) ? self::RIGHT_COLUMN : -1); + + $currentLogoBlockPosition = ($this->isRegisteredInHook('leftColumn')) ? self::LEFT_COLUMN : + (($this->isRegisteredInHook('rightColumn')) ? self::RIGHT_COLUMN : -1); /* Display settings form */ $output .= ' @@ -368,7 +368,7 @@ class MoneyBookers extends PaymentModule
'.$this->l('Settings').'
- '.$this->l('Select the logo position').' : + '.$this->l('Select the logo position').' :

'.$this->l('Change youpr logo position in the Front Office. Works with').' @@ -424,7 +424,7 @@ class MoneyBookers extends PaymentModule '.$this->l('For merchants over €100,000 fees can be negotiated.').' Contact: ecommerce@moneybookers.com
-'.$this->l('To view the last update of the detailed fees').' '.$this->l('Click here').' +'.$this->l('To view the last update of the detailed fees').' '.$this->l('Click here').'

** '.$this->l('Moneybookers eWallet').'
@@ -562,7 +562,7 @@ class MoneyBookers extends PaymentModule $imgPath = __PS_BASE_URI__.'modules/moneybookers/logo-skrill.png'; return '

'; } - + public function hookRightColumn($params) { return $this->_displayLogoBlock(self::RIGHT_COLUMN); @@ -597,7 +597,7 @@ class MoneyBookers extends PaymentModule { $localMethods = Configuration::get('MB_LOCAL_METHODS'); $interMethods = Configuration::get('MB_INTER_METHODS'); - + $this->context->smarty->assign(array( 'display_mode' => (int)(Configuration::get('MB_DISPLAY_MODE')), 'local' => $localMethods ? explode('|', $localMethods) : array(), @@ -662,11 +662,11 @@ class MoneyBookers extends PaymentModule case _PS_OS_OUTOFSTOCK_: $this->context->smarty->assign('status', 'ok'); break; - + case _PS_OS_BANKWIRE_: $this->context->smarty->assign('status', 'pending'); break; - + case _PS_OS_ERROR_: default: $this->context->smarty->assign('status', 'failed'); @@ -677,4 +677,3 @@ class MoneyBookers extends PaymentModule } } - diff --git a/modules/shopimporter/shopimporter.php b/modules/shopimporter/shopimporter.php index dd355e870..6cb35f153 100644 --- a/modules/shopimporter/shopimporter.php +++ b/modules/shopimporter/shopimporter.php @@ -268,7 +268,7 @@ class shopimporter extends ImportModule unset($exportModules[$key]); $html = ' - +