Пример #1
0
 /**
  *  最大値のチェックを行う
  *
  *  @access public
  *  @param  string  $name       フォームの名前
  *  @param  mixed   $var        フォームの値
  *  @param  array   $params     プラグインのパラメータ
  *  @return true: 成功  Ethna_Error: エラー
  */
 public function validate($name, $var, $params)
 {
     $true = true;
     $type = $this->getFormType($name);
     if (isset($params['strmaxcompat']) == false || $this->isEmpty($var, $type)) {
         return $true;
     }
     $ctl = $this->backend->getController();
     $client_enc = $ctl->getClientEncoding();
     if (mb_enabled() && (strcasecmp('EUC-JP', $client_enc) != 0 && strcasecmp('eucJP-win', $client_enc) != 0)) {
         $var = mb_convert_encoding($var, 'EUC-JP', $client_enc);
     }
     if ($type == VAR_TYPE_STRING) {
         $max_param = $params['strmaxcompat'];
         if (strlen($var) > $max_param) {
             if (isset($params['error'])) {
                 $msg = $params['error'];
             } else {
                 $msg = _et('Please input less than %d full-size (%d half-size) characters to {form}.');
             }
             return Ethna::raiseNotice($msg, E_FORM_MAX_STRING, array(intval($max_param / 2), $max_param));
         }
     }
     return $true;
 }
Пример #2
0
 /**
  *  Jsonを出力する
  *
  *  @access public
  *  @param  array  $encode_param  出力するJSONにエンコードする値
  */
 function preforward($encode_param = array())
 {
     $client_enc = $this->ctl->getClientEncoding();
     if (mb_enabled() && strcasecmp('UTF-8', $client_enc) != 0) {
         mb_convert_variables('UTF-8', $client_enc, $encode_param);
     }
     $encoded_param = json_encode($encode_param);
     $this->header(array('Content-Type' => 'application/json; charset=UTF-8'));
     echo $encoded_param;
 }
Пример #3
0
 /**
  *  Jsonを出力する
  *  @access public
  *  @param  array  $encode_param  出力するJSONにエンコードする値
  *  @see Admin_ViewClass::preforward
  */
 function preforward($encode_param)
 {
     $client_enc = $this->ctl->getClientEncoding();
     if (mb_enabled() && strcasecmp('UTF-8', $client_enc) != 0) {
         mb_convert_variables('UTF-8', $client_enc, $encode_param);
     }
     $this->jsonI18n($encode_param);
     $encoded_param = json_encode($encode_param);
     header('Content-Type: application/json; charset=UTF-8');
     echo $encoded_param;
     exit;
 }
Пример #4
0
 /**
  * 404の出力
  * @see Api_ViewClass::preforward()
  */
 function preforward($param = false)
 {
     if ($param !== false) {
         $this->logger->log(LOG_CRIT, $param);
     }
     // エンコードをUTF-8に変更する
     $client_enc = $this->ctl->getClientEncoding();
     if (mb_enabled() && strcasecmp('UTF-8', $client_enc) != 0) {
         mb_convert_variables('UTF-8', $client_enc, $param);
     }
     $param = json_encode($param);
     // 出力
     header("HTTP/1.1 500 Interal Server Error");
     header('Content-Type: application/json; charset=UTF-8');
     echo $param;
     exit;
 }
