ManageSettings.php 69 KB

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