ManageSettings.php 68 KB

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