* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7541 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; require (_PS_MODULE_DIR_.'trustedshops/lib/AbsTrustedShops.php'); require (_PS_MODULE_DIR_.'trustedshops/lib/TrustedShopsRating.php'); require (_PS_MODULE_DIR_.'trustedshops/lib/TSBuyerProtection.php'); class TrustedShops extends Module { /** * Saved each Object needed list of AbsTrustedShops extended objects * @var array */ private static $objects_list = array(); private $errors = array(); private $warnings = array(); public $limited_countries = array(); private $confirmations = array(); public function __construct() { global $smarty; $this->name = 'trustedshops'; $this->tab = 'payment_security'; $this->version = 1.3; parent::__construct(); if (empty(self::$objects_list)) { TSBuyerProtection::setTranslationObject($this); $obj_ts_rating = new TrustedShopsRating(); $obj_ts_buyerprotection = new TSBuyerProtection(); $obj_ts_buyerprotection->_setEnvApi(TSBuyerProtection::ENV_PROD); self::$objects_list = array($obj_ts_rating, $obj_ts_buyerprotection); self::$objects_list[0]->setModuleName($this->name); self::$objects_list[0]->setSmarty($smarty); } if (!extension_loaded('soap')) $this->warnings[] = $this->l('This module requires the SOAP PHP extension to function properly.'); foreach (self::$objects_list as $object) { $this->limited_countries = array_merge($this->limited_countries, $object->limited_countries); if (!empty($object->warnings)) $this->warnings = array_merge($this->warnings, $object->warnings); } if (!empty($this->warnings)) $this->warning = implode(',
', $this->warnings).'.'; $this->displayName = $this->l('Trusted Shops trust solutions'); $this->description = $this->l('Build confidence in your online shop with the Trusted Shops quality seal, buyer protection and customer rating.'); $this->confirmUninstall = $this->l('Are you sure you want to delete all your settings?'); } public function install() { $return = true; foreach (self::$objects_list as $object) { $return = $object->install(); if (!$return) break; } $return = ($return) ? (parent::install() AND $this->registerHook('orderConfirmation') AND $this->registerHook('newOrder') AND $this->registerHook('rightColumn') AND $this->registerHook('paymentTop') AND $this->registerHook('orderConfirmation')) : $return; $id_hook = Hook::get('payment'); $this->updatePosition($id_hook, 0, 1); return $return; } public function uninstall() { $return = true; foreach (self::$objects_list as $object) { $return = $object->uninstall(); if (!$return) break; } $return = ($return) ? parent::uninstall() : $return; return $return; } public function getContent() { $out = '

'.$this->displayName.'

'; $tabs = array(); foreach (self::$objects_list as $key=>$object) { $object->id_tab = $key; $tabs['title'][] = $object->tab_name; $tabs['content'][] = $object->getContent(); } // Display Title Tabs $out .= ''; // Display content Tabs $out .= '
'; foreach($tabs['content'] as $key=>$content) $out .= ''; $out .= '
'.$this->displayCSSJSTab(); // Check If each object (display as Tab) contains errors message of $this->checkObjectsErrorsOrConfirmations(); return ( !empty($this->errors) ? $this->displayErrors() : $this->displayConfirmations() ).$out; } private function displayCSSJSTab() { $id_tab = isset($_GET['id_tab']) ? (int)$_GET['id_tab'] : 0; return ' '; } /** * Check If each object (display as Tab) contains errors message of * * @return void */ private function checkObjectsErrorsOrConfirmations() { foreach (self::$objects_list as $object) { if (!empty($object->errors)) $this->errors = array_merge($this->errors, $object->errors); if (!empty($object->confirmations)) $this->confirmations = array_merge($this->confirmations, $object->confirmations); } } private function displayConfirmations() { $html = ''; if (!empty($this->confirmations)) foreach ($this->confirmations as $confirmations) $html .= $this->displayConfirmation($confirmations); return $html; } private function displayErrors() { $html = ''; if (!empty($this->errors)) foreach ($this->errors as $error) $html .= $this->displayError($error); return $html; } public function hookOrderConfirmation($params) { return $this->dynamicHook($params, __FUNCTION__); } public function hookNewOrder($params) { return $this->dynamicHook($params, __FUNCTION__); } public function hookRightColumn($params) { return $this->dynamicHook($params, __FUNCTION__); } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } public function hookPaymentTop($params) { return $this->dynamicHook($params, __FUNCTION__); } private function dynamicHook($params, $hook_name) { if (!$this->active) return ''; $return = ''; foreach (self::$objects_list as $object) if (method_exists($object, $hook_name)) $return .= $object->{$hook_name}($params); return $return; } }