PageRenderTime 21ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://xoopscube-modules.googlecode.com/
PHP | 127 lines | 79 code | 13 blank | 35 comment | 23 complexity | c062c0164c432df90a3455b26d621475 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4. * Min.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: Min.php 822 2009-05-16 17:57:18Z sotarok $
  10. */
  11. // {{{ Ethna_Plugin_Validator_Min
  12. /**
  13. * ????????????
  14. *
  15. * @author ICHII Takashi <ichii386@schweetheart.jp>
  16. * @access public
  17. * @package Ethna
  18. */
  19. class Ethna_Plugin_Validator_Min 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['min']) == false || $this->isEmpty($var, $type)) {
  36. return $true;
  37. }
  38. switch ($type) {
  39. case VAR_TYPE_INT:
  40. if ($var < $params['min']) {
  41. if (isset($params['error'])) {
  42. $msg = $params['error'];
  43. } else {
  44. $msg = _et('Please input more than %d(int) to {form}.');
  45. }
  46. return Ethna::raiseNotice($msg, E_FORM_MIN_INT, array($params['min']));
  47. }
  48. break;
  49. case VAR_TYPE_FLOAT:
  50. if ($var < $params['min']) {
  51. if (isset($params['error'])) {
  52. $msg = $params['error'];
  53. } else {
  54. $msg = _et('Please input more than %f(float) to {form}.');
  55. }
  56. return Ethna::raiseNotice($msg, E_FORM_MIN_FLOAT, array($params['min']));
  57. }
  58. break;
  59. case VAR_TYPE_DATETIME:
  60. $t_min = strtotime($params['min']);
  61. $t_var = strtotime($var);
  62. if ($t_var < $t_min) {
  63. if (isset($params['error'])) {
  64. $msg = $params['error'];
  65. } else {
  66. $msg = _et('Please input datetime value %s or later to {form}.');
  67. }
  68. return Ethna::raiseNotice($msg, E_FORM_MIN_DATETIME, array($params['min']));
  69. }
  70. break;
  71. case VAR_TYPE_FILE:
  72. $st = stat($var['tmp_name']);
  73. if ($st[7] < $params['min'] * 1024) {
  74. if (isset($params['error'])) {
  75. $msg = $params['error'];
  76. } else {
  77. $msg = _et('Please specify file whose size is more than %d KB.');
  78. }
  79. return Ethna::raiseNotice($msg, E_FORM_MIN_FILE, array($params['min']));
  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 = 'Mbstrmin';
  96. $params['mbstrmin'] = $params['min'];
  97. } elseif (strcasecmp('EUC-JP', $client_enc == 0)
  98. || strcasecmp('eucJP-win', $client_enc == 0)) {
  99. $plugin_name = 'Strmincompat';
  100. $params['strmincompat'] = $params['min'];
  101. } else {
  102. $plugin_name = 'Strmin';
  103. $params['strmin'] = $params['min'];
  104. }
  105. unset($params['min']);
  106. $vld = $plugin->getPlugin('Validator', $plugin_name);
  107. return $vld->validate($name, $var, $params);
  108. break;
  109. }
  110. return $true;
  111. }
  112. }
  113. // }}}
  114. ?>