* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminMeta extends AdminTab { public function __construct() { $this->table = 'meta'; $this->className = 'Meta'; $this->lang = true; $this->edit = true; $this->delete = true; $this->fieldsDisplay = array( 'id_meta' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'page' => array('title' => $this->l('Page'), 'width' => 120, 'suffix' => '.php'), 'title' => array('title' => $this->l('Title'), 'width' => 120), 'url_rewrite' => array('title' => $this->l('Friendly URL'), 'width' => 120) ); global $cookie; $this->optionTitle = $this->l('URLs Setup'); $this->_fieldsOptions = array( '__PS_BASE_URI__' => array('title' => $this->l('PS directory'), 'desc' => $this->l('Name of the PrestaShop directory on your Web server, bracketed by forward slashes (e.g., /shop/)'), 'validation' => 'isUrl', 'type' => 'text', 'size' => 20, 'default' => __PS_BASE_URI__), 'PS_HOMEPAGE_PHP_SELF' => array('title' => $this->l('Homepage file'), 'desc' => $this->l('Usually "index.php", but may be different for a few hosts.'), 'type' => 'string', 'size' => 50), 'PS_SHOP_DOMAIN' => array('title' => $this->l('Shop domain name'), 'desc' => $this->l('Domain name of your shop, used as a canonical URL (e.g., www.myshop.com). Keep it blank if you don\'t know what to do.'), 'validation' => 'isUrlOrEmpty', 'type' => 'text', 'size' => 30, 'default' => ''), 'PS_SHOP_DOMAIN_SSL' => array('title' => $this->l('Shop domain name for SSL'), 'desc' => $this->l('Domain name for the secured area of your shop, used as a canonical URL (e.g., secure.myshop.com). Keep it blank if you don\'t know what to do.'), 'validation' => 'isUrlOrEmpty', 'type' => 'text', 'size' => 30, 'default' => ''), 'PS_REWRITING_SETTINGS' => array('title' => $this->l('Friendly URL'), 'desc' => $this->l('Enable only if your server allows URL rewriting (recommended)').'

'.$this->l('If you turn on this feature, you must').' '.$this->l('generate a .htaccess file').'

', 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CANONICAL_REDIRECT' => array('title' => $this->l('Automatically redirect to Canonical url'), 'desc' => $this->l('Recommended but your theme must be compliant'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), ); if (!Tools::getValue('__PS_BASE_URI__')) $_POST['__PS_BASE_URI__'] = __PS_BASE_URI__; parent::__construct(); } public function display() { $this->warnDomainName(); parent::display(); } public function displayForm($isMainTab = true) { global $currentIndex; parent::displayForm(); if (!($meta = $this->loadObject(true))) return; $files = Meta::getPages(true, ($meta->page ? $meta->page : false)); echo '
'.($meta->id ? '' : '').'
'.$this->l('Meta-Tags').'
'; if (!sizeof($files)) echo '

'.$this->l('There is no page available!').'

'; else { echo ' *

'.$this->l('Name of the related page').'

'; } echo '
'; foreach ($this->_languages as $language) echo '
'.$this->l('Invalid characters:').' <>;=#{} 

'.$this->l('Title of this page').'

'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'title¤description¤keywords¤url_rewrite', 'title'); echo '
 
'; foreach ($this->_languages as $language) echo '
'.$this->l('Invalid characters:').' <>;=#{} 

'.$this->l('A short description').'

'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'title¤description¤keywords¤url_rewrite', 'description'); echo '
 
'; foreach ($this->_languages as $language) echo '
'.$this->l('Invalid characters:').' <>;=#{} 

'.$this->l('List of keywords').'

'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'title¤description¤keywords¤url_rewrite', 'keywords'); echo '
 
'; foreach ($this->_languages as $language) echo '
'.$this->l('Invalid characters:').' <>;=#{} 

'.$this->l('Example : "contacts" for http://mysite.com/shop/contacts to redirect to http://mysite.com/shop/contact-form.php').'

'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'title¤description¤keywords¤url_rewrite', 'url_rewrite'); echo '
 
* '.$this->l('Required field').'
'; } public function postProcess() { if (Tools::isSubmit('submitAddmeta')) { $langs = Language::getLanguages(true); $default_language = Configuration::get('PS_LANG_DEFAULT'); if (Tools::getValue('page') != 'index') { $defaultLangIsValidated = Validate::isLinkRewrite(Tools::getValue('url_rewrite_'.$default_language)); $englishLangIsValidated = Validate::isLinkRewrite(Tools::getValue('url_rewrite_1')); } else { // index.php can have empty rewrite rule $defaultLangIsValidated = !Tools::getValue('url_rewrite_'.$default_language) OR Validate::isLinkRewrite(Tools::getValue('url_rewrite_'.$default_language)); $englishLangIsValidated = !Tools::getValue('url_rewrite_1') OR Validate::isLinkRewrite(Tools::getValue('url_rewrite_1')); } if (!$defaultLangIsValidated AND !$englishLangIsValidated) { $this->_errors[] = Tools::displayError('Url rewrite field must be filled at least in default or english language.'); return false; } foreach ($langs as $lang) { $current = Tools::getValue('url_rewrite_'.$lang['id_lang']); if (strlen($current) == 0) // Prioritize default language first if ($defaultLangIsValidated) $_POST['url_rewrite_'.$lang['id_lang']] = Tools::getValue('url_rewrite_'.$default_language); else $_POST['url_rewrite_'.$lang['id_lang']] = Tools::getValue('url_rewrite_1'); } } if (Tools::isSubmit('submitOptions'.$this->table)) { $baseUrls = array(); if ($__PS_BASE_URI__ = Tools::getValue('__PS_BASE_URI__')) $baseUrls['__PS_BASE_URI__'] = $__PS_BASE_URI__; rewriteSettingsFile($baseUrls, NULL, NULL); unset($this->_fieldsGeneral['__PS_BASE_URI__']); } if (Tools::isSubmit('submitOptions'.$this->table) OR Tools::isSubmit('submitAddmeta')) Module::hookExec('afterSaveAdminMeta'); return parent::postProcess(); } }