ManageSettings.php 68 KB

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