From 4ee194031d1f03b86849bc236506039a91e89617 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 10:22:27 +0000 Subject: [PATCH 1/3] Phase 5: moderation Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MZy45V5RV9nx6Buq8vqKHr --- CHANGELOG.md | 1 + README.md | 2 +- src/assets/css/imforum.css | 2 + src/class/ModerationService.php | 362 +++++++++++++++++++++++++++ src/class/PermissionService.php | 14 ++ src/class/PostHandler.php | 9 + src/class/ReportHandler.php | 10 + src/forum.php | 4 + src/icms_version.php | 1 + src/language/english/main.php | 47 ++++ src/language/nederlands/main.php | 47 ++++ src/moderate.php | 230 +++++++++++++++++ src/report.php | 81 ++++++ src/templates/imforum_forum.html | 7 + src/templates/imforum_moderate.html | 97 +++++++ src/templates/imforum_topic.html | 10 +- src/topic.php | 16 ++ tests/Integration/ModerationTest.php | 305 ++++++++++++++++++++++ 18 files changed, 1243 insertions(+), 2 deletions(-) create mode 100644 src/class/ModerationService.php create mode 100644 src/moderate.php create mode 100644 src/report.php create mode 100644 src/templates/imforum_moderate.html create mode 100644 tests/Integration/ModerationTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 33013b1..63bcbeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,3 +7,4 @@ - Phase 2: administration. Admin screens on `icms_ipf_view_Table` and `getSecureForm()` for categories and forums (moderators and group permissions on the forum form), a permission template that new forums start with and that can be applied to existing forums, reports, suspensions, digests, the archive, prune (with a preview and a confirmation) and a full recount. Every operation that writes runs only on POST with a valid security token, deletion confirmations included. Works around three core issues: a missing admin menu on the first request after the menu cache is rebuilt, `count(null)` when a permission select is left empty, and the date picker failing when a form is built before `icms_cp_header()`. - Phase 3: reading. `index.php`, `forum.php`, `topic.php` (flat and threaded), `viewall.php` (latest, unread, featured), `archive.php`, `rss.php`, search, who is online, signatures, ranks and the poster bar, read marks per topic and per forum ("mark all as read" is a POST with a token), karma and required-reply locks that hide the text until unlocked, three blocks (recent, hot, top posters) and six preferences. Permissions are checked in one `PermissionService`: category access, forum access and view, switched-off forums for moderators and webmasters only. Our own pager replaces the core's, which prints `PHP_SELF` unescaped. Integration tests cover the permission checks, read marks, thread order, karma, online tracking, the archive and search. - Phase 4: writing. `post.php` starts topics, replies, edits and deletes through one `PostService` that holds all rules: the permissions forum_post, forum_reply, forum_edit, forum_delete, forum_attach and forum_noapprove, suspensions, a flood limit, a time limit for members, locked topics, what the forum allows (HTML, signature, topic prefix), approval and the edit history. Members delete only their own last post of a topic. The form is built on the IPF secure form, with a preview, a disclaimer and a captcha for guests. Attachments go through `Uploader` (extension list per forum, a list of extensions that is never accepted, size limit, a random file name without extension in a folder the web server cannot reach) and are served by `attachment.php`, which checks the read permission and the karma lock and always sends a download. Subscriptions use the core notification system for topics, forums and all forums; the mail is only sent to members who may read the forum and never holds the text of a post. Post text is now stored as typed (`XOBJ_DTYPE_OTHER`): the IPF textarea type ran every text through HTMLPurifier when saving, which turned BBCode into HTML for good and made the HTML, smiley and line break switches of a post meaningless. The text is made safe when it is shown. The welcome post is left for a later release: the core has no event for a new registration to hook it on. +- Phase 5: moderation. `moderate.php` and one `ModerationService` that holds all rules: lock and unlock, pin, feature, move (the moderator must moderate both forums), merge (counters, last post, views and read marks follow), split from a post onward (replies are re-attached to the new first post), delete a topic, approve waiting posts (subscribers are told only then), a queue of waiting posts and a list of open reports per forum, and suspensions with a number of days (reading stays possible; moderators and webmasters cannot be suspended). `report.php` lets members report a post, one open report per member and post. Every action is a confirmation form followed by a POST with a security token. Restoring pruned topics from the archive stays an admin task for now. Integration tests cover each action, the counters after merge and split, and a suspended member who can read but not write. diff --git a/README.md b/README.md index d1b1f83..5d22073 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Community forum module for ImpressCMS 2.0, built on the ImpressCMS Persistable Framework (IPF). imforum is the successor of iForum: same features, new code, and an importer that takes over the data of a running iForum installation. -Status: phase 4 (writing). Members start topics, reply (with a quick reply under the topic), quote, edit and delete their own posts, attach files and follow topics and forums by notification; guests can post where the group permissions allow it, behind a captcha. Posts wait for a moderator when the group lacks forum_noapprove. Moderation from the front end (move, merge, split, lock, approve, reports) comes in phase 5. Categories, forums, moderators, permissions, reports, suspensions, digests, the archive and pruning are managed from the admin area. +Status: phase 5 (moderation). Members start topics, reply (with a quick reply under the topic), quote, edit and delete their own posts, attach files and follow topics and forums by notification; guests can post where the group permissions allow it, behind a captcha. Posts wait for a moderator when the group lacks forum_noapprove. Moderators of a forum lock, pin and feature topics, move, merge and split them, delete topics, approve waiting posts, handle reports from members and suspend members, all from the front end through `moderate.php`; members report posts through `report.php`. Categories, forums, moderators, permissions, reports, suspensions, digests, the archive and pruning are managed from the admin area. ## Requirements diff --git a/src/assets/css/imforum.css b/src/assets/css/imforum.css index 1409b86..24a692a 100644 --- a/src/assets/css/imforum.css +++ b/src/assets/css/imforum.css @@ -69,3 +69,5 @@ .imforum .imforum-errors p { margin: 0.25em 0; } .imforum .imforum-disclaimer { margin: 0.75em 0; padding: 0.5em 0.75em; border-left: 3px solid currentColor; opacity: 0.85; } .imforum .imforum-confirm { margin: 1em 0; } +.imforum .imforum-modtools { margin: 0.5em 0; } +.imforum .imforum-modtools a { margin-right: 0.75em; } diff --git a/src/class/ModerationService.php b/src/class/ModerationService.php new file mode 100644 index 0000000..31c7fbd --- /dev/null +++ b/src/class/ModerationService.php @@ -0,0 +1,362 @@ +permissions = $permissions; + $this->notifier = $notifier; + } + + /** + * @return array{ok: bool, errors: list} + */ + private static function result(bool $ok, string $error = ''): array { + return ['ok' => $ok, 'errors' => $ok || $error === '' ? [] : [$error]]; + } + + /** + * A write that has already been allowed + */ + private function run(string $sql): bool { + return (bool) icms::$xoopsDB->queryF($sql); + } + + private function mayModerate(int $forumId): bool { + $forum = $this->permissions->getForum($forumId); + return $forum !== null && $this->permissions->canModerate($forum); + } + + private static function topics(): mod_imforum_TopicHandler { + return icms_getModuleHandler('topic', IMFORUM_DIRNAME); + } + + private static function posts(): mod_imforum_PostHandler { + return icms_getModuleHandler('post', IMFORUM_DIRNAME); + } + + private static function forums(): mod_imforum_ForumHandler { + return icms_getModuleHandler('forum', IMFORUM_DIRNAME); + } + + /** + * Close a topic to replies from members, or open it again + * + * @return array{ok: bool, errors: list} + */ + public function setLocked(mod_imforum_Topic $topic, bool $locked): array { + return $this->setFlag($topic, 'topic_status', $locked); + } + + /** + * Keep a topic at the top of its forum, or let it sink again + * + * @return array{ok: bool, errors: list} + */ + public function setSticky(mod_imforum_Topic $topic, bool $sticky): array { + return $this->setFlag($topic, 'topic_sticky', $sticky); + } + + /** + * Feature a topic in the digest list, or take it out + * + * @return array{ok: bool, errors: list} + */ + public function setDigest(mod_imforum_Topic $topic, bool $digest): array { + return $this->setFlag($topic, 'topic_digest', $digest); + } + + /** + * @return array{ok: bool, errors: list} + */ + private function setFlag(mod_imforum_Topic $topic, string $field, bool $on): array { + if (!$this->mayModerate((int) $topic->getVar('forum_id', 'e'))) { + return self::result(false, _NOPERM); + } + $topic->setVar($field, $on ? 1 : 0); + if ($field === 'topic_digest') { + $topic->setVar('digest_time', $on ? time() : 0); + } + return self::result(self::topics()->insert($topic, true), _MD_IMFORUM_ERR_SAVE_FAILED); + } + + /** + * Move a topic to another forum; the moderator must moderate both + * + * @return array{ok: bool, errors: list} + */ + public function move(mod_imforum_Topic $topic, int $targetForumId): array { + $fromId = (int) $topic->getVar('forum_id', 'e'); + if (!$this->mayModerate($fromId) || !$this->mayModerate($targetForumId)) { + return self::result(false, _NOPERM); + } + if ($fromId === $targetForumId) { + return self::result(false, _MD_IMFORUM_MOD_ERR_SAME_FORUM); + } + return self::result(self::topics()->moveToForum((int) $topic->id(), $targetForumId), _MD_IMFORUM_ERR_SAVE_FAILED); + } + + /** + * Add all posts of a topic to another topic and remove the empty one + * + * The target keeps its title. The views are added up. + * + * @return array{ok: bool, errors: list, topic: ?mod_imforum_Topic} + */ + public function merge(mod_imforum_Topic $source, mod_imforum_Topic $target): array { + $fail = static fn (string $error): array => ['ok' => false, 'errors' => [$error], 'topic' => null]; + if ($source->isNew() || $target->isNew()) { + return $fail(_MD_IMFORUM_MOD_ERR_NO_TOPIC); + } + $sourceId = (int) $source->id(); + $targetId = (int) $target->id(); + $sourceForum = (int) $source->getVar('forum_id', 'e'); + $targetForum = (int) $target->getVar('forum_id', 'e'); + if (!$this->mayModerate($sourceForum) || !$this->mayModerate($targetForum)) { + return $fail(_NOPERM); + } + if ($sourceId === $targetId) { + return $fail(_MD_IMFORUM_MOD_ERR_SAME_TOPIC); + } + + $db = icms::$xoopsDB; + $posts = $db->prefix(IMFORUM_DIRNAME . '_post'); + $topicTable = $db->prefix(IMFORUM_DIRNAME . '_topic'); + $ok = $this->run("UPDATE $posts SET topic_id = $targetId, forum_id = $targetForum WHERE topic_id = $sourceId"); + $views = (int) $source->getVar('topic_views', 'e'); + $ok = $this->run("UPDATE $topicTable SET topic_views = topic_views + $views WHERE topic_id = $targetId") && $ok; + $ok = $this->run("DELETE FROM $topicTable WHERE topic_id = $sourceId") && $ok; + icms_getModuleHandler('readmark', IMFORUM_DIRNAME)->deleteByItem(mod_imforum_ReadmarkHandler::TYPE_TOPIC, $sourceId); + + $ok = self::topics()->synchronise($targetId) && $ok; + $ok = self::forums()->synchronise($sourceForum) && $ok; + if ($targetForum !== $sourceForum) { + $ok = self::forums()->synchronise($targetForum) && $ok; + } + return ['ok' => $ok, 'errors' => $ok ? [] : [_MD_IMFORUM_ERR_SAVE_FAILED], 'topic' => self::topics()->get($targetId)]; + } + + /** + * Move a post and every later post of the topic to a new topic + * + * Replies that pointed at a post that stays behind now answer the new + * first post, so the tree view stays whole. + * + * @return array{ok: bool, errors: list, topic: ?mod_imforum_Topic} + */ + public function split(mod_imforum_Post $post, string $title): array { + $fail = static fn (string $error): array => ['ok' => false, 'errors' => [$error], 'topic' => null]; + $oldTopic = self::topics()->get((int) $post->getVar('topic_id', 'e')); + if ($post->isNew() || $oldTopic->isNew()) { + return $fail(_MD_IMFORUM_MOD_ERR_NO_POST); + } + $forumId = (int) $oldTopic->getVar('forum_id', 'e'); + if (!$this->mayModerate($forumId)) { + return $fail(_NOPERM); + } + $title = trim($title); + if ($title === '' || mb_strlen($title) > mod_imforum_PostService::MAX_SUBJECT) { + return $fail(sprintf(_MD_IMFORUM_ERR_SUBJECT_LONG, mod_imforum_PostService::MAX_SUBJECT)); + } + $postId = (int) $post->id(); + $oldId = (int) $oldTopic->id(); + + $db = icms::$xoopsDB; + $posts = $db->prefix(IMFORUM_DIRNAME . '_post'); + $result = $db->queryF("SELECT MIN(post_id) FROM $posts WHERE topic_id = $oldId"); + $row = $result ? $db->fetchRow($result) : false; + if ($row && (int) $row[0] === $postId) { + return $fail(_MD_IMFORUM_MOD_ERR_SPLIT_FIRST); + } + + $topic = self::topics()->create(); + $topic->setVar('forum_id', $forumId); + $topic->setVar('topic_title', $title); + $topic->setVar('topic_poster', (int) $post->getVar('uid', 'e')); + $topic->setVar('poster_name', (string) $post->getVar('poster_name', 'n')); + $topic->setVar('topic_time', (int) $post->getVar('post_time', 'e')); + $topic->setVar('approved', (int) $post->getVar('approved', 'e')); + if (!self::topics()->insert($topic, true)) { + return $fail(_MD_IMFORUM_ERR_SAVE_FAILED); + } + $newId = (int) $topic->id(); + + $ok = $this->run("UPDATE $posts SET topic_id = $newId WHERE topic_id = $oldId AND post_id >= $postId"); + $ok = $this->run("UPDATE $posts SET pid = 0 WHERE post_id = $postId") && $ok; + $ok = $this->run("UPDATE $posts SET pid = $postId WHERE topic_id = $newId AND post_id > $postId AND pid < $postId") && $ok; + $ok = self::topics()->synchronise($oldId) && $ok; + $ok = self::topics()->synchronise($newId) && $ok; + $ok = self::forums()->synchronise($forumId) && $ok; + return ['ok' => $ok, 'errors' => $ok ? [] : [_MD_IMFORUM_ERR_SAVE_FAILED], 'topic' => self::topics()->get($newId)]; + } + + /** + * Delete a topic with all its posts + * + * @return array{ok: bool, errors: list} + */ + public function deleteTopic(mod_imforum_Topic $topic): array { + if (!$this->mayModerate((int) $topic->getVar('forum_id', 'e'))) { + return self::result(false, _NOPERM); + } + return self::result(self::topics()->delete($topic, true), _MD_IMFORUM_ERR_SAVE_FAILED); + } + + /** + * Let a waiting post appear, and the topic with it when the post starts it + * + * Subscribers are told only now, as they were not told when the post was written. + * + * @return array{ok: bool, errors: list} + */ + public function approve(mod_imforum_Post $post): array { + $topic = self::topics()->get((int) $post->getVar('topic_id', 'e')); + $forum = $this->permissions->getForum((int) $post->getVar('forum_id', 'e')); + if ($post->isNew() || $topic->isNew() || $forum === null || !$this->permissions->canModerate($forum)) { + return self::result(false, _NOPERM); + } + if ((int) $post->getVar('approved', 'e') === 1) { + return self::result(true); + } + + $post->setVar('approved', 1); + if (!self::posts()->insert($post, true)) { + return self::result(false, _MD_IMFORUM_ERR_SAVE_FAILED); + } + $newTopic = false; + if ((int) $topic->getVar('approved', 'e') === 0) { + $firstId = $this->firstPostId((int) $topic->id()); + if ($firstId === (int) $post->id()) { + $topic->setVar('approved', 1); + self::topics()->insert($topic, true); + $newTopic = true; + } + } + $topic = self::topics()->get((int) $topic->id()); + // a reply in a topic that still waits stays invisible, so nobody is told + if ((int) $topic->getVar('approved', 'e') === 1) { + ($this->notifier ?? new mod_imforum_Notifier())->newPost($post, $topic, $forum, $newTopic); + } + return self::result(true); + } + + private function firstPostId(int $topicId): int { + $db = icms::$xoopsDB; + $result = $db->queryF('SELECT MIN(post_id) FROM ' . $db->prefix(IMFORUM_DIRNAME . '_post') . " WHERE topic_id = $topicId"); + $row = $result ? $db->fetchRow($result) : false; + return $row ? (int) $row[0] : 0; + } + + /** + * A member tells the moderators about a post + * + * @return array{ok: bool, errors: list} + */ + public function report(mod_imforum_Post $post, string $text): array { + $forum = $this->permissions->getForum((int) $post->getVar('forum_id', 'e')); + if ($post->isNew() || $forum === null || !$this->permissions->canReport($forum)) { + return self::result(false, _NOPERM); + } + $text = trim($text); + if ($text === '') { + return self::result(false, _MD_IMFORUM_REPORT_ERR_TEXT); + } + $uid = $this->permissions->getUid(); + $handler = icms_getModuleHandler('report', IMFORUM_DIRNAME); + $open = new icms_db_criteria_Compo(new icms_db_criteria_Item('post_id', (int) $post->id())); + $open->add(new icms_db_criteria_Item('reporter_uid', $uid)); + $open->add(new icms_db_criteria_Item('report_result', mod_imforum_Report::RESULT_OPEN)); + if ($handler->getCount($open) > 0) { + return self::result(false, _MD_IMFORUM_REPORT_ERR_TWICE); + } + + $report = $handler->create(); + $report->setVar('post_id', (int) $post->id()); + $report->setVar('reporter_uid', $uid); + $report->setVar('reporter_ip', mod_imforum_View::clientIp()); + $report->setVar('report_text', $text); + return self::result($handler->insert($report, true), _MD_IMFORUM_ERR_SAVE_FAILED); + } + + /** + * Close a report with a note for the other moderators + * + * @return array{ok: bool, errors: list} + */ + public function handleReport(mod_imforum_Report $report, string $memo): array { + $post = self::posts()->get((int) $report->getVar('post_id', 'e')); + $forumId = $post->isNew() ? 0 : (int) $post->getVar('forum_id', 'e'); + // a report whose post is gone can be closed by any moderator or webmaster + $allowed = $post->isNew() ? $this->permissions->isWebmaster() || $this->moderatesAny() : $this->mayModerate($forumId); + if (!$allowed) { + return self::result(false, _NOPERM); + } + $report->setVar('report_result', mod_imforum_Report::RESULT_HANDLED); + $report->setVar('report_memo', trim($memo)); + return self::result(icms_getModuleHandler('report', IMFORUM_DIRNAME)->insert($report, true), _MD_IMFORUM_ERR_SAVE_FAILED); + } + + private function moderatesAny(): bool { + foreach ($this->permissions->getAllForums() as $forumId => $forum) { + if ($this->permissions->isModerator((int) $forumId)) { + return true; + } + } + return false; + } + + /** + * Stop a member from writing in one forum for some days + * + * Reading stays possible. Moderators and webmasters cannot be suspended. + * + * @return array{ok: bool, errors: list} + */ + public function suspend(mod_imforum_Forum $forum, int $uid, int $days, string $description): array { + if (!$this->permissions->canModerate($forum)) { + return self::result(false, _NOPERM); + } + if ($uid < 1 || $uid === $this->permissions->getUid()) { + return self::result(false, _MD_IMFORUM_MOD_ERR_SUSPEND_WHO); + } + if ($days < 1 || $days > self::MAX_DAYS) { + return self::result(false, sprintf(_MD_IMFORUM_MOD_ERR_SUSPEND_DAYS, self::MAX_DAYS)); + } + $target = new mod_imforum_PermissionService(array_map('intval', (array) icms::handler('icms_member')->getGroupsByUser($uid)), $uid); + if ($target->isModerator((int) $forum->id()) || in_array((int) ICMS_GROUP_ADMIN, $target->getGroups(), true)) { + return self::result(false, _MD_IMFORUM_MOD_ERR_SUSPEND_MOD); + } + + $handler = icms_getModuleHandler('suspension', IMFORUM_DIRNAME); + $suspension = $handler->create(); + $suspension->setVar('uid', $uid); + $suspension->setVar('forum_id', (int) $forum->id()); + $suspension->setVar('start_time', time()); + $suspension->setVar('end_time', time() + $days * 86400); + $suspension->setVar('description', trim($description)); + return self::result($handler->insert($suspension, true), _MD_IMFORUM_ERR_SAVE_FAILED); + } +} diff --git a/src/class/PermissionService.php b/src/class/PermissionService.php index f9f55c7..c6b070b 100644 --- a/src/class/PermissionService.php +++ b/src/class/PermissionService.php @@ -154,6 +154,20 @@ public function canDelete(mod_imforum_Forum $forum, mod_imforum_Topic $topic, mo && (int) $topic->getVar('topic_last_post_id', 'e') === (int) $post->id(); } + /** + * Lock, move, merge, split, approve and handle reports of the forum + */ + public function canModerate(mod_imforum_Forum $forum): bool { + return $this->isModerator((int) $forum->id()); + } + + /** + * Members tell the moderators about a post they can read; guests cannot, so nobody can flood the list unseen + */ + public function canReport(mod_imforum_Forum $forum): bool { + return $this->uid > 0 && $this->canReadForum($forum); + } + public function canAttach(mod_imforum_Forum $forum): bool { return $this->has('forum_attach', (int) $forum->id()); } diff --git a/src/class/PostHandler.php b/src/class/PostHandler.php index 5fb7853..efc5611 100644 --- a/src/class/PostHandler.php +++ b/src/class/PostHandler.php @@ -70,6 +70,15 @@ public function getPage(int $topicId, int $start, int $limit): array { return $this->getObjects($criteria, true); } + /** + * Posts of a forum that wait for a moderator + */ + public function countPending(int $forumId): int { + $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('forum_id', $forumId)); + $criteria->add(new icms_db_criteria_Item('approved', 0)); + return (int) $this->getCount($criteria); + } + public function countApproved(int $topicId): int { return (int) $this->getCount($this->approvedIn($topicId)); } diff --git a/src/class/ReportHandler.php b/src/class/ReportHandler.php index 70541fb..77e4ddb 100644 --- a/src/class/ReportHandler.php +++ b/src/class/ReportHandler.php @@ -22,6 +22,16 @@ public function getOpenCount(): int { return (int) $this->getCount(new icms_db_criteria_Item('report_result', mod_imforum_Report::RESULT_OPEN)); } + /** + * Open reports about posts of one forum + */ + public function countOpenInForum(int $forumId): int { + $posts = $this->db->prefix(IMFORUM_DIRNAME . '_post'); + $result = $this->db->queryF("SELECT COUNT(*) FROM {$this->table} r JOIN $posts p ON p.post_id = r.post_id WHERE r.report_result = " . mod_imforum_Report::RESULT_OPEN . " AND p.forum_id = $forumId"); + $row = $result ? $this->db->fetchRow($result) : false; + return $row ? (int) $row[0] : 0; + } + protected function beforeInsert(mod_imforum_Report $report): bool { if ((int) $report->getVar('report_time', 'e') === 0) { $report->setVar('report_time', time()); diff --git a/src/forum.php b/src/forum.php index 12408e2..f521e9b 100644 --- a/src/forum.php +++ b/src/forum.php @@ -95,6 +95,10 @@ $icmsTpl->assign('imforum_subforums', $subforums); $icmsTpl->assign('imforum_topics', $rows); $icmsTpl->assign('imforum_moderators', $moderators); +$icmsTpl->assign('imforum_mod_links', $permissions->canModerate($forum) ? [ + 'pending' => ['url' => mod_imforum_View::link('moderate', ['do' => 'pending', 'forum' => $forumId]), 'count' => icms_getModuleHandler('post', IMFORUM_DIRNAME)->countPending($forumId)], + 'reports' => ['url' => mod_imforum_View::link('moderate', ['do' => 'reports', 'forum' => $forumId]), 'count' => icms_getModuleHandler('report', IMFORUM_DIRNAME)->countOpenInForum($forumId)], +] : null); $icmsTpl->assign('imforum_pager', mod_imforum_View::pager('forum', ['forum' => $forumId], $total, $perPage, $start)); $icmsTpl->assign('imforum_can_mark_read', $tracker->isTracking()); $icmsTpl->assign('imforum_token', icms::$security->getTokenHTML()); diff --git a/src/icms_version.php b/src/icms_version.php index ec68a92..88f1262 100644 --- a/src/icms_version.php +++ b/src/icms_version.php @@ -123,6 +123,7 @@ ['file' => 'imforum_forum.html', 'description' => 'Forum with its topics'], ['file' => 'imforum_topic.html', 'description' => 'Topic with its posts'], ['file' => 'imforum_post.html', 'description' => 'Form to write, edit or delete a post'], + ['file' => 'imforum_moderate.html', 'description' => 'Moderation forms, the queue of waiting posts and the reports'], ['file' => 'imforum_viewall.html', 'description' => 'Topics of all forums'], ['file' => 'imforum_archive.html', 'description' => 'Archived topics'], ['file' => 'imforum_breadcrumb.html', 'description' => 'Path above a page'], diff --git a/src/language/english/main.php b/src/language/english/main.php index ba9170a..5cdb2b1 100644 --- a/src/language/english/main.php +++ b/src/language/english/main.php @@ -81,3 +81,50 @@ define('_MD_IMFORUM_ERR_ATTACH_FAILED', 'A file could not be uploaded.'); define('_MD_IMFORUM_QUOTE_WROTE', '%s wrote:'); define('_MD_IMFORUM_ANONYMOUS', 'a guest'); +define('_MD_IMFORUM_BACK', 'Back'); +define('_MD_IMFORUM_MODERATION', 'Moderation'); +define('_MD_IMFORUM_REPORT', 'Report'); +define('_MD_IMFORUM_REPORT_HELP', 'Tell the moderators what is wrong with this post.'); +define('_MD_IMFORUM_REPORT_SENT', 'Thank you, the moderators have your report.'); +define('_MD_IMFORUM_REPORT_ERR_TEXT', 'Write what is wrong with the post.'); +define('_MD_IMFORUM_REPORT_ERR_TWICE', 'You have already reported this post and a moderator has not handled it yet.'); +define('_MD_IMFORUM_MOD_DONE', 'Done.'); +define('_MD_IMFORUM_MOD_SUSPENDED', 'The member is suspended.'); +define('_MD_IMFORUM_MOD_LOCK', 'Lock'); +define('_MD_IMFORUM_MOD_UNLOCK', 'Unlock'); +define('_MD_IMFORUM_MOD_STICKY', 'Pin'); +define('_MD_IMFORUM_MOD_UNSTICKY', 'Unpin'); +define('_MD_IMFORUM_MOD_DIGEST', 'Feature'); +define('_MD_IMFORUM_MOD_UNDIGEST', 'Unfeature'); +define('_MD_IMFORUM_MOD_MOVE', 'Move'); +define('_MD_IMFORUM_MOD_MERGE', 'Merge'); +define('_MD_IMFORUM_MOD_DELETE', 'Delete topic'); +define('_MD_IMFORUM_MOD_SPLIT', 'Split topic here'); +define('_MD_IMFORUM_MOD_APPROVE', 'Approve'); +define('_MD_IMFORUM_MOD_SUSPEND', 'Suspend member'); +define('_MD_IMFORUM_MOD_PENDING', 'Waiting for approval'); +define('_MD_IMFORUM_MOD_REPORTS', 'Reports'); +define('_MD_IMFORUM_MOD_HANDLE', 'Handle report'); +define('_MD_IMFORUM_MOD_WAITING', 'Posts waiting for approval'); +define('_MD_IMFORUM_MOD_NONE_WAITING', 'No posts are waiting.'); +define('_MD_IMFORUM_MOD_REPORTED', 'Reported posts'); +define('_MD_IMFORUM_MOD_NONE_REPORTS', 'No open reports.'); +define('_MD_IMFORUM_MOD_TARGET_FORUM', 'Move to forum'); +define('_MD_IMFORUM_MOD_TARGET_TOPIC', 'Number of the topic to merge into'); +define('_MD_IMFORUM_MOD_MERGE_HELP', 'All posts of this topic are added to the other topic, which keeps its title. You find the number in the address of that topic (topic=N).'); +define('_MD_IMFORUM_MOD_NEW_TITLE', 'Title of the new topic'); +define('_MD_IMFORUM_MOD_SPLIT_HELP', 'This post and every later post of the topic move to a new topic.'); +define('_MD_IMFORUM_MOD_SUSPEND_WHO', 'Member'); +define('_MD_IMFORUM_MOD_DAYS', 'Days'); +define('_MD_IMFORUM_MOD_REASON', 'Reason'); +define('_MD_IMFORUM_MOD_MEMO', 'Note for the other moderators'); +define('_MD_IMFORUM_MOD_DELETE_CONFIRM', 'The topic and all its posts, files and reports are deleted for good.'); +define('_MD_IMFORUM_MOD_APPROVE_CONFIRM', 'The post appears in the topic and members who follow it are told.'); +define('_MD_IMFORUM_MOD_ERR_SAME_FORUM', 'The topic is already in that forum.'); +define('_MD_IMFORUM_MOD_ERR_NO_TOPIC', 'That topic does not exist.'); +define('_MD_IMFORUM_MOD_ERR_SAME_TOPIC', 'A topic cannot be merged into itself.'); +define('_MD_IMFORUM_MOD_ERR_NO_POST', 'That post does not exist.'); +define('_MD_IMFORUM_MOD_ERR_SPLIT_FIRST', 'The first post cannot start a new topic: it already does.'); +define('_MD_IMFORUM_MOD_ERR_SUSPEND_WHO', 'Choose another member than yourself.'); +define('_MD_IMFORUM_MOD_ERR_SUSPEND_DAYS', 'Choose between 1 and %d days.'); +define('_MD_IMFORUM_MOD_ERR_SUSPEND_MOD', 'Moderators and webmasters cannot be suspended.'); diff --git a/src/language/nederlands/main.php b/src/language/nederlands/main.php index 5efd6f0..26a2245 100644 --- a/src/language/nederlands/main.php +++ b/src/language/nederlands/main.php @@ -81,3 +81,50 @@ define('_MD_IMFORUM_ERR_ATTACH_FAILED', 'Een bestand kon niet worden geüpload.'); define('_MD_IMFORUM_QUOTE_WROTE', '%s schreef:'); define('_MD_IMFORUM_ANONYMOUS', 'een gast'); +define('_MD_IMFORUM_BACK', 'Terug'); +define('_MD_IMFORUM_MODERATION', 'Moderatie'); +define('_MD_IMFORUM_REPORT', 'Melden'); +define('_MD_IMFORUM_REPORT_HELP', 'Vertel de moderatoren wat er mis is met dit bericht.'); +define('_MD_IMFORUM_REPORT_SENT', 'Bedankt, de moderatoren hebben uw melding.'); +define('_MD_IMFORUM_REPORT_ERR_TEXT', 'Schrijf wat er mis is met het bericht.'); +define('_MD_IMFORUM_REPORT_ERR_TWICE', 'U hebt dit bericht al gemeld en een moderator heeft de melding nog niet behandeld.'); +define('_MD_IMFORUM_MOD_DONE', 'Klaar.'); +define('_MD_IMFORUM_MOD_SUSPENDED', 'Het lid is geschorst.'); +define('_MD_IMFORUM_MOD_LOCK', 'Sluiten'); +define('_MD_IMFORUM_MOD_UNLOCK', 'Heropenen'); +define('_MD_IMFORUM_MOD_STICKY', 'Vastpinnen'); +define('_MD_IMFORUM_MOD_UNSTICKY', 'Losmaken'); +define('_MD_IMFORUM_MOD_DIGEST', 'Uitlichten'); +define('_MD_IMFORUM_MOD_UNDIGEST', 'Niet meer uitlichten'); +define('_MD_IMFORUM_MOD_MOVE', 'Verplaatsen'); +define('_MD_IMFORUM_MOD_MERGE', 'Samenvoegen'); +define('_MD_IMFORUM_MOD_DELETE', 'Onderwerp verwijderen'); +define('_MD_IMFORUM_MOD_SPLIT', 'Onderwerp hier splitsen'); +define('_MD_IMFORUM_MOD_APPROVE', 'Goedkeuren'); +define('_MD_IMFORUM_MOD_SUSPEND', 'Lid schorsen'); +define('_MD_IMFORUM_MOD_PENDING', 'Wacht op goedkeuring'); +define('_MD_IMFORUM_MOD_REPORTS', 'Meldingen'); +define('_MD_IMFORUM_MOD_HANDLE', 'Melding afhandelen'); +define('_MD_IMFORUM_MOD_WAITING', 'Berichten die op goedkeuring wachten'); +define('_MD_IMFORUM_MOD_NONE_WAITING', 'Er wacht geen enkel bericht.'); +define('_MD_IMFORUM_MOD_REPORTED', 'Gemelde berichten'); +define('_MD_IMFORUM_MOD_NONE_REPORTS', 'Geen openstaande meldingen.'); +define('_MD_IMFORUM_MOD_TARGET_FORUM', 'Verplaatsen naar forum'); +define('_MD_IMFORUM_MOD_TARGET_TOPIC', 'Nummer van het onderwerp waarin dit opgaat'); +define('_MD_IMFORUM_MOD_MERGE_HELP', 'Alle berichten van dit onderwerp komen in het andere onderwerp, dat zijn titel houdt. Het nummer staat in het adres van dat onderwerp (topic=N).'); +define('_MD_IMFORUM_MOD_NEW_TITLE', 'Titel van het nieuwe onderwerp'); +define('_MD_IMFORUM_MOD_SPLIT_HELP', 'Dit bericht en elk later bericht van het onderwerp verhuizen naar een nieuw onderwerp.'); +define('_MD_IMFORUM_MOD_SUSPEND_WHO', 'Lid'); +define('_MD_IMFORUM_MOD_DAYS', 'Dagen'); +define('_MD_IMFORUM_MOD_REASON', 'Reden'); +define('_MD_IMFORUM_MOD_MEMO', 'Notitie voor de andere moderatoren'); +define('_MD_IMFORUM_MOD_DELETE_CONFIRM', 'Het onderwerp met alle berichten, bestanden en meldingen wordt definitief verwijderd.'); +define('_MD_IMFORUM_MOD_APPROVE_CONFIRM', 'Het bericht verschijnt in het onderwerp en leden die het volgen krijgen bericht.'); +define('_MD_IMFORUM_MOD_ERR_SAME_FORUM', 'Het onderwerp staat al in dat forum.'); +define('_MD_IMFORUM_MOD_ERR_NO_TOPIC', 'Dat onderwerp bestaat niet.'); +define('_MD_IMFORUM_MOD_ERR_SAME_TOPIC', 'Een onderwerp kan niet in zichzelf opgaan.'); +define('_MD_IMFORUM_MOD_ERR_NO_POST', 'Dat bericht bestaat niet.'); +define('_MD_IMFORUM_MOD_ERR_SPLIT_FIRST', 'Het eerste bericht kan geen nieuw onderwerp starten: dat doet het al.'); +define('_MD_IMFORUM_MOD_ERR_SUSPEND_WHO', 'Kies een ander lid dan uzelf.'); +define('_MD_IMFORUM_MOD_ERR_SUSPEND_DAYS', 'Kies tussen 1 en %d dagen.'); +define('_MD_IMFORUM_MOD_ERR_SUSPEND_MOD', 'Moderatoren en webmasters kunnen niet geschorst worden.'); diff --git a/src/moderate.php b/src/moderate.php new file mode 100644 index 0000000..8d90b07 --- /dev/null +++ b/src/moderate.php @@ -0,0 +1,230 @@ + is_scalar($request[$name] ?? null) ? max(0, (int) $request[$name]) : 0; +$text = static fn (string $name): string => is_string($request[$name] ?? null) ? trim($request[$name]) : ''; +$do = $text('do'); + +$topicActions = ['lock', 'unlock', 'sticky', 'unsticky', 'digest', 'undigest', 'move', 'merge', 'delete']; +$postActions = ['split', 'approve', 'suspend']; +$listActions = ['pending', 'reports']; + +$topic = null; +$post = null; +$report = null; +if (in_array($do, $topicActions, true)) { + $topic = $topicHandler->get($param('topic')); + $forumId = $topic->isNew() ? 0 : (int) $topic->getVar('forum_id', 'e'); +} elseif (in_array($do, $postActions, true)) { + $post = $postHandler->get($param('post')); + $topic = $post->isNew() ? null : $topicHandler->get((int) $post->getVar('topic_id', 'e')); + $forumId = $post->isNew() ? 0 : (int) $post->getVar('forum_id', 'e'); +} elseif ($do === 'handle') { + $report = $reportHandler->get($param('report')); + $reported = $report->isNew() ? null : $postHandler->get((int) $report->getVar('post_id', 'e')); + $forumId = ($reported !== null && !$reported->isNew()) ? (int) $reported->getVar('forum_id', 'e') : 0; +} elseif (in_array($do, $listActions, true)) { + $forumId = $param('forum'); +} else { + redirect_header(mod_imforum_View::url('index'), 3, _NOPERM); + exit; +} + +$forum = $permissions->getForum($forumId); +$orphanReport = $do === 'handle' && $report !== null && !$report->isNew() && $forum === null; +if (!$orphanReport && ($forum === null || !$permissions->canModerate($forum) || ($topic !== null && $topic->isNew()) || ($post !== null && $post->isNew()) || ($report !== null && $report->isNew()))) { + redirect_header(mod_imforum_View::url($forum !== null ? 'forum' : 'index', $forum !== null ? ['forum' => $forumId] : []), 3, _NOPERM); + exit; +} + +$service = new mod_imforum_ModerationService($permissions); +$errors = []; +$topicId = $topic !== null ? (int) $topic->id() : 0; +$back = $topic !== null ? mod_imforum_View::url('topic', ['topic' => $topicId]) : mod_imforum_View::url('forum', ['forum' => $forumId]); +if ($do === 'handle' || $do === 'reports') { + $back = mod_imforum_View::url('moderate', ['do' => 'reports', 'forum' => $forumId]); +} + +// doing the work +if ($isPost && !in_array($do, $listActions, true)) { + if (!icms::$security->check()) { + $errors = array_merge($errors, (array) icms::$security->getErrors()); + } else { + $message = _MD_IMFORUM_MOD_DONE; + $target = $back; + switch ($do) { + case 'lock': + case 'unlock': + $outcome = $service->setLocked($topic, $do === 'lock'); + break; + case 'sticky': + case 'unsticky': + $outcome = $service->setSticky($topic, $do === 'sticky'); + break; + case 'digest': + case 'undigest': + $outcome = $service->setDigest($topic, $do === 'digest'); + break; + case 'move': + $outcome = $service->move($topic, $param('target_forum')); + break; + case 'merge': + $outcome = $service->merge($topic, $topicHandler->get($param('target_topic'))); + if ($outcome['ok'] && $outcome['topic'] !== null) { + $target = mod_imforum_View::url('topic', ['topic' => (int) $outcome['topic']->id()]); + } + break; + case 'delete': + $outcome = $service->deleteTopic($topic); + $target = mod_imforum_View::url('forum', ['forum' => $forumId]); + break; + case 'split': + $outcome = $service->split($post, $text('title')); + if ($outcome['ok'] && $outcome['topic'] !== null) { + $target = mod_imforum_View::url('topic', ['topic' => (int) $outcome['topic']->id()]); + } + break; + case 'approve': + $outcome = $service->approve($post); + $target = mod_imforum_View::url('moderate', ['do' => 'pending', 'forum' => $forumId]); + break; + case 'suspend': + $outcome = $service->suspend($forum, (int) $post->getVar('uid', 'e'), $param('days'), $text('description')); + $message = _MD_IMFORUM_MOD_SUSPENDED; + break; + default: + $outcome = $service->handleReport($report, $text('memo')); + break; + } + if ($outcome['ok']) { + redirect_header($target, 2, $message); + exit; + } + $errors = $outcome['errors']; + } +} + +$xoopsOption['template_main'] = 'imforum_moderate.html'; +include_once ICMS_ROOT_PATH . '/header.php'; +global $icmsTpl, $xoTheme; +$xoTheme->addStylesheet(IMFORUM_URL . 'assets/css/imforum.css'); + +$trail = []; +for ($parent = $forumId, $guard = 0; $parent > 0 && $guard < 10; $guard++) { + $step = $permissions->getForum($parent); + if ($step === null || !$permissions->canSeeForum($step)) { + break; + } + array_unshift($trail, [$step->getVar('forum_name', 'n'), mod_imforum_View::url('forum', ['forum' => $parent])]); + $parent = (int) $step->getVar('parent_forum', 'e'); +} +if ($topic !== null) { + $trail[] = [$topic->getVar('topic_title', 'n'), mod_imforum_View::url('topic', ['topic' => $topicId])]; +} +$trail[] = [constant('_MD_IMFORUM_MOD_' . strtoupper($do))]; + +$icmsTpl->assign('imforum_breadcrumb', mod_imforum_View::breadcrumb($trail)); +$icmsTpl->assign('imforum_errors', $errors); +$icmsTpl->assign('imforum_back', mod_imforum_View::escape($back)); +$icmsTpl->assign('imforum_mod_do', $do); +$icmsTpl->assign('imforum_mod_title', constant('_MD_IMFORUM_MOD_' . strtoupper($do))); + +if (in_array($do, $listActions, true)) { + $rows = []; + if ($do === 'pending') { + $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('forum_id', $forumId)); + $criteria->add(new icms_db_criteria_Item('approved', 0)); + $criteria->setSort('post_id'); + $criteria->setOrder('ASC'); + $criteria->setLimit(100); + foreach ($postHandler->getObjects($criteria, true) as $waiting) { + $waitingTopic = $topicHandler->get((int) $waiting->getVar('topic_id', 'e')); + $rows[] = [ + 'subject' => $waiting->getVar('subject'), + 'topic' => $waitingTopic->getVar('topic_title'), + 'author' => mod_imforum_View::poster((int) $waiting->getVar('uid', 'e'), (string) $waiting->getVar('poster_name', 'n')), + 'time' => mod_imforum_View::time((int) $waiting->getVar('post_time', 'e')), + 'excerpt' => mod_imforum_View::escape(icms_core_DataFilter::icms_substr(strip_tags((string) $waiting->getVar('post_text', 'n')), 0, 200)), + 'approve_url' => mod_imforum_View::link('moderate', ['do' => 'approve', 'post' => (int) $waiting->id()]), + 'delete_url' => mod_imforum_View::link('post', ['do' => 'delete', 'post' => (int) $waiting->id()]), + 'suspend_url' => (int) $waiting->getVar('uid', 'e') > 0 ? mod_imforum_View::link('moderate', ['do' => 'suspend', 'post' => (int) $waiting->id()]) : '', + ]; + } + } else { + $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('report_result', mod_imforum_Report::RESULT_OPEN)); + $criteria->setSort('report_id'); + $criteria->setOrder('ASC'); + foreach ($reportHandler->getObjects($criteria, true) as $open) { + $reportedPost = $postHandler->get((int) $open->getVar('post_id', 'e')); + // only the reports of this forum; reports of posts that are gone belong to nobody + if ($reportedPost->isNew() || (int) $reportedPost->getVar('forum_id', 'e') !== $forumId) { + continue; + } + $rows[] = [ + 'subject' => $reportedPost->getVar('subject'), + 'post_url' => mod_imforum_View::link('topic', ['topic' => (int) $reportedPost->getVar('topic_id', 'e'), 'post' => (int) $reportedPost->id()]) . '#post-' . (int) $reportedPost->id(), + 'reporter' => mod_imforum_View::poster((int) $open->getVar('reporter_uid', 'e'), ''), + 'time' => mod_imforum_View::time((int) $open->getVar('report_time', 'e')), + 'text' => $open->getVar('report_text'), + 'handle_url' => mod_imforum_View::link('moderate', ['do' => 'handle', 'report' => (int) $open->id()]), + ]; + } + } + $icmsTpl->assign('imforum_mod_rows', $rows); +} else { + $form = [ + 'action' => mod_imforum_View::link('moderate'), + 'token' => icms::$security->getTokenHTML(), + 'do' => $do, + 'topic' => $topicId, + 'post' => $post !== null ? (int) $post->id() : 0, + 'report' => $report !== null ? (int) $report->id() : 0, + 'subject' => $topic !== null ? $topic->getVar('topic_title') : ($post !== null ? $post->getVar('subject') : ''), + 'forums' => [], + 'author' => '', + 'text' => $report !== null ? $report->getVar('report_text') : '', + 'values' => [ + 'title' => mod_imforum_View::escape($text('title') !== '' ? $text('title') : ($post !== null ? (string) $post->getVar('subject', 'n') : '')), + 'target_topic' => $param('target_topic') ?: '', + 'days' => $param('days') ?: 7, + 'description' => mod_imforum_View::escape($text('description')), + 'memo' => mod_imforum_View::escape($text('memo')), + ], + ]; + if ($do === 'move') { + foreach ($permissions->getAllForums() as $id => $candidate) { + if ((int) $id !== $forumId && $permissions->canModerate($candidate)) { + $form['forums'][] = ['id' => (int) $id, 'name' => $candidate->getVar('forum_name')]; + } + } + } + if ($do === 'suspend' && $post !== null) { + $form['author'] = mod_imforum_View::poster((int) $post->getVar('uid', 'e'), ''); + } + $icmsTpl->assign('imforum_mod_form', $form); +} + +include_once ICMS_ROOT_PATH . '/footer.php'; diff --git a/src/report.php b/src/report.php new file mode 100644 index 0000000..c443191 --- /dev/null +++ b/src/report.php @@ -0,0 +1,81 @@ +get($postId); +$topic = $post->isNew() ? null : $topicHandler->get((int) $post->getVar('topic_id', 'e')); +$forum = $post->isNew() ? null : $permissions->getForum((int) $post->getVar('forum_id', 'e')); + +if ($permissions->getUid() === 0) { + redirect_header(ICMS_URL . '/user.php?xoops_redirect=' . rawurlencode($_SERVER['REQUEST_URI'] ?? ''), 3, _NOPERM); + exit; +} +if ($forum === null || $topic === null || $topic->isNew() || (int) $post->getVar('approved', 'e') !== 1 || !$permissions->canReport($forum)) { + redirect_header(mod_imforum_View::url('index'), 3, _NOPERM); + exit; +} +$back = mod_imforum_View::url('topic', ['topic' => (int) $topic->id(), 'post' => $postId]) . '#post-' . $postId; + +$errors = []; +$reason = is_string($request['report_text'] ?? null) ? trim($request['report_text']) : ''; +if ($isPost) { + if (!icms::$security->check()) { + $errors = array_merge($errors, (array) icms::$security->getErrors()); + } else { + $outcome = (new mod_imforum_ModerationService($permissions))->report($post, $reason); + if ($outcome['ok']) { + redirect_header($back, 3, _MD_IMFORUM_REPORT_SENT); + exit; + } + $errors = $outcome['errors']; + } +} + +$xoopsOption['template_main'] = 'imforum_moderate.html'; +include_once ICMS_ROOT_PATH . '/header.php'; +global $icmsTpl, $xoTheme; +$xoTheme->addStylesheet(IMFORUM_URL . 'assets/css/imforum.css'); + +$icmsTpl->assign('imforum_breadcrumb', mod_imforum_View::breadcrumb([ + [$forum->getVar('forum_name', 'n'), mod_imforum_View::url('forum', ['forum' => (int) $forum->id()])], + [$topic->getVar('topic_title', 'n'), mod_imforum_View::url('topic', ['topic' => (int) $topic->id()])], + [_MD_IMFORUM_REPORT], +])); +$icmsTpl->assign('imforum_errors', $errors); +$icmsTpl->assign('imforum_back', mod_imforum_View::escape($back)); +$icmsTpl->assign('imforum_mod_do', 'report'); +$icmsTpl->assign('imforum_mod_title', _MD_IMFORUM_REPORT); +$icmsTpl->assign('imforum_mod_form', [ + 'action' => mod_imforum_View::link('report'), + 'token' => icms::$security->getTokenHTML(), + 'do' => 'report', + 'topic' => 0, + 'post' => $postId, + 'report' => 0, + 'subject' => $post->getVar('subject'), + 'forums' => [], + 'author' => '', + 'text' => '', + 'values' => ['report_text' => mod_imforum_View::escape($reason)], +]); + +include_once ICMS_ROOT_PATH . '/footer.php'; diff --git a/src/templates/imforum_forum.html b/src/templates/imforum_forum.html index ff0d085..815da9a 100644 --- a/src/templates/imforum_forum.html +++ b/src/templates/imforum_forum.html @@ -7,6 +7,13 @@

