From 6ec267956388e7925f71d4a392da3eeb12e011b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Thu, 6 Aug 2015 13:10:46 -0300 Subject: [PATCH] Ability to open a link as a popup window The window dimensions are hardcode at the moment, but at least it gives webmaster a place to modify these settings while getting the basic working feature already implemented. --- blocktopmenu.php | 51 ++++++++++++++++++++++++++++++++++++----- menutoplinks.class.php | 14 +++++++---- upgrade/install-2.3.php | 12 ++++++++++ 3 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 upgrade/install-2.3.php diff --git a/blocktopmenu.php b/blocktopmenu.php index a7015a3..8b0fc46 100644 --- a/blocktopmenu.php +++ b/blocktopmenu.php @@ -52,7 +52,7 @@ public function __construct() { $this->name = 'blocktopmenu'; $this->tab = 'front_office_features'; - $this->version = '2.2.2'; + $this->version = '2.3'; $this->author = 'PrestaShop'; $this->bootstrap = true; @@ -106,6 +106,7 @@ public function installDb() `id_linksmenutop` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_shop` INT(11) UNSIGNED NOT NULL, `new_window` TINYINT( 1 ) NOT NULL, + `new_popup` TINYINT( 1 ) NOT NULL, INDEX (`id_shop`) ) ENGINE = '._MYSQL_ENGINE_.' CHARACTER SET utf8 COLLATE utf8_general_ci;') && Db::getInstance()->execute(' @@ -226,7 +227,7 @@ public function getContent() $shops = Shop::getContextListShopID(); foreach ($shops as $shop_id) { - $added = MenuTopLinks::add($links_label, $labels, Tools::getValue('new_window', 0), (int)$shop_id); + $added = MenuTopLinks::add($links_label, $labels, Tools::getValue('new_window', 0), Tools::getValue('new_popup', 0), (int)$shop_id); if (!$added) { $shop = new Shop($shop_id); @@ -272,13 +273,14 @@ public function getContent() $link = array(); $label = array(); $new_window = (int)Tools::getValue('new_window', 0); + $new_popup = (int)Tools::getValue('new_popup', 0); foreach (Language::getLanguages(false) as $lang) { $link[$lang['id_lang']] = Tools::getValue('link_'.(int)$lang['id_lang']); $label[$lang['id_lang']] = Tools::getValue('label_'.(int)$lang['id_lang']); } - MenuTopLinks::update($link, $label, $new_window, (int)$id_shop, (int)$id_linksmenutop, (int)$id_linksmenutop); + MenuTopLinks::update($link, $label, $new_window, $new_popup, (int)$id_shop, (int)$id_linksmenutop, (int)$id_linksmenutop); $this->_html .= $this->displayConfirmation($this->l('The link has been edited.')); } $update_cache = true; @@ -565,7 +567,17 @@ protected function makeMenu() $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); } - $this->_menu .= '
  • '.Tools::safeOutput($link[0]['label']).'
  • '.PHP_EOL; + $this->_menu .= '
  • _menu .= ' onclick="return !window.open(this.href, \'prestashop-popup-blocktopmenu\', \'menubar=no, status=no, scrollbars=no, menubar=no, status=no, width=400, height=300\');"'; + } else { + $this->_menu .= ' onclick="return !window.open(this.href);"'; + } + } + $this->_menu .= ' title="'.Tools::safeOutput($link[0]['label']).'">'.Tools::safeOutput($link[0]['label']).'
  • '.PHP_EOL; + } break; } @@ -915,8 +927,8 @@ public function hookActionShopDataDuplication($params) foreach ($linksmenutop as $id => $link) { Db::getInstance()->execute(' - INSERT IGNORE INTO '._DB_PREFIX_.'linksmenutop (id_linksmenutop, id_shop, new_window) - VALUES (null, '.(int)$params['new_id_shop'].', '.(int)$link['new_window'].')'); + INSERT IGNORE INTO '._DB_PREFIX_.'linksmenutop (id_linksmenutop, id_shop, new_window, new_popup) + VALUES (null, '.(int)$params['new_id_shop'].', '.(int)$link['new_window'].', '.(int)$link['new_popup'].')'); $linksmenutop[$id]['new_id_linksmenutop'] = Db::getInstance()->Insert_ID(); } @@ -1076,6 +1088,24 @@ public function renderAddForm() 'label' => $this->l('Disabled') ) ), + ), + array( + 'type' => 'switch', + 'label' => $this->l('New popup'), + 'name' => 'new_popup', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), ) ), 'submit' => array( @@ -1275,6 +1305,7 @@ public function getAddLinkFieldsValues() $links_label_edit = ''; $labels_edit = ''; $new_window_edit = ''; + $new_popup_edit = ''; if (Tools::isSubmit('updatelinksmenutop')) { $link = MenuTopLinks::getLinkLang(Tools::getValue('id_linksmenutop'), (int)Shop::getContextShopID()); @@ -1286,10 +1317,12 @@ public function getAddLinkFieldsValues() $links_label_edit = $link['link']; $labels_edit = $link['label']; $new_window_edit = $link['new_window']; + $new_popup_edit = $link['new_popup']; } $fields_values = array( 'new_window' => Tools::getValue('new_window', $new_window_edit), + 'new_popup' => Tools::getValue('new_popup', $new_popup_edit), 'id_linksmenutop' => Tools::getValue('id_linksmenutop'), ); @@ -1341,6 +1374,12 @@ public function renderList() 'type' => 'bool', 'align' => 'center', 'active' => 'status', + ), + 'new_popup' => array( + 'title' => $this->l('New popup'), + 'type' => 'bool', + 'align' => 'center', + 'active' => 'status', ) ); diff --git a/menutoplinks.class.php b/menutoplinks.class.php index b483afd..7882790 100644 --- a/menutoplinks.class.php +++ b/menutoplinks.class.php @@ -28,7 +28,7 @@ class MenuTopLinks { public static function gets($id_lang, $id_linksmenutop = null, $id_shop) { - $sql = 'SELECT l.id_linksmenutop, l.new_window, s.name, ll.link, ll.label + $sql = 'SELECT l.id_linksmenutop, l.new_window, l.new_popup, s.name, ll.link, ll.label FROM '._DB_PREFIX_.'linksmenutop l LEFT JOIN '._DB_PREFIX_.'linksmenutop_lang ll ON (l.id_linksmenutop = ll.id_linksmenutop AND ll.id_lang = '.(int)$id_lang.' AND ll.id_shop='.(int)$id_shop.') LEFT JOIN '._DB_PREFIX_.'shop s ON l.id_shop = s.id_shop @@ -46,7 +46,7 @@ public static function get($id_linksmenutop, $id_lang, $id_shop) public static function getLinkLang($id_linksmenutop, $id_shop) { $ret = Db::getInstance()->executeS(' - SELECT l.id_linksmenutop, l.new_window, ll.link, ll.label, ll.id_lang + SELECT l.id_linksmenutop, l.new_window, l.new_popup, ll.link, ll.label, ll.id_lang FROM '._DB_PREFIX_.'linksmenutop l LEFT JOIN '._DB_PREFIX_.'linksmenutop_lang ll ON (l.id_linksmenutop = ll.id_linksmenutop AND ll.id_shop='.(int)$id_shop.') WHERE 1 @@ -57,17 +57,19 @@ public static function getLinkLang($id_linksmenutop, $id_shop) $link = array(); $label = array(); $new_window = false; + $new_popup = false; foreach ($ret as $line) { $link[$line['id_lang']] = Tools::safeOutput($line['link']); $label[$line['id_lang']] = Tools::safeOutput($line['label']); $new_window = (bool)$line['new_window']; + $new_popup = (bool)$line['new_popup']; } - return array('link' => $link, 'label' => $label, 'new_window' => $new_window); + return array('link' => $link, 'label' => $label, 'new_window' => $new_window, 'new_popup' => $new_popup); } - public static function add($link, $label, $newWindow = 0, $id_shop) + public static function add($link, $label, $newWindow = 0, $newPopup = 0, $id_shop) { if (!is_array($label)) { return false; @@ -80,6 +82,7 @@ public static function add($link, $label, $newWindow = 0, $id_shop) 'linksmenutop', array( 'new_window'=>(int)$newWindow, + 'new_popup'=>(int)$newPopup, 'id_shop' => (int)$id_shop ) ); @@ -103,7 +106,7 @@ public static function add($link, $label, $newWindow = 0, $id_shop) return $result; } - public static function update($link, $labels, $newWindow = 0, $id_shop, $id_link) + public static function update($link, $labels, $newWindow = 0, $newPopup = 0, $id_shop, $id_link) { if (!is_array($labels)) { return false; @@ -116,6 +119,7 @@ public static function update($link, $labels, $newWindow = 0, $id_shop, $id_link 'linksmenutop', array( 'new_window'=>(int)$newWindow, + 'new_popup'=>(int)$newPopup, 'id_shop' => (int)$id_shop ), 'id_linksmenutop = '.(int)$id_link diff --git a/upgrade/install-2.3.php b/upgrade/install-2.3.php new file mode 100644 index 0000000..a40ae1d --- /dev/null +++ b/upgrade/install-2.3.php @@ -0,0 +1,12 @@ +ExecuteS('SHOW COLUMNS FROM `'._DB_PREFIX_.'linksmenutop` LIKE \'new_popup\'') == false) + Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'linksmenutop` ADD `new_popup` TINYINT( 1 ) NOT NULL DEFAULT 0 AFTER `new_window`'); + return true; +}