/usr/share/php/smarty3/plugins/function.validate.php is in smarty-validate 3.0.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | <?php
/**
* 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->getTemplateVars('validate_init');
if(isset($_init_params)) {
$params = array_merge($_init_params, $params);
}
static $_halt = array();
static $_is_init = null;
static $_form = null;
static $_local_is_init = null;
$_form = SmartyValidate::$form;
if(isset($params['form']))
{
if($params['form'] != $_form)
$_is_init = null;
$_form = $params['form'];
}
$_sess =& $_SESSION['SmartyValidate'][$_form];
if(!isset($_is_init)) {
$_is_init = $_sess['is_init'];
}
if(!isset($_local_is_init))
{
$_local_is_init = $_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')) {
trigger_error("validate: missing SmartyValidate class");
return;
}
if (!isset($_SESSION['SmartyValidate'])) {
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) {
trigger_error("validate: validator id '" . $params['id'] . "' is not registered.");
return;
}
} else {
if (strlen($params['field']) == 0) {
trigger_error("validate: missing 'field' parameter");
return;
}
if (strlen($params['criteria']) == 0) {
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($_local_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(!$_local_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'])) {
$smarty->append($params['append'], $_sess['validators'][$_validator_key]['message']);
} 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;
}
?>
|