ManageSettings.php 67 KB

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