Пример #5
0
Файл: Min.php Проект: riaf/ethna
 /**
  *  最小値のチェックを行う
  *
  *  @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['min']) == false || $this->isEmpty($var, $type)) {
         return $true;
     }
     switch ($type) {
         case VAR_TYPE_INT:
             if ($var < $params['min']) {
                 if (isset($params['error'])) {
                     $msg = $params['error'];
                 } else {
                     $msg = _et('Please input more than %d(int) to {form}.');
                 }
                 return Ethna::raiseNotice($msg, E_FORM_MIN_INT, array($params['min']));
             }
             break;
         case VAR_TYPE_FLOAT:
             if ($var < $params['min']) {
                 if (isset($params['error'])) {
                     $msg = $params['error'];
                 } else {
                     $msg = _et('Please input more than %f(float) to {form}.');
                 }
                 return Ethna::raiseNotice($msg, E_FORM_MIN_FLOAT, array($params['min']));
             }
             break;
         case VAR_TYPE_DATETIME:
             $t_min = strtotime($params['min']);
             $t_var = strtotime($var);
             if ($t_var < $t_min) {
                 if (isset($params['error'])) {
                     $msg = $params['error'];
                 } else {
                     $msg = _et('Please input datetime value %s or later to {form}.');
                 }
                 return Ethna::raiseNotice($msg, E_FORM_MIN_DATETIME, array($params['min']));
             }
             break;
         case VAR_TYPE_FILE:
             $st = stat($var['tmp_name']);
             if ($st[7] < $params['min'] * 1024) {
                 if (isset($params['error'])) {
                     $msg = $params['error'];
                 } else {
                     $msg = _et('Please specify file whose size is more than %d KB.');
                 }
                 return Ethna::raiseNotice($msg, E_FORM_MIN_FILE, array($params['min']));
             }
             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 = 'Mbstrmin';
                 $params['mbstrmin'] = $params['min'];
             } elseif (strcasecmp('EUC-JP', $client_enc == 0) || strcasecmp('eucJP-win', $client_enc == 0)) {
                 $plugin_name = 'Strmincompat';
                 $params['strmincompat'] = $params['min'];
             } else {
                 $plugin_name = 'Strmin';
                 $params['strmin'] = $params['min'];
             }
             unset($params['min']);
             $vld = $plugin->getPlugin('Validator', $plugin_name);
             return $vld->validate($name, $var, $params);
             break;
     }
     return $true;
 }
Пример #6
0
 /**
  *  Ethna_Controllerクラスのコンストラクタ
  *
  *  @access     public
  */
 function Ethna_Controller($gateway = GATEWAY_WWW)
 {
     $GLOBALS['_Ethna_controller'] =& $this;
     if ($this->base === "") {
         // EthnaコマンドなどでBASEが定義されていない場合がある
         if (defined('BASE')) {
             $this->base = BASE;
         }
     }
     $this->gateway = $gateway;
     // クラス設定の未定義値を補完
     foreach ($this->class_default as $key => $val) {
         if (isset($this->class[$key]) == false) {
             $this->class[$key] = $val;
         }
     }
     // ディレクトリ設定の未定義値を補完
     foreach ($this->directory_default as $key => $val) {
         if (isset($this->directory[$key]) == false) {
             $this->directory[$key] = $val;
         }
     }
     // クラスファクトリオブジェクトの生成
     $class_factory = $this->class['class'];
     $this->class_factory =& new $class_factory($this, $this->class);
     // エラーハンドラの設定
     Ethna::setErrorCallback(array(&$this, 'handleError'));
     // ディレクトリ名の設定(相対パス->絶対パス)
     foreach ($this->directory as $key => $value) {
         if ($key == 'plugins') {
             // Smartyプラグインディレクトリは配列で指定する
             $tmp = array();
             foreach (to_array($value) as $elt) {
                 if (Ethna_Util::isAbsolute($elt) == false) {
                     $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt;
                 }
             }
             $this->directory[$key] = $tmp;
         } else {
             if (Ethna_Util::isAbsolute($value) == false) {
                 $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value;
             }
         }
     }
     // 遷移先設定をマージ
     // 但し、キーは完全に維持する
     $this->forward = $this->forward + $this->forward_default;
     // 初期設定
     // フレームワークとしての内部エンコーディングはクライアント
     // エンコーディング(=ブラウザからのエンコーディング)
     //
     // @see Ethna_Controller#_getDefaultLanguage
     list($this->locale, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage();
     if (mb_enabled()) {
         mb_internal_encoding($this->client_encoding);
         mb_regex_encoding($this->client_encoding);
     }
     $this->config =& $this->getConfig();
     $this->dsn = $this->_prepareDSN();
     $this->url = $this->config->get('url');
     // プラグインオブジェクトの用意
     $this->plugin =& $this->getPlugin();
     //// assert (experimental)
     //if ($this->config->get('debug') === false) {
     //    ini_set('assert.active', 0);
     //}
     // ログ出力開始
     $this->logger =& $this->getLogger();
     $this->plugin->setLogger($this->logger);
     $this->logger->begin();
     // Ethnaマネージャ設定
     $this->_activateEthnaManager();
 }