menu and $params = new mosParameters($mainframe->menu->params); $exec = new TASK_kingyoya_comment($option); $exec->group = mosGetParam($_POST, 'group'); switch($task) { case 'save': if (strtolower($_SERVER['REQUEST_METHOD']) !== 'post') { header('HTTP/1.0 403 Forbidden'); echo _NOT_EXIST; return; } $exec->target = mosGetParam($_POST, 'target'); $exec->return = mosGetParam($_POST, 'return'); $exec->return or $exec->return = $params->get('return'); $exec->return or $exec->return = mosGetParam($_SERVER, 'HTTP_REFERER'); $exec->return_error = mosGetParam($_POST, 'return_error'); $exec->return_error or $exec->return_error = $params->get('return_error'); $exec->name = mosGetParam($_POST, 'name'); $exec->comment = trim(mosGetParam($_POST, 'comment')); $exec->error_key = mosGetParam($_POST, 'error_key'); $exec->error_key or $exec->error_key = $params->get('error_key'); $exec->publish = $params->get('immediate_publish') ? true : false; $exec->message = mosGetParam($_POST, 'message'); $exec->message or $exec->message = $params->get('message'); $exec->message_key = mosGetParam($_POST, 'message_key'); $exec->message_key or $exec->message_key = $params->get('message_key'); $exec->save(); break; default: header('HTTP/1.0 404 Not Found'); echo _NOT_EXIST; break; } } /** @var string of option */ var $option = ''; /** @var int of id */ var $id = 0; /** @var string of group */ var $group = ''; /** @var string of target */ var $target = ''; /** @var string of name */ var $name = ''; /** @var string of comment */ var $comment = ''; /** @var string of return url */ var $return = ''; /** @var string of return error url */ var $return_error = ''; /** @var string of error key */ var $error_key = ''; /** @var boolean of publish flag */ var $publish = ''; /** @var string of message */ var $message = ''; /** @var string of message key */ var $message_key = ''; /** * コンストラクタ */ function TASK_kingyoya_comment($option) { $this->option = $option; } /** * 登録処理 */ function save() { if (!$this->return) { trigger_error("Failed get return", E_USER_WARNING); mosNotAuth(); return; } $this->return_error or $this->return_error = $this->return; if (!$this->group) { trigger_error("Failed get group", E_USER_WARNING); mosNotAuth(); return; } if (!$this->target) { trigger_error("Failed get target", E_USER_WARNING); mosNotAuth(); return; } $error = array(); if (!$this->name) { $error[] = 'name'; } if (!$this->comment) { $error[] = 'comment'; } if ($error) { $return_error =& $this->return_error; $message_key_reg = preg_quote(urlencode($this->message_key)); $message_key_reg = "/(\?|\&){$message_key_reg}(=.*?)(\&|$)/"; if (preg_match($message_key_reg, $return_error, $matches)) { $replace = $matches[0] === '?' ? '?' : ''; $return_error = str_replace($matches[0], $replace, $return_error); } if ($this->error_key) { $error = urlencode(implode(',', $error)); $error_key = urlencode($this->error_key); $error_key_reg = preg_quote($error_key); $error_key_reg = "/(\?|\&){$error_key_reg}(=.*?)(\&|$)/"; if (preg_match($error_key_reg, $return_error, $matches)) { $search = "{$matches[1]}{$error_key}{$matches[2]}{$matches[3]}"; $replace = "{$matches[1]}{$error_key}=".$error."{$matches[3]}"; $return_error = str_replace($search, $replace, $return_error); } else { if (strpos('?', $return_error) === false) { $return_error .= '?'; } else { $return_error .= '&'; } $return_error .= urlencode($this->error_key).'='.$error; } } header('HTTP/1.0 303 See Other'); header("Location: {$return_error}"); exit; } $comment =& TASK_kingyoya_comment::get_class_object(); $comment->group = $this->group; $comment->target = $this->target; $comment->name = $this->name; $comment->comment = $this->comment; $comment->publish = $this->publish ? true : false; if (!$comment->check()) { trigger_error( "Failed check comment: ".$comment->getError() , E_USER_WARNING ); mosNotAuth(); return; } if (!$comment->store()) { trigger_error( "Failed store comment: ".$comment->getError() , E_USER_WARNING ); mosNotAuth(); return; } $return = $this->return; $error_key_reg = preg_quote(urlencode($this->error_key)); $error_key_reg = "/(\?|\&){$error_key_reg}(=.*?)(\&|$)/"; if (preg_match($error_key_reg, $return, $matches)) { $replace = $matches[0] === '?' ? '?' : ''; $return = str_replace($matches[0], $replace, $return); } if ($this->message && $this->message_key) { $message_key_reg = preg_quote(urlencode($this->message_key)); $message_key_reg = "/(\?|\&){$message_key_reg}(=.*?)(\&|$)/"; if (preg_match($message_key_reg, $return, $matches)) { $search = "{$matches[1]}{$this->message_key}{$matches[2]}{$matches[3]}"; $replace = "{$matches[1]}{$this->message_key}=".urlencode($this->message)."{$matches[3]}"; $return = str_replace($search, $replace, $return); } else { $message_key = urlencode($this->message_key); $message = urlencode($this->message); if (strpos('?', $return) === false) { $return .= '?'; } else { $return .= '&'; } $return .= "{$message_key}={$message}"; } } header('HTTP/1.0 303 See Other'); header("Location: {$return}"); exit; } /** * クラスをrequire する * @static */ function require_class() { global $_MAMBOTS; $_MAMBOTS->loadBotGroup('Kingyoya'); global $mainframe; require_once $mainframe->getPath('class'); } /** * クラスオブジェクトを取得する。 * @static */ function & get_class_object() { TASK_kingyoya_comment::require_class(); global $database; $class =& new mosKingyoyaComment($database); return $class; } } if ($option === 'com_kingyoya_comment') { TASK_kingyoya_comment::exec($option, ($task ? $task : 'view')); }