ManageSettings.php 68 KB

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