protected function _prepareHook($params) { $languages = Language::getLanguages(true, $this->context->shop->id); if (!count($languages)) { return false; } $link = new Link(); if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { $default_rewrite = array(); if (Dispatcher::getInstance()->getController() == 'product' && ($id_product = (int) Tools::getValue('id_product'))) { $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']); } } if (Dispatcher::getInstance()->getController() == 'category' && ($id_category = (int) Tools::getValue('id_category'))) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } } if (Dispatcher::getInstance()->getController() == 'cms' && (($id_cms = (int) Tools::getValue('id_cms')) || ($id_cms_category = (int) Tools::getValue('id_cms_category')))) { $rewrite_infos = isset($id_cms) && !isset($id_cms_category) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category); foreach ($rewrite_infos as $infos) { $arr_link = isset($id_cms) && !isset($id_cms_category) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], null, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } } $this->smarty->assign('lang_rewrite_urls', $default_rewrite); } return true; }
public function getTemplateVarSitemap() { $pages = []; $catalog_mode = Configuration::isCatalogMode(); $cms = CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1); foreach ($cms['cms'] as $p) { $pages[] = ['id' => 'cms-page-' . $p['id_cms'], 'label' => $p['meta_title'], 'url' => $this->context->link->getCMSLink(new CMS($p['id_cms']))]; } $pages[] = ['id' => 'stores-page', 'label' => $this->trans('Our stores', array(), 'Shop.Theme'), 'url' => $this->context->link->getPageLink('stores')]; $pages[] = ['id' => 'contact-page', 'label' => $this->trans('Contact us', array(), 'Shop.Theme'), 'url' => $this->context->link->getPageLink('contact')]; $pages[] = ['id' => 'sitemap-page', 'label' => $this->trans('Sitemap', array(), 'Shop.Theme'), 'url' => $this->context->link->getPageLink('sitemap')]; $pages[] = ['id' => 'login-page', 'label' => $this->trans('Log in', array(), 'Shop.Theme'), 'url' => $this->context->link->getPageLink('authentication')]; $pages[] = ['id' => 'register-page', 'label' => $this->trans('Create new account', array(), 'Shop.Theme'), 'url' => $this->context->link->getPageLink('authentication')]; $catalog = ['new-product' => ['id' => 'new-product-page', 'label' => $this->trans('New products', array(), 'Shop.Theme.Catalog'), 'url' => $this->context->link->getPageLink('new-products')]]; if ($catalog_mode && Configuration::get('PS_DISPLAY_BEST_SELLERS')) { $catalog['best-sales'] = ['id' => 'best-sales-page', 'label' => $this->trans('Best sellers', array(), 'Shop.Theme.Catalog'), 'url' => $this->context->link->getPageLink('best-sales')]; $catalog['prices-drop'] = ['id' => 'prices-drop-page', 'label' => $this->trans('Price drop', array(), 'Shop.Theme.Catalog'), 'url' => $this->context->link->getPageLink('prices-drop')]; } if (Configuration::get('PS_DISPLAY_SUPPLIERS')) { $manufacturers = Manufacturer::getLiteManufacturersList($this->context->language->id, 'sitemap'); $catalog['manufacturer'] = ['id' => 'manufacturer-page', 'label' => $this->trans('Manufacturers', array(), 'Shop.Theme.Catalog'), 'url' => $this->context->link->getPageLink('manufacturer'), 'children' => $manufacturers]; $suppliers = Supplier::getLiteSuppliersList($this->context->language->id, 'sitemap'); $catalog['supplier'] = ['id' => 'supplier-page', 'label' => $this->trans('Suppliers', array(), 'Shop.Theme.Catalog'), 'url' => $this->context->link->getPageLink('supplier'), 'children' => $suppliers]; } $categories = Category::getRootCategory()->recurseLiteCategTree(0, 0, null, null, 'sitemap'); $catalog['category'] = ['id' => 'category-page', 'label' => $this->trans('Categories', array(), 'Shop.Theme.Catalog'), 'url' => '#', 'children' => $categories['children']]; $sitemap = [['id' => 'page-page', 'label' => $this->trans('Pages', array(), 'Shop.Theme'), 'url' => '#', 'children' => $pages], ['id' => 'catalog-page', 'label' => $this->trans('Catalog', array(), 'Shop.Theme'), 'url' => '#', 'children' => $catalog]]; return $sitemap; }
public function renderForm() { $fields_form = array('form' => array('legend' => array('title' => $this->l('Homepage categories'), 'icon' => ''), 'input' => array(array('type' => 'cms_choice', 'label' => '', 'name' => 'cats')), 'submit' => array('name' => 'submitBlockshortcms', 'title' => $this->l('Save')))); $lang = $this->context->language; if ($selectedItems = Configuration::get('MOD_BLOCKHOMECMS_ITEMS')) { $selectedItems = explode(',', $selectedItems); foreach ($selectedItems as $index => $id_cms) { $selectedItems[$index] = new CMS($id_cms, $this->context->language->id); } } else { $selectedItems = null; } $helper = new HelperForm(); $helper->show_toolbar = false; $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->module = $this; $helper->identifier = 'id_blocklink'; $helper->submit_action = 'submit'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->fields_value = array('text' => 'text'); $categories = current(CMSCategory::getCategories($this->context->language->id)); $allCms = CMS::getCMSPages($this->context->language->id); $helper->tpl_vars = array('categories' => current(CMSCategory::getCategories($this->context->language->id)), 'allCms' => CMS::getCMSPages($this->context->language->id), 'selectedCms' => $selectedItems); return $helper->generateForm(array($fields_form)); }
public function process() { parent::process(); self::$smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); self::$smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory(_USER_ID_LANG_, 1, 1, 1)); self::$smarty->assign('voucherAllowed', (int) Configuration::get('PS_VOUCHERS')); $blockmanufacturer = Module::getInstanceByName('blockmanufacturer'); $blocksupplier = Module::getInstanceByName('blocksupplier'); self::$smarty->assign('display_manufacturer_link', (int) $blockmanufacturer->id ? true : false); self::$smarty->assign('display_supplier_link', (int) $blocksupplier->id ? true : false); self::$smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS')); self::$smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP')); }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $this->context->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); $this->context->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1)); $this->context->smarty->assign('voucherAllowed', (int) Configuration::get('PS_VOUCHERS')); $blockmanufacturer = Module::getInstanceByName('blockmanufacturer'); $blocksupplier = Module::getInstanceByName('blocksupplier'); $this->context->smarty->assign('display_manufacturer_link', (bool) $blockmanufacturer->active); $this->context->smarty->assign('display_supplier_link', (bool) $blocksupplier->active); $this->context->smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS')); $this->context->smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP')); $this->setTemplate(_PS_THEME_DIR_ . 'sitemap.tpl'); }
public function getTemplateVarCategoryCms() { $categoryCms = array(); $categoryCms['cms_category'] = $this->objectPresenter->present($this->cms_category); $categoryCms['sub_categories'] = array(); $categoryCms['cms_pages'] = array(); foreach ($this->cms_category->getSubCategories($this->context->language->id) as $subCategory) { $categoryCms['sub_categories'][$subCategory['id_cms_category']] = $subCategory; $categoryCms['sub_categories'][$subCategory['id_cms_category']]['link'] = $this->context->link->getCMSCategoryLink($subCategory['id_cms_category'], $subCategory['link_rewrite']); } foreach (CMS::getCMSPages($this->context->language->id, (int) $this->cms_category->id, true, (int) $this->context->shop->id) as $cmsPages) { $categoryCms['cms_pages'][$cmsPages['id_cms']] = $cmsPages; $categoryCms['cms_pages'][$cmsPages['id_cms']]['link'] = $this->context->link->getCMSLink($cmsPages['id_cms'], $cmsPages['link_rewrite']); } return $categoryCms; }
function reorderpositions() { /* Clean products positions */ if ($cat = Category::getCategories(1, false, false)) { foreach ($cat as $i => $categ) { Product::cleanPositions((int) $categ['id_category']); } } //clean Category position and delete old position system Language::loadLanguages(); $language = Language::getLanguages(); $cat_parent = Db::getInstance()->ExecuteS('SELECT DISTINCT c.id_parent FROM `' . _DB_PREFIX_ . 'category` c WHERE id_category != 1'); foreach ($cat_parent as $parent) { $result = Db::getInstance()->ExecuteS(' SELECT DISTINCT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . (int) Configuration::get('PS_LANG_DEFAULT') . ') WHERE c.id_parent = ' . (int) $parent['id_parent'] . ' ORDER BY name ASC'); foreach ($result as $i => $categ) { Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'category` SET `position` = ' . (int) $i . ' WHERE `id_parent` = ' . (int) $categ['id_parent'] . ' AND `id_category` = ' . (int) $categ['id_category']); } $result = Db::getInstance()->ExecuteS(' SELECT DISTINCT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category`) WHERE c.id_parent = ' . (int) $parent['id_parent'] . ' ORDER BY name ASC'); // Remove number from category name foreach ($result as $i => $categ) { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category`) SET `name` = \'' . preg_replace('/^[0-9]+\\./', '', $categ['name']) . '\' WHERE c.id_category = ' . (int) $categ['id_category'] . ' AND id_lang = \'' . (int) $categ['id_lang'] . '\''); } } /* Clean CMS positions */ if ($cms_cat = CMSCategory::getCategories(1, false, false)) { foreach ($cms_cat as $i => $categ) { CMS::cleanPositions((int) $categ['id_cms_category']); } } }
public function preProcess() { if ($id_cms = (int) Tools::getValue('id_cms')) { $this->cms = new CMS($id_cms, self::$cookie->id_lang); } elseif ($id_cms_category = (int) Tools::getValue('id_cms_category')) { $this->cms_category = new CMSCategory($id_cms_category, self::$cookie->id_lang); } // Automatically redirect to the canonical URL if the current in is the right one // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain if ($this->cms and $canonicalURL = self::$link->getCMSLink($this->cms)) { if (!preg_match('/^' . Tools::pRegexp($canonicalURL, '/') . '([&?].*)?$/', Tools::getProtocol() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); if (defined(_PS_MODE_DEV_) and _PS_MODE_DEV_) { die('[Debug] This page has moved<br />Please use the following URL instead: <a href="' . $canonicalURL . '">' . $canonicalURL . '</a>'); } Tools::redirectLink($canonicalURL); } } if ($this->cms_category and $canonicalURL = self::$link->getCMSCategoryLink($this->cms_category)) { if (!preg_match('/^' . Tools::pRegexp($canonicalURL, '/') . '([&?].*)?$/', Tools::getProtocol() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); if (_PS_MODE_DEV_) { die('[Debug] This page has moved<br />Please use the following URL instead: <a href="' . $canonicalURL . '">' . $canonicalURL . '</a>'); } Tools::redirectLink($canonicalURL); } } parent::preProcess(); /* assignCase (1 = CMS page, 2 = CMS category) */ if (Validate::isLoadedObject($this->cms) and ($this->cms->active or Tools::getValue('adtoken') == Tools::encrypt('PreviewCMS' . $this->cms->id) and file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php'))) { $this->assignCase = 1; } elseif (Validate::isLoadedObject($this->cms_category)) { $this->assignCase = 2; } else { Tools::redirect('404.php'); } if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { $rewrite_infos = (isset($id_cms) and !isset($id_cms_category)) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category); $default_rewrite = array(); foreach ($rewrite_infos as $infos) { $arr_link = (isset($id_cms) and !isset($id_cms_category)) ? self::$link->getCMSLink($id_cms, $infos['link_rewrite'], $this->ssl, $infos['id_lang']) : self::$link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } self::$smarty->assign('lang_rewrite_urls', $default_rewrite); } }
public function renderForm() { $this->display = 'edit'; $this->toolbar_btn['save-and-preview'] = array('href' => '#', 'desc' => $this->l('Save and preview')); $this->initToolbar(); if (!$this->loadObject(true)) { return; } $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'), 'image' => '../img/admin/tab-categories.gif'), 'input' => array(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', 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}', 'size' => 50), array('type' => 'text', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}', 'size' => 70), array('type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}', 'size' => 70, 'desc' => $this->l('To add "tags" click in the field, write something, then press "Enter"')), array('type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true, 'hint' => $this->l('Only letters and the minus (-) 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' => 'radio', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', '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 '), 'class' => 'button')); 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); return parent::renderForm(); }
/** * Method processSave() : add or update cms category object * * @module now_seo_links * @return object CMS Category * * @see AdminCmsCategoriesControllerCore::processSave() */ public function processSave() { $iIdCmsCategory = Tools::getValue('id_cms_category', false); $aLinkRewrite = array(); foreach (Language::getLanguages(true) as $aLang) { if (array_key_exists('link_rewrite_' . (int) $aLang['id_lang'], $_POST)) { $aLinkRewrite[(int) $aLang['id_lang']] = Tools::getValue('link_rewrite_' . (int) $aLang['id_lang']); } } // Check if name already exist foreach ($aLinkRewrite as $iIdLang => $sLinkRewrite) { if (CMSCategory::linkRewriteIsAlreadyUsed($iIdCmsCategory, $sLinkRewrite, $iIdLang)) { $this->errors[] = sprintf(Tools::displayError('Ce link_rewrite "%s" (%s) existe déjà pour une autre catégorie de CMS et ne peut être utilisé une nouvelle fois.'), $sLinkRewrite, Language::getIsoById($iIdLang)); } } return parent::processSave(); }
public function renderForm() { if (!$this->loadObject(true)) { return; } $checkVersion = version_compare(_PS_VERSION_, '1.6'); $this->isPS6 = false; if ($checkVersion >= 0) { $this->isPS6 = true; } if (Validate::isLoadedObject($this->object)) { $this->display = 'edit'; } else { $this->display = 'add'; } if (!$this->isPS6) { //ps5 $this->toolbar_btn['save-and-preview'] = array('href' => '#', 'desc' => $this->l('Save and preview')); $this->toolbar_btn['save-and-stay'] = array('short' => 'SaveAndStay', 'href' => '#', 'desc' => $this->l('Save and stay')); } $this->initToolbar(); if ($this->isPS6) { //ps6 $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); $galleries = $this->getSliders(); $this->fields_form = array('tinymce' => true, 'legend' => array('title' => $this->l('CMS Page'), 'image' => '../img/admin/tab-categories.gif', 'icon' => 'icon-folder-close'), 'input' => array(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', 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl copyMeta2friendlyURL', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'select_category', 'label' => $this->l('Slider'), 'name' => 'proslider', 'empty_message' => $this->l('None'), 'options' => array('html' => $galleries)), 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' => $this->l('Invalid characters:') . ' <>;=#{}', 'desc' => $this->l('To add "tags" click in the field, write something, and then press "Enter."')), array('type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true, 'hint' => $this->l('Only letters and the minus (-) 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' => $this->isPS6 ? 'switch' : 'hidden', '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' => $this->isPS6 ? 'switch' : 'radio', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', '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'), 'class' => 'button btn btn-default')); if ($this->isPS6) { $this->fields_form['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')); } $this->fields_form['submit'] = array('title' => $this->l('Save'), 'class' => 'button btn btn-default pull-right'); if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso'); } if ($this->isPS6) { if (Validate::isLoadedObject($this->object)) { $this->context->smarty->assign('url_prev', $this->getPreviewUrl($this->object)); } } $this->tpl_form_vars = array('active' => $this->object->active, 'PS_ALLOW_ACCENTED_CHARS_URL', (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL')); return adminController::renderForm(); }
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(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', '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(); }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $parent_cat = new CMSCategory(1, $this->context->language->id); $this->context->smarty->assign('id_current_lang', $this->context->language->id); $this->context->smarty->assign('home_title', $parent_cat->name); $this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID')); if ($this->assignCase == 1) { if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category) { $path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS'); } elseif (isset($this->cms_category->meta_title)) { $path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS'); } $this->context->smarty->assign(array('cms' => $this->cms, 'content_only' => (int) Tools::getValue('content_only'), 'path' => $path, 'body_classes' => array($this->php_self . '-' . $this->cms->id, $this->php_self . '-' . $this->cms->link_rewrite))); if ($this->cms->indexation == 0) { $this->context->smarty->assign('nobots', true); } } elseif ($this->assignCase == 2) { $this->context->smarty->assign(array('category' => $this->cms_category, 'cms_category' => $this->cms_category, 'sub_category' => $this->cms_category->getSubCategories($this->context->language->id), 'cms_pages' => CMS::getCMSPages($this->context->language->id, (int) $this->cms_category->id, true, (int) $this->context->shop->id), 'path' => $this->cms_category->id !== 1 ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '', 'body_classes' => array($this->php_self . '-' . $this->cms_category->id, $this->php_self . '-' . $this->cms_category->link_rewrite))); } $this->setTemplate(_PS_THEME_DIR_ . 'cms.tpl'); }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $this->context->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); $this->context->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1)); $this->context->smarty->assign('voucherAllowed', (int) CartRule::isFeatureActive()); if (Module::isInstalled('blockmanufacturer') && Module::isEnabled('blockmanufacturer')) { $blockmanufacturer = Module::getInstanceByName('blockmanufacturer'); $this->context->smarty->assign('display_manufacturer_link', isset($blockmanufacturer->active) ? (bool) $blockmanufacturer->active : false); } else { $this->context->smarty->assign('display_manufacturer_link', 0); } if (Module::isInstalled('blocksupplier') && Module::isEnabled('blocksupplier')) { $blocksupplier = Module::getInstanceByName('blocksupplier'); $this->context->smarty->assign('display_supplier_link', isset($blocksupplier->active) ? (bool) $blocksupplier->active : false); } else { $this->context->smarty->assign('display_supplier_link', 0); } $this->context->smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS')); $this->context->smarty->assign('PS_DISPLAY_BEST_SELLERS', Configuration::get('PS_DISPLAY_BEST_SELLERS')); $this->context->smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP')); $this->setTemplate(_PS_THEME_DIR_ . 'sitemap.tpl'); }
/** * Returns module content for header * * @param array $params Parameters * @return string Content */ public function hookTop($params) { global $smarty; $languages = Language::getLanguages(); if (!count($languages)) { return; } $link = new Link(); if ((int) Configuration::get('PS_REWRITING_SETTINGS')) { $default_rewrite = array(); $phpSelf = isset($_SERVER['PHP_SELF']) ? substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)) : ''; if ($phpSelf == 'product.php' and $id_product = (int) Tools::getValue('id_product')) { $rewrite_infos = Product::getUrlRewriteInformations((int) $id_product); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getProductLink((int) $id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int) $infos['id_lang']); } } if ($phpSelf == 'category.php' and $id_category = (int) Tools::getValue('id_category')) { $rewrite_infos = Category::getUrlRewriteInformations((int) $id_category); foreach ($rewrite_infos as $infos) { $default_rewrite[$infos['id_lang']] = $link->getCategoryLink((int) $id_category, $infos['link_rewrite'], $infos['id_lang']); } } if ($phpSelf == 'cms.php' and ($id_cms = (int) Tools::getValue('id_cms') or $id_cms_category = (int) Tools::getValue('id_cms_category'))) { $rewrite_infos = (isset($id_cms) and !isset($id_cms_category)) ? CMS::getUrlRewriteInformations($id_cms) : CMSCategory::getUrlRewriteInformations($id_cms_category); foreach ($rewrite_infos as $infos) { $arr_link = (isset($id_cms) and !isset($id_cms_category)) ? $link->getCMSLink($id_cms, $infos['link_rewrite'], NULL, $infos['id_lang']) : $link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } } if (count($default_rewrite)) { $smarty->assign('lang_rewrite_urls', $default_rewrite); } } $smarty->assign('languages', $languages); return $this->display(__FILE__, 'blocklanguages.tpl'); }
protected function getCMSMenuItems($parent, $depth = 1, $id_lang = false) { $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id; if ($depth > 3) { return; } $categories = $this->getCMSCategories(false, (int) $parent, (int) $id_lang); $pages = $this->getCMSPages((int) $parent); if (count($categories) || count($pages)) { $this->_menu .= '<ul>'; foreach ($categories as $category) { $cat = new CMSCategory((int) $category['id_cms_category'], (int) $id_lang); $this->_menu .= '<li>'; $this->_menu .= '<a href="' . Tools::HtmlEntitiesUTF8($cat->getLink()) . '">' . $category['name'] . '</a>'; $this->getCMSMenuItems($category['id_cms_category'], (int) $depth + 1); $this->_menu .= '</li>'; } foreach ($pages as $page) { $cms = new CMS($page['id_cms'], (int) $id_lang); $links = $cms->getLinks((int) $id_lang, array((int) $cms->id)); $selected = $this->page_name == 'cms' && (int) Tools::getValue('id_cms') == $page['id_cms'] ? ' class="sfHoverForce"' : ''; $this->_menu .= '<li ' . $selected . '>'; $this->_menu .= '<a href="' . $links[0]['link'] . '">' . $cms->meta_title . '</a>'; $this->_menu .= '</li>'; } $this->_menu .= '</ul>'; } }
private function _displayAddForm() { global $currentIndex, $cookie; $defaultLanguage = (int) Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $divLangName = 'name'; $cmsBlock = NULL; if (Tools::isSubmit('editBlockCMS') and Tools::getValue('id_cms_block')) { $cmsBlock = $this->getBlockCMS((int) Tools::getValue('id_cms_block')); } $this->_html .= ' <script type="text/javascript" src="' . _PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/' . $this->name . '.js"></script> <script type="text/javascript">id_language = Number(' . $defaultLanguage . ');</script> <form method="POST" action="' . Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']) . '"> '; if (Tools::getValue('id_cms_block')) { $this->_html .= '<input type="hidden" name="id_cms_block" value="' . (int) Tools::getValue('id_cms_block') . '" id="id_cms_block" />'; } $this->_html .= ' <fieldset>'; if (Tools::isSubmit('addBlockCMS')) { $this->_html .= '<legend><img src="' . _PS_ADMIN_IMG_ . 'add.gif" alt="" /> ' . $this->l('New CMS block') . '</legend>'; } elseif (Tools::isSubmit('editBlockCMS')) { $this->_html .= '<legend><img src="' . _PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/logo.gif" alt="" /> ' . $this->l('Edit CMS block') . '</legend>'; } $this->_html .= ' <label>' . $this->l('Name of block:') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->_html .= ' <div id="name_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . ';float: left;"> <input type="text" name="block_name_' . $language['id_lang'] . '" id="block_name_' . $language['id_lang'] . '" size="30" value="' . (Tools::getValue('block_name_' . $language['id_lang']) ? Tools::getValue('block_name_' . $language['id_lang']) : (isset($cmsBlock['name'][$language['id_lang']]) ? $cmsBlock['name'][$language['id_lang']] : '')) . '" /> </div>'; } $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'name', true); $this->_html .= '<p class="clear">' . $this->l('If you leave this field empty, the block name will use the category name') . '</p> </div><br /> <label for="id_category">' . $this->l('Choose a CMS category:') . '</label> <div class="margin-form"> <select name="id_category" id="id_category" onchange="CMSCategory_js($(this).val(), \'' . $this->secure_key . '\')">'; $categories = CMSCategory::getCategories((int) $cookie->id_lang, false); $this->_html .= CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $cmsBlock != NULL ? $cmsBlock[0]['id_cms_category'] : 1, 1); $this->_html .= ' </select> </div><br /> <label>' . $this->l('Location:') . '</label> <div class="margin-form"> <select name="block_location" id="block_location"> <option value="' . self::LEFT_COLUMN . '" ' . (($cmsBlock and $cmsBlock[0]['location'] == self::LEFT_COLUMN) ? 'selected="selected"' : '') . '>' . $this->l('Left') . '</option> <option value="' . self::RIGHT_COLUMN . '" ' . (($cmsBlock and $cmsBlock[0]['location'] == self::RIGHT_COLUMN) ? 'selected="selected"' : '') . '>' . $this->l('Right') . '</option> </select> </div>'; $this->_html .= ' <label for="PS_STORES_DISPLAY_CMS_on">' . $this->l('Display Stores:') . '</label> <div class="margin-form"> <img src="../img/admin/enabled.gif" alt="Yes" title="Yes" /> <input type="radio" name="PS_STORES_DISPLAY_CMS" id="PS_STORES_DISPLAY_CMS_on" ' . (($cmsBlock and isset($cmsBlock[0]['display_store']) && $cmsBlock[0]['display_store'] == 0) ? '' : 'checked="checked" ') . 'value="1" /> <label class="t" for="PS_STORES_DISPLAY_CMS_on">' . $this->l('Yes') . '</label> <img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" /> <input type="radio" name="PS_STORES_DISPLAY_CMS" id="PS_STORES_DISPLAY_CMS_off" ' . (($cmsBlock and isset($cmsBlock[0]['display_store']) && $cmsBlock[0]['display_store'] == 0) ? 'checked="checked" ' : '') . 'value="0" /> <label class="t" for="PS_STORES_DISPLAY_CMS_off">' . $this->l('No') . '</label><br />' . $this->l('Display "our stores" at the end of the block') . '</div>'; $this->_html .= '<div id="cms_subcategories"></div> <p class="center"> <input type="submit" class="button" name="submitBlockCMS" value="' . $this->l('Save') . '" /> <a class="button" style="position:relative; padding:3px 3px 4px 3px; top:1px" href="' . $currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '">' . $this->l('Cancel') . '</a> </p>'; $this->_html .= ' </fieldset> </form> <script type="text/javascript">CMSCategory_js($(\'#id_category\').val(), \'' . $this->secure_key . '\')</script>'; }
public static function create_category($parent, $name, $linkRewrite, $description = '', $meta_title = '', $meta_description = '', $meta_keywords = '') { $configuration = PS_CLI_CONFIGURE::getConfigurationInstance(); $category = new CMSCategory(); if (!Validate::isUnsignedId($parent)) { echo "Error, {$parent} is not a valid category ID\n"; return false; } $parentCat = new CMSCategory($parent); if (!Validate::isloadedObject($parentCat)) { echo "Error: category {$parentCat} does not exists\n"; return false; } $category->id_parent = $parent; if (!Validate::isName($name)) { echo "Error, {$name} is not a valid category name\n"; return false; } $category->name = array($configuration->lang => $name); if (!Validate::isLinkRewrite($linkRewrite)) { echo "Error, {$linkRewrite} is not a valid link rewrite\n"; return false; } $category->link_rewrite = array($configuration->lang => $linkRewrite); if (!Validate::isCleanHtml($description)) { echo "Warning, {$description} is not a valid category description\n"; $description = ''; } $category->description = array($configuration->lang => $description); if (!Validate::isGenericName($meta_title)) { echo "Warning, {$meta_title} is not a valid value for meta_title\n"; $meta_title = ''; } $category->meta_title = array($configuration->lang => $meta_title); if (!Validate::isGenericName($meta_description)) { echo "Warning, {$meta_description} is not a valid value for meta_description\n"; $meta_description = ''; } $category->meta_description = array($configuration->lang => $meta_description); if (!Validate::isGenericName($meta_keywords)) { echo "Warning, {$meta_keywords} is not a valid value for meta_keywords\n"; $meta_keywords = ''; } $category->meta_keywords = array($configuration->lang => $meta_keywords); if ($category->add()) { if ($configuration->porcelain) { echo $category->id_cms_category; } else { echo "Successfully created category {$category->id_cms_category}\n"; } return true; } else { echo "Error, could not create category {$name}\n"; return false; } }
public function displayForm($token = NULL) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) { return; } $active = $this->getFieldValue($obj, 'active'); echo ' <form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . ($token != NULL ? $token : $this->token) . '" method="post" enctype="multipart/form-data"> ' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '') . ' <fieldset style="width:520px"><legend><img src="../img/admin/tab-categories.gif" />' . $this->l('CMS Category') . '</legend> <label>' . $this->l('Name:') . ' </label> <div class="margin-form translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input type="text" style="width: 260px" name="name_' . $language['id_lang'] . '" id="name_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'name', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" ' . (!$obj->id ? ' onkeyup="copy2friendlyURL();"' : '') . ' /><sup> *</sup> <span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear"></p> </div> <label>' . $this->l('Displayed:') . ' </label> <div class="margin-form"> <input type="radio" name="active" id="active_on" value="1" ' . ($active ? 'checked="checked" ' : '') . '/> <label class="t" for="active_on"><img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" /></label> <input type="radio" name="active" id="active_off" value="0" ' . (!$active ? 'checked="checked" ' : '') . '/> <label class="t" for="active_off"><img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" /></label> </div> <label>' . $this->l('Parent CMS Category:') . ' </label> <div class="margin-form"> <select name="id_parent">'; $categories = CMSCategory::getCategories((int) $cookie->id_lang, false); CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($obj, 'id_parent')); echo ' </select> </div> <label>' . $this->l('Description:') . ' </label> <div class="margin-form translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <textarea name="description_' . $language['id_lang'] . '" rows="5" cols="40">' . htmlentities($this->getFieldValue($obj, 'description', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '</textarea> </div>'; } echo ' <p class="clear"></p> </div> <div class="clear"><br /></div> <label>' . $this->l('Meta title:') . ' </label> <div class="margin-form translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input type="text" name="meta_title_' . $language['id_lang'] . '" id="meta_title_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_title', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear"></p> </div> <label>' . $this->l('Meta description:') . ' </label> <div class="margin-form translatable">'; foreach ($this->_languages as $language) { echo '<div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input type="text" name="meta_description_' . $language['id_lang'] . '" id="meta_description_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_description', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear"></p> </div> <label>' . $this->l('Meta keywords:') . ' </label> <div class="margin-form translatable">'; foreach ($this->_languages as $language) { echo ' <div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input type="text" name="meta_keywords_' . $language['id_lang'] . '" id="meta_keywords_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'meta_keywords', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /> <span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear"></p> </div> <label>' . $this->l('Friendly URL:') . ' </label> <div class="margin-form translatable">'; foreach ($this->_languages as $language) { echo '<div class="lang_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;"> <input type="text" name="link_rewrite_' . $language['id_lang'] . '" id="link_rewrite_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'link_rewrite', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" onkeyup="this.value = str2url(this.value);" /><sup> *</sup> <span class="hint" name="help_box">' . $this->l('Only letters and the minus (-) character are allowed') . '<span class="hint-pointer"> </span></span> </div>'; } echo ' <p class="clear"></p> </div> <div class="margin-form"> <input type="submit" value="' . $this->l('Save and back to parent CMS Category') . '" name="submitAdd' . $this->table . 'AndBackToParent" class="button" /> <input type="submit" class="button" name="submitAdd' . $this->table . '" value="' . $this->l('Save') . '"/> </div> <div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div> </fieldset> </form> <p class="clear"></p>'; }
public function renderForm() { $this->display = 'edit'; $this->initToolbar(); if (!$this->loadObject(true)) { return; } $categories = CMSCategory::getCategories($this->context->language->id, false); $html_categories = CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($this->object, 'id_parent'), 1); $this->fields_form = array('legend' => array('title' => $this->l('CMS Category'), 'image' => '../img/admin/tab-categories.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'required' => true, 'lang' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'radio', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', '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')))), array('type' => 'select_category', 'label' => $this->l('Parent CMS Category:'), 'name' => 'id_parent', 'options' => array('html' => $html_categories)), array('type' => 'textarea', 'label' => $this->l('Description:'), 'name' => 'description', 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'lang' => true, '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' => 'text', 'label' => $this->l('Meta keywords:'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $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 minus (-) character are allowed'))), 'submit' => array('title' => $this->l('Save'), 'class' => 'button')); $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'); return parent::renderForm(); }
/** * Return path to a product category * * @param string $urlBase Start URL * @param integer $id_category Start category * @param string $path Current path * @param string $highlight String to highlight (in XHTML/CSS) * @param string $type Category type (products/cms) */ function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryType = 'catalog', $home = false) { $context = Context::getContext(); if ($categoryType == 'catalog') { $category = Db::getInstance()->getRow(' SELECT id_category, level_depth, nleft, nright FROM ' . _DB_PREFIX_ . 'category WHERE id_category = ' . (int) $id_category); if (isset($category['id_category'])) { $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite FROM ' . _DB_PREFIX_ . 'category c LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category' . Shop::addSqlRestrictionOnLang('cl') . ') WHERE c.nleft <= ' . (int) $category['nleft'] . ' AND c.nright >= ' . (int) $category['nright'] . ' AND cl.id_lang = ' . (int) $context->language->id . ($home ? ' AND c.id_category=' . $id_category : '') . ' AND c.id_category != ' . (int) Category::getTopCategory()->id . ' GROUP BY c.id_category ORDER BY c.level_depth ASC LIMIT ' . (!$home ? (int) ($category['level_depth'] + 1) : 1); $categories = Db::getInstance()->executeS($sql); $fullPath = ''; $n = 1; $nCategories = (int) sizeof($categories); foreach ($categories as $category) { $link = Context::getContext()->link->getAdminLink('AdminCategories'); $edit = '<a href="' . $link . '&id_category=' . (int) $category['id_category'] . '&' . ($category['id_category'] == 1 || $home ? 'viewcategory' : 'updatecategory') . '" title="' . ($category['id_category'] == Category::getRootCategory()->id_category ? 'Home' : 'Modify') . '"><i class="icon-' . ($category['id_category'] == Category::getRootCategory()->id_category || $home ? 'home' : 'pencil') . '"></i></a> '; $fullPath .= $edit . ($n < $nCategories ? '<a href="' . $urlBase . '&id_category=' . (int) $category['id_category'] . '&viewcategory&token=' . Tools::getAdminToken('AdminCategories' . (int) Tab::getIdFromClassName('AdminCategories') . (int) $context->employee->id) . '" title="' . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . '">' : '') . (!empty($highlight) ? str_ireplace($highlight, '<span class="highlight">' . htmlentities($highlight, ENT_NOQUOTES, 'UTF-8') . '</span>', $category['name']) : $category['name']) . ($n < $nCategories ? '</a>' : '') . ($n++ != $nCategories || !empty($path) ? ' > ' : ''); } return $fullPath . $path; } } elseif ($categoryType == 'cms') { $category = new CMSCategory($id_category, $context->language->id); if (!$category->id) { return $path; } $name = $highlight != null ? str_ireplace($highlight, '<span class="highlight">' . $highlight . '</span>', CMSCategory::hideCMSCategoryPosition($category->name)) : CMSCategory::hideCMSCategoryPosition($category->name); $edit = '<a href="' . $urlBase . '&id_cms_category=' . $category->id . '&addcategory&token=' . Tools::getAdminToken('AdminCmsContent' . (int) Tab::getIdFromClassName('AdminCmsContent') . (int) $context->employee->id) . '"> <i class="icon-pencil"></i></a> '; if ($category->id == 1) { $edit = '<li><a href="' . $urlBase . '&id_cms_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCmsContent' . (int) Tab::getIdFromClassName('AdminCmsContent') . (int) $context->employee->id) . '"> <i class="icon-home"></i></a></li> '; } $path = $edit . '<li><a href="' . $urlBase . '&id_cms_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCmsContent' . (int) Tab::getIdFromClassName('AdminCmsContent') . (int) $context->employee->id) . '"> ' . $name . '</a></li> > ' . $path; if ($category->id == 1) { return substr($path, 0, strlen($path) - 3); } return getPath($urlBase, $category->id_parent, $path, '', 'cms'); } }
public static function getChildren($id_parent, $id_lang, $active = true) { $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.`id_cms_category`, cl.`name`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'cms_category` c LEFT JOIN `' . _DB_PREFIX_ . 'cms_category_lang` cl ON c.`id_cms_category` = cl.`id_cms_category` WHERE `id_lang` = ' . (int) $id_lang . ' AND c.`id_parent` = ' . (int) $id_parent . ' ' . ($active ? 'AND `active` = 1' : '') . ' ORDER BY `name` ASC'); /* Remove numbers from the titles */ foreach ($results as &$row) { $row['name'] = CMSCategory::hideCMSCategoryPosition($row['name']); } return $results; }
public static function getChildren($id_parent, $id_lang, $active = true) { if (!Validate::isBool($active)) { die(Tools::displayError()); } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.`id_cms_category`, cl.`name`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'cms_category` c LEFT JOIN `' . _DB_PREFIX_ . 'cms_category_lang` cl ON c.`id_cms_category` = cl.`id_cms_category` WHERE `id_lang` = ' . (int) $id_lang . ' AND c.`id_parent` = ' . (int) $id_parent . ' ' . ($active ? 'AND `active` = 1' : '') . ' ORDER BY `name` ASC'); // Modify SQL result $results_array = array(); foreach ($result as $row) { $row['name'] = CMSCategory::hideCMSCategoryPosition($row['name']); $results_array[] = $row; } return $results_array; }
public function display($token = NULL) { global $currentIndex, $cookie; if ($id_cms_category = (int) Tools::getValue('id_cms_category')) { $currentIndex .= '&id_cms_category=' . $id_cms_category; } $this->getList((int) $cookie->id_lang, !$cookie->__get($this->table . 'Orderby') ? 'position' : NULL, !$cookie->__get($this->table . 'Orderway') ? 'ASC' : NULL); //$this->getList((int)($cookie->id_lang)); if (!$id_cms_category) { $id_cms_category = 1; } echo '<h3>' . (!$this->_listTotal ? $this->l('No pages found') : $this->_listTotal . ' ' . ($this->_listTotal > 1 ? $this->l('pages') : $this->l('page'))) . ' ' . $this->l('in category') . ' "' . stripslashes(CMSCategory::hideCMSCategoryPosition($this->_category->getName())) . '"</h3>'; echo '<a href="' . $currentIndex . '&id_cms_category=' . $id_cms_category . '&add' . $this->table . '&token=' . Tools::getAdminTokenLite('AdminCMSContent') . '"><img src="../img/admin/add.gif" border="0" /> ' . $this->l('Add a new page') . '</a> <div style="margin:10px;">'; $this->displayList($token); echo '</div>'; }
public function renderForm() { $this->display = 'edit'; $this->initToolbar(); if (!$this->loadObject(true)) { return; } $categories = CMSCategory::getCategories($this->context->language->id, false); $html_categories = CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($this->object, 'id_parent'), 1); $this->fields_form = array('legend' => array('title' => $this->l('CMS Category'), 'icon' => 'icon-folder-close'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'required' => true, 'lang' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), 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')))), array('type' => 'select_category', 'label' => $this->l('Parent CMS Category'), 'name' => 'id_parent', 'options' => array('html' => $html_categories)), array('type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'description', 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Meta title'), 'name' => 'meta_title', 'lang' => true, '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' => 'text', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $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 minus (-) character are allowed.'))), 'submit' => array('title' => $this->l('Save'))); if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso'); } $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'); return parent::renderForm(); }
protected function generateCMSCategoriesMenu($id_cms_category, $id_lang) { $category = new CMSCategory($id_cms_category, $id_lang); $rawSubCategories = $this->getCMSCategories(false, $id_cms_category, $id_lang); $rawSubPages = $this->getCMSPages($id_cms_category); $subCategories = array_map(function ($category) use($id_lang) { return $this->generateCMSCategoriesMenu($category['id_cms_category'], $id_lang); }, $rawSubCategories); $subPages = array_map(function ($page) use($id_lang) { return $this->makeNode(['type' => 'cms-page', 'page_identifier' => 'cms-page-' . $page['id_cms'], 'label' => $page['meta_title'], 'url' => $this->context->link->getCMSLink(new CMS($page['id_cms'], $id_lang), null, null, $id_lang)]); }, $rawSubPages); $node = $this->makeNode(['type' => 'cms-category', 'page_identifier' => 'cms-category-' . $id_cms_category, 'label' => $category->name, 'url' => $category->getLink(), 'children' => array_merge($subCategories, $subPages)]); return $node; }
/** * This checks if the template set is available for mobile themes, * otherwise the front template is choosen. */ public function setMobileTemplate($template) { // Needed for site map $blockmanufacturer = Module::getInstanceByName('blockmanufacturer'); $blocksupplier = Module::getInstanceByName('blocksupplier'); $this->context->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); $this->context->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1)); $this->context->smarty->assign('voucherAllowed', (int) CartRule::isFeatureActive()); $this->context->smarty->assign('display_manufacturer_link', (bool) $blockmanufacturer->active); $this->context->smarty->assign('display_supplier_link', (bool) $blocksupplier->active); $this->context->smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS')); $this->context->smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP')); $this->context->smarty->assign('conditions', Configuration::get('PS_CONDITIONS')); $this->context->smarty->assign('id_cgv', Configuration::get('PS_CONDITIONS_CMS_ID')); $this->context->smarty->assign('PS_SHOP_NAME', Configuration::get('PS_SHOP_NAME')); $mobile_template = ''; $tpl_file = basename($template); $dirname = dirname($template) . (substr(dirname($template), -1, 1) == '/' ? '' : '/'); if ($dirname == _PS_THEME_DIR_) { if (file_exists(_PS_THEME_MOBILE_DIR_ . $tpl_file)) { $template = _PS_THEME_MOBILE_DIR_ . $tpl_file; } } elseif ($dirname == _PS_THEME_MOBILE_DIR_) { if (!file_exists(_PS_THEME_MOBILE_DIR_ . $tpl_file) && file_exists(_PS_THEME_DIR_ . $tpl_file)) { $template = _PS_THEME_DIR_ . $tpl_file; } } $assign = array(); $assign['tpl_file'] = basename($tpl_file, '.tpl'); if (isset($this->php_self)) { $assign['controller_name'] = $this->php_self; } $this->context->smarty->assign($assign); $this->template = $template; }
/** * Return path to a product category * * @param string $urlBase Start URL * @param integer $id_category Start category * @param string $path Current path * @param string $highlight String to highlight (in XHTML/CSS) * @param string $type Category type (products/cms) */ function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryType = 'catalog') { global $cookie; if ($categoryType == 'catalog') { $category = Db::getInstance()->getRow(' SELECT id_category, level_depth, nleft, nright FROM ' . _DB_PREFIX_ . 'category WHERE id_category = ' . (int) $id_category); if (isset($category['id_category'])) { $categories = Db::getInstance()->ExecuteS(' SELECT c.id_category, cl.name, cl.link_rewrite FROM ' . _DB_PREFIX_ . 'category c LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category) WHERE c.nleft <= ' . (int) $category['nleft'] . ' AND c.nright >= ' . (int) $category['nright'] . ' AND cl.id_lang = ' . (int) $cookie->id_lang . ' ORDER BY c.level_depth ASC LIMIT ' . (int) ($category['level_depth'] + 1)); $fullPath = ''; $n = 1; $nCategories = (int) sizeof($categories); foreach ($categories as $category) { $edit = '<a href="' . $urlBase . '&id_category=' . (int) $category['id_category'] . '&' . ($category['id_category'] == 1 ? 'viewcategory' : 'addcategory') . '&token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" title="' . ($category['id_category'] == 1 ? 'Home' : 'Modify') . '"><img src="../img/admin/' . ($category['id_category'] == 1 ? 'home' : 'edit') . '.gif" alt="" /></a> '; $fullPath .= $edit . ($n < $nCategories ? '<a href="' . $urlBase . '&id_category=' . (int) $category['id_category'] . '&viewcategory&token=' . Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee) . '" title="' . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . '">' : '') . (!empty($highlight) ? str_ireplace($highlight, '<span class="highlight">' . htmlentities($highlight, ENT_NOQUOTES, 'UTF-8') . '</span>', $category['name']) : $category['name']) . ($n < $nCategories ? '</a>' : '') . (($n++ != $nCategories or !empty($path)) ? ' > ' : ''); } return $fullPath . $path; } } elseif ($categoryType == 'cms') { $category = new CMSCategory($id_category, (int) $cookie->id_lang); if (!$category->id) { return $path; } $name = $highlight != NULL ? str_ireplace($highlight, '<span class="highlight">' . $highlight . '</span>', CMSCategory::hideCMSCategoryPosition($category->name)) : CMSCategory::hideCMSCategoryPosition($category->name); $edit = '<a href="' . $urlBase . '&id_cms_category=' . $category->id . '&addcategory&token=' . Tools::getAdminToken('AdminCMSContent' . (int) Tab::getIdFromClassName('AdminCMSContent') . (int) $cookie->id_employee) . '"> <img src="../img/admin/edit.gif" alt="Modify" /></a> '; if ($category->id == 1) { $edit = '<a href="' . $urlBase . '&id_cms_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCMSContent' . (int) Tab::getIdFromClassName('AdminCMSContent') . (int) $cookie->id_employee) . '"> <img src="../img/admin/home.gif" alt="Home" /></a> '; } $path = $edit . '<a href="' . $urlBase . '&id_cms_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCMSContent' . (int) Tab::getIdFromClassName('AdminCMSContent') . (int) $cookie->id_employee) . '"> ' . $name . '</a> > ' . $path; if ($category->id == 1) { return substr($path, 0, strlen($path) - 3); } return getPath($urlBase, $category->id_parent, $path, '', 'cms'); } }
/** * This checks if the template set is available for mobile themes, * otherwise the front template is choosen. */ public function setMobileTemplate($template) { // Needed for site map $blockmanufacturer = Module::getInstanceByName('blockmanufacturer'); $blocksupplier = Module::getInstanceByName('blocksupplier'); $this->context->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); $this->context->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1)); $this->context->smarty->assign('voucherAllowed', (int) CartRule::isFeatureActive()); $this->context->smarty->assign('display_manufacturer_link', (bool) $blockmanufacturer->active); $this->context->smarty->assign('display_supplier_link', (bool) $blocksupplier->active); $this->context->smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS')); $this->context->smarty->assign('PS_DISPLAY_BEST_SELLERS', Configuration::get('PS_DISPLAY_BEST_SELLERS')); $this->context->smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP')); $this->context->smarty->assign('conditions', Configuration::get('PS_CONDITIONS')); $this->context->smarty->assign('id_cgv', Configuration::get('PS_CONDITIONS_CMS_ID')); $this->context->smarty->assign('PS_SHOP_NAME', Configuration::get('PS_SHOP_NAME')); $template = $this->getTemplatePath($template); $assign = array(); $assign['tpl_file'] = basename($template, '.tpl'); if (isset($this->php_self)) { $assign['controller_name'] = $this->php_self; } $this->context->smarty->assign($assign); $this->template = $template; }
protected function generateCMSCategoryData() { $delimiter = ';'; $line = array(); $titles = array(); $new_path = new Sampledatainstall(); $id_lang = $this->use_lang; $f = fopen($new_path->sendPath() . 'output/cms_categories.vsc', 'w'); foreach ($this->cms_category_fields as $field => $array) { $titles[] = $array['label']; } fputcsv($f, $titles, $delimiter, '"'); $cms_categories = CMSCategory::getCategories($id_lang); if ($cms_categories) { foreach ($cms_categories as $cms_category) { foreach ($cms_category as $cc) { $cms_cat = new Category($cc['infos']['id_cms_category'], $id_lang); foreach ($this->cms_category_fields as $field => $array) { $line[$field] = property_exists('Category', $field) && !is_array($cms_cat->{$field}) && !Tools::isEmpty($cms_cat->{$field}) ? $cms_cat->{$field} : ''; } if (!$line[$field]) { $line[$field] = ''; } fputcsv($f, $line, $delimiter, '"'); } } } fclose($f); }