ManageSettings.php 73 KB

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