フォーク元 tak4/bibis
Add deleating future-post.
このコミットが含まれているのは:
コミット
47f2f0d82c
|
@ -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);
|
||||
|
|
|
@ -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'] = ['書き込みを削除しました。'];
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -55,6 +55,9 @@ function view_post($post, $options = []) {
|
|||
$html_attachment_items = join(PHP_EOL, $attachment_items);
|
||||
?>
|
||||
<dl<?= ($res_num > 0 ? ' id="N' . $res_num . '"' : '') ?>>
|
||||
<?php if ($post['is_future'] ?? false): ?>
|
||||
<dt><strong>【予約投稿】</strong></dt>
|
||||
<?php endif; ?>
|
||||
<?php if (!$is_single && $title > ''): ?>
|
||||
<dt>件名:<b><?= $title ?></b></dt>
|
||||
<?php endif; ?>
|
||||
|
|
読み込み中…
新しいイシューから参照