From 88a92f745d6e04a1b72ba5101cdfd00b222926a0 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 18 Jun 2022 13:16:36 +0800 Subject: [PATCH] add topic reply notice --- app/Models/Forum.php | 10 ++++++++ app/Models/Topic.php | 19 +++++++++++++++ app/Models/TorrentOperationLog.php | 3 ++- include/constants.php | 2 +- public/forums.php | 38 +++++++++++++++++++++++++++++- public/takeedit.php | 3 ++- resources/lang/en/forum.php | 12 ++++++++++ resources/lang/zh_CN/forum.php | 12 ++++++++++ resources/lang/zh_TW/forum.php | 12 ++++++++++ 9 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 app/Models/Forum.php create mode 100644 app/Models/Topic.php create mode 100644 resources/lang/en/forum.php create mode 100644 resources/lang/zh_CN/forum.php create mode 100644 resources/lang/zh_TW/forum.php diff --git a/app/Models/Forum.php b/app/Models/Forum.php new file mode 100644 index 000000000..057fb8ba4 --- /dev/null +++ b/app/Models/Forum.php @@ -0,0 +1,10 @@ +belongsTo(User::class, 'userid'); + } + + public function forum() + { + return $this->belongsTo(Forum::class. 'forumid'); + } +} diff --git a/app/Models/TorrentOperationLog.php b/app/Models/TorrentOperationLog.php index 7b089adbb..62254082f 100644 --- a/app/Models/TorrentOperationLog.php +++ b/app/Models/TorrentOperationLog.php @@ -57,7 +57,7 @@ private static function notifyUser(self $torrentOperationLog) $subject = nexus_trans("torrent.operation_log.$actionType.notify_subject", [], $locale); $msg = nexus_trans("torrent.operation_log.$actionType.notify_msg", [ 'torrent_name' => $torrentOperationLog->torrent->name, - 'detail_url' => sprintf('%s/details.php?id=%s', getSchemeAndHttpHost(), $torrentOperationLog->torrent_id), + 'detail_url' => sprintf('details.php?id=%s', $torrentOperationLog->torrent_id), 'operator' => $torrentOperationLog->user->username, 'reason' => $torrentOperationLog->comment, ], $locale); @@ -70,5 +70,6 @@ private static function notifyUser(self $torrentOperationLog) ]; Message::query()->insert($message); NexusDB::cache_del("user_{$receiver->id}_unread_message_count"); + NexusDB::cache_del("user_{$receiver->id}_inbox_count"); } } diff --git a/include/constants.php b/include/constants.php index 1f49a6f8e..61b5edfa9 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ delete_value('post_'.$postid.'_content'); + //send pm + $topicInfo = \App\Models\Topic::query()->findOrFail($topicid); + $postInfo = \App\Models\Post::query()->findOrFail($id); + $postUrl = sprintf('[url=forums.php?action=viewtopic&topicid=%s&page=p%s#pid%s]%s[/url]', $topicid, $id, $id, $topicInfo->subject); + if ($postInfo->userid != $CURUSER['id']) { + $receiver = $postInfo->user; + $locale = $receiver->locale; + $notify = [ + 'sender' => 0, + 'receiver' => $receiver->id, + 'subject' => nexus_trans('forum.post.edited_notify_subject', [], $locale), + 'msg' => nexus_trans('forum.post.edited_notify_body', ['topic_subject' => $postUrl, 'editor' => $CURUSER['username']], $locale), + 'added' => now(), + ]; + \App\Models\Message::query()->insert($notify); + \Nexus\Database\NexusDB::cache_del("user_{$postInfo->userid}_unread_message_count"); + \Nexus\Database\NexusDB::cache_del("user_{$postInfo->userid}_inbox_count"); + } } else { @@ -436,6 +454,24 @@ function insert_compose_frame($id, $type = 'new') sql_query("INSERT INTO posts (topicid, userid, added, body, ori_body) VALUES ($topicid, $userid, ".sqlesc($date).", ".sqlesc($body).", ".sqlesc($body).")") or sqlerr(__FILE__, __LINE__); $postid = mysql_insert_id() or die($lang_forums['std_post_id_not_available']); + //send pm + $topicInfo = \App\Models\Topic::query()->findOrFail($topicid); + $postUrl = sprintf('[url=forums.php?action=viewtopic&topicid=%s&page=p%s#pid%s]%s[/url]', $topicid, $postid, $postid, $topicInfo->subject); + if ($type == 'reply' && $topicInfo->userid != $CURUSER['id']) { + $receiver = $topicInfo->user; + $locale = $receiver->locale; + $notify = [ + 'sender' => 0, + 'receiver' => $receiver->id, + 'subject' => nexus_trans('forum.topic.replied_notify_subject', [], $locale), + 'msg' => nexus_trans('forum.topic.replied_notify_body', ['topic_subject' => $postUrl], $locale), + 'added' => now(), + ]; + \App\Models\Message::query()->insert($notify); + \Nexus\Database\NexusDB::cache_del("user_{$topicInfo->userid}_unread_message_count"); + \Nexus\Database\NexusDB::cache_del("user_{$topicInfo->userid}_inbox_count"); + } + $Cache->delete_value('forum_'.$forumid.'_post_'.$today_date.'_count'); $Cache->delete_value('today_'.$today_date.'_posts_count'); $Cache->delete_value('forum_'.$forumid.'_last_replied_topic_content'); @@ -473,7 +509,7 @@ function insert_compose_frame($id, $type = 'new') $topicid = intval($_GET["topicid"] ?? 0); int_check($topicid,true); - $page = intval($_GET["page"] ?? 0); + $page = $_GET["page"] ?? 0; $authorid = intval($_GET["authorid"] ?? 0); if ($authorid) { diff --git a/public/takeedit.php b/public/takeedit.php index c4300b047..71a887219 100644 --- a/public/takeedit.php +++ b/public/takeedit.php @@ -252,7 +252,7 @@ function bark($msg) { $searchRep->updateTorrent($id); if ($affectedRows == 1 && $row['banned'] == 'yes' && $row['owner'] == $CURUSER['id']) { - $torrentUrl = sprintf('%s/details.php?id=%s', getSchemeAndHttpHost(), $row['id']); + $torrentUrl = sprintf('details.php?id=%s', $row['id']); \App\Models\StaffMessage::query()->insert([ 'sender' => $CURUSER['id'], 'subject' => nexus_trans('torrent.owner_update_torrent_subject', ['detail_url' => $torrentUrl, 'torrent_name' => $_POST['name']]), @@ -260,6 +260,7 @@ function bark($msg) { 'added' => now(), ]); \Nexus\Database\NexusDB::cache_del("staff_new_message_count"); + \Nexus\Database\NexusDB::cache_del("staff_message_count"); } $returl = "details.php?id=$id&edited=1"; diff --git a/resources/lang/en/forum.php b/resources/lang/en/forum.php new file mode 100644 index 000000000..8e367e6db --- /dev/null +++ b/resources/lang/en/forum.php @@ -0,0 +1,12 @@ + [ + 'replied_notify_subject' => 'The topic has a new reply', + 'replied_notify_body' => 'Your topic::topic_subject has a new reply.', + ], + 'post' => [ + 'edited_notify_subject' => 'Post reply was modified', + 'edited_notify_body' => 'Your reply to topic: :topic_subject was modified by: :editor.', + ] +]; diff --git a/resources/lang/zh_CN/forum.php b/resources/lang/zh_CN/forum.php new file mode 100644 index 000000000..f76637fe0 --- /dev/null +++ b/resources/lang/zh_CN/forum.php @@ -0,0 +1,12 @@ + [ + 'replied_notify_subject' => '帖子有了新回复', + 'replied_notify_body' => '你的帖子::topic_subject 收到了新的回复。', + ], + 'post' => [ + 'edited_notify_subject' => '帖子回复被修改', + 'edited_notify_body' => '你在帖子::topic_subject 的回复被::editor 修改。', + ] +]; diff --git a/resources/lang/zh_TW/forum.php b/resources/lang/zh_TW/forum.php new file mode 100644 index 000000000..5c5b99901 --- /dev/null +++ b/resources/lang/zh_TW/forum.php @@ -0,0 +1,12 @@ + [ + 'replied_notify_subject' => '帖子有了新回復', + 'replied_notify_body' => '你的帖子::topic_subject 收到了新的回復。', + ], + 'post' => [ + 'edited_notify_subject' => '帖子回復被修改', + 'edited_notify_body' => '你在帖子::topic_subject 的回復被::editor 修改。', + ] +];