ManageSettings.php 66 KB

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