ManageSettings.php 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731
  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 Advanced Profile Fields are disabled don't show the setting page
  54. if (!in_array('cp', $context['admin_features']))
  55. unset($subActions['profile']);
  56. // Same for Karma
  57. if (!in_array('k', $context['admin_features']))
  58. unset($subActions['karma']);
  59. loadGeneralSettingParameters($subActions, 'basic');
  60. // Load up all the tabs...
  61. $context[$context['admin_menu_name']]['tab_data'] = array(
  62. 'title' => $txt['modSettings_title'],
  63. 'help' => 'featuresettings',
  64. 'description' => sprintf($txt['modSettings_desc'], $settings['theme_id'], $context['session_id'], $context['session_var']),
  65. 'tabs' => array(
  66. 'basic' => array(
  67. ),
  68. 'layout' => array(
  69. ),
  70. 'karma' => array(
  71. ),
  72. 'sig' => array(
  73. 'description' => $txt['signature_settings_desc'],
  74. ),
  75. 'profile' => array(
  76. 'description' => $txt['custom_profile_desc'],
  77. ),
  78. ),
  79. );
  80. // Call the right function for this sub-action.
  81. $subActions[$_REQUEST['sa']]();
  82. }
  83. /**
  84. * This function passes control through to the relevant security tab.
  85. */
  86. function ModifySecuritySettings()
  87. {
  88. global $context, $txt, $scripturl, $modSettings, $settings;
  89. $context['page_title'] = $txt['admin_security_moderation'];
  90. $subActions = array(
  91. 'general' => 'ModifyGeneralSecuritySettings',
  92. 'spam' => 'ModifySpamSettings',
  93. 'moderation' => 'ModifyModerationSettings',
  94. );
  95. call_integration_hook('integrate_modify_security', array(&$subActions));
  96. // If Warning System is disabled don't show the setting page
  97. if (!in_array('w', $context['admin_features']))
  98. unset($subActions['moderation']);
  99. loadGeneralSettingParameters($subActions, 'general');
  100. // Load up all the tabs...
  101. $context[$context['admin_menu_name']]['tab_data'] = array(
  102. 'title' => $txt['admin_security_moderation'],
  103. 'help' => 'securitysettings',
  104. 'description' => $txt['security_settings_desc'],
  105. 'tabs' => array(
  106. 'general' => array(
  107. ),
  108. 'spam' => array(
  109. 'description' => $txt['antispam_Settings_desc'] ,
  110. ),
  111. 'moderation' => array(
  112. ),
  113. ),
  114. );
  115. // Call the right function for this sub-action.
  116. $subActions[$_REQUEST['sa']]();
  117. }
  118. /**
  119. * This my friend, is for all the mod authors out there.
  120. */
  121. function ModifyModSettings()
  122. {
  123. global $context, $txt, $scripturl, $modSettings, $settings;
  124. $context['page_title'] = $txt['admin_modifications'];
  125. $subActions = array(
  126. 'general' => 'ModifyGeneralModSettings',
  127. 'hooks' => 'list_integration_hooks',
  128. // Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
  129. );
  130. // Make it easier for mods to add new areas.
  131. call_integration_hook('integrate_modify_modifications', array(&$subActions));
  132. loadGeneralSettingParameters($subActions, 'general');
  133. // Load up all the tabs...
  134. $context[$context['admin_menu_name']]['tab_data'] = array(
  135. 'title' => $txt['admin_modifications'],
  136. 'help' => 'modsettings',
  137. 'description' => $txt['modification_settings_desc'],
  138. 'tabs' => array(
  139. 'general' => array(
  140. ),
  141. 'hooks' => array(
  142. ),
  143. ),
  144. );
  145. // Call the right function for this sub-action.
  146. $subActions[$_REQUEST['sa']]();
  147. }
  148. /**
  149. * This is an overall control panel enabling/disabling lots of SMF's key feature components.
  150. *
  151. * @param $return_config
  152. */
  153. function ModifyCoreFeatures($return_config = false)
  154. {
  155. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  156. /* This is an array of all the features that can be enabled/disabled - each option can have the following:
  157. title - Text title of this item (If standard string does not exist).
  158. desc - Description of this feature (If standard string does not exist).
  159. 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.
  160. setting_callback- Function that returns an array of settings to save - takes one parameter which is value for this feature.
  161. save_callback - Function called on save, takes state as parameter.
  162. */
  163. $core_features = array(
  164. // cd = calendar.
  165. 'cd' => array(
  166. 'url' => 'action=admin;area=managecalendar',
  167. 'settings' => array(
  168. 'cal_enabled' => 1,
  169. ),
  170. ),
  171. // cp = custom profile fields.
  172. 'cp' => array(
  173. 'url' => 'action=admin;area=featuresettings;sa=profile',
  174. 'save_callback' => create_function('$value', '
  175. global $smcFunc;
  176. if (!$value)
  177. {
  178. $smcFunc[\'db_query\'](\'\', \'
  179. UPDATE {db_prefix}custom_fields
  180. SET active = 0\');
  181. }
  182. '),
  183. 'setting_callback' => create_function('$value', '
  184. if (!$value)
  185. return array(
  186. \'disabled_profile_fields\' => \'\',
  187. \'registration_fields\' => \'\',
  188. \'displayFields\' => \'\',
  189. );
  190. else
  191. return array();
  192. '),
  193. ),
  194. // dr = drafts
  195. 'dr' => array(
  196. 'url' => 'action=admin;area=managedrafts',
  197. 'settings' => array(
  198. 'drafts_enabled' => 1,
  199. 'drafts_post_enabled' => 2,
  200. 'drafts_pm_enabled' => 2,
  201. 'drafts_autosave_enabled' => 2,
  202. 'drafts_show_saved_enabled' => 2,
  203. ),
  204. 'setting_callback' => create_function('$value', '
  205. global $smcFunc, $sourcedir;
  206. // Set the correct disabled value for the scheduled task.
  207. $smcFunc[\'db_query\'](\'\', \'
  208. UPDATE {db_prefix}scheduled_tasks
  209. SET disabled = {int:disabled}
  210. WHERE task = {string:task}\',
  211. array(
  212. \'disabled\' => $value ? 0 : 1,
  213. \'task\' => \'remove_old_drafts\',
  214. )
  215. );
  216. '),
  217. ),
  218. // ih = Integration Hooks Handling.
  219. 'ih' => array(
  220. 'url' => 'action=admin;area=modsettings;sa=hooks',
  221. 'settings' => array(
  222. 'handlinghooks_enabled' => 1,
  223. ),
  224. ),
  225. // k = karma.
  226. 'k' => array(
  227. 'url' => 'action=admin;area=featuresettings;sa=karma',
  228. 'settings' => array(
  229. 'karmaMode' => 2,
  230. ),
  231. ),
  232. // ml = moderation log.
  233. 'ml' => array(
  234. 'url' => 'action=admin;area=logs;sa=modlog',
  235. 'settings' => array(
  236. 'modlog_enabled' => 1,
  237. ),
  238. ),
  239. // pm = post moderation.
  240. 'pm' => array(
  241. 'url' => 'action=admin;area=permissions;sa=postmod',
  242. 'setting_callback' => create_function('$value', '
  243. global $sourcedir;
  244. // Cant use warning post moderation if disabled!
  245. if (!$value)
  246. {
  247. require_once($sourcedir . \'/PostModeration.php\');
  248. approveAllData();
  249. return array(\'warning_moderate\' => 0);
  250. }
  251. else
  252. return array();
  253. '),
  254. ),
  255. // ps = Paid Subscriptions.
  256. 'ps' => array(
  257. 'url' => 'action=admin;area=paidsubscribe',
  258. 'settings' => array(
  259. 'paid_enabled' => 1,
  260. ),
  261. 'setting_callback' => create_function('$value', '
  262. global $smcFunc, $sourcedir;
  263. // Set the correct disabled value for scheduled task.
  264. $smcFunc[\'db_query\'](\'\', \'
  265. UPDATE {db_prefix}scheduled_tasks
  266. SET disabled = {int:disabled}
  267. WHERE task = {string:task}\',
  268. array(
  269. \'disabled\' => $value ? 0 : 1,
  270. \'task\' => \'paid_subscriptions\',
  271. )
  272. );
  273. // Should we calculate next trigger?
  274. if ($value)
  275. {
  276. require_once($sourcedir . \'/ScheduledTasks.php\');
  277. CalculateNextTrigger(\'paid_subscriptions\');
  278. }
  279. '),
  280. ),
  281. // rg = report generator.
  282. 'rg' => array(
  283. 'url' => 'action=admin;area=reports',
  284. ),
  285. // w = warning.
  286. 'w' => array(
  287. 'url' => 'action=admin;area=securitysettings;sa=moderation',
  288. 'setting_callback' => create_function('$value', '
  289. global $modSettings;
  290. list ($modSettings[\'warning_enable\'], $modSettings[\'user_limit\'], $modSettings[\'warning_decrement\']) = explode(\',\', $modSettings[\'warning_settings\']);
  291. $warning_settings = ($value ? 1 : 0) . \',\' . $modSettings[\'user_limit\'] . \',\' . $modSettings[\'warning_decrement\'];
  292. if (!$value)
  293. {
  294. $returnSettings = array(
  295. \'warning_watch\' => 0,
  296. \'warning_moderate\' => 0,
  297. \'warning_mute\' => 0,
  298. );
  299. }
  300. elseif (empty($modSettings[\'warning_enable\']) && $value)
  301. {
  302. $returnSettings = array(
  303. \'warning_watch\' => 10,
  304. \'warning_moderate\' => 35,
  305. \'warning_mute\' => 60,
  306. );
  307. }
  308. else
  309. $returnSettings = array();
  310. $returnSettings[\'warning_settings\'] = $warning_settings;
  311. return $returnSettings;
  312. '),
  313. ),
  314. // Search engines
  315. 'sp' => array(
  316. 'url' => 'action=admin;area=sengines',
  317. 'settings' => array(
  318. 'spider_mode' => 1,
  319. ),
  320. 'setting_callback' => create_function('$value', '
  321. // Turn off the spider group if disabling.
  322. if (!$value)
  323. return array(\'spider_group\' => 0, \'show_spider_online\' => 0);
  324. '),
  325. 'on_save' => create_function('', '
  326. global $sourcedir, $modSettings;
  327. require_once($sourcedir . \'/ManageSearchEngines.php\');
  328. recacheSpiderNames();
  329. '),
  330. ),
  331. );
  332. // Anyone who would like to add a core feature?
  333. call_integration_hook('integrate_core_features', array(&$core_features));
  334. // Are we getting info for the help section.
  335. if ($return_config)
  336. {
  337. $return_data = array();
  338. foreach ($core_features as $id => $data)
  339. $return_data[] = array('switch', isset($data['title']) ? $data['title'] : $txt['core_settings_item_' . $id]);
  340. return $return_data;
  341. }
  342. loadGeneralSettingParameters();
  343. // Are we saving?
  344. if (isset($_POST['save']))
  345. {
  346. checkSession();
  347. if (isset($_GET['xml']))
  348. {
  349. $tokenValidation = validateToken('admin-core', 'post', false);
  350. if (empty($tokenValidation))
  351. return 'token_verify_fail';
  352. }
  353. else
  354. validateToken('admin-core');
  355. $setting_changes = array('admin_features' => array());
  356. // Cycle each feature and change things as required!
  357. foreach ($core_features as $id => $feature)
  358. {
  359. // Enabled?
  360. if (!empty($_POST['feature_' . $id]))
  361. $setting_changes['admin_features'][] = $id;
  362. // Setting values to change?
  363. if (isset($feature['settings']))
  364. {
  365. foreach ($feature['settings'] as $key => $value)
  366. {
  367. if (empty($_POST['feature_' . $id]) || (!empty($_POST['feature_' . $id]) && ($value < 2 || empty($modSettings[$key]))))
  368. $setting_changes[$key] = !empty($_POST['feature_' . $id]) ? $value : !$value;
  369. }
  370. }
  371. // Is there a call back for settings?
  372. if (isset($feature['setting_callback']))
  373. {
  374. $returned_settings = $feature['setting_callback'](!empty($_POST['feature_' . $id]));
  375. if (!empty($returned_settings))
  376. $setting_changes = array_merge($setting_changes, $returned_settings);
  377. }
  378. // Standard save callback?
  379. if (isset($feature['on_save']))
  380. $feature['on_save']();
  381. }
  382. // Make sure this one setting is a string!
  383. $setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']);
  384. // Make any setting changes!
  385. updateSettings($setting_changes);
  386. // This is needed to let menus appear if cache > 2
  387. clean_cache('data');
  388. // Any post save things?
  389. foreach ($core_features as $id => $feature)
  390. {
  391. // Standard save callback?
  392. if (isset($feature['save_callback']))
  393. $feature['save_callback'](!empty($_POST['feature_' . $id]));
  394. }
  395. if (!isset($_REQUEST['xml']))
  396. redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']);
  397. }
  398. // Put them in context.
  399. $context['features'] = array();
  400. foreach ($core_features as $id => $feature)
  401. $context['features'][$id] = array(
  402. 'title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id],
  403. 'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'],
  404. 'enabled' => in_array($id, $context['admin_features']),
  405. 'state' => in_array($id, $context['admin_features']) ? 'on' : 'off',
  406. 'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '',
  407. 'image' => (file_exists($settings['theme_dir'] . '/images/admin/feature_' . $id . '.png') ? $settings['images_url'] : $settings['default_images_url']) . '/admin/feature_' . $id . '.png',
  408. );
  409. // Are they a new user?
  410. $context['is_new_install'] = !isset($modSettings['admin_features']);
  411. $context['force_disable_tabs'] = $context['is_new_install'];
  412. // Don't show them this twice!
  413. if ($context['is_new_install'])
  414. updateSettings(array('admin_features' => ''));
  415. // sub_template is already generic_xml and the token is created somewhere else
  416. if (isset($_REQUEST['xml']))
  417. return;
  418. $context['sub_template'] = 'core_features';
  419. $context['page_title'] = $txt['core_settings_title'];
  420. $context[$context['admin_menu_name']]['tab_data'] = array(
  421. 'title' => $txt['core_settings_title'],
  422. 'help' => '',
  423. 'description' => $txt['core_settings_desc'],
  424. );
  425. // We love our tokens.
  426. createToken('admin-core');
  427. }
  428. /**
  429. * Config array for chaning the basic forum settings
  430. * Accessed from ?action=admin;area=featuresettings;sa=basic;
  431. *
  432. * @param $return_config
  433. */
  434. function ModifyBasicSettings($return_config = false)
  435. {
  436. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  437. // We need to know if personal text is enabled, and if it's in the registration fields option.
  438. // If admins have set it up as an on-registration thing, they can't set a default value (because it'll never be used)
  439. $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
  440. $reg_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
  441. $can_personal_text = !in_array('personal_text', $disabled_fields) && !in_array('personal_text', $reg_fields);
  442. $config_vars = array(
  443. // Big Options... polls, sticky, bbc....
  444. array('select', 'pollMode', array($txt['disable_polls'], $txt['enable_polls'], $txt['polls_as_topics'])),
  445. '',
  446. // Basic stuff, titles, flash, permissions...
  447. array('check', 'allow_guestAccess'),
  448. array('check', 'enable_buddylist'),
  449. array('check', 'enable_unwatch'),
  450. array('check', 'allow_editDisplayName'),
  451. array('check', 'allow_hideOnline'),
  452. array('check', 'titlesEnable'),
  453. array('text', 'default_personal_text', 'subtext' => $txt['default_personal_text_note'], 'disabled' => !$can_personal_text),
  454. '',
  455. // Jquery source
  456. 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;}'),
  457. array('text', 'jquery_custom', 'javascript' => 'disabled', 'size' => 75),
  458. '',
  459. // SEO stuff
  460. array('check', 'queryless_urls', 'subtext' => '<strong>' . $txt['queryless_urls_note'] . '</strong>'),
  461. array('text', 'meta_keywords', 'subtext' => $txt['meta_keywords_note'], 'size' => 50),
  462. '',
  463. // Number formatting, timezones.
  464. array('text', 'time_format'),
  465. array('float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours']),
  466. 'default_timezone' => array('select', 'default_timezone', array()),
  467. '',
  468. // Who's online?
  469. array('check', 'who_enabled'),
  470. array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
  471. '',
  472. // Statistics.
  473. array('check', 'trackStats'),
  474. array('check', 'hitStats'),
  475. '',
  476. // Option-ish things... miscellaneous sorta.
  477. array('check', 'allow_disableAnnounce'),
  478. array('check', 'disallow_sendBody'),
  479. );
  480. // Get all the time zones.
  481. if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set'))
  482. {
  483. $all_zones = timezone_identifiers_list();
  484. // Make sure we set the value to the same as the printed value.
  485. foreach ($all_zones as $zone)
  486. $config_vars['default_timezone'][2][$zone] = $zone;
  487. }
  488. else
  489. unset($config_vars['default_timezone']);
  490. call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
  491. if ($return_config)
  492. return $config_vars;
  493. // Saving?
  494. if (isset($_GET['save']))
  495. {
  496. checkSession();
  497. // Prevent absurd boundaries here - make it a day tops.
  498. if (isset($_POST['lastActive']))
  499. $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
  500. call_integration_hook('integrate_save_basic_settings');
  501. saveDBSettings($config_vars);
  502. writeLog();
  503. redirectexit('action=admin;area=featuresettings;sa=basic');
  504. }
  505. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic';
  506. $context['settings_title'] = $txt['mods_cat_features'];
  507. prepareDBSettingContext($config_vars);
  508. }
  509. /**
  510. * Settings really associated with general security aspects.
  511. *
  512. * @param $return_config
  513. */
  514. function ModifyGeneralSecuritySettings($return_config = false)
  515. {
  516. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  517. $config_vars = array(
  518. array('check', 'guest_hideContacts'),
  519. array('check', 'make_email_viewable'),
  520. '',
  521. array('int', 'failed_login_threshold'),
  522. array('int', 'loginHistoryDays'),
  523. '',
  524. array('check', 'enableErrorLogging'),
  525. array('check', 'enableErrorQueryLogging'),
  526. '',
  527. array('check', 'securityDisable'),
  528. array('check', 'securityDisable_moderate'),
  529. '',
  530. // Reactive on email, and approve on delete
  531. array('check', 'send_validation_onChange'),
  532. array('check', 'approveAccountDeletion'),
  533. '',
  534. // Password strength.
  535. array('select', 'password_strength', array($txt['setting_password_strength_low'], $txt['setting_password_strength_medium'], $txt['setting_password_strength_high'])),
  536. array('check', 'enable_password_conversion'),
  537. '',
  538. // Reporting of personal messages?
  539. array('check', 'enableReportPM'),
  540. '',
  541. array('select', 'frame_security', array('SAMEORIGIN' => $txt['setting_frame_security_SAMEORIGIN'], 'DENY' => $txt['setting_frame_security_DENY'], 'DISABLE' => $txt['setting_frame_security_DISABLE'])),
  542. );
  543. call_integration_hook('integrate_general_security_settings', array(&$config_vars));
  544. if ($return_config)
  545. return $config_vars;
  546. // Saving?
  547. if (isset($_GET['save']))
  548. {
  549. checkSession();
  550. saveDBSettings($config_vars);
  551. call_integration_hook('integrate_save_general_security_settings');
  552. writeLog();
  553. redirectexit('action=admin;area=securitysettings;sa=general');
  554. }
  555. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=general';
  556. $context['settings_title'] = $txt['mods_cat_security_general'];
  557. prepareDBSettingContext($config_vars);
  558. }
  559. /**
  560. * Allows modifying the global layout settings in the forum
  561. * Accessed through ?action=admin;area=featuresettings;sa=layout;
  562. *
  563. * @param $return_config
  564. */
  565. function ModifyLayoutSettings($return_config = false)
  566. {
  567. global $txt, $scripturl, $context, $settings, $sc;
  568. $config_vars = array(
  569. // Pagination stuff.
  570. array('check', 'compactTopicPagesEnable'),
  571. 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>'),
  572. array('int', 'defaultMaxMembers'),
  573. '',
  574. // Stuff that just is everywhere - today, search, online, etc.
  575. array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'])),
  576. array('check', 'topbottomEnable'),
  577. array('check', 'onlineEnable'),
  578. array('check', 'enableVBStyleLogin'),
  579. '',
  580. // Automagic image resizing.
  581. array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
  582. array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
  583. '',
  584. // This is like debugging sorta.
  585. array('check', 'timeLoadPageEnable'),
  586. );
  587. call_integration_hook('integrate_layout_settings', array(&$config_vars));
  588. if ($return_config)
  589. return $config_vars;
  590. // Saving?
  591. if (isset($_GET['save']))
  592. {
  593. checkSession();
  594. call_integration_hook('integrate_save_layout_settings');
  595. saveDBSettings($config_vars);
  596. writeLog();
  597. redirectexit('action=admin;area=featuresettings;sa=layout');
  598. }
  599. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout';
  600. $context['settings_title'] = $txt['mods_cat_layout'];
  601. prepareDBSettingContext($config_vars);
  602. }
  603. /**
  604. * Config array for chaning the karma settings
  605. * Accessed from ?action=admin;area=featuresettings;sa=karma;
  606. *
  607. * @param $return_config
  608. */
  609. function ModifyKarmaSettings($return_config = false)
  610. {
  611. global $txt, $scripturl, $context, $settings, $sc;
  612. $config_vars = array(
  613. // Karma - On or off?
  614. array('select', 'karmaMode', explode('|', $txt['karma_options'])),
  615. '',
  616. // Who can do it.... and who is restricted by time limits?
  617. array('int', 'karmaMinPosts', 6, 'postinput' => strtolower($txt['posts'])),
  618. array('float', 'karmaWaitTime', 6, 'postinput' => $txt['hours']),
  619. array('check', 'karmaTimeRestrictAdmins'),
  620. '',
  621. // What does it look like? [smite]?
  622. array('text', 'karmaLabel'),
  623. array('text', 'karmaApplaudLabel'),
  624. array('text', 'karmaSmiteLabel'),
  625. );
  626. call_integration_hook('integrate_karma_settings', array(&$config_vars));
  627. if ($return_config)
  628. return $config_vars;
  629. // Saving?
  630. if (isset($_GET['save']))
  631. {
  632. checkSession();
  633. call_integration_hook('integrate_save_karma_settings');
  634. saveDBSettings($config_vars);
  635. redirectexit('action=admin;area=featuresettings;sa=karma');
  636. }
  637. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=karma';
  638. $context['settings_title'] = $txt['karma'];
  639. prepareDBSettingContext($config_vars);
  640. }
  641. /**
  642. * Moderation type settings - although there are fewer than we have you believe ;)
  643. *
  644. * @param bool $return_config = false
  645. */
  646. function ModifyModerationSettings($return_config = false)
  647. {
  648. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  649. $config_vars = array(
  650. // Warning system?
  651. array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'], 'help' => 'warning_enable'),
  652. 'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note']),
  653. array('int', 'warning_mute', 'subtext' => $txt['setting_warning_mute_note']),
  654. 'rem1' => array('int', 'user_limit', 'subtext' => $txt['setting_user_limit_note']),
  655. 'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note']),
  656. 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'])),
  657. );
  658. call_integration_hook('integrate_moderation_settings', array(&$config_vars));
  659. if ($return_config)
  660. return $config_vars;
  661. // Cannot use moderation if post moderation is not enabled.
  662. if (!$modSettings['postmod_active'])
  663. unset($config_vars['moderate']);
  664. // Saving?
  665. if (isset($_GET['save']))
  666. {
  667. checkSession();
  668. // Make sure these don't have an effect.
  669. if (substr($modSettings['warning_settings'], 0, 1) != 1)
  670. {
  671. $_POST['warning_watch'] = 0;
  672. $_POST['warning_moderate'] = 0;
  673. $_POST['warning_mute'] = 0;
  674. }
  675. else
  676. {
  677. $_POST['warning_watch'] = min($_POST['warning_watch'], 100);
  678. $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
  679. $_POST['warning_mute'] = min($_POST['warning_mute'], 100);
  680. }
  681. // Fix the warning setting array!
  682. $_POST['warning_settings'] = '1,' . min(100, (int) $_POST['user_limit']) . ',' . min(100, (int) $_POST['warning_decrement']);
  683. $save_vars = $config_vars;
  684. $save_vars[] = array('text', 'warning_settings');
  685. unset($save_vars['rem1'], $save_vars['rem2']);
  686. call_integration_hook('integrate_save_karma_settings', array(&$save_vars));
  687. saveDBSettings($save_vars);
  688. redirectexit('action=admin;area=securitysettings;sa=moderation');
  689. }
  690. // We actually store lots of these together - for efficiency.
  691. list ($modSettings['warning_enable'], $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
  692. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=moderation';
  693. $context['settings_title'] = $txt['moderation_settings'];
  694. prepareDBSettingContext($config_vars);
  695. }
  696. /**
  697. * Let's try keep the spam to a minimum ah Thantos?
  698. * @param bool $return_config = false
  699. */
  700. function ModifySpamSettings($return_config = false)
  701. {
  702. global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc, $language;
  703. // Generate a sample registration image.
  704. $context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
  705. $context['verification_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand());
  706. $config_vars = array(
  707. array('check', 'reg_verification'),
  708. array('check', 'search_enable_captcha'),
  709. // This, my friend, is a cheat :p
  710. 'guest_verify' => array('check', 'guests_require_captcha', 'subtext' => $txt['setting_guests_require_captcha_desc']),
  711. 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;}'),
  712. '',
  713. // PM Settings
  714. 'pm1' => array('int', 'max_pm_recipients', 'subtext' => $txt['max_pm_recipients_note']),
  715. 'pm2' => array('int', 'pm_posts_verification', 'subtext' => $txt['pm_posts_verification_note']),
  716. 'pm3' => array('int', 'pm_posts_per_hour', 'subtext' => $txt['pm_posts_per_hour_note']),
  717. // Visual verification.
  718. array('title', 'configure_verification_means'),
  719. array('desc', 'configure_verification_means_desc'),
  720. '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();' : ''),
  721. // Clever Thomas, who is looking sheepy now? Not I, the mighty sword swinger did say.
  722. array('title', 'setup_verification_questions'),
  723. array('desc', 'setup_verification_questions_desc'),
  724. array('int', 'qa_verification_number', 'subtext' => $txt['setting_qa_verification_number_desc']),
  725. array('callback', 'question_answer_list'),
  726. );
  727. call_integration_hook('integrate_spam_settings', array(&$config_vars));
  728. if ($return_config)
  729. return $config_vars;
  730. // Firstly, figure out what languages we're dealing with, and do a little processing for the form's benefit.
  731. getLanguages();
  732. $context['qa_languages'] = array();
  733. foreach ($context['languages'] as $lang_id => $lang)
  734. {
  735. $lang_id = strtr($lang_id, array('-utf8' => ''));
  736. $lang['name'] = strtr($lang['name'], array('-utf8' => ''));
  737. $context['qa_languages'][$lang_id] = $lang;
  738. }
  739. // Secondly, load any questions we currently have.
  740. $context['question_answers'] = array();
  741. $request = $smcFunc['db_query']('', '
  742. SELECT id_question, lngfile, question, answers
  743. FROM {db_prefix}qanda'
  744. );
  745. while ($row = $smcFunc['db_fetch_assoc']($request))
  746. {
  747. $lang = strtr($row['lngfile'], array('-utf8' => ''));
  748. $context['question_answers'][$row['id_question']] = array(
  749. 'lngfile' => $lang,
  750. 'question' => $row['question'],
  751. 'answers' => unserialize($row['answers']),
  752. );
  753. $context['qa_by_lang'][$lang][] = $row['id_question'];
  754. }
  755. // Thirdly, push some JavaScript for the form to make it work.
  756. addInlineJavascript('
  757. var nextrow = ' . (!empty($context['question_answers']) ? max(array_keys($context['question_answers'])) + 1 : 1) . ';
  758. $(".qa_link a").click(function() {
  759. var id = $(this).parent().attr("id").substring(6);
  760. $("#qa_fs_" + id).show();
  761. $(this).parent().hide();
  762. });
  763. $(".qa_fieldset legend a").click(function() {
  764. var id = $(this).closest("fieldset").attr("id").substring(6);
  765. $("#qa_dt_" + id).show();
  766. $(this).closest("fieldset").hide();
  767. });
  768. $(".qa_add_question a").click(function() {
  769. var id = $(this).closest("fieldset").attr("id").substring(6);
  770. $(\'<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());
  771. nextrow++;
  772. });
  773. function addAnswer(obj)
  774. {
  775. var attr = $(obj).closest("dd").find(".verification_answer:last").attr("name");
  776. $(\'<input type="text" name="\' + attr + \'" value="" size="50" class="input_text verification_answer" />\').insertBefore($(obj).closest("div"));
  777. return false;
  778. }
  779. $("#qa_dt_' . $language . ' a").click();', true);
  780. // Saving?
  781. if (isset($_GET['save']))
  782. {
  783. checkSession();
  784. // Fix PM settings.
  785. $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
  786. // Hack in guest requiring verification!
  787. if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
  788. $_POST['posts_require_captcha'] = -1;
  789. $save_vars = $config_vars;
  790. unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
  791. $save_vars[] = array('text', 'pm_spam_settings');
  792. // Handle verification questions.
  793. $changes = array(
  794. 'insert' => array(),
  795. 'replace' => array(),
  796. 'delete' => array(),
  797. );
  798. $qs_per_lang = array();
  799. foreach ($context['qa_languages'] as $lang_id => $dummy)
  800. {
  801. // If we had some questions for this language before, but don't now, delete everything from that language.
  802. if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
  803. $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
  804. // Now step through and see if any existing questions no longer exist.
  805. if (!empty($context['qa_by_lang'][$lang_id]))
  806. foreach ($context['qa_by_lang'][$lang_id] as $q_id)
  807. if (empty($_POST['question'][$lang_id][$q_id]))
  808. $changes['delete'][] = $q_id;
  809. // Now let's see if there are new questions or ones that need updating.
  810. foreach ($_POST['question'][$lang_id] as $q_id => $question)
  811. {
  812. // Ignore junky ids.
  813. $q_id = (int) $q_id;
  814. if ($q_id <= 0)
  815. continue;
  816. // Check the question isn't empty (because they want to delete it?)
  817. if (empty($question) || trim($question) == '')
  818. {
  819. if (isset($context['question_answers'][$q_id]))
  820. $changes['delete'][] = $q_id;
  821. continue;
  822. }
  823. $question = $smcFunc['htmlspecialchars'](trim($question));
  824. // Get the answers. Firstly check there actually might be some.
  825. if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
  826. {
  827. if (isset($context['question_answers'][$q_id]))
  828. $changes['delete'][] = $q_id;
  829. continue;
  830. }
  831. // Now get them and check that they might be viable.
  832. $answers = array();
  833. foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
  834. if (!empty($answer) && trim($answer) !== '')
  835. $answers[] = $smcFunc['htmlspecialchars'](trim($answer));
  836. if (empty($answers))
  837. {
  838. if (isset($context['question_answers'][$q_id]))
  839. $changes['delete'][] = $q_id;
  840. continue;
  841. }
  842. $answers = serialize($answers);
  843. // At this point we know we have a question and some answers. What are we doing with it?
  844. if (!isset($context['question_answers'][$q_id]))
  845. {
  846. // New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
  847. $changes['insert'][] = array($lang_id, $question, $answers);
  848. }
  849. else
  850. {
  851. // It's an existing question. Let's see what's changed, if anything.
  852. if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
  853. $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
  854. }
  855. if (!isset($qs_per_lang[$lang_id]))
  856. $qs_per_lang[$lang_id] = 0;
  857. $qs_per_lang[$lang_id]++;
  858. }
  859. }
  860. // OK, so changes?
  861. if (!empty($changes['delete']))
  862. {
  863. $smcFunc['db_query']('', '
  864. DELETE FROM {db_prefix}qanda
  865. WHERE id_question IN ({array_int:questions})',
  866. array(
  867. 'questions' => $changes['delete'],
  868. )
  869. );
  870. }
  871. if (!empty($changes['replace']))
  872. {
  873. foreach ($changes['replace'] as $q_id => $question)
  874. {
  875. $smcFunc['db_query']('', '
  876. UPDATE {db_prefix}qanda
  877. SET lngfile = {string:lngfile},
  878. question = {string:question},
  879. answers = {string:answers}
  880. WHERE id_question = {int:id_question}',
  881. array(
  882. 'id_question' => $q_id,
  883. 'lngfile' => $question['lngfile'],
  884. 'question' => $question['question'],
  885. 'answers' => $question['answers'],
  886. )
  887. );
  888. }
  889. }
  890. if (!empty($changes['insert']))
  891. {
  892. $smcFunc['db_insert']('insert',
  893. '{db_prefix}qanda',
  894. array('lngfile' => 'string-50', 'question' => 'string-255', 'answers' => 'string-65534'),
  895. $changes['insert'],
  896. array('id_question')
  897. );
  898. }
  899. // Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
  900. $count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
  901. if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
  902. $_POST['qa_verification_number'] = $count_questions;
  903. call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
  904. // Now save.
  905. saveDBSettings($save_vars);
  906. cache_put_data('verificationQuestions', null, 300);
  907. redirectexit('action=admin;area=securitysettings;sa=spam');
  908. }
  909. $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
  910. $_SESSION['visual_verification_code'] = '';
  911. for ($i = 0; $i < 6; $i++)
  912. $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
  913. // Some javascript for CAPTCHA.
  914. $context['settings_post_javascript'] = '';
  915. if ($context['use_graphic_library'])
  916. $context['settings_post_javascript'] .= '
  917. function refreshImages()
  918. {
  919. var imageType = document.getElementById(\'visual_verification_type\').value;
  920. document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
  921. }';
  922. // Show the image itself, or text saying we can't.
  923. if ($context['use_graphic_library'])
  924. $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 />';
  925. else
  926. $config_vars['vv']['postinput'] = '<br /><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
  927. // Hack for PM spam settings.
  928. list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
  929. // Hack for guests requiring verification.
  930. $modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']);
  931. $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
  932. // Some minor javascript for the guest post setting.
  933. if ($modSettings['posts_require_captcha'])
  934. $context['settings_post_javascript'] .= '
  935. document.getElementById(\'guests_require_captcha\').disabled = true;';
  936. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=spam';
  937. $context['settings_title'] = $txt['antispam_Settings'];
  938. prepareDBSettingContext($config_vars);
  939. }
  940. /**
  941. * You'll never guess what this function does...
  942. *
  943. * @param $return_config
  944. */
  945. function ModifySignatureSettings($return_config = false)
  946. {
  947. global $context, $txt, $modSettings, $sig_start, $smcFunc, $helptxt, $scripturl;
  948. $config_vars = array(
  949. // Are signatures even enabled?
  950. array('check', 'signature_enable'),
  951. '',
  952. // Tweaking settings!
  953. array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
  954. array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
  955. array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
  956. array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
  957. array('int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']),
  958. '',
  959. // Image settings.
  960. array('int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']),
  961. array('int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']),
  962. array('int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']),
  963. '',
  964. array('bbc', 'signature_bbc'),
  965. );
  966. call_integration_hook('integrate_signature_settings', array(&$config_vars));
  967. if ($return_config)
  968. return $config_vars;
  969. // Setup the template.
  970. $context['page_title'] = $txt['signature_settings'];
  971. $context['sub_template'] = 'show_settings';
  972. // Disable the max smileys option if we don't allow smileys at all!
  973. $context['settings_post_javascript'] = 'document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;';
  974. // Load all the signature settings.
  975. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  976. $sig_limits = explode(',', $sig_limits);
  977. $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
  978. // Applying to ALL signatures?!!
  979. if (isset($_GET['apply']))
  980. {
  981. // Security!
  982. checkSession('get');
  983. $sig_start = time();
  984. // This is horrid - but I suppose some people will want the option to do it.
  985. $_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
  986. $done = false;
  987. $request = $smcFunc['db_query']('', '
  988. SELECT MAX(id_member)
  989. FROM {db_prefix}members',
  990. array(
  991. )
  992. );
  993. list ($context['max_member']) = $smcFunc['db_fetch_row']($request);
  994. $smcFunc['db_free_result']($request);
  995. while (!$done)
  996. {
  997. $changes = array();
  998. $request = $smcFunc['db_query']('', '
  999. SELECT id_member, signature
  1000. FROM {db_prefix}members
  1001. WHERE id_member BETWEEN ' . $_GET['step'] . ' AND ' . $_GET['step'] . ' + 49
  1002. AND id_group != {int:admin_group}
  1003. AND FIND_IN_SET({int:admin_group}, additional_groups) = 0',
  1004. array(
  1005. 'admin_group' => 1,
  1006. )
  1007. );
  1008. while ($row = $smcFunc['db_fetch_assoc']($request))
  1009. {
  1010. // Apply all the rules we can realistically do.
  1011. $sig = strtr($row['signature'], array('<br />' => "\n"));
  1012. // Max characters...
  1013. if (!empty($sig_limits[1]))
  1014. $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
  1015. // Max lines...
  1016. if (!empty($sig_limits[2]))
  1017. {
  1018. $count = 0;
  1019. for ($i = 0; $i < strlen($sig); $i++)
  1020. {
  1021. if ($sig[$i] == "\n")
  1022. {
  1023. $count++;
  1024. if ($count >= $sig_limits[2])
  1025. $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
  1026. }
  1027. }
  1028. }
  1029. if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $sig, $matches) !== false && isset($matches[2]))
  1030. {
  1031. foreach ($matches[1] as $ind => $size)
  1032. {
  1033. $limit_broke = 0;
  1034. // Attempt to allow all sizes of abuse, so to speak.
  1035. if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
  1036. $limit_broke = $sig_limits[7] . 'px';
  1037. elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
  1038. $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
  1039. elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
  1040. $limit_broke = ((float) $sig_limits[7] / 16) . 'em';
  1041. elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
  1042. $limit_broke = 'large';
  1043. if ($limit_broke)
  1044. $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
  1045. }
  1046. }
  1047. // Stupid images - this is stupidly, stupidly challenging.
  1048. if ((!empty($sig_limits[3]) || !empty($sig_limits[5]) || !empty($sig_limits[6])))
  1049. {
  1050. $replaces = array();
  1051. $img_count = 0;
  1052. // Get all BBC tags...
  1053. preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br />)*([^<">]+?)(?:<br />)*\[/img\]~i', $sig, $matches);
  1054. // ... and all HTML ones.
  1055. 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);
  1056. // And stick the HTML in the BBC.
  1057. if (!empty($matches2))
  1058. {
  1059. foreach ($matches2[0] as $ind => $dummy)
  1060. {
  1061. $matches[0][] = $matches2[0][$ind];
  1062. $matches[1][] = '';
  1063. $matches[2][] = '';
  1064. $matches[3][] = '';
  1065. $matches[4][] = '';
  1066. $matches[5][] = '';
  1067. $matches[6][] = '';
  1068. $matches[7][] = $matches2[1][$ind];
  1069. }
  1070. }
  1071. // Try to find all the images!
  1072. if (!empty($matches))
  1073. {
  1074. $image_count_holder = array();
  1075. foreach ($matches[0] as $key => $image)
  1076. {
  1077. $width = -1; $height = -1;
  1078. $img_count++;
  1079. // Too many images?
  1080. if (!empty($sig_limits[3]) && $img_count > $sig_limits[3])
  1081. {
  1082. // If we've already had this before we only want to remove the excess.
  1083. if (isset($image_count_holder[$image]))
  1084. {
  1085. $img_offset = -1;
  1086. $rep_img_count = 0;
  1087. while ($img_offset !== false)
  1088. {
  1089. $img_offset = strpos($sig, $image, $img_offset + 1);
  1090. $rep_img_count++;
  1091. if ($rep_img_count > $image_count_holder[$image])
  1092. {
  1093. // Only replace the excess.
  1094. $sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
  1095. // Stop looping.
  1096. $img_offset = false;
  1097. }
  1098. }
  1099. }
  1100. else
  1101. $replaces[$image] = '';
  1102. continue;
  1103. }
  1104. // Does it have predefined restraints? Width first.
  1105. if ($matches[6][$key])
  1106. $matches[2][$key] = $matches[6][$key];
  1107. if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
  1108. {
  1109. $width = $sig_limits[5];
  1110. $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
  1111. }
  1112. elseif ($matches[2][$key])
  1113. $width = $matches[2][$key];
  1114. // ... and height.
  1115. if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
  1116. {
  1117. $height = $sig_limits[6];
  1118. if ($width != -1)
  1119. $width = $width * ($height / $matches[4][$key]);
  1120. }
  1121. elseif ($matches[4][$key])
  1122. $height = $matches[4][$key];
  1123. // If the dimensions are still not fixed - we need to check the actual image.
  1124. if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
  1125. {
  1126. $sizes = url_image_size($matches[7][$key]);
  1127. if (is_array($sizes))
  1128. {
  1129. // Too wide?
  1130. if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
  1131. {
  1132. $width = $sig_limits[5];
  1133. $sizes[1] = $sizes[1] * ($width / $sizes[0]);
  1134. }
  1135. // Too high?
  1136. if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
  1137. {
  1138. $height = $sig_limits[6];
  1139. if ($width == -1)
  1140. $width = $sizes[0];
  1141. $width = $width * ($height / $sizes[1]);
  1142. }
  1143. elseif ($width != -1)
  1144. $height = $sizes[1];
  1145. }
  1146. }
  1147. // Did we come up with some changes? If so remake the string.
  1148. if ($width != -1 || $height != -1)
  1149. {
  1150. $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
  1151. }
  1152. // Record that we got one.
  1153. $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
  1154. }
  1155. if (!empty($replaces))
  1156. $sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
  1157. }
  1158. }
  1159. // Try to fix disabled tags.
  1160. if (!empty($disabledTags))
  1161. {
  1162. $sig = preg_replace('~\[(?:' . implode('|', $disabledTags) . ').+?\]~i', '', $sig);
  1163. $sig = preg_replace('~\[/(?:' . implode('|', $disabledTags) . ')\]~i', '', $sig);
  1164. }
  1165. $sig = strtr($sig, array("\n" => '<br />'));
  1166. call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
  1167. if ($sig != $row['signature'])
  1168. $changes[$row['id_member']] = $sig;
  1169. }
  1170. if ($smcFunc['db_num_rows']($request) == 0)
  1171. $done = true;
  1172. $smcFunc['db_free_result']($request);
  1173. // Do we need to delete what we have?
  1174. if (!empty($changes))
  1175. {
  1176. foreach ($changes as $id => $sig)
  1177. $smcFunc['db_query']('', '
  1178. UPDATE {db_prefix}members
  1179. SET signature = {string:signature}
  1180. WHERE id_member = {int:id_member}',
  1181. array(
  1182. 'id_member' => $id,
  1183. 'signature' => $sig,
  1184. )
  1185. );
  1186. }
  1187. $_GET['step'] += 50;
  1188. if (!$done)
  1189. pauseSignatureApplySettings();
  1190. }
  1191. $settings_applied = true;
  1192. }
  1193. $context['signature_settings'] = array(
  1194. 'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
  1195. 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
  1196. 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
  1197. 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
  1198. 'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
  1199. 'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
  1200. 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
  1201. 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
  1202. 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
  1203. );
  1204. // Temporarily make each setting a modSetting!
  1205. foreach ($context['signature_settings'] as $key => $value)
  1206. $modSettings['signature_' . $key] = $value;
  1207. // Make sure we check the right tags!
  1208. $modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
  1209. // Saving?
  1210. if (isset($_GET['save']))
  1211. {
  1212. checkSession();
  1213. // Clean up the tag stuff!
  1214. $bbcTags = array();
  1215. foreach (parse_bbc(false) as $tag)
  1216. $bbcTags[] = $tag['tag'];
  1217. if (!isset($_POST['signature_bbc_enabledTags']))
  1218. $_POST['signature_bbc_enabledTags'] = array();
  1219. elseif (!is_array($_POST['signature_bbc_enabledTags']))
  1220. $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
  1221. $sig_limits = array();
  1222. foreach ($context['signature_settings'] as $key => $value)
  1223. {
  1224. if ($key == 'allow_smileys')
  1225. continue;
  1226. elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
  1227. $sig_limits[] = -1;
  1228. else
  1229. $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
  1230. }
  1231. call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
  1232. $_POST['signature_settings'] = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $_POST['signature_bbc_enabledTags']));
  1233. // Even though we have practically no settings let's keep the convention going!
  1234. $save_vars = array();
  1235. $save_vars[] = array('text', 'signature_settings');
  1236. saveDBSettings($save_vars);
  1237. redirectexit('action=admin;area=featuresettings;sa=sig');
  1238. }
  1239. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig';
  1240. $context['settings_title'] = $txt['signature_settings'];
  1241. $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>';
  1242. prepareDBSettingContext($config_vars);
  1243. }
  1244. /**
  1245. * Just pause the signature applying thing.
  1246. */
  1247. function pauseSignatureApplySettings()
  1248. {
  1249. global $context, $txt, $sig_start;
  1250. // Try get more time...
  1251. @set_time_limit(600);
  1252. if (function_exists('apache_reset_timeout'))
  1253. @apache_reset_timeout();
  1254. // Have we exhausted all the time we allowed?
  1255. if (time() - array_sum(explode(' ', $sig_start)) < 3)
  1256. return;
  1257. $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
  1258. $context['page_title'] = $txt['not_done_title'];
  1259. $context['continue_post_data'] = '';
  1260. $context['continue_countdown'] = '2';
  1261. $context['sub_template'] = 'not_done';
  1262. // Specific stuff to not break this template!
  1263. $context[$context['admin_menu_name']]['current_subsection'] = 'sig';
  1264. // Get the right percent.
  1265. $context['continue_percent'] = round(($_GET['step'] / $context['max_member']) * 100);
  1266. // Never more than 100%!
  1267. $context['continue_percent'] = min($context['continue_percent'], 100);
  1268. obExit();
  1269. }
  1270. /**
  1271. * Show all the custom profile fields available to the user.
  1272. */
  1273. function ShowCustomProfiles()
  1274. {
  1275. global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
  1276. global $modSettings, $sourcedir;
  1277. $context['page_title'] = $txt['custom_profile_title'];
  1278. $context['sub_template'] = 'show_custom_profile';
  1279. // What about standard fields they can tweak?
  1280. $standard_fields = array('icq', 'aim', 'yim', 'skype', 'location', 'gender', 'website', 'personal_text', 'posts', 'warning_status');
  1281. // What fields can't you put on the registration page?
  1282. $context['fields_no_registration'] = array('posts', 'warning_status');
  1283. // Are we saving any standard field changes?
  1284. if (isset($_POST['save']))
  1285. {
  1286. checkSession();
  1287. validateToken('admin-scp');
  1288. // Do the active ones first.
  1289. $disable_fields = array_flip($standard_fields);
  1290. if (!empty($_POST['active']))
  1291. {
  1292. foreach ($_POST['active'] as $value)
  1293. if (isset($disable_fields[$value]))
  1294. unset($disable_fields[$value]);
  1295. }
  1296. // What we have left!
  1297. $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
  1298. // Things we want to show on registration?
  1299. $reg_fields = array();
  1300. if (!empty($_POST['reg']))
  1301. {
  1302. foreach ($_POST['reg'] as $value)
  1303. if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
  1304. $reg_fields[] = $value;
  1305. }
  1306. // What we have left!
  1307. $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
  1308. if (!empty($changes))
  1309. updateSettings($changes);
  1310. }
  1311. createToken('admin-scp');
  1312. require_once($sourcedir . '/Subs-List.php');
  1313. $listOptions = array(
  1314. 'id' => 'standard_profile_fields',
  1315. 'title' => $txt['standard_profile_title'],
  1316. 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1317. 'get_items' => array(
  1318. 'function' => 'list_getProfileFields',
  1319. 'params' => array(
  1320. true,
  1321. ),
  1322. ),
  1323. 'columns' => array(
  1324. 'field' => array(
  1325. 'header' => array(
  1326. 'value' => $txt['standard_profile_field'],
  1327. ),
  1328. 'data' => array(
  1329. 'db' => 'label',
  1330. 'style' => 'width: 60%;',
  1331. ),
  1332. ),
  1333. 'active' => array(
  1334. 'header' => array(
  1335. 'value' => $txt['custom_edit_active'],
  1336. 'class' => 'centercol',
  1337. ),
  1338. 'data' => array(
  1339. 'function' => create_function('$rowData', '
  1340. $isChecked = $rowData[\'disabled\'] ? \'\' : \' checked="checked"\';
  1341. $onClickHandler = $rowData[\'can_show_register\'] ? sprintf(\'onclick="document.getElementById(\\\'reg_%1$s\\\').disabled = !this.checked;"\', $rowData[\'id\']) : \'\';
  1342. 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);
  1343. '),
  1344. 'style' => 'width: 20%;',
  1345. 'class' => 'centercol',
  1346. ),
  1347. ),
  1348. 'show_on_registration' => array(
  1349. 'header' => array(
  1350. 'value' => $txt['custom_edit_registration'],
  1351. 'class' => 'centercol',
  1352. ),
  1353. 'data' => array(
  1354. 'function' => create_function('$rowData', '
  1355. $isChecked = $rowData[\'on_register\'] && !$rowData[\'disabled\'] ? \' checked="checked"\' : \'\';
  1356. $isDisabled = $rowData[\'can_show_register\'] ? \'\' : \' disabled="disabled"\';
  1357. 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);
  1358. '),
  1359. 'style' => 'width: 20%;',
  1360. 'class' => 'centercol',
  1361. ),
  1362. ),
  1363. ),
  1364. 'form' => array(
  1365. 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1366. 'name' => 'standardProfileFields',
  1367. 'token' => 'admin-scp',
  1368. ),
  1369. 'additional_rows' => array(
  1370. array(
  1371. 'position' => 'below_table_data',
  1372. 'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />',
  1373. ),
  1374. ),
  1375. );
  1376. createList($listOptions);
  1377. $listOptions = array(
  1378. 'id' => 'custom_profile_fields',
  1379. 'title' => $txt['custom_profile_title'],
  1380. 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1381. 'default_sort_col' => 'field_name',
  1382. 'no_items_label' => $txt['custom_profile_none'],
  1383. 'items_per_page' => 25,
  1384. 'get_items' => array(
  1385. 'function' => 'list_getProfileFields',
  1386. 'params' => array(
  1387. false,
  1388. ),
  1389. ),
  1390. 'get_count' => array(
  1391. 'function' => 'list_getProfileFieldSize',
  1392. ),
  1393. 'columns' => array(
  1394. 'field_name' => array(
  1395. 'header' => array(
  1396. 'value' => $txt['custom_profile_fieldname'],
  1397. ),
  1398. 'data' => array(
  1399. 'function' => create_function('$rowData', '
  1400. global $scripturl;
  1401. 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\']);
  1402. '),
  1403. 'style' => 'width: 62%;',
  1404. ),
  1405. 'sort' => array(
  1406. 'default' => 'field_name',
  1407. 'reverse' => 'field_name DESC',
  1408. ),
  1409. ),
  1410. 'field_type' => array(
  1411. 'header' => array(
  1412. 'value' => $txt['custom_profile_fieldtype'],
  1413. ),
  1414. 'data' => array(
  1415. 'function' => create_function('$rowData', '
  1416. global $txt;
  1417. $textKey = sprintf(\'custom_profile_type_%1$s\', $rowData[\'field_type\']);
  1418. return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
  1419. '),
  1420. 'style' => 'width: 15%;',
  1421. ),
  1422. 'sort' => array(
  1423. 'default' => 'field_type',
  1424. 'reverse' => 'field_type DESC',
  1425. ),
  1426. ),
  1427. 'active' => array(
  1428. 'header' => array(
  1429. 'value' => $txt['custom_profile_active'],
  1430. ),
  1431. 'data' => array(
  1432. 'function' => create_function('$rowData', '
  1433. global $txt;
  1434. return $rowData[\'active\'] ? $txt[\'yes\'] : $txt[\'no\'];
  1435. '),
  1436. 'style' => 'width: 8%;',
  1437. ),
  1438. 'sort' => array(
  1439. 'default' => 'active DESC',
  1440. 'reverse' => 'active',
  1441. ),
  1442. ),
  1443. 'placement' => array(
  1444. 'header' => array(
  1445. 'value' => $txt['custom_profile_placement'],
  1446. ),
  1447. 'data' => array(
  1448. 'function' => create_function('$rowData', '
  1449. global $txt;
  1450. return $txt[\'custom_profile_placement_\' . (empty($rowData[\'placement\']) ? \'standard\' : ($rowData[\'placement\'] == 1 ? \'withicons\' : \'abovesignature\'))];
  1451. '),
  1452. 'style' => 'width: 8%;',
  1453. ),
  1454. 'sort' => array(
  1455. 'default' => 'placement DESC',
  1456. 'reverse' => 'placement',
  1457. ),
  1458. ),
  1459. 'show_on_registration' => array(
  1460. 'data' => array(
  1461. 'sprintf' => array(
  1462. 'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
  1463. 'params' => array(
  1464. 'id_field' => false,
  1465. ),
  1466. ),
  1467. 'style' => 'width: 15%;',
  1468. ),
  1469. ),
  1470. ),
  1471. 'form' => array(
  1472. 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit',
  1473. 'name' => 'customProfileFields',
  1474. ),
  1475. 'additional_rows' => array(
  1476. array(
  1477. 'position' => 'below_table_data',
  1478. 'value' => '<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="button_submit" />',
  1479. ),
  1480. ),
  1481. );
  1482. createList($listOptions);
  1483. }
  1484. /**
  1485. * Callback for createList().
  1486. *
  1487. * @param $start
  1488. * @param $items_per_page
  1489. * @param $sort
  1490. * @param $standardFields
  1491. */
  1492. function list_getProfileFields($start, $items_per_page, $sort, $standardFields)
  1493. {
  1494. global $txt, $modSettings, $smcFunc;
  1495. $list = array();
  1496. if ($standardFields)
  1497. {
  1498. $standard_fields = array('icq', 'aim', 'yim', 'skype', 'location', 'gender', 'website', 'personal_text', 'posts', 'warning_status');
  1499. $fields_no_registration = array('posts', 'warning_status');
  1500. $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
  1501. $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
  1502. foreach ($standard_fields as $field)
  1503. $list[] = array(
  1504. 'id' => $field,
  1505. 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
  1506. 'disabled' => in_array($field, $disabled_fields),
  1507. 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
  1508. 'can_show_register' => !in_array($field, $fields_no_registration),
  1509. );
  1510. }
  1511. else
  1512. {
  1513. // Load all the fields.
  1514. $request = $smcFunc['db_query']('', '
  1515. SELECT id_field, col_name, field_name, field_desc, field_type, active, placement
  1516. FROM {db_prefix}custom_fields
  1517. ORDER BY {raw:sort}
  1518. LIMIT {int:start}, {int:items_per_page}',
  1519. array(
  1520. 'sort' => $sort,
  1521. 'start' => $start,
  1522. 'items_per_page' => $items_per_page,
  1523. )
  1524. );
  1525. while ($row = $smcFunc['db_fetch_assoc']($request))
  1526. $list[] = $row;
  1527. $smcFunc['db_free_result']($request);
  1528. }
  1529. return $list;
  1530. }
  1531. /**
  1532. * Callback for createList().
  1533. */
  1534. function list_getProfileFieldSize()
  1535. {
  1536. global $smcFunc;
  1537. $request = $smcFunc['db_query']('', '
  1538. SELECT COUNT(*)
  1539. FROM {db_prefix}custom_fields',
  1540. array(
  1541. )
  1542. );
  1543. list ($numProfileFields) = $smcFunc['db_fetch_row']($request);
  1544. $smcFunc['db_free_result']($request);
  1545. return $numProfileFields;
  1546. }
  1547. /**
  1548. * Edit some profile fields?
  1549. */
  1550. function EditCustomProfiles()
  1551. {
  1552. global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
  1553. // Sort out the context!
  1554. $context['fid'] = isset($_GET['fid']) ? (int) $_GET['fid'] : 0;
  1555. $context[$context['admin_menu_name']]['current_subsection'] = 'profile';
  1556. $context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
  1557. $context['sub_template'] = 'edit_profile_field';
  1558. // Load the profile language for section names.
  1559. loadLanguage('Profile');
  1560. if ($context['fid'])
  1561. {
  1562. $request = $smcFunc['db_query']('', '
  1563. SELECT
  1564. id_field, col_name, field_name, field_desc, field_type, field_length, field_options,
  1565. show_reg, show_display, show_profile, private, active, default_value, can_search,
  1566. bbc, mask, enclose, placement
  1567. FROM {db_prefix}custom_fields
  1568. WHERE id_field = {int:current_field}',
  1569. array(
  1570. 'current_field' => $context['fid'],
  1571. )
  1572. );
  1573. $context['field'] = array();
  1574. while ($row = $smcFunc['db_fetch_assoc']($request))
  1575. {
  1576. if ($row['field_type'] == 'textarea')
  1577. @list ($rows, $cols) = @explode(',', $row['default_value']);
  1578. else
  1579. {
  1580. $rows = 3;
  1581. $cols = 30;
  1582. }
  1583. $context['field'] = array(
  1584. 'name' => $row['field_name'],
  1585. 'desc' => $row['field_desc'],
  1586. 'colname' => $row['col_name'],
  1587. 'profile_area' => $row['show_profile'],
  1588. 'reg' => $row['show_reg'],
  1589. 'display' => $row['show_display'],
  1590. 'type' => $row['field_type'],
  1591. 'max_length' => $row['field_length'],
  1592. 'rows' => $rows,
  1593. 'cols' => $cols,
  1594. 'bbc' => $row['bbc'] ? true : false,
  1595. 'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false,
  1596. 'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '',
  1597. 'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : array('', '', ''),
  1598. 'active' => $row['active'],
  1599. 'private' => $row['private'],
  1600. 'can_search' => $row['can_search'],
  1601. 'mask' => $row['mask'],
  1602. 'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '',
  1603. 'enclose' => $row['enclose'],
  1604. 'placement' => $row['placement'],
  1605. );
  1606. }
  1607. $smcFunc['db_free_result']($request);
  1608. }
  1609. // Setup the default values as needed.
  1610. if (empty($context['field']))
  1611. $context['field'] = array(
  1612. 'name' => '',
  1613. 'colname' => '???',
  1614. 'desc' => '',
  1615. 'profile_area' => 'forumprofile',
  1616. 'reg' => false,
  1617. 'display' => false,
  1618. 'type' => 'text',
  1619. 'max_length' => 255,
  1620. 'rows' => 4,
  1621. 'cols' => 30,
  1622. 'bbc' => false,
  1623. 'default_check' => false,
  1624. 'default_select' => '',
  1625. 'options' => array('', '', ''),
  1626. 'active' => true,
  1627. 'private' => false,
  1628. 'can_search' => false,
  1629. 'mask' => 'nohtml',
  1630. 'regex' => '',
  1631. 'enclose' => '',
  1632. 'placement' => 0,
  1633. );
  1634. // Are we saving?
  1635. if (isset($_POST['save']))
  1636. {
  1637. checkSession();
  1638. validateToken('admin-ecp');
  1639. // Everyone needs a name - even the (bracket) unknown...
  1640. if (trim($_POST['field_name']) == '')
  1641. redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
  1642. // Regex you say? Do a very basic test to see if the pattern is valid
  1643. if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
  1644. redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
  1645. $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
  1646. $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
  1647. // Checkboxes...
  1648. $show_reg = isset($_POST['reg']) ? (int) $_POST['reg'] : 0;
  1649. $show_display = isset($_POST['display']) ? 1 : 0;
  1650. $bbc = isset($_POST['bbc']) ? 1 : 0;
  1651. $show_profile = $_POST['profile_area'];
  1652. $active = isset($_POST['active']) ? 1 : 0;
  1653. $private = isset($_POST['private']) ? (int) $_POST['private'] : 0;
  1654. $can_search = isset($_POST['can_search']) ? 1 : 0;
  1655. // Some masking stuff...
  1656. $mask = isset($_POST['mask']) ? $_POST['mask'] : '';
  1657. if ($mask == 'regex' && isset($_POST['regex']))
  1658. $mask .= $_POST['regex'];
  1659. $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
  1660. $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
  1661. $placement = isset($_POST['placement']) ? (int) $_POST['placement'] : 0;
  1662. // Select options?
  1663. $field_options = '';
  1664. $newOptions = array();
  1665. $default = isset($_POST['default_check']) && $_POST['field_type'] == 'check' ? 1 : '';
  1666. if (!empty($_POST['select_option']) && ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio'))
  1667. {
  1668. foreach ($_POST['select_option'] as $k => $v)
  1669. {
  1670. // Clean, clean, clean...
  1671. $v = $smcFunc['htmlspecialchars']($v);
  1672. $v = strtr($v, array(',' => ''));
  1673. // Nada, zip, etc...
  1674. if (trim($v) == '')
  1675. continue;
  1676. // Otherwise, save it boy.
  1677. $field_options .= $v . ',';
  1678. // This is just for working out what happened with old options...
  1679. $newOptions[$k] = $v;
  1680. // Is it default?
  1681. if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
  1682. $default = $v;
  1683. }
  1684. $field_options = substr($field_options, 0, -1);
  1685. }
  1686. // Text area has default has dimensions
  1687. if ($_POST['field_type'] == 'textarea')
  1688. $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
  1689. // Come up with the unique name?
  1690. if (empty($context['fid']))
  1691. {
  1692. $colname = $smcFunc['substr'](strtr($_POST['field_name'], array(' ' => '')), 0, 6);
  1693. preg_match('~([\w\d_-]+)~', $colname, $matches);
  1694. // If there is nothing to the name, then let's start out own - for foreign languages etc.
  1695. if (isset($matches[1]))
  1696. $colname = $initial_colname = 'cust_' . strtolower($matches[1]);
  1697. else
  1698. $colname = $initial_colname = 'cust_' . mt_rand(1, 999);
  1699. // Make sure this is unique.
  1700. // @todo This may not be the most efficient way to do this.
  1701. $unique = false;
  1702. for ($i = 0; !$unique && $i < 9; $i ++)
  1703. {
  1704. $request = $smcFunc['db_query']('', '
  1705. SELECT id_field
  1706. FROM {db_prefix}custom_fields
  1707. WHERE col_name = {string:current_column}',
  1708. array(
  1709. 'current_column' => $colname,
  1710. )
  1711. );
  1712. if ($smcFunc['db_num_rows']($request) == 0)
  1713. $unique = true;
  1714. else
  1715. $colname = $initial_colname . $i;
  1716. $smcFunc['db_free_result']($request);
  1717. }
  1718. // Still not a unique colum name? Leave it up to the user, then.
  1719. if (!$unique)
  1720. fatal_lang_error('custom_option_not_unique');
  1721. }
  1722. // Work out what to do with the user data otherwise...
  1723. else
  1724. {
  1725. // Anything going to check or select is pointless keeping - as is anything coming from check!
  1726. if (($_POST['field_type'] == 'check' && $context['field']['type'] != 'check')
  1727. || (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
  1728. || ($context['field']['type'] == 'check' && $_POST['field_type'] != 'check'))
  1729. {
  1730. $smcFunc['db_query']('', '
  1731. DELETE FROM {db_prefix}themes
  1732. WHERE variable = {string:current_column}
  1733. AND id_member > {int:no_member}',
  1734. array(
  1735. 'no_member' => 0,
  1736. 'current_column' => $context['field']['colname'],
  1737. )
  1738. );
  1739. }
  1740. // Otherwise - if the select is edited may need to adjust!
  1741. elseif ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio')
  1742. {
  1743. $optionChanges = array();
  1744. $takenKeys = array();
  1745. // Work out what's changed!
  1746. foreach ($context['field']['options'] as $k => $option)
  1747. {
  1748. if (trim($option) == '')
  1749. continue;
  1750. // Still exists?
  1751. if (in_array($option, $newOptions))
  1752. {
  1753. $takenKeys[] = $k;
  1754. continue;
  1755. }
  1756. }
  1757. // Finally - have we renamed it - or is it really gone?
  1758. foreach ($optionChanges as $k => $option)
  1759. {
  1760. // Just been renamed?
  1761. if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
  1762. $smcFunc['db_query']('', '
  1763. UPDATE {db_prefix}themes
  1764. SET value = {string:new_value}
  1765. WHERE variable = {string:current_column}
  1766. AND value = {string:old_value}
  1767. AND id_member > {int:no_member}',
  1768. array(
  1769. 'no_member' => 0,
  1770. 'new_value' => $newOptions[$k],
  1771. 'current_column' => $context['field']['colname'],
  1772. 'old_value' => $option,
  1773. )
  1774. );
  1775. }
  1776. }
  1777. // @todo Maybe we should adjust based on new text length limits?
  1778. }
  1779. // Do the insertion/updates.
  1780. if ($context['fid'])
  1781. {
  1782. $smcFunc['db_query']('', '
  1783. UPDATE {db_prefix}custom_fields
  1784. SET
  1785. field_name = {string:field_name}, field_desc = {string:field_desc},
  1786. field_type = {string:field_type}, field_length = {int:field_length},
  1787. field_options = {string:field_options}, show_reg = {int:show_reg},
  1788. show_display = {int:show_display}, show_profile = {string:show_profile},
  1789. private = {int:private}, active = {int:active}, default_value = {string:default_value},
  1790. can_search = {int:can_search}, bbc = {int:bbc}, mask = {string:mask},
  1791. enclose = {string:enclose}, placement = {int:placement}
  1792. WHERE id_field = {int:current_field}',
  1793. array(
  1794. 'field_length' => $field_length,
  1795. 'show_reg' => $show_reg,
  1796. 'show_display' => $show_display,
  1797. 'private' => $private,
  1798. 'active' => $active,
  1799. 'can_search' => $can_search,
  1800. 'bbc' => $bbc,
  1801. 'current_field' => $context['fid'],
  1802. 'field_name' => $_POST['field_name'],
  1803. 'field_desc' => $_POST['field_desc'],
  1804. 'field_type' => $_POST['field_type'],
  1805. 'field_options' => $field_options,
  1806. 'show_profile' => $show_profile,
  1807. 'default_value' => $default,
  1808. 'mask' => $mask,
  1809. 'enclose' => $enclose,
  1810. 'placement' => $placement,
  1811. )
  1812. );
  1813. // Just clean up any old selects - these are a pain!
  1814. if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
  1815. $smcFunc['db_query']('', '
  1816. DELETE FROM {db_prefix}themes
  1817. WHERE variable = {string:current_column}
  1818. AND value NOT IN ({array_string:new_option_values})
  1819. AND id_member > {int:no_member}',
  1820. array(
  1821. 'no_member' => 0,
  1822. 'new_option_values' => $newOptions,
  1823. 'current_column' => $context['field']['colname'],
  1824. )
  1825. );
  1826. }
  1827. else
  1828. {
  1829. $smcFunc['db_insert']('',
  1830. '{db_prefix}custom_fields',
  1831. array(
  1832. 'col_name' => 'string', 'field_name' => 'string', 'field_desc' => 'string',
  1833. 'field_type' => 'string', 'field_length' => 'string', 'field_options' => 'string',
  1834. 'show_reg' => 'int', 'show_display' => 'int', 'show_profile' => 'string',
  1835. 'private' => 'int', 'active' => 'int', 'default_value' => 'string', 'can_search' => 'int',
  1836. 'bbc' => 'int', 'mask' => 'string', 'enclose' => 'string', 'placement' => 'int',
  1837. ),
  1838. array(
  1839. $colname, $_POST['field_name'], $_POST['field_desc'],
  1840. $_POST['field_type'], $field_length, $field_options,
  1841. $show_reg, $show_display, $show_profile,
  1842. $private, $active, $default, $can_search,
  1843. $bbc, $mask, $enclose, $placement,
  1844. ),
  1845. array('id_field')
  1846. );
  1847. }
  1848. // As there's currently no option to priorize certain fields over others, let's order them alphabetically.
  1849. $smcFunc['db_query']('alter_table_boards', '
  1850. ALTER TABLE {db_prefix}custom_fields
  1851. ORDER BY field_name',
  1852. array(
  1853. 'db_error_skip' => true,
  1854. )
  1855. );
  1856. }
  1857. // Deleting?
  1858. elseif (isset($_POST['delete']) && $context['field']['colname'])
  1859. {
  1860. checkSession();
  1861. validateToken('admin-ecp');
  1862. // Delete the user data first.
  1863. $smcFunc['db_query']('', '
  1864. DELETE FROM {db_prefix}themes
  1865. WHERE variable = {string:current_column}
  1866. AND id_member > {int:no_member}',
  1867. array(
  1868. 'no_member' => 0,
  1869. 'current_column' => $context['field']['colname'],
  1870. )
  1871. );
  1872. // Finally - the field itself is gone!
  1873. $smcFunc['db_query']('', '
  1874. DELETE FROM {db_prefix}custom_fields
  1875. WHERE id_field = {int:current_field}',
  1876. array(
  1877. 'current_field' => $context['fid'],
  1878. )
  1879. );
  1880. }
  1881. // Rebuild display cache etc.
  1882. if (isset($_POST['delete']) || isset($_POST['save']))
  1883. {
  1884. checkSession();
  1885. $request = $smcFunc['db_query']('', '
  1886. SELECT col_name, field_name, field_type, bbc, enclose, placement
  1887. FROM {db_prefix}custom_fields
  1888. WHERE show_display = {int:is_displayed}
  1889. AND active = {int:active}
  1890. AND private != {int:not_owner_only}
  1891. AND private != {int:not_admin_only}',
  1892. array(
  1893. 'is_displayed' => 1,
  1894. 'active' => 1,
  1895. 'not_owner_only' => 2,
  1896. 'not_admin_only' => 3,
  1897. )
  1898. );
  1899. $fields = array();
  1900. while ($row = $smcFunc['db_fetch_assoc']($request))
  1901. {
  1902. $fields[] = array(
  1903. 'colname' => strtr($row['col_name'], array('|' => '', ';' => '')),
  1904. 'title' => strtr($row['field_name'], array('|' => '', ';' => '')),
  1905. 'type' => $row['field_type'],
  1906. 'bbc' => $row['bbc'] ? '1' : '0',
  1907. 'placement' => !empty($row['placement']) ? $row['placement'] : '0',
  1908. 'enclose' => !empty($row['enclose']) ? $row['enclose'] : '',
  1909. );
  1910. }
  1911. $smcFunc['db_free_result']($request);
  1912. updateSettings(array('displayFields' => serialize($fields)));
  1913. redirectexit('action=admin;area=featuresettings;sa=profile');
  1914. }
  1915. createToken('admin-ecp');
  1916. }
  1917. /**
  1918. * Allow to edit the settings on the pruning screen.
  1919. * @param $return_config
  1920. */
  1921. function ModifyPruningSettings($return_config = false)
  1922. {
  1923. global $txt, $scripturl, $sourcedir, $context, $settings, $sc, $modSettings;
  1924. // Make sure we understand what's going on.
  1925. loadLanguage('ManageSettings');
  1926. $context['page_title'] = $txt['pruning_title'];
  1927. $config_vars = array(
  1928. // Even do the pruning?
  1929. // The array indexes are there so we can remove/change them before saving.
  1930. 'pruningOptions' => array('check', 'pruningOptions'),
  1931. '',
  1932. // Various logs that could be pruned.
  1933. array('int', 'pruneErrorLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Error log.
  1934. array('int', 'pruneModLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Moderation log.
  1935. array('int', 'pruneBanLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Ban hit log.
  1936. array('int', 'pruneReportLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Report to moderator log.
  1937. array('int', 'pruneScheduledTaskLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
  1938. array('int', 'pruneSpiderHitLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
  1939. // 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.
  1940. // Mod Developers: Do NOT use the pruningOptions master variable for this as SMF Core may overwrite your setting in the future!
  1941. );
  1942. call_integration_hook('integrate_prune_settings', array(&$config_vars));
  1943. if ($return_config)
  1944. return $config_vars;
  1945. // We'll need this in a bit.
  1946. require_once($sourcedir . '/ManageServer.php');
  1947. // Saving?
  1948. if (isset($_GET['save']))
  1949. {
  1950. checkSession();
  1951. $savevar = array(
  1952. array('text', 'pruningOptions')
  1953. );
  1954. if (!empty($_POST['pruningOptions']))
  1955. {
  1956. $vals = array();
  1957. foreach ($config_vars as $index => $dummy)
  1958. {
  1959. if (!is_array($dummy) || $index == 'pruningOptions')
  1960. continue;
  1961. $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
  1962. }
  1963. $_POST['pruningOptions'] = implode(',', $vals);
  1964. }
  1965. else
  1966. $_POST['pruningOptions'] = '';
  1967. saveDBSettings($savevar);
  1968. redirectexit('action=admin;area=logs;sa=pruning');
  1969. }
  1970. $context['post_url'] = $scripturl . '?action=admin;area=logs;save;sa=pruning';
  1971. $context['settings_title'] = $txt['pruning_title'];
  1972. $context['sub_template'] = 'show_settings';
  1973. // Get the actual values
  1974. if (!empty($modSettings['pruningOptions']))
  1975. @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
  1976. else
  1977. $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
  1978. prepareDBSettingContext($config_vars);
  1979. }
  1980. /**
  1981. * If you have a general mod setting to add stick it here.
  1982. *
  1983. * @param $return_config
  1984. */
  1985. function ModifyGeneralModSettings($return_config = false)
  1986. {
  1987. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  1988. $config_vars = array(
  1989. // Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
  1990. );
  1991. // Make it even easier to add new settings.
  1992. call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
  1993. if ($return_config)
  1994. return $config_vars;
  1995. $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
  1996. $context['settings_title'] = $txt['mods_cat_modifications_misc'];
  1997. // No removing this line you, dirty unwashed mod authors. :p
  1998. if (empty($config_vars))
  1999. {
  2000. $context['settings_save_dont_show'] = true;
  2001. $context['settings_message'] = '<div class="centertext">' . $txt['modification_no_misc_settings'] . '</div>';
  2002. return prepareDBSettingContext($config_vars);
  2003. }
  2004. // Saving?
  2005. if (isset($_GET['save']))
  2006. {
  2007. checkSession();
  2008. $save_vars = $config_vars;
  2009. call_integration_hook('integrate_save_general_mod_settings', array(&$save_vars));
  2010. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
  2011. saveDBSettings($save_vars);
  2012. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
  2013. redirectexit('action=admin;area=modsettings;sa=general');
  2014. }
  2015. // 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!
  2016. prepareDBSettingContext($config_vars);
  2017. }
  2018. /**
  2019. * Generates a list of integration hooks for display
  2020. * Accessed through ?action=admin;area=modsettings;sa=hooks;
  2021. * Allows for removal or disabing of selected hooks
  2022. */
  2023. function list_integration_hooks()
  2024. {
  2025. global $sourcedir, $scripturl, $context, $txt, $modSettings, $settings;
  2026. $context['filter_url'] = '';
  2027. $context['current_filter'] = '';
  2028. $currentHooks = get_integration_hooks();
  2029. if (isset($_GET['filter']) && in_array($_GET['filter'], array_keys($currentHooks)))
  2030. {
  2031. $context['filter_url'] = ';filter=' . $_GET['filter'];
  2032. $context['current_filter'] = $_GET['filter'];
  2033. }
  2034. if (!empty($modSettings['handlinghooks_enabled']))
  2035. {
  2036. if (!empty($_REQUEST['do']) && isset($_REQUEST['hook']) && isset($_REQUEST['function']))
  2037. {
  2038. checkSession('request');
  2039. validateToken('admin-hook', 'request');
  2040. if ($_REQUEST['do'] == 'remove')
  2041. remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
  2042. else
  2043. {
  2044. if ($_REQUEST['do'] == 'disable')
  2045. {
  2046. // It's a hack I know...but I'm way too lazy!!!
  2047. $function_remove = $_REQUEST['function'];
  2048. $function_add = $_REQUEST['function'] . ']';
  2049. }
  2050. else
  2051. {
  2052. $function_remove = $_REQUEST['function'] . ']';
  2053. $function_add = $_REQUEST['function'];
  2054. }
  2055. $file = !empty($_REQUEST['includedfile']) ? urldecode($_REQUEST['includedfile']) : '';
  2056. remove_integration_function($_REQUEST['hook'], $function_remove, $file);
  2057. add_integration_function($_REQUEST['hook'], $function_add, $file);
  2058. redirectexit('action=admin;area=modsettings;sa=hooks' . $context['filter_url']);
  2059. }
  2060. }
  2061. }
  2062. $list_options = array(
  2063. 'id' => 'list_integration_hooks',
  2064. 'title' => $txt['hooks_title_list'],
  2065. 'items_per_page' => 20,
  2066. 'base_href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  2067. 'default_sort_col' => 'hook_name',
  2068. 'get_items' => array(
  2069. 'function' => 'get_integration_hooks_data',
  2070. ),
  2071. 'get_count' => array(
  2072. 'function' => 'get_integration_hooks_count',
  2073. ),
  2074. 'no_items_label' => $txt['hooks_no_hooks'],
  2075. 'columns' => array(
  2076. 'hook_name' => array(
  2077. 'header' => array(
  2078. 'value' => $txt['hooks_field_hook_name'],
  2079. ),
  2080. 'data' => array(
  2081. 'db' => 'hook_name',
  2082. ),
  2083. 'sort' => array(
  2084. 'default' => 'hook_name',
  2085. 'reverse' => 'hook_name DESC',
  2086. ),
  2087. ),
  2088. 'function_name' => array(
  2089. 'header' => array(
  2090. 'value' => $txt['hooks_field_function_name'],
  2091. ),
  2092. 'data' => array(
  2093. 'function' => create_function('$data', '
  2094. global $txt;
  2095. if (!empty($data[\'included_file\']))
  2096. return $txt[\'hooks_field_function\'] . \': \' . $data[\'real_function\'] . \'<br />\' . $txt[\'hooks_field_included_file\'] . \': \' . $data[\'included_file\'];
  2097. else
  2098. return $data[\'real_function\'];
  2099. '),
  2100. ),
  2101. 'sort' => array(
  2102. 'default' => 'function_name',
  2103. 'reverse' => 'function_name DESC',
  2104. ),
  2105. ),
  2106. 'file_name' => array(
  2107. 'header' => array(
  2108. 'value' => $txt['hooks_field_file_name'],
  2109. ),
  2110. 'data' => array(
  2111. 'db' => 'file_name',
  2112. ),
  2113. 'sort' => array(
  2114. 'default' => 'file_name',
  2115. 'reverse' => 'file_name DESC',
  2116. ),
  2117. ),
  2118. 'status' => array(
  2119. 'header' => array(
  2120. 'value' => $txt['hooks_field_hook_exists'],
  2121. 'style' => 'width:3%;',
  2122. ),
  2123. 'data' => array(
  2124. 'function' => create_function('$data', '
  2125. global $txt, $settings, $scripturl, $context;
  2126. $change_status = array(\'before\' => \'\', \'after\' => \'\');
  2127. if ($data[\'can_be_disabled\'] && $data[\'status\'] != \'deny\')
  2128. {
  2129. $change_status[\'before\'] = \'<a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=\' . ($data[\'enabled\'] ? \'disable\' : \'enable\') . \';hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'real_function\'] . (!empty($data[\'included_file\']) ? \';includedfile=\' . urlencode($data[\'included_file\']) : \'\') . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">\';
  2130. $change_status[\'after\'] = \'</a>\';
  2131. }
  2132. return $change_status[\'before\'] . \'<img src="\' . $settings[\'images_url\'] . \'/admin/post_moderation_\' . $data[\'status\'] . \'.png" alt="\' . $data[\'img_text\'] . \'" title="\' . $data[\'img_text\'] . \'" />\' . $change_status[\'after\'];
  2133. '),
  2134. 'class' => 'centertext',
  2135. ),
  2136. 'sort' => array(
  2137. 'default' => 'status',
  2138. 'reverse' => 'status DESC',
  2139. ),
  2140. ),
  2141. ),
  2142. 'additional_rows' => array(
  2143. array(
  2144. 'position' => 'after_title',
  2145. 'value' => $txt['hooks_disable_instructions'] . '<br />
  2146. ' . $txt['hooks_disable_legend'] . ':
  2147. <ul style="list-style: none;">
  2148. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_allow.png" alt="' . $txt['hooks_active'] . '" title="' . $txt['hooks_active'] . '" /> ' . $txt['hooks_disable_legend_exists'] . '</li>
  2149. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_moderate.png" alt="' . $txt['hooks_disabled'] . '" title="' . $txt['hooks_disabled'] . '" /> ' . $txt['hooks_disable_legend_disabled'] . '</li>
  2150. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_deny.png" alt="' . $txt['hooks_missing'] . '" title="' . $txt['hooks_missing'] . '" /> ' . $txt['hooks_disable_legend_missing'] . '</li>
  2151. </ul>'
  2152. ),
  2153. ),
  2154. );
  2155. if (!empty($modSettings['handlinghooks_enabled']))
  2156. {
  2157. createToken('admin-hook', 'request');
  2158. $list_options['columns']['remove'] = array(
  2159. 'header' => array(
  2160. 'value' => $txt['hooks_button_remove'],
  2161. 'style' => 'width:3%',
  2162. ),
  2163. 'data' => array(
  2164. 'function' => create_function('$data', '
  2165. global $txt, $settings, $scripturl, $context;
  2166. if (!$data[\'hook_exists\'])
  2167. return \'
  2168. <a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=remove;hook=\' . $data[\'hook_name\'] . \';function=\' . urlencode($data[\'function_name\']) . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">
  2169. <img src="\' . $settings[\'images_url\'] . \'/icons/quick_remove.png" alt="\' . $txt[\'hooks_button_remove\'] . \'" title="\' . $txt[\'hooks_button_remove\'] . \'" />
  2170. </a>\';
  2171. '),
  2172. 'class' => 'centertext',
  2173. ),
  2174. );
  2175. $list_options['form'] = array(
  2176. 'href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  2177. 'name' => 'list_integration_hooks',
  2178. );
  2179. }
  2180. require_once($sourcedir . '/Subs-List.php');
  2181. createList($list_options);
  2182. $context['page_title'] = $txt['hooks_title_list'];
  2183. $context['sub_template'] = 'show_list';
  2184. $context['default_list'] = 'list_integration_hooks';
  2185. }
  2186. /**
  2187. * Gets all of the files in a directory and its chidren directories
  2188. *
  2189. * @param type $dir_path
  2190. * @return array
  2191. */
  2192. function get_files_recursive($dir_path)
  2193. {
  2194. $files = array();
  2195. if ($dh = opendir($dir_path))
  2196. {
  2197. while (($file = readdir($dh)) !== false)
  2198. {
  2199. if ($file != '.' && $file != '..')
  2200. {
  2201. if (is_dir($dir_path . '/' . $file))
  2202. $files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
  2203. else
  2204. $files[] = array('dir' => $dir_path, 'name' => $file);
  2205. }
  2206. }
  2207. }
  2208. closedir($dh);
  2209. return $files;
  2210. }
  2211. /**
  2212. * Callback function for the integration hooks list (list_integration_hooks)
  2213. * Gets all of the hooks in the system and their status
  2214. * Would be better documented if Ema was not lazy
  2215. *
  2216. * @param type $start
  2217. * @param type $per_page
  2218. * @param type $sort
  2219. * @return array
  2220. */
  2221. function get_integration_hooks_data($start, $per_page, $sort)
  2222. {
  2223. global $boarddir, $sourcedir, $settings, $txt, $context, $scripturl, $modSettings;
  2224. $hooks = $temp_hooks = get_integration_hooks();
  2225. $hooks_data = $temp_data = $hook_status = array();
  2226. $files = get_files_recursive($sourcedir);
  2227. if (!empty($files))
  2228. {
  2229. foreach ($files as $file)
  2230. {
  2231. if (is_file($file['dir'] . '/' . $file['name']) && substr($file['name'], -4) === '.php')
  2232. {
  2233. $fp = fopen($file['dir'] . '/' . $file['name'], 'rb');
  2234. $fc = fread($fp, filesize($file['dir'] . '/' . $file['name']));
  2235. fclose($fp);
  2236. foreach ($temp_hooks as $hook => $functions)
  2237. {
  2238. foreach ($functions as $function_o)
  2239. {
  2240. $hook_name = str_replace(']', '', $function_o);
  2241. if (strpos($hook_name, '::') !== false)
  2242. {
  2243. $function = explode('::', $hook_name);
  2244. $function = $function[1];
  2245. }
  2246. else
  2247. $function = $hook_name;
  2248. $function = explode(':', $function);
  2249. $function = $function[0];
  2250. if (substr($hook, -8) === '_include')
  2251. {
  2252. $hook_status[$hook][$function]['exists'] = file_exists(strtr(trim($function), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])));
  2253. // I need to know if there is at least one function called in this file.
  2254. $temp_data['include'][basename($function)] = array('hook' => $hook, 'function' => $function);
  2255. unset($temp_hooks[$hook][$function_o]);
  2256. }
  2257. elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($function) . '(') !== false)
  2258. {
  2259. $hook_status[$hook][$hook_name]['exists'] = true;
  2260. $hook_status[$hook][$hook_name]['in_file'] = $file['name'];
  2261. // I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
  2262. $temp_data['function'][$file['name']][] = $function_o;
  2263. unset($temp_hooks[$hook][$function_o]);
  2264. }
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. $sort_types = array(
  2271. 'hook_name' => array('hook', SORT_ASC),
  2272. 'hook_name DESC' => array('hook', SORT_DESC),
  2273. 'function_name' => array('function', SORT_ASC),
  2274. 'function_name DESC' => array('function', SORT_DESC),
  2275. 'file_name' => array('file_name', SORT_ASC),
  2276. 'file_name DESC' => array('file_name', SORT_DESC),
  2277. 'status' => array('status', SORT_ASC),
  2278. 'status DESC' => array('status', SORT_DESC),
  2279. );
  2280. $sort_options = $sort_types[$sort];
  2281. $sort = array();
  2282. $hooks_filters = array();
  2283. foreach ($hooks as $hook => $functions)
  2284. {
  2285. $hooks_filters[] = '<option ' . ($context['current_filter'] == $hook ? 'selected="selected" ' : '') . 'onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks;filter=' . $hook . '\';">' . $hook . '</option>';
  2286. foreach ($functions as $function)
  2287. {
  2288. $enabled = strstr($function, ']') === false;
  2289. $function = str_replace(']', '', $function);
  2290. // This is a not an include and the function is included in a certain file (if not it doesn't exists so don't care)
  2291. if (substr($hook, -8) !== '_include' && isset($hook_status[$hook][$function]['in_file']))
  2292. {
  2293. $current_hook = isset($temp_data['include'][$hook_status[$hook][$function]['in_file']]) ? $temp_data['include'][$hook_status[$hook][$function]['in_file']] : '';
  2294. $enabled = false;
  2295. // Checking all the functions within this particular file
  2296. // if any of them is enable then the file *must* be included and the integrate_*_include hook cannot be disabled
  2297. foreach ($temp_data['function'][$hook_status[$hook][$function]['in_file']] as $func)
  2298. $enabled = $enabled || strstr($func, ']') !== false;
  2299. if (!$enabled && !empty($current_hook))
  2300. $hook_status[$current_hook['hook']][$current_hook['function']]['enabled'] = true;
  2301. }
  2302. }
  2303. }
  2304. if (!empty($hooks_filters))
  2305. $context['insert_after_template'] .= '
  2306. <script type="text/javascript"><!-- // --><![CDATA[
  2307. var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
  2308. hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;"><option>---</option><option onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks\';">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). ';
  2309. // ]]></script>';
  2310. $temp_data = array();
  2311. $id = 0;
  2312. foreach ($hooks as $hook => $functions)
  2313. {
  2314. if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
  2315. {
  2316. foreach ($functions as $function)
  2317. {
  2318. $enabled = strstr($function, ']') === false;
  2319. $function = str_replace(']', '', $function);
  2320. $hook_exists = !empty($hook_status[$hook][$function]['exists']);
  2321. $file_name = isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ((substr($hook, -8) === '_include') ? 'zzzzzzzzz' : 'zzzzzzzza');
  2322. $sort[] = $$sort_options[0];
  2323. if (strpos($function, '::') !== false)
  2324. {
  2325. $function = explode('::', $function);
  2326. $function = $function[1];
  2327. }
  2328. $exploded = explode(':', $function);
  2329. $temp_data[] = array(
  2330. 'id' => 'hookid_' . $id++,
  2331. 'hook_name' => $hook,
  2332. 'function_name' => $function,
  2333. 'real_function' => $exploded[0],
  2334. 'included_file' => isset($exploded[1]) ? strtr(trim($exploded[1]), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])) : '',
  2335. 'file_name' => (isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ''),
  2336. 'hook_exists' => $hook_exists,
  2337. 'status' => $hook_exists ? ($enabled ? 'allow' : 'moderate') : 'deny',
  2338. 'img_text' => $txt['hooks_' . ($hook_exists ? ($enabled ? 'active' : 'disabled') : 'missing')],
  2339. 'enabled' => $enabled,
  2340. 'can_be_disabled' => !empty($modSettings['handlinghooks_enabled']) && !isset($hook_status[$hook][$function]['enabled']),
  2341. );
  2342. }
  2343. }
  2344. }
  2345. array_multisort($sort, $sort_options[1], $temp_data);
  2346. $counter = 0;
  2347. $start++;
  2348. foreach ($temp_data as $data)
  2349. {
  2350. if (++$counter < $start)
  2351. continue;
  2352. elseif ($counter == $start + $per_page)
  2353. break;
  2354. $hooks_data[] = $data;
  2355. }
  2356. return $hooks_data;
  2357. }
  2358. /**
  2359. * Simply returns the total count of integraion hooks
  2360. * Used but the intergation hooks list function (list_integration_hooks)
  2361. *
  2362. * @global type $context
  2363. * @return int
  2364. */
  2365. function get_integration_hooks_count()
  2366. {
  2367. global $context;
  2368. $hooks = get_integration_hooks();
  2369. $hooks_count = 0;
  2370. $context['filter'] = false;
  2371. if (isset($_GET['filter']))
  2372. $context['filter'] = $_GET['filter'];
  2373. foreach ($hooks as $hook => $functions)
  2374. {
  2375. if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
  2376. $hooks_count += count($functions);
  2377. }
  2378. return $hooks_count;
  2379. }
  2380. /**
  2381. * Parses modSettings to create integration hook array
  2382. *
  2383. * @staticvar type $integration_hooks
  2384. * @return type
  2385. */
  2386. function get_integration_hooks()
  2387. {
  2388. global $modSettings;
  2389. static $integration_hooks;
  2390. if (!isset($integration_hooks))
  2391. {
  2392. $integration_hooks = array();
  2393. foreach ($modSettings as $key => $value)
  2394. {
  2395. if (!empty($value) && substr($key, 0, 10) === 'integrate_')
  2396. $integration_hooks[$key] = explode(',', $value);
  2397. }
  2398. }
  2399. return $integration_hooks;
  2400. }
  2401. ?>