ManageSettings.php 68 KB

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