ManageSettings.php 68 KB

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