$wt->set_title("変愚蛮怒 スコア カスタム検索");
$fp = $wt->main_contents_fp();
-fwrite($fp, <<<EOM
+fwrite(
+ $fp,
+ <<<EOM
<h2>変愚蛮怒 スコア カスタム検索</h2>
<form action="score_ranking.php" method="GET">
<p>
print_select_form($fp, $defines['realm'], 'realm_id2');
fwrite($fp, "</p>\n");
-fwrite($fp, <<<EOM
+fwrite(
+ $fp,
+ <<<EOM
<p>
<label for="name">キャラクター名:</label>
<input type="text" name="name">
{
private static $sort_mode_list = ['default' => 'score', 'newcome'];
- public function __construct() {
+ public function __construct()
+ {
$this->dbh = new PDO('sqlite:db/score.db');
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
*/
public function set_sort_mode($mode)
{
- if ($mode !== NULL && in_array($mode, self::$sort_mode_list)) {
+ if ($mode !== null && in_array($mode, self::$sort_mode_list)) {
$this->sort_mode = $mode;
} else {
$this->sort_mode = self::$sort_mode_list['default'];
$from_date = filter_input(INPUT_GET, 'fd');
$to_date = filter_input(INPUT_GET, 'td');
- if ($from_date !== NULL && $to_date !== NULL &&
+ if ($from_date !== null && $to_date !== null &&
strlen($from_date) > 0 && strlen($to_date) > 0) {
$wheres[] = "(date >= date(:from_date) AND date < date(:to_date, '+1 days'))";
$params[":from_date"] = $from_date;
}
foreach (['race_id', 'class_id', 'personality_id'] as $key_column) {
- $val = filter_input(INPUT_GET, $key_column, FILTER_VALIDATE_INT);
+ $val = filter_input(INPUT_GET, $key_column, FILTER_VALIDATE_INT);
if ($val > 0) {
$wheres[] = "{$key_column} = :{$key_column}";
$params[":{$key_column}"] = $val;
}
foreach (['realm_id1', 'realm_id2'] as $idx => $key_column) {
- $val = filter_input(INPUT_GET, $key_column, FILTER_VALIDATE_INT);
+ $val = filter_input(INPUT_GET, $key_column, FILTER_VALIDATE_INT);
if ($val > 0) {
$seq = $idx + 1;
$wheres[] = "score_id IN (SELECT score_id FROM score_realms WHERE realm_id = :{$key_column} AND realm_seq = {$seq})";
foreach (['name'] as $key_column) {
$val = filter_input(INPUT_GET, $key_column);
$match_mode = filter_input(INPUT_GET, $key_column."_match");
- if ($val !== NULL && strlen($val) > 0) {
+ if ($val !== null && strlen($val) > 0) {
$wheres[] = ($match_mode == "strict") ? "{$key_column} = :{$key_column}" : "{$key_column} LIKE :{$key_column}";
$params[":{$key_column}"] = ($match_mode == "strict") ? $val : "%".$val."%";
}
}
foreach (['sex'] as $key_column) {
- $val = filter_input(INPUT_GET, $key_column, FILTER_VALIDATE_INT);
- if ($val !== FALSE && $val !== NULL) {
+ $val = filter_input(INPUT_GET, $key_column, FILTER_VALIDATE_INT);
+ if ($val !== false && $val !== null) {
$wheres[] = "{$key_column} = :{$key_column}";
$params[":{$key_column}"] = $val;
}
foreach (['killer'] as $key_column) {
$val = filter_input(INPUT_GET, $key_column);
- if ($val !== NULL && strlen($val) > 0) {
+ if ($val !== null && strlen($val) > 0) {
$wheres[] = "({$key_column} LIKE :{$key_column} OR {$key_column} = :{$key_column}1 OR {$key_column} = :{$key_column}2)";
$params[":{$key_column}"] = "%".$val."%";
$params[":{$key_column}1"] = "麻痺状態で".$val;
return $result;
}
- public function get_db_handle() {
+ public function get_db_handle()
+ {
return $this->dbh;
}
private function update_killers_cache_table()
{
$this->dbh->exec("DROP TABLE IF EXISTS killers_cache");
- $this->dbh->exec(<<<EOM
+ $this->dbh->exec(
+ <<<EOM
CREATE TABLE
killers_cache
AS
* 種族・職業・性格について各種統計情報を取得しキャッシュテーブルに保存する
* 通常の統計情報の取得はこのキャッシュテーブルから行う
*/
- private function update_statistics_cache_tables() {
+ private function update_statistics_cache_tables()
+ {
$statistics_list = ['race', 'class', 'personality'];
foreach ($statistics_list as $stat) {
* 魔法領域1・魔法領域2について各種統計情報を取得しキャッシュテーブルに保存する
* 通常の統計情報の取得はこのキャッシュテーブルから行う
*/
- private function update_realm_statistics_cache_tables() {
+ private function update_realm_statistics_cache_tables()
+ {
foreach (range(1, 2) as $seq) {
$table_name = "realm{$seq}_statistics";
$this->dbh->exec("DROP TABLE IF EXISTS ".$table_name);
*
* @return array 統計情報
*/
- public function get_statistics_tables($sort_key_column) {
+ public function get_statistics_tables($sort_key_column)
+ {
try {
$this->dbh->beginTransaction();
if (!$this->get_cache_status('statistics_cache')) {
public function create_cache_status_table()
{
- $this->dbh->exec(<<<EOM
+ $this->dbh->exec(
+ <<<EOM
CREATE TABLE cache_status_table
(table_name TEXT PRIMARY KEY,
cached BOOLEAN)
try {
$this->dbh->beginTransaction();
- if ($insert_stmt->execute($score_data['character_info']) === FALSE ||
+ if ($insert_stmt->execute($score_data['character_info']) === false ||
$insert_stmt->rowCount() !== 1) {
$dbh->rollBack();
- return FALSE;
+ return false;
}
// NOTE: score_idはINTEGER PRIMARY KEYなのでROWIDを参照している
$score_id = $this->dbh->lastInsertId();
foreach ($score_data['realm_info'] as $realm_seq => $realm_name) {
- if ($realm_insert_stmt->execute([$score_id, $realm_seq + 1, $realm_name]) === FALSE ||
+ if ($realm_insert_stmt->execute([$score_id, $realm_seq + 1, $realm_name]) === false ||
$realm_insert_stmt->rowCount() !== 1) {
$dbh->rollBack();
- return FALSE;
+ return false;
}
}
$dbh->rollBack();
}
- return FALSE;
+ return false;
}
*/
public function update_dead_place($score_id, $dead_place)
{
- if ($dead_place === FALSE) {
- return FALSE;
+ if ($dead_place === false) {
+ return false;
}
$stmt = $this->dbh->prepare(
<<<EOM
<?php
class DumpFile
{
- public function __construct($score_id) {
+ public function __construct($score_id)
+ {
$this->score_id = $score_id;
- $this->dump_lines = NULL;
+ $this->dump_lines = null;
}
header("Etag: ".$etag);
header("Content-Type: ".$content_type);
- if ($content_encoding !== NULL) {
+ if ($content_encoding !== null) {
header("Content-Encoding: ".$content_encoding);
echo $contents;
} else {
public function save($dir, $ext, $contents)
{
- if ($contents === FALSE) return;
+ if ($contents === false) {
+ return;
+ }
umask(2); // Group書き込み権限許可
$dirname = dirname($filename);
if (!file_exists($dirname)) {
- mkdir($dirname, 02775, TRUE);
+ mkdir($dirname, 02775, true);
}
$zp = gzopen($filename, "w9");
*/
private function readlines()
{
- if ($this->dump_lines !== NULL) {
- return TRUE;
+ if ($this->dump_lines !== null) {
+ return true;
}
$lines = gzfile($this->get_filename('dumps', 'txt'));
- if ($lines !== FALSE) {
+ if ($lines !== false) {
$this->dump_lines = $lines;
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
*/
public function get_last_message()
{
- if ($this->readlines() === FALSE) {
+ if ($this->readlines() === false) {
return [];
}
- $in_message = FALSE;
+ $in_message = false;
$result = [];
foreach ($this->dump_lines as $line) {
if (preg_match('/^\s*\[(.*)\]\s*$/u', $line, $matches)) {
if ($matches[1] == '*勝利*メッセージ' ||
$matches[1] == '死ぬ直前のメッセージ') {
- $in_message = TRUE;
- }
- else if ($in_message) {
+ $in_message = true;
+ } elseif ($in_message) {
break;
}
}
*/
public function get_death_reason_detail()
{
- if ($this->readlines() === FALSE) {
- return FALSE;
+ if ($this->readlines() === false) {
+ return false;
}
$death_reason_lines = array_slice($this->dump_lines, 30, 3);
if (preg_match("/^…あなたは、?(.+)。/u", $death_reason, $matches)) {
return $matches[1];
} else {
- return FALSE;
+ return false;
}
}
*/
public function get_dead_place()
{
-
$death_reason_detail = $this->get_death_reason_detail();
- if ($death_reason_detail === FALSE) {
- return FALSE;
+ if ($death_reason_detail === false) {
+ return false;
}
$places = implode("|", [
"階", "荒野", "地上", "街",
"クエスト「.+」", "クエスト",
]);
- if (preg_match("/^(.*(?:{$places})\s*)で.+$/u",
- $death_reason_detail, $matches)) {
+ if (preg_match(
+ "/^(.*(?:{$places})\s*)で.+$/u",
+ $death_reason_detail,
+ $matches
+ )) {
return $matches[1];
} else {
- return FALSE;
+ return false;
}
}
private static function browser_accept_encodings()
{
$accept_encoding = filter_input(INPUT_SERVER, 'HTTP_ACCEPT_ENCODING');
- if ($accept_encoding == NULL) return [];
+ if ($accept_encoding == null) {
+ return [];
+ }
return array_map('trim', explode(",", $accept_encoding));
}
{
$supported_gzip_encodings = array_intersect(
self::browser_accept_encodings(),
- ['gzip', 'x-gzip']);
+ ['gzip', 'x-gzip']
+ );
return array_shift($supported_gzip_encodings);
}
-
}
$dump_file = new DumpFile($s['score_id']);
$death_reason_detail = $dump_file->get_death_reason_detail();
- if ($death_reason_detail === FALSE) {
+ if ($death_reason_detail === false) {
$death_reason_detail = "{$s['death_reason']} @{$s['depth']}F";
}
$wt->set_title("変愚蛮怒 スコア 死因ランキング");
$fp = $wt->main_contents_fp();
-fwrite($fp, <<<EOM
+fwrite(
+ $fp,
+ <<<EOM
<h2>変愚蛮怒 死因ランキング</h2>
<table class="score">
<thead>
foreach ($killers as $k) {
//$freeze = $k['killer_count_freeze'] > 0 ? "(".$k['killer_count_freeze'].")" : "";
$killer_name = h($k['killer_name']);
- fwrite($fp, <<<EOM
+ fwrite(
+ $fp,
+ <<<EOM
<tr>
<td class="number">{$k['killer_count_total']}</td>
<td class="number">{$k['killer_count_freeze']}</td>
function print_popularity_table($fp, $stat, $id_name, $name)
{
- fwrite($fp, <<<EOM
+ fwrite(
+ $fp,
+ <<<EOM
<div id="{$id_name}">
<table class="tablesorter score statistics_table">
<thead>
EOM
);
-
+
foreach ([
'計', '男性', '女性', '勝利', '平均スコア', '最大スコア',
] as $name) {
foreach ($stat as $k => $s) {
$name_link = "<a href='score_ranking.php?{$id_name}={$s['id']}'>{$s['name']}</a></td>";
- fwrite($fp, <<<EOM
+ fwrite(
+ $fp,
+ <<<EOM
<tr>
<td>$name_link</td>
<td class="number">{$s['total_count']}</td>
// 職業ごとにテーブルを表示
foreach ($class_realm_stat_list as $class_id => $class_realm_stat) {
- if (count($class_realm_stat) <= 1) continue; // 領域固定の職業は飛ばす
+ if (count($class_realm_stat) <= 1) {
+ continue; // 領域固定の職業は飛ばす
+ }
$class_name = $class_realm_stat[0]['class_name'];
- fwrite($fp, <<<EOM
+ fwrite(
+ $fp,
+ <<<EOM
<table class="tablesorter score statistics_table" id="${id_name}">
<thead>
<tr>
foreach ($class_realm_stat as $realm) {
$name_link = "<a href='score_ranking.php?class_id={$class_id}&{$id_name}={$realm['realm_id']}'>{$realm['realm_name']}</a></td>";
- fwrite($fp, <<<EOM
+ fwrite(
+ $fp,
+ <<<EOM
<tr>
<td>$name_link</td>
<td class="number">{$realm['total_count']}</td>
$fp = $wt->main_contents_fp();
fwrite($fp, "<h2>人気のある種族・職業・性格・魔法領域</h2>\n");
//fprintf($fp, "<small>(%.2f 秒)</small>", $query_time);
-fwrite($fp, <<<EOM
+fwrite(
+ $fp,
+ <<<EOM
<nobr>[ <a href="javascript:void(0)" class="table_select" id="race_id">種族</a> | <a href="javascript:void(0)" class="table_select" id="class_id">職業</a> | <a href="javascript:void(0)" class="table_select" id="personality_id">性格</a> ] [ <a href="javascript:void(0)" class="table_select" id="realm_id1">魔法領域1</a> | <a href="javascript:void(0)" class="table_select" id="realm_id2">魔法領域2</a> ]</nobr>
EOM
* @return string|false 送られてきたスコアの、PHPのマルチバイト文字処理における文字エンコーディングを表す文字列
* 取得できなかった場合はFALSE
*/
-function get_mb_encoding(){
+function get_mb_encoding()
+{
$content_type = filter_input(INPUT_SERVER, 'CONTENT_TYPE');
- if ($content_type == NULL) return FALSE;
+ if ($content_type == null) {
+ return false;
+ }
$s = explode(';', $content_type);
if (count($s) != 2 ||
$s[0] !== "text/plain" ||
- strpos(trim($s[1]), "charset=") !== 0) return FALSE;
+ strpos(trim($s[1]), "charset=") !== 0) {
+ return false;
+ }
$c = explode('=', $s[1]);
case "utf-8":
return "UTF-8";
default:
- return FALSE;
+ return false;
}
}
$dump_info_end_line = array_search('-----charcter dump-----', $recv_lines);
$dump_txt_end_line = array_search('-----screen shot-----', $recv_lines);
- if ($dump_info_end_line === FALSE) return FALSE;
+ if ($dump_info_end_line === false) {
+ return false;
+ }
$info_lines = array_slice($recv_lines, 0, $dump_info_end_line);
$dump_lines = array_slice(
$recv_lines,
$dump_info_end_line + 1,
- $dump_txt_end_line ? $dump_txt_end_line - $dump_info_end_line - 1: NULL
+ $dump_txt_end_line ? $dump_txt_end_line - $dump_info_end_line - 1: null
);
$screen_lines = $dump_txt_end_line ?
array_slice(
$recv_lines,
$dump_txt_end_line + 1,
- NULL
- ) : FALSE;
+ null
+ ) : false;
return [$info_lines, $dump_lines, $screen_lines];
}
$info = [];
foreach ($info_lines as $l) {
$splitpos = strpos($l, ':');
- if ($splitpos !== FALSE) {
+ if ($splitpos !== false) {
$key = substr($l, 0, $splitpos);
$val = substr($l, $splitpos + 1);
$info[$key] = trim($val);
$realm_info_array = array_values(
array_filter(
[$info['realm1'], $info['realm2']],
- function($v) {return $v !== '魔法なし';})
+ function ($v) {
+ return $v !== '魔法なし';
+ }
+ )
);
return [
*/
function validate_screen_dump($screen_dump_lines)
{
- if ($screen_dump_lines === FALSE) {
- return FALSE;
+ if ($screen_dump_lines === false) {
+ return false;
}
$allow_tags = ['html', 'body', 'pre', 'font'];
- $is_valid = TRUE;
+ $is_valid = true;
foreach ($screen_dump_lines as $line) {
if (preg_match_all("|</?([^>\s]+)(\s*[^>]+)?>|", $line, $matches, PREG_SET_ORDER) > 0) {
- $invalid_tag_matches = array_filter($matches, function($m) use($allow_tags) {
- return !in_array($m[1], $allow_tags);
- });
+ $invalid_tag_matches = array_filter(
+ $matches,
+ function ($m) use ($allow_tags) {
+ return !in_array($m[1], $allow_tags);
+ }
+ );
if (count($invalid_tag_matches) > 0) {
- $is_valid = FALSE;
+ $is_valid = false;
}
}
}
$recv_encoding = get_mb_encoding();
-if ($recv_encoding === FALSE) {
+if ($recv_encoding === false) {
exit;
}
$recv_contents = mb_convert_encoding($recv_contents, "UTF-8", $recv_encoding);
$split_contents = split_recv_contents($recv_contents);
-if ($split_contents === FALSE) {
+if ($split_contents === false) {
exit;
}
$db = new ScoreDB();
$score_id = $db->register_new_score(create_db_insert_score_data($char_info));
-if ($score_id === FALSE) {
+if ($score_id === false) {
exit;
}
*/
function print_navi_page_table($fp, $pageinfo)
{
- if (count($pageinfo['navi_list']) <= 1) return;
+ if (count($pageinfo['navi_list']) <= 1) {
+ return;
+ }
$href_base = filter_input(INPUT_SERVER, 'SCRIPT_NAME')."?"
.preg_replace('/(&?start=\w+)/', '', filter_input(INPUT_SERVER, 'QUERY_STRING'));
- if (strpos($href_base, "?") === FALSE) {
+ if (strpos($href_base, "?") === false) {
$href_base .= "?";
}
*/
function print_score_table($fp, $scores, $rank_start)
{
- fwrite($fp, <<<EOM
+ fwrite(
+ $fp,
+ <<<EOM
<table class="score">
<thead>
<tr>
);
fwrite($fp, "<tbody>\n");
- foreach($scores as $idx => $score) {
+ foreach ($scores as $idx => $score) {
$rank = $rank_start + $idx + 1;
$date = substr($score['date'], 0, 10); // 日時から日付部分を取り出す
$sex_str = $score['sex'] ? "男" : "女";
if ($dumpfile->exists('dumps', 'txt')) {
$name = "<a href=\"show_dump.php?score_id={$score['score_id']}\">{$name}</a>";
}
- fwrite($fp, <<<EOM
+ fwrite(
+ $fp,
+ <<<EOM
<tr>
<td>$rank</td>
<td class="number">{$score['score']}</td>
$wt->add_head_contents('<link rel="stylesheet" type="text/css" href="css/score-table.css">');
$fp = $wt->main_contents_fp();
fprintf($fp, "<h2>変愚蛮怒 歴代スコア (%s)</h2>\n", $db->get_sort_mode_name());
-fprintf($fp, <<<EOM
+fprintf(
+ $fp,
+ <<<EOM
<div align="right">
<small>
件数 %d 件 (%.2f 秒)
</div>
EOM
- ,$search_result['total_data_count'], $search_result['elapsed_time']
+ ,
+ $search_result['total_data_count'],
+ $search_result['elapsed_time']
);
print_navi_page_table($fp, $pageinfo);
require_once "dump_file.inc";
$score_id = filter_input(INPUT_GET, 'score_id', FILTER_VALIDATE_INT);
-if ($score_id === FALSE || $score_id === NULL) {
+if ($score_id === false || $score_id === null) {
http_response_code(404);
} else {
$dump_file = new DumpFile($score_id);
require_once "dump_file.inc";
$score_id = filter_input(INPUT_GET, 'score_id', FILTER_VALIDATE_INT);
-if ($score_id === FALSE || $score_id === NULL) {
+if ($score_id === false || $score_id === null) {
http_response_code(404);
} else {
$dump_file = new DumpFile($score_id);
{
private static $template_dir = "../template";
- public function __construct() {
+ public function __construct()
+ {
$this->template = file(self::$template_dir."/template.html");
$this->head = file(self::$template_dir."/head.html");
$this->header = file(self::$template_dir."/header.html");
/**
* Webページを出力する
*/
- public function print_page() {
+ public function print_page()
+ {
rewind($this->main_contents_fp);
$this->main_contents = [stream_get_contents($this->main_contents_fp)];
foreach ($this->template as $line) {
}
}
- private static function print_page_sub($lines) {
- foreach ($lines as $line){
+ private static function print_page_sub($lines)
+ {
+ foreach ($lines as $line) {
echo $line;
- }
+ }
}
}