<{$imforum_forum.name}>

<{$smarty.const._MD_IMFORUM_MODERATORS}>: <{foreach from=$imforum_moderators item=moderator name=mods}><{$moderator}><{if !$smarty.foreach.mods.last}>, <{/if}><{/foreach}>

<{/if}> + <{if $imforum_mod_links}> +

<{$smarty.const._MD_IMFORUM_MODERATION}>: + <{$smarty.const._MD_IMFORUM_MOD_PENDING}> (<{$imforum_mod_links.pending.count}>) + <{$smarty.const._MD_IMFORUM_MOD_REPORTS}> (<{$imforum_mod_links.reports.count}>) +

+ <{/if}> + <{if $imforum_subforums}> diff --git a/src/templates/imforum_moderate.html b/src/templates/imforum_moderate.html new file mode 100644 index 0000000..6054328 --- /dev/null +++ b/src/templates/imforum_moderate.html @@ -0,0 +1,97 @@ +
+ <{include file="db:imforum_breadcrumb.html"}> +

<{$imforum_mod_title}>

+ <{if $imforum_errors}> +
+ <{foreach from=$imforum_errors item=error}>

<{$error}>

<{/foreach}> +
+ <{/if}> + + <{if $imforum_mod_do == 'pending'}> + <{if $imforum_mod_rows}> +
+ + + <{foreach from=$imforum_mod_rows item=row}> + "> + + + + <{/foreach}> + +
<{$smarty.const._MD_IMFORUM_MOD_WAITING}>
+ <{$row.subject}> (<{$row.topic}>) +
<{$row.author}> · <{$row.time}>
+
<{$row.excerpt}>
+
+ <{$smarty.const._MD_IMFORUM_MOD_APPROVE}> + <{$smarty.const._MD_IMFORUM_DELETE}> + <{if $row.suspend_url}><{$smarty.const._MD_IMFORUM_MOD_SUSPEND}><{/if}> +
+ <{else}> +

