ManageSettings.php 76 KB

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