Admin.php 35 KB

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