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. ),
  145. ),
  146. 'current_theme' => array(
  147. 'label' => $txt['theme_current_settings'],
  148. 'file' => 'Themes.php',
  149. 'function' => 'ThemesMain',
  150. 'custom_url' => $scripturl . '?action=admin;area=theme;sa=settings;th=' . $settings['theme_id'],
  151. 'icon' => 'current_theme.gif',
  152. ),
  153. 'theme' => array(
  154. 'label' => $txt['theme_admin'],
  155. 'file' => 'Themes.php',
  156. 'function' => 'ThemesMain',
  157. 'custom_url' => $scripturl . '?action=admin;area=theme;sa=admin',
  158. 'icon' => 'themes.gif',
  159. 'subsections' => array(
  160. 'admin' => array($txt['themeadmin_admin_title']),
  161. 'list' => array($txt['themeadmin_list_title']),
  162. 'reset' => array($txt['themeadmin_reset_title']),
  163. 'edit' => array($txt['themeadmin_edit_title']),
  164. ),
  165. ),
  166. 'modsettings' => array(
  167. 'label' => $txt['admin_modifications'],
  168. 'file' => 'ManageSettings.php',
  169. 'function' => 'ModifyModSettings',
  170. 'icon' => 'modifications.gif',
  171. 'subsections' => array(
  172. 'general' => array($txt['mods_cat_modifications_misc']),
  173. // Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example:
  174. // 'shout' => array($txt['shout']),
  175. // Note the comma!! The setting with automatically appear with the first mod to be added.
  176. ),
  177. ),
  178. ),
  179. ),
  180. 'layout' => array(
  181. 'title' => $txt['layout_controls'],
  182. 'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
  183. 'areas' => array(
  184. 'manageboards' => array(
  185. 'label' => $txt['admin_boards'],
  186. 'file' => 'ManageBoards.php',
  187. 'function' => 'ManageBoards',
  188. 'icon' => 'boards.gif',
  189. 'permission' => array('manage_boards'),
  190. 'subsections' => array(
  191. 'main' => array($txt['boardsEdit']),
  192. 'newcat' => array($txt['mboards_new_cat']),
  193. 'settings' => array($txt['settings'], 'admin_forum'),
  194. ),
  195. ),
  196. 'postsettings' => array(
  197. 'label' => $txt['manageposts'],
  198. 'file' => 'ManagePosts.php',
  199. 'function' => 'ManagePostSettings',
  200. 'permission' => array('admin_forum'),
  201. 'icon' => 'posts.gif',
  202. 'subsections' => array(
  203. 'posts' => array($txt['manageposts_settings']),
  204. 'bbc' => array($txt['manageposts_bbc_settings']),
  205. 'censor' => array($txt['admin_censored_words']),
  206. 'topics' => array($txt['manageposts_topic_settings']),
  207. ),
  208. ),
  209. 'managecalendar' => array(
  210. 'label' => $txt['manage_calendar'],
  211. 'file' => 'ManageCalendar.php',
  212. 'function' => 'ManageCalendar',
  213. 'icon' => 'calendar.gif',
  214. 'permission' => array('admin_forum'),
  215. 'enabled' => in_array('cd', $context['admin_features']),
  216. 'subsections' => array(
  217. 'holidays' => array($txt['manage_holidays'], 'admin_forum', 'enabled' => !empty($modSettings['cal_enabled'])),
  218. 'settings' => array($txt['calendar_settings'], 'admin_forum'),
  219. ),
  220. ),
  221. 'managesearch' => array(
  222. 'label' => $txt['manage_search'],
  223. 'file' => 'ManageSearch.php',
  224. 'function' => 'ManageSearch',
  225. 'icon' => 'search.gif',
  226. 'permission' => array('admin_forum'),
  227. 'subsections' => array(
  228. 'weights' => array($txt['search_weights']),
  229. 'method' => array($txt['search_method']),
  230. 'settings' => array($txt['settings']),
  231. ),
  232. ),
  233. 'smileys' => array(
  234. 'label' => $txt['smileys_manage'],
  235. 'file' => 'ManageSmileys.php',
  236. 'function' => 'ManageSmileys',
  237. 'icon' => 'smiley.gif',
  238. 'permission' => array('manage_smileys'),
  239. 'subsections' => array(
  240. 'editsets' => array($txt['smiley_sets']),
  241. 'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])),
  242. 'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])),
  243. 'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])),
  244. 'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])),
  245. 'settings' => array($txt['settings']),
  246. ),
  247. ),
  248. 'manageattachments' => array(
  249. 'label' => $txt['attachments_avatars'],
  250. 'file' => 'ManageAttachments.php',
  251. 'function' => 'ManageAttachments',
  252. 'icon' => 'attachment.gif',
  253. 'permission' => array('manage_attachments'),
  254. 'subsections' => array(
  255. 'browse' => array($txt['attachment_manager_browse']),
  256. 'attachments' => array($txt['attachment_manager_settings']),
  257. 'avatars' => array($txt['attachment_manager_avatar_settings']),
  258. 'maintenance' => array($txt['attachment_manager_maintenance']),
  259. ),
  260. ),
  261. ),
  262. ),
  263. 'members' => array(
  264. 'title' => $txt['admin_manage_members'],
  265. 'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'),
  266. 'areas' => array(
  267. 'viewmembers' => array(
  268. 'label' => $txt['admin_users'],
  269. 'file' => 'ManageMembers.php',
  270. 'function' => 'ViewMembers',
  271. 'icon' => 'members.gif',
  272. 'permission' => array('moderate_forum'),
  273. 'subsections' => array(
  274. 'all' => array($txt['view_all_members']),
  275. 'search' => array($txt['mlist_search']),
  276. ),
  277. ),
  278. 'membergroups' => array(
  279. 'label' => $txt['admin_groups'],
  280. 'file' => 'ManageMembergroups.php',
  281. 'function' => 'ModifyMembergroups',
  282. 'icon' => 'membergroups.gif',
  283. 'permission' => array('manage_membergroups'),
  284. 'subsections' => array(
  285. 'index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'),
  286. 'add' => array($txt['membergroups_new_group'], 'manage_membergroups'),
  287. 'settings' => array($txt['settings'], 'admin_forum'),
  288. ),
  289. ),
  290. 'permissions' => array(
  291. 'label' => $txt['edit_permissions'],
  292. 'file' => 'ManagePermissions.php',
  293. 'function' => 'ModifyPermissions',
  294. 'icon' => 'permissions.gif',
  295. 'permission' => array('manage_permissions'),
  296. 'subsections' => array(
  297. 'index' => array($txt['permissions_groups'], 'manage_permissions'),
  298. 'board' => array($txt['permissions_boards'], 'manage_permissions'),
  299. 'profiles' => array($txt['permissions_profiles'], 'manage_permissions'),
  300. 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']),
  301. 'settings' => array($txt['settings'], 'admin_forum'),
  302. ),
  303. ),
  304. 'regcenter' => array(
  305. 'label' => $txt['registration_center'],
  306. 'file' => 'ManageRegistration.php',
  307. 'function' => 'RegCenter',
  308. 'icon' => 'regcenter.gif',
  309. 'permission' => array('admin_forum', 'moderate_forum'),
  310. 'subsections' => array(
  311. 'register' => array($txt['admin_browse_register_new'], 'moderate_forum'),
  312. 'agreement' => array($txt['registration_agreement'], 'admin_forum'),
  313. 'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'),
  314. 'settings' => array($txt['settings'], 'admin_forum'),
  315. ),
  316. ),
  317. 'ban' => array(
  318. 'label' => $txt['ban_title'],
  319. 'file' => 'ManageBans.php',
  320. 'function' => 'Ban',
  321. 'icon' => 'ban.gif',
  322. 'permission' => 'manage_bans',
  323. 'subsections' => array(
  324. 'list' => array($txt['ban_edit_list']),
  325. 'add' => array($txt['ban_add_new']),
  326. 'browse' => array($txt['ban_trigger_browse']),
  327. 'log' => array($txt['ban_log']),
  328. ),
  329. ),
  330. 'paidsubscribe' => array(
  331. 'label' => $txt['paid_subscriptions'],
  332. 'enabled' => in_array('ps', $context['admin_features']),
  333. 'file' => 'ManagePaid.php',
  334. 'icon' => 'paid.gif',
  335. 'function' => 'ManagePaidSubscriptions',
  336. 'permission' => 'admin_forum',
  337. 'subsections' => array(
  338. 'view' => array($txt['paid_subs_view']),
  339. 'settings' => array($txt['settings']),
  340. ),
  341. ),
  342. 'sengines' => array(
  343. 'label' => $txt['search_engines'],
  344. 'enabled' => in_array('sp', $context['admin_features']),
  345. 'file' => 'ManageSearchEngines.php',
  346. 'icon' => 'engines.gif',
  347. 'function' => 'SearchEngines',
  348. 'permission' => 'admin_forum',
  349. 'subsections' => array(
  350. 'stats' => array($txt['spider_stats']),
  351. 'logs' => array($txt['spider_logs']),
  352. 'spiders' => array($txt['spiders']),
  353. 'settings' => array($txt['settings']),
  354. ),
  355. ),
  356. ),
  357. ),
  358. 'maintenance' => array(
  359. 'title' => $txt['admin_maintenance'],
  360. 'permission' => array('admin_forum'),
  361. 'areas' => array(
  362. 'maintain' => array(
  363. 'label' => $txt['maintain_title'],
  364. 'file' => 'ManageMaintenance.php',
  365. 'icon' => 'maintain.gif',
  366. 'function' => 'ManageMaintenance',
  367. 'subsections' => array(
  368. 'routine' => array($txt['maintain_sub_routine'], 'admin_forum'),
  369. 'database' => array($txt['maintain_sub_database'], 'admin_forum'),
  370. 'members' => array($txt['maintain_sub_members'], 'admin_forum'),
  371. 'topics' => array($txt['maintain_sub_topics'], 'admin_forum'),
  372. ),
  373. ),
  374. 'scheduledtasks' => array(
  375. 'label' => $txt['maintain_tasks'],
  376. 'file' => 'ManageScheduledTasks.php',
  377. 'icon' => 'scheduled.gif',
  378. 'function' => 'ManageScheduledTasks',
  379. 'subsections' => array(
  380. 'tasks' => array($txt['maintain_tasks'], 'admin_forum'),
  381. 'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
  382. ),
  383. ),
  384. 'mailqueue' => array(
  385. 'label' => $txt['mailqueue_title'],
  386. 'file' => 'ManageMail.php',
  387. 'function' => 'ManageMail',
  388. 'icon' => 'mail.gif',
  389. 'subsections' => array(
  390. 'browse' => array($txt['mailqueue_browse'], 'admin_forum'),
  391. 'settings' => array($txt['mailqueue_settings'], 'admin_forum'),
  392. ),
  393. ),
  394. 'reports' => array(
  395. 'enabled' => in_array('rg', $context['admin_features']),
  396. 'label' => $txt['generate_reports'],
  397. 'file' => 'Reports.php',
  398. 'function' => 'ReportsMain',
  399. 'icon' => 'reports.gif',
  400. ),
  401. 'logs' => array(
  402. 'label' => $txt['logs'],
  403. 'function' => 'AdminLogs',
  404. 'icon' => 'logs.gif',
  405. 'subsections' => array(
  406. 'errorlog' => array($txt['errlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'),
  407. 'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])),
  408. 'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])),
  409. 'banlog' => array($txt['ban_log'], 'manage_bans'),
  410. 'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => in_array('sp', $context['admin_features'])),
  411. 'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
  412. 'pruning' => array($txt['pruning_title'], 'admin_forum'),
  413. ),
  414. ),
  415. 'repairboards' => array(
  416. 'label' => $txt['admin_repair'],
  417. 'file' => 'RepairBoards.php',
  418. 'function' => 'RepairBoards',
  419. 'select' => 'maintain',
  420. 'hidden' => true,
  421. ),
  422. ),
  423. ),
  424. );
  425. // Any files to include for administration?
  426. if (!empty($modSettings['integrate_admin_include']))
  427. {
  428. $admin_includes = explode(',', $modSettings['integrate_admin_include']);
  429. foreach ($admin_includes as $include)
  430. {
  431. $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
  432. if (file_exists($include))
  433. require_once($include);
  434. }
  435. }
  436. // Let them modify admin areas easily.
  437. call_integration_hook('integrate_admin_areas', array(&$admin_areas));
  438. // Make sure the administrator has a valid session...
  439. validateSession();
  440. // Actually create the menu!
  441. $admin_include_data = createMenu($admin_areas);
  442. unset($admin_areas);
  443. // Nothing valid?
  444. if ($admin_include_data == false)
  445. fatal_lang_error('no_access', false);
  446. // Build the link tree.
  447. $context['linktree'][] = array(
  448. 'url' => $scripturl . '?action=admin',
  449. 'name' => $txt['admin_center'],
  450. );
  451. if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
  452. $context['linktree'][] = array(
  453. 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  454. 'name' => $admin_include_data['label'],
  455. );
  456. if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
  457. $context['linktree'][] = array(
  458. 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  459. 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
  460. );
  461. // Make a note of the Unique ID for this menu.
  462. $context['admin_menu_id'] = $context['max_menu_id'];
  463. $context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id'];
  464. // Why on the admin are we?
  465. $context['admin_area'] = $admin_include_data['current_area'];
  466. // Now - finally - call the right place!
  467. if (isset($admin_include_data['file']))
  468. require_once($sourcedir . '/' . $admin_include_data['file']);
  469. $admin_include_data['function']();
  470. }
  471. /**
  472. * The main administration section.
  473. * It prepares all the data necessary for the administration front page.
  474. * It uses the Admin template along with the admin sub template.
  475. * It requires the moderate_forum, manage_membergroups, manage_bans,
  476. * admin_forum, manage_permissions, manage_attachments, manage_smileys,
  477. * manage_boards, edit_news, or send_mail permission.
  478. * It uses the index administrative area.
  479. * It can be found by going to ?action=admin.
  480. */
  481. function AdminHome()
  482. {
  483. global $sourcedir, $forum_version, $txt, $scripturl, $context, $user_info, $boardurl, $modSettings, $smcFunc;
  484. // You have to be able to do at least one of the below to see this page.
  485. isAllowedTo(array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'));
  486. // Find all of this forum's administrators...
  487. require_once($sourcedir . '/Subs-Membergroups.php');
  488. if (listMembergroupMembers_Href($context['administrators'], 1, 32) && allowedTo('manage_membergroups'))
  489. {
  490. // Add a 'more'-link if there are more than 32.
  491. $context['more_admins_link'] = '<a href="' . $scripturl . '?action=moderate;area=viewgroups;sa=members;group=1">' . $txt['more'] . '</a>';
  492. }
  493. // Load the credits stuff.
  494. require_once($sourcedir . '/Who.php');
  495. Credits(true);
  496. // This makes it easier to get the latest news with your time format.
  497. $context['time_format'] = urlencode($user_info['time_format']);
  498. $context['current_versions'] = array(
  499. 'php' => array('title' => $txt['support_versions_php'], 'version' => PHP_VERSION),
  500. 'db' => array('title' => sprintf($txt['support_versions_db'], $smcFunc['db_title']), 'version' => ''),
  501. 'server' => array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']),
  502. );
  503. $context['forum_version'] = $forum_version;
  504. // Get a list of current server versions.
  505. require_once($sourcedir . '/Subs-Admin.php');
  506. $checkFor = array(
  507. 'gd',
  508. 'db_server',
  509. 'mmcache',
  510. 'eaccelerator',
  511. 'phpa',
  512. 'apc',
  513. 'memcache',
  514. 'xcache',
  515. 'php',
  516. 'server',
  517. );
  518. $context['current_versions'] = getServerVersions($checkFor);
  519. $context['can_admin'] = allowedTo('admin_forum');
  520. $context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
  521. $context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
  522. // The format of this array is: permission, action, title, description, icon.
  523. $quick_admin_tasks = array(
  524. array('', 'credits', 'support_credits_title', 'support_credits_info', 'support_and_credits.png'),
  525. array('admin_forum', 'featuresettings', 'modSettings_title', 'modSettings_info', 'features_and_options.png'),
  526. array('admin_forum', 'maintain', 'maintain_title', 'maintain_info', 'forum_maintenance.png'),
  527. array('manage_permissions', 'permissions', 'edit_permissions', 'edit_permissions_info', 'permissions.png'),
  528. array('admin_forum', 'theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id'], 'theme_admin', 'theme_admin_info', 'themes_and_layout.png'),
  529. array('admin_forum', 'packages', 'package', 'package_info', 'packages.png'),
  530. array('manage_smileys', 'smileys', 'smileys_manage', 'smileys_manage_info', 'smilies_and_messageicons.png'),
  531. array('moderate_forum', 'viewmembers', 'admin_users', 'member_center_info', 'members.png'),
  532. );
  533. $context['quick_admin_tasks'] = array();
  534. foreach ($quick_admin_tasks as $task)
  535. {
  536. if (!empty($task[0]) && !allowedTo($task[0]))
  537. continue;
  538. $context['quick_admin_tasks'][] = array(
  539. 'href' => $scripturl . '?action=admin;area=' . $task[1],
  540. 'link' => '<a href="' . $scripturl . '?action=admin;area=' . $task[1] . '">' . $txt[$task[2]] . '</a>',
  541. 'title' => $txt[$task[2]],
  542. 'description' => $txt[$task[3]],
  543. 'icon' => $task[4],
  544. 'is_last' => false
  545. );
  546. }
  547. if (count($context['quick_admin_tasks']) % 2 == 1)
  548. {
  549. $context['quick_admin_tasks'][] = array(
  550. 'href' => '',
  551. 'link' => '',
  552. 'title' => '',
  553. 'description' => '',
  554. 'is_last' => true
  555. );
  556. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
  557. }
  558. elseif (count($context['quick_admin_tasks']) != 0)
  559. {
  560. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 1]['is_last'] = true;
  561. $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
  562. }
  563. // Lastly, fill in the blanks in the support resources paragraphs.
  564. $txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
  565. 'http://wiki.simplemachines.org/',
  566. 'http://wiki.simplemachines.org/smf/features2',
  567. 'http://wiki.simplemachines.org/smf/options2',
  568. 'http://wiki.simplemachines.org/smf/themes2',
  569. 'http://wiki.simplemachines.org/smf/packages2'
  570. );
  571. $txt['support_resources_p2'] = sprintf($txt['support_resources_p2'],
  572. 'http://www.simplemachines.org/community/',
  573. 'http://www.simplemachines.org/redirect/english_support',
  574. 'http://www.simplemachines.org/redirect/international_support_boards',
  575. 'http://www.simplemachines.org/redirect/smf_support',
  576. 'http://www.simplemachines.org/redirect/customize_support'
  577. );
  578. }
  579. /**
  580. * Get one of the admin information files from Simple Machines.
  581. */
  582. function DisplayAdminFile()
  583. {
  584. global $context, $modSettings, $smcFunc;
  585. @ini_set('memory_limit', '32M');
  586. if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
  587. fatal_lang_error('no_access', false);
  588. $request = $smcFunc['db_query']('', '
  589. SELECT data, filetype
  590. FROM {db_prefix}admin_info_files
  591. WHERE filename = {string:current_filename}
  592. LIMIT 1',
  593. array(
  594. 'current_filename' => $_REQUEST['filename'],
  595. )
  596. );
  597. if ($smcFunc['db_num_rows']($request) == 0)
  598. fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']));
  599. list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
  600. $smcFunc['db_free_result']($request);
  601. // @todo Temp
  602. // Figure out if sesc is still being used.
  603. if (strpos($file_data, ';sesc=') !== false)
  604. $file_data = '
  605. if (!(\'smfForum_sessionvar\' in window))
  606. window.smfForum_sessionvar = \'sesc\';
  607. ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
  608. $context['template_layers'] = array();
  609. // Lets make sure we aren't going to output anything nasty.
  610. @ob_end_clean();
  611. if (!empty($modSettings['enableCompressedOutput']))
  612. @ob_start('ob_gzhandler');
  613. else
  614. @ob_start();
  615. // Make sure they know what type of file we are.
  616. header('Content-Type: ' . $filetype);
  617. echo $file_data;
  618. obExit(false);
  619. }
  620. /**
  621. * This function allocates out all the search stuff.
  622. */
  623. function AdminSearch()
  624. {
  625. global $txt, $context, $smcFunc, $sourcedir;
  626. isAllowedTo('admin_forum');
  627. // What can we search for?
  628. $subactions = array(
  629. 'internal' => 'AdminSearchInternal',
  630. 'online' => 'AdminSearchOM',
  631. 'member' => 'AdminSearchMember',
  632. );
  633. $context['search_type'] = !isset($_REQUEST['search_type']) || !isset($subactions[$_REQUEST['search_type']]) ? 'internal' : $_REQUEST['search_type'];
  634. $context['search_term'] = isset($_REQUEST['search_term']) ? $smcFunc['htmlspecialchars']($_REQUEST['search_term'], ENT_QUOTES) : '';
  635. $context['sub_template'] = 'admin_search_results';
  636. $context['page_title'] = $txt['admin_search_results'];
  637. // Keep track of what the admin wants.
  638. if (empty($context['admin_preferences']['sb']) || $context['admin_preferences']['sb'] != $context['search_type'])
  639. {
  640. $context['admin_preferences']['sb'] = $context['search_type'];
  641. // Update the preferences.
  642. require_once($sourcedir . '/Subs-Admin.php');
  643. updateAdminPreferences();
  644. }
  645. if (trim($context['search_term']) == '')
  646. $context['search_results'] = array();
  647. else
  648. $subactions[$context['search_type']]();
  649. }
  650. /**
  651. * A complicated but relatively quick internal search.
  652. */
  653. function AdminSearchInternal()
  654. {
  655. global $context, $txt, $helptxt, $scripturl, $sourcedir;
  656. // Try to get some more memory.
  657. @ini_set('memory_limit', '128M');
  658. // Load a lot of language files.
  659. $language_files = array(
  660. 'Help', 'ManageMail', 'ManageSettings', 'ManageCalendar', 'ManageBoards', 'ManagePaid', 'ManagePermissions', 'Search',
  661. 'Login', 'ManageSmileys',
  662. );
  663. loadLanguage(implode('+', $language_files));
  664. // All the files we need to include.
  665. $include_files = array(
  666. 'ManageSettings', 'ManageBoards', 'ManageNews', 'ManageAttachments', 'ManageCalendar', 'ManageMail', 'ManagePaid', 'ManagePermissions',
  667. 'ManagePosts', 'ManageRegistration', 'ManageSearch', 'ManageSearchEngines', 'ManageServer', 'ManageSmileys', 'ManageLanguages',
  668. );
  669. // @todo add hook to add more include_files here
  670. foreach ($include_files as $file)
  671. require_once($sourcedir . '/' . $file . '.php');
  672. /* This is the huge array that defines everything... it's a huge array of items formatted as follows:
  673. 0 = Language index (Can be array of indexes) to search through for this setting.
  674. 1 = URL for this indexes page.
  675. 2 = Help index for help associated with this item (If different from 0)
  676. */
  677. $search_data = array(
  678. // All the major sections of the forum.
  679. 'sections' => array(
  680. ),
  681. 'settings' => array(
  682. array('COPPA', 'area=regcenter;sa=settings'),
  683. array('CAPTCHA', 'area=securitysettings;sa=spam'),
  684. ),
  685. );
  686. // Go through the admin menu structure trying to find suitably named areas!
  687. foreach ($context[$context['admin_menu_name']]['sections'] as $section)
  688. {
  689. foreach ($section['areas'] as $menu_key => $menu_item)
  690. {
  691. $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
  692. if (!empty($menu_item['subsections']))
  693. foreach ($menu_item['subsections'] as $key => $sublabel)
  694. {
  695. if (isset($sublabel['label']))
  696. $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
  697. }
  698. }
  699. }
  700. // This is a special array of functions that contain setting data - we query all these to simply pull all setting bits!
  701. $settings_search = array(
  702. array('ModifyCoreFeatures', 'area=corefeatures'),
  703. array('ModifyBasicSettings', 'area=featuresettings;sa=basic'),
  704. array('ModifyLayoutSettings', 'area=featuresettings;sa=layout'),
  705. array('ModifyKarmaSettings', 'area=featuresettings;sa=karma'),
  706. array('ModifySignatureSettings', 'area=featuresettings;sa=sig'),
  707. array('ModifyGeneralSecuritySettings', 'area=securitysettings;sa=general'),
  708. array('ModifySpamSettings', 'area=securitysettings;sa=spam'),
  709. array('ModifyModerationSettings', 'area=securitysettings;sa=moderation'),
  710. array('ModifyGeneralModSettings', 'area=modsettings;sa=general'),
  711. // Mod authors if you want to be "real freaking good" then add any setting pages for your mod BELOW this line!
  712. array('ManageAttachmentSettings', 'area=manageattachments;sa=attachments'),
  713. array('ManageAvatarSettings', 'area=manageattachments;sa=avatars'),
  714. array('ModifyCalendarSettings', 'area=managecalendar;sa=settings'),
  715. array('EditBoardSettings', 'area=manageboards;sa=settings'),
  716. array('ModifyMailSettings', 'area=mailqueue;sa=settings'),
  717. array('ModifyNewsSettings', 'area=news;sa=settings'),
  718. array('GeneralPermissionSettings', 'area=permissions;sa=settings'),
  719. array('ModifyPostSettings', 'area=postsettings;sa=posts'),
  720. array('ModifyBBCSettings', 'area=postsettings;sa=bbc'),
  721. array('ModifyTopicSettings', 'area=postsettings;sa=topics'),
  722. array('EditSearchSettings', 'area=managesearch;sa=settings'),
  723. array('EditSmileySettings', 'area=smileys;sa=settings'),
  724. array('ModifyGeneralSettings', 'area=serversettings;sa=general'),
  725. array('ModifyDatabaseSettings', 'area=serversettings;sa=database'),
  726. array('ModifyCookieSettings', 'area=serversettings;sa=cookie'),
  727. array('ModifyCacheSettings', 'area=serversettings;sa=cache'),
  728. array('ModifyLanguageSettings', 'area=languages;sa=settings'),
  729. array('ModifyRegistrationSettings', 'area=regcenter;sa=settings'),
  730. array('ManageSearchEngineSettings', 'area=sengines;sa=settings'),
  731. array('ModifySubscriptionSettings', 'area=paidsubscribe;sa=settings'),
  732. array('ModifyPruningSettings', 'area=logs;sa=pruning'),
  733. );
  734. // @todo add hook to add more $settings search
  735. foreach ($settings_search as $setting_area)
  736. {
  737. // Get a list of their variables.
  738. $config_vars = $setting_area[0](true);
  739. foreach ($config_vars as $var)
  740. if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch')))
  741. $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]);
  742. }
  743. $context['page_title'] = $txt['admin_search_results'];
  744. $context['search_results'] = array();
  745. $search_term = strtolower($context['search_term']);
  746. // Go through all the search data trying to find this text!
  747. foreach ($search_data as $section => $data)
  748. {
  749. foreach ($data as $item)
  750. {
  751. $found = false;
  752. if (!is_array($item[0]))
  753. $item[0] = array($item[0]);
  754. foreach ($item[0] as $term)
  755. {
  756. $lc_term = strtolower($term);
  757. if (strpos($lc_term, $search_term) !== false || (isset($txt[$term]) && strpos(strtolower($txt[$term]), $search_term) !== false) || (isset($txt['setting_' . $term]) && strpos(strtolower($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' => (strpos($item[1], 'area') === 0 ? $scripturl . '?action=admin;' . $item[1] : $item[1]) . ';' . $context['session_var'] . '=' . $context['session_id'] . ((strpos($item[1], 'area') === 0 && $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. loadClassFile('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. ?>