PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/extras/installer-ftp/lib/Curaga/class/Plugin/Validator/Max.php

http://xoopscube-modules.googlecode.com/
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
  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4. * Max.php
  5. *
  6. * @author ICHII Takashi <ichii386@schweetheart.jp>
  7. * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  8. * @package Ethna
  9. * @version $Id: Max.php 822 2009-05-16 17:57:18Z sotarok $
  10. */
  11. // {{{ Ethna_Plugin_Validator_Max
  12. /**
  13. * ????????????
  14. *
  15. * @author ICHII Takashi <ichii386@schweetheart.jp>
  16. * @access public
  17. * @package Ethna
  18. */
  19. class Ethna_Plugin_Validator_Max extends Ethna_Plugin_Validator
  20. {
  21. /** @var bool ??????????? */
  22. var $accept_array = false;
  23. /**
  24. * ???????????
  25. *
  26. * @access public
  27. * @param string $name ???????
  28. * @param mixed $var ??????
  29. * @param array $params ???????????
  30. */
  31. function &validate($name, $var, $params)
  32. {
  33. $true = true;
  34. $type = $this->getFormType($name);
  35. if (isset($params['max']) == false || $this->isEmpty($var, $type)) {
  36. return $true;
  37. }
  38. switch ($type) {
  39. case VAR_TYPE_INT:
  40. if ($var > $params['max']) {
  41. if (isset($params['error'])) {
  42. $msg = $params['error'];
  43. } else {
  44. $msg = _et('Please input less than %d(int) to {form}.');
  45. }
  46. return Ethna::raiseNotice($msg, E_FORM_MAX_INT, array($params['max']));
  47. }
  48. break;
  49. case VAR_TYPE_FLOAT:
  50. if ($var > $params['max']) {
  51. if (isset($params['error'])) {
  52. $msg = $params['error'];
  53. } else {
  54. $msg = _et('Please input less than %f(float) to {form}.');
  55. }
  56. return Ethna::raiseNotice($msg, E_FORM_MAX_FLOAT, array($params['max']));
  57. }
  58. break;
  59. case VAR_TYPE_DATETIME:
  60. $t_max = strtotime($params['max']);
  61. $t_var = strtotime($var);
  62. if ($t_var > $t_max) {
  63. if (isset($params['error'])) {
  64. $msg = $params['error'];
  65. } else {
  66. $msg = _et('Please input datetime value before %s to {form}.');
  67. }
  68. return Ethna::raiseNotice($msg, E_FORM_MAX_DATETIME, array($params['max']));
  69. }
  70. break;
  71. case VAR_TYPE_FILE:
  72. $st = stat($var['tmp_name']);
  73. if ($st[7] > $params['max'] * 1024) {
  74. if (isset($params['error'])) {
  75. $msg = $params['error'];
  76. } else {
  77. $msg = _et('Please specify file whose size is less than %d KB to {form}.');
  78. }
  79. return Ethna::raiseNotice($msg, E_FORM_MAX_FILE, array($params['max']));
  80. }
  81. break;
  82. case VAR_TYPE_STRING:
  83. //
  84. // ????????????????????????
  85. // ????????????
  86. //
  87. // ??? Ethna_Controller#client_encoding ????
  88. // ????????
  89. //
  90. $ctl = Ethna_Controller::getInstance();
  91. $client_enc = $ctl->getClientEncoding();
  92. $plugin = $this->backend->getPlugin();
  93. // select Plugin.
  94. if (mb_enabled() && strcasecmp('UTF-8', $client_enc) == 0) {
  95. $plugin_name = 'Mbstrmax';
  96. $params['mbstrmax'] = $params['max'];
  97. } elseif (strcasecmp('EUC-JP', $client_enc == 0)
  98. || strcasecmp('eucJP-win', $client_enc == 0)) {
  99. // 2.3.x compatibility
  100. $plugin_name = 'Strmaxcompat';
  101. $params['strmaxcompat'] = $params['max'];
  102. } else {
  103. $plugin_name = 'Strmax';
  104. $params['strmax'] = $params['max'];
  105. }
  106. unset($params['max']);
  107. $vld = $plugin->getPlugin('Validator', $plugin_name);
  108. return $vld->validate($name, $var, $params);
  109. break;
  110. }
  111. return $true;
  112. }
  113. }
  114. // }}}
  115. ?>