ManageSettings.php 69 KB

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