Admin.php 37 KB

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