/** * 最大値のチェックを行う * * @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; }
/** * 最小値のチェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public 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: $params['mbstrmin'] = $params['min']; unset($params['min']); $vld = $this->plugin->getPlugin('Validator', 'Mbstrmin'); return $vld->validate($name, $var, $params); break; } return $true; }
/** * ユーザの支払能力をチェックします * * @param int $value * @return int */ public function isMoneyAvailable($value = 0) { $current_money = $this->get('money'); if ($current_money < $value) { return Ethna::raiseNotice('そんなお金ないです。'); } return $current_money; }
/** * フォーム値の型チェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; $type = $params['type']; if ($type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } foreach (array_keys(to_array($var)) as $key) { switch ($type) { case VAR_TYPE_INT: if (!preg_match('/^-?\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には数字(整数)を入力して下さい"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_INT); } break; case VAR_TYPE_FLOAT: if (!preg_match('/^-?\\d+$/', $var) && !preg_match('/^-?\\d+\\.\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には数字(小数)を入力して下さい"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FLOAT); } break; case VAR_TYPE_BOOLEAN: if ($var != "1" && $var != "0") { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には1または0のみ入力できます"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_BOOLEAN); } break; case VAR_TYPE_DATETIME: $r = strtotime($var); if ($r == -1 || $r === false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}には日付を入力して下さい"; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_DATETIME); } break; } } return $true; }
/** * フォーム値の型チェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public function validate($name, $var, $params) { $true = true; $type = $params['type']; if ($type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } foreach (array_keys(to_array($var)) as $key) { switch ($type) { case VAR_TYPE_INT: if (!preg_match('/^-?\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input integer value to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_INT); } break; case VAR_TYPE_FLOAT: if (!preg_match('/^-?\\d+$/', $var) && !preg_match('/^-?\\d+\\.\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input float value to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FLOAT); } break; case VAR_TYPE_BOOLEAN: if ($var != "1" && $var != "0") { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('You can input 0 or 1 to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_BOOLEAN); } break; case VAR_TYPE_DATETIME: $r = strtotime($var); if ($r == -1 || $r === false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input valid datetime to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_DATETIME); } break; } } return $true; }
/** * エラーオブジェクトを生成/追加する * * @access public * @param string $name エラーの発生したフォーム項目名(不要ならnull) * @param string $message i18n翻訳後のエラーメッセージ * @param int $code エラーコード * @return Ethna_Error エラーオブジェクト */ public function add($name, $message, $code = null) { if (func_num_args() > 3) { $userinfo = array_slice(func_get_args(), 3); $error = Ethna::raiseNotice($message, $code, $userinfo); } else { $error = Ethna::raiseNotice($message, $code); } $this->addObject($name, $error); return $error; }
/** * 拡張子チェック * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { if (empty($var['size'])) { return true; } $safety_ext_list = array('jpg', 'png', 'gif', 'bmp', 'doc', 'xls', 'ppt', 'csv', 'txt', 'pdf', 'zip', 'lzh', 'sit', 'rar', 'tar', 'tgz'); $ext = pathinfo($var['name'], PATHINFO_EXTENSION); $ext = strToLower($ext); if (in_array($ext, $safety_ext_list)) { return true; } return Ethna::raiseNotice('{form}のファイルタイプは対応していません', E_FORM_INVALIDVALUE); }
/** * addicon_do action implementation. * * @access public * @return string forward name. */ public function perform() { if (!$this->session->isStart()) { return 'needlogin'; } $file = $this->af->get('userfile'); if ($file['size'] === 0 || $file['tmp_name'] === '') { $this->ae->addObject('iconadderror', Ethna::raiseNotice('need file', E_SAMPLE_AUTH)); return 'iconadd'; } $um = new UserManager(); $userid = $this->session->get('username'); $res = $um->uploadIcon($userid, $file['tmp_name'], pathinfo($file['name'], PATHINFO_EXTENSION)); $this->redirect('iconadd'); return 'iconadd'; }
/** * 正規表現によるフォーム値のチェックを行う * * @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['regexp']) == false || $type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } if (preg_match($params['regexp'], $var) == 0) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input {form} properly.'); } return Ethna::raiseNotice($msg, E_FORM_REGEXP); } return $true; }
/** * エラーオブジェクトを生成/追加する * * @access public * @param string $name エラーの発生したフォーム項目名(不要ならnull) * @param string $message エラーメッセージ * @param int $code エラーコード */ function add($name, $message, $code = null) { if (func_num_args() > 3) { $userinfo = array_slice(func_get_args(), 3); $error =& Ethna::raiseNotice($message, $code, $userinfo); } else { $error =& Ethna::raiseNotice($message, $code); } $elt = array(); $elt['name'] = $name; $elt['object'] =& $error; $this->error_list[] = $elt; // ログ出力(補足) $af =& $this->_getActionForm(); $logger =& $this->_getLogger(); $logger->log(LOG_NOTICE, '{form} -> [%s]', $this->action_form->getName($name)); }
/** * 正規表現によるフォーム値のチェックを行う(マルチバイト対応) * * @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['mbregexp']) == false || $type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } $encoding = isset($params['encoding']) ? $params['encoding'] : 'EUC-JP'; mb_regex_encoding($encoding); if (mb_ereg($params['mbregexp'], $var) !== 1) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}を正しく入力してください"; } return Ethna::raiseNotice($msg, E_FORM_REGEXP); } return $true; }
/** * プロジェクトのメッセージカタログを生成する * * @access public * @param string $locale 生成するカタログのロケール * @param int $use_gettext gettext 使用フラグ * true ならgettext のカタログ生成 * false ならEthna組み込みのカタログ生成 * @param array $ext_dirs 走査する追加のディレクトリの配列 * @return true|Ethna_Error true:成功 Ethna_Error:失敗 */ function &generate($locale, $use_gettext, $ext_dirs = array()) { $this->time = time(); $this->locale = $locale; $this->use_gettext = $use_gettext; $outfile_path = $this->_get_output_file(); // // 既存ファイルが存在した場合は、以下の動きをする // // 1. Ethna 組み込みのカタログの場合、既存のiniファイル // の中身を抽出し、既存の翻訳を可能な限りマージする // 2. gettext 利用の場合は、新たにファイルを作らせ、 // 既存翻訳とのマージは msgmergeプログラムを使わせる // if ($this->file_exists) { $msg = $this->use_gettext ? "[NOTICE]: Message catalog file already exists! " . "CREATING NEW FILE ...\n" . "You can run msgmerge program to merge translation.\n" : "[NOTICE]: Message catalog file already exists!\n" . "This is overwritten and existing translation is merged automatically.\n"; print "\n-------------------------------\n" . $msg . "-------------------------------\n\n"; } // app ディレクトリとテンプレートディレクトリを // 再帰的に走査する。ユーザから指定があればそれも走査 $app_dir = $this->ctl->getDirectory('app'); $template_dir = $this->ctl->getDirectory('template'); $scan_dir = array($app_dir, "{$template_dir}/{$locale}"); $scan_dir = array_merge($scan_dir, $ext_dirs); // ディレクトリを走査 foreach ($scan_dir as $dir) { if (is_dir($dir) === false) { Ethna::raiseNotice("{$dir} is not Directory.", E_GENERAL); continue; } $r = $this->_analyzeDirectory($dir); if (Ethna::isError($r)) { return $r; } } // 解析済みトークンを元に、カタログファイルを生成 $r = $this->_generateFile(); if (Ethna::isError($r)) { return $r; } $true = true; return $true; }
/** * 最小値のチェックを行う (シングルバイト文字列用) * * @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['strmin']) == false || $this->isEmpty($var, $type)) { return $true; } if ($type == VAR_TYPE_STRING) { $min_param = $params['strmin']; if (strlen($var) < $min_param) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %d characters to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_STRING, array($min_param)); } } return $true; }
public function s3upload($fname, $fileid, $ext) { $ctype = 'binary/octet-stream'; if (array_key_exists($ext, $this->acceptable_exts)) { $ctype = $this->acceptable_exts[$ext]['content-type']; } else { return Ethna::raiseNotice("a file which has ext " . $ext . ' is not allowed to upload', E_SAMPLE_AUTH); } //$fullpath=$this->savepath($newfname); //rename($fname, $fullpath); try { $s3 = Aws\S3\S3Client::factory(array('key' => SecretConfig::$config['AWS_ACCESS_KEY_ID'], 'secret' => SecretConfig::$config['AWS_SECRET_ACCESS_KEY'], 'region' => SecretConfig::$config['AWS_DEFAULT_REGION'])); error_log('ctype:' . $ctype); $result = $s3->putObject(array('ACL' => 'public-read', 'Bucket' => SecretConfig::$config['AWS_BUCKET_NAME'], 'Key' => $fileid, 'Body' => fopen($fname, 'r'), 'ContentType' => $ctype)); //$fileurl=$result['ObjectURL']; } catch (Exception $e) { throw $e; //return Ethna::raiseNotice('error occured while accessing AWS errormessage:' . $e->getMessage(),E_SAMPLE_AUTH); } return null; }
/** * 正規表現によるフォーム値のチェックを行う(マルチバイト対応) * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public function validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['mbregexp']) == false || $type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } $ctl = $this->backend->getController(); $cli_enc = $ctl->getClientEncoding(); $encoding = isset($params['encoding']) ? $params['encoding'] : $cli_enc; mb_regex_encoding($encoding); if (mb_ereg($params['mbregexp'], $var) !== 1) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input {form} properly.'); } return Ethna::raiseNotice($msg, E_FORM_REGEXP); } return $true; }
/** * board_do action implementation. * * @access public * @return string forward name. */ public function perform() { if (!$this->session->isStart()) { $this->ae->addObject('boardError', Ethna::raiseNotice("you need to login to post", E_SAMPLE_AUTH)); return 'board'; } $bm = new BoardManager(); $color = $this->af->get('color'); if ($color === NULL) { $color = '#000000'; } $fileid = $this->af->get('uploaded-fileid'); $content = $this->af->get('content'); //$content='hage'; $res = $bm->post($this->backend, $this->session->get('username'), $content, $color, $fileid); if (Ethna::isError($res)) { $this->ae->addObject('PostError', $res); } else { $this->redirect('board'); } return 'board'; }
/** * 最小値のチェックを行う * * @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; }
/** * エラーを返す * * @access protected * @param string $msg エラーメッセージ * @param int $code エラーコード * @param mixed $info エラーメッセージにsprintfで渡すパラメータ */ function &error($msg, $code, $info = null) { if ($info != null) { if (is_array($info)) { return Ethna::raiseNotice($msg, $code, $info); } else { return Ethna::raiseNotice($msg, $code, array($info)); } } else { return Ethna::raiseNotice($msg, $code); } }
/** * アップロードされたファイルのチェックを行う * XXX: プラグインのエラーコードを修正する * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; if ($this->getFormType($name) != VAR_TYPE_FILE) { return $true; } // そもそもアップロードされていない場合はスキップ if ($var['error'] == UPLOAD_ERR_NO_FILE) { return $true; } // エラーコードの検査 $msg = ''; switch ($var['error']) { case UPLOAD_ERR_INI_SIZE: $msg = _et("Uploaded file size exceeds php.ini's upload_max_filesize directive."); break; case UPLOAD_ERR_FORM_SIZE: $msg = _et('Uploaded File size exceeds MAX_FILE_SIZE specified in HTML Form.'); break; case UPLOAD_ERR_PARTIAL: $msg = _et('File was only uploaded patially.'); break; case UPLOAD_ERR_NO_FILE: $msg = _et('File was not uploaded.'); break; case UPLOAD_ERR_NO_TMP_DIR: $msg = _et('Temporary folder was not found.'); break; case UPLOAD_ERR_CANT_WRITE: $msg = _et('Could not write uploaded file to disk.'); break; } if ($msg != '') { if (isset($params['error'])) { $msg = $params['error']; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } // tmp_name の検査 if (isset($var['tmp_name']) == false || is_uploaded_file($var['tmp_name']) == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('invalid tmp_name.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } // size の検査 if (isset($params['size_max'])) { $st = stat($var['tmp_name']); if ($st[7] > $this->_getSizeAsBytes($params['size_max'])) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Uploaded file size must be less than %s.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE, array($params['size_max'])); } } if (isset($params['size_min'])) { $st = stat($var['tmp_name']); if ($st[7] < $this->_getSizeAsBytes($params['size_min'])) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Uploaded file size must be more than %s.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE, array($params['size_min'])); } } // type の検査 if (isset($params['type'])) { $type_list = to_array($params['type']); $posted_mime = explode('/', $var['type'], 2); foreach ($type_list as $type) { $wanted_mime = explode('/', $type, 2); $test = count($wanted_mime) == 1 ? strcasecmp($wanted_mime[0], $posted_mime[0]) == 0 : strcasecmp($type, $var['type']) == 0; if ($test == true) { break; } } if ($test == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Invalid file type.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } } // name(ファイル名)の検査 if (isset($params['name'])) { $test = $params['name'][0] == '/' ? preg_match($params['name'], $var['name']) : strcmp($params['name'], $var['name']) == 0; if ($test == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Invalid file name.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } } return $true; }
/** * クエリを発行する * * @access private * @param string $query SQL文 * @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー */ function _query($query) { $this->logger->log(LOG_DEBUG, "{$query}"); $r = $this->db->query($query); if (DB::isError($r)) { if ($r->getCode() == DB_ERROR_ALREADY_EXISTS) { $error = Ethna::raiseNotice('Unique Constraint Error SQL[%s]', E_DB_DUPENT, $query, $this->db->errorNative(), $r->getUserInfo()); } else { $error = Ethna::raiseError('Query Error SQL[%s] CODE[%d] MESSAGE[%s]', E_DB_QUERY, $query, $this->db->errorNative(), $r->getUserInfo()); } return $error; } return $r; }
/** * お菓子の購入が可能かチェックします。 * * @param Sampleshop_User $user_object * @param Sampleshop_Item $item_object * @param int $item_count * @return boolean */ public function _validateShopSnack(Sampleshop_User $user_object, Sampleshop_Item $item_object, $item_count) { $user_item_manager = $this->backend->getManager('UserItem'); $current_snack_count = $user_item_manager->getSnackCountByUserId($user_object->get('id')); if (Ethna::isError($current_snack_count)) { return $current_snack_count; } $total_snack_count = $current_snack_count + $item_count; if ($total_snack_count > 10) { return Ethna::raiseNotice('お菓子は10個までだよ。'); } return true; }
/** * オブジェクトを更新する * * @access public * @return mixed 0:正常終了 Ethna_Error:エラー */ function update() { $sql = $this->_getSQL_Update(); for ($i = 0; $i < 4; $i++) { $r =& $this->my_db_rw->query($sql); if (Ethna::isError($r)) { if ($r->getCode() == E_DB_DUPENT) { // 重複エラーキーの判別 $duplicate_key_list = $this->_getDuplicateKeyList(); if (Ethna::isError($duplicate_key_list)) { return $duplicate_key_list; } if (is_array($duplicate_key_list) && count($duplicate_key_list) > 0) { foreach ($duplicate_key_list as $k) { return Ethna::raiseNotice('重複エラー[%s]', E_APP_DUPENT, $k); } } } else { return $r; } } else { break; } } if ($i == 4) { // cannot be reached return Ethna::raiseError('重複エラーキー判別エラー', E_GENERAL); } $affected_rows = $this->my_db_rw->affectedRows(); if ($affected_rows <= 0) { $this->backend->log(LOG_DEBUG, "update query with 0 updated rows"); } // バックアップ/キャッシュ更新 $this->prop_backup = $this->prop; $this->_clearPropCache(); return 0; }
function test_raiseNotice() { $error = Ethna::raiseNotice('Error!!!!!'); $this->assertEqual('Error!!!!!', $error->getMessage()); $this->assertEqual(E_USER_NOTICE, $error->getLevel()); $this->assertEqual(E_GENERAL, $error->getCode()); $error = Ethna::raiseNotice('Error!!!!!', E_CACHE_GENERAL); $this->assertEqual(E_CACHE_GENERAL, $error->getCode()); }
/** * CSV形式の文字列を配列に分割する * * @access public * @param string $csv CSV形式の文字列(1行分) * @param string $delimiter フィールドの区切り文字 * @return mixed (array):分割結果 Ethna_Error:エラー(行継続) */ public static function explodeCSV($csv, $delimiter = ",") { $space_list = ''; foreach (array(" ", "\t", "\r", "\n") as $c) { if ($c != $delimiter) { $space_list .= $c; } } $line_end = ""; if (preg_match("/([{$space_list}]+)\$/sS", $csv, $match)) { $line_end = $match[1]; } $csv = substr($csv, 0, strlen($csv) - strlen($line_end)); $csv .= ' '; $field = ''; $retval = array(); $index = 0; $csv_len = strlen($csv); do { // 1. skip leading spaces if (preg_match("/^([{$space_list}]+)/sS", substr($csv, $index), $match)) { $index += strlen($match[1]); } if ($index >= $csv_len) { break; } // 2. read field if ($csv[$index] == '"') { // 2A. handle quote delimited field $index++; while ($index < $csv_len) { if ($csv[$index] == '"') { // handle double quote if ($csv[$index + 1] == '"') { $field .= $csv[$index]; $index += 2; } else { // must be end of string while ($csv[$index] != $delimiter && $index < $csv_len) { $index++; } if ($csv[$index] == $delimiter) { $index++; } break; } } else { // normal character if (preg_match("/^([^\"]*)/S", substr($csv, $index), $match)) { $field .= $match[1]; $index += strlen($match[1]); } if ($index == $csv_len) { $field = substr($field, 0, strlen($field) - 1); $field .= $line_end; // request one more line return Ethna::raiseNotice('CSV Split Error (line continue)', E_UTIL_CSV_CONTINUE); } } } } else { // 2B. handle non-quoted field if (preg_match("/^([^{$delimiter}]*)/S", substr($csv, $index), $match)) { $field .= $match[1]; $index += strlen($match[1]); } // remove trailing spaces $field = preg_replace("/[{$space_list}]+\$/S", '', $field); if ($csv[$index] == $delimiter) { $index++; } } $retval[] = $field; $field = ''; } while ($index < $csv_len); return $retval; }
/** * 最小値のチェックを行う * * @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 = "{form}には%d以上の数字(整数)を入力して下さい"; } 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 = "{form}には%f以上の数字(小数)を入力して下さい"; } 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 = "{form}には%s以降の日付を入力して下さい"; } 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 = "{form}には%dKB以上のファイルを指定して下さい"; } return Ethna::raiseNotice($msg, E_FORM_MIN_FILE, array($params['min'])); } break; case VAR_TYPE_STRING: if (strlen($var) < $params['min']) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = "{form}は全角%d文字以上(半角%d文字以上)で入力して下さい"; } return Ethna::raiseNotice($msg, E_FORM_MIN_STRING, array(intval($params['min'] / 2), $params['min'])); } break; } return $true; }
public function signup($backend, $mailaddr, $passwd) { $db =& $backend->getDB(); if (Ethna::isError($db)) { return $db; } $list = $db->query("SELECT * FROM userlist WHERE id=?", array($mailaddr)); if (Ethna::isError($list)) { return $list; } $item = $list->fetchRow(); if ($item) { return Ethna::raiseNotice("the user name is already used", E_SAMPLE_AUTH); } $res = $db->autoExecute("userlist", array("id" => $mailaddr, "passwd" => $passwd), "INSERT"); if (Ethna::isError($res)) { return $res; } //return Ethna::raiseNotice("database error:"+$db->getMessage(),E_SAMPLE_AUTH); return null; }
/** * アップロードされたファイルのチェックを行う * XXX: プラグインのエラーコードを修正する * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; if ($this->getFormType($name) != VAR_TYPE_FILE) { return $true; } // そもそもアップロードされていない場合はスキップ if ($var['error'] == UPLOAD_ERR_NO_FILE) { return $true; } // エラーコードの検査 $msg = ''; switch ($var['error']) { case UPLOAD_ERR_INI_SIZE: $msg = 'アップロードされたファイルは、php.ini の upload_max_filesize ディレクティブの値を超えています。'; break; case UPLOAD_ERR_FORM_SIZE: $msg = 'アップロードされたファイルは、HTML フォームで指定された MAX_FILE_SIZE を超えています。'; break; case UPLOAD_ERR_PARTIAL: $msg = 'アップロードされたファイルは一部のみしかアップロードされていません。'; break; case UPLOAD_ERR_NO_FILE: $msg = 'ファイルはアップロードされませんでした。'; break; case UPLOAD_ERR_NO_TMP_DIR: $msg = 'テンポラリフォルダがありません。'; break; case UPLOAD_ERR_CANT_WRITE: $msg = 'ディスクへの書き込みに失敗しました。'; break; } if ($msg != '') { if (isset($params['error'])) { $msg = $params['error']; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } // tmp_name の検査 if (isset($var['tmp_name']) == false || is_uploaded_file($var['tmp_name']) == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = 'tmp_name が不正です。'; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } // size の検査 if (isset($params['size_max'])) { $st = stat($var['tmp_name']); if ($st[7] > $this->_getSizeAsBytes($params['size_max'])) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = 'ファイルサイズは%s以下にしてください。'; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE, array($params['size_max'])); } } if (isset($params['size_min'])) { $st = stat($var['tmp_name']); if ($st[7] < $this->_getSizeAsBytes($params['size_min'])) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = 'ファイルサイズは%s以上にしてください。'; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE, array($params['size_min'])); } } // type の検査 if (isset($params['type'])) { $type_list = to_array($params['type']); $posted_mime = explode('/', $var['type'], 2); foreach ($type_list as $type) { $wanted_mime = explode('/', $type, 2); $test = count($wanted_mime) == 1 ? strcasecmp($wanted_mime[0], $posted_mime[0]) == 0 : strcasecmp($type, $var['type']) == 0; if ($test == true) { break; } } if ($test == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = 'ファイルタイプが正しくありません。'; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } } // name(ファイル名)の検査 if (isset($params['name'])) { $test = $params['name'][0] == '/' ? preg_match($params['name'], $var['name']) : strcmp($params['name'], $var['name']) == 0; if ($test == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = 'ファイル名が正しくありません。'; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } } return $true; }
/** * フォームに値が入力されているかを検証する * * 配列の場合は、入力されるべき key のリスト、 * あるいは key の数を指定できます * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; if (isset($params['required']) && $params['required'] == false) { return $true; } $form_def = $this->getFormDef($name); // 選択型のフォームかどうか switch ($form_def['form_type']) { case FORM_TYPE_SELECT: case FORM_TYPE_RADIO: case FORM_TYPE_CHECKBOX: case FORM_TYPE_FILE: $choice = true; break; default: $choice = false; } // スカラーの場合 if (is_array($form_def['type']) == false) { if ($this->isEmpty($var, $this->getFormType($name))) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = '{form}が選択されていません'; } else { $msg = '{form}が入力されていません'; } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } else { return $true; } } // 配列の場合 $valid_keys = array(); if ($var != null) { foreach (array_keys($var) as $key) { if ($this->isEmpty($var[$key], $form_def['type']) == false) { $valid_keys[] = $key; } } } // required_key のチェック if (isset($params['key'])) { $invalid_keys = array_diff(to_array($params['key']), $valid_keys); if (count($invalid_keys) > 0) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = '{form}の必要な項目が選択されていません'; } else { $msg = '{form}の必要な項目が入力されていません'; } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } // required_num のチェック if (isset($params['num'])) { if (count($valid_keys) < intval($params['num'])) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = '{form}が必要な数まで選択されていません'; } else { $msg = '{form}が必要な数まで入力されていません'; } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } // とくに指定がないとき: フォームに与えられた全要素 if (isset($params['key']) == false && isset($params['num']) == false) { if (count($valid_keys) == 0 || count($valid_keys) != count($var)) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = '{form}が選択されていません'; } else { $msg = '{form}が入力されていません'; } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } return $true; }
/** * get canonical package name (case sensitive) * * @param string $package package name. * @return string canonical name * @access public */ public function getCanonicalPackageName($package) { if ($this->isInstalled($package) == false) { return Ethna::raiseNotice("{$this->channel}/{$package} is not installed."); } $pobj = $this->registry->getPackage($package, $this->channel); $cname = $pobj->getName(); return $cname; }
/** * フォームに値が入力されているかを検証する * * 配列の場合は、入力されるべき key のリスト、 * あるいは key の数を指定できます * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function validate($name, $var, $params) { $true = true; if (isset($params['required']) && $params['required'] == false) { return $true; } $form_def = $this->getFormDef($name); // 選択型のフォームかどうか switch ($form_def['form_type']) { case FORM_TYPE_SELECT: case FORM_TYPE_RADIO: case FORM_TYPE_CHECKBOX: case FORM_TYPE_FILE: $choice = true; break; default: $choice = false; } // スカラーの場合 if (is_array($form_def['type']) == false) { if ($this->isEmpty($var, $this->getFormType($name))) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('{form} was not selected.'); } else { $msg = _et('no input to {form}.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } else { return $true; } } // 配列の場合 $valid_keys = array(); if ($var != null) { foreach (array_keys($var) as $key) { if ($this->isEmpty($var[$key], $this->getFormType($name)) == false) { $valid_keys[] = $key; } } } // 配列の required_key のチェック // 'required_key' => array(xx) に設定された配列の要素値がなければエラー。 if (isset($params['key'])) { $invalid_keys = array_diff(to_array($params['key']), $valid_keys); if (count($invalid_keys) > 0) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('Required item of {form} was not selected.'); } else { $msg = _et('Required item of {form} was not submitted.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } // 配列の required_num のチェック // 'required_num' => xx に設定された数より、validな値の数が少なければエラー。 if (isset($params['num'])) { if (count($valid_keys) < intval($params['num'])) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('Required numbers of {form} was not selected.'); } else { $msg = _et('Required numbers of {form} was not submitted.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } // とくに指定がないとき: フォームに与えられた全要素に // valid な値が入っていなければならない if (isset($params['key']) == false && isset($params['num']) == false) { if (count($valid_keys) == 0 || count($valid_keys) != count($var)) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('Please select {form}.'); } else { $msg = _et('Please input {form}.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } return $true; }