kotkotan Posted December 11, 2013 Share Posted December 11, 2013 (edited) Hello Have part of code of module (from here): <?php if (!defined('_PS_VERSION_')) exit; class wnfaq extends Module { protected $error = false; public function __construct() { $this->name = 'wnfaq'; $this->tab = 'other'; $this->version = '1.0'; $this->author = 'Dulco'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('wnFAQ'); $this->description = $this->l('Вопросы и ответы на вашем сайте.'); $this->confirmUninstall = $this->l('Вы уверены, что хотите удалить все ваши вопросы-ответы ?'); } public function install() { if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('header') || !Db::getInstance()->execute(' CREATE TABLE '._DB_PREFIX_.'wnfaq ( `id_wnfaq` int(2) NOT NULL AUTO_INCREMENT, `answer` varchar(2000) NOT NULL, `new_window` TINYINT(1) NOT NULL, PRIMARY KEY(`id_wnfaq`)) ENGINE='._MYSQL_ENGINE_.' default CHARSET=utf8') || !Db::getInstance()->execute(' CREATE TABLE '._DB_PREFIX_.'wnfaq_shop ( `id_wnfaq` int(2) NOT NULL AUTO_INCREMENT, `id_shop` int(2) NOT NULL, PRIMARY KEY(`id_wnfaq`, `id_shop`)) ENGINE='._MYSQL_ENGINE_.' default CHARSET=utf8') || !Db::getInstance()->execute(' CREATE TABLE '._DB_PREFIX_.'wnfaq_lang ( `id_wnfaq` int(2) NOT NULL, `id_lang` int(2) NOT NULL, `text` varchar(255) NOT NULL, PRIMARY KEY(`id_wnfaq`, `id_lang`)) ENGINE='._MYSQL_ENGINE_.' default CHARSET=utf8') ) return false; return true; } public function uninstall() { if (!parent::uninstall() || !Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.'wnfaq') || !Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.'wnfaq_lang') || !Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.'wnfaq_shop') || !Configuration::deleteByName('PS_wnfaq_answer')) return false; return true; } public function hookLeftColumn($params) { $links = $this->getLinks(); $this->context->smarty->assign(array( 'answers_dir' => $this->context->link->getModuleLink('wnfaq', 'answers'), 'wnfaq_links' => $links, 'answer' => Configuration::get('PS_wnfaq_answer'), 'lang' => 'text_'.$this->context->language->id )); if (!$links) return false; return $this->display(__FILE__, 'wnfaq.tpl'); } public function hookRightColumn($params) { return $this->hookLeftColumn($params); } public function hookHeader($params) { $this->context->controller->addCSS($this->_path.'wnfaq.css', 'all'); } public function getLinks() { $result = array(); // Get id and answer $sql = 'SELECT b.`id_wnfaq`, b.`answer`, b.`new_window` FROM `'._DB_PREFIX_.'wnfaq` b'; if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) $sql .= ' JOIN `'._DB_PREFIX_.'wnfaq_shop` bs ON b.`id_wnfaq` = bs.`id_wnfaq` AND bs.`id_shop` IN ('.implode(', ', Shop::getContextListShopID()).') '; $sql .= (int)Configuration::get('PS_wnfaq_ORDERWAY') == 999 ? ' ORDER BY `id_wnfaq` DESC' : ''; if (!$links = Db::getInstance()->executeS($sql)) return false; $i = 0; foreach ($links as $link) { $result[$i]['id'] = $link['id_wnfaq']; $result[$i]['answer'] = $link['answer']; $result[$i]['newWindow'] = $link['new_window']; // Get multilingual text if (!$texts = Db::getInstance()->executeS('SELECT `id_lang`, `text` FROM '._DB_PREFIX_.'wnfaq_lang WHERE `id_wnfaq`='.(int)$link['id_wnfaq'])) return false; foreach ($texts as $text) $result[$i]['text_'.$text['id_lang']] = $text['text']; $i++; } return $result; } public function addLink() { if (!($languages = Language::getLanguages())) return false; $id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT'); if ($id_link = Tools::getValue('id_link')) { if (!Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'wnfaq SET `answer` = \''.pSQL($_POST['answer']).'\', `new_window` = '.(isset($_POST['newWindow']) ? 1 : 0).' WHERE `id_wnfaq` = '.(int)$id_link)) return false; if (!Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'wnfaq_lang WHERE `id_wnfaq` = '.(int)$id_link)) return false; foreach ($languages as $language) if (!empty($_POST['text_'.$language['id_lang']])) { if (!Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'wnfaq_lang VALUES ('.(int)$id_link.', '.(int)($language['id_lang']).', \''.pSQL($_POST['text_'.$language['id_lang']]).'\')')) return false; } else if (!Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'wnfaq_lang VALUES ('.(int)$id_link.', '.$language['id_lang'].', \''.pSQL($_POST['text_'.$id_lang_default]).'\')')) return false; } else { if (!Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'wnfaq VALUES (NULL, \''.pSQL($_POST['answer']).'\', '.((isset($_POST['newWindow']) && $_POST['newWindow']) == 'on' ? 1 : 0).')') || !$id_link = Db::getInstance()->Insert_ID()) return false; foreach ($languages as $language) if (!empty($_POST['text_'.$language['id_lang']])) { if (!Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'wnfaq_lang VALUES ('.(int)$id_link.', '.(int)$language['id_lang'].', \''.pSQL($_POST['text_'.$language['id_lang']]).'\')')) return false; } else if (!Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'wnfaq_lang VALUES ('.(int)$id_link.', '.(int)($language['id_lang']).', \''.pSQL($_POST['text_'.$id_lang_default]).'\')')) return false; } Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'wnfaq_shop WHERE id_wnfaq='.(int)$id_link); if (!Shop::isFeatureActive()) { Db::getInstance()->insert('wnfaq_shop', array( 'id_wnfaq' => (int)$id_link, 'id_shop' => (int)Context::getContext()->shop->id, )); } else { $assos_shop = Tools::getValue('checkBoxShopAsso_wnfaq'); if (empty($assos_shop)) return false; foreach ($assos_shop as $id_shop => $row) Db::getInstance()->insert('wnfaq_shop', array( 'id_wnfaq' => (int)$id_link, 'id_shop' => (int)$id_shop, )); } return true; } public function deleteLink() { return (Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'wnfaq WHERE `id_wnfaq` = '.(int)$_GET['id']) && Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'wnfaq_shop WHERE `id_wnfaq` = '.(int)$_GET['id']) && Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'wnfaq_lang WHERE `id_wnfaq` = '.(int)$_GET['id'])); } public function getContent() { $this->_html = '<h2>'.$this->displayName.'</h2> <script type="text/javascript" src="'.$this->_path.'wnfaq.js"></script>'; // Add a link if (isset($_POST['submitLinkAdd'])) { if (empty($_POST['text_'.Configuration::get('PS_LANG_DEFAULT')]) || empty($_POST['answer'])) $this->_html .= $this->displayError($this->l('Вы должны заполнить все поля')); else if ($this->addLink()) $this->_html .= $this->displayConfirmation($this->l('Вопрос-ответ добавлен.')); else $this->_html .= $this->displayError($this->l('Ошибка создания вопроса-ответа.')); } // Delete a link elseif (Tools::getValue('delete_link') && isset($_GET['id'])) { if (!is_numeric($_GET['id']) || !$this->deleteLink()) $this->_html .= $this->displayError($this->l('Произошла ошибка во время удаления FAQ.')); else $this->_html .= $this->displayConfirmation($this->l('Ссылка была удалена.')); } $this->_displayForm(); $this->_list(); return $this->_html; } private function _displayForm() { $this->_html = ' <fieldset style="width: 300px;float:right;margin-left:15px;"> <legend><img src="../img/admin/information.png"/> '.$this->l('Информация').'</legend> <div > <p><a href="http://webnewbie.ru/"><img src="'.$this->_path.'logo.png" alt="Бесплатные модули и шаблоны для PrestaShop"/></a></p> <span><strong>Версия: </strong>'.$this->version.'</span><br> <span><strong>Автор:</strong> <a class="link" href="http://webnewbie.ru/modules/blogwp/wordpress/" target="_blank">'.$this->author.'</a><br> <span><strong>Ресурс:</strong> <a class="link" href="http://webnewbie.ru/" target="_blank">webnewbie.ru</a><br> <p><strong>Поблагодарить можно и так:</strong></p><iframe frameborder="0" allowtransparency="true" scrolling="no" src="https://money.yandex.ru/embed/small.xml?uid=41001507750418&button-text=06&button-size=s&button-color=orange&targets=%D0%9F%D0%BE%D0%B1%D0%BB%D0%B0%D0%B3%D0%BE%D0%B4%D0%B0%D1%80%D0%B8%D1%82%D1%8C+%D0%BC%D0%BE%D0%B6%D0%BD%D0%BE+%D0%B8+%D1%82%D0%B0%D0%BA&default-sum=50&mail=on" width="auto" height="31"></iframe> </div><br /> </fieldset>'; /* Language */ $id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $divLangName = 'text¤title'; /* Title */ if (!Tools::isSubmit('submitLinkAdd')) { if ($id_link = (int)Tools::getValue('id_link')) { $res = Db::getInstance()->executeS(' SELECT * FROM '._DB_PREFIX_.'wnfaq b LEFT JOIN '._DB_PREFIX_.'wnfaq_lang bl ON (b.id_wnfaq = bl.id_wnfaq) WHERE b.id_wnfaq='.(int)$id_link); if ($res) foreach ($res as $row) { $links['text'][(int)$row['id_lang']] = $row['text']; $links['answer'] = $row['answer']; } } } $this->_html .= ' <script type="text/javascript"> id_language = Number('.(int)$id_lang_default.'); </script> <fieldset> <legend><img src="../img/admin/add.gif" alt="" title="" /> '.$this->l('Добавить вопрос-ответ').'</legend> <form method="post" action="index.php?controller=adminmodules&configure='.Tools::safeOutput(Tools::getValue('configure')).'&token='.Tools::safeOutput(Tools::getValue('token')).'&tab_module='.Tools::safeOutput(Tools::getValue('tab_module')).'&module_name='.Tools::safeOutput(Tools::getValue('module_name')).'"> <input type="hidden" name="id_link" value="'.(int)Tools::getValue('id_link').'" /> <label>'.$this->l('вопрос:').'</label> <div class="margin-form">'; foreach ($languages as $language) $this->_html .= ' <div id="text_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;"> <input type="text" name="text_'.$language['id_lang'].'" id="textInput_'.$language['id_lang'].'" value="'.((isset($links) && isset($links['text'][$language['id_lang']])) ? $links['text'][$language['id_lang']] : '').'" /><sup> *</sup> </div>'; $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'text', true); $this->_html .= ' <div class="clear"></div> </div> <label>'.$this->l('ответ:').'</label> <div class="margin-form"> <textarea style="width: 350px; height: 100px;" type="text" class="rte" name="answer" id="answer" value="'.(isset($links) && isset($links['answer']) ? Tools::safeOutput($links['answer']) : '').'" /></textarea> </div> '; $shops = Shop::getShops(true, null, true); if (Shop::isFeatureActive() && count($shops) > 1) { $helper = new HelperForm(); $helper->id = (int)Tools::getValue('id_link'); $helper->table = 'wnfaq'; $helper->identifier = 'id_wnfaq'; $this->_html .= '<label for="shop_association">'.$this->l('Shop association:').'</label><div id="shop_association" class="margin-form">'.$helper->renderAssoShop().'</div>'; } $this->_html .= ' <div class="margin-form"> <input type="submit" class="button" name="submitLinkAdd" value="'.$this->l('Добавить').'" /> </div> </form> </fieldset> '; } private function _list() { $links = $this->getLinks(); $languages = Language::getLanguages(); $token = Tools::safeOutput(Tools::getValue('token')); if (!Validate::isCleanHtml($token)) $token = ''; if ($links) { $this->_html .= ' <script type="text/javascript"> var currentUrl = \''.Tools::safeOutput($_SERVER['REQUEST_URI']).'\'; var token=\''.$token.'\'; var links = new Array();'; foreach ($links as $link) { $this->_html .= 'links['.$link['id'].'] = new Array(\''.addslashes($link['answer']).'\', '.$link['newWindow']; foreach ($languages as $language) if (isset($link['text_'.$language['id_lang']])) $this->_html .= ', \''.addslashes($link['text_'.$language['id_lang']]).'\''; else $this->_html .= ', \'\''; $this->_html .= ');'; } $this->_html .= '</script>'; } $this->_html .= ' <h3 class="blue space">'.$this->l('FAQ list').'</h3> <table class="table"> <tr> <th>'.$this->l('ID').'</th> <th>'.$this->l('вопрос').'</th> <th>'.$this->l('ответ').'</th> <th>'.$this->l('действие').'</th> </tr>'; if (!$links) $this->_html .= ' <tr> <td colspan="3">'.$this->l('нет вопроса-ответа.').'</td> </tr>'; else foreach ($links as $link) $this->_html .= ' <tr> <td>'.(int)$link['id'].'</td> <td>'.Tools::safeOutput($link['text_'.$this->context->language->id]).'</td> <td>'.Tools::safeOutput($link['answer']).'</td> <td> <a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&id_link='.(int)$link['id'].'"><img src="../img/admin/edit.gif" alt="" title="" style="cursor: pointer" /></a> <a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&id='.(int)$link['id'].'&delete_link=1"><img src="../img/admin/delete.gif" alt="" title="" style="cursor: pointer" /></a> </td> </tr>'; $i = 0; $nb = count($languages); $idLng = 0; while ($i < $nb) { if ($languages[$i]['id_lang'] == (int)Configuration::get('PS_LANG_DEFAULT')) $idLng = $i; $i++; } $this->_html .= ' </table> <input type="hidden" id="languageFirst" value="'.(int)$languages[0]['id_lang'].'" /> <input type="hidden" id="languageNb" value="'.count($languages).'" />'; } } How to add TinyMCE editor for textarea: <textarea style="width: 350px; height: 100px;" type="text" class="rte" name="answer" id="answer" value="'.(isset($links) && isset($links['answer']) ? Tools::safeOutput($links['answer']) : '').'" /></textarea> Edited December 11, 2013 by kotkotan (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted December 11, 2013 Share Posted December 11, 2013 you can check how i created it in this free module: http://www.prestashop.com/forums/topic/189039-module-html-box-for-free/ Link to comment Share on other sites More sharing options...
kotkotan Posted December 11, 2013 Author Share Posted December 11, 2013 you can check how i created it in this free module: http://www.prestashop.com/forums/topic/189039-module-html-box-for-free/ thanks for module, but i need just TinyMCE editor for BO for module Link to comment Share on other sites More sharing options...
vekia Posted December 11, 2013 Share Posted December 11, 2013 this is why i posted link to this addon. there is tinymce editor for textarea you can grab code Link to comment Share on other sites More sharing options...
kotkotan Posted December 11, 2013 Author Share Posted December 11, 2013 I have code ot TinyMCE <script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script> <script type="text/javascript"> function tinyMCEInit(element) { $().ready(function() { $(element).tinymce({ // Location of TinyMCE script script_url : \''.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/tiny_mce.js\', // General options theme : "advanced", plugins : "safari,pagebreak,style,layer,table,advimage,advlink,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen", // Theme options theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,,|,forecolor,backcolor", theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,pagebreak", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : false, content_css : "'.__PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/global.css", width: "582", height: "auto", font_size_style_values : "8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt", // Drop lists for link/image/media/template dialogs template_external_list_url : "lists/template_list.js", external_link_list_url : "lists/link_list.js", external_image_list_url : "lists/image_list.js", media_external_list_url : "lists/media_list.js", elements : "nourlconvert", convert_urls : false, language : "'.(file_exists(_PS_ROOT_DIR_.'/js/tinymce/jscripts/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en').'" }); }); } tinyMCEInit(\'textarea.rte\'); </script> I don't know place in which it should be add Link to comment Share on other sites More sharing options...
Recommended Posts