ManageSettings.php 73 KB

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