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