name = 'blocklinkmulti1'; $this->tab = 'front_office_features'; $this->version = '1.4'; parent::__construct(); $this->displayName = $this->l('Link multi block #1'); $this->description = $this->l('Adds a block with additional links (to use in multiple blocks)'); $this->confirmUninstall = $this->l('Are you sure you want to delete all your links ?'); } public function install() { if (parent::install() == false OR $this->registerHook('footer') == false) return false; $query = 'CREATE TABLE '._DB_PREFIX_.'blocklinkmulti1 (`id_link` int(2) NOT NULL AUTO_INCREMENT, `url` varchar(255) NOT NULL, new_window TINYINT(1) NOT NULL, PRIMARY KEY(`id_link`)) ENGINE=MyISAM default CHARSET=utf8'; if (!Db::getInstance()->Execute($query)) return false; $query = 'CREATE TABLE '._DB_PREFIX_.'blocklinkmulti1_lang (`id_link` int(2) NOT NULL, `id_lang` int(2) NOT NULL, `text` varchar(64) NOT NULL, PRIMARY KEY(`id_link`, `id_lang`)) ENGINE=MyISAM default CHARSET=utf8'; if (!Db::getInstance()->Execute($query)) return false; return (Configuration::updateValue('PS_BLOCKLINKMULTI1_TITLE', array('1' => 'Block link', '2' => 'Bloc lien')) AND Configuration::updateValue('PS_BLOCKLINKMULTI1_TITLE', '')); } public function uninstall() { if (parent::uninstall() == false) return false; if (!Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'blocklinkmulti1')) return false; if (!Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'blocklinkmulti1_lang')) return false; return (Configuration::deleteByName('PS_BLOCKLINKMULTI1_TITLE') AND Configuration::deleteByName('PS_BLOCKLINKMULTI1_URL')); } public function hookLeftColumn($params) { global $cookie, $smarty; Tools::enableCache(); if(!$this->isCached('blocklinkmulti1_'.$cookie->id_lang.'.tpl')) { $links = $this->getLinks(); $smarty->assign(array( 'blocklinkmulti1_links' => $links, 'title' => Configuration::get('PS_BLOCKLINKMULTI1_TITLE', $cookie->id_lang), 'url' => Configuration::get('PS_BLOCKLINKMULTI1_URL'), 'lang' => 'text_'.$cookie->id_lang, 'url_link' => 'url_'.$cookie->id_lang )); if (!$links) return false; } $display = $this->display(__FILE__, 'blocklinkmulti1_'.$cookie->id_lang.'.tpl'); Tools::restoreCacheSettings(); return $display; } public function hookRightColumn($params) { return $this->hookLeftColumn($params); } public function hookFooter($params) { return $this->hookLeftColumn($params); } public function getLinks($admin = false) { $result = array(); /* Get id and url */ if (!$links = Db::getInstance()->ExecuteS('SELECT `id_link`, `new_window` FROM '._DB_PREFIX_.'blocklinkmulti1'.(intval(Configuration::get('PS_BLOCKLINKMULTI1_ORDERWAY')) == 1 ? ' ORDER BY `id_link` DESC' : ' ORDER BY `id_link` ASC'))) return false; $i = 0; foreach ($links AS $link) { $result[$i]['id'] = $link['id_link']; $result[$i]['newWindow'] = $link['new_window']; /* Get multilingual text */ if (!$texts = Db::getInstance()->ExecuteS('SELECT `id_lang`, `text`, `url` FROM '._DB_PREFIX_.'blocklinkmulti1_lang WHERE `id_link`='.intval($link['id_link']))) return false; foreach ($texts AS $text) { $result[$i]['text_'.$text['id_lang']] = $text['text']; $result[$i]['url_'.$text['id_lang']] = $text['url']; } // $result[$i]['url'] = ($link['url'] == ''? '': ((!$admin && substr($link['url'], 0, 4) != 'http') ? substr(__PS_BASE_URI__, 0, -1).$link['url'] : $link['url'])); $i++; } return $result; } public function addLink() { /* Url registration */ if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1 VALUES (\'\', \''.pSQL(isset($_POST['url']) && !empty($_POST['url'])? $_POST['url']: '').'\', '.((isset($_POST['newWindow']) AND $_POST['newWindow']) == 'on' ? 1 : 0).')') OR !$lastId = mysql_insert_id()) return false; /* Multilingual text */ $languages = Language::getLanguages(); $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); if (!$languages) return false; foreach ($languages AS $language) if (!empty($_POST['text_'.$language['id_lang']])) { if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1_lang VALUES ('.intval($lastId).', '.intval($language['id_lang']).', \''.pSQL($_POST['text_'.$language['id_lang']]).'\')')) return false; } else if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'blocklinkmulti1_lang VALUES ('.intval($lastId).', '.intval($language['id_lang']).', \''.pSQL($_POST['text_'.$defaultLanguage]).'\')')) return false; return true; } public function updateLink() { /* Multilingual text */ $languages = Language::getLanguages(FALSE); $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); if (!$languages) return false; foreach ($languages AS $language) if (!empty($_POST['text_'.$language['id_lang']]) && !empty($_POST['url_'.$language['id_lang']])) { if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'blocklinkmulti1_lang SET `text` = \''.pSQL($_POST['text_'.$language['id_lang']]).'\' , `url` = \''.pSQL($_POST['url_'.$language['id_lang']]).'\' WHERE `id_link`='.intval($_POST['id']).' AND `id_lang`='.$language['id_lang'] )) return false; } else if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'blocklinkmulti1_lang SET `text`=\''.pSQL($_POST['text_'.$defaultLanguage]).'\' WHERE `id_link`='.intval($_POST['id']).' AND `id_lang`='.$language['id_lang'])) return false; return true; } public function deleteLink() { return Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'blocklinkmulti1_lang WHERE `id_link`='.intval($_GET['id'])); return Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'blocklinkmulti1 WHERE `id_link`='.intval($_GET['id'])); } public function updateTitle() { $languages = Language::getLanguages(FALSE); $result = array(); foreach ($languages AS $language) $result[$language['id_lang']] = $_POST['title_'.$language['id_lang']]; if (!Configuration::updateValue('PS_BLOCKLINKMULTI1_TITLE', $result)) return false; return Configuration::updateValue('PS_BLOCKLINKMULTI1_URL', $_POST['title_url']); } public function getContent() { $this->_html = '
'.$this->l('ID').' | '.$this->l('Text').' | '.$this->l('URL').' | '.$this->l('Actions').' |
---|---|---|---|
'.$this->l('There are no links yet').' | |||
'.$link['id'].' | '.$link['text_'.$cookie->id_lang].' | '.$link['url_'.$cookie->id_lang].' |