ManageSettings.php 67 KB

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