update
This commit is contained in:
154
core/lib/SmartyValidate/plugins/function.validate.php
Normal file
154
core/lib/SmartyValidate/plugins/function.validate.php
Normal file
@@ -0,0 +1,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;
|
||||
}
|
||||
|
||||
?>
|
||||
39
core/lib/SmartyValidate/plugins/function.validate_init.php
Normal file
39
core/lib/SmartyValidate/plugins/function.validate_init.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: function.validate_init.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* initialize validate parameters
|
||||
*
|
||||
* @param array $params the parameters passed to initialize
|
||||
* @param object $smarty the smarty object
|
||||
*/
|
||||
|
||||
function smarty_function_validate_init($params, &$smarty) {
|
||||
$smarty->assign('validate_init', $params);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.dummyValid.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* always return valid
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_dummyValid($value, $empty, &$params, &$formvars) {
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isCCExpDate.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid credit card expiration date
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isCCExpDate($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
if(!preg_match('!^(\d+)\D+(\d+)$!', $value, $_match))
|
||||
return false;
|
||||
|
||||
$_month = $_match[1];
|
||||
$_year = $_match[2];
|
||||
|
||||
if(strlen($_year) == 2)
|
||||
$_year = substr(date('Y', time()),0,2) . $_year;
|
||||
|
||||
$_month = (int) $_month;
|
||||
$_year = (int) $_year;
|
||||
|
||||
if($_month < 1 || $_month > 12)
|
||||
return false;
|
||||
if(date('Y',time()) > $_year)
|
||||
return false;
|
||||
|
||||
if(date('Y',time()) == $_year && date('m', time()) > $_month)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
70
core/lib/SmartyValidate/plugins/validatecriteria.isccnum.php
Normal file
70
core/lib/SmartyValidate/plugins/validatecriteria.isccnum.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isCCNum.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid credit card checksum
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isCCNum($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
// strip everything but digits
|
||||
$value = preg_replace('!\D+!', '', $value);
|
||||
|
||||
if (empty($value))
|
||||
return false;
|
||||
|
||||
$_c_digits = preg_split('//', $value, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$_max_digit = count($_c_digits)-1;
|
||||
$_even_odd = $_max_digit % 2;
|
||||
|
||||
$_sum = 0;
|
||||
for ($_count=0; $_count <= $_max_digit; $_count++) {
|
||||
$_digit = $_c_digits[$_count];
|
||||
if ($_even_odd) {
|
||||
$_digit = $_digit * 2;
|
||||
if ($_digit > 9) {
|
||||
$_digit = substr($_digit, 1, 1) + 1;
|
||||
}
|
||||
}
|
||||
$_even_odd = 1 - $_even_odd;
|
||||
$_sum += $_digit;
|
||||
}
|
||||
$_sum = $_sum % 10;
|
||||
if($_sum)
|
||||
return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
44
core/lib/SmartyValidate/plugins/validatecriteria.isdate.php
Normal file
44
core/lib/SmartyValidate/plugins/validatecriteria.isdate.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isDate.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid date (parsable by strtotime)
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isDate($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
$_ret = strtotime($value);
|
||||
return $_ret != -1 && $_ret !== false;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isDateAfter.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a date is later than another
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isDateAfter($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
if(!isset($params['field2'])) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$_date1 = strtotime($value);
|
||||
$_date2 = strtotime($formvars[$params['field2']]);
|
||||
|
||||
if($_date1 == -1 || !$_date1) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
if($_date2 == -1 || !$_date2) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $_date1 > $_date2;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isDateBefore.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a date is earlier than another
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isDateBefore($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
if(!isset($params['field2'])) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$_date1 = strtotime($value);
|
||||
$_date2 = strtotime($formvars[$params['field2']]);
|
||||
|
||||
if($_date1 == -1 || !$_date1) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
if($_date2 == -1 || !$_date2) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $_date1 < $_date2;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isDateEqual.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if two dates are equal
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isDateEqual($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
if(!isset($params['field2'])) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$_date1 = strtotime($value);
|
||||
$_date2 = strtotime($formvars[$params['field2']]);
|
||||
|
||||
if($_date1 == -1 || !$_date1) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
if($_date2 == -1 || !$_date2) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $_date1 == $_date2;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isDateOnOrAfter.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a date is equal or later than another
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isDateOnOrAfter($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
if(!isset($params['field2'])) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$_date1 = strtotime($value);
|
||||
$_date2 = strtotime($formvars[$params['field2']]);
|
||||
|
||||
if($_date1 == -1 || !$_date1) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
if($_date2 == -1 || !$_date2) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $_date1 >= $_date2;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isDateOnOrBefore.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a date is equal or earlier than another
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isDateOnOrBefore($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
if(!isset($params['field2'])) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$_date1 = strtotime($value);
|
||||
$_date2 = strtotime($formvars[$params['field2']]);
|
||||
|
||||
if($_date1 == -1 || !$_date1) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
if($_date2 == -1 || !$_date2) {
|
||||
trigger_error("SmartyValidate: [isDateAfter] parameter 'field2' is not a valid date.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $_date1 <= $_date2;
|
||||
}
|
||||
|
||||
?>
|
||||
55
core/lib/SmartyValidate/plugins/validatecriteria.isemail.php
Normal file
55
core/lib/SmartyValidate/plugins/validatecriteria.isemail.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isEmail.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid e-mail address
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
|
||||
function smarty_validate_criteria_isEmail($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
// in case value is several addresses separated by newlines
|
||||
$_addresses = preg_split('![\n\r]+!', $value);
|
||||
|
||||
foreach($_addresses as $_address) {
|
||||
$_is_valid = !(preg_match('!@.*@|\.\.|\,|\;!', $_address) ||
|
||||
!preg_match('!^.+\@(\[?)[a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$!', $_address));
|
||||
|
||||
if(!$_is_valid)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
53
core/lib/SmartyValidate/plugins/validatecriteria.isequal.php
Normal file
53
core/lib/SmartyValidate/plugins/validatecriteria.isequal.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isEqual.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid range
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isEqual($value, $empty, &$params, &$formvars) {
|
||||
if(!isset($params['field2'])) {
|
||||
trigger_error("SmartyValidate: [isEqual] parameter 'field2' is missing.");
|
||||
return false;
|
||||
}
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
if(strpos($params['field2'],'[') !== false && strpos($params['field2'],']') !== false) {
|
||||
// pull apart array value
|
||||
preg_match('!(\w+)\[(\w*)\]!',$params['field2'],$_match);
|
||||
return $value == $formvars[$_match[1]][$_match[2]];
|
||||
} else {
|
||||
return $value == $formvars[$params['field2']];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isFileSize.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid file size.
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isFileSize($value, $empty, &$params, &$formvars) {
|
||||
|
||||
$_field = $params['field'];
|
||||
$_max = isset($params['field2']) ? $params['field2'] : trim($params['max']);
|
||||
|
||||
|
||||
if(!isset($_FILES[$_field]))
|
||||
// nothing in the form
|
||||
return false;
|
||||
|
||||
if($_FILES[$_field]['error'] == 4)
|
||||
// no file uploaded
|
||||
return $empty;
|
||||
|
||||
if(!isset($_max)) {
|
||||
trigger_error("SmartyValidate: [isFileSize] 'max' attribute is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!preg_match('!^(\d+)([bkmg](b)?)?$!i', $_max, $_match)) {
|
||||
trigger_error("SmartyValidate: [isFileSize] 'max' attribute is invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
$_size = $_match[1];
|
||||
$_type = strtolower($_match[2]);
|
||||
|
||||
switch($_type) {
|
||||
case 'k':
|
||||
$_maxsize = $_size * 1024;
|
||||
break;
|
||||
case 'm':
|
||||
$_maxsize = $_size * 1024 * 1024;
|
||||
break;
|
||||
case 'g':
|
||||
$_maxsize = $_size * 1024 * 1024 * 1024;
|
||||
break;
|
||||
case 'b':
|
||||
default:
|
||||
$_maxsize = $_size;
|
||||
break;
|
||||
}
|
||||
|
||||
return $_FILES[$_field]['size'] <= $_maxsize;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isFileType.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid file type. This only checks the
|
||||
* file extention, it does not test the actual file type.
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isFileType($value, $empty, &$params, &$formvars) {
|
||||
|
||||
$_field = $params['field'];
|
||||
$_type = isset($params['field2']) ? $params['field2'] : $params['type'];
|
||||
|
||||
if(!isset($_FILES[$_field]))
|
||||
// nothing in the form
|
||||
return false;
|
||||
|
||||
if($_FILES[$_field]['error'] == 4)
|
||||
// no file uploaded
|
||||
return $empty;
|
||||
|
||||
if(!preg_match('!\.(\w+)$!i', $_FILES[$_field]['name'], $_match))
|
||||
// not valid filename
|
||||
return false;
|
||||
|
||||
$_file_ext = $_match[1];
|
||||
$_types = preg_split('![\s,]+!', $_type, -1, PREG_SPLIT_NO_EMPTY);
|
||||
foreach($_types as $_key => $_val) {
|
||||
$_types[$_key] = strtolower($_types[$_key]);
|
||||
}
|
||||
|
||||
if(!in_array(strtolower($_file_ext),$_types))
|
||||
// not valid file extention
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
43
core/lib/SmartyValidate/plugins/validatecriteria.isfloat.php
Normal file
43
core/lib/SmartyValidate/plugins/validatecriteria.isfloat.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isFloat.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a float
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isFloat($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
return preg_match('!^\-?\d+\.\d+?$!', $value);
|
||||
}
|
||||
|
||||
?>
|
||||
43
core/lib/SmartyValidate/plugins/validatecriteria.isint.php
Normal file
43
core/lib/SmartyValidate/plugins/validatecriteria.isint.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isInt.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is an integer
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isInt($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
return preg_match('!^-?\d+$!', $value);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isLength.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid range
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isLength($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(isset($params['field2'])) {
|
||||
$_min = $params['field2'];
|
||||
} elseif(isset($params['min'])) {
|
||||
$_min = $params['min'];
|
||||
} else {
|
||||
$_min = -1;
|
||||
}
|
||||
|
||||
if(isset($params['field3'])) {
|
||||
$_max = $params['field3'];
|
||||
} elseif(isset($params['max'])) {
|
||||
$_max = $params['max'];
|
||||
} else {
|
||||
$_max = -1;
|
||||
}
|
||||
|
||||
$_length = strlen($value);
|
||||
|
||||
if(($_min == -1 || $_length >= $_min) && ($_max == -1 || $_length <= $_max))
|
||||
return true;
|
||||
elseif($_length == 0)
|
||||
return $empty;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isNumber.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid number (int of float)
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isNumber($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
return preg_match('!^\-?\d+(\.\d+)?$!', $value);
|
||||
}
|
||||
|
||||
?>
|
||||
43
core/lib/SmartyValidate/plugins/validatecriteria.isprice.php
Normal file
43
core/lib/SmartyValidate/plugins/validatecriteria.isprice.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isPrice.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a price
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isPrice($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
return preg_match('/^\d+(\.\d{1,2})?$/', $value);
|
||||
}
|
||||
|
||||
?>
|
||||
63
core/lib/SmartyValidate/plugins/validatecriteria.isrange.php
Normal file
63
core/lib/SmartyValidate/plugins/validatecriteria.isrange.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isRange.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid range
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isRange($value, $empty, &$params, &$formvars) {
|
||||
|
||||
if(isset($params['field2'])) {
|
||||
$_low = $params['field2'];
|
||||
} elseif(isset($params['low'])) {
|
||||
$_low = $params['low'];
|
||||
} else {
|
||||
trigger_error("SmartyValidate: [isRange] parameter 'low' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isset($params['field3'])) {
|
||||
$_high = $params['field3'];
|
||||
} elseif(isset($params['high'])) {
|
||||
$_high = $params['high'];
|
||||
} else {
|
||||
trigger_error("SmartyValidate: [isRange] parameter 'high' is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
return ($value >= $_low && $value <= $_high);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isRegExp.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid regular expression match
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isRegExp($value, $empty, &$params, &$formvars) {
|
||||
if(isset($params['field2'])) {
|
||||
$_exp = $params['field2'];
|
||||
} elseif (isset($params['expression'])) {
|
||||
$_exp = $params['expression'];
|
||||
} else {
|
||||
trigger_error("SmartyValidate: [isRegExp] parameter 'expression' is missing.");
|
||||
return false;
|
||||
|
||||
}
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
return (preg_match($_exp, $value));
|
||||
}
|
||||
|
||||
?>
|
||||
43
core/lib/SmartyValidate/plugins/validatecriteria.isurl.php
Normal file
43
core/lib/SmartyValidate/plugins/validatecriteria.isurl.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.isURL.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is a valid URL
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_isURL($value, $empty, &$params, &$formvars) {
|
||||
if(strlen($value) == 0)
|
||||
return $empty;
|
||||
|
||||
return preg_match('!^http(s)?://[\w-]+\.[\w-]+(\S+)?$!i', $value);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_criteria.notEmpty.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* test if a value is not empty
|
||||
*
|
||||
* @param string $value the value being tested
|
||||
* @param boolean $empty if field can be empty
|
||||
* @param array params validate parameter values
|
||||
* @param array formvars form var values
|
||||
*/
|
||||
function smarty_validate_criteria_notEmpty($value, $empty, &$params, &$formvars) {
|
||||
return strlen($value) > 0;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_transform.default.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* transform fuction, set an empty value to a default value
|
||||
*
|
||||
* @param string $value the value being defaulted
|
||||
* @param array $params the parameters passed to the transform function
|
||||
* @param array $formvars the form variables
|
||||
*/
|
||||
|
||||
function smarty_validate_transform_default($value, $params, &$formvars) {
|
||||
if($value == '') {
|
||||
if( isset($params['default2']) )
|
||||
return $params['default2'];
|
||||
elseif( isset($params['default']) )
|
||||
return $params['default'];
|
||||
else
|
||||
return '';
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_transform.makeDate.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* transform fuction, make a date out of three other form fields
|
||||
*
|
||||
* @param string $value the value of the field being transformed
|
||||
* @param array $params the parameters passed to the transform function
|
||||
* @param array $formvars the form variables
|
||||
*/
|
||||
|
||||
function smarty_validate_transform_makeDate($value, $params, &$formvars) {
|
||||
|
||||
if(!empty($params['date_fields'])) {
|
||||
list($_year, $_month, $_day) = preg_split('![\s,]+!',$params['date_fields']);
|
||||
} elseif(!empty($params['field2']) && !empty($params['field3']) && !empty($params['field4'])) {
|
||||
$_year = $params['field2'];
|
||||
$_month = $params['field3'];
|
||||
$_day = $params['field4'];
|
||||
} else {
|
||||
$_year = $params['field'] . 'Year';
|
||||
$_month = $params['field'] . 'Month';
|
||||
$_day = $params['field'] . 'Day';
|
||||
}
|
||||
|
||||
if(!isset($formvars[$_year]) || strlen($formvars[$_year]) == 0) {
|
||||
trigger_error("SmartyValidate: [makeDate] form field '$_year' is empty.");
|
||||
return $value;
|
||||
} elseif(!isset($formvars[$_month]) || strlen($formvars[$_month]) == 0) {
|
||||
trigger_error("SmartyValidate: [makeDate] form field '$_month' is empty.");
|
||||
return $value;
|
||||
} elseif(!isset($formvars[$_day]) || strlen($formvars[$_day]) == 0) {
|
||||
trigger_error("SmartyValidate: [makeDate] form field '$_day' is empty.");
|
||||
return $value;
|
||||
} else {
|
||||
return $formvars[$_year] . '-' . $formvars[$_month] . '-' . $formvars[$_day];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
40
core/lib/SmartyValidate/plugins/validatetransform.trim.php
Normal file
40
core/lib/SmartyValidate/plugins/validatetransform.trim.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Project: SmartyValidate: Form Validator for the Smarty Template Engine
|
||||
* File: validate_transform.trim.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* transform fuction, trim a value
|
||||
*
|
||||
* @param string $value the value being trimmed
|
||||
* @param array $params the parameters passed to the transform function
|
||||
* @param array $formvars the form variables
|
||||
*/
|
||||
|
||||
function smarty_validate_transform_trim($value, $params, &$formvars) {
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user