Skip to content

Commit 8b7a54d

Browse files
committed
Initial commit
1 parent 6101857 commit 8b7a54d

File tree

10 files changed

+732
-1
lines changed

10 files changed

+732
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# groupwarn
1+
# Group Warn
2+
23
Allows an administrator to enable/disable warning users in certain groups.
4+
5+
## Installation
6+
7+
1. Copy the extension to: `/ext/phpbbmodders/groupwarn`
8+
2. In the Administration Control Panel, navigate to: **Customise → Manage extensions**
9+
3. Enable the **Group Warn** extension
10+
11+
## Automated testing
12+
13+
We use automated unit tests to prevent regressions. Check out our build below:
14+
15+
[![Tests](https://github.com/phpbbmodders/groupwarn/actions/workflows/tests.yml/badge.svg)](https://github.com/phpbbmodders/groupwarn/actions/workflows/tests.yml)
16+
17+
## License
18+
19+
Licensed under the [GNU General Public License v2](license.txt)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<dl>
2+
<dt><label for="group_warn">{{ lang('GROUP_WARN') ~ lang('COLON') }}</label><br /><span>{{ lang('GROUP_WARN_EXPLAIN') }}</span></dt>
3+
<dd><input name="group_warn" type="checkbox" value="1" class="radio" id="group_warn"{{ GROUP_WARN }} /></dd>
4+
</dl>

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "phpbbmodders/groupwarn",
3+
"type": "phpbb-extension",
4+
"description": "Allows an administrator to enable/disable warning users in certain groups.",
5+
"homepage": "https://www.phpbbmodders.com/",
6+
"version": "1.0.0-dev",
7+
"time": "2026-03-05",
8+
"license": "GPL-2.0-only",
9+
"authors": [
10+
{
11+
"name": "phpBB Modders",
12+
"email": "board@phpbbmodders.com",
13+
"homepage": "https://www.phpbbmodders.com/",
14+
"role": "Extension Developer"
15+
}
16+
],
17+
"require": {
18+
"php": ">=8.1.0",
19+
"composer/installers": "~1.0"
20+
},
21+
"extra": {
22+
"display-name": "Group Warn",
23+
"soft-require": {
24+
"phpbb/phpbb": ">=3.3.16,<4.0.0@dev"
25+
}
26+
}
27+
}

config/services.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
phpbbmodders.groupwarn.listener:
3+
class: phpbbmodders\groupwarn\event\main_listener
4+
arguments:
5+
- '@dbal.conn'
6+
- '@language'
7+
- '@request'
8+
- '@template'
9+
- '@user'
10+
- '%core.table_prefix%'
11+
tags:
12+
- { name: event.listener }

event/main_listener.php

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<?php
2+
/**
3+
*
4+
* Group Warn extension for the phpBB Forum Software package
5+
*
6+
* @copyright (c) 2026, phpBB Modders, https://www.phpbbmodders.com/
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbbmodders\groupwarn\event;
12+
13+
/**
14+
* @ignore
15+
*/
16+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17+
18+
/**
19+
* Group Warn event listener
20+
*/
21+
class main_listener implements EventSubscriberInterface
22+
{
23+
/** @var \phpbb\db\driver\driver_interface */
24+
protected $db;
25+
26+
/** @var \phpbb\language\language */
27+
protected $language;
28+
29+
/** @var \phpbb\request\request */
30+
protected $request;
31+
32+
/** @var \phpbb\template\template */
33+
protected $template;
34+
35+
/** @var \phpbb\user */
36+
protected $user;
37+
38+
/** @var string */
39+
protected $table_prefix;
40+
41+
/**
42+
* Constructor
43+
*
44+
* @param \phpbb\db\driver\driver_interface $db
45+
* @param \phpbb\language\language $language
46+
* @param \phpbb\request\request $request
47+
* @param \phpbb\template\template $template
48+
* @param \phpbb\user $user
49+
* @param string $table_prefix
50+
*/
51+
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\language\language $language, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $table_prefix)
52+
{
53+
$this->db = $db;
54+
$this->language = $language;
55+
$this->request = $request;
56+
$this->template = $template;
57+
$this->user = $user;
58+
$this->table_prefix = $table_prefix;
59+
}
60+
61+
/**
62+
* Map phpBB core events to the listener methods that should handle those events
63+
*
64+
* @return array
65+
*/
66+
public static function getSubscribedEvents()
67+
{
68+
return [
69+
'core.user_setup' => 'user_setup',
70+
71+
// ACP
72+
'core.acp_manage_group_request_data' => 'acp_manage_group_request_data',
73+
'core.acp_manage_group_initialise_data' => 'acp_manage_group_initialise_data',
74+
'core.acp_manage_group_display_form' => 'acp_manage_group_display_form',
75+
76+
// MCP
77+
'core.mcp_warn_post_before' => 'mcp_warn_before',
78+
'core.mcp_warn_user_before' => 'mcp_warn_before',
79+
80+
// Memberlist
81+
'core.memberlist_view_profile' => 'memberlist_view_profile',
82+
83+
// Viewtopic
84+
'core.viewtopic_modify_post_action_conditions' => 'viewtopic_modify_post_action_conditions',
85+
];
86+
}
87+
88+
/**
89+
* Load common language files
90+
*/
91+
public function user_setup($event)
92+
{
93+
$lang_set_ext = $event['lang_set_ext'];
94+
$lang_set_ext[] = [
95+
'ext_name' => 'phpbbmodders/groupwarn',
96+
'lang_set' => 'common',
97+
];
98+
$event['lang_set_ext'] = $lang_set_ext;
99+
}
100+
101+
/**
102+
* Request group data and operate on it
103+
*/
104+
public function acp_manage_group_request_data($event)
105+
{
106+
$event->update_subarray('submit_ary', 'warn', $this->request->variable('group_warn', 0));
107+
}
108+
109+
/**
110+
* Initialise data before displaying the add/edit form
111+
*/
112+
public function acp_manage_group_initialise_data($event)
113+
{
114+
$event->update_subarray('test_variables', 'warn', 'int');
115+
}
116+
117+
/**
118+
* Modify group template data before displaying the form
119+
*/
120+
public function acp_manage_group_display_form($event)
121+
{
122+
$this->template->assign_vars([
123+
'GROUP_WARN' => (!empty($event['group_row']['group_warn'])) ? ' checked="checked"' : '',
124+
]);
125+
}
126+
127+
/**
128+
* Event for before warning a user
129+
*/
130+
public function mcp_warn_before($event)
131+
{
132+
$group_warn = $this->query_warn_groups();
133+
134+
if (in_array($event['user_row']['user_id'], $group_warn) && $this->user->data['user_type'] != USER_FOUNDER)
135+
{
136+
trigger_error($this->language->lang('CANNOT_WARN_USER_GROUP'));
137+
}
138+
}
139+
140+
/**
141+
* Modify user data before displaying the profile
142+
*/
143+
public function memberlist_view_profile($event)
144+
{
145+
$group_warn = $this->query_warn_groups();
146+
147+
if (in_array($event['member']['user_id'], $group_warn) && $this->user->data['user_type'] != USER_FOUNDER)
148+
{
149+
$event['warn_user_enabled'] = false;
150+
}
151+
}
152+
153+
public function viewtopic_modify_post_action_conditions($event)
154+
{
155+
$group_warn = $this->query_warn_groups();
156+
157+
if (in_array($event['row']['user_id'], $group_warn) && $this->user->data['user_type'] != USER_FOUNDER)
158+
{
159+
$event['warn_allowed'] = false;
160+
}
161+
}
162+
163+
private function query_warn_groups()
164+
{
165+
$sql_array = [
166+
'SELECT' => 'g.group_id, g.group_warn, ug.user_id, ug.group_id',
167+
168+
'FROM' => [
169+
$this->table_prefix . 'groups' => 'g',
170+
],
171+
172+
'LEFT_JOIN' => [
173+
[
174+
'FROM' => [
175+
$this->table_prefix . 'user_group' => 'ug'
176+
],
177+
'ON' => 'g.group_id = ug.group_id'
178+
],
179+
],
180+
181+
'WHERE' => 'g.group_warn = 0'
182+
];
183+
184+
$sql = $this->db->sql_build_query('SELECT', $sql_array);
185+
$result = $this->db->sql_query($sql);
186+
$group_warn = [];
187+
while ($row = $this->db->sql_fetchrow($result))
188+
{
189+
$group_warn[] = (int) $row['user_id'];
190+
}
191+
$this->db->sql_freeresult($result);
192+
193+
return $group_warn;
194+
}
195+
}

