From 33a41503f8df0b17c5fc105c6aadb78287388ea3 Mon Sep 17 00:00:00 2001 From: Victor Jay Date: Fri, 29 May 2026 04:32:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=96=E8=BE=91=E5=B7=B2=E8=BF=87?= =?UTF-8?q?=E5=AE=A1=E5=B8=96=E5=AD=90=E8=87=AA=E5=8A=A8=E9=80=80=E5=9B=9E?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 21 ++++++++++++++ composer.json | 29 +++++++++++++++++++ extend.php | 12 ++++++++ src/Listener/ReapproveOnEditListener.php | 36 ++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 LICENSE create mode 100644 composer.json create mode 100644 extend.php create mode 100644 src/Listener/ReapproveOnEditListener.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7e4d90f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 MetaLab + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c8f0601 --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "metazone/reapprove-on-edit", + "description": "编辑已通过审核的帖子时自动退回审核队列,防止恶意绕过审核。", + "type": "flarum-extension", + "license": "MIT", + "require": { + "flarum/core": "^1.0", + "flarum/approval": "^1.0" + }, + "autoload": { + "psr-4": { + "MetaZone\\ReapproveOnEdit\\": "src/" + } + }, + "extra": { + "flarum-extension": { + "title": "Reapprove On Edit", + "icon": { + "name": "fas fa-shield-alt", + "backgroundColor": "#e67e22", + "color": "#fff" + } + }, + "flarum-locale": { + "code": "en", + "title": "English" + } + } +} diff --git a/extend.php b/extend.php new file mode 100644 index 0000000..2ede3d0 --- /dev/null +++ b/extend.php @@ -0,0 +1,12 @@ +listen(Saving::class, ReapproveOnEditListener::class), +]; diff --git a/src/Listener/ReapproveOnEditListener.php b/src/Listener/ReapproveOnEditListener.php new file mode 100644 index 0000000..142b985 --- /dev/null +++ b/src/Listener/ReapproveOnEditListener.php @@ -0,0 +1,36 @@ +post; + + // 新帖子不处理 + if (! $post->exists) { + return; + } + + // 帖子未被审核通过 + if ($post->is_approved != 1) { + return; + } + + // 内容未变动 + if (! $post->isDirty('content')) { + return; + } + + // 管理员免审 + if (isset($event->actor) && $event->actor->isAdmin()) { + return; + } + + // 退回审核队列 + $post->is_approved = null; + } +}