ManageSettings.php 69 KB

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