ManageSettings.php 70 KB

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