Admin.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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['forum_version'] = $forum_version;
  500. // Get a list of current server versions.
  501. require_once($sourcedir . '/Subs-Admin.php');
  502. $checkFor = array(
  503. 'gd',
  504. 'db_server',
  505. 'mmcache',
  506. 'eaccelerator',
  507. 'phpa',
  508. 'apc',
  509. 'memcache',
  510. 'xcache',
  511. 'php',
  512. 'server',
  513. );
  514. $context['current_versions'] = getServerVersions($checkFor);
  515. $context['can_admin'] = allowedTo('admin_forum');
  516. $context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
  517. $context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
  518. // The format of this array is: permission, action, title, description, icon.
  519. $quick_admin_tasks = array(
  520. array('', 'credits', 'support_credits_title', 'support_credits_info', 'support_and_credits.png'),
  521. array('admin_forum', 'featuresettings', 'modSettings_title', 'modSettings_info', 'features_and_options.png'),
  522. array('admin_forum', 'maintain', 'maintain_title', 'maintain_info', 'forum_maintenance.png'),
  523. array('manage_permissions', 'permissions', 'edit_permissions', 'edit_permissions_info', 'permissions.png'),
  524. array('admin_forum', 'theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id'], 'theme_admin', 'theme_admin_info', 'themes_and_layout.png'),
  525. array('admin_forum', 'packages', 'package', 'package_info', 'packages.png'),
  526. array('manage_smileys', 'smileys', 'smileys_manage', 'smileys_manage_info', 'smilies_and_messageicons.png'),
  527. array('moderate_forum', 'viewmembers', 'admin_users', 'member_center_info', 'members.png'),
  528. );
  529. $context['quick_admin_tasks'] = array();
  530. foreach ($quick_admin_tasks as $task)
  531. {
  532. if (!empty($task[0]) && !allowedTo($task[0]))
  533. continue;
  534. $context['quick_admin_tasks'][] = array(
  535. 'href' => $scripturl . '?action=admin;area=' . $task[1],
  536. 'link' => '<a href="' . $scripturl . '?action=admin;area=' . $task[1] . '">' . $txt[$task[2]] . '</a>',
  537. 'title' => $txt[$task[2]],
  538. 'description' => $txt[$task[3]],
  539. 'icon' => $task[4],
  540. 'is_last' => false
  541. );
  542. }
  543. if (count($context['quick_admin_tasks']) % 2 == 1)
  544. {
  545. $context['quick_admin_tasks'][] = array(
  546. 'href' => '',
  547. 'link' => '',
  548. 'title' => '',
  549. 'description' => '',
  550. 'is_last' => true
  551. );
  552. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
  553. }
  554. elseif (count($context['quick_admin_tasks']) != 0)
  555. {
  556. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 1]['is_last'] = true;
  557. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
  558. }
  559. // Lastly, fill in the blanks in the support resources paragraphs.
  560. $txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
  561. 'http://wiki.simplemachines.org/',
  562. 'http://wiki.simplemachines.org/smf/features2',
  563. 'http://wiki.simplemachines.org/smf/options2',
  564. 'http://wiki.simplemachines.org/smf/themes2',
  565. 'http://wiki.simplemachines.org/smf/packages2'
  566. );
  567. $txt['support_resources_p2'] = sprintf($txt['support_resources_p2'],
  568. 'http://www.simplemachines.org/community/',
  569. 'http://www.simplemachines.org/redirect/english_support',
  570. 'http://www.simplemachines.org/redirect/international_support_boards',
  571. 'http://www.simplemachines.org/redirect/smf_support',
  572. 'http://www.simplemachines.org/redirect/customize_support'
  573. );
  574. }
  575. /**
  576. * Get one of the admin information files from Simple Machines.
  577. */
  578. function DisplayAdminFile()
  579. {
  580. global $context, $modSettings, $smcFunc;
  581. @ini_set('memory_limit', '32M');
  582. if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
  583. fatal_lang_error('no_access', false);
  584. $request = $smcFunc['db_query']('', '
  585. SELECT data, filetype
  586. FROM {db_prefix}admin_info_files
  587. WHERE filename = {string:current_filename}
  588. LIMIT 1',
  589. array(
  590. 'current_filename' => $_REQUEST['filename'],
  591. )
  592. );
  593. if ($smcFunc['db_num_rows']($request) == 0)
  594. fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']));
  595. list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
  596. $smcFunc['db_free_result']($request);
  597. // @todo Temp
  598. // Figure out if sesc is still being used.
  599. if (strpos($file_data, ';sesc=') !== false)
  600. $file_data = '
  601. if (!(\'smfForum_sessionvar\' in window))
  602. window.smfForum_sessionvar = \'sesc\';
  603. ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
  604. $context['template_layers'] = array();
  605. // Lets make sure we aren't going to output anything nasty.
  606. @ob_end_clean();
  607. if (!empty($modSettings['enableCompressedOutput']))
  608. @ob_start('ob_gzhandler');
  609. else
  610. @ob_start();
  611. // Make sure they know what type of file we are.
  612. header('Content-Type: ' . $filetype);
  613. echo $file_data;
  614. obExit(false);
  615. }
  616. /**
  617. * This function allocates out all the search stuff.
  618. */
  619. function AdminSearch()
  620. {
  621. global $txt, $context, $smcFunc, $sourcedir;
  622. isAllowedTo('admin_forum');
  623. // What can we search for?
  624. $subactions = array(
  625. 'internal' => 'AdminSearchInternal',
  626. 'online' => 'AdminSearchOM',
  627. 'member' => 'AdminSearchMember',
  628. );
  629. $context['search_type'] = !isset($_REQUEST['search_type']) || !isset($subactions[$_REQUEST['search_type']]) ? 'internal' : $_REQUEST['search_type'];
  630. $context['search_term'] = isset($_REQUEST['search_term']) ? $smcFunc['htmlspecialchars']($_REQUEST['search_term'], ENT_QUOTES) : '';
  631. $context['sub_template'] = 'admin_search_results';
  632. $context['page_title'] = $txt['admin_search_results'];
  633. // Keep track of what the admin wants.
  634. if (empty($context['admin_preferences']['sb']) || $context['admin_preferences']['sb'] != $context['search_type'])
  635. {
  636. $context['admin_preferences']['sb'] = $context['search_type'];
  637. // Update the preferences.
  638. require_once($sourcedir . '/Subs-Admin.php');
  639. updateAdminPreferences();
  640. }
  641. if (trim($context['search_term']) == '')
  642. $context['search_results'] = array();
  643. else
  644. $subactions[$context['search_type']]();
  645. }
  646. /**
  647. * A complicated but relatively quick internal search.
  648. */
  649. function AdminSearchInternal()
  650. {
  651. global $context, $txt, $helptxt, $scripturl, $sourcedir;
  652. // Try to get some more memory.
  653. @ini_set('memory_limit', '128M');
  654. // Load a lot of language files.
  655. $language_files = array(
  656. 'Help', 'ManageMail', 'ManageSettings', 'ManageCalendar', 'ManageBoards', 'ManagePaid', 'ManagePermissions', 'Search',
  657. 'Login', 'ManageSmileys',
  658. );
  659. loadLanguage(implode('+', $language_files));
  660. // All the files we need to include.
  661. $include_files = array(
  662. 'ManageSettings', 'ManageBoards', 'ManageNews', 'ManageAttachments', 'ManageCalendar', 'ManageMail', 'ManagePaid', 'ManagePermissions',
  663. 'ManagePosts', 'ManageRegistration', 'ManageSearch', 'ManageSearchEngines', 'ManageServer', 'ManageSmileys', 'ManageLanguages',
  664. );
  665. // @todo add hook to add more include_files here
  666. foreach ($include_files as $file)
  667. require_once($sourcedir . '/' . $file . '.php');
  668. /* This is the huge array that defines everything... it's a huge array of items formatted as follows:
  669. 0 = Language index (Can be array of indexes) to search through for this setting.
  670. 1 = URL for this indexes page.
  671. 2 = Help index for help associated with this item (If different from 0)
  672. */
  673. $search_data = array(
  674. // All the major sections of the forum.
  675. 'sections' => array(
  676. ),
  677. 'settings' => array(
  678. array('COPPA', 'area=regcenter;sa=settings'),
  679. array('CAPTCHA', 'area=securitysettings;sa=spam'),
  680. ),
  681. );
  682. // Go through the admin menu structure trying to find suitably named areas!
  683. foreach ($context[$context['admin_menu_name']]['sections'] as $section)
  684. {
  685. foreach ($section['areas'] as $menu_key => $menu_item)
  686. {
  687. $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
  688. if (!empty($menu_item['subsections']))
  689. foreach ($menu_item['subsections'] as $key => $sublabel)
  690. {
  691. if (isset($sublabel['label']))
  692. $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
  693. }
  694. }
  695. }
  696. // This is a special array of functions that contain setting data - we query all these to simply pull all setting bits!
  697. $settings_search = array(
  698. array('ModifyCoreFeatures', 'area=corefeatures'),
  699. array('ModifyBasicSettings', 'area=featuresettings;sa=basic'),
  700. array('ModifyLayoutSettings', 'area=featuresettings;sa=layout'),
  701. array('ModifyKarmaSettings', 'area=featuresettings;sa=karma'),
  702. array('ModifySignatureSettings', 'area=featuresettings;sa=sig'),
  703. array('ModifyGeneralSecuritySettings', 'area=securitysettings;sa=general'),
  704. array('ModifySpamSettings', 'area=securitysettings;sa=spam'),
  705. array('ModifyModerationSettings', 'area=securitysettings;sa=moderation'),
  706. array('ModifyGeneralModSettings', 'area=modsettings;sa=general'),
  707. // Mod authors if you want to be "real freaking good" then add any setting pages for your mod BELOW this line!
  708. array('ManageAttachmentSettings', 'area=manageattachments;sa=attachments'),
  709. array('ManageAvatarSettings', 'area=manageattachments;sa=avatars'),
  710. array('ModifyCalendarSettings', 'area=managecalendar;sa=settings'),
  711. array('EditBoardSettings', 'area=manageboards;sa=settings'),
  712. array('ModifyMailSettings', 'area=mailqueue;sa=settings'),
  713. array('ModifyNewsSettings', 'area=news;sa=settings'),
  714. array('GeneralPermissionSettings', 'area=permissions;sa=settings'),
  715. array('ModifyPostSettings', 'area=postsettings;sa=posts'),
  716. array('ModifyBBCSettings', 'area=postsettings;sa=bbc'),
  717. array('ModifyTopicSettings', 'area=postsettings;sa=topics'),
  718. array('EditSearchSettings', 'area=managesearch;sa=settings'),
  719. array('EditSmileySettings', 'area=smileys;sa=settings'),
  720. array('ModifyGeneralSettings', 'area=serversettings;sa=general'),
  721. array('ModifyDatabaseSettings', 'area=serversettings;sa=database'),
  722. array('ModifyCookieSettings', 'area=serversettings;sa=cookie'),
  723. array('ModifyCacheSettings', 'area=serversettings;sa=cache'),
  724. array('ModifyLanguageSettings', 'area=languages;sa=settings'),
  725. array('ModifyRegistrationSettings', 'area=regcenter;sa=settings'),
  726. array('ManageSearchEngineSettings', 'area=sengines;sa=settings'),
  727. array('ModifySubscriptionSettings', 'area=paidsubscribe;sa=settings'),
  728. array('ModifyPruningSettings', 'area=logs;sa=pruning'),
  729. );
  730. // @todo add hook to add more $settings search
  731. foreach ($settings_search as $setting_area)
  732. {
  733. // Get a list of their variables.
  734. $config_vars = $setting_area[0](true);
  735. foreach ($config_vars as $var)
  736. if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch')))
  737. $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]);
  738. }
  739. $context['page_title'] = $txt['admin_search_results'];
  740. $context['search_results'] = array();
  741. $search_term = strtolower($context['search_term']);
  742. // Go through all the search data trying to find this text!
  743. foreach ($search_data as $section => $data)
  744. {
  745. foreach ($data as $item)
  746. {
  747. $found = false;
  748. if (!is_array($item[0]))
  749. $item[0] = array($item[0]);
  750. foreach ($item[0] as $term)
  751. {
  752. 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))
  753. {
  754. $found = $term;
  755. break;
  756. }
  757. }
  758. if ($found)
  759. {
  760. // Format the name - and remove any descriptions the entry may have.
  761. $name = isset($txt[$found]) ? $txt[$found] : (isset($txt['setting_' . $found]) ? $txt['setting_' . $found] : $found);
  762. $name = preg_replace('~<(?:div|span)\sclass="smalltext">.+?</(?:div|span)>~', '', $name);
  763. $context['search_results'][] = array(
  764. '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] : '')),
  765. 'name' => $name,
  766. 'type' => $section,
  767. 'help' => shorten_subject(isset($item[2]) ? strip_tags($helptxt[$item[2]]) : (isset($helptxt[$found]) ? strip_tags($helptxt[$found]) : ''), 255),
  768. );
  769. }
  770. }
  771. }
  772. }
  773. /**
  774. * All this does is pass through to manage members.
  775. */
  776. function AdminSearchMember()
  777. {
  778. global $context, $sourcedir;
  779. require_once($sourcedir . '/ManageMembers.php');
  780. $_REQUEST['sa'] = 'query';
  781. $_POST['membername'] = $context['search_term'];
  782. ViewMembers();
  783. }
  784. /**
  785. * This file allows the user to search the SM online manual for a little of help.
  786. * @todo wiki search
  787. */
  788. function AdminSearchOM()
  789. {
  790. global $context, $sourcedir;
  791. $docsURL = 'docs.simplemachines.org';
  792. $context['doc_scripturl'] = 'http://docs.simplemachines.org/index.php';
  793. // Set all the parameters search might expect.
  794. $postVars = array(
  795. 'search' => $context['search_term'],
  796. );
  797. // Encode the search data.
  798. foreach ($postVars as $k => $v)
  799. $postVars[$k] = urlencode($k) . '=' . urlencode($v);
  800. // This is what we will send.
  801. $postVars = implode('&', $postVars);
  802. // Get the results from the doc site.
  803. require_once($sourcedir . '/Subs-Package.php');
  804. $search_results = fetch_web_data($context['doc_scripturl'] . '?action=search2&xml', $postVars);
  805. // If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
  806. if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\sencoding=".+?"\?' . '>\s*(<smf>.+?</smf>)~is', $search_results, $matches) != true)
  807. fatal_lang_error('cannot_connect_doc_site');
  808. $search_results = $matches[1];
  809. // Otherwise we simply walk through the XML and stick it in context for display.
  810. $context['search_results'] = array();
  811. require_once($sourcedir . '/Class-Package.php');
  812. // Get the results loaded into an array for processing!
  813. $results = new xmlArray($search_results, false);
  814. // Move through the smf layer.
  815. if (!$results->exists('smf'))
  816. fatal_lang_error('cannot_connect_doc_site');
  817. $results = $results->path('smf[0]');
  818. // Are there actually some results?
  819. if (!$results->exists('noresults') && !$results->exists('results'))
  820. fatal_lang_error('cannot_connect_doc_site');
  821. elseif ($results->exists('results'))
  822. {
  823. foreach ($results->set('results/result') as $result)
  824. {
  825. if (!$result->exists('messages'))
  826. continue;
  827. $context['search_results'][$result->fetch('id')] = array(
  828. 'topic_id' => $result->fetch('id'),
  829. 'relevance' => $result->fetch('relevance'),
  830. 'board' => array(
  831. 'id' => $result->fetch('board/id'),
  832. 'name' => $result->fetch('board/name'),
  833. 'href' => $result->fetch('board/href'),
  834. ),
  835. 'category' => array(
  836. 'id' => $result->fetch('category/id'),
  837. 'name' => $result->fetch('category/name'),
  838. 'href' => $result->fetch('category/href'),
  839. ),
  840. 'messages' => array(),
  841. );
  842. // Add the messages.
  843. foreach ($result->set('messages/message') as $message)
  844. $context['search_results'][$result->fetch('id')]['messages'][] = array(
  845. 'id' => $message->fetch('id'),
  846. 'subject' => $message->fetch('subject'),
  847. 'body' => $message->fetch('body'),
  848. 'time' => $message->fetch('time'),
  849. 'timestamp' => $message->fetch('timestamp'),
  850. 'start' => $message->fetch('start'),
  851. 'author' => array(
  852. 'id' => $message->fetch('author/id'),
  853. 'name' => $message->fetch('author/name'),
  854. 'href' => $message->fetch('author/href'),
  855. ),
  856. );
  857. }
  858. }
  859. }
  860. /**
  861. * This function decides which log to load.
  862. */
  863. function AdminLogs()
  864. {
  865. global $sourcedir, $context, $txt, $scripturl;
  866. // These are the logs they can load.
  867. $log_functions = array(
  868. 'errorlog' => array('ManageErrors.php', 'ViewErrorLog'),
  869. 'adminlog' => array('Modlog.php', 'ViewModlog'),
  870. 'modlog' => array('Modlog.php', 'ViewModlog'),
  871. 'banlog' => array('ManageBans.php', 'BanLog'),
  872. 'spiderlog' => array('ManageSearchEngines.php', 'SpiderLogs'),
  873. 'tasklog' => array('ManageScheduledTasks.php', 'TaskLog'),
  874. 'pruning' => array('ManageSettings.php', 'ModifyPruningSettings'),
  875. );
  876. call_integration_hook('integrate_manage_logs', array(&$log_functions));
  877. $sub_action = isset($_REQUEST['sa']) && isset($log_functions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'errorlog';
  878. // If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
  879. if (!isset($_REQUEST['sa']))
  880. $_REQUEST['desc'] = true;
  881. // Setup some tab stuff.
  882. $context[$context['admin_menu_name']]['tab_data'] = array(
  883. 'title' => $txt['logs'],
  884. 'help' => '',
  885. 'description' => $txt['maintain_info'],
  886. 'tabs' => array(
  887. 'errorlog' => array(
  888. 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
  889. 'description' => sprintf($txt['errlog_desc'], $txt['remove']),
  890. ),
  891. 'adminlog' => array(
  892. 'description' => $txt['admin_log_desc'],
  893. ),
  894. 'modlog' => array(
  895. 'description' => $txt['moderation_log_desc'],
  896. ),
  897. 'banlog' => array(
  898. 'description' => $txt['ban_log_description'],
  899. ),
  900. 'spiderlog' => array(
  901. 'description' => $txt['spider_log_desc'],
  902. ),
  903. 'tasklog' => array(
  904. 'description' => $txt['scheduled_log_desc'],
  905. ),
  906. 'pruning' => array(
  907. 'description' => $txt['pruning_log_desc'],
  908. ),
  909. ),
  910. );
  911. require_once($sourcedir . '/' . $log_functions[$sub_action][0]);
  912. $log_functions[$sub_action][1]();
  913. }
  914. /**
  915. * This ends a admin session, requiring authentication to access the ACP again.
  916. */
  917. function AdminEndSession()
  918. {
  919. // This is so easy!
  920. unset($_SESSION['admin_time']);
  921. // Clean any admin tokens as well.
  922. foreach ($_SESSION['token'] as $key => $token)
  923. if (strpos($key, '-admin') !== false)
  924. unset($_SESSION['token'][$key]);
  925. redirectexit('?action=admin');
  926. }
  927. ?>