/** * Validate the form * * @param array $dirty reference to unverified $_POST * @param object smarty template * @param string $form the name of the form being validated * @return bool */ static function formValidate(&$dirty, $tpl, $form = null) { if (!isset($form)) { $form = self::$form; } if (!empty($dirty) && SmartyValidate::is_registered_form($form)) { // Check token if (!empty($dirty['token'])) { if (!in_array($dirty['token'], $_SESSION['_sux0r_tokens'])) { return false; } } unset($dirty['token']); // Validate self::connect($tpl); if (self::is_valid($dirty, $form)) { SmartyValidate::disconnect(true); return true; } } return false; }
/********************************** INITIALIZATION METHODS *********************************/ require '../bootstrap.php'; Pommo::init(); $logger =& Pommo::$_logger; $dbo =& Pommo::$_dbo; /********************************** SETUP TEMPLATE, PAGE *********************************/ require_once Pommo::$_baseDir . 'classes/Pommo_Template.php'; $smarty = new Pommo_Template(); $smarty->prepareForForm(); $exchanger = current(Pommo_Api::configGet(array('list_exchanger'))); SmartyValidate::connect($smarty); if (!SmartyValidate::is_registered_form('exchanger') || empty($_POST)) { // ___ USER HAS NOT SENT FORM ___ SmartyValidate::register_form('exchanger', true); SmartyValidate::register_validator('email', 'email', 'isEmail', false, false, false, 'exchanger'); $vMsg = array(); $vMsg['email'] = Pommo::_T('Invalid email address'); $smarty->assign('vMsg', $vMsg); $dbvals = array('exchanger' => $exchanger, 'email' => Pommo::$_config['admin_email']); $smarty->assign($dbvals); } else { // ___ USER HAS SENT FORM ___ /********************************** JSON OUTPUT INITIALIZATION *********************************/ require_once Pommo::$_baseDir . 'classes/Pommo_Json.php'; $json = new Pommo_Json();
Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $smarty->prepareForForm(); // Check to make sure poMMo is not already installed. if (PommoInstall::verify()) { $logger->addErr(Pommo::_T('poMMo is already installed.')); $smarty->assign('installed', TRUE); $smarty->display('install.tpl'); Pommo::kill(); } if (isset($_REQUEST['disableDebug'])) { unset($_REQUEST['debugInstall']); } elseif (isset($_REQUEST['debugInstall'])) { $smarty->assign('debug', TRUE); } if (!SmartyValidate::is_registered_form() || empty($_POST)) { // ___ USER HAS NOT SENT FORM ___ SmartyValidate::connect($smarty, true); SmartyValidate::register_validator('list_name', 'list_name', 'notEmpty', false, false, 'trim'); SmartyValidate::register_validator('site_name', 'site_name', 'notEmpty', false, false, 'trim'); SmartyValidate::register_validator('site_url', 'site_url', 'isURL'); SmartyValidate::register_validator('admin_password', 'admin_password', 'notEmpty', false, false, 'trim'); SmartyValidate::register_validator('admin_password2', 'admin_password:admin_password2', 'isEqual'); SmartyValidate::register_validator('admin_email', 'admin_email', 'isEmail'); $formError = array(); $formError['list_name'] = $formError['site_name'] = $formError['admin_password'] = Pommo::_T('Cannot be empty.'); $formError['admin_password2'] = Pommo::_T('Passwords must match.'); $formError['site_url'] = Pommo::_T('Must be a valid URL'); $formError['admin_email'] = Pommo::_T('Must be a valid email'); $smarty->assign('formError', $formError); } else {
/** * register a callable function for form verification * * @param string $func_name the function being registered */ function _register_function($type, $name, $func_name, $form = SMARTY_VALIDATE_DEFAULT_FORM) { if(!SmartyValidate::is_registered_form($form)) { trigger_error("SmartyValidate: [register_$type] form '$form' is not registered."); return false; } if(strpos($func_name,'->') !== false) { // object method preg_match('!(\w+)->(\w+)!', $func_name, $_match); $_object_name = $_match[1]; $_method_name = $_match[2]; $_object =& SmartyValidate::_object_instance($_object_name, $_dummy); if(!method_exists($_object, $_method_name)) { trigger_error("SmartyValidate: [register_$type] method '$_method_name' is not valid for object '$_object_name'."); return false; } } elseif (strpos($func_name,'::') !== false) { // static method preg_match('!(\w+)::(\w+)!', $func_name, $_match); if(!is_callable(array($_match[1], $_match[2]))) { trigger_error("SmartyValidate: [register_$type] static method '$func_name' does not exist."); return false; } } elseif(!function_exists($func_name)) { trigger_error("SmartyValidate: [register_$type] function '$func_name' does not exist."); return false; } $_SESSION['SmartyValidate'][$form]['registered_funcs'][$type][$name] = $func_name; return true; }
$json->serve(); } // ADD CUSTOM VALIDATOR FOR CHARSET function check_notifyMails($value, $empty, &$params, &$formvars) { $mails = PommoHelper::trimArray(explode(',', $value)); $ret = true; foreach ($mails as $mail) { if (!empty($mail) && !PommoHelper::isEmail($mail)) { $ret = false; } } return $ret; } SmartyValidate::connect($smarty); if (!SmartyValidate::is_registered_form('messages') || empty($_POST)) { // ___ USER HAS NOT SENT FORM ___ SmartyValidate::register_form('messages', true); // register custom criteria SmartyValidate::register_criteria('isMails', 'check_notifyMails', 'messages'); SmartyValidate::register_validator('subscribe_sub', 'subscribe_sub', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('subscribe_msg', 'subscribe_msg', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('subscribe_web', 'subscribe_web', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('unsubscribe_sub', 'unsubscribe_sub', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('unsubscribe_msg', 'unsubscribe_msg', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('unsubscribe_web', 'unsubscribe_web', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('confirm_sub', 'confirm_sub', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('confirm_msg', 'confirm_msg:!\\[\\[URL\\]\\]!i', 'isRegExp', false, false, 'trim', 'messages'); SmartyValidate::register_validator('activate_sub', 'activate_sub', 'notEmpty', false, false, 'trim', 'messages'); SmartyValidate::register_validator('activate_msg', 'activate_msg:!\\[\\[URL\\]\\]!i', 'isRegExp', false, false, 'trim', 'messages'); SmartyValidate::register_validator('update_sub', 'update_sub', 'notEmpty', false, false, 'trim', 'messages');
/** * Project: SmartyValidate: Form Validator for the Smarty Template Engine * File: SmartyValidate.class.php * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @link http://www.phpinsider.com/php/code/SmartyValidate/ * @copyright 2001-2004 ispi of Lincoln, Inc. * @author Monte Ohrt <*****@*****.**> * @package SmartyValidate * @version 2.1-dev */ function smarty_function_validate($params, &$smarty) { static $_halt = array(); $_form = isset($params['form']) ? $params['form'] : 'default'; if (!SmartyValidate::is_registered_form($_form)) { trigger_error("SmartyValidate: [validate plugin] form '{$_form}' is not registered."); return false; } if (isset($_halt[$_form]) && $_halt[$_form]) { return; } if (!class_exists('SmartyValidate')) { $smarty->trigger_error("validate: missing SmartyValidate class"); return; } if (!isset($_SESSION['SmartyValidate'])) { $smarty->trigger_error("validate: SmartyValidate is not initialized, use connect() first"); return; } if (strlen($params['field']) == 0) { $smarty->trigger_error("validate: missing 'field' parameter"); return; } if (strlen($params['criteria']) == 0) { $smarty->trigger_error("validate: missing 'criteria' parameter"); return; } if (isset($params['trim'])) { $params['trim'] = SmartyValidate::_booleanize($params['trim']); } else { $params['trim'] = false; } if (isset($params['empty'])) { $params['empty'] = SmartyValidate::_booleanize($params['empty']); } else { $params['empty'] = false; } if (isset($params['halt'])) { $params['halt'] = SmartyValidate::_booleanize($params['halt']); } else { $params['halt'] = false; } if (strlen($params['criteria']) == 0) { $smarty->trigger_error("validate: parameter 'criteria' missing."); return; } $_sess =& $_SESSION['SmartyValidate'][$_form]['validators']; $_found = false; if (isset($_sess) && is_array($_sess)) { foreach ($_sess as $_key => $_field) { if ($_field['field'] == $params['field'] && $_field['criteria'] == $params['criteria']) { // field exists $_found = true; if (isset($_sess[$_key]['valid']) && !$_sess[$_key]['valid']) { // not valid, show error and reset $_halt[$_form] = $params['halt']; $_echo = true; if (!isset($params['assign']) && !isset($params['append'])) { // no assign or append, so echo message echo $_sess[$_key]['message']; } $_sess[$_key]['valid'] = null; break; } } } } if (!$_found) { // create $_sess[] = $params; } }
/** * Project: SmartyValidate: Form Validator for the Smarty Template Engine * File: function.validate.php * Author: Monte Ohrt <monte at newdigitalgroup dot com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @link http://www.phpinsider.com/php/code/SmartyValidate/ * @copyright 2001-2005 New Digital Group, Inc. * @author Monte Ohrt <monte at newdigitalgroup dot com> * @package SmartyValidate */ function smarty_function_validate($params, &$smarty) { $_init_params = $smarty->get_template_vars('validate_init'); if (isset($_init_params)) { $params = array_merge($_init_params, $params); } static $_halt = array(); static $_is_init = null; $_form = isset($params['form']) ? $params['form'] : 'default'; $_sess =& $_SESSION['SmartyValidate'][$_form]; if (!isset($_is_init)) { $_is_init = $_sess['is_init']; } if (!SmartyValidate::is_registered_form($_form)) { trigger_error("SmartyValidate: [validate plugin] form '{$_form}' is not registered."); return false; } if (isset($_halt[$_form]) && $_halt[$_form]) { return; } if (!class_exists('SmartyValidate')) { $smarty->trigger_error("validate: missing SmartyValidate class"); return; } if (!isset($_SESSION['SmartyValidate'])) { $smarty->trigger_error("validate: SmartyValidate is not initialized, use connect() first"); return; } if (isset($params['id'])) { if (($_validator_key = SmartyValidate::is_registered_validator($params['id'], $_form)) === false) { $smarty->trigger_error("validate: validator id '" . $params['id'] . "' is not registered."); return; } } else { if (strlen($params['field']) == 0) { $smarty->trigger_error("validate: missing 'field' parameter"); return; } if (strlen($params['criteria']) == 0) { $smarty->trigger_error("validate: missing 'criteria' parameter"); return; } } if (isset($params['trim'])) { $params['trim'] = SmartyValidate::_booleanize($params['trim']); } if (isset($params['empty'])) { $params['empty'] = SmartyValidate::_booleanize($params['empty']); } if (isset($params['halt'])) { $params['halt'] = SmartyValidate::_booleanize($params['halt']); } if (isset($_sess['validators']) && is_array($_sess['validators'])) { if (isset($params['id'])) { if ($_is_init) { $_sess['validators'][$_validator_key]['message'] = $params['message']; } } else { foreach ($_sess['validators'] as $_key => $_field) { if ($_field['field'] == $params['field'] && $_field['criteria'] == $params['criteria']) { // field exists $_validator_key = $_key; break; } } } if (!$_is_init) { if (!$_sess['is_error']) { // no validation error return; } if (!isset($_sess['validators'][$_validator_key]['valid']) || !$_sess['validators'][$_validator_key]['valid']) { // not valid, show error and reset $_halt[$_form] = isset($_sess['validators'][$_validator_key]['halt']) ? $_sess['validators'][$_validator_key]['halt'] : false; $_echo = true; if (isset($params['assign'])) { $smarty->assign($params['assign'], $_sess['validators'][$_validator_key]['message']); } elseif (isset($params['append'])) { // bb $smarty->append($params['append'], $_sess['validators'][$_validator_key]['message']); $smarty->append($params['append'], array($_sess['validators'][$_validator_key]['field'] => $_sess['validators'][$_validator_key]['message']), true); } else { // no assign or append, so echo message echo $_sess['validators'][$_validator_key]['message']; } } } else { if (isset($params['id'])) { $_sess['validators'][$_validator_key] = array_merge($_sess['validators'][$_validator_key], $params); } else { $_params = $params; $_params['valid'] = false; $_sess['validators'][] = $_params; } } } $_sess['is_init'] = false; }
$logger =& $pommo->_logger; $dbo =& $pommo->_dbo; /********************************** SETUP TEMPLATE, PAGE *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $smarty->prepareForForm(); // ADD CUSTOM VALIDATOR FOR CHARSET function check_charset($value, $empty, &$params, &$formvars) { $validCharsets = array('UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-7', 'ISO-8859-15', 'cp1251', 'KOI8-R', 'GB2312', 'EUC-JP', 'ISO-2022-JP'); return in_array($value, $validCharsets); } SmartyValidate::connect($smarty); if (!SmartyValidate::is_registered_form('mailings') || empty($_POST)) { // ___ USER HAS NOT SENT FORM ___ SmartyValidate::register_form('mailings', true); // register custom criteria SmartyValidate::register_criteria('isCharSet', 'check_charset', 'mailings'); SmartyValidate::register_validator('list_fromname', 'list_fromname', 'notEmpty', false, false, 'trim', 'mailings'); SmartyValidate::register_validator('list_fromemail', 'list_fromemail', 'isEmail', false, false, false, 'mailings'); SmartyValidate::register_validator('list_frombounce', 'list_frombounce', 'isEmail', false, false, false, 'mailings'); SmartyValidate::register_validator('list_charset', 'list_charset', 'isCharSet', false, false, 'trim', 'mailings'); SmartyValidate::register_validator('public_history', 'public_history:!^(on|off)$!', 'isRegExp', false, false, false, 'mailings'); SmartyValidate::register_validator('demo_mode', 'demo_mode:!^(on|off)$!', 'isRegExp', false, false, false, 'mailings'); SmartyValidate::register_validator('list_fromname', 'list_fromname', 'notEmpty', false, false, 'trim', 'mailings'); SmartyValidate::register_validator('maxRuntime', 'maxRuntime', 'isInt', false, false, 'trim', 'mailings'); $vMsg = array(); $vMsg['maxRuntime'] = Pommo::_T('Enter a number.'); $vMsg['list_fromname'] = Pommo::_T('Cannot be empty.');
/** * register a callable function for form verification * * @param string $func_name the function being registered */ static function _register_function($type, $name, $func_name, $form = null) { if (!isset($form)) { $form = self::$form; } if (!SmartyValidate::is_registered_form($form)) { trigger_error("SmartyValidate: [register_{$type}] form '{$form}' is not registered."); return false; } if (strpos($func_name, '->') !== false) { // object method preg_match('!(\\w+)->(\\w+)!', $func_name, $_match); $_object_name = $_match[1]; $_method_name = $_match[2]; $_object =& SmartyValidate::_object_instance($_object_name, $_dummy); if (!method_exists($_object, $_method_name)) { trigger_error("SmartyValidate: [register_{$type}] method '{$_method_name}' is not valid for object '{$_object_name}'."); return false; } } elseif (strpos($func_name, '::') !== false) { // static method preg_match('!(\\w+)::(\\w+)!', $func_name, $_match); if (!is_callable(array($_match[1], $_match[2]))) { trigger_error("SmartyValidate: [register_{$type}] static method '{$func_name}' does not exist."); return false; } } elseif (!function_exists($func_name)) { trigger_error("SmartyValidate: [register_{$type}] function '{$func_name}' does not exist."); return false; } $_SESSION['SmartyValidate'][$form]['registered_funcs'][$type][$name] = $func_name; return true; }