ext.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
*
4+
* Group Warn extension for the phpBB Forum Software package
5+
*
6+
* @copyright (c) 2026, phpBB Modders, https://www.phpbbmodders.com/
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbbmodders\groupwarn;
12+
13+
/**
14+
* Group Warn extension base
15+
*
16+
* It is recommended to remove this file from
17+
* an extension if it is not going to be used.
18+
*/
19+
class ext extends \phpbb\extension\base
20+
{
21+
/**
22+
* Check whether the extension can be enabled.
23+
* The current phpBB version should meet or exceed
24+
* the minimum version required by this extension.
25+
*
26+
* @return bool|array
27+
* @access public
28+
*/
29+
public function is_enableable()
30+
{
31+
$enableable = $this->check_phpbb_version() && $this->check_php_version();
32+
33+
if (!$enableable)
34+
{
35+
$language = $this->container->get('language');
36+
$language->add_lang('install_groupwarn', 'phpbbmodders/groupwarn');
37+
38+
return $language->lang('GROUPWARN_NOT_ENABLEABLE');
39+
}
40+
41+
return $enableable;
42+
}
43+
44+
/**
45+
* Require phpBB 3.3.16
46+
*
47+
* @return bool
48+
*/
49+
protected function check_phpbb_version()
50+
{
51+
return phpbb_version_compare(PHPBB_VERSION, '3.3.16', '>=');
52+
}
53+
54+
/**
55+
* Require PHP 8.1
56+
*
57+
* @return bool
58+
*/
59+
protected function check_php_version()
60+
{
61+
return PHP_VERSION_ID >= 80100;
62+
}
63+
}

language/en/common.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
*
4+
* Group Warn extension for the phpBB Forum Software package
5+
*
6+
* @copyright (c) 2026, phpBB Modders, https://www.phpbbmodders.com/
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
if (!defined('IN_PHPBB'))
12+
{
13+
exit;
14+
}
15+
16+
if (empty($lang) || !is_array($lang))
17+
{
18+
$lang = [];
19+
}
20+
21+
// DEVELOPERS PLEASE NOTE
22+
//
23+
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
24+
//
25+
// Placeholders can now contain order information, e.g. instead of
26+
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
27+
// translators to re-order the output of data while ensuring it remains correct
28+
//
29+
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
30+
// equally where a string contains only two placeholders which are used to wrap text
31+
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
32+
//
33+
// Some characters you may want to copy&paste:
34+
// ’ » “ ” …
35+
//
36+
37+
$lang = array_merge($lang, [
38+
'GROUP_WARN' => 'Group warn',
39+
'GROUP_WARN_EXPLAIN' => 'Members in this group can be warned. Founders can always warn.',
40+
41+
'CANNOT_WARN_USER_GROUP' => 'You cannot warn this user. This user\'s group memebership prohibits warnings.',
42+
]);

0 commit comments

Comments
 (0)