<{$smarty.const._MD_IMFORUM_MOD_NONE_WAITING}>

+ <{/if}> +

« <{$smarty.const._MD_IMFORUM_BACK}>

+ + <{elseif $imforum_mod_do == 'reports'}> + <{if $imforum_mod_rows}> + + + + <{foreach from=$imforum_mod_rows item=row}> + "> + + + + <{/foreach}> + +
<{$smarty.const._MD_IMFORUM_MOD_REPORTED}>
+ <{$row.subject}> +
<{$row.reporter}> · <{$row.time}>
+
<{$row.text}>
+
<{$smarty.const._MD_IMFORUM_MOD_HANDLE}>
+ <{else}> +

<{$smarty.const._MD_IMFORUM_MOD_NONE_REPORTS}>

+ <{/if}> +

« <{$smarty.const._MD_IMFORUM_BACK}>

+ + <{else}> +
+ <{$imforum_mod_form.token}> + + <{if $imforum_mod_form.topic}><{/if}> + <{if $imforum_mod_form.post}><{/if}> + <{if $imforum_mod_form.report}><{/if}> +

“<{$imforum_mod_form.subject}>”

+ + <{if $imforum_mod_do == 'move'}> +

+ <{elseif $imforum_mod_do == 'merge'}> +

+

<{$smarty.const._MD_IMFORUM_MOD_MERGE_HELP}>

