/** * エラーメッセージを表示 * @param string $msg エラーメッセージ * @param string $title エラーのタイトル * @param int $http_code 出力するヘッダー */ public static function dieMessage($msg = '', $error_title = '', $http_code = Response::STATUS_CODE_200) { global $_string, $_title, $_button, $vars; // エラーメッセージの内容 if (!isset($vars['ajax'])) { $body[] = '<p>[ '; if (isset($vars['page']) && !empty($vars['page'])) { $body[] = '<a href="' . Factory::Wiki($vars['page'])->uri() . '">' . $_button['back'] . '</a> | '; $body[] = '<a href="' . Router::get_cmd_uri('edit', $vars['page']) . '">' . $_button['try_edit'] . '</a> | '; } $body[] = '<a href="' . Router::get_cmd_uri() . '">' . $_button['return_home'] . '</a> ]</p>'; } $body[] = '<p class="alert alert-warning"><span class="fa fa-ban"></span> <strong>' . $_title['error'] . '</strong>'; $body[] = PKWK_WARNING !== true || empty($msg) ? $msg = $_string['error_msg'] : $msg; $body[] = '</p>'; if (DEBUG) { $body[] = '<div class="panel panel-info">'; $body[] = '<div class="panel-heading"><span class="fa fa-info-circle"></span> Back Trace</div>'; $body[] = '<div class="panel-body">'; $body[] = '<ol>'; foreach (debug_backtrace() as $k => $v) { if ($k < 2) { continue; } array_walk($v['args'], function ($item, $key) { $item = var_export($item, true); }); $body[] = '<li>' . (isset($v['file']) ? $v['file'] : '?') . '(<var>' . (isset($v['line']) ? $v['line'] : '?') . '</var>):<br /><code>' . (isset($v['class']) ? '<strong>' . $v['class'] . '</strong>->' : '') . $v['function'] . '(<var>' . implode(', ', $v['args']) . '</var>)</code></li>' . "\n"; } $body[] = '</ol>'; $body[] = '</div>'; $body[] = '</div>'; } if (empty($error_title)) { $error_title = $_title['error']; } if (isset($vars['ajax'])) { $headers = Header::getHeaders('application/json'); Header::writeResponse($headers, $http_code, Json::encode(array('posted' => false, 'title' => $error_title, 'body' => join("\n", $body), 'taketime' => Time::getTakeTime()))); } else { new Render($error_title, join("\n", $body), $http_code); die(join("\n", $body)); } die; }
function plugin_edit_honeypot() { if (isset($vars['ajax'])) { $headers = Header::getHeaders('application/json'); Header::writeResponse($headers, 200, Json::encode(array('posted' => false, 'message' => 'Sorry your post has been prohibited.', 'taketime' => Time::getTakeTime()))); exit; } // SPAM Logging Utility::dump(); // Same as "Cancel" action return plugin_edit_cancel(); }
/** * コンストラクタ * @param string $title 題目 * @param string $body 内容 */ public function __construct($title, $body, $http_code = Response::STATUS_CODE_200) { global $vars, $lastmod; $this->page = isset($vars['page']) ? $vars['page'] : null; $this->ajax = isset($vars['ajax']) ? $vars['ajax'] : null; $this->cmd = isset($vars['cmd']) ? $vars['cmd'] : 'read'; // ※通常は空にならない $this->wiki = !empty($this->page) ? Factory::Wiki($this->page) : null; $this->title = $title; $this->body = $body; switch ($this->ajax) { case 'json': $content_type = 'application/json'; $content = Json::encode(array('title' => $this->title, 'body' => $this->body, 'process_time' => Time::getTakeTime())); break; case 'xml': $content_type = 'application/xml'; $content = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . "\n" . '<response>' . "\n" . '<title>' . $this->title . '</title>' . "\n" . '<body><![CDATA[' . $this->body . ']]></body>' . "\n" . '<process_time>' . Time::getTakeTime() . '</process_time>' . "\n" . '</response>'; break; case 'raw': $content_type = 'text/plain'; $content = $this->body; break; default: // 厳格にXHTMLとして出力する場合は、ブラウザの対応状況を読んでapplication/xhtml+xmlを出力 $content_type = self::USE_STRICT_XHTML === TRUE && strstr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') !== false ? 'application/xhtml+xml' : 'text/html'; $content = self::getContent(); break; } if (empty($this->page) || !$lastmod) { $headers = Header::getHeaders($content_type); } else { // ページ名が定義されている場合、最終更新日時をヘッダーに追加 $headers = Header::getHeaders($content_type, $this->wiki->time()); } Header::writeResponse($headers, $http_code, $content); }