|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Manage signature settings. |
|
5
|
|
|
* |
|
6
|
|
|
* @package ElkArte Forum |
|
7
|
|
|
* @copyright ElkArte Forum contributors |
|
8
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
|
9
|
|
|
* |
|
10
|
|
|
* @version 2.0 Beta 1 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace ElkArte\AdminController; |
|
14
|
|
|
|
|
15
|
|
|
use BBC\ParserWrapper; |
|
16
|
|
|
use ElkArte\AbstractController; |
|
17
|
|
|
use ElkArte\Action; |
|
18
|
|
|
use ElkArte\Languages\Txt; |
|
19
|
|
|
use ElkArte\SettingsForm\SettingsForm; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Signature administration controller. |
|
23
|
|
|
* This class allows modifying signature settings for the forum. |
|
24
|
|
|
*/ |
|
25
|
|
|
class ManageSignature extends AbstractController |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Pre-dispatch, called before other methods. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function pre_dispatch() |
|
31
|
|
|
{ |
|
32
|
|
|
// We need this in a few places, so it's easier to have it loaded here |
|
33
|
|
|
require_once(SUBSDIR . '/ManageFeatures.subs.php'); |
|
34
|
|
|
|
|
35
|
|
|
Txt::load('Help+ManageSettings'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Default action for this controller. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function action_index() |
|
42
|
|
|
{ |
|
43
|
|
|
$subActions = [ |
|
44
|
|
|
'sig' => [$this, 'action_signatureSettings_display', 'permission' => 'admin_forum'], |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
// Set up the action control |
|
48
|
|
|
$action = new Action('modify_sig'); |
|
49
|
|
|
|
|
50
|
|
|
// There is only one option |
|
51
|
|
|
$subAction = $action->initialize($subActions, 'sig'); |
|
52
|
|
|
$action->dispatch($subAction); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Display configuration settings for signatures on forum. |
|
57
|
|
|
* |
|
58
|
|
|
* - Accessed from ?action=admin;area=featuresettings;sa=sig; |
|
59
|
|
|
* |
|
60
|
|
|
* @event integrate_save_signature_settings |
|
61
|
|
|
*/ |
|
62
|
|
|
public function action_signatureSettings_display(): void |
|
63
|
|
|
{ |
|
64
|
|
|
global $context, $txt, $modSettings; |
|
65
|
|
|
|
|
66
|
|
|
// Initialize the form |
|
67
|
|
|
$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER); |
|
68
|
|
|
|
|
69
|
|
|
// Initialize it with our settings |
|
70
|
|
|
$settingsForm->setConfigVars($this->_signatureSettings()); |
|
71
|
|
|
|
|
72
|
|
|
// Set up the template. |
|
73
|
|
|
$context['page_title'] = $txt['signature_settings']; |
|
74
|
|
|
$context['sub_template'] = 'show_settings'; |
|
75
|
|
|
|
|
76
|
|
|
// Disable the max smileys option if we don't allow smileys at all! |
|
77
|
|
|
theme()->addInlineJavascript(' |
|
78
|
|
|
document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;', true); |
|
79
|
|
|
|
|
80
|
|
|
// Load all the signature settings. |
|
81
|
|
|
[$sig_limits, $sig_bbc] = explode(':', $modSettings['signature_settings']); |
|
82
|
|
|
$sig_limits = explode(',', $sig_limits); |
|
83
|
|
|
$disabledTags = empty($sig_bbc) ? [] : explode(',', $sig_bbc); |
|
84
|
|
|
|
|
85
|
|
|
// It does not work in signatures, and seriously, why would you do this? |
|
86
|
|
|
$disabledTags[] = 'footnote'; |
|
87
|
|
|
|
|
88
|
|
|
// Applying to ALL signatures?!! |
|
89
|
|
|
if ($this->_req->hasQuery('apply')) |
|
90
|
|
|
{ |
|
91
|
|
|
// Security! |
|
92
|
|
|
checkSession('get'); |
|
93
|
|
|
|
|
94
|
|
|
// This is horrid - but I suppose some people will want the option to do it. |
|
95
|
|
|
$applied_sigs = $this->_req->getQuery('step', 'intval', 0); |
|
96
|
|
|
updateAllSignatures($applied_sigs); |
|
97
|
|
|
|
|
98
|
|
|
$settings_applied = true; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$context['signature_settings'] = [ |
|
102
|
|
|
'enable' => $sig_limits[0] ?? 0, |
|
103
|
|
|
'max_length' => $sig_limits[1] ?? 0, |
|
104
|
|
|
'max_lines' => $sig_limits[2] ?? 0, |
|
105
|
|
|
'max_images' => $sig_limits[3] ?? 0, |
|
106
|
|
|
'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1, |
|
107
|
|
|
'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0, |
|
108
|
|
|
'max_image_width' => $sig_limits[5] ?? 0, |
|
109
|
|
|
'max_image_height' => $sig_limits[6] ?? 0, |
|
110
|
|
|
'max_font_size' => $sig_limits[7] ?? 0, |
|
111
|
|
|
'repetition_guests' => $sig_limits[8] ?? 0, |
|
112
|
|
|
'repetition_members' => $sig_limits[9] ?? 0, |
|
113
|
|
|
]; |
|
114
|
|
|
|
|
115
|
|
|
// Temporarily make each setting a modSetting! |
|
116
|
|
|
foreach ($context['signature_settings'] as $key => $value) |
|
117
|
|
|
{ |
|
118
|
|
|
$modSettings['signature_' . $key] = $value; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
// Make sure we check the right tags! |
|
122
|
|
|
$modSettings['bbc_disabled_signature_bbc'] = $disabledTags; |
|
123
|
|
|
|
|
124
|
|
|
// Saving? |
|
125
|
|
|
if ($this->_req->hasQuery('save')) |
|
126
|
|
|
{ |
|
127
|
|
|
checkSession(); |
|
128
|
|
|
|
|
129
|
|
|
// Clean up the tag stuff! |
|
130
|
|
|
$codes = ParserWrapper::instance()->getCodes(); |
|
131
|
|
|
$bbcTags = $codes->getTags(); |
|
132
|
|
|
|
|
133
|
|
|
$signature_bbc_enabledTags = $this->_req->getPost('signature_bbc_enabledTags', null, []); |
|
134
|
|
|
if (!is_array($signature_bbc_enabledTags)) |
|
135
|
|
|
{ |
|
136
|
|
|
$signature_bbc_enabledTags = [$signature_bbc_enabledTags]; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
// Do not mutate the request; keep a local copy for settings persistence |
|
140
|
|
|
$signature_bbc_enabledTags_local = $signature_bbc_enabledTags; |
|
141
|
|
|
|
|
142
|
|
|
$sig_limits = []; |
|
143
|
|
|
foreach (array_keys($context['signature_settings']) as $key) |
|
144
|
|
|
{ |
|
145
|
|
|
if ($key === 'allow_smileys') |
|
146
|
|
|
{ |
|
147
|
|
|
continue; |
|
148
|
|
|
} |
|
149
|
|
|
if ($key === 'max_smileys' && empty($this->_req->post->signature_allow_smileys)) |
|
150
|
|
|
{ |
|
151
|
|
|
$sig_limits[] = -1; |
|
152
|
|
|
} |
|
153
|
|
|
else |
|
154
|
|
|
{ |
|
155
|
|
|
$current_key = $this->_req->getPost('signature_' . $key, 'intval'); |
|
156
|
|
|
$sig_limits[] = empty($current_key) ? 0 : max(1, $current_key); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
call_integration_hook('integrate_save_signature_settings', [&$sig_limits, &$bbcTags]); |
|
161
|
|
|
|
|
162
|
|
|
// Build the combined signature settings string using locals (do not write back to request) |
|
163
|
|
|
$signature_settings_local = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $signature_bbc_enabledTags_local)); |
|
164
|
|
|
|
|
165
|
|
|
// Even though we have practically no settings, let's keep the convention going! |
|
166
|
|
|
$save_vars = []; |
|
167
|
|
|
$save_vars[] = ['text', 'signature_settings']; |
|
168
|
|
|
|
|
169
|
|
|
$settingsForm->setConfigVars($save_vars); |
|
170
|
|
|
// Start from posted values but override with our local computed values |
|
171
|
|
|
$config_values = (array) $this->_req->post; |
|
172
|
|
|
$config_values['signature_bbc_enabledTags'] = $signature_bbc_enabledTags_local; |
|
173
|
|
|
$config_values['signature_settings'] = $signature_settings_local; |
|
174
|
|
|
$settingsForm->setConfigValues($config_values); |
|
175
|
|
|
$settingsForm->save(); |
|
176
|
|
|
redirectexit('action=admin;area=featuresettings;sa=sig'); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'save']); |
|
180
|
|
|
$context['settings_title'] = $txt['signature_settings']; |
|
181
|
|
|
$context['settings_message'] = empty($settings_applied) ? sprintf($txt['signature_settings_warning'], getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'apply', '{session_data}'])) : $txt['signature_settings_applied']; |
|
182
|
|
|
|
|
183
|
|
|
$settingsForm->prepare(); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Return signature settings. |
|
188
|
|
|
* |
|
189
|
|
|
* - Used in admin center search and settings form |
|
190
|
|
|
* |
|
191
|
|
|
* @event integrate_modify_signature_settings Adds options to Signature Settings |
|
192
|
|
|
*/ |
|
193
|
|
|
private function _signatureSettings() |
|
194
|
|
|
{ |
|
195
|
|
|
global $txt; |
|
196
|
|
|
|
|
197
|
|
|
$config_vars = [ |
|
198
|
|
|
// Are signatures even enabled? |
|
199
|
|
|
['check', 'signature_enable'], |
|
200
|
|
|
'', |
|
201
|
|
|
// Tweaking settings! |
|
202
|
|
|
['int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']], |
|
203
|
|
|
['int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']], |
|
204
|
|
|
['int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']], |
|
205
|
|
|
['check', 'signature_allow_smileys', 'onclick' => "document.getElementById('signature_max_smileys').disabled = !this.checked;"], |
|
206
|
|
|
['int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']], |
|
207
|
|
|
['select', 'signature_repetition_guests', |
|
208
|
|
|
[ |
|
209
|
|
|
$txt['signature_always'], |
|
210
|
|
|
$txt['signature_onlyfirst'], |
|
211
|
|
|
$txt['signature_never'], |
|
212
|
|
|
], |
|
213
|
|
|
], |
|
214
|
|
|
['select', 'signature_repetition_members', |
|
215
|
|
|
[ |
|
216
|
|
|
$txt['signature_always'], |
|
217
|
|
|
$txt['signature_onlyfirst'], |
|
218
|
|
|
$txt['signature_never'], |
|
219
|
|
|
], |
|
220
|
|
|
], |
|
221
|
|
|
'', |
|
222
|
|
|
// Image settings. |
|
223
|
|
|
['int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']], |
|
224
|
|
|
['int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']], |
|
225
|
|
|
['int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']], |
|
226
|
|
|
'', |
|
227
|
|
|
['bbc', 'signature_bbc'], |
|
228
|
|
|
]; |
|
229
|
|
|
|
|
230
|
|
|
call_integration_hook('integrate_modify_signature_settings', [&$config_vars]); |
|
231
|
|
|
|
|
232
|
|
|
return $config_vars; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Public method to return the signature settings, used for admin search |
|
237
|
|
|
*/ |
|
238
|
|
|
public function signatureSettings_search() |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->_signatureSettings(); |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|