* @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminCmsControllerCore extends AdminController { protected $category; public $id_cms_category; protected $position_identifier = 'id_cms'; public function __construct() { $this->bootstrap = true; $this->table = 'cms'; $this->list_id = 'cms'; $this->className = 'CMS'; $this->lang = true; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash' ) ); $this->fields_list = array( 'id_cms' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'link_rewrite' => array('title' => $this->l('URL')), 'meta_title' => array('title' => $this->l('Title'), 'filter_key' => 'b!meta_title'), 'position' => array('title' => $this->l('Position'),'filter_key' => 'position', 'align' => 'center', 'class' => 'fixed-width-sm', 'position' => 'position'), 'active' => array('title' => $this->l('Displayed'), 'align' => 'center', 'active' => 'status', 'class' => 'fixed-width-sm', 'type' => 'bool', 'orderby' => false) ); // The controller can't be call directly // In this case, AdminCmsContentController::getCurrentCMSCategory() is null if (!AdminCmsContentController::getCurrentCMSCategory()) { $this->redirect_after = '?controller=AdminCmsContent&token='.Tools::getAdminTokenLite('AdminCmsContent'); $this->redirect(); } $this->_category = AdminCmsContentController::getCurrentCMSCategory(); $this->tpl_list_vars['icon'] = 'icon-folder-close'; $this->tpl_list_vars['title'] = sprintf($this->l('Pages in category "%s"'), $this->_category->name[Context::getContext()->employee->id_lang]); $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'cms_category` c ON (c.`id_cms_category` = a.`id_cms_category`)'; $this->_select = 'a.position '; $this->_where = ' AND c.id_cms_category = '.(int)$this->_category->id; parent::__construct(); } public function initPageHeaderToolbar() { $this->page_header_toolbar_btn['save-and-preview'] = array( 'href' => '#', 'desc' => $this->l('Save and preview', null, null, false) ); $this->page_header_toolbar_btn['save-and-stay'] = array( 'short' => $this->l('Save and stay', null, null, false), 'href' => '#', 'desc' => $this->l('Save and stay', null, null, false), ); return parent::initPageHeaderToolbar(); } public function renderForm() { if (!$this->loadObject(true)) return; if (Validate::isLoadedObject($this->object)) $this->display = 'edit'; else $this->display = 'add'; $this->initToolbar(); $this->initPageHeaderToolbar(); $categories = CMSCategory::getCategories($this->context->language->id, false); $html_categories = CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($this->object, 'id_cms_category'), 1); $this->fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('CMS Page'), 'icon' => 'icon-folder-close' ), 'input' => array( // custom template array( 'type' => 'select_category', 'label' => $this->l('CMS Category'), 'name' => 'id_cms_category', 'options' => array( 'html' => $html_categories, ), ), array( 'type' => 'text', 'label' => $this->l('Meta title'), 'name' => 'meta_title', 'id' => 'name', // for copyMeta2friendlyURL compatibility 'lang' => true, 'required' => true, 'class' => 'copyMeta2friendlyURL', 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'text', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => array( $this->l('To add "tags" click in the field, write something, and then press "Enter."'), $this->l('Invalid characters:').' <>;=#{}' ) ), array( 'type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true, 'hint' => $this->l('Only letters and the hyphen (-) character are allowed.') ), array( 'type' => 'textarea', 'label' => $this->l('Page content'), 'name' => 'content', 'autoload_rte' => true, 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), array( 'type' => 'switch', 'label' => $this->l('Indexation by search engines'), 'name' => 'indexation', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'indexation_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'indexation_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'switch', 'label' => $this->l('Displayed'), 'name' => 'active', 'required' => false, '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( 'title' => $this->l('Save'), ), 'buttons' => array( 'save_and_preview' => array( 'name' => 'viewcms', 'type' => 'submit', 'title' => $this->l('Save and preview'), 'class' => 'btn btn-default pull-right', 'icon' => 'process-icon-preview' ) ) ); if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array( 'type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso', ); } $this->tpl_form_vars = array( 'active' => $this->object->active, 'PS_ALLOW_ACCENTED_CHARS_URL', (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL') ); return parent::renderForm(); } public function renderList() { //self::$currentIndex = self::$currentIndex.'&cms'; $this->position_group_identifier = (int)$this->id_cms_category; $this->toolbar_title = $this->l('Pages in this category'); $this->toolbar_btn['new'] = array( 'href' => self::$currentIndex.'&add'.$this->table.'&id_cms_category='.(int)$this->id_cms_category.'&token='.$this->token, 'desc' => $this->l('Add new') ); return parent::renderList(); } public function displayList($token = null) { /* Display list header (filtering, pagination and column names) */ $this->displayListHeader($token); if (!count($this->_list)) echo '