ManageSettings.php 66 KB

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