2
0

ManageSettings.php 68 KB

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