-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathAntiSpam.php
More file actions
163 lines (133 loc) · 4.88 KB
/
AntiSpam.php
File metadata and controls
163 lines (133 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2025 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 3
*/
declare(strict_types=1);
namespace SMF\Actions\Admin;
use SMF\ActionInterface;
use SMF\ActionTrait;
use SMF\BackwardCompatibility;
use SMF\Config;
use SMF\IntegrationHook;
use SMF\Lang;
use SMF\Menu;
use SMF\User;
use SMF\Utils;
/**
* Handles anti-spam settings.
*/
class AntiSpam implements ActionInterface
{
use ActionTrait;
use BackwardCompatibility;
/****************
* Public methods
****************/
/**
* Does the job.
*/
public function execute(): void
{
$config_vars = self::getConfigVars();
// You need to be an admin to edit settings!
User::$me->isAllowedTo('admin_forum');
// Saving?
if (isset($_GET['save'])) {
User::$me->checkSession();
// Fix PM settings.
$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
// Hack in guest requiring verification!
if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
$_POST['posts_require_captcha'] = -1;
}
$save_vars = $config_vars;
unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
$save_vars[] = ['text', 'pm_spam_settings'];
// Process all of our config vars from various agents.
\SMF\AntiSpam\AntiSpam::saveConfigVars();
IntegrationHook::call('integrate_save_spam_settings', [&$save_vars]);
// Now save.
ACP::saveDBSettings($save_vars);
$_SESSION['adm-save'] = true;
Utils::redirectexit('action=admin;area=antispam');
}
// Hack for PM spam settings.
list(Config::$modSettings['max_pm_recipients'], Config::$modSettings['pm_posts_verification'], Config::$modSettings['pm_posts_per_hour']) = explode(',', Config::$modSettings['pm_spam_settings']);
// Hack for guests requiring verification.
Config::$modSettings['guests_require_captcha'] = !empty(Config::$modSettings['posts_require_captcha']);
Config::$modSettings['posts_require_captcha'] = !isset(Config::$modSettings['posts_require_captcha']) || Config::$modSettings['posts_require_captcha'] == -1 ? 0 : Config::$modSettings['posts_require_captcha'];
// Some minor javascript for the guest post setting.
if (Config::$modSettings['posts_require_captcha']) {
Utils::$context['settings_post_javascript'] .= '
document.getElementById(\'guests_require_captcha\').disabled = true;';
}
// And everything else.
Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=antispam;save';
Utils::$context['settings_title'] = Lang::getTxt('antispam_Settings', file: 'ManageSettings');
Utils::$context['page_title'] = Lang::getTxt('antispam_title', file: 'Admin');
Utils::$context['sub_template'] = 'show_settings';
Menu::$loaded['admin']->tab_data = [
'title' => Lang::getTxt('antispam_title', file: 'Admin'),
'description' => Lang::getTxt('antispam_Settings_desc', file: 'ManageSettings'),
];
ACP::prepareDBSettingContext($config_vars);
}
/***********************
* Public static methods
***********************/
/**
* Gets the configuration variables for the anti-spam area.
*
* @return array $config_vars for the anti-spam area.
*/
public static function getConfigVars(): array
{
$agents = [];
$config_vars = [
['check', 'reg_verification'],
['check', 'search_enable_captcha'],
// This, my friend, is a cheat :p
'guest_verify' => [
'check',
'guests_require_captcha',
'subtext' => Lang::getTxt('setting_guests_require_captcha_desc', file: 'ManageSettings'),
],
[
'int',
'posts_require_captcha',
'subtext' => Lang::getTxt('posts_require_captcha_desc', file: 'ManageSettings'),
'min' => -1,
'onchange' => 'if (this.value > 0){ document.getElementById(\'guests_require_captcha\').checked = true; document.getElementById(\'guests_require_captcha\').disabled = true;} else {document.getElementById(\'guests_require_captcha\').disabled = false;}',
],
'',
// PM Settings
'pm1' => [
'int',
'max_pm_recipients',
'subtext' => Lang::getTxt('max_pm_recipients_note', file: 'ManageSettings'),
],
'pm2' => [
'int',
'pm_posts_verification',
'subtext' => Lang::getTxt('pm_posts_verification_note', file: 'ManageSettings'),
],
'pm3' => [
'int',
'pm_posts_per_hour',
'subtext' => Lang::getTxt('pm_posts_per_hour_note', file: 'ManageSettings'),
],
'antispamagents' => ['select', 'antispam_agents', &$agents, 'multiple' => true],
];
// Process all of our config vars from various agents.
\SMF\AntiSpam\AntiSpam::getConfigVars($config_vars, $agents);
IntegrationHook::call('integrate_spam_settings', [&$config_vars]);
return $config_vars;
}
}