From 47f2f0d82ce861d130f6e844f35e42bd8a10f418 Mon Sep 17 00:00:00 2001 From: takashi Date: Mon, 4 Sep 2023 12:56:01 +0000 Subject: [PATCH] Add deleating future-post. --- data-post.php | 28 +++++++++++++++++----------- public/post-delete/index.php | 2 +- public/user/index.php | 1 + view/post-common.php | 3 +++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/data-post.php b/data-post.php index 4d69e35..b79f6e2 100644 --- a/data-post.php +++ b/data-post.php @@ -165,6 +165,7 @@ function load_post_by_id($id) { } function search_post($options = []) { + $includes_future = $options['includes_future'] ?? false; $pagesize = $options['pagesize'] ?? 0; $has_paging = $pagesize > 0; $thread = false; @@ -188,17 +189,18 @@ function search_post($options = []) { $key = null; $value = null; - $now = date('Y-m-d\\TH:i:s\\Z'); $files = glob(POST_DIR . $pattern); - $files = array_filter( - $files, - function ($v) use($now) { - $datetime = substr(basename($v), 0, 20); - return $datetime <= $now; - }, - ARRAY_FILTER_USE_BOTH - ); + if (!$includes_future) { + $files = array_filter( + $files, + function ($v) use($now) { + $datetime = substr(basename($v), 0, 20); + return $datetime <= $now; + }, + ARRAY_FILTER_USE_BOTH + ); + } if (!$thread) { $files = array_reverse($files); } @@ -330,7 +332,7 @@ function save_uploaded_image($key, $attachment_id) { return []; } -function delete_post($id) { +function delete_post($id, $hard = false) { $files = glob(POST_DIR . '2*Z*.id' . $id . '.*.txt'); if (sizeof($files) !== 1) { return ['書き込みのファイルが存在しない。']; } @@ -349,7 +351,11 @@ function delete_post($id) { } } - $result = file_put_contents($filepath, '', LOCK_EX); + if ($hard) { + $result = unlink($filepath); + } else { + $result = file_put_contents($filepath, '', LOCK_EX); + } if ($result === false) { return ['書き込みの削除に失敗。']; } @chmod($filepath, 0600); diff --git a/public/post-delete/index.php b/public/post-delete/index.php index 5f1036b..17d2151 100644 --- a/public/post-delete/index.php +++ b/public/post-delete/index.php @@ -32,7 +32,7 @@ function do_post() { // 削除済み投稿はuseridが空になるからここにくる。 if ($post['userid'] !== ($_SESSION['user']['id'] ?? '')) { return on_error(403, ['権限無し。']); } - $errors = delete_post($id); + $errors = delete_post($id, $post['is_future'] ?? false); if ($errors) { return on_error('500', $errors); } $_SESSION['messages'] = ['書き込みを削除しました。']; diff --git a/public/user/index.php b/public/user/index.php index 30dcc56..c3064e4 100644 --- a/public/user/index.php +++ b/public/user/index.php @@ -24,6 +24,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { 'page' => $page, 'pagesize' => POSTS_PER_PAGE, 'pager_prefix' => "?id={$id}&page=", + 'includes_future' => ($id === ($_SESSION['user']['id'] ?? '')), ]); $view['post_list'] = $result['post_list']; $view['post_count'] = $result['total']; diff --git a/view/post-common.php b/view/post-common.php index d73cf37..347556c 100644 --- a/view/post-common.php +++ b/view/post-common.php @@ -55,6 +55,9 @@ function view_post($post, $options = []) { $html_attachment_items = join(PHP_EOL, $attachment_items); ?> 0 ? ' id="N' . $res_num . '"' : '') ?>> + +
【予約投稿】
+ ''): ?>
件名: