Ajax 用の呼出プログラム作成
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
const LOG_PATH = '../log.txt';
|
||||
|
||||
header ('Content-Type: application/json; charset=UTF-8');
|
||||
|
||||
$log_data = [];
|
||||
|
||||
$page = (int) (filter_input (INPUT_POST, 'p') ?? 1);
|
||||
$length = (int) (filter_input (INPUT_POST, 'max') ?? 20);
|
||||
$asc = (int) (filter_input (INPUT_POST, 'asc') ?? 0) !== 0;
|
||||
$keyword = trim (filter_input (INPUT_POST, 'q') ?? '');
|
||||
|
||||
$date_start = filter_input (INPUT_POST, 'start');
|
||||
$date_end = filter_input (INPUT_POST, 'end');
|
||||
|
||||
$f = fopen (LOG_PATH, 'r');
|
||||
|
||||
if ($f !== false)
|
||||
{
|
||||
while (($dt = fgetcsv ($f, 0, "\t")) !== false)
|
||||
{
|
||||
$chat_info = json_decode ($dt[1]);
|
||||
|
||||
$log_data[] = ['dateTime' => $dt[0],
|
||||
'chatIcon' => $chat_info -> author -> imageUrl,
|
||||
'chatName' => htmlspecialchars ($chat_info -> author -> name),
|
||||
'chatMessage' => htmlspecialchars ($chat_info -> message),
|
||||
'answer' => htmlspecialchars ($dt[2])];
|
||||
}
|
||||
}
|
||||
|
||||
fclose ($f);
|
||||
|
||||
unset ($f);
|
||||
|
||||
if ($keyword !== '')
|
||||
{
|
||||
$log_data = array_filter ($log_data, fn ($row) => (
|
||||
strpos (($row['chatName'] . "\n" . $row['chatMessage'] . "\n"
|
||||
. $row['answer']),
|
||||
$keyword)
|
||||
!== false));
|
||||
}
|
||||
|
||||
if ($date_start)
|
||||
{
|
||||
$log_data = array_filter ($log_data, fn ($row) => (
|
||||
substr ($row['dateTime'], 0, 10) >= $date_start));
|
||||
}
|
||||
|
||||
if ($date_end)
|
||||
{
|
||||
$log_data = array_filter ($log_data, fn ($row) => (
|
||||
substr ($row['dateTime'], 0, 10) <= $date_end));
|
||||
}
|
||||
|
||||
$pages_max = (int) ((count ($log_data) - 1) / $length) + 1;
|
||||
|
||||
if (!($asc))
|
||||
$log_data = array_reverse ($log_data);
|
||||
|
||||
$log_data = array_slice ($log_data, ($page - 1) * $length, $length, true);
|
||||
|
||||
echo json_encode ($log_data);
|
||||
|
||||
Reference in New Issue
Block a user