Admin.php 37 KB

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