comparison forum/Sources/ManageSettings.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 /**
4 * Simple Machines Forum (SMF)
5 *
6 * @package SMF
7 * @author Simple Machines http://www.simplemachines.org
8 * @copyright 2011 Simple Machines
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
10 *
11 * @version 2.0
12 */
13
14 if (!defined('SMF'))
15 die('Hacking attempt...');
16
17 /* This file is here to make it easier for installed mods to have settings
18 and options. It uses the following functions:
19
20 void ModifyFeatureSettings()
21 // !!!
22
23 void ModifySecuritySettings()
24 // !!!
25
26 void ModifyModSettings()
27 // !!!
28
29 void ModifyCoreFeatures()
30 // !!!
31
32 void ModifyBasicSettings()
33 // !!!
34
35 void ModifyGeneralSecuritySettings()
36 // !!!
37
38 void ModifyLayoutSettings()
39 // !!!
40
41 void ModifyKarmaSettings()
42 // !!!
43
44 void ModifyModerationSettings()
45 // !!!
46
47 void ModifySpamSettings()
48 // !!!
49
50 void ModifySignatureSettings()
51 // !!!
52
53 void pauseSignatureApplySettings()
54 // !!!
55
56 void ShowCustomProfiles()
57 // !!!
58
59 void EditCustomProfiles()
60 // !!!
61
62 void ModifyPruningSettings()
63 // !!!
64
65 void disablePostModeration()
66 // !!!
67 // !!!
68 */
69
70 // This just avoids some repetition.
71 function loadGeneralSettingParameters($subActions = array(), $defaultAction = '')
72 {
73 global $context, $txt, $sourcedir;
74
75 // You need to be an admin to edit settings!
76 isAllowedTo('admin_forum');
77
78 loadLanguage('Help');
79 loadLanguage('ManageSettings');
80
81 // Will need the utility functions from here.
82 require_once($sourcedir . '/ManageServer.php');
83
84 $context['sub_template'] = 'show_settings';
85
86 // By default do the basic settings.
87 $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($defaultAction) ? $defaultAction : array_pop(array_keys($subActions)));
88 $context['sub_action'] = $_REQUEST['sa'];
89 }
90
91 // This function passes control through to the relevant tab.
92 function ModifyFeatureSettings()
93 {
94 global $context, $txt, $scripturl, $modSettings, $settings;
95
96 $context['page_title'] = $txt['modSettings_title'];
97
98 $subActions = array(
99 'basic' => 'ModifyBasicSettings',
100 'layout' => 'ModifyLayoutSettings',
101 'karma' => 'ModifyKarmaSettings',
102 'sig' => 'ModifySignatureSettings',
103 'profile' => 'ShowCustomProfiles',
104 'profileedit' => 'EditCustomProfiles',
105 );
106
107 loadGeneralSettingParameters($subActions, 'basic');
108
109 // Load up all the tabs...
110 $context[$context['admin_menu_name']]['tab_data'] = array(
111 'title' => $txt['modSettings_title'],
112 'help' => 'featuresettings',
113 'description' => sprintf($txt['modSettings_desc'], $settings['theme_id'], $context['session_id'], $context['session_var']),
114 'tabs' => array(
115 'basic' => array(
116 ),
117 'layout' => array(
118 ),
119 'karma' => array(
120 ),
121 'sig' => array(
122 'description' => $txt['signature_settings_desc'],
123 ),
124 'profile' => array(
125 'description' => $txt['custom_profile_desc'],
126 ),
127 ),
128 );
129
130 // Call the right function for this sub-acton.
131 $subActions[$_REQUEST['sa']]();
132 }
133
134 // This function passes control through to the relevant security tab.
135 function ModifySecuritySettings()
136 {
137 global $context, $txt, $scripturl, $modSettings, $settings;
138
139 $context['page_title'] = $txt['admin_security_moderation'];
140
141 $subActions = array(
142 'general' => 'ModifyGeneralSecuritySettings',
143 'spam' => 'ModifySpamSettings',
144 'moderation' => 'ModifyModerationSettings',
145 );
146
147 loadGeneralSettingParameters($subActions, 'general');
148
149 // Load up all the tabs...
150 $context[$context['admin_menu_name']]['tab_data'] = array(
151 'title' => $txt['admin_security_moderation'],
152 'help' => 'securitysettings',
153 'description' => $txt['security_settings_desc'],
154 'tabs' => array(
155 'general' => array(
156 ),
157 'spam' => array(
158 'description' => $txt['antispam_Settings_desc'] ,
159 ),
160 'moderation' => array(
161 ),
162 ),
163 );
164
165 // Call the right function for this sub-acton.
166 $subActions[$_REQUEST['sa']]();
167 }
168
169 // This my friend, is for all the mod authors out there. They're like builders without the ass crack - with the possible exception of... /cut short
170 function ModifyModSettings()
171 {
172 global $context, $txt, $scripturl, $modSettings, $settings;
173
174 $context['page_title'] = $txt['admin_modifications'];
175
176 $subActions = array(
177 'general' => 'ModifyGeneralModSettings',
178 // Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
179 );
180
181 // Make it easier for mods to add new areas.
182 call_integration_hook('integrate_modify_modifications', array(&$subActions));
183
184 loadGeneralSettingParameters($subActions, 'general');
185
186 // Load up all the tabs...
187 $context[$context['admin_menu_name']]['tab_data'] = array(
188 'title' => $txt['admin_modifications'],
189 'help' => 'modsettings',
190 'description' => $txt['modification_settings_desc'],
191 'tabs' => array(
192 'general' => array(
193 ),
194 ),
195 );
196
197 // Call the right function for this sub-acton.
198 $subActions[$_REQUEST['sa']]();
199 }
200
201 // This is an overall control panel enabling/disabling lots of SMF's key feature components.
202 function ModifyCoreFeatures($return_config = false)
203 {
204 global $txt, $scripturl, $context, $settings, $sc, $modSettings;
205
206 /* This is an array of all the features that can be enabled/disabled - each option can have the following:
207 title - Text title of this item (If standard string does not exist).
208 desc - Description of this feature (If standard string does not exist).
209 image - Custom image to show next to feature.
210 settings - Array of settings to change (For each name => value) on enable - reverse is done for disable. If > 1 will not change value if set.
211 setting_callback- Function that returns an array of settings to save - takes one parameter which is value for this feature.
212 save_callback - Function called on save, takes state as parameter.
213 */
214 $core_features = array(
215 // cd = calendar.
216 'cd' => array(
217 'url' => 'action=admin;area=managecalendar',
218 'settings' => array(
219 'cal_enabled' => 1,
220 ),
221 ),
222 // cp = custom profile fields.
223 'cp' => array(
224 'url' => 'action=admin;area=featuresettings;sa=profile',
225 'save_callback' => create_function('$value', '
226 global $smcFunc;
227 if (!$value)
228 {
229 $smcFunc[\'db_query\'](\'\', \'
230 UPDATE {db_prefix}custom_fields
231 SET active = 0\');
232 }
233 '),
234 'setting_callback' => create_function('$value', '
235 if (!$value)
236 return array(
237 \'disabled_profile_fields\' => \'\',
238 \'registration_fields\' => \'\',
239 \'displayFields\' => \'\',
240 );
241 else
242 return array();
243 '),
244 ),
245 // k = karma.
246 'k' => array(
247 'url' => 'action=admin;area=featuresettings;sa=karma',
248 'settings' => array(
249 'karmaMode' => 2,
250 ),
251 ),
252 // ml = moderation log.
253 'ml' => array(
254 'url' => 'action=admin;area=logs;sa=modlog',
255 'settings' => array(
256 'modlog_enabled' => 1,
257 ),
258 ),
259 // pm = post moderation.
260 'pm' => array(
261 'url' => 'action=admin;area=permissions;sa=postmod',
262 'setting_callback' => create_function('$value', '
263 global $sourcedir;
264
265 // Cant use warning post moderation if disabled!
266 if (!$value)
267 {
268 require_once($sourcedir . \'/PostModeration.php\');
269 approveAllData();
270
271 return array(\'warning_moderate\' => 0);
272 }
273 else
274 return array();
275 '),
276 ),
277 // ps = Paid Subscriptions.
278 'ps' => array(
279 'url' => 'action=admin;area=paidsubscribe',
280 'settings' => array(
281 'paid_enabled' => 1,
282 ),
283 'setting_callback' => create_function('$value', '
284 global $smcFunc, $sourcedir;
285
286 // Set the correct disabled value for scheduled task.
287 $smcFunc[\'db_query\'](\'\', \'
288 UPDATE {db_prefix}scheduled_tasks
289 SET disabled = {int:disabled}
290 WHERE task = {string:task}\',
291 array(
292 \'disabled\' => $value ? 0 : 1,
293 \'task\' => \'paid_subscriptions\',
294 )
295 );
296
297 // Should we calculate next trigger?
298 if ($value)
299 {
300 require_once($sourcedir . \'/ScheduledTasks.php\');
301 CalculateNextTrigger(\'paid_subscriptions\');
302 }
303 '),
304 ),
305 // rg = report generator.
306 'rg' => array(
307 'url' => 'action=admin;area=reports',
308 ),
309 // w = warning.
310 'w' => array(
311 'url' => 'action=admin;area=securitysettings;sa=moderation',
312 'setting_callback' => create_function('$value', '
313 global $modSettings;
314 list ($modSettings[\'warning_enable\'], $modSettings[\'user_limit\'], $modSettings[\'warning_decrement\']) = explode(\',\', $modSettings[\'warning_settings\']);
315 $warning_settings = ($value ? 1 : 0) . \',\' . $modSettings[\'user_limit\'] . \',\' . $modSettings[\'warning_decrement\'];
316 if (!$value)
317 {
318 $returnSettings = array(
319 \'warning_watch\' => 0,
320 \'warning_moderate\' => 0,
321 \'warning_mute\' => 0,
322 );
323 }
324 elseif (empty($modSettings[\'warning_enable\']) && $value)
325 {
326 $returnSettings = array(
327 \'warning_watch\' => 10,
328 \'warning_moderate\' => 35,
329 \'warning_mute\' => 60,
330 );
331 }
332 else
333 $returnSettings = array();
334
335 $returnSettings[\'warning_settings\'] = $warning_settings;
336 return $returnSettings;
337 '),
338 ),
339 // Search engines
340 'sp' => array(
341 'url' => 'action=admin;area=sengines',
342 'settings' => array(
343 'spider_mode' => 1,
344 ),
345 'setting_callback' => create_function('$value', '
346 // Turn off the spider group if disabling.
347 if (!$value)
348 return array(\'spider_group\' => 0, \'show_spider_online\' => 0);
349 '),
350 'on_save' => create_function('', '
351 global $sourcedir, $modSettings;
352 require_once($sourcedir . \'/ManageSearchEngines.php\');
353 recacheSpiderNames();
354 '),
355 ),
356 );
357
358 // Anyone who would like to add a core feature?
359 call_integration_hook('integrate_core_features', array(&$core_features));
360
361 // Are we getting info for the help section.
362 if ($return_config)
363 {
364 $return_data = array();
365 foreach ($core_features as $id => $data)
366 $return_data[] = array('switch', isset($data['title']) ? $data['title'] : $txt['core_settings_item_' . $id]);
367 return $return_data;
368 }
369
370 loadGeneralSettingParameters();
371
372 // Are we saving?
373 if (isset($_POST['save']))
374 {
375 checkSession();
376
377 $setting_changes = array('admin_features' => array());
378
379 // Are we using the javascript stuff or radios to submit?
380 $post_var_prefix = empty($_POST['js_worked']) ? 'feature_plain_' : 'feature_';
381
382 // Cycle each feature and change things as required!
383 foreach ($core_features as $id => $feature)
384 {
385 // Enabled?
386 if (!empty($_POST[$post_var_prefix . $id]))
387 $setting_changes['admin_features'][] = $id;
388
389 // Setting values to change?
390 if (isset($feature['settings']))
391 {
392 foreach ($feature['settings'] as $key => $value)
393 {
394 if (empty($_POST[$post_var_prefix . $id]) || (!empty($_POST[$post_var_prefix . $id]) && ($value < 2 || empty($modSettings[$key]))))
395 $setting_changes[$key] = !empty($_POST[$post_var_prefix . $id]) ? $value : !$value;
396 }
397 }
398 // Is there a call back for settings?
399 if (isset($feature['setting_callback']))
400 {
401 $returned_settings = $feature['setting_callback'](!empty($_POST[$post_var_prefix . $id]));
402 if (!empty($returned_settings))
403 $setting_changes = array_merge($setting_changes, $returned_settings);
404 }
405
406 // Standard save callback?
407 if (isset($feature['on_save']))
408 $feature['on_save']();
409 }
410
411 // Make sure this one setting is a string!
412 $setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']);
413
414 // Make any setting changes!
415 updateSettings($setting_changes);
416
417 // Any post save things?
418 foreach ($core_features as $id => $feature)
419 {
420 // Standard save callback?
421 if (isset($feature['save_callback']))
422 $feature['save_callback'](!empty($_POST[$post_var_prefix . $id]));
423 }
424
425 redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']);
426 }
427
428 // Put them in context.
429 $context['features'] = array();
430 foreach ($core_features as $id => $feature)
431 $context['features'][$id] = array(
432 'title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id],
433 'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'],
434 'enabled' => in_array($id, $context['admin_features']),
435 'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '',
436 );
437
438 // Are they a new user?
439 $context['is_new_install'] = !isset($modSettings['admin_features']);
440 $context['force_disable_tabs'] = $context['is_new_install'];
441 // Don't show them this twice!
442 if ($context['is_new_install'])
443 updateSettings(array('admin_features' => ''));
444
445 $context['sub_template'] = 'core_features';
446 $context['page_title'] = $txt['core_settings_title'];
447 }
448
449 function ModifyBasicSettings($return_config = false)
450 {
451 global $txt, $scripturl, $context, $settings, $sc, $modSettings;
452
453 $config_vars = array(
454 // Big Options... polls, sticky, bbc....
455 array('select', 'pollMode', array($txt['disable_polls'], $txt['enable_polls'], $txt['polls_as_topics'])),
456 '',
457 // Basic stuff, titles, flash, permissions...
458 array('check', 'allow_guestAccess'),
459 array('check', 'enable_buddylist'),
460 array('check', 'allow_editDisplayName'),
461 array('check', 'allow_hideOnline'),
462 array('check', 'titlesEnable'),
463 array('text', 'default_personal_text'),
464 '',
465 // SEO stuff
466 array('check', 'queryless_urls'),
467 array('text', 'meta_keywords', 'size' => 50),
468 '',
469 // Number formatting, timezones.
470 array('text', 'time_format'),
471 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')),
472 array('float', 'time_offset'),
473 'default_timezone' => array('select', 'default_timezone', array()),
474 '',
475 // Who's online?
476 array('check', 'who_enabled'),
477 array('int', 'lastActive'),
478 '',
479 // Statistics.
480 array('check', 'trackStats'),
481 array('check', 'hitStats'),
482 '',
483 // Option-ish things... miscellaneous sorta.
484 array('check', 'allow_disableAnnounce'),
485 array('check', 'disallow_sendBody'),
486 );
487
488 // Get all the time zones.
489 if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set'))
490 {
491 $all_zones = timezone_identifiers_list();
492 // Make sure we set the value to the same as the printed value.
493 foreach ($all_zones as $zone)
494 $config_vars['default_timezone'][2][$zone] = $zone;
495 }
496 else
497 unset($config_vars['default_timezone']);
498
499 if ($return_config)
500 return $config_vars;
501
502 // Saving?
503 if (isset($_GET['save']))
504 {
505 checkSession();
506
507 // Prevent absurd boundaries here - make it a day tops.
508 if (isset($_POST['lastActive']))
509 $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
510
511 saveDBSettings($config_vars);
512
513 writeLog();
514 redirectexit('action=admin;area=featuresettings;sa=basic');
515 }
516
517 $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic';
518 $context['settings_title'] = $txt['mods_cat_features'];
519
520 prepareDBSettingContext($config_vars);
521 }
522
523 // Settings really associated with general security aspects.
524 function ModifyGeneralSecuritySettings($return_config = false)
525 {
526 global $txt, $scripturl, $context, $settings, $sc, $modSettings;
527
528 $config_vars = array(
529 array('check', 'guest_hideContacts'),
530 array('check', 'make_email_viewable'),
531 '',
532 array('int', 'failed_login_threshold'),
533 '',
534 array('check', 'enableErrorLogging'),
535 array('check', 'enableErrorQueryLogging'),
536 array('check', 'securityDisable'),
537 '',
538 // Reactive on email, and approve on delete
539 array('check', 'send_validation_onChange'),
540 array('check', 'approveAccountDeletion'),
541 '',
542 // Password strength.
543 array('select', 'password_strength', array($txt['setting_password_strength_low'], $txt['setting_password_strength_medium'], $txt['setting_password_strength_high'])),
544 '',
545 // Reporting of personal messages?
546 array('check', 'enableReportPM'),
547 );
548
549 if ($return_config)
550 return $config_vars;
551
552 // Saving?
553 if (isset($_GET['save']))
554 {
555 checkSession();
556
557 saveDBSettings($config_vars);
558
559 writeLog();
560 redirectexit('action=admin;area=securitysettings;sa=general');
561 }
562
563 $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=general';
564 $context['settings_title'] = $txt['mods_cat_security_general'];
565
566 prepareDBSettingContext($config_vars);
567 }
568
569 function ModifyLayoutSettings($return_config = false)
570 {
571 global $txt, $scripturl, $context, $settings, $sc;
572
573 $config_vars = array(
574 // Pagination stuff.
575 array('check', 'compactTopicPagesEnable'),
576 array('int', 'compactTopicPagesContiguous', null, $txt['contiguous_page_display'] . '<div class="smalltext">' . str_replace(' ', '&nbsp;', '"3" ' . $txt['to_display'] . ': <strong>1 ... 4 [5] 6 ... 9</strong>') . '<br />' . str_replace(' ', '&nbsp;', '"5" ' . $txt['to_display'] . ': <strong>1 ... 3 4 [5] 6 7 ... 9</strong>') . '</div>'),
577 array('int', 'defaultMaxMembers'),
578 '',
579 // Stuff that just is everywhere - today, search, online, etc.
580 array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'])),
581 array('check', 'topbottomEnable'),
582 array('check', 'onlineEnable'),
583 array('check', 'enableVBStyleLogin'),
584 '',
585 // Automagic image resizing.
586 array('int', 'max_image_width'),
587 array('int', 'max_image_height'),
588 '',
589 // This is like debugging sorta.
590 array('check', 'timeLoadPageEnable'),
591 );
592
593 if ($return_config)
594 return $config_vars;
595
596 // Saving?
597 if (isset($_GET['save']))
598 {
599 checkSession();
600
601 saveDBSettings($config_vars);
602 writeLog();
603
604 redirectexit('action=admin;area=featuresettings;sa=layout');
605 }
606
607 $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout';
608 $context['settings_title'] = $txt['mods_cat_layout'];
609
610 prepareDBSettingContext($config_vars);
611 }
612
613 function ModifyKarmaSettings($return_config = false)
614 {
615 global $txt, $scripturl, $context, $settings, $sc;
616
617 $config_vars = array(
618 // Karma - On or off?
619 array('select', 'karmaMode', explode('|', $txt['karma_options'])),
620 '',
621 // Who can do it.... and who is restricted by time limits?
622 array('int', 'karmaMinPosts'),
623 array('float', 'karmaWaitTime'),
624 array('check', 'karmaTimeRestrictAdmins'),
625 '',
626 // What does it look like? [smite]?
627 array('text', 'karmaLabel'),
628 array('text', 'karmaApplaudLabel'),
629 array('text', 'karmaSmiteLabel'),
630 );
631
632 if ($return_config)
633 return $config_vars;
634
635 // Saving?
636 if (isset($_GET['save']))
637 {
638 checkSession();
639
640 saveDBSettings($config_vars);
641 redirectexit('action=admin;area=featuresettings;sa=karma');
642 }
643
644 $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=karma';
645 $context['settings_title'] = $txt['karma'];
646
647 prepareDBSettingContext($config_vars);
648 }
649
650 // Moderation type settings - although there are fewer than we have you believe ;)
651 function ModifyModerationSettings($return_config = false)
652 {
653 global $txt, $scripturl, $context, $settings, $sc, $modSettings;
654
655 $config_vars = array(
656 // Warning system?
657 array('int', 'warning_watch', 'help' => 'warning_enable'),
658 'moderate' => array('int', 'warning_moderate'),
659 array('int', 'warning_mute'),
660 'rem1' => array('int', 'user_limit'),
661 'rem2' => array('int', 'warning_decrement'),
662 array('select', 'warning_show', array($txt['setting_warning_show_mods'], $txt['setting_warning_show_user'], $txt['setting_warning_show_all'])),
663 );
664
665 if ($return_config)
666 return $config_vars;
667
668 // Cannot use moderation if post moderation is not enabled.
669 if (!$modSettings['postmod_active'])
670 unset($config_vars['moderate']);
671
672 // Saving?
673 if (isset($_GET['save']))
674 {
675 checkSession();
676
677 // Make sure these don't have an effect.
678 if (substr($modSettings['warning_settings'], 0, 1) != 1)
679 {
680 $_POST['warning_watch'] = 0;
681 $_POST['warning_moderate'] = 0;
682 $_POST['warning_mute'] = 0;
683 }
684 else
685 {
686 $_POST['warning_watch'] = min($_POST['warning_watch'], 100);
687 $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
688 $_POST['warning_mute'] = min($_POST['warning_mute'], 100);
689 }
690
691 // Fix the warning setting array!
692 $_POST['warning_settings'] = '1,' . min(100, (int) $_POST['user_limit']) . ',' . min(100, (int) $_POST['warning_decrement']);
693 $save_vars = $config_vars;
694 $save_vars[] = array('text', 'warning_settings');
695 unset($save_vars['rem1'], $save_vars['rem2']);
696
697 saveDBSettings($save_vars);
698 redirectexit('action=admin;area=securitysettings;sa=moderation');
699 }
700
701 // We actually store lots of these together - for efficiency.
702 list ($modSettings['warning_enable'], $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
703
704 $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=moderation';
705 $context['settings_title'] = $txt['moderation_settings'];
706
707 prepareDBSettingContext($config_vars);
708 }
709
710 // Let's try keep the spam to a minimum ah Thantos?
711 function ModifySpamSettings($return_config = false)
712 {
713 global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc;
714
715 // Generate a sample registration image.
716 $context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
717 $context['verification_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand());
718
719 $config_vars = array(
720 array('check', 'reg_verification'),
721 array('check', 'search_enable_captcha'),
722 // This, my friend, is a cheat :p
723 'guest_verify' => array('check', 'guests_require_captcha', 'subtext' => $txt['setting_guests_require_captcha_desc']),
724 array('int', 'posts_require_captcha', 'subtext' => $txt['posts_require_captcha_desc'], '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;}'),
725 array('check', 'guests_report_require_captcha'),
726 '',
727 // PM Settings
728 'pm1' => array('int', 'max_pm_recipients'),
729 'pm2' => array('int', 'pm_posts_verification'),
730 'pm3' => array('int', 'pm_posts_per_hour'),
731 // Visual verification.
732 array('title', 'configure_verification_means'),
733 array('desc', 'configure_verification_means_desc'),
734 'vv' => array('select', 'visual_verification_type', array($txt['setting_image_verification_off'], $txt['setting_image_verification_vsimple'], $txt['setting_image_verification_simple'], $txt['setting_image_verification_medium'], $txt['setting_image_verification_high'], $txt['setting_image_verification_extreme']), 'subtext'=> $txt['setting_visual_verification_type_desc'], 'onchange' => $context['use_graphic_library'] ? 'refreshImages();' : ''),
735 array('int', 'qa_verification_number', 'subtext' => $txt['setting_qa_verification_number_desc']),
736 // Clever Thomas, who is looking sheepy now? Not I, the mighty sword swinger did say.
737 array('title', 'setup_verification_questions'),
738 array('desc', 'setup_verification_questions_desc'),
739 array('callback', 'question_answer_list'),
740 );
741
742 if ($return_config)
743 return $config_vars;
744
745 // Load any question and answers!
746 $context['question_answers'] = array();
747 $request = $smcFunc['db_query']('', '
748 SELECT id_comment, body AS question, recipient_name AS answer
749 FROM {db_prefix}log_comments
750 WHERE comment_type = {string:ver_test}',
751 array(
752 'ver_test' => 'ver_test',
753 )
754 );
755 while ($row = $smcFunc['db_fetch_assoc']($request))
756 {
757 $context['question_answers'][$row['id_comment']] = array(
758 'id' => $row['id_comment'],
759 'question' => $row['question'],
760 'answer' => $row['answer'],
761 );
762 }
763 $smcFunc['db_free_result']($request);
764
765 // Saving?
766 if (isset($_GET['save']))
767 {
768 checkSession();
769
770 // Fix PM settings.
771 $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
772
773 // Hack in guest requiring verification!
774 if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
775 $_POST['posts_require_captcha'] = -1;
776
777 $save_vars = $config_vars;
778 unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
779
780 $save_vars[] = array('text', 'pm_spam_settings');
781
782 // Handle verification questions.
783 $questionInserts = array();
784 $count_questions = 0;
785 foreach ($_POST['question'] as $id => $question)
786 {
787 $question = trim($smcFunc['htmlspecialchars']($question, ENT_COMPAT, $context['character_set']));
788 $answer = trim($smcFunc['strtolower']($smcFunc['htmlspecialchars']($_POST['answer'][$id], ENT_COMPAT, $context['character_set'])));
789
790 // Already existed?
791 if (isset($context['question_answers'][$id]))
792 {
793 $count_questions++;
794 // Changed?
795 if ($context['question_answers'][$id]['question'] != $question || $context['question_answers'][$id]['answer'] != $answer)
796 {
797 if ($question == '' || $answer == '')
798 {
799 $smcFunc['db_query']('', '
800 DELETE FROM {db_prefix}log_comments
801 WHERE comment_type = {string:ver_test}
802 AND id_comment = {int:id}',
803 array(
804 'id' => $id,
805 'ver_test' => 'ver_test',
806 )
807 );
808 $count_questions--;
809 }
810 else
811 $request = $smcFunc['db_query']('', '
812 UPDATE {db_prefix}log_comments
813 SET body = {string:question}, recipient_name = {string:answer}
814 WHERE comment_type = {string:ver_test}
815 AND id_comment = {int:id}',
816 array(
817 'id' => $id,
818 'ver_test' => 'ver_test',
819 'question' => $question,
820 'answer' => $answer,
821 )
822 );
823 }
824 }
825 // It's so shiney and new!
826 elseif ($question != '' && $answer != '')
827 {
828 $questionInserts[] = array(
829 'comment_type' => 'ver_test',
830 'body' => $question,
831 'recipient_name' => $answer,
832 );
833 }
834 }
835
836 // Any questions to insert?
837 if (!empty($questionInserts))
838 {
839 $smcFunc['db_insert']('',
840 '{db_prefix}log_comments',
841 array('comment_type' => 'string', 'body' => 'string-65535', 'recipient_name' => 'string-80'),
842 $questionInserts,
843 array('id_comment')
844 );
845 $count_questions++;
846 }
847
848 if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
849 $_POST['qa_verification_number'] = $count_questions;
850
851 // Now save.
852 saveDBSettings($save_vars);
853
854 cache_put_data('verificationQuestionIds', null, 300);
855
856 redirectexit('action=admin;area=securitysettings;sa=spam');
857 }
858
859 $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
860 $_SESSION['visual_verification_code'] = '';
861 for ($i = 0; $i < 6; $i++)
862 $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
863
864 // Some javascript for CAPTCHA.
865 $context['settings_post_javascript'] = '';
866 if ($context['use_graphic_library'])
867 $context['settings_post_javascript'] .= '
868 function refreshImages()
869 {
870 var imageType = document.getElementById(\'visual_verification_type\').value;
871 document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
872 }';
873
874 // Show the image itself, or text saying we can't.
875 if ($context['use_graphic_library'])
876 $config_vars['vv']['postinput'] = '<br /><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image" /><br />';
877 else
878 $config_vars['vv']['postinput'] = '<br /><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
879
880 // Hack for PM spam settings.
881 list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
882
883 // Hack for guests requiring verification.
884 $modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']);
885 $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
886
887 // Some minor javascript for the guest post setting.
888 if ($modSettings['posts_require_captcha'])
889 $context['settings_post_javascript'] .= '
890 document.getElementById(\'guests_require_captcha\').disabled = true;';
891
892 $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=spam';
893 $context['settings_title'] = $txt['antispam_Settings'];
894
895 prepareDBSettingContext($config_vars);
896 }
897
898 // You'll never guess what this function does...
899 function ModifySignatureSettings($return_config = false)
900 {
901 global $context, $txt, $modSettings, $sig_start, $smcFunc, $helptxt, $scripturl;
902
903 $config_vars = array(
904 // Are signatures even enabled?
905 array('check', 'signature_enable'),
906 '',
907 // Tweaking settings!
908 array('int', 'signature_max_length'),
909 array('int', 'signature_max_lines'),
910 array('int', 'signature_max_font_size'),
911 array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
912 array('int', 'signature_max_smileys'),
913 '',
914 // Image settings.
915 array('int', 'signature_max_images'),
916 array('int', 'signature_max_image_width'),
917 array('int', 'signature_max_image_height'),
918 '',
919 array('bbc', 'signature_bbc'),
920 );
921
922 if ($return_config)
923 return $config_vars;
924
925 // Setup the template.
926 $context['page_title'] = $txt['signature_settings'];
927 $context['sub_template'] = 'show_settings';
928
929 // Disable the max smileys option if we don't allow smileys at all!
930 $context['settings_post_javascript'] = 'document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;';
931
932 // Load all the signature settings.
933 list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
934 $sig_limits = explode(',', $sig_limits);
935 $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
936
937 // Applying to ALL signatures?!!
938 if (isset($_GET['apply']))
939 {
940 // Security!
941 checkSession('get');
942
943 $sig_start = time();
944 // This is horrid - but I suppose some people will want the option to do it.
945 $_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
946 $done = false;
947
948 $request = $smcFunc['db_query']('', '
949 SELECT MAX(id_member)
950 FROM {db_prefix}members',
951 array(
952 )
953 );
954 list ($context['max_member']) = $smcFunc['db_fetch_row']($request);
955 $smcFunc['db_free_result']($request);
956
957 while (!$done)
958 {
959 $changes = array();
960
961 $request = $smcFunc['db_query']('', '
962 SELECT id_member, signature
963 FROM {db_prefix}members
964 WHERE id_member BETWEEN ' . $_GET['step'] . ' AND ' . $_GET['step'] . ' + 49
965 AND id_group != {int:admin_group}
966 AND FIND_IN_SET({int:admin_group}, additional_groups) = 0',
967 array(
968 'admin_group' => 1,
969 )
970 );
971 while ($row = $smcFunc['db_fetch_assoc']($request))
972 {
973 // Apply all the rules we can realistically do.
974 $sig = strtr($row['signature'], array('<br />' => "\n"));
975
976 // Max characters...
977 if (!empty($sig_limits[1]))
978 $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
979 // Max lines...
980 if (!empty($sig_limits[2]))
981 {
982 $count = 0;
983 for ($i = 0; $i < strlen($sig); $i++)
984 {
985 if ($sig[$i] == "\n")
986 {
987 $count++;
988 if ($count >= $sig_limits[2])
989 $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
990 }
991 }
992 }
993
994 if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $sig, $matches) !== false && isset($matches[2]))
995 {
996 foreach ($matches[1] as $ind => $size)
997 {
998 $limit_broke = 0;
999 // Attempt to allow all sizes of abuse, so to speak.
1000 if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
1001 $limit_broke = $sig_limits[7] . 'px';
1002 elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
1003 $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1004 elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
1005 $limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1006 elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
1007 $limit_broke = 'large';
1008
1009 if ($limit_broke)
1010 $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1011 }
1012 }
1013
1014 // Stupid images - this is stupidly, stupidly challenging.
1015 if ((!empty($sig_limits[3]) || !empty($sig_limits[5]) || !empty($sig_limits[6])))
1016 {
1017 $replaces = array();
1018 $img_count = 0;
1019 // Get all BBC tags...
1020 preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br />)*([^<">]+?)(?:<br />)*\[/img\]~i', $sig, $matches);
1021 // ... and all HTML ones.
1022 preg_match_all('~&lt;img\s+src=(?:&quot;)?((?:http://|ftp://|https://|ftps://).+?)(?:&quot;)?(?:\s+alt=(?:&quot;)?(.*?)(?:&quot;)?)?(?:\s?/)?&gt;~i', $sig, $matches2, PREG_PATTERN_ORDER);
1023 // And stick the HTML in the BBC.
1024 if (!empty($matches2))
1025 {
1026 foreach ($matches2[0] as $ind => $dummy)
1027 {
1028 $matches[0][] = $matches2[0][$ind];
1029 $matches[1][] = '';
1030 $matches[2][] = '';
1031 $matches[3][] = '';
1032 $matches[4][] = '';
1033 $matches[5][] = '';
1034 $matches[6][] = '';
1035 $matches[7][] = $matches2[1][$ind];
1036 }
1037 }
1038 // Try to find all the images!
1039 if (!empty($matches))
1040 {
1041 $image_count_holder = array();
1042 foreach ($matches[0] as $key => $image)
1043 {
1044 $width = -1; $height = -1;
1045 $img_count++;
1046 // Too many images?
1047 if (!empty($sig_limits[3]) && $img_count > $sig_limits[3])
1048 {
1049 // If we've already had this before we only want to remove the excess.
1050 if (isset($image_count_holder[$image]))
1051 {
1052 $img_offset = -1;
1053 $rep_img_count = 0;
1054 while ($img_offset !== false)
1055 {
1056 $img_offset = strpos($sig, $image, $img_offset + 1);
1057 $rep_img_count++;
1058 if ($rep_img_count > $image_count_holder[$image])
1059 {
1060 // Only replace the excess.
1061 $sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
1062 // Stop looping.
1063 $img_offset = false;
1064 }
1065 }
1066 }
1067 else
1068 $replaces[$image] = '';
1069
1070 continue;
1071 }
1072
1073 // Does it have predefined restraints? Width first.
1074 if ($matches[6][$key])
1075 $matches[2][$key] = $matches[6][$key];
1076 if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1077 {
1078 $width = $sig_limits[5];
1079 $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1080 }
1081 elseif ($matches[2][$key])
1082 $width = $matches[2][$key];
1083 // ... and height.
1084 if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1085 {
1086 $height = $sig_limits[6];
1087 if ($width != -1)
1088 $width = $width * ($height / $matches[4][$key]);
1089 }
1090 elseif ($matches[4][$key])
1091 $height = $matches[4][$key];
1092
1093 // If the dimensions are still not fixed - we need to check the actual image.
1094 if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
1095 {
1096 $sizes = url_image_size($matches[7][$key]);
1097 if (is_array($sizes))
1098 {
1099 // Too wide?
1100 if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
1101 {
1102 $width = $sig_limits[5];
1103 $sizes[1] = $sizes[1] * ($width / $sizes[0]);
1104 }
1105 // Too high?
1106 if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1107 {
1108 $height = $sig_limits[6];
1109 if ($width == -1)
1110 $width = $sizes[0];
1111 $width = $width * ($height / $sizes[1]);
1112 }
1113 elseif ($width != -1)
1114 $height = $sizes[1];
1115 }
1116 }
1117
1118 // Did we come up with some changes? If so remake the string.
1119 if ($width != -1 || $height != -1)
1120 {
1121 $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
1122 }
1123
1124 // Record that we got one.
1125 $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1126 }
1127 if (!empty($replaces))
1128 $sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1129 }
1130 }
1131 // Try to fix disabled tags.
1132 if (!empty($disabledTags))
1133 {
1134 $sig = preg_replace('~\[(?:' . implode('|', $disabledTags) . ').+?\]~i', '', $sig);
1135 $sig = preg_replace('~\[/(?:' . implode('|', $disabledTags) . ')\]~i', '', $sig);
1136 }
1137
1138 $sig = strtr($sig, array("\n" => '<br />'));
1139 if ($sig != $row['signature'])
1140 $changes[$row['id_member']] = $sig;
1141 }
1142 if ($smcFunc['db_num_rows']($request) == 0)
1143 $done = true;
1144 $smcFunc['db_free_result']($request);
1145
1146 // Do we need to delete what we have?
1147 if (!empty($changes))
1148 {
1149 foreach ($changes as $id => $sig)
1150 $smcFunc['db_query']('', '
1151 UPDATE {db_prefix}members
1152 SET signature = {string:signature}
1153 WHERE id_member = {int:id_member}',
1154 array(
1155 'id_member' => $id,
1156 'signature' => $sig,
1157 )
1158 );
1159 }
1160
1161 $_GET['step'] += 50;
1162 if (!$done)
1163 pauseSignatureApplySettings();
1164 }
1165 }
1166
1167 $context['signature_settings'] = array(
1168 'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
1169 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
1170 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
1171 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
1172 'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
1173 'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
1174 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
1175 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
1176 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
1177 );
1178
1179 // Temporarily make each setting a modSetting!
1180 foreach ($context['signature_settings'] as $key => $value)
1181 $modSettings['signature_' . $key] = $value;
1182
1183 // Make sure we check the right tags!
1184 $modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
1185
1186 // Saving?
1187 if (isset($_GET['save']))
1188 {
1189 checkSession();
1190
1191 // Clean up the tag stuff!
1192 $bbcTags = array();
1193 foreach (parse_bbc(false) as $tag)
1194 $bbcTags[] = $tag['tag'];
1195
1196 if (!isset($_POST['signature_bbc_enabledTags']))
1197 $_POST['signature_bbc_enabledTags'] = array();
1198 elseif (!is_array($_POST['signature_bbc_enabledTags']))
1199 $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1200
1201 $sig_limits = array();
1202 foreach ($context['signature_settings'] as $key => $value)
1203 {
1204 if ($key == 'allow_smileys')
1205 continue;
1206 elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1207 $sig_limits[] = -1;
1208 else
1209 $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1210 }
1211
1212 $_POST['signature_settings'] = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $_POST['signature_bbc_enabledTags']));
1213
1214 // Even though we have practically no settings let's keep the convention going!
1215 $save_vars = array();
1216 $save_vars[] = array('text', 'signature_settings');
1217
1218 saveDBSettings($save_vars);
1219 redirectexit('action=admin;area=featuresettings;sa=sig');
1220 }
1221
1222 $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig';
1223 $context['settings_title'] = $txt['signature_settings'];
1224
1225 $context['settings_message'] = '<p class="centertext">' . sprintf($txt['signature_settings_warning'], $context['session_id'], $context['session_var']) . '</p>';
1226
1227 prepareDBSettingContext($config_vars);
1228 }
1229
1230 // Just pause the signature applying thing.
1231 function pauseSignatureApplySettings()
1232 {
1233 global $context, $txt, $sig_start;
1234
1235 // Try get more time...
1236 @set_time_limit(600);
1237 if (function_exists('apache_reset_timeout'))
1238 @apache_reset_timeout();
1239
1240 // Have we exhausted all the time we allowed?
1241 if (time() - array_sum(explode(' ', $sig_start)) < 3)
1242 return;
1243
1244 $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1245 $context['page_title'] = $txt['not_done_title'];
1246 $context['continue_post_data'] = '';
1247 $context['continue_countdown'] = '2';
1248 $context['sub_template'] = 'not_done';
1249
1250 // Specific stuff to not break this template!
1251 $context[$context['admin_menu_name']]['current_subsection'] = 'sig';
1252
1253 // Get the right percent.
1254 $context['continue_percent'] = round(($_GET['step'] / $context['max_member']) * 100);
1255
1256 // Never more than 100%!
1257 $context['continue_percent'] = min($context['continue_percent'], 100);
1258
1259 obExit();
1260 }
1261
1262 // Show all the custom profile fields available to the user.
1263 function ShowCustomProfiles()
1264 {
1265 global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
1266 global $modSettings, $sourcedir;
1267
1268 $context['page_title'] = $txt['custom_profile_title'];
1269 $context['sub_template'] = 'show_custom_profile';
1270
1271 // What about standard fields they can tweak?
1272 $standard_fields = array('icq', 'msn', 'aim', 'yim', 'location', 'gender', 'website', 'posts', 'warning_status');
1273 // What fields can't you put on the registration page?
1274 $context['fields_no_registration'] = array('posts', 'warning_status');
1275
1276 // Are we saving any standard field changes?
1277 if (isset($_POST['save']))
1278 {
1279 checkSession();
1280
1281 // Do the active ones first.
1282 $disable_fields = array_flip($standard_fields);
1283 if (!empty($_POST['active']))
1284 {
1285 foreach ($_POST['active'] as $value)
1286 if (isset($disable_fields[$value]))
1287 unset($disable_fields[$value]);
1288 }
1289 // What we have left!
1290 $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
1291
1292 // Things we want to show on registration?
1293 $reg_fields = array();
1294 if (!empty($_POST['reg']))
1295 {
1296 foreach ($_POST['reg'] as $value)
1297 if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1298 $reg_fields[] = $value;
1299 }
1300 // What we have left!
1301 $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1302
1303 if (!empty($changes))
1304 updateSettings($changes);
1305 }
1306
1307 require_once($sourcedir . '/Subs-List.php');
1308
1309 $listOptions = array(
1310 'id' => 'standard_profile_fields',
1311 'title' => $txt['standard_profile_title'],
1312 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1313 'get_items' => array(
1314 'function' => 'list_getProfileFields',
1315 'params' => array(
1316 true,
1317 ),
1318 ),
1319 'columns' => array(
1320 'field' => array(
1321 'header' => array(
1322 'value' => $txt['standard_profile_field'],
1323 'style' => 'text-align: left;',
1324 ),
1325 'data' => array(
1326 'db' => 'label',
1327 'style' => 'width: 60%;',
1328 ),
1329 ),
1330 'active' => array(
1331 'header' => array(
1332 'value' => $txt['custom_edit_active'],
1333 ),
1334 'data' => array(
1335 'function' => create_function('$rowData', '
1336 $isChecked = $rowData[\'disabled\'] ? \'\' : \' checked="checked"\';
1337 $onClickHandler = $rowData[\'can_show_register\'] ? sprintf(\'onclick="document.getElementById(\\\'reg_%1$s\\\').disabled = !this.checked;"\', $rowData[\'id\']) : \'\';
1338 return sprintf(\'<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" class="input_check"%2$s%3$s />\', $rowData[\'id\'], $isChecked, $onClickHandler);
1339 '),
1340 'style' => 'width: 20%; text-align: center;',
1341 ),
1342 ),
1343 'show_on_registration' => array(
1344 'header' => array(
1345 'value' => $txt['custom_edit_registration'],
1346 ),
1347 'data' => array(
1348 'function' => create_function('$rowData', '
1349 $isChecked = $rowData[\'on_register\'] && !$rowData[\'disabled\'] ? \' checked="checked"\' : \'\';
1350 $isDisabled = $rowData[\'can_show_register\'] ? \'\' : \' disabled="disabled"\';
1351 return sprintf(\'<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" class="input_check"%2$s%3$s />\', $rowData[\'id\'], $isChecked, $isDisabled);
1352 '),
1353 'style' => 'width: 20%; text-align: center;',
1354 ),
1355 ),
1356 ),
1357 'form' => array(
1358 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1359 'name' => 'standardProfileFields',
1360 ),
1361 'additional_rows' => array(
1362 array(
1363 'position' => 'below_table_data',
1364 'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />',
1365 'style' => 'text-align: right;',
1366 ),
1367 ),
1368 );
1369 createList($listOptions);
1370
1371 $listOptions = array(
1372 'id' => 'custom_profile_fields',
1373 'title' => $txt['custom_profile_title'],
1374 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
1375 'default_sort_col' => 'field_name',
1376 'no_items_label' => $txt['custom_profile_none'],
1377 'items_per_page' => 25,
1378 'get_items' => array(
1379 'function' => 'list_getProfileFields',
1380 'params' => array(
1381 false,
1382 ),
1383 ),
1384 'get_count' => array(
1385 'function' => 'list_getProfileFieldSize',
1386 ),
1387 'columns' => array(
1388 'field_name' => array(
1389 'header' => array(
1390 'value' => $txt['custom_profile_fieldname'],
1391 'style' => 'text-align: left;',
1392 ),
1393 'data' => array(
1394 'function' => create_function('$rowData', '
1395 global $scripturl;
1396
1397 return sprintf(\'<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>\', $scripturl, $rowData[\'id_field\'], $rowData[\'field_name\'], $rowData[\'field_desc\']);
1398 '),
1399 'style' => 'width: 62%;',
1400 ),
1401 'sort' => array(
1402 'default' => 'field_name',
1403 'reverse' => 'field_name DESC',
1404 ),
1405 ),
1406 'field_type' => array(
1407 'header' => array(
1408 'value' => $txt['custom_profile_fieldtype'],
1409 'style' => 'text-align: left;',
1410 ),
1411 'data' => array(
1412 'function' => create_function('$rowData', '
1413 global $txt;
1414
1415 $textKey = sprintf(\'custom_profile_type_%1$s\', $rowData[\'field_type\']);
1416 return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
1417 '),
1418 'style' => 'width: 15%;',
1419 ),
1420 'sort' => array(
1421 'default' => 'field_type',
1422 'reverse' => 'field_type DESC',
1423 ),
1424 ),
1425 'active' => array(
1426 'header' => array(
1427 'value' => $txt['custom_profile_active'],
1428 ),
1429 'data' => array(
1430 'function' => create_function('$rowData', '
1431 global $txt;
1432
1433 return $rowData[\'active\'] ? $txt[\'yes\'] : $txt[\'no\'];
1434 '),
1435 'style' => 'width: 8%; text-align: center;',
1436 ),
1437 'sort' => array(
1438 'default' => 'active DESC',
1439 'reverse' => 'active',
1440 ),
1441 ),
1442 'placement' => array(
1443 'header' => array(
1444 'value' => $txt['custom_profile_placement'],
1445 ),
1446 'data' => array(
1447 'function' => create_function('$rowData', '
1448 global $txt;
1449
1450 return $txt[\'custom_profile_placement_\' . (empty($rowData[\'placement\']) ? \'standard\' : ($rowData[\'placement\'] == 1 ? \'withicons\' : \'abovesignature\'))];
1451 '),
1452 'style' => 'width: 8%; text-align: center;',
1453 ),
1454 'sort' => array(
1455 'default' => 'placement DESC',
1456 'reverse' => 'placement',
1457 ),
1458 ),
1459 'show_on_registration' => array(
1460 'header' => array(
1461 'value' => $txt['modify'],
1462 ),
1463 'data' => array(
1464 'sprintf' => array(
1465 'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
1466 'params' => array(
1467 'id_field' => false,
1468 ),
1469 ),
1470 'style' => 'width: 15%; text-align: center;',
1471 ),
1472 ),
1473 ),
1474 'form' => array(
1475 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit',
1476 'name' => 'customProfileFields',
1477 ),
1478 'additional_rows' => array(
1479 array(
1480 'position' => 'below_table_data',
1481 'value' => '<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="button_submit" />',
1482 'style' => 'text-align: right;',
1483 ),
1484 ),
1485 );
1486 createList($listOptions);
1487 }
1488
1489 function list_getProfileFields($start, $items_per_page, $sort, $standardFields)
1490 {
1491 global $txt, $modSettings, $smcFunc;
1492
1493 $list = array();
1494
1495 if ($standardFields)
1496 {
1497 $standard_fields = array('icq', 'msn', 'aim', 'yim', 'location', 'gender', 'website', 'posts', 'warning_status');
1498 $fields_no_registration = array('posts', 'warning_status');
1499 $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1500 $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1501
1502 foreach ($standard_fields as $field)
1503 $list[] = array(
1504 'id' => $field,
1505 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1506 'disabled' => in_array($field, $disabled_fields),
1507 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1508 'can_show_register' => !in_array($field, $fields_no_registration),
1509 );
1510 }
1511 else
1512 {
1513 // Load all the fields.
1514 $request = $smcFunc['db_query']('', '
1515 SELECT id_field, col_name, field_name, field_desc, field_type, active, placement
1516 FROM {db_prefix}custom_fields
1517 ORDER BY {raw:sort}
1518 LIMIT {int:start}, {int:items_per_page}',
1519 array(
1520 'sort' => $sort,
1521 'start' => $start,
1522 'items_per_page' => $items_per_page,
1523 )
1524 );
1525 while ($row = $smcFunc['db_fetch_assoc']($request))
1526 $list[] = $row;
1527 $smcFunc['db_free_result']($request);
1528 }
1529
1530 return $list;
1531 }
1532
1533 function list_getProfileFieldSize()
1534 {
1535 global $smcFunc;
1536
1537 $request = $smcFunc['db_query']('', '
1538 SELECT COUNT(*)
1539 FROM {db_prefix}custom_fields',
1540 array(
1541 )
1542 );
1543
1544 list ($numProfileFields) = $smcFunc['db_fetch_row']($request);
1545 $smcFunc['db_free_result']($request);
1546
1547 return $numProfileFields;
1548 }
1549
1550 // Edit some profile fields?
1551 function EditCustomProfiles()
1552 {
1553 global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
1554
1555 // Sort out the context!
1556 $context['fid'] = isset($_GET['fid']) ? (int) $_GET['fid'] : 0;
1557 $context[$context['admin_menu_name']]['current_subsection'] = 'profile';
1558 $context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
1559 $context['sub_template'] = 'edit_profile_field';
1560
1561 // Load the profile language for section names.
1562 loadLanguage('Profile');
1563
1564 if ($context['fid'])
1565 {
1566 $request = $smcFunc['db_query']('', '
1567 SELECT
1568 id_field, col_name, field_name, field_desc, field_type, field_length, field_options,
1569 show_reg, show_display, show_profile, private, active, default_value, can_search,
1570 bbc, mask, enclose, placement
1571 FROM {db_prefix}custom_fields
1572 WHERE id_field = {int:current_field}',
1573 array(
1574 'current_field' => $context['fid'],
1575 )
1576 );
1577 $context['field'] = array();
1578 while ($row = $smcFunc['db_fetch_assoc']($request))
1579 {
1580 if ($row['field_type'] == 'textarea')
1581 @list ($rows, $cols) = @explode(',', $row['default_value']);
1582 else
1583 {
1584 $rows = 3;
1585 $cols = 30;
1586 }
1587
1588 $context['field'] = array(
1589 'name' => $row['field_name'],
1590 'desc' => $row['field_desc'],
1591 'colname' => $row['col_name'],
1592 'profile_area' => $row['show_profile'],
1593 'reg' => $row['show_reg'],
1594 'display' => $row['show_display'],
1595 'type' => $row['field_type'],
1596 'max_length' => $row['field_length'],
1597 'rows' => $rows,
1598 'cols' => $cols,
1599 'bbc' => $row['bbc'] ? true : false,
1600 'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false,
1601 'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '',
1602 'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : array('', '', ''),
1603 'active' => $row['active'],
1604 'private' => $row['private'],
1605 'can_search' => $row['can_search'],
1606 'mask' => $row['mask'],
1607 'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '',
1608 'enclose' => $row['enclose'],
1609 'placement' => $row['placement'],
1610 );
1611 }
1612 $smcFunc['db_free_result']($request);
1613 }
1614
1615 // Setup the default values as needed.
1616 if (empty($context['field']))
1617 $context['field'] = array(
1618 'name' => '',
1619 'colname' => '???',
1620 'desc' => '',
1621 'profile_area' => 'forumprofile',
1622 'reg' => false,
1623 'display' => false,
1624 'type' => 'text',
1625 'max_length' => 255,
1626 'rows' => 4,
1627 'cols' => 30,
1628 'bbc' => false,
1629 'default_check' => false,
1630 'default_select' => '',
1631 'options' => array('', '', ''),
1632 'active' => true,
1633 'private' => false,
1634 'can_search' => false,
1635 'mask' => 'nohtml',
1636 'regex' => '',
1637 'enclose' => '',
1638 'placement' => 0,
1639 );
1640
1641 // Are we saving?
1642 if (isset($_POST['save']))
1643 {
1644 checkSession();
1645
1646 // Everyone needs a name - even the (bracket) unknown...
1647 if (trim($_POST['field_name']) == '')
1648 fatal_lang_error('custom_option_need_name');
1649 $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1650 $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
1651
1652 // Checkboxes...
1653 $show_reg = isset($_POST['reg']) ? (int) $_POST['reg'] : 0;
1654 $show_display = isset($_POST['display']) ? 1 : 0;
1655 $bbc = isset($_POST['bbc']) ? 1 : 0;
1656 $show_profile = $_POST['profile_area'];
1657 $active = isset($_POST['active']) ? 1 : 0;
1658 $private = isset($_POST['private']) ? (int) $_POST['private'] : 0;
1659 $can_search = isset($_POST['can_search']) ? 1 : 0;
1660
1661 // Some masking stuff...
1662 $mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1663 if ($mask == 'regex' && isset($_POST['regex']))
1664 $mask .= $_POST['regex'];
1665
1666 $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1667 $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
1668 $placement = isset($_POST['placement']) ? (int) $_POST['placement'] : 0;
1669
1670 // Select options?
1671 $field_options = '';
1672 $newOptions = array();
1673 $default = isset($_POST['default_check']) && $_POST['field_type'] == 'check' ? 1 : '';
1674 if (!empty($_POST['select_option']) && ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio'))
1675 {
1676 foreach ($_POST['select_option'] as $k => $v)
1677 {
1678 // Clean, clean, clean...
1679 $v = $smcFunc['htmlspecialchars']($v);
1680 $v = strtr($v, array(',' => ''));
1681
1682 // Nada, zip, etc...
1683 if (trim($v) == '')
1684 continue;
1685
1686 // Otherwise, save it boy.
1687 $field_options .= $v . ',';
1688 // This is just for working out what happened with old options...
1689 $newOptions[$k] = $v;
1690
1691 // Is it default?
1692 if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1693 $default = $v;
1694 }
1695 $field_options = substr($field_options, 0, -1);
1696 }
1697
1698 // Text area has default has dimensions
1699 if ($_POST['field_type'] == 'textarea')
1700 $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1701
1702 // Come up with the unique name?
1703 if (empty($context['fid']))
1704 {
1705 $colname = $smcFunc['substr'](strtr($_POST['field_name'], array(' ' => '')), 0, 6);
1706 preg_match('~([\w\d_-]+)~', $colname, $matches);
1707
1708 // If there is nothing to the name, then let's start out own - for foreign languages etc.
1709 if (isset($matches[1]))
1710 $colname = $initial_colname = 'cust_' . strtolower($matches[1]);
1711 else
1712 $colname = $initial_colname = 'cust_' . mt_rand(1, 999);
1713
1714 // Make sure this is unique.
1715 // !!! This may not be the most efficient way to do this.
1716 $unique = false;
1717 for ($i = 0; !$unique && $i < 9; $i ++)
1718 {
1719 $request = $smcFunc['db_query']('', '
1720 SELECT id_field
1721 FROM {db_prefix}custom_fields
1722 WHERE col_name = {string:current_column}',
1723 array(
1724 'current_column' => $colname,
1725 )
1726 );
1727 if ($smcFunc['db_num_rows']($request) == 0)
1728 $unique = true;
1729 else
1730 $colname = $initial_colname . $i;
1731 $smcFunc['db_free_result']($request);
1732 }
1733
1734 // Still not a unique colum name? Leave it up to the user, then.
1735 if (!$unique)
1736 fatal_lang_error('custom_option_not_unique');
1737 }
1738 // Work out what to do with the user data otherwise...
1739 else
1740 {
1741 // Anything going to check or select is pointless keeping - as is anything coming from check!
1742 if (($_POST['field_type'] == 'check' && $context['field']['type'] != 'check')
1743 || (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
1744 || ($context['field']['type'] == 'check' && $_POST['field_type'] != 'check'))
1745 {
1746 $smcFunc['db_query']('', '
1747 DELETE FROM {db_prefix}themes
1748 WHERE variable = {string:current_column}
1749 AND id_member > {int:no_member}',
1750 array(
1751 'no_member' => 0,
1752 'current_column' => $context['field']['colname'],
1753 )
1754 );
1755 }
1756 // Otherwise - if the select is edited may need to adjust!
1757 elseif ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio')
1758 {
1759 $optionChanges = array();
1760 $takenKeys = array();
1761 // Work out what's changed!
1762 foreach ($context['field']['options'] as $k => $option)
1763 {
1764 if (trim($option) == '')
1765 continue;
1766
1767 // Still exists?
1768 if (in_array($option, $newOptions))
1769 {
1770 $takenKeys[] = $k;
1771 continue;
1772 }
1773 }
1774
1775 // Finally - have we renamed it - or is it really gone?
1776 foreach ($optionChanges as $k => $option)
1777 {
1778 // Just been renamed?
1779 if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1780 $smcFunc['db_query']('', '
1781 UPDATE {db_prefix}themes
1782 SET value = {string:new_value}
1783 WHERE variable = {string:current_column}
1784 AND value = {string:old_value}
1785 AND id_member > {int:no_member}',
1786 array(
1787 'no_member' => 0,
1788 'new_value' => $newOptions[$k],
1789 'current_column' => $context['field']['colname'],
1790 'old_value' => $option,
1791 )
1792 );
1793 }
1794 }
1795 //!!! Maybe we should adjust based on new text length limits?
1796 }
1797
1798 // Do the insertion/updates.
1799 if ($context['fid'])
1800 {
1801 $smcFunc['db_query']('', '
1802 UPDATE {db_prefix}custom_fields
1803 SET
1804 field_name = {string:field_name}, field_desc = {string:field_desc},
1805 field_type = {string:field_type}, field_length = {int:field_length},
1806 field_options = {string:field_options}, show_reg = {int:show_reg},
1807 show_display = {int:show_display}, show_profile = {string:show_profile},
1808 private = {int:private}, active = {int:active}, default_value = {string:default_value},
1809 can_search = {int:can_search}, bbc = {int:bbc}, mask = {string:mask},
1810 enclose = {string:enclose}, placement = {int:placement}
1811 WHERE id_field = {int:current_field}',
1812 array(
1813 'field_length' => $field_length,
1814 'show_reg' => $show_reg,
1815 'show_display' => $show_display,
1816 'private' => $private,
1817 'active' => $active,
1818 'can_search' => $can_search,
1819 'bbc' => $bbc,
1820 'current_field' => $context['fid'],
1821 'field_name' => $_POST['field_name'],
1822 'field_desc' => $_POST['field_desc'],
1823 'field_type' => $_POST['field_type'],
1824 'field_options' => $field_options,
1825 'show_profile' => $show_profile,
1826 'default_value' => $default,
1827 'mask' => $mask,
1828 'enclose' => $enclose,
1829 'placement' => $placement,
1830 )
1831 );
1832
1833 // Just clean up any old selects - these are a pain!
1834 if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1835 $smcFunc['db_query']('', '
1836 DELETE FROM {db_prefix}themes
1837 WHERE variable = {string:current_column}
1838 AND value NOT IN ({array_string:new_option_values})
1839 AND id_member > {int:no_member}',
1840 array(
1841 'no_member' => 0,
1842 'new_option_values' => $newOptions,
1843 'current_column' => $context['field']['colname'],
1844 )
1845 );
1846 }
1847 else
1848 {
1849 $smcFunc['db_insert']('',
1850 '{db_prefix}custom_fields',
1851 array(
1852 'col_name' => 'string', 'field_name' => 'string', 'field_desc' => 'string',
1853 'field_type' => 'string', 'field_length' => 'string', 'field_options' => 'string',
1854 'show_reg' => 'int', 'show_display' => 'int', 'show_profile' => 'string',
1855 'private' => 'int', 'active' => 'int', 'default_value' => 'string', 'can_search' => 'int',
1856 'bbc' => 'int', 'mask' => 'string', 'enclose' => 'string', 'placement' => 'int',
1857 ),
1858 array(
1859 $colname, $_POST['field_name'], $_POST['field_desc'],
1860 $_POST['field_type'], $field_length, $field_options,
1861 $show_reg, $show_display, $show_profile,
1862 $private, $active, $default, $can_search,
1863 $bbc, $mask, $enclose, $placement,
1864 ),
1865 array('id_field')
1866 );
1867 }
1868
1869 // As there's currently no option to priorize certain fields over others, let's order them alphabetically.
1870 $smcFunc['db_query']('alter_table_boards', '
1871 ALTER TABLE {db_prefix}custom_fields
1872 ORDER BY field_name',
1873 array(
1874 'db_error_skip' => true,
1875 )
1876 );
1877 }
1878 // Deleting?
1879 elseif (isset($_POST['delete']) && $context['field']['colname'])
1880 {
1881 checkSession();
1882
1883 // Delete the user data first.
1884 $smcFunc['db_query']('', '
1885 DELETE FROM {db_prefix}themes
1886 WHERE variable = {string:current_column}
1887 AND id_member > {int:no_member}',
1888 array(
1889 'no_member' => 0,
1890 'current_column' => $context['field']['colname'],
1891 )
1892 );
1893 // Finally - the field itself is gone!
1894 $smcFunc['db_query']('', '
1895 DELETE FROM {db_prefix}custom_fields
1896 WHERE id_field = {int:current_field}',
1897 array(
1898 'current_field' => $context['fid'],
1899 )
1900 );
1901 }
1902
1903 // Rebuild display cache etc.
1904 if (isset($_POST['delete']) || isset($_POST['save']))
1905 {
1906 checkSession();
1907
1908 $request = $smcFunc['db_query']('', '
1909 SELECT col_name, field_name, field_type, bbc, enclose, placement
1910 FROM {db_prefix}custom_fields
1911 WHERE show_display = {int:is_displayed}
1912 AND active = {int:active}
1913 AND private != {int:not_owner_only}
1914 AND private != {int:not_admin_only}',
1915 array(
1916 'is_displayed' => 1,
1917 'active' => 1,
1918 'not_owner_only' => 2,
1919 'not_admin_only' => 3,
1920 )
1921 );
1922
1923 $fields = array();
1924 while ($row = $smcFunc['db_fetch_assoc']($request))
1925 {
1926 $fields[] = array(
1927 'colname' => strtr($row['col_name'], array('|' => '', ';' => '')),
1928 'title' => strtr($row['field_name'], array('|' => '', ';' => '')),
1929 'type' => $row['field_type'],
1930 'bbc' => $row['bbc'] ? '1' : '0',
1931 'placement' => !empty($row['placement']) ? $row['placement'] : '0',
1932 'enclose' => !empty($row['enclose']) ? $row['enclose'] : '',
1933 );
1934 }
1935 $smcFunc['db_free_result']($request);
1936
1937 updateSettings(array('displayFields' => serialize($fields)));
1938 redirectexit('action=admin;area=featuresettings;sa=profile');
1939 }
1940 }
1941
1942 function ModifyPruningSettings($return_config = false)
1943 {
1944 global $txt, $scripturl, $sourcedir, $context, $settings, $sc, $modSettings;
1945
1946 // Make sure we understand what's going on.
1947 loadLanguage('ManageSettings');
1948
1949 $context['page_title'] = $txt['pruning_title'];
1950
1951 $config_vars = array(
1952 // Even do the pruning?
1953 // The array indexes are there so we can remove/change them before saving.
1954 'pruningOptions' => array('check', 'pruningOptions'),
1955 '',
1956 // Various logs that could be pruned.
1957 array('int', 'pruneErrorLog', 'postinput' => $txt['days_word']), // Error log.
1958 array('int', 'pruneModLog', 'postinput' => $txt['days_word']), // Moderation log.
1959 array('int', 'pruneBanLog', 'postinput' => $txt['days_word']), // Ban hit log.
1960 array('int', 'pruneReportLog', 'postinput' => $txt['days_word']), // Report to moderator log.
1961 array('int', 'pruneScheduledTaskLog', 'postinput' => $txt['days_word']), // Log of the scheduled tasks and how long they ran.
1962 array('int', 'pruneSpiderHitLog', 'postinput' => $txt['days_word']), // Log of the scheduled tasks and how long they ran.
1963 // If you add any additional logs make sure to add them after this point. Additionally, make sure you add them to the weekly scheduled task.
1964 // Mod Developers: Do NOT use the pruningOptions master variable for this as SMF Core may overwrite your setting in the future!
1965 );
1966
1967 if ($return_config)
1968 return $config_vars;
1969
1970 // We'll need this in a bit.
1971 require_once($sourcedir . '/ManageServer.php');
1972
1973 // Saving?
1974 if (isset($_GET['save']))
1975 {
1976 checkSession();
1977
1978 $savevar = array(
1979 array('text', 'pruningOptions')
1980 );
1981
1982 if (!empty($_POST['pruningOptions']))
1983 {
1984 $vals = array();
1985 foreach ($config_vars as $index => $dummy)
1986 {
1987 if (!is_array($dummy) || $index == 'pruningOptions')
1988 continue;
1989
1990 $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
1991 }
1992 $_POST['pruningOptions'] = implode(',', $vals);
1993 }
1994 else
1995 $_POST['pruningOptions'] = '';
1996
1997 saveDBSettings($savevar);
1998 redirectexit('action=admin;area=logs;sa=pruning');
1999 }
2000
2001 $context['post_url'] = $scripturl . '?action=admin;area=logs;save;sa=pruning';
2002 $context['settings_title'] = $txt['pruning_title'];
2003 $context['sub_template'] = 'show_settings';
2004
2005 // Get the actual values
2006 if (!empty($modSettings['pruningOptions']))
2007 @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2008 else
2009 $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2010
2011 prepareDBSettingContext($config_vars);
2012 }
2013
2014 // If you have a general mod setting to add stick it here.
2015 function ModifyGeneralModSettings($return_config = false)
2016 {
2017 global $txt, $scripturl, $context, $settings, $sc, $modSettings;
2018
2019 $config_vars = array(
2020 // Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
2021 );
2022
2023 // Make it even easier to add new settings.
2024 call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2025
2026 if ($return_config)
2027 return $config_vars;
2028
2029 $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2030 $context['settings_title'] = $txt['mods_cat_modifications_misc'];
2031
2032 // No removing this line you, dirty unwashed mod authors. :p
2033 if (empty($config_vars))
2034 {
2035 $context['settings_save_dont_show'] = true;
2036 $context['settings_message'] = '<div class="centertext">' . $txt['modification_no_misc_settings'] . '</div>';
2037
2038 return prepareDBSettingContext($config_vars);
2039 }
2040
2041 // Saving?
2042 if (isset($_GET['save']))
2043 {
2044 checkSession();
2045
2046 $save_vars = $config_vars;
2047
2048 // This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
2049 saveDBSettings($save_vars);
2050
2051 // This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
2052 redirectexit('action=admin;area=modsettings;sa=general');
2053 }
2054
2055 // This line is to help mod authors do a search/add after if you want to add something here. Keyword: RED INK IS FOR TEACHERS AND THOSE WHO LIKE PAIN!
2056 prepareDBSettingContext($config_vars);
2057 }
2058
2059 ?>