+ <{elseif $imforum_mod_do == 'split'}> +

+

<{$smarty.const._MD_IMFORUM_MOD_SPLIT_HELP}>

+ <{elseif $imforum_mod_do == 'suspend'}> +

<{$smarty.const._MD_IMFORUM_MOD_SUSPEND_WHO}>: <{$imforum_mod_form.author}>

+

+

+ <{elseif $imforum_mod_do == 'handle'}> +
<{$imforum_mod_form.text}>
+

+ <{elseif $imforum_mod_do == 'report'}> +

<{$smarty.const._MD_IMFORUM_REPORT_HELP}>

+

+ <{elseif $imforum_mod_do == 'delete'}> +

<{$smarty.const._MD_IMFORUM_MOD_DELETE_CONFIRM}>

+ <{elseif $imforum_mod_do == 'approve'}> +

<{$smarty.const._MD_IMFORUM_MOD_APPROVE_CONFIRM}>

+ <{/if}> + +

<{$smarty.const._MD_IMFORUM_CANCEL}>

+
+ <{/if}> + diff --git a/src/templates/imforum_topic.html b/src/templates/imforum_topic.html index 278f758..52e4343 100644 --- a/src/templates/imforum_topic.html +++ b/src/templates/imforum_topic.html @@ -8,6 +8,11 @@

