ManageSettings.php 74 KB

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