comparison forum/Sources/ModSettings.php @ 76:e3e11437ecea website

Add forum code
author Chris Cannam
date Sun, 07 Jul 2013 11:25:48 +0200
parents
children
comparison
equal deleted inserted replaced
75:72f59aa7e503 76:e3e11437ecea
1 <?php
2 /**********************************************************************************
3 * ModSettings.php *
4 ***********************************************************************************
5 * SMF: Simple Machines Forum *
6 * Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) *
7 * =============================================================================== *
8 * Software Version: SMF 1.1 *
9 * Software by: Simple Machines (http://www.simplemachines.org) *
10 * Copyright 2006 by: Simple Machines LLC (http://www.simplemachines.org) *
11 * 2001-2006 by: Lewis Media (http://www.lewismedia.com) *
12 * Support, News, Updates at: http://www.simplemachines.org *
13 ***********************************************************************************
14 * This program is free software; you may redistribute it and/or modify it under *
15 * the terms of the provided license as published by Simple Machines LLC. *
16 * *
17 * This program is distributed in the hope that it is and will be useful, but *
18 * WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY *
19 * or FITNESS FOR A PARTICULAR PURPOSE. *
20 * *
21 * See the "license.txt" file for details of the Simple Machines license. *
22 * The latest version can always be found at http://www.simplemachines.org. *
23 **********************************************************************************/
24 if (!defined('SMF'))
25 die('Hacking attempt...');
26
27 /* This file is here to make it easier for installed mods to have settings
28 and options. It uses the following functions:
29
30 void ModifyFeatureSettings()
31 // !!!
32
33 void ModifyFeatureSettings2()
34 // !!!
35
36 void ModifyBasicSettings()
37 // !!!
38
39 void ModifyLayoutSettings()
40 // !!!
41
42 void ModifyKarmaSettings()
43 // !!!
44
45 Adding new settings to the $modSettings array:
46 ---------------------------------------------------------------------------
47 // !!!
48 */
49
50 /* Adding options to one of the setting screens isn't hard. The basic format for a checkbox is:
51 array('check', 'nameInModSettingsAndSQL'),
52
53 And for a text box:
54 array('text', 'nameInModSettingsAndSQL')
55 (NOTE: You have to add an entry for this at the bottom!)
56
57 In these cases, it will look for $txt['nameInModSettingsAndSQL'] as the description,
58 and $helptxt['nameInModSettingsAndSQL'] as the help popup description.
59
60 Here's a quick explanation of how to add a new item:
61
62 * A text input box. For textual values.
63 ie. array('text', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth',
64 &$txt['OptionalDescriptionOfTheOption'], 'OptionalReferenceToHelpAdmin'),
65
66 * A text input box. For numerical values.
67 ie. array('int', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth',
68 &$txt['OptionalDescriptionOfTheOption'], 'OptionalReferenceToHelpAdmin'),
69
70 * A text input box. For floating point values.
71 ie. array('float', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth',
72 &$txt['OptionalDescriptionOfTheOption'], 'OptionalReferenceToHelpAdmin'),
73
74 * A large text input box. Used for textual values spanning multiple lines.
75 ie. array('large_text', 'nameInModSettingsAndSQL', 'OptionalNumberOfRows',
76 &$txt['OptionalDescriptionOfTheOption'], 'OptionalReferenceToHelpAdmin'),
77
78 * A check box. Either one or zero. (boolean)
79 ie. array('check', 'nameInModSettingsAndSQL', null, &$txt['descriptionOfTheOption'],
80 'OptionalReferenceToHelpAdmin'),
81
82 * A selection box. Used for the selection of something from a list.
83 ie. array('select', 'nameInModSettingsAndSQL', array('valueForSQL' => &$txt['displayedValue']),
84 &$txt['descriptionOfTheOption'], 'OptionalReferenceToHelpAdmin'),
85 Note that just saying array('first', 'second') will put 0 in the SQL for 'first'.
86
87 * A password input box. Used for passwords, no less!
88 ie. array('password', 'nameInModSettingsAndSQL', 'OptionalInputBoxWidth',
89 &$txt['descriptionOfTheOption'], 'OptionalReferenceToHelpAdmin'),
90
91 For each option:
92 type (see above), variable name, size/possible values, description, helptext.
93 OR make type 'rule' for an empty string for a horizontal rule.
94 OR make type 'heading' with a string for a titled section. */
95
96 // This function passes control through to the relevant tab.
97 function ModifyFeatureSettings()
98 {
99 global $context, $txt, $scripturl, $modSettings, $sourcedir;
100
101 // You need to be an admin to edit settings!
102 isAllowedTo('admin_forum');
103
104 // All the admin bar, to make it right.
105 adminIndex('edit_mods_settings');
106 loadLanguage('Help');
107 loadLanguage('ModSettings');
108
109 // Will need the utility functions from here.
110 require_once($sourcedir . '/ManageServer.php');
111
112 $context['page_title'] = $txt['modSettings_title'];
113 $context['sub_template'] = 'show_settings';
114
115 $subActions = array(
116 'basic' => 'ModifyBasicSettings',
117 'layout' => 'ModifyLayoutSettings',
118 'karma' => 'ModifyKarmaSettings',
119 );
120
121 // By default do the basic settings.
122 $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'basic';
123 $context['sub_action'] = $_REQUEST['sa'];
124
125 // Load up all the tabs...
126 $context['admin_tabs'] = array(
127 'title' => &$txt['modSettings_title'],
128 'help' => 'modsettings',
129 'description' => $txt['smf3'],
130 'tabs' => array(
131 'basic' => array(
132 'title' => $txt['mods_cat_features'],
133 'href' => $scripturl . '?action=featuresettings;sa=basic;sesc=' . $context['session_id'],
134 ),
135 'layout' => array(
136 'title' => $txt['mods_cat_layout'],
137 'href' => $scripturl . '?action=featuresettings;sa=layout;sesc=' . $context['session_id'],
138 ),
139 'karma' => array(
140 'title' => $txt['smf293'],
141 'href' => $scripturl . '?action=featuresettings;sa=karma;sesc=' . $context['session_id'],
142 'is_last' => true,
143 ),
144 ),
145 );
146
147 // Select the right tab based on the sub action.
148 if (isset($context['admin_tabs']['tabs'][$context['sub_action']]))
149 $context['admin_tabs']['tabs'][$context['sub_action']]['is_selected'] = true;
150
151 // Call the right function for this sub-acton.
152 $subActions[$_REQUEST['sa']]();
153 }
154
155 // This function basically just redirects to the right save function.
156 function ModifyFeatureSettings2()
157 {
158 global $context, $txt, $scripturl, $modSettings, $sourcedir;
159
160 isAllowedTo('admin_forum');
161 loadLanguage('ModSettings');
162
163 // Quick session check...
164 checkSession();
165
166 require_once($sourcedir . '/ManageServer.php');
167
168 $subActions = array(
169 'basic' => 'ModifyBasicSettings',
170 'layout' => 'ModifyLayoutSettings',
171 'karma' => 'ModifyKarmaSettings',
172 );
173
174 // Default to core (I assume)
175 $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'basic';
176
177 // Actually call the saving function.
178 $subActions[$_REQUEST['sa']]();
179 }
180
181 function ModifyBasicSettings()
182 {
183 global $txt, $scripturl, $context, $settings, $sc, $modSettings;
184
185 $config_vars = array(
186 // Big Options... polls, sticky, bbc....
187 array('select', 'pollMode', array(&$txt['smf34'], &$txt['smf32'], &$txt['smf33'])),
188 '',
189 // Basic stuff, user languages, titles, flash, permissions...
190 array('check', 'allow_guestAccess'),
191 array('check', 'userLanguage'),
192 array('check', 'allow_editDisplayName'),
193 array('check', 'allow_hideOnline'),
194 array('check', 'allow_hideEmail'),
195 array('check', 'guest_hideContacts'),
196 array('check', 'titlesEnable'),
197 array('check', 'enable_buddylist'),
198 array('text', 'default_personalText'),
199 array('int', 'max_signatureLength'),
200 '',
201 // Stats, compression, cookies.... server type stuff.
202 array('text', 'time_format'),
203 array('select', 'number_format', array('1234.00' => '1234.00', '1,234.00' => '1,234.00', '1.234,00' => '1.234,00', '1 234,00' => '1 234,00', '1234,00' => '1234,00')),
204 array('float', 'time_offset'),
205 array('int', 'failed_login_threshold'),
206 array('int', 'lastActive'),
207 array('check', 'trackStats'),
208 array('check', 'hitStats'),
209 array('check', 'enableErrorLogging'),
210 array('check', 'securityDisable'),
211 '',
212 // Reactive on email, and approve on delete
213 array('check', 'send_validation_onChange'),
214 array('check', 'approveAccountDeletion'),
215 '',
216 // Option-ish things... miscellaneous sorta.
217 array('check', 'allow_disableAnnounce'),
218 array('check', 'disallow_sendBody'),
219 array('check', 'modlog_enabled'),
220 array('check', 'queryless_urls'),
221 '',
222 // Width/Height image reduction.
223 array('int', 'max_image_width'),
224 array('int', 'max_image_height'),
225 '',
226 // Reporting of personal messages?
227 array('check', 'enableReportPM'),
228 );
229
230 // Saving?
231 if (isset($_GET['save']))
232 {
233 // Fix PM settings.
234 $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
235 $save_vars = $config_vars;
236 $save_vars[] = array('text', 'pm_spam_settings');
237
238 saveDBSettings($save_vars);
239
240 writeLog();
241 redirectexit('action=featuresettings;sa=basic');
242 }
243
244 // Hack for PM spam settings.
245 list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
246 $config_vars[] = array('int', 'max_pm_recipients');
247 $config_vars[] = array('int', 'pm_posts_verification');
248 $config_vars[] = array('int', 'pm_posts_per_hour');
249
250 $context['post_url'] = $scripturl . '?action=featuresettings2;save;sa=basic';
251 $context['settings_title'] = $txt['mods_cat_features'];
252
253 prepareDBSettingContext($config_vars);
254 }
255
256 function ModifyLayoutSettings()
257 {
258 global $txt, $scripturl, $context, $settings, $sc;
259
260 $config_vars = array(
261 // Compact pages?
262 array('check', 'compactTopicPagesEnable'),
263 array('int', 'compactTopicPagesContiguous', null, $txt['smf235'] . '<div class="smalltext">' . str_replace(' ', '&nbsp;', '"3" ' . $txt['smf236'] . ': <b>1 ... 4 [5] 6 ... 9</b>') . '<br />' . str_replace(' ', '&nbsp;', '"5" ' . $txt['smf236'] . ': <b>1 ... 3 4 [5] 6 7 ... 9</b>') . '</div>'),
264 '',
265 // Stuff that just is everywhere - today, search, online, etc.
266 array('select', 'todayMod', array(&$txt['smf290'], &$txt['smf291'], &$txt['smf292'])),
267 array('check', 'topbottomEnable'),
268 array('check', 'onlineEnable'),
269 array('check', 'enableVBStyleLogin'),
270 '',
271 // Pagination stuff.
272 array('int', 'defaultMaxMembers'),
273 '',
274 // This is like debugging sorta.
275 array('check', 'timeLoadPageEnable'),
276 array('check', 'disableHostnameLookup'),
277 '',
278 // Who's online.
279 array('check', 'who_enabled'),
280 );
281
282 // Saving?
283 if (isset($_GET['save']))
284 {
285 saveDBSettings($config_vars);
286 redirectexit('action=featuresettings;sa=layout');
287
288 loadUserSettings();
289 writeLog();
290 }
291
292 $context['post_url'] = $scripturl . '?action=featuresettings2;save;sa=layout';
293 $context['settings_title'] = $txt['mods_cat_layout'];
294
295 prepareDBSettingContext($config_vars);
296 }
297
298 function ModifyKarmaSettings()
299 {
300 global $txt, $scripturl, $context, $settings, $sc;
301
302 $config_vars = array(
303 // Karma - On or off?
304 array('select', 'karmaMode', explode('|', $txt['smf64'])),
305 '',
306 // Who can do it.... and who is restricted by time limits?
307 array('int', 'karmaMinPosts'),
308 array('float', 'karmaWaitTime'),
309 array('check', 'karmaTimeRestrictAdmins'),
310 '',
311 // What does it look like? [smite]?
312 array('text', 'karmaLabel'),
313 array('text', 'karmaApplaudLabel'),
314 array('text', 'karmaSmiteLabel'),
315 );
316
317 // Saving?
318 if (isset($_GET['save']))
319 {
320 saveDBSettings($config_vars);
321 redirectexit('action=featuresettings;sa=karma');
322 }
323
324 $context['post_url'] = $scripturl . '?action=featuresettings2;save;sa=karma';
325 $context['settings_title'] = $txt['smf293'];
326
327 prepareDBSettingContext($config_vars);
328 }
329
330 ?>