ManageSettings.php 71 KB

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