Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWCS committed Jul 6, 2024
1 parent bfedcc8 commit 891faea
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 58 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "lukewcs/limitreplies",
"type": "phpbb-extension",
"description" : "Forces a waiting period between two posts in a topic if the last post was from the same user. Posts in the topic’s moderation queue are also taken into account.",
"description": "Forces a waiting period between two posts in a topic if the last post was from the same user. Posts in the topic’s moderation queue are also taken into account.",
"homepage": "https://github.com/LukeWCS/limit-multiple-replies",
"version": "1.0.0",
"time": "2024-06-23",
"version": "1.0.1",
"time": "2024-07-06",
"license": "GPL-2.0-only",
"authors": [
{
Expand All @@ -15,7 +15,7 @@
],
"require": {
"php": ">=7.1.3,<8.4.0@dev",
"composer/installers": "~1.0"
"composer/installers": "~1.0.0"
},
"extra": {
"display-name": "Limit Multiple Replies",
Expand Down
2 changes: 0 additions & 2 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ services:
- '@auth'
- '@user'
- '@dbal.conn'
- '%core.root_path%'
- '%core.php_ext%'
tags:
- { name: event.listener }
lukewcs.limitreplies.controller.acp:
Expand Down
21 changes: 16 additions & 5 deletions docs/limit-multiple-replies_build_changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
### 1.0.1
* Release (2024-07-06)
* Gründer sind jetzt generell ausgeschlossen.
* Listener:
* Nicht mehr benötigten Code von 1.0.0-rc1 entfernt.
* Code Optimierung.
* Foren-Template:
* Twig Code Optimierung.
* JS:
* Objektname gemäss JS Richtlinien benannt.

### 1.0.0
* Release (2024-06-23)
* Fix: Wenn die Wartezeit auf 1 Minute eingestellt war, dann wurde das als "1 Minuten" ausgegeben, weil die Plural-Funktion von `lang()` offensichtlich explizit einen Integer als Key benötigt, damit das funktioniert.
Expand All @@ -18,13 +29,13 @@
* Texte überarbeitet.

#### 1.0.0-b2
* ACP Modul:
* ACP-Template:
* Den Schalter bei "Erklärung anzeigen" durch ein Auswahlmenü ersetzt, damit diese Einstellung intuitiver und gleichzeitig flexibler wird.
* Twig Makro `select()` von FAR übernommen, mit dem Auswahlmenüs in Templates einfacher und effizienter realisiert werden können.
* ACP Controller:
* Controller an das neue Auswahlmenü angepasst.
* ACP-Controller:
* An das neue Auswahlmenü angepasst.
* Funktion `select_struct` von FAR übernommen zum Bauen einer Select Struktur fürs Template.
* Foren Frontend:
* Foren-Template:
* Bei der Klick-abhängigen Anzeige der Erklärung wird nicht mehr die bisherige Variante für die permanente Anzeige verwendet, sondern die phpBB Popup Funktion `phpbb.alert()`. Dadurch wurde es jetzt möglich, dass man auch bei den Zitat-Buttons die Erklärung anzeigen kann.
* Bei der permanenten Anzeige der Erklärung wird jetzt ein `not-allowed` Pointer bei den Antwort- und Zitat-Buttons verwendet. [Vorschlag von Kirk (phpBB.de)]
* Listener:
Expand All @@ -42,7 +53,7 @@
#### 1.0.0-b1
* Erste interne Testversion.
* Online Versionsprüfung bereits eingebaut und im Repo eingerichtet. Die VP zeigt jedoch während der Beta immer, dass die Version aktuell ist.
* Änderungen/Neuerungen gegenüber "Deny double posts":
* Änderungen/Neuerungen gegenüber "Deny double post":
* Statt einem hardcodet Wert für die Anzahl Sekunden gibts jetzt ein ACP Modul mit paar Einstellungen.
* Statt einem hardcodet Foren-Recht (Moderator Recht) gibt es jetzt ein eigenes Gruppen-Recht mit dem bei jeder Gruppe individuell festgelegt werden kann, ob sie die Sperre umgehen darf. Bei Admins und GlobMods ist das Recht per Standard bereits gesetzt.
* Gruppenrechte > Beiträge > Mehrfachantworten begrenzen: Kann Wartezeit umgehen
Expand Down
6 changes: 6 additions & 0 deletions docs/limit-multiple-replies_changelog_de.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 1.0.1
(2024-07-06)

* Gründer sind jetzt ebenfalls ausgeschlossen.
* Nicht mehr benötigten Code entfernt und Code Optimierung.

### 1.0.0
(2024-06-23)

Expand Down
2 changes: 1 addition & 1 deletion docs/version_check.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"stable": {
"3.3": {
"current": "1.0.0",
"current": "1.0.1",
"announcement": "https://github.com/LukeWCS/limit-multiple-replies/releases",
"eol": null,
"security": false
Expand Down
62 changes: 21 additions & 41 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ class listener implements EventSubscriberInterface
protected $auth;
protected $user;
protected $db;
protected $phpbb_root_path;
protected $php_ext;

protected $wait_time;

public function __construct(
\phpbb\language\language $language,
\phpbb\template\template $template,
\phpbb\config\config $config,
\phpbb\auth\auth $auth,
\phpbb\user $user,
\phpbb\db\driver\driver_interface $db,
$phpbb_root_path,
$php_ext
\phpbb\db\driver\driver_interface $db
)
{
$this->language = $language;
Expand All @@ -45,24 +39,20 @@ public function __construct(
$this->auth = $auth;
$this->user = $user;
$this->db = $db;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;

$this->wait_time = $this->config['limitreplies_number_wait_time'] * 60;
}

public static function getSubscribedEvents(): array
{
return array(
return [
'core.viewtopic_modify_page_title' => 'set_template_vars',
'core.modify_posting_auth' => 'check_posting',
'core.permissions' => 'add_permissions',
);
];
}

public function set_template_vars($event): void
{
if ($this->user->data['user_type'] == USER_IGNORE
if ($this->user->data['user_type'] != USER_NORMAL
|| $this->auth->acl_get('u_limitreplies_bypass_lock')
|| !$this->config['limitreplies_switch_enable']
|| $event['topic_data']['topic_status'] == ITEM_LOCKED
Expand All @@ -77,15 +67,15 @@ public function set_template_vars($event): void
{
$this->template->assign_vars([
'S_QUICK_REPLY' => false,
'LIMITREPLIES_MESSAGE' => (string) $this->create_message($locked_until_time),
'LIMITREPLIES_MESSAGE' => $this->create_message($locked_until_time),
'LIMITREPLIES_SELECT_HINT_MODE' => (int) $this->config['limitreplies_select_hint_mode'],
]);
}
}

public function check_posting($event): void
{
if ($this->user->data['user_type'] == USER_IGNORE
if ($this->user->data['user_type'] != USER_NORMAL
|| !in_array($event['mode'], ['reply', 'quote', 'bump'])
|| $this->auth->acl_get('u_limitreplies_bypass_lock')
|| !$this->config['limitreplies_switch_enable']
Expand All @@ -108,46 +98,36 @@ public function add_permissions($event): void
$event->update_subarray('permissions', 'u_limitreplies_bypass_lock', ['lang' => 'ACL_U_LIMITREPLIES_BYPASS_LOCK', 'cat' => 'post']);
}

private function get_last_unapproved_post(int $topic_id, int $poster_id): ?array
{
$sql = 'SELECT post_id, post_time
FROM ' . POSTS_TABLE . '
WHERE topic_id = ' . (int) $topic_id . '
AND poster_id = ' . (int) $poster_id . '
AND post_visibility = 0
ORDER BY post_time DESC LIMIT 1';
$result = $this->db->sql_query($sql);
$post_row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);

return $post_row !== false ? $post_row : null;
}

private function get_lock_time(array $topic_data): int
{
if (!function_exists('group_memberships'))
{
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}

$locked_until_time = 0;
$wait_time = $this->config['limitreplies_number_wait_time'] * 60;
$locked_until_time = 0;

// Check whether there are posts in the queue of the topic.
if ($topic_data['topic_posts_unapproved'])
{
$last_unapproved_post = $this->get_last_unapproved_post($topic_data['topic_id'], $this->user->data['user_id']);
// Get the data of the user's last post in the topic queue, if such a post exists.
$sql = 'SELECT post_id, post_time
FROM ' . POSTS_TABLE . '
WHERE topic_id = ' . (int) $topic_data['topic_id'] . '
AND poster_id = ' . (int) $this->user->data['user_id'] . '
AND post_visibility = 0
ORDER BY post_time DESC LIMIT 1';
$result = $this->db->sql_query($sql);
$last_unapproved_post = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);

// Check if the timestamp of the user's last post in the queue is greater than the timestamp of the last visible post.
if ($last_unapproved_post !== null && $last_unapproved_post['post_time'] > $topic_data['topic_last_post_time'])
if ($last_unapproved_post !== false && $last_unapproved_post['post_time'] > $topic_data['topic_last_post_time'])
{
$locked_until_time = $last_unapproved_post['post_time'] + $this->wait_time;
$locked_until_time = $last_unapproved_post['post_time'] + $wait_time;
}
}

// Check if the last visible post was from the same user.
if ($locked_until_time == 0 && $topic_data['topic_last_poster_id'] == $this->user->data['user_id'])
{
$locked_until_time = $topic_data['topic_last_post_time'] + $this->wait_time;
$locked_until_time = $topic_data['topic_last_post_time'] + $wait_time;
}

return $locked_until_time > time() ? $locked_until_time : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
*
#}

{% if LIMITREPLIES_MESSAGE is defined && LIMITREPLIES_SELECT_HINT_MODE == 2 %}
{% if (LIMITREPLIES_SELECT_HINT_MODE ?? 0) == 2 %}
{% INCLUDE '@lukewcs_limitreplies/show_message.html' %}
{% endif %}
2 changes: 1 addition & 1 deletion styles/all/template/event/viewtopic_body_poll_before.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endif %}

<script>
const limitreplies = Object.freeze({
const LimitReplies = Object.freeze({
MessageTitle : {{ lang('INFORMATION')|json_encode }},
MessageText : {{ LIMITREPLIES_MESSAGE|json_encode }},
HintMode : {{ LIMITREPLIES_SELECT_HINT_MODE|json_encode }},
Expand Down
6 changes: 3 additions & 3 deletions styles/all/template/limitreplies.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ const HintModeAlways = 2;
$(function () {
$('a[href*="mode=quote"],a[href*="mode=reply"]').on('click', function (e) {
e.preventDefault();
if (limitreplies.HintMode == HintModeOnClick) {
phpbb.alert(limitreplies.MessageTitle, limitreplies.MessageText);
if (LimitReplies.HintMode == HintModeOnClick) {
phpbb.alert(LimitReplies.MessageTitle, LimitReplies.MessageText);
}
});

if (limitreplies.HintMode == HintModeAlways) {
if (LimitReplies.HintMode == HintModeAlways) {
$('a[href*="mode=quote"],a[href*="mode=reply"]').addClass('limitreplies_lock');
};
});
Expand Down

0 comments on commit 891faea

Please sign in to comment.