ManageSettings.php 68 KB

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