ManageSettings.php 66 KB

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