Admin.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <?php
  2. /**
  3. * This file, unpredictable as this might be, handles basic administration.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines
  9. *
  10. * @copyright 2011 Simple Machines
  11. * @license http://www.simplemachines.org/about/smf/license.php BSD
  12. *
  13. * @version 2.1 Alpha 1
  14. */
  15. if (!defined('SMF'))
  16. die('Hacking attempt...');
  17. /**
  18. * The main admin handling function.
  19. * It initialises all the basic context required for the admin center.
  20. * It passes execution onto the relevant admin section.
  21. * If the passed section is not found it shows the admin home page.
  22. */
  23. function AdminMain()
  24. {
  25. global $txt, $context, $scripturl, $sc, $modSettings, $user_info, $settings, $sourcedir, $options, $smcFunc, $boarddir;
  26. // Load the language and templates....
  27. loadLanguage('Admin');
  28. loadTemplate('Admin', 'admin');
  29. loadJavascriptFile('admin.js?alp21', array('default_theme' => true), 'admin.js');
  30. // No indexing evil stuff.
  31. $context['robot_no_index'] = true;
  32. require_once($sourcedir . '/Subs-Menu.php');
  33. // Some preferences.
  34. $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  35. $context['hooks_exist'] = false;
  36. foreach ($modSettings as $key => $setting)
  37. if (strpos($key, 'integrate') === 0)
  38. if (!empty($setting))
  39. {
  40. $context['hooks_exist'] = true;
  41. break;
  42. }
  43. // Define all the menu structure - see Subs-Menu.php for details!
  44. $admin_areas = array(
  45. 'forum' => array(
  46. 'title' => $txt['admin_main'],
  47. 'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'),
  48. 'areas' => array(
  49. 'index' => array(
  50. 'label' => $txt['admin_center'],
  51. 'function' => 'AdminHome',
  52. 'icon' => 'administration.png',
  53. ),
  54. 'credits' => array(
  55. 'label' => $txt['support_credits_title'],
  56. 'function' => 'AdminHome',
  57. 'icon' => 'support.png',
  58. ),
  59. 'news' => array(
  60. 'label' => $txt['news_title'],
  61. 'file' => 'ManageNews.php',
  62. 'function' => 'ManageNews',
  63. 'icon' => 'news.png',
  64. 'permission' => array('edit_news', 'send_mail', 'admin_forum'),
  65. 'subsections' => array(
  66. 'editnews' => array($txt['admin_edit_news'], 'edit_news'),
  67. 'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'),
  68. 'settings' => array($txt['settings'], 'admin_forum'),
  69. ),
  70. ),
  71. 'packages' => array(
  72. 'label' => $txt['package'],
  73. 'file' => 'Packages.php',
  74. 'function' => 'Packages',
  75. 'permission' => array('admin_forum'),
  76. 'icon' => 'packages.png',
  77. 'subsections' => array(
  78. 'browse' => array($txt['browse_packages']),
  79. 'packageget' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packages;sa=packageget;get'),
  80. 'installed' => array($txt['installed_packages']),
  81. 'perms' => array($txt['package_file_perms']),
  82. 'options' => array($txt['package_settings']),
  83. ),
  84. ),
  85. 'search' => array(
  86. 'function' => 'AdminSearch',
  87. 'permission' => array('admin_forum'),
  88. 'select' => 'index'
  89. ),
  90. 'adminlogoff' => array(
  91. 'label' => $txt['admin_logoff'],
  92. 'function' => 'AdminEndSession',
  93. 'enabled' => empty($modSettings['securityDisable']),
  94. 'icon' => 'exit.png',
  95. ),
  96. ),
  97. ),
  98. 'config' => array(
  99. 'title' => $txt['admin_config'],
  100. 'permission' => array('admin_forum'),
  101. 'areas' => array(
  102. 'corefeatures' => array(
  103. 'label' => $txt['core_settings_title'],
  104. 'file' => 'ManageSettings.php',
  105. 'function' => 'ModifyCoreFeatures',
  106. 'icon' => 'corefeatures.png',
  107. ),
  108. 'featuresettings' => array(
  109. 'label' => $txt['modSettings_title'],
  110. 'file' => 'ManageSettings.php',
  111. 'function' => 'ModifyFeatureSettings',
  112. 'icon' => 'features.png',
  113. 'subsections' => array(
  114. 'basic' => array($txt['mods_cat_features']),
  115. 'layout' => array($txt['mods_cat_layout']),
  116. 'karma' => array($txt['karma'], 'enabled' => in_array('k', $context['admin_features'])),
  117. 'sig' => array($txt['signature_settings_short']),
  118. 'profile' => array($txt['custom_profile_shorttitle'], 'enabled' => in_array('cp', $context['admin_features'])),
  119. ),
  120. ),
  121. 'securitysettings' => array(
  122. 'label' => $txt['admin_security_moderation'],
  123. 'file' => 'ManageSettings.php',
  124. 'function' => 'ModifySecuritySettings',
  125. 'icon' => 'security.png',
  126. 'subsections' => array(
  127. 'general' => array($txt['mods_cat_security_general']),
  128. 'spam' => array($txt['antispam_title']),
  129. 'moderation' => array($txt['moderation_settings_short'], 'enabled' => substr($modSettings['warning_settings'], 0, 1) == 1),
  130. ),
  131. ),
  132. 'languages' => array(
  133. 'label' => $txt['language_configuration'],
  134. 'file' => 'ManageLanguages.php',
  135. 'function' => 'ManageLanguages',
  136. 'icon' => 'languages.png',
  137. 'subsections' => array(
  138. 'edit' => array($txt['language_edit']),
  139. 'add' => array($txt['language_add']),
  140. 'settings' => array($txt['language_settings']),
  141. ),
  142. ),
  143. 'serversettings' => array(
  144. 'label' => $txt['admin_server_settings'],
  145. 'file' => 'ManageServer.php',
  146. 'function' => 'ModifySettings',
  147. 'icon' => 'server.png',
  148. 'subsections' => array(
  149. 'general' => array($txt['general_settings']),
  150. 'database' => array($txt['database_paths_settings']),
  151. 'cookie' => array($txt['cookies_sessions_settings']),
  152. 'cache' => array($txt['caching_settings']),
  153. 'loads' => array($txt['load_balancing_settings']),
  154. 'phpinfo' => array($txt['phpinfo_settings']),
  155. ),
  156. ),
  157. 'current_theme' => array(
  158. 'label' => $txt['theme_current_settings'],
  159. 'file' => 'Themes.php',
  160. 'function' => 'ThemesMain',
  161. 'custom_url' => $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'],
  162. 'icon' => 'current_theme.png',
  163. ),
  164. 'theme' => array(
  165. 'label' => $txt['theme_admin'],
  166. 'file' => 'Themes.php',
  167. 'function' => 'ThemesMain',
  168. 'custom_url' => $scripturl . '?action=admin;area=theme',
  169. 'icon' => 'themes.png',
  170. 'subsections' => array(
  171. 'admin' => array($txt['themeadmin_admin_title']),
  172. 'list' => array($txt['themeadmin_list_title']),
  173. 'reset' => array($txt['themeadmin_reset_title']),
  174. 'edit' => array($txt['themeadmin_edit_title']),
  175. ),
  176. ),
  177. 'modsettings' => array(
  178. 'label' => $txt['admin_modifications'],
  179. 'file' => 'ManageSettings.php',
  180. 'function' => 'ModifyModSettings',
  181. 'icon' => 'modifications.png',
  182. 'subsections' => array(
  183. 'hooks' => array($txt['hooks_title_list'], 'enabled' => $context['hooks_exist']),
  184. 'general' => array($txt['mods_cat_modifications_misc']),
  185. // Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example:
  186. // 'shout' => array($txt['shout']),
  187. // Note the comma!! The setting with automatically appear with the first mod to be added.
  188. ),
  189. ),
  190. ),
  191. ),
  192. 'layout' => array(
  193. 'title' => $txt['layout_controls'],
  194. 'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
  195. 'areas' => array(
  196. 'manageboards' => array(
  197. 'label' => $txt['admin_boards'],
  198. 'file' => 'ManageBoards.php',
  199. 'function' => 'ManageBoards',
  200. 'icon' => 'boards.png',
  201. 'permission' => array('manage_boards'),
  202. 'subsections' => array(
  203. 'main' => array($txt['boardsEdit']),
  204. 'newcat' => array($txt['mboards_new_cat']),
  205. 'settings' => array($txt['settings'], 'admin_forum'),
  206. ),
  207. ),
  208. 'postsettings' => array(
  209. 'label' => $txt['manageposts'],
  210. 'file' => 'ManagePosts.php',
  211. 'function' => 'ManagePostSettings',
  212. 'permission' => array('admin_forum'),
  213. 'icon' => 'posts.png',
  214. 'subsections' => array(
  215. 'posts' => array($txt['manageposts_settings']),
  216. 'bbc' => array($txt['manageposts_bbc_settings']),
  217. 'censor' => array($txt['admin_censored_words']),
  218. 'topics' => array($txt['manageposts_topic_settings']),
  219. ),
  220. ),
  221. 'managedrafts' => array(
  222. 'label' => $txt['manage_drafts'],
  223. 'file' => 'Drafts.php',
  224. 'function' => 'ModifyDraftSettings',
  225. 'icon' => 'logs.png',
  226. 'permission' => array('admin_forum'),
  227. 'enabled' => in_array('dr', $context['admin_features']),
  228. ),
  229. 'managecalendar' => array(
  230. 'label' => $txt['manage_calendar'],
  231. 'file' => 'ManageCalendar.php',
  232. 'function' => 'ManageCalendar',
  233. 'icon' => 'calendar.png',
  234. 'permission' => array('admin_forum'),
  235. 'enabled' => in_array('cd', $context['admin_features']),
  236. 'subsections' => array(
  237. 'holidays' => array($txt['manage_holidays'], 'admin_forum', 'enabled' => !empty($modSettings['cal_enabled'])),
  238. 'settings' => array($txt['calendar_settings'], 'admin_forum'),
  239. ),
  240. ),
  241. 'managesearch' => array(
  242. 'label' => $txt['manage_search'],
  243. 'file' => 'ManageSearch.php',
  244. 'function' => 'ManageSearch',
  245. 'icon' => 'search.png',
  246. 'permission' => array('admin_forum'),
  247. 'subsections' => array(
  248. 'weights' => array($txt['search_weights']),
  249. 'method' => array($txt['search_method']),
  250. 'settings' => array($txt['settings']),
  251. ),
  252. ),
  253. 'smileys' => array(
  254. 'label' => $txt['smileys_manage'],
  255. 'file' => 'ManageSmileys.php',
  256. 'function' => 'ManageSmileys',
  257. 'icon' => 'smiley.png',
  258. 'permission' => array('manage_smileys'),
  259. 'subsections' => array(
  260. 'editsets' => array($txt['smiley_sets']),
  261. 'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])),
  262. 'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])),
  263. 'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])),
  264. 'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])),
  265. 'settings' => array($txt['settings']),
  266. ),
  267. ),
  268. 'manageattachments' => array(
  269. 'label' => $txt['attachments_avatars'],
  270. 'file' => 'ManageAttachments.php',
  271. 'function' => 'ManageAttachments',
  272. 'icon' => 'attachment.png',
  273. 'permission' => array('manage_attachments'),
  274. 'subsections' => array(
  275. 'browse' => array($txt['attachment_manager_browse']),
  276. 'attachments' => array($txt['attachment_manager_settings']),
  277. 'avatars' => array($txt['attachment_manager_avatar_settings']),
  278. 'maintenance' => array($txt['attachment_manager_maintenance']),
  279. ),
  280. ),
  281. ),
  282. ),
  283. 'members' => array(
  284. 'title' => $txt['admin_manage_members'],
  285. 'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'),
  286. 'areas' => array(
  287. 'viewmembers' => array(
  288. 'label' => $txt['admin_users'],
  289. 'file' => 'ManageMembers.php',
  290. 'function' => 'ViewMembers',
  291. 'icon' => 'members.png',
  292. 'permission' => array('moderate_forum'),
  293. 'subsections' => array(
  294. 'all' => array($txt['view_all_members']),
  295. 'search' => array($txt['mlist_search']),
  296. ),
  297. ),
  298. 'membergroups' => array(
  299. 'label' => $txt['admin_groups'],
  300. 'file' => 'ManageMembergroups.php',
  301. 'function' => 'ModifyMembergroups',
  302. 'icon' => 'membergroups.png',
  303. 'permission' => array('manage_membergroups'),
  304. 'subsections' => array(
  305. 'index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'),
  306. 'add' => array($txt['membergroups_new_group'], 'manage_membergroups'),
  307. 'settings' => array($txt['settings'], 'admin_forum'),
  308. ),
  309. ),
  310. 'permissions' => array(
  311. 'label' => $txt['edit_permissions'],
  312. 'file' => 'ManagePermissions.php',
  313. 'function' => 'ModifyPermissions',
  314. 'icon' => 'permissions.png',
  315. 'permission' => array('manage_permissions'),
  316. 'subsections' => array(
  317. 'index' => array($txt['permissions_groups'], 'manage_permissions'),
  318. 'board' => array($txt['permissions_boards'], 'manage_permissions'),
  319. 'profiles' => array($txt['permissions_profiles'], 'manage_permissions'),
  320. 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']),
  321. 'settings' => array($txt['settings'], 'admin_forum'),
  322. ),
  323. ),
  324. 'regcenter' => array(
  325. 'label' => $txt['registration_center'],
  326. 'file' => 'ManageRegistration.php',
  327. 'function' => 'RegCenter',
  328. 'icon' => 'regcenter.png',
  329. 'permission' => array('admin_forum', 'moderate_forum'),
  330. 'subsections' => array(
  331. 'register' => array($txt['admin_browse_register_new'], 'moderate_forum'),
  332. 'agreement' => array($txt['registration_agreement'], 'admin_forum'),
  333. 'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'),
  334. 'settings' => array($txt['settings'], 'admin_forum'),
  335. ),
  336. ),
  337. 'ban' => array(
  338. 'label' => $txt['ban_title'],
  339. 'file' => 'ManageBans.php',
  340. 'function' => 'Ban',
  341. 'icon' => 'ban.png',
  342. 'permission' => 'manage_bans',
  343. 'subsections' => array(
  344. 'list' => array($txt['ban_edit_list']),
  345. 'add' => array($txt['ban_add_new']),
  346. 'browse' => array($txt['ban_trigger_browse']),
  347. 'log' => array($txt['ban_log']),
  348. ),
  349. ),
  350. 'paidsubscribe' => array(
  351. 'label' => $txt['paid_subscriptions'],
  352. 'enabled' => in_array('ps', $context['admin_features']),
  353. 'file' => 'ManagePaid.php',
  354. 'icon' => 'paid.png',
  355. 'function' => 'ManagePaidSubscriptions',
  356. 'permission' => 'admin_forum',
  357. 'subsections' => array(
  358. 'view' => array($txt['paid_subs_view']),
  359. 'settings' => array($txt['settings']),
  360. ),
  361. ),
  362. 'sengines' => array(
  363. 'label' => $txt['search_engines'],
  364. 'enabled' => in_array('sp', $context['admin_features']),
  365. 'file' => 'ManageSearchEngines.php',
  366. 'icon' => 'engines.png',
  367. 'function' => 'SearchEngines',
  368. 'permission' => 'admin_forum',
  369. 'subsections' => array(
  370. 'stats' => array($txt['spider_stats']),
  371. 'logs' => array($txt['spider_logs']),
  372. 'spiders' => array($txt['spiders']),
  373. 'settings' => array($txt['settings']),
  374. ),
  375. ),
  376. ),
  377. ),
  378. 'maintenance' => array(
  379. 'title' => $txt['admin_maintenance'],
  380. 'permission' => array('admin_forum'),
  381. 'areas' => array(
  382. 'maintain' => array(
  383. 'label' => $txt['maintain_title'],
  384. 'file' => 'ManageMaintenance.php',
  385. 'icon' => 'maintain.png',
  386. 'function' => 'ManageMaintenance',
  387. 'subsections' => array(
  388. 'routine' => array($txt['maintain_sub_routine'], 'admin_forum'),
  389. 'database' => array($txt['maintain_sub_database'], 'admin_forum'),
  390. 'members' => array($txt['maintain_sub_members'], 'admin_forum'),
  391. 'topics' => array($txt['maintain_sub_topics'], 'admin_forum'),
  392. ),
  393. ),
  394. 'scheduledtasks' => array(
  395. 'label' => $txt['maintain_tasks'],
  396. 'file' => 'ManageScheduledTasks.php',
  397. 'icon' => 'scheduled.png',
  398. 'function' => 'ManageScheduledTasks',
  399. 'subsections' => array(
  400. 'tasks' => array($txt['maintain_tasks'], 'admin_forum'),
  401. 'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
  402. ),
  403. ),
  404. 'mailqueue' => array(
  405. 'label' => $txt['mailqueue_title'],
  406. 'file' => 'ManageMail.php',
  407. 'function' => 'ManageMail',
  408. 'icon' => 'mail.png',
  409. 'subsections' => array(
  410. 'browse' => array($txt['mailqueue_browse'], 'admin_forum'),
  411. 'settings' => array($txt['mailqueue_settings'], 'admin_forum'),
  412. ),
  413. ),
  414. 'reports' => array(
  415. 'enabled' => in_array('rg', $context['admin_features']),
  416. 'label' => $txt['generate_reports'],
  417. 'file' => 'Reports.php',
  418. 'function' => 'ReportsMain',
  419. 'icon' => 'reports.png',
  420. ),
  421. 'logs' => array(
  422. 'label' => $txt['logs'],
  423. 'function' => 'AdminLogs',
  424. 'icon' => 'logs.png',
  425. 'subsections' => array(
  426. 'errorlog' => array($txt['errlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'),
  427. 'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])),
  428. 'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])),
  429. 'banlog' => array($txt['ban_log'], 'manage_bans'),
  430. 'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => in_array('sp', $context['admin_features'])),
  431. 'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
  432. 'pruning' => array($txt['pruning_title'], 'admin_forum'),
  433. ),
  434. ),
  435. 'repairboards' => array(
  436. 'label' => $txt['admin_repair'],
  437. 'file' => 'RepairBoards.php',
  438. 'function' => 'RepairBoards',
  439. 'select' => 'maintain',
  440. 'hidden' => true,
  441. ),
  442. ),
  443. ),
  444. );
  445. // Any files to include for administration?
  446. if (!empty($modSettings['integrate_admin_include']))
  447. {
  448. $admin_includes = explode(',', $modSettings['integrate_admin_include']);
  449. foreach ($admin_includes as $include)
  450. {
  451. $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
  452. if (file_exists($include))
  453. require_once($include);
  454. }
  455. }
  456. // Let them modify admin areas easily.
  457. call_integration_hook('integrate_admin_areas', array(&$admin_areas));
  458. // Make sure the administrator has a valid session...
  459. validateSession();
  460. // Actually create the menu!
  461. $admin_include_data = createMenu($admin_areas);
  462. unset($admin_areas);
  463. // Nothing valid?
  464. if ($admin_include_data == false)
  465. fatal_lang_error('no_access', false);
  466. // Build the link tree.
  467. $context['linktree'][] = array(
  468. 'url' => $scripturl . '?action=admin',
  469. 'name' => $txt['admin_center'],
  470. );
  471. if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
  472. $context['linktree'][] = array(
  473. 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  474. 'name' => $admin_include_data['label'],
  475. );
  476. if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
  477. $context['linktree'][] = array(
  478. 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  479. 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
  480. );
  481. // Make a note of the Unique ID for this menu.
  482. $context['admin_menu_id'] = $context['max_menu_id'];
  483. $context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id'];
  484. // Where in the admin are we?
  485. $context['admin_area'] = $admin_include_data['current_area'];
  486. // Now - finally - call the right place!
  487. if (isset($admin_include_data['file']))
  488. require_once($sourcedir . '/' . $admin_include_data['file']);
  489. $admin_include_data['function']();
  490. }
  491. /**
  492. * The main administration section.
  493. * It prepares all the data necessary for the administration front page.
  494. * It uses the Admin template along with the admin sub template.
  495. * It requires the moderate_forum, manage_membergroups, manage_bans,
  496. * admin_forum, manage_permissions, manage_attachments, manage_smileys,
  497. * manage_boards, edit_news, or send_mail permission.
  498. * It uses the index administrative area.
  499. * It can be found by going to ?action=admin.
  500. */
  501. function AdminHome()
  502. {
  503. global $sourcedir, $forum_version, $txt, $scripturl, $context, $user_info, $boardurl, $modSettings, $smcFunc;
  504. // You have to be able to do at least one of the below to see this page.
  505. isAllowedTo(array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'));
  506. // Find all of this forum's administrators...
  507. require_once($sourcedir . '/Subs-Membergroups.php');
  508. if (listMembergroupMembers_Href($context['administrators'], 1, 32) && allowedTo('manage_membergroups'))
  509. {
  510. // Add a 'more'-link if there are more than 32.
  511. $context['more_admins_link'] = '<a href="' . $scripturl . '?action=moderate;area=viewgroups;sa=members;group=1">' . $txt['more'] . '</a>';
  512. }
  513. // Load the credits stuff.
  514. require_once($sourcedir . '/Who.php');
  515. Credits(true);
  516. // This makes it easier to get the latest news with your time format.
  517. $context['time_format'] = urlencode($user_info['time_format']);
  518. $context['forum_version'] = $forum_version;
  519. // Get a list of current server versions.
  520. require_once($sourcedir . '/Subs-Admin.php');
  521. $checkFor = array(
  522. 'gd',
  523. 'imagick',
  524. 'db_server',
  525. 'mmcache',
  526. 'eaccelerator',
  527. 'phpa',
  528. 'apc',
  529. 'memcache',
  530. 'xcache',
  531. 'php',
  532. 'server',
  533. );
  534. $context['current_versions'] = getServerVersions($checkFor);
  535. $context['can_admin'] = allowedTo('admin_forum');
  536. $context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
  537. $context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
  538. // The format of this array is: permission, action, title, description, icon.
  539. $quick_admin_tasks = array(
  540. array('', 'credits', 'support_credits_title', 'support_credits_info', 'support_and_credits.png'),
  541. array('admin_forum', 'featuresettings', 'modSettings_title', 'modSettings_info', 'features_and_options.png'),
  542. array('admin_forum', 'maintain', 'maintain_title', 'maintain_info', 'forum_maintenance.png'),
  543. array('manage_permissions', 'permissions', 'edit_permissions', 'edit_permissions_info', 'permissions_lg.png'),
  544. array('admin_forum', 'theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id'], 'theme_admin', 'theme_admin_info', 'themes_and_layout.png'),
  545. array('admin_forum', 'packages', 'package', 'package_info', 'packages_lg.png'),
  546. array('manage_smileys', 'smileys', 'smileys_manage', 'smileys_manage_info', 'smilies_and_messageicons.png'),
  547. array('moderate_forum', 'viewmembers', 'admin_users', 'member_center_info', 'members_lg.png'),
  548. );
  549. $context['quick_admin_tasks'] = array();
  550. foreach ($quick_admin_tasks as $task)
  551. {
  552. if (!empty($task[0]) && !allowedTo($task[0]))
  553. continue;
  554. $context['quick_admin_tasks'][] = array(
  555. 'href' => $scripturl . '?action=admin;area=' . $task[1],
  556. 'link' => '<a href="' . $scripturl . '?action=admin;area=' . $task[1] . '">' . $txt[$task[2]] . '</a>',
  557. 'title' => $txt[$task[2]],
  558. 'description' => $txt[$task[3]],
  559. 'icon' => $task[4],
  560. 'is_last' => false
  561. );
  562. }
  563. if (count($context['quick_admin_tasks']) % 2 == 1)
  564. {
  565. $context['quick_admin_tasks'][] = array(
  566. 'href' => '',
  567. 'link' => '',
  568. 'title' => '',
  569. 'description' => '',
  570. 'is_last' => true
  571. );
  572. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
  573. }
  574. elseif (count($context['quick_admin_tasks']) != 0)
  575. {
  576. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 1]['is_last'] = true;
  577. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
  578. }
  579. // Lastly, fill in the blanks in the support resources paragraphs.
  580. $txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
  581. 'http://wiki.simplemachines.org/',
  582. 'http://wiki.simplemachines.org/smf/features2',
  583. 'http://wiki.simplemachines.org/smf/options2',
  584. 'http://wiki.simplemachines.org/smf/themes2',
  585. 'http://wiki.simplemachines.org/smf/packages2'
  586. );
  587. $txt['support_resources_p2'] = sprintf($txt['support_resources_p2'],
  588. 'http://www.simplemachines.org/community/',
  589. 'http://www.simplemachines.org/redirect/english_support',
  590. 'http://www.simplemachines.org/redirect/international_support_boards',
  591. 'http://www.simplemachines.org/redirect/smf_support',
  592. 'http://www.simplemachines.org/redirect/customize_support'
  593. );
  594. }
  595. /**
  596. * Get one of the admin information files from Simple Machines.
  597. */
  598. function DisplayAdminFile()
  599. {
  600. global $context, $modSettings, $smcFunc;
  601. setMemoryLimit('32M');
  602. if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
  603. fatal_lang_error('no_access', false);
  604. $request = $smcFunc['db_query']('', '
  605. SELECT data, filetype
  606. FROM {db_prefix}admin_info_files
  607. WHERE filename = {string:current_filename}
  608. LIMIT 1',
  609. array(
  610. 'current_filename' => $_REQUEST['filename'],
  611. )
  612. );
  613. if ($smcFunc['db_num_rows']($request) == 0)
  614. fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']));
  615. list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
  616. $smcFunc['db_free_result']($request);
  617. // @todo Temp
  618. // Figure out if sesc is still being used.
  619. if (strpos($file_data, ';sesc=') !== false)
  620. $file_data = '
  621. if (!(\'smfForum_sessionvar\' in window))
  622. window.smfForum_sessionvar = \'sesc\';
  623. ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
  624. $context['template_layers'] = array();
  625. // Lets make sure we aren't going to output anything nasty.
  626. @ob_end_clean();
  627. if (!empty($modSettings['enableCompressedOutput']))
  628. @ob_start('ob_gzhandler');
  629. else
  630. @ob_start();
  631. // Make sure they know what type of file we are.
  632. header('Content-Type: ' . $filetype);
  633. echo $file_data;
  634. obExit(false);
  635. }
  636. /**
  637. * This function allocates out all the search stuff.
  638. */
  639. function AdminSearch()
  640. {
  641. global $txt, $context, $smcFunc, $sourcedir;
  642. isAllowedTo('admin_forum');
  643. // What can we search for?
  644. $subactions = array(
  645. 'internal' => 'AdminSearchInternal',
  646. 'online' => 'AdminSearchOM',
  647. 'member' => 'AdminSearchMember',
  648. );
  649. $context['search_type'] = !isset($_REQUEST['search_type']) || !isset($subactions[$_REQUEST['search_type']]) ? 'internal' : $_REQUEST['search_type'];
  650. $context['search_term'] = isset($_REQUEST['search_term']) ? $smcFunc['htmlspecialchars']($_REQUEST['search_term'], ENT_QUOTES) : '';
  651. $context['sub_template'] = 'admin_search_results';
  652. $context['page_title'] = $txt['admin_search_results'];
  653. // Keep track of what the admin wants.
  654. if (empty($context['admin_preferences']['sb']) || $context['admin_preferences']['sb'] != $context['search_type'])
  655. {
  656. $context['admin_preferences']['sb'] = $context['search_type'];
  657. // Update the preferences.
  658. require_once($sourcedir . '/Subs-Admin.php');
  659. updateAdminPreferences();
  660. }
  661. if (trim($context['search_term']) == '')
  662. $context['search_results'] = array();
  663. else
  664. $subactions[$context['search_type']]();
  665. }
  666. /**
  667. * A complicated but relatively quick internal search.
  668. */
  669. function AdminSearchInternal()
  670. {
  671. global $context, $txt, $helptxt, $scripturl, $sourcedir;
  672. // Try to get some more memory.
  673. setMemoryLimit('128M');
  674. // Load a lot of language files.
  675. $language_files = array(
  676. 'Help', 'ManageMail', 'ManageSettings', 'ManageCalendar', 'ManageBoards', 'ManagePaid', 'ManagePermissions', 'Search',
  677. 'Login', 'ManageSmileys',
  678. );
  679. // All the files we need to include.
  680. $include_files = array(
  681. 'ManageSettings', 'ManageBoards', 'ManageNews', 'ManageAttachments', 'ManageCalendar', 'ManageMail', 'ManagePaid', 'ManagePermissions',
  682. 'ManagePosts', 'ManageRegistration', 'ManageSearch', 'ManageSearchEngines', 'ManageServer', 'ManageSmileys', 'ManageLanguages',
  683. );
  684. // This is a special array of functions that contain setting data - we query all these to simply pull all setting bits!
  685. $settings_search = array(
  686. array('ModifyCoreFeatures', 'area=corefeatures'),
  687. array('ModifyBasicSettings', 'area=featuresettings;sa=basic'),
  688. array('ModifyLayoutSettings', 'area=featuresettings;sa=layout'),
  689. array('ModifyKarmaSettings', 'area=featuresettings;sa=karma'),
  690. array('ModifySignatureSettings', 'area=featuresettings;sa=sig'),
  691. array('ModifyGeneralSecuritySettings', 'area=securitysettings;sa=general'),
  692. array('ModifySpamSettings', 'area=securitysettings;sa=spam'),
  693. array('ModifyModerationSettings', 'area=securitysettings;sa=moderation'),
  694. array('ModifyGeneralModSettings', 'area=modsettings;sa=general'),
  695. // Mod authors if you want to be "real freaking good" then add any setting pages for your mod BELOW this line!
  696. array('ManageAttachmentSettings', 'area=manageattachments;sa=attachments'),
  697. array('ManageAvatarSettings', 'area=manageattachments;sa=avatars'),
  698. array('ModifyCalendarSettings', 'area=managecalendar;sa=settings'),
  699. array('EditBoardSettings', 'area=manageboards;sa=settings'),
  700. array('ModifyMailSettings', 'area=mailqueue;sa=settings'),
  701. array('ModifyNewsSettings', 'area=news;sa=settings'),
  702. array('GeneralPermissionSettings', 'area=permissions;sa=settings'),
  703. array('ModifyPostSettings', 'area=postsettings;sa=posts'),
  704. array('ModifyBBCSettings', 'area=postsettings;sa=bbc'),
  705. array('ModifyTopicSettings', 'area=postsettings;sa=topics'),
  706. array('EditSearchSettings', 'area=managesearch;sa=settings'),
  707. array('EditSmileySettings', 'area=smileys;sa=settings'),
  708. array('ModifyGeneralSettings', 'area=serversettings;sa=general'),
  709. array('ModifyDatabaseSettings', 'area=serversettings;sa=database'),
  710. array('ModifyCookieSettings', 'area=serversettings;sa=cookie'),
  711. array('ModifyCacheSettings', 'area=serversettings;sa=cache'),
  712. array('ModifyLanguageSettings', 'area=languages;sa=settings'),
  713. array('ModifyRegistrationSettings', 'area=regcenter;sa=settings'),
  714. array('ManageSearchEngineSettings', 'area=sengines;sa=settings'),
  715. array('ModifySubscriptionSettings', 'area=paidsubscribe;sa=settings'),
  716. array('ModifyPruningSettings', 'area=logs;sa=pruning'),
  717. );
  718. call_integration_hook('integrate_admin_search', array(&$language_files, &$include_files, &$settings_search));
  719. loadLanguage(implode('+', $language_files));
  720. foreach ($include_files as $file)
  721. require_once($sourcedir . '/' . $file . '.php');
  722. /* This is the huge array that defines everything... it's a huge array of items formatted as follows:
  723. 0 = Language index (Can be array of indexes) to search through for this setting.
  724. 1 = URL for this indexes page.
  725. 2 = Help index for help associated with this item (If different from 0)
  726. */
  727. $search_data = array(
  728. // All the major sections of the forum.
  729. 'sections' => array(
  730. ),
  731. 'settings' => array(
  732. array('COPPA', 'area=regcenter;sa=settings'),
  733. array('CAPTCHA', 'area=securitysettings;sa=spam'),
  734. ),
  735. );
  736. // Go through the admin menu structure trying to find suitably named areas!
  737. foreach ($context[$context['admin_menu_name']]['sections'] as $section)
  738. {
  739. foreach ($section['areas'] as $menu_key => $menu_item)
  740. {
  741. $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
  742. if (!empty($menu_item['subsections']))
  743. foreach ($menu_item['subsections'] as $key => $sublabel)
  744. {
  745. if (isset($sublabel['label']))
  746. $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
  747. }
  748. }
  749. }
  750. foreach ($settings_search as $setting_area)
  751. {
  752. // Get a list of their variables.
  753. $config_vars = $setting_area[0](true);
  754. foreach ($config_vars as $var)
  755. if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch')))
  756. $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]);
  757. }
  758. $context['page_title'] = $txt['admin_search_results'];
  759. $context['search_results'] = array();
  760. $search_term = strtolower(un_htmlspecialchars($context['search_term']));
  761. // Go through all the search data trying to find this text!
  762. foreach ($search_data as $section => $data)
  763. {
  764. foreach ($data as $item)
  765. {
  766. $found = false;
  767. if (!is_array($item[0]))
  768. $item[0] = array($item[0]);
  769. foreach ($item[0] as $term)
  770. {
  771. if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false))
  772. {
  773. $found = $term;
  774. break;
  775. }
  776. }
  777. if ($found)
  778. {
  779. // Format the name - and remove any descriptions the entry may have.
  780. $name = isset($txt[$found]) ? $txt[$found] : (isset($txt['setting_' . $found]) ? $txt['setting_' . $found] : $found);
  781. $name = preg_replace('~<(?:div|span)\sclass="smalltext">.+?</(?:div|span)>~', '', $name);
  782. $context['search_results'][] = array(
  783. 'url' => (substr($item[1], 0, 4) == 'area' ? $scripturl . '?action=admin;' . $item[1] : $item[1]) . ';' . $context['session_var'] . '=' . $context['session_id'] . ((substr($item[1], 0, 4) == 'area' && $section == 'settings' ? '#' . $item[0][0] : '')),
  784. 'name' => $name,
  785. 'type' => $section,
  786. 'help' => shorten_subject(isset($item[2]) ? strip_tags($helptxt[$item[2]]) : (isset($helptxt[$found]) ? strip_tags($helptxt[$found]) : ''), 255),
  787. );
  788. }
  789. }
  790. }
  791. }
  792. /**
  793. * All this does is pass through to manage members.
  794. */
  795. function AdminSearchMember()
  796. {
  797. global $context, $sourcedir;
  798. require_once($sourcedir . '/ManageMembers.php');
  799. $_REQUEST['sa'] = 'query';
  800. $_POST['membername'] = un_htmlspecialchars($context['search_term']);
  801. $_POST['types'] = '';
  802. ViewMembers();
  803. }
  804. /**
  805. * This file allows the user to search the SM online manual for a little of help.
  806. */
  807. function AdminSearchOM()
  808. {
  809. global $context, $sourcedir;
  810. $context['doc_apiurl'] = 'http://wiki.simplemachines.org/api.php';
  811. $context['doc_scripturl'] = 'http://wiki.simplemachines.org/smf/';
  812. // Set all the parameters search might expect.
  813. $postVars = explode(' ', $context['search_term']);
  814. // Encode the search data.
  815. foreach ($postVars as $k => $v)
  816. $postVars[$k] = urlencode($v);
  817. // This is what we will send.
  818. $postVars = implode('+', $postVars);
  819. // Get the results from the doc site.
  820. require_once($sourcedir . '/Subs-Package.php');
  821. // Demo URL:
  822. // http://wiki.simplemachines.org/api.php?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=template+eval
  823. $search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars);
  824. // If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
  825. if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?>\s*(<api>.+?</api>)~is', $search_results, $matches) != true)
  826. fatal_lang_error('cannot_connect_doc_site');
  827. $search_results = $matches[1];
  828. // Otherwise we simply walk through the XML and stick it in context for display.
  829. $context['search_results'] = array();
  830. require_once($sourcedir . '/Class-Package.php');
  831. // Get the results loaded into an array for processing!
  832. $results = new xmlArray($search_results, false);
  833. // Move through the api layer.
  834. if (!$results->exists('api'))
  835. fatal_lang_error('cannot_connect_doc_site');
  836. // Are there actually some results?
  837. if ($results->exists('api/query/search/p'))
  838. {
  839. $relevance = 0;
  840. foreach ($results->set('api/query/search/p') as $result)
  841. {
  842. $context['search_results'][$result->fetch('@title')] = array(
  843. 'title' => $result->fetch('@title'),
  844. 'relevance' => $relevance++,
  845. 'snippet' => str_replace('class=\'searchmatch\'', 'class="highlight"', un_htmlspecialchars($result->fetch('@snippet'))),
  846. );
  847. }
  848. }
  849. }
  850. /**
  851. * This function decides which log to load.
  852. */
  853. function AdminLogs()
  854. {
  855. global $sourcedir, $context, $txt, $scripturl;
  856. // These are the logs they can load.
  857. $log_functions = array(
  858. 'errorlog' => array('ManageErrors.php', 'ViewErrorLog'),
  859. 'adminlog' => array('Modlog.php', 'ViewModlog'),
  860. 'modlog' => array('Modlog.php', 'ViewModlog', 'disabled' => !in_array('ml', $context['admin_features'])),
  861. 'banlog' => array('ManageBans.php', 'BanLog'),
  862. 'spiderlog' => array('ManageSearchEngines.php', 'SpiderLogs'),
  863. 'tasklog' => array('ManageScheduledTasks.php', 'TaskLog'),
  864. 'pruning' => array('ManageSettings.php', 'ModifyPruningSettings'),
  865. );
  866. call_integration_hook('integrate_manage_logs', array(&$log_functions));
  867. $sub_action = isset($_REQUEST['sa']) && isset($log_functions[$_REQUEST['sa']]) && empty($log_functions[$_REQUEST['sa']]['disabled']) ? $_REQUEST['sa'] : 'errorlog';
  868. // If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
  869. if (!isset($_REQUEST['sa']))
  870. $_REQUEST['desc'] = true;
  871. // Setup some tab stuff.
  872. $context[$context['admin_menu_name']]['tab_data'] = array(
  873. 'title' => $txt['logs'],
  874. 'help' => '',
  875. 'description' => $txt['maintain_info'],
  876. 'tabs' => array(
  877. 'errorlog' => array(
  878. 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
  879. 'description' => sprintf($txt['errlog_desc'], $txt['remove']),
  880. ),
  881. 'adminlog' => array(
  882. 'description' => $txt['admin_log_desc'],
  883. ),
  884. 'modlog' => array(
  885. 'description' => $txt['moderation_log_desc'],
  886. ),
  887. 'banlog' => array(
  888. 'description' => $txt['ban_log_description'],
  889. ),
  890. 'spiderlog' => array(
  891. 'description' => $txt['spider_log_desc'],
  892. ),
  893. 'tasklog' => array(
  894. 'description' => $txt['scheduled_log_desc'],
  895. ),
  896. 'pruning' => array(
  897. 'description' => $txt['pruning_log_desc'],
  898. ),
  899. ),
  900. );
  901. require_once($sourcedir . '/' . $log_functions[$sub_action][0]);
  902. $log_functions[$sub_action][1]();
  903. }
  904. /**
  905. * This ends a admin session, requiring authentication to access the ACP again.
  906. */
  907. function AdminEndSession()
  908. {
  909. // This is so easy!
  910. unset($_SESSION['admin_time']);
  911. // Clean any admin tokens as well.
  912. foreach ($_SESSION['token'] as $key => $token)
  913. if (strpos($key, '-admin') !== false)
  914. unset($_SESSION['token'][$key]);
  915. redirectexit('action=admin');
  916. }
  917. ?>