<{if $imforum_topic.prefix}>[<{$imforum_topic.prefix}>] <{/if}><{$imforum_to <{else}><{$smarty.const._MD_IMFORUM_VIEW_FLAT}> | <{$smarty.const._MD_IMFORUM_VIEW_TREE}><{/if}>

+ <{if $imforum_mod_tools}> +

<{$smarty.const._MD_IMFORUM_MODERATION}>: + <{foreach from=$imforum_mod_tools item=tool}><{$tool.label}> <{/foreach}> +

+ <{/if}> <{if $imforum_reply_url}>

<{$smarty.const._MD_IMFORUM_REPLY}>

<{/if}> <{$imforum_pager}> <{foreach from=$imforum_posts item=post}> @@ -53,12 +58,15 @@

<{if $imforum_topic.prefix}>[<{$imforum_topic.prefix}>] <{/if}><{$imforum_to <{foreach from=$post.edits item=edit name=edits}><{$edit.name}> (<{$edit.time}>)<{if !$smarty.foreach.edits.last}>, <{/if}><{/foreach}> <{/if}> - <{if $post.reply_url || $post.edit_url || $post.delete_url}> + <{if $post.reply_url || $post.edit_url || $post.delete_url || $post.report_url || $post.split_url || $post.suspend_url}>
<{if $post.reply_url}><{$smarty.const._MD_IMFORUM_REPLY}><{/if}> <{if $post.quote_url}><{$smarty.const._MD_IMFORUM_QUOTE}><{/if}> <{if $post.edit_url}><{$smarty.const._MD_IMFORUM_EDIT}><{/if}> <{if $post.delete_url}><{$smarty.const._MD_IMFORUM_DELETE}><{/if}> + <{if $post.report_url}><{$smarty.const._MD_IMFORUM_REPORT}><{/if}> + <{if $post.split_url}><{$smarty.const._MD_IMFORUM_MOD_SPLIT}><{/if}> + <{if $post.suspend_url}><{$smarty.const._MD_IMFORUM_MOD_SUSPEND}><{/if}>
<{/if}> diff --git a/src/topic.php b/src/topic.php index 18cc479..32a1449 100644 --- a/src/topic.php +++ b/src/topic.php @@ -62,6 +62,8 @@ $karma = new mod_imforum_KarmaService($permissions->getUid()); $canReply = $permissions->canReply($forum, $topic); +$canReport = $permissions->canReport($forum); +$firstPostId = $moderator ? (int) $topic->getVar('topic_first_post_id', 'e') : 0; $minutes = mod_imforum_Settings::getCount('online_minutes'); $posters = mod_imforum_PosterInfo::load(array_map(static fn (mod_imforum_Post $post): int => (int) $post->getVar('uid', 'e'), $posts), $minutes); @@ -89,6 +91,9 @@ $row['quote_url'] = ($canReply && !$row['locked']) ? mod_imforum_View::link('post', ['topic' => $topicId, 'post' => $postId, 'quote' => 1]) : ''; $row['edit_url'] = $row['can_edit'] ? mod_imforum_View::link('post', ['do' => 'edit', 'post' => $postId]) : ''; $row['delete_url'] = $row['can_delete'] ? mod_imforum_View::link('post', ['do' => 'delete', 'post' => $postId]) : ''; + $row['report_url'] = $canReport ? mod_imforum_View::link('report', ['post' => $postId]) : ''; + $row['split_url'] = ($moderator && $postId !== $firstPostId) ? mod_imforum_View::link('moderate', ['do' => 'split', 'post' => $postId]) : ''; + $row['suspend_url'] = ($moderator && $uid > 0 && $uid !== $permissions->getUid()) ? mod_imforum_View::link('moderate', ['do' => 'suspend', 'post' => $postId]) : ''; $rows[] = $row; } @@ -150,10 +155,21 @@ 'views' => (int) $topic->getVar('topic_views', 'e'), 'replies' => (int) $topic->getVar('topic_replies', 'e'), 'locked' => $topic->isLocked(), + 'sticky' => (int) $topic->getVar('topic_sticky', 'e') === 1, + 'digest' => (int) $topic->getVar('topic_digest', 'e') === 1, 'forum_url' => mod_imforum_View::link('forum', ['forum' => $forumId]), 'forum_name' => $forum->getVar('forum_name'), ]); $icmsTpl->assign('imforum_posts', $rows); +$topicLink = static fn (string $do): string => mod_imforum_View::link('moderate', ['do' => $do, 'topic' => $topicId]); +$icmsTpl->assign('imforum_mod_tools', $moderator ? [ + ['url' => $topicLink($topic->isLocked() ? 'unlock' : 'lock'), 'label' => $topic->isLocked() ? _MD_IMFORUM_MOD_UNLOCK : _MD_IMFORUM_MOD_LOCK], + ['url' => $topicLink((int) $topic->getVar('topic_sticky', 'e') === 1 ? 'unsticky' : 'sticky'), 'label' => (int) $topic->getVar('topic_sticky', 'e') === 1 ? _MD_IMFORUM_MOD_UNSTICKY : _MD_IMFORUM_MOD_STICKY], + ['url' => $topicLink((int) $topic->getVar('topic_digest', 'e') === 1 ? 'undigest' : 'digest'), 'label' => (int) $topic->getVar('topic_digest', 'e') === 1 ? _MD_IMFORUM_MOD_UNDIGEST : _MD_IMFORUM_MOD_DIGEST], + ['url' => $topicLink('move'), 'label' => _MD_IMFORUM_MOD_MOVE], + ['url' => $topicLink('merge'), 'label' => _MD_IMFORUM_MOD_MERGE], + ['url' => $topicLink('delete'), 'label' => _MD_IMFORUM_MOD_DELETE], +] : []); $icmsTpl->assign('imforum_reply_url', $canReply ? mod_imforum_View::link('post', ['topic' => $topicId]) : ''); // the quick reply is a short form on the page; with a captcha the full form is needed $quick = $canReply && (int) mod_imforum_Settings::get('quickreply_enabled') === 1 diff --git a/tests/Integration/ModerationTest.php b/tests/Integration/ModerationTest.php new file mode 100644 index 0000000..292c4eb --- /dev/null +++ b/tests/Integration/ModerationTest.php @@ -0,0 +1,305 @@ + 0, 'edit_timelimit' => 30]); + $category = self::category(); + $this->forumId = (int) self::forum((int) $category->id(), 'One')->id(); + $this->otherForumId = (int) self::forum((int) $category->id(), 'Two')->id(); + self::grantCategory((int) $category->id(), [2, 3]); + foreach ([$this->forumId, $this->otherForumId] as $forumId) { + self::grant($forumId, ['forum_access', 'forum_view'], [2, 3]); + self::grant($forumId, ['forum_post', 'forum_reply', 'forum_noapprove'], self::MEMBERS); + } + self::handler('moderator')->setModerators($this->forumId, [self::MODERATOR]); + } + + protected function tearDown(): void + { + Settings::override(null); + } + + private function moderator(): Moderation + { + return new Moderation(new Permissions(self::MEMBERS, self::MODERATOR), new ApprovalNotifier()); + } + + private function member(?ApprovalNotifier $notifier = null): Moderation + { + return new Moderation(new Permissions(self::MEMBERS, self::MEMBER), $notifier ?? new ApprovalNotifier()); + } + + private function webmaster(): Moderation + { + return new Moderation(new Permissions([1], 1, true), new ApprovalNotifier()); + } + + private function topicWithReplies(int $forumId, string $title, int $replies): \mod_imforum_Topic + { + $topic = self::topic($forumId, $title, self::MEMBER); + for ($i = 1; $i <= $replies; $i++) { + self::post((int) $topic->id(), "Re $i of $title", self::MEMBER, (int) $topic->getVar('topic_first_post_id', 'e')); + } + return self::reload('topic', (int) $topic->id()); + } + + public function testOnlyModeratorsOfTheForumLockPinAndFeature(): void + { + $topic = self::topic($this->forumId); + + self::assertFalse($this->member()->setLocked($topic, true)['ok']); + self::assertFalse(self::reload('topic', (int) $topic->id())->isLocked()); + + self::assertTrue($this->moderator()->setLocked($topic, true)['ok']); + self::assertTrue(self::reload('topic', (int) $topic->id())->isLocked()); + self::assertTrue($this->moderator()->setLocked($topic, false)['ok']); + self::assertFalse(self::reload('topic', (int) $topic->id())->isLocked()); + + self::assertTrue($this->moderator()->setSticky($topic, true)['ok']); + self::assertSame(1, (int) self::reload('topic', (int) $topic->id())->getVar('topic_sticky', 'e')); + self::assertTrue($this->moderator()->setDigest($topic, true)['ok']); + $featured = self::reload('topic', (int) $topic->id()); + self::assertSame(1, (int) $featured->getVar('topic_digest', 'e')); + self::assertGreaterThan(0, (int) $featured->getVar('digest_time', 'e')); + self::assertTrue($this->moderator()->setDigest($topic, false)['ok']); + self::assertSame(0, (int) self::reload('topic', (int) $topic->id())->getVar('digest_time', 'e')); + + $elsewhere = self::topic($this->otherForumId); + self::assertFalse($this->moderator()->setLocked($elsewhere, true)['ok'], 'moderates only forum one'); + } + + public function testMovingNeedsModerationOfBothForumsAndRecountsThem(): void + { + $topic = $this->topicWithReplies($this->forumId, 'Move me', 2); + self::assertFalse($this->moderator()->move($topic, $this->otherForumId)['ok'], 'not a moderator of forum two'); + + self::handler('moderator')->setModerators($this->otherForumId, [self::MODERATOR]); + self::assertFalse($this->moderator()->move($topic, $this->forumId)['ok'], 'same forum'); + self::assertTrue($this->moderator()->move($topic, $this->otherForumId)['ok']); + + self::assertSame(0, (int) self::reload('forum', $this->forumId)->getVar('forum_posts', 'e')); + $target = self::reload('forum', $this->otherForumId); + self::assertSame(1, (int) $target->getVar('forum_topics', 'e')); + self::assertSame(3, (int) $target->getVar('forum_posts', 'e')); + foreach (self::handler('post')->getObjects(new \icms_db_criteria_Item('topic_id', (int) $topic->id())) as $post) { + self::assertSame($this->otherForumId, (int) $post->getVar('forum_id', 'e')); + } + } + + public function testMergingKeepsTheCountersRight(): void + { + $target = $this->topicWithReplies($this->forumId, 'Target', 1); + $source = $this->topicWithReplies($this->forumId, 'Source', 2); + self::handler('topic')->incrementViews((int) $source->id()); + self::handler('topic')->incrementViews((int) $source->id()); + $source = self::reload('topic', (int) $source->id()); + $lastOfSource = (int) $source->getVar('topic_last_post_id', 'e'); + + self::assertFalse($this->moderator()->merge($target, $target)['ok']); + $outcome = $this->moderator()->merge($source, $target); + self::assertTrue($outcome['ok'], implode(', ', $outcome['errors'])); + + self::assertTrue(self::handler('topic')->get((int) $source->id())->isNew(), 'the source topic is gone'); + $merged = self::reload('topic', (int) $target->id()); + self::assertSame('Target', $merged->getVar('topic_title', 'n')); + self::assertSame(4, (int) $merged->getVar('topic_replies', 'e'), 'five posts, the first is no reply'); + self::assertSame($lastOfSource, (int) $merged->getVar('topic_last_post_id', 'e')); + self::assertSame(2, (int) $merged->getVar('topic_views', 'e')); + $forum = self::reload('forum', $this->forumId); + self::assertSame(1, (int) $forum->getVar('forum_topics', 'e')); + self::assertSame(5, (int) $forum->getVar('forum_posts', 'e')); + self::assertSame($lastOfSource, (int) $forum->getVar('forum_last_post_id', 'e')); + } + + public function testMergingAcrossForumsNeedsBoth(): void + { + $target = self::topic($this->otherForumId, 'Elsewhere'); + $source = self::topic($this->forumId, 'Here'); + self::assertFalse($this->moderator()->merge($source, $target)['ok']); + self::assertTrue($this->webmaster()->merge($source, $target)['ok']); + self::assertSame(2, (int) self::reload('forum', $this->otherForumId)->getVar('forum_posts', 'e')); + self::assertSame(0, (int) self::reload('forum', $this->forumId)->getVar('forum_posts', 'e')); + } + + public function testSplittingMovesThePostAndTheLaterOnes(): void + { + $topic = $this->topicWithReplies($this->forumId, 'Long', 3); + $posts = array_values(self::handler('post')->getObjects(new \icms_db_criteria_Item('topic_id', (int) $topic->id()))); + usort($posts, static fn ($a, $b): int => (int) $a->id() <=> (int) $b->id()); + $first = $posts[0]; + $second = $posts[1]; + $third = $posts[2]; + + self::assertFalse($this->moderator()->split($first, 'New')['ok'], 'the first post stays'); + self::assertFalse($this->moderator()->split($second, ' ')['ok'], 'a title is needed'); + self::assertFalse($this->member()->split($second, 'New')['ok']); + + $outcome = $this->moderator()->split($second, 'Split off'); + self::assertTrue($outcome['ok'], implode(', ', $outcome['errors'])); + $new = $outcome['topic']; + self::assertNotNull($new); + + $old = self::reload('topic', (int) $topic->id()); + self::assertSame(0, (int) $old->getVar('topic_replies', 'e')); + self::assertSame((int) $first->id(), (int) $old->getVar('topic_last_post_id', 'e')); + self::assertSame('Split off', $new->getVar('topic_title', 'n')); + self::assertSame(2, (int) $new->getVar('topic_replies', 'e')); + self::assertSame((int) $second->id(), (int) $new->getVar('topic_first_post_id', 'e')); + self::assertSame((int) $posts[3]->id(), (int) $new->getVar('topic_last_post_id', 'e')); + + self::assertSame(0, (int) self::reload('post', (int) $second->id())->getVar('pid', 'e')); + self::assertSame((int) $second->id(), (int) self::reload('post', (int) $third->id())->getVar('pid', 'e'), 'answers to a post left behind now answer the new first post'); + $forum = self::reload('forum', $this->forumId); + self::assertSame(2, (int) $forum->getVar('forum_topics', 'e')); + self::assertSame(4, (int) $forum->getVar('forum_posts', 'e')); + } + + public function testApprovingShowsTheTopicAndTellsSubscribersOnce(): void + { + $notifier = new ApprovalNotifier(); + $moderation = new Moderation(new Permissions(self::MEMBERS, self::MODERATOR), $notifier); + $guestPosting = new PostService(new Permissions([3], 0), new ApprovalNotifier()); + self::grant($this->forumId, ['forum_post'], [3]); + $created = $guestPosting->createTopic(self::reload('forum', $this->forumId), ['subject' => 'Waiting', 'post_text' => 'Hi', 'poster_name' => 'Guest']); + self::assertSame([], $created['errors']); + self::assertTrue($created['pending']); + self::assertSame(0, (int) self::reload('forum', $this->forumId)->getVar('forum_topics', 'e')); + + $post = self::reload('post', (int) $created['post']->id()); + self::assertFalse($this->member($notifier)->approve($post)['ok']); + self::assertSame([], $notifier->calls); + + self::assertTrue($moderation->approve($post)['ok']); + self::assertSame([[true, (int) $post->id()]], $notifier->calls, 'a new topic is announced as one'); + self::assertTrue($moderation->approve($post)['ok'], 'approving twice changes nothing'); + self::assertCount(1, $notifier->calls); + + $topic = self::reload('topic', (int) $created['topic']->id()); + self::assertSame(1, (int) $topic->getVar('approved', 'e')); + $forum = self::reload('forum', $this->forumId); + self::assertSame(1, (int) $forum->getVar('forum_topics', 'e')); + self::assertSame(1, (int) $forum->getVar('forum_posts', 'e')); + self::assertSame(1, self::handler('post')->countApproved((int) $topic->id())); + } + + public function testApprovingAReplyCountsItAndKeepsTheLastPostRight(): void + { + $topic = self::topic($this->forumId); + $waiting = self::post((int) $topic->id(), 'Waiting reply', self::MEMBER, 0, 0); + self::assertSame(0, (int) self::reload('topic', (int) $topic->id())->getVar('topic_replies', 'e')); + + self::assertTrue($this->moderator()->approve($waiting)['ok']); + $after = self::reload('topic', (int) $topic->id()); + self::assertSame(1, (int) $after->getVar('topic_replies', 'e')); + self::assertSame((int) $waiting->id(), (int) $after->getVar('topic_last_post_id', 'e')); + } + + public function testDeletingATopicRemovesPostsAndRecounts(): void + { + $topic = $this->topicWithReplies($this->forumId, 'Gone', 2); + self::assertFalse($this->member()->deleteTopic($topic)['ok']); + self::assertTrue($this->moderator()->deleteTopic($topic)['ok']); + self::assertSame(0, self::rows('post')); + self::assertSame(0, (int) self::reload('forum', $this->forumId)->getVar('forum_topics', 'e')); + } + + public function testMembersReportAndModeratorsHandle(): void + { + $topic = self::topic($this->forumId); + $post = self::reload('post', (int) $topic->getVar('topic_first_post_id', 'e')); + + $guest = new Moderation(new Permissions([3], 0), new ApprovalNotifier()); + self::assertFalse($guest->report($post, 'Spam')['ok'], 'guests cannot report'); + self::assertFalse($this->member()->report($post, ' ')['ok'], 'a reason is needed'); + self::assertTrue($this->member()->report($post, 'Spam')['ok']); + self::assertFalse($this->member()->report($post, 'Spam again')['ok'], 'one open report per member'); + self::assertSame(1, self::handler('report')->countOpenInForum($this->forumId)); + self::assertSame(0, self::handler('report')->countOpenInForum($this->otherForumId)); + + $report = array_values(self::handler('report')->getObjects())[0]; + self::assertFalse($this->member()->handleReport($report, 'Mine')['ok']); + self::assertTrue($this->moderator()->handleReport($report, 'Removed the link')['ok']); + $closed = self::reload('report', (int) $report->id()); + self::assertSame(mod_imforum_Report::RESULT_HANDLED, (int) $closed->getVar('report_result', 'e')); + self::assertSame(0, self::handler('report')->countOpenInForum($this->forumId)); + self::assertTrue($this->member()->report($post, 'It came back')['ok'], 'a handled report no longer blocks'); + } + + public function testASuspendedMemberReadsButCannotPost(): void + { + $forum = self::reload('forum', $this->forumId); + $topic = self::topic($this->forumId); + $member = new Permissions(self::MEMBERS, 6); + self::assertTrue($member->canReply($forum, $topic)); + + self::assertFalse($this->member()->suspend($forum, 6, 3, 'Rude')['ok'], 'members cannot suspend'); + self::assertFalse($this->moderator()->suspend($forum, 6, 0, 'Rude')['ok']); + self::assertFalse($this->moderator()->suspend($forum, self::MODERATOR, 3, 'Self')['ok']); + $outcome = $this->moderator()->suspend($forum, 6, 3, 'Rude'); + self::assertTrue($outcome['ok'], implode(', ', $outcome['errors'])); + + $suspended = new Permissions(self::MEMBERS, 6); + self::assertTrue($suspended->canReadForum($forum), 'reading stays possible'); + self::assertFalse($suspended->canReply($forum, $topic)); + self::assertFalse($suspended->canStartTopic($forum)); + $refused = (new PostService($suspended, new ApprovalNotifier()))->reply($forum, $topic, ['subject' => 'Hi', 'post_text' => 'Text']); + self::assertNotSame([], $refused['errors']); + self::assertNull($refused['post']); + self::assertFalse((new Permissions(self::MEMBERS, 7))->isSuspended($this->forumId), 'others are not affected'); + } + + public function testModeratorsCannotBeSuspended(): void + { + $forum = self::reload('forum', $this->forumId); + self::handler('moderator')->setModerators($this->forumId, [self::MODERATOR, 9]); + self::assertFalse($this->moderator()->suspend($forum, 9, 3, 'No')['ok']); + self::assertSame(0, self::rows('suspension')); + } + + public function testReportingNeedsReadAccess(): void + { + $hidden = (int) self::forum((int) self::category('Hidden')->id(), 'Hidden')->id(); + $topic = self::topic($hidden); + $post = self::reload('post', (int) $topic->getVar('topic_first_post_id', 'e')); + self::assertFalse($this->member()->report($post, 'Spam')['ok']); + } +} + +/** + * Remembers who would have been told instead of sending mail + */ +final class ApprovalNotifier extends mod_imforum_Notifier +{ + /** @var list */ + public array $calls = []; + + public function newPost(\mod_imforum_Post $post, \mod_imforum_Topic $topic, \mod_imforum_Forum $forum, bool $newTopic): void + { + $this->calls[] = [$newTopic, (int) $post->id()]; + } +} From 2f2c00e98d7a5b326de9973633fbf12379708e15 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 10:38:34 +0000 Subject: [PATCH 2/3] Show the phase in the module version: 1.0.5 Alpha Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MZy45V5RV9nx6Buq8vqKHr --- CHANGELOG.md | 4 +++- src/icms_version.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63bcbeb..b343da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog -## 1.0.0 Alpha (unreleased) +## 1.0.x Alpha (unreleased) + +The module version follows the phase while the module is in development: 1.0.5 Alpha is phase 5. - Phase 0: module skeleton for ImpressCMS 2.0 in IPF mode, install and update routines, English and Dutch language files, CI on PHP 8.2 to 8.5. - Phase 1: data model. 13 IPF objects with handlers (category, forum, moderator, topic, post, attachment, report, suspension, readmark, online, digest, archive, permtemplate), group permissions on categories and forums, counters and cascading deletes through handler events, indexes in `imforum_db_upgrade_1()`, labels in English and Dutch, integration tests against MySQL 5.5, MySQL 5.7 (MyISAM) and MariaDB 10.11. diff --git a/src/icms_version.php b/src/icms_version.php index 88f1262..d1c0185 100644 --- a/src/icms_version.php +++ b/src/icms_version.php @@ -18,9 +18,9 @@ $modversion = [ 'name' => _MI_IMFORUM_NAME, - 'version' => '1.0.0', + 'version' => '1.0.5', 'status' => 'Alpha', - 'status_version' => '1.0.0 Alpha', + 'status_version' => '1.0.5 Alpha', 'date' => '25 October 2026', 'description' => _MI_IMFORUM_DESC, 'author' => 'fiammybe', From cb1348a057b38fa46d34cae731215169d6991b34 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 12:32:05 +0000 Subject: [PATCH 3/3] Show the phase in the module status: 1.0.0 Alpha 5 Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MZy45V5RV9nx6Buq8vqKHr --- CHANGELOG.md | 4 ++-- src/icms_version.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b343da2..4aaf7c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog -## 1.0.x Alpha (unreleased) +## 1.0.0 Alpha (unreleased) -The module version follows the phase while the module is in development: 1.0.5 Alpha is phase 5. +While the module is in development the status carries the phase: 1.0.0 Alpha 5 is phase 5. - Phase 0: module skeleton for ImpressCMS 2.0 in IPF mode, install and update routines, English and Dutch language files, CI on PHP 8.2 to 8.5. - Phase 1: data model. 13 IPF objects with handlers (category, forum, moderator, topic, post, attachment, report, suspension, readmark, online, digest, archive, permtemplate), group permissions on categories and forums, counters and cascading deletes through handler events, indexes in `imforum_db_upgrade_1()`, labels in English and Dutch, integration tests against MySQL 5.5, MySQL 5.7 (MyISAM) and MariaDB 10.11. diff --git a/src/icms_version.php b/src/icms_version.php index d1c0185..6d88f43 100644 --- a/src/icms_version.php +++ b/src/icms_version.php @@ -18,9 +18,9 @@ $modversion = [ 'name' => _MI_IMFORUM_NAME, - 'version' => '1.0.5', - 'status' => 'Alpha', - 'status_version' => '1.0.5 Alpha', + 'version' => '1.0.0', + 'status' => 'Alpha 5', + 'status_version' => '1.0.0 Alpha 5', 'date' => '25 October 2026', 'description' => _MI_IMFORUM_DESC, 'author' => 'fiammybe',