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