From 0ba35651cde09a5b27b0a0139f37747766909921 Mon Sep 17 00:00:00 2001 From: Habu Date: Fri, 30 Mar 2018 20:32:13 +0900 Subject: [PATCH] =?utf8?q?[feature]=E6=96=B0=E7=9D=80RSS=E3=81=AE=E6=AD=BB?= =?utf8?q?=E5=9B=A0=E3=81=AE=E8=A8=98=E8=BF=B0=E3=82=92=E8=A9=B3=E7=B4=B0?= =?utf8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- score/dump_file.inc | 54 +++++++++++++++++++++++++++++++++++++++++++++++----- score/feed_maker.inc | 12 +++++++++--- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/score/dump_file.inc b/score/dump_file.inc index 526009d..c89bd47 100644 --- a/score/dump_file.inc +++ b/score/dump_file.inc @@ -3,6 +3,7 @@ class DumpFile { public function __construct($score_id) { $this->score_id = $score_id; + $this->dump_lines = NULL; } @@ -77,20 +78,41 @@ class DumpFile /** + * キャラクタダンプを配列に読み込む + * 読み込んだ配列はメンバ変数dump_linesに格納 + * + * @return boolean 読み込みに成功した場合TRUE、失敗した場合FALSE + */ + public function readlines() + { + if ($this->dump_lines !== NULL) { + return TRUE; + } + + $lines = gzfile($this->get_filename('dumps', 'txt')); + if ($lines !== FALSE) { + $this->dump_lines = $lines; + return TRUE; + } + + return FALSE; + } + + + /** * キャラクタダンプの死ぬ直前のメッセージもしくは勝利メッセージを取得する * * @return array 死ぬ直前のメッセージもしくは勝利メッセージを1行1要素にした文字列の配列 */ public function get_last_message() { - $zp = gzopen($this->get_filename('dumps', 'txt'), 'r'); - if ($zp === FALSE) return []; + if ($this->readlines() === FALSE) { + return []; + } $in_message = FALSE; $result = []; - while (!gzeof($zp)) { - $line = gzgets($zp); - + foreach ($this->dump_lines as $line) { if (preg_match('/^\s*\[(.*)\]\s*$/u', $line, $matches)) { if ($matches[1] == '*勝利*メッセージ' || $matches[1] == '死ぬ直前のメッセージ') { @@ -109,6 +131,28 @@ class DumpFile return $result; } + + /** + * キャラクタダンプから死因の詳細を得る + * + * @return string 死因の詳細を表す文字列 + */ + public function get_death_reason_detail() + { + if ($this->readlines() === FALSE) { + return FALSE; + } + + $death_reason_lines = array_slice($this->dump_lines, 30, 3); + $death_reason = implode("", array_map('trim', $death_reason_lines)); + + if (preg_match("/^…あなたは、?(.+)。/u", $death_reason, $matches)) { + return $matches[1]; + } else { + return FALSE; + } + } + private static function browser_accept_encodings() { $accept_encoding = filter_input(INPUT_SERVER, 'HTTP_ACCEPT_ENCODING'); diff --git a/score/feed_maker.inc b/score/feed_maker.inc index 8a2cc51..8e3a1a7 100644 --- a/score/feed_maker.inc +++ b/score/feed_maker.inc @@ -1,5 +1,6 @@ createNewItem(); + $dump_file = new DumpFile($s['score_id']); + $death_reason_detail = $dump_file->get_death_reason_detail(); + if ($death_reason_detail === FALSE) { + $death_reason_detail = "{$s['death_reason']} @{$s['depth']}F"; + } + $dump_url = "${base_url}/show_dump.php?score_id={$s['score_id']}"; - $item->setTitle("{$s['personality_name']}{$s['name']} Score:{$s['score']} {$s['race_name']} {$s['class_name']} {$s['death_reason']} @{$s['depth']}F"); + $item->setTitle("{$s['personality_name']}{$s['name']} Score:{$s['score']} {$s['race_name']} {$s['class_name']} {$death_reason_detail}"); $item->setLink($dump_url); $item->setDate($s['date']); - $dump_file = new DumpFile($s['score_id']); $contents = implode( '', array_map(function ($v) { - return htmlentities($v).'
'; + return h($v).'
'; }, $dump_file->get_last_message()) ); $item->setContent($contents); -- 2.11.0