diff --git a/modules/addsharethis/addsharethis.php b/modules/addsharethis/addsharethis.php index cd0637d70..825d3e1c9 100644 --- a/modules/addsharethis/addsharethis.php +++ b/modules/addsharethis/addsharethis.php @@ -1,10 +1,35 @@ +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +if (!defined('_PS_VERSION_')) exit; -} + class AddShareThis extends Module { - function __construct() + public function __construct() { $this->name = 'addsharethis'; $this->author = 'Custom'; @@ -14,49 +39,45 @@ class AddShareThis extends Module parent::__construct(); $this->displayName = $this->l('Add Sharethis'); $this->description = $this->l('Display social count button on the home page'); -} + } -public function install() + public function install() { - Configuration::updateValue('CONF_ROW', 'ea22d519-9f98-4018-99a9-5b5f1b100fa8'); - Configuration::updateValue('ADDTHISSHARE_TWITTER',1); - Configuration::updateValue('ADDTHISSHARE_GOOGLE',1); - Configuration::updateValue('ADDTHISSHARE_PINTEREST',1); - Configuration::updateValue('ADDTHISSHARE_FACEBOOK',1); - if (!parent::install() OR - - !$this->registerHook('Extraright') OR - !$this->registerHook('header')) - return false; - return true; -} + return ( + parent::install() && + $this->registerHook('Extraright') && + $this->registerHook('header') && + Configuration::updateValue('CONF_ROW', 'ea22d519-9f98-4018-99a9-5b5f1b100fa8') && + Configuration::updateValue('ADDTHISSHARE_TWITTER', 1) && + Configuration::updateValue('ADDTHISSHARE_GOOGLE', 1) && + Configuration::updateValue('ADDTHISSHARE_PINTEREST', 1) && + Configuration::updateValue('ADDTHISSHARE_FACEBOOK', 1) + ); + } -public function uninstall() - { - if (!parent::uninstall() OR - !Configuration::deleteByName('CONF_ROW') OR - !Configuration::deleteByName('ADDTHISSHARE_TWITTER') OR - !Configuration::deleteByName('ADDTHISSHARE_GOOGLE') OR - !Configuration::deleteByName('ADDTHISSHARE_PINTEREST') OR - !Configuration::deleteByName('ADDTHISSHARE_FACEBOOK') OR - !$this->unregisterHook('Extraright') OR - !$this->unregisterHook('header')) - return false; - else return true; -} - -public function getContent() - { + public function uninstall() + { + return ( + parent::uninstall() && + Configuration::deleteByName('CONF_ROW') && + Configuration::deleteByName('ADDTHISSHARE_TWITTER') && + Configuration::deleteByName('ADDTHISSHARE_GOOGLE') && + Configuration::deleteByName('ADDTHISSHARE_PINTEREST') && + Configuration::deleteByName('ADDTHISSHARE_FACEBOOK') && + $this->unregisterHook('Extraright') && + $this->unregisterHook('header') + ); + } + public function getContent() + { $this->_html .= '

'.$this->displayName.'

'; - if (isset($_POST['submitCog'])) $this->updateCog(); - if (Tools::isSubmit('submitCog')) { - $conf_row = Tools::getValue('conf_row'); - Configuration::updateValue('CONF_ROW', $conf_row); - - } + $this->updateCog(); + Configuration::updateValue('CONF_ROW', Tools::getValue('conf_row')); + } + $this->_html .= '
'.$this->l('Configuration').' @@ -66,23 +87,23 @@ public function getContent()


- +


- - + +
- - + +
- - + +
- - + +


@@ -93,96 +114,93 @@ public function getContent() return $this->_html; } -public function updateCog() + public function updateCog() { - Configuration::updateValue('ADDTHISSHARE_TWITTER', (isset($_POST['Twitter']) ? 1 : 0)); - Configuration::updateValue('ADDTHISSHARE_GOOGLE', (isset($_POST['Google']) ? 1 : 0)); - Configuration::updateValue('ADDTHISSHARE_PINTEREST', (isset($_POST['Pinterest']) ? 1 : 0)); - Configuration::updateValue('ADDTHISSHARE_FACEBOOK', (isset($_POST['Facebook']) ? 1 : 0)); - + Configuration::updateValue('ADDTHISSHARE_TWITTER', (int)Tools::getValue('Twitter')); + Configuration::updateValue('ADDTHISSHARE_GOOGLE', (int)Tools::getValue('Google')); + Configuration::updateValue('ADDTHISSHARE_PINTEREST', (int)Tools::getValue('Pinterest')); + Configuration::updateValue('ADDTHISSHARE_FACEBOOK', (int)Tools::getValue('Facebook')); } - -function hookDisplayHeader($params) + public function hookDisplayHeader($params) { - global $smarty, $cookie; - global $link; - $product = new Product((int)Tools::getValue('id_product'), false, (int)$cookie->id_lang); - $productLink = $link->getProductLink($product); - $images = $product->getImages((int)$cookie->id_lang); + $id_lang = (int)$this->context->language->id; + $product = new Product((int)Tools::getValue('id_product'), false, $id_lang); + $productLink = $this->context->link->getProductLink($product); + $images = $product->getImages((int)$id_lang); + foreach ($images AS $k => $image) if ($image['cover']) { $cover['id_image'] = (int)$product->id.'-'.(int)$image['id_image']; $cover['legend'] = $image['legend']; + break; } + if (!isset($cover)) - $cover = array('id_image' => Language::getIsoById((int)$cookie->id_lang).'-default', 'legend' => 'No picture'); - $this->context->smarty->assign(array( + $cover = array('id_image' => Language::getIsoById((int)$id_lang).'-default', 'legend' => 'No picture'); + + $this->context->smarty->assign(array( 'cover' => $cover, 'product' => $product, 'productLink' => $productLink, 'this_path' => $this->_path - )); + ) + ); + return $this->display(__FILE__, 'addsharethis_header.tpl'); } - -public function hookExtraRight($params) + + public function hookExtraRight($params) { - global $smarty, $cookie, $link; - - $conf_row = Configuration::get('CONF_ROW'); - $this->context->smarty->assign(array( - 'conf_row' => $conf_row, - )); - - if (Configuration::get('ADDTHISSHARE_TWITTER') == 1) + if (Configuration::get('ADDTHISSHARE_TWITTER')) $data['twitter'] = ''; - if (Configuration::get('ADDTHISSHARE_GOOGLE') == 1) - { + + if (Configuration::get('ADDTHISSHARE_GOOGLE')) $data['google'] = ''; - } - if (Configuration::get('ADDTHISSHARE_PINTEREST') == 1) + + if (Configuration::get('ADDTHISSHARE_PINTEREST')) $data['pinterest'] = ''; - if (Configuration::get('ADDTHISSHARE_FACEBOOK') == 1) + if (Configuration::get('ADDTHISSHARE_FACEBOOK')) $data['facebook'] = ''; - - $smarty->assign('addsharethis_data', $data); - - + $this->context->smarty->assign(array( + 'addsharethis_data' => $data, + 'conf_row' => Configuration::get('CONF_ROW') + ) + ); + return $this->display(__FILE__, 'addsharethis.tpl'); - } + } - function hookLeftColumn($params) + public function hookLeftColumn($params) { - return $this->hookExtraRight($params); + return $this->hookExtraRight($params); } - function hookFooter($params) + public function hookFooter($params) { - return $this->hookExtraRight($params); + return $this->hookExtraRight($params); } - function hookHome($params) + public function hookHome($params) { - return $this->hookExtraRight($params); + return $this->hookExtraRight($params); } - function hookExtraleft($params) + public function hookExtraleft($params) { - return $this->hookExtraRight($params); + return $this->hookExtraRight($params); } - function hookProductActions($params) + + public function hookProductActions($params) { - return $this->hookExtraRight($params); + return $this->hookExtraRight($params); } - function hookProductFooter($params) + public function hookProductFooter($params) { - return $this->hookExtraRight($params); + return $this->hookExtraRight($params); } - -} -?> \ No newline at end of file +} \ No newline at end of file