// Routes for dispatcher (part 5)

This commit is contained in:
rMalie
2011-08-03 07:53:59 +00:00
parent 2644d41f7d
commit a1a33de41b
5 changed files with 118 additions and 21 deletions
+14 -13
View File
@@ -34,23 +34,24 @@ class AdminEmails extends AdminPreferences
$this->className = 'Configuration';
$this->table = 'configuration';
parent::__construct();
foreach (Contact::getContacts($this->context->language->id) AS $contact)
$arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']);
$this->_fieldsEmail = array(
'PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to:'), 'desc' => $this->l('When customers send message from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr),
'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Use PHP mail() function. Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#SMTP_CONTAINER\').slideUp();"', 2 => 'onclick="$(\'#SMTP_CONTAINER\').slideDown();"'), 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Send e-mail as HTML'), 2 => $this->l('Send e-mail as Text'), 3 => $this->l('Both'))),
'SMTP_CONTAINER' => array('title' => '', 'type' => 'container'),
'PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain:'), 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'), 'validation' => 'isUrl', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Number of port to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL),
'SMTP_CONTAINER_END' => array('title' => '', 'type' => 'container_end', 'content' => '<script type="text/javascript">if (getE("PS_MAIL_METHOD2_on").checked == false) { $(\'#SMTP_CONTAINER\').hide(); }</script>'));
parent::__construct();
'PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to:'), 'desc' => $this->l('When customers send message from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr),
'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Use PHP mail() function. Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#SMTP_CONTAINER\').slideUp();"', 2 => 'onclick="$(\'#SMTP_CONTAINER\').slideDown();"'), 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'required' => true, 'type' => 'radio', 'choices' => array(1 => $this->l('Send e-mail as HTML'), 2 => $this->l('Send e-mail as Text'), 3 => $this->l('Both'))),
'SMTP_CONTAINER' => array('title' => '', 'type' => 'container'),
'PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain:'), 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'), 'validation' => 'isUrl', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Number of port to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL),
'SMTP_CONTAINER_END' => array('title' => '', 'type' => 'container_end', 'content' => '<script type="text/javascript">if (getE("PS_MAIL_METHOD2_on").checked == false) { $(\'#SMTP_CONTAINER\').hide(); }</script>'),
);
}
public function postProcess()
+74 -4
View File
@@ -50,8 +50,20 @@ class AdminMeta extends AdminTab
'PS_REWRITING_SETTINGS' => array('title' => $this->l('Friendly URL'), 'desc' => $this->l('Enable only if your server allows URL rewriting (recommended)').'<p class="hint clear" style="display: block;">'.$this->l('If you turn on this feature, you must').' <a href="?tab=AdminGenerator&token='.Tools::getAdminToken('AdminGenerator'.(int)(Tab::getIdFromClassName('AdminGenerator')).(int)$this->context->employee->id).'">'.$this->l('generate a .htaccess file').'</a></p><div class="clear"></div>', '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__;
// Display route options only if friendly URL is activated
if (Configuration::get('PS_REWRITING_SETTINGS'))
{
$this->_fieldsOptions += array(
'PS_ROUTE_product_rule' => array('title' => $this->l('Route to products'), 'desc' => $this->l('Select URL pattern if friendly url is activated'), 'validation' => 'isString', 'type' => 'text', 'size' => 50, 'defaultValue' => Dispatcher::getInstance()->defaultRoutes['product_rule']['rule']),
'PS_ROUTE_product_rule2' => array('title' => $this->l('Route to products with category'), 'desc' => $this->l('Select URL pattern if friendly url is activated'), 'validation' => 'isString', 'type' => 'text', 'size' => 50, 'defaultValue' => Dispatcher::getInstance()->defaultRoutes['product_rule2']['rule']),
'PS_ROUTE_category_rule' => array('title' => $this->l('Route to category'), 'desc' => $this->l('Select URL pattern if friendly url is activated'), 'validation' => 'isString', 'type' => 'text', 'size' => 50, 'defaultValue' => Dispatcher::getInstance()->defaultRoutes['category_rule']['rule']),
'PS_ROUTE_supplier_rule' => array('title' => $this->l('Route to supplier'), 'desc' => $this->l('Select URL pattern if friendly url is activated'), 'validation' => 'isString', 'type' => 'text', 'size' => 50, 'defaultValue' => Dispatcher::getInstance()->defaultRoutes['supplier_rule']['rule']),
'PS_ROUTE_manufacturer_rule' => array('title' => $this->l('Route to manufacturer'), 'desc' => $this->l('Select URL pattern if friendly url is activated'), 'validation' => 'isString', 'type' => 'text', 'size' => 50, 'defaultValue' => Dispatcher::getInstance()->defaultRoutes['manufacturer_rule']['rule']),
'PS_ROUTE_cms_rule' => array('title' => $this->l('Route to CMS page'), 'desc' => $this->l('Select URL pattern if friendly url is activated'), 'validation' => 'isString', 'type' => 'text', 'size' => 50, 'defaultValue' => Dispatcher::getInstance()->defaultRoutes['cms_rule']['rule']),
'PS_ROUTE_cms_category_rule' => array('title' => $this->l('Route to CMS category'), 'desc' => $this->l('Select URL pattern if friendly url is activated'), 'validation' => 'isString', 'type' => 'text', 'size' => 50, 'defaultValue' => Dispatcher::getInstance()->defaultRoutes['cms_category_rule']['rule']),
);
}
}
public function display()
@@ -189,6 +201,64 @@ class AdminMeta extends AdminTab
{
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID());
}
/**
* Validate route syntax and save it in configuration
*
* @param string $routeID
*/
public function checkAndUpdateRoute($routeID)
{
$defaultRoutes = Dispatcher::getInstance()->defaultRoutes;
if (!isset($defaultRoutes[$routeID]))
return ;
$rule = Tools::getValue('PS_ROUTE_'.$routeID);
if (!$rule || $rule == $defaultRoutes[$routeID]['rule'])
return ;
$errors = array();
if (!Dispatcher::getInstance()->validateRoute($routeID, $rule, $errors))
{
foreach ($errors as $error)
$this->_errors[] = sprintf('Keyword "%1$s" required for route "%2$s" (rule: "%3$s")', $error, $routeID, htmlspecialchars($rule));
}
else
Configuration::updateValue('PS_ROUTE_'.$routeID, $rule);
}
public function updateOptionPsDispatcherRouteProductRule()
{
$this->checkAndUpdateRoute('product_rule');
}
public function updateOptionPsDispatcherRouteProductRule2()
{
$this->checkAndUpdateRoute('product_rule2');
}
public function updateOptionPsDispatcherRouteCategoryRule()
{
$this->checkAndUpdateRoute('category_rule');
}
public function updateOptionPsDispatcherRouteSupplierRule()
{
$this->checkAndUpdateRoute('supplier_rule');
}
public function updateOptionPsDispatcherRouteManufacturerRule()
{
$this->checkAndUpdateRoute('manufacturer_rule');
}
public function updateOptionPsDispatcherRouteCmsRule()
{
$this->checkAndUpdateRoute('cms_rule');
}
public function updateOptionPsDispatcherRouteCmsCategoryRule()
{
$this->checkAndUpdateRoute('cms_category_rule');
}
}