/extras/installer-ftp/lib/Curaga/class/Plugin/Validator/Max.php
PHP | 129 lines | 79 code | 14 blank | 36 comment | 23 complexity | fe6bc803fc00c33c687f962028551b37 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
- <?php
- // vim: foldmethod=marker
- /**
- * Max.php
- *
- * @author ICHII Takashi <ichii386@schweetheart.jp>
- * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
- * @package Ethna
- * @version $Id: Max.php 822 2009-05-16 17:57:18Z sotarok $
- */
- // {{{ Ethna_Plugin_Validator_Max
- /**
- * ????????????
- *
- * @author ICHII Takashi <ichii386@schweetheart.jp>
- * @access public
- * @package Ethna
- */
- class Ethna_Plugin_Validator_Max extends Ethna_Plugin_Validator
- {
- /** @var bool ??????????? */
- var $accept_array = false;
- /**
- * ???????????
- *
- * @access public
- * @param string $name ???????
- * @param mixed $var ??????
- * @param array $params ???????????
- */
- function &validate($name, $var, $params)
- {
- $true = true;
- $type = $this->getFormType($name);
- if (isset($params['max']) == false || $this->isEmpty($var, $type)) {
- return $true;
- }
- switch ($type) {
- case VAR_TYPE_INT:
- if ($var > $params['max']) {
- if (isset($params['error'])) {
- $msg = $params['error'];
- } else {
- $msg = _et('Please input less than %d(int) to {form}.');
- }
- return Ethna::raiseNotice($msg, E_FORM_MAX_INT, array($params['max']));
- }
- break;
- case VAR_TYPE_FLOAT:
- if ($var > $params['max']) {
- if (isset($params['error'])) {
- $msg = $params['error'];
- } else {
- $msg = _et('Please input less than %f(float) to {form}.');
- }
- return Ethna::raiseNotice($msg, E_FORM_MAX_FLOAT, array($params['max']));
- }
- break;
- case VAR_TYPE_DATETIME:
- $t_max = strtotime($params['max']);
- $t_var = strtotime($var);
- if ($t_var > $t_max) {
- if (isset($params['error'])) {
- $msg = $params['error'];
- } else {
- $msg = _et('Please input datetime value before %s to {form}.');
- }
- return Ethna::raiseNotice($msg, E_FORM_MAX_DATETIME, array($params['max']));
- }
- break;
- case VAR_TYPE_FILE:
- $st = stat($var['tmp_name']);
- if ($st[7] > $params['max'] * 1024) {
- if (isset($params['error'])) {
- $msg = $params['error'];
- } else {
- $msg = _et('Please specify file whose size is less than %d KB to {form}.');
- }
- return Ethna::raiseNotice($msg, E_FORM_MAX_FILE, array($params['max']));
- }
- break;
- case VAR_TYPE_STRING:
- //
- // ????????????????????????
- // ????????????
- //
- // ??? Ethna_Controller#client_encoding ????
- // ????????
- //
- $ctl = Ethna_Controller::getInstance();
- $client_enc = $ctl->getClientEncoding();
- $plugin = $this->backend->getPlugin();
- // select Plugin.
- if (mb_enabled() && strcasecmp('UTF-8', $client_enc) == 0) {
- $plugin_name = 'Mbstrmax';
- $params['mbstrmax'] = $params['max'];
- } elseif (strcasecmp('EUC-JP', $client_enc == 0)
- || strcasecmp('eucJP-win', $client_enc == 0)) {
- // 2.3.x compatibility
- $plugin_name = 'Strmaxcompat';
- $params['strmaxcompat'] = $params['max'];
- } else {
- $plugin_name = 'Strmax';
- $params['strmax'] = $params['max'];
- }
- unset($params['max']);
- $vld = $plugin->getPlugin('Validator', $plugin_name);
- return $vld->validate($name, $var, $params);
- break;
- }
- return $true;
- }
- }
- // }}}
- ?>