Admin.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  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. loadJavascriptFile('scripts/admin.js?alp21', array('default_theme' => true));
  30. // No indexing evil stuff.
  31. $context['robot_no_index'] = true;
  32. require_once($sourcedir . '/Subs-Menu.php');
  33. // Some preferences.
  34. $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  35. // Define all the menu structure - see Subs-Menu.php for details!
  36. $admin_areas = array(
  37. 'forum' => array(
  38. 'title' => $txt['admin_main'],
  39. 'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'),
  40. 'areas' => array(
  41. 'index' => array(
  42. 'label' => $txt['admin_center'],
  43. 'function' => 'AdminHome',
  44. 'icon' => 'administration.png',
  45. ),
  46. 'credits' => array(
  47. 'label' => $txt['support_credits_title'],
  48. 'function' => 'AdminHome',
  49. 'icon' => 'support.png',
  50. ),
  51. 'news' => array(
  52. 'label' => $txt['news_title'],
  53. 'file' => 'ManageNews.php',
  54. 'function' => 'ManageNews',
  55. 'icon' => 'news.png',
  56. 'permission' => array('edit_news', 'send_mail', 'admin_forum'),
  57. 'subsections' => array(
  58. 'editnews' => array($txt['admin_edit_news'], 'edit_news'),
  59. 'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'),
  60. 'settings' => array($txt['settings'], 'admin_forum'),
  61. ),
  62. ),
  63. 'packages' => array(
  64. 'label' => $txt['package'],
  65. 'file' => 'Packages.php',
  66. 'function' => 'Packages',
  67. 'permission' => array('admin_forum'),
  68. 'icon' => 'packages.png',
  69. 'subsections' => array(
  70. 'browse' => array($txt['browse_packages']),
  71. 'packageget' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packages;sa=packageget;get'),
  72. 'installed' => array($txt['installed_packages']),
  73. 'perms' => array($txt['package_file_perms']),
  74. 'options' => array($txt['package_settings']),
  75. ),
  76. ),
  77. 'search' => array(
  78. 'function' => 'AdminSearch',
  79. 'permission' => array('admin_forum'),
  80. 'select' => 'index'
  81. ),
  82. 'adminlogoff' => array(
  83. 'label' => $txt['admin_logoff'],
  84. 'function' => 'AdminEndSession',
  85. 'enabled' => empty($modSettings['securityDisable']),
  86. 'icon' => 'exit.png',
  87. ),
  88. ),
  89. ),
  90. 'config' => array(
  91. 'title' => $txt['admin_config'],
  92. 'permission' => array('admin_forum'),
  93. 'areas' => array(
  94. 'corefeatures' => array(
  95. 'label' => $txt['core_settings_title'],
  96. 'file' => 'ManageSettings.php',
  97. 'function' => 'ModifyCoreFeatures',
  98. 'icon' => 'corefeatures.png',
  99. ),
  100. 'featuresettings' => array(
  101. 'label' => $txt['modSettings_title'],
  102. 'file' => 'ManageSettings.php',
  103. 'function' => 'ModifyFeatureSettings',
  104. 'icon' => 'features.png',
  105. 'subsections' => array(
  106. 'basic' => array($txt['mods_cat_features']),
  107. 'layout' => array($txt['mods_cat_layout']),
  108. 'karma' => array($txt['karma'], 'enabled' => in_array('k', $context['admin_features'])),
  109. 'sig' => array($txt['signature_settings_short']),
  110. 'profile' => array($txt['custom_profile_shorttitle'], 'enabled' => in_array('cp', $context['admin_features'])),
  111. ),
  112. ),
  113. 'securitysettings' => array(
  114. 'label' => $txt['admin_security_moderation'],
  115. 'file' => 'ManageSettings.php',
  116. 'function' => 'ModifySecuritySettings',
  117. 'icon' => 'security.png',
  118. 'subsections' => array(
  119. 'general' => array($txt['mods_cat_security_general']),
  120. 'spam' => array($txt['antispam_title']),
  121. 'moderation' => array($txt['moderation_settings_short'], 'enabled' => substr($modSettings['warning_settings'], 0, 1) == 1),
  122. ),
  123. ),
  124. 'languages' => array(
  125. 'label' => $txt['language_configuration'],
  126. 'file' => 'ManageLanguages.php',
  127. 'function' => 'ManageLanguages',
  128. 'icon' => 'languages.png',
  129. 'subsections' => array(
  130. 'edit' => array($txt['language_edit']),
  131. 'add' => array($txt['language_add']),
  132. 'settings' => array($txt['language_settings']),
  133. ),
  134. ),
  135. 'serversettings' => array(
  136. 'label' => $txt['admin_server_settings'],
  137. 'file' => 'ManageServer.php',
  138. 'function' => 'ModifySettings',
  139. 'icon' => 'server.png',
  140. 'subsections' => array(
  141. 'general' => array($txt['general_settings']),
  142. 'database' => array($txt['database_paths_settings']),
  143. 'cookie' => array($txt['cookies_sessions_settings']),
  144. 'cache' => array($txt['caching_settings']),
  145. 'loads' => array($txt['load_balancing_settings']),
  146. 'phpinfo' => array($txt['phpinfo_settings']),
  147. ),
  148. ),
  149. 'current_theme' => array(
  150. 'label' => $txt['theme_current_settings'],
  151. 'file' => 'Themes.php',
  152. 'function' => 'ThemesMain',
  153. 'custom_url' => $scripturl . '?action=admin;area=theme;sa=settings;th=' . $settings['theme_id'],
  154. 'icon' => 'current_theme.png',
  155. ),
  156. 'theme' => array(
  157. 'label' => $txt['theme_admin'],
  158. 'file' => 'Themes.php',
  159. 'function' => 'ThemesMain',
  160. 'custom_url' => $scripturl . '?action=admin;area=theme',
  161. 'icon' => 'themes.png',
  162. 'subsections' => array(
  163. 'admin' => array($txt['themeadmin_admin_title']),
  164. 'list' => array($txt['themeadmin_list_title']),
  165. 'reset' => array($txt['themeadmin_reset_title']),
  166. 'edit' => array($txt['themeadmin_edit_title']),
  167. ),
  168. ),
  169. 'modsettings' => array(
  170. 'label' => $txt['admin_modifications'],
  171. 'file' => 'ManageSettings.php',
  172. 'function' => 'ModifyModSettings',
  173. 'icon' => 'modifications.png',
  174. 'subsections' => array(
  175. 'hooks' => array($txt['hooks_title_list']),
  176. 'general' => array($txt['mods_cat_modifications_misc']),
  177. // Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example:
  178. // 'shout' => array($txt['shout']),
  179. // Note the comma!! The setting with automatically appear with the first mod to be added.
  180. ),
  181. ),
  182. ),
  183. ),
  184. 'layout' => array(
  185. 'title' => $txt['layout_controls'],
  186. 'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
  187. 'areas' => array(
  188. 'manageboards' => array(
  189. 'label' => $txt['admin_boards'],
  190. 'file' => 'ManageBoards.php',
  191. 'function' => 'ManageBoards',
  192. 'icon' => 'boards.png',
  193. 'permission' => array('manage_boards'),
  194. 'subsections' => array(
  195. 'main' => array($txt['boardsEdit']),
  196. 'newcat' => array($txt['mboards_new_cat']),
  197. 'settings' => array($txt['settings'], 'admin_forum'),
  198. ),
  199. ),
  200. 'postsettings' => array(
  201. 'label' => $txt['manageposts'],
  202. 'file' => 'ManagePosts.php',
  203. 'function' => 'ManagePostSettings',
  204. 'permission' => array('admin_forum'),
  205. 'icon' => 'posts.png',
  206. 'subsections' => array(
  207. 'posts' => array($txt['manageposts_settings']),
  208. 'bbc' => array($txt['manageposts_bbc_settings']),
  209. 'censor' => array($txt['admin_censored_words']),
  210. 'topics' => array($txt['manageposts_topic_settings']),
  211. ),
  212. ),
  213. 'managecalendar' => array(
  214. 'label' => $txt['manage_calendar'],
  215. 'file' => 'ManageCalendar.php',
  216. 'function' => 'ManageCalendar',
  217. 'icon' => 'calendar.png',
  218. 'permission' => array('admin_forum'),
  219. 'enabled' => in_array('cd', $context['admin_features']),
  220. 'subsections' => array(
  221. 'holidays' => array($txt['manage_holidays'], 'admin_forum', 'enabled' => !empty($modSettings['cal_enabled'])),
  222. 'settings' => array($txt['calendar_settings'], 'admin_forum'),
  223. ),
  224. ),
  225. 'managesearch' => array(
  226. 'label' => $txt['manage_search'],
  227. 'file' => 'ManageSearch.php',
  228. 'function' => 'ManageSearch',
  229. 'icon' => 'search.png',
  230. 'permission' => array('admin_forum'),
  231. 'subsections' => array(
  232. 'weights' => array($txt['search_weights']),
  233. 'method' => array($txt['search_method']),
  234. 'settings' => array($txt['settings']),
  235. ),
  236. ),
  237. 'smileys' => array(
  238. 'label' => $txt['smileys_manage'],
  239. 'file' => 'ManageSmileys.php',
  240. 'function' => 'ManageSmileys',
  241. 'icon' => 'smiley.png',
  242. 'permission' => array('manage_smileys'),
  243. 'subsections' => array(
  244. 'editsets' => array($txt['smiley_sets']),
  245. 'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])),
  246. 'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])),
  247. 'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])),
  248. 'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])),
  249. 'settings' => array($txt['settings']),
  250. ),
  251. ),
  252. 'manageattachments' => array(
  253. 'label' => $txt['attachments_avatars'],
  254. 'file' => 'ManageAttachments.php',
  255. 'function' => 'ManageAttachments',
  256. 'icon' => 'attachment.png',
  257. 'permission' => array('manage_attachments'),
  258. 'subsections' => array(
  259. 'browse' => array($txt['attachment_manager_browse']),
  260. 'attachments' => array($txt['attachment_manager_settings']),
  261. 'avatars' => array($txt['attachment_manager_avatar_settings']),
  262. 'maintenance' => array($txt['attachment_manager_maintenance']),
  263. ),
  264. ),
  265. ),
  266. ),
  267. 'members' => array(
  268. 'title' => $txt['admin_manage_members'],
  269. 'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'),
  270. 'areas' => array(
  271. 'viewmembers' => array(
  272. 'label' => $txt['admin_users'],
  273. 'file' => 'ManageMembers.php',
  274. 'function' => 'ViewMembers',
  275. 'icon' => 'members.png',
  276. 'permission' => array('moderate_forum'),
  277. 'subsections' => array(
  278. 'all' => array($txt['view_all_members']),
  279. 'search' => array($txt['mlist_search']),
  280. ),
  281. ),
  282. 'membergroups' => array(
  283. 'label' => $txt['admin_groups'],
  284. 'file' => 'ManageMembergroups.php',
  285. 'function' => 'ModifyMembergroups',
  286. 'icon' => 'membergroups.png',
  287. 'permission' => array('manage_membergroups'),
  288. 'subsections' => array(
  289. 'index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'),
  290. 'add' => array($txt['membergroups_new_group'], 'manage_membergroups'),
  291. 'settings' => array($txt['settings'], 'admin_forum'),
  292. ),
  293. ),
  294. 'permissions' => array(
  295. 'label' => $txt['edit_permissions'],
  296. 'file' => 'ManagePermissions.php',
  297. 'function' => 'ModifyPermissions',
  298. 'icon' => 'permissions.png',
  299. 'permission' => array('manage_permissions'),
  300. 'subsections' => array(
  301. 'index' => array($txt['permissions_groups'], 'manage_permissions'),
  302. 'board' => array($txt['permissions_boards'], 'manage_permissions'),
  303. 'profiles' => array($txt['permissions_profiles'], 'manage_permissions'),
  304. 'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions', 'enabled' => $modSettings['postmod_active']),
  305. 'settings' => array($txt['settings'], 'admin_forum'),
  306. ),
  307. ),
  308. 'regcenter' => array(
  309. 'label' => $txt['registration_center'],
  310. 'file' => 'ManageRegistration.php',
  311. 'function' => 'RegCenter',
  312. 'icon' => 'regcenter.png',
  313. 'permission' => array('admin_forum', 'moderate_forum'),
  314. 'subsections' => array(
  315. 'register' => array($txt['admin_browse_register_new'], 'moderate_forum'),
  316. 'agreement' => array($txt['registration_agreement'], 'admin_forum'),
  317. 'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'),
  318. 'settings' => array($txt['settings'], 'admin_forum'),
  319. ),
  320. ),
  321. 'ban' => array(
  322. 'label' => $txt['ban_title'],
  323. 'file' => 'ManageBans.php',
  324. 'function' => 'Ban',
  325. 'icon' => 'ban.png',
  326. 'permission' => 'manage_bans',
  327. 'subsections' => array(
  328. 'list' => array($txt['ban_edit_list']),
  329. 'add' => array($txt['ban_add_new']),
  330. 'browse' => array($txt['ban_trigger_browse']),
  331. 'log' => array($txt['ban_log']),
  332. ),
  333. ),
  334. 'paidsubscribe' => array(
  335. 'label' => $txt['paid_subscriptions'],
  336. 'enabled' => in_array('ps', $context['admin_features']),
  337. 'file' => 'ManagePaid.php',
  338. 'icon' => 'paid.png',
  339. 'function' => 'ManagePaidSubscriptions',
  340. 'permission' => 'admin_forum',
  341. 'subsections' => array(
  342. 'view' => array($txt['paid_subs_view']),
  343. 'settings' => array($txt['settings']),
  344. ),
  345. ),
  346. 'sengines' => array(
  347. 'label' => $txt['search_engines'],
  348. 'enabled' => in_array('sp', $context['admin_features']),
  349. 'file' => 'ManageSearchEngines.php',
  350. 'icon' => 'engines.png',
  351. 'function' => 'SearchEngines',
  352. 'permission' => 'admin_forum',
  353. 'subsections' => array(
  354. 'stats' => array($txt['spider_stats']),
  355. 'logs' => array($txt['spider_logs']),
  356. 'spiders' => array($txt['spiders']),
  357. 'settings' => array($txt['settings']),
  358. ),
  359. ),
  360. ),
  361. ),
  362. 'maintenance' => array(
  363. 'title' => $txt['admin_maintenance'],
  364. 'permission' => array('admin_forum'),
  365. 'areas' => array(
  366. 'maintain' => array(
  367. 'label' => $txt['maintain_title'],
  368. 'file' => 'ManageMaintenance.php',
  369. 'icon' => 'maintain.png',
  370. 'function' => 'ManageMaintenance',
  371. 'subsections' => array(
  372. 'routine' => array($txt['maintain_sub_routine'], 'admin_forum'),
  373. 'database' => array($txt['maintain_sub_database'], 'admin_forum'),
  374. 'members' => array($txt['maintain_sub_members'], 'admin_forum'),
  375. 'topics' => array($txt['maintain_sub_topics'], 'admin_forum'),
  376. ),
  377. ),
  378. 'scheduledtasks' => array(
  379. 'label' => $txt['maintain_tasks'],
  380. 'file' => 'ManageScheduledTasks.php',
  381. 'icon' => 'scheduled.png',
  382. 'function' => 'ManageScheduledTasks',
  383. 'subsections' => array(
  384. 'tasks' => array($txt['maintain_tasks'], 'admin_forum'),
  385. 'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
  386. ),
  387. ),
  388. 'mailqueue' => array(
  389. 'label' => $txt['mailqueue_title'],
  390. 'file' => 'ManageMail.php',
  391. 'function' => 'ManageMail',
  392. 'icon' => 'mail.png',
  393. 'subsections' => array(
  394. 'browse' => array($txt['mailqueue_browse'], 'admin_forum'),
  395. 'settings' => array($txt['mailqueue_settings'], 'admin_forum'),
  396. ),
  397. ),
  398. 'reports' => array(
  399. 'enabled' => in_array('rg', $context['admin_features']),
  400. 'label' => $txt['generate_reports'],
  401. 'file' => 'Reports.php',
  402. 'function' => 'ReportsMain',
  403. 'icon' => 'reports.png',
  404. ),
  405. 'logs' => array(
  406. 'label' => $txt['logs'],
  407. 'function' => 'AdminLogs',
  408. 'icon' => 'logs.png',
  409. 'subsections' => array(
  410. 'errorlog' => array($txt['errlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'),
  411. 'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])),
  412. 'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => in_array('ml', $context['admin_features'])),
  413. 'banlog' => array($txt['ban_log'], 'manage_bans'),
  414. 'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => in_array('sp', $context['admin_features'])),
  415. 'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
  416. 'pruning' => array($txt['pruning_title'], 'admin_forum'),
  417. ),
  418. ),
  419. 'repairboards' => array(
  420. 'label' => $txt['admin_repair'],
  421. 'file' => 'RepairBoards.php',
  422. 'function' => 'RepairBoards',
  423. 'select' => 'maintain',
  424. 'hidden' => true,
  425. ),
  426. ),
  427. ),
  428. );
  429. // Any files to include for administration?
  430. if (!empty($modSettings['integrate_admin_include']))
  431. {
  432. $admin_includes = explode(',', $modSettings['integrate_admin_include']);
  433. foreach ($admin_includes as $include)
  434. {
  435. $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
  436. if (file_exists($include))
  437. require_once($include);
  438. }
  439. }
  440. // Let them modify admin areas easily.
  441. call_integration_hook('integrate_admin_areas', array(&$admin_areas));
  442. // Make sure the administrator has a valid session...
  443. validateSession();
  444. // Actually create the menu!
  445. $admin_include_data = createMenu($admin_areas);
  446. unset($admin_areas);
  447. // Nothing valid?
  448. if ($admin_include_data == false)
  449. fatal_lang_error('no_access', false);
  450. // Build the link tree.
  451. $context['linktree'][] = array(
  452. 'url' => $scripturl . '?action=admin',
  453. 'name' => $txt['admin_center'],
  454. );
  455. if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
  456. $context['linktree'][] = array(
  457. 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  458. 'name' => $admin_include_data['label'],
  459. );
  460. if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
  461. $context['linktree'][] = array(
  462. 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  463. 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
  464. );
  465. // Make a note of the Unique ID for this menu.
  466. $context['admin_menu_id'] = $context['max_menu_id'];
  467. $context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id'];
  468. // Where in the admin are we?
  469. $context['admin_area'] = $admin_include_data['current_area'];
  470. // Now - finally - call the right place!
  471. if (isset($admin_include_data['file']))
  472. require_once($sourcedir . '/' . $admin_include_data['file']);
  473. $admin_include_data['function']();
  474. }
  475. /**
  476. * The main administration section.
  477. * It prepares all the data necessary for the administration front page.
  478. * It uses the Admin template along with the admin sub template.
  479. * It requires the moderate_forum, manage_membergroups, manage_bans,
  480. * admin_forum, manage_permissions, manage_attachments, manage_smileys,
  481. * manage_boards, edit_news, or send_mail permission.
  482. * It uses the index administrative area.
  483. * It can be found by going to ?action=admin.
  484. */
  485. function AdminHome()
  486. {
  487. global $sourcedir, $forum_version, $txt, $scripturl, $context, $user_info, $boardurl, $modSettings, $smcFunc;
  488. // You have to be able to do at least one of the below to see this page.
  489. isAllowedTo(array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'));
  490. // Find all of this forum's administrators...
  491. require_once($sourcedir . '/Subs-Membergroups.php');
  492. if (listMembergroupMembers_Href($context['administrators'], 1, 32) && allowedTo('manage_membergroups'))
  493. {
  494. // Add a 'more'-link if there are more than 32.
  495. $context['more_admins_link'] = '<a href="' . $scripturl . '?action=moderate;area=viewgroups;sa=members;group=1">' . $txt['more'] . '</a>';
  496. }
  497. // Load the credits stuff.
  498. require_once($sourcedir . '/Who.php');
  499. Credits(true);
  500. // This makes it easier to get the latest news with your time format.
  501. $context['time_format'] = urlencode($user_info['time_format']);
  502. $context['forum_version'] = $forum_version;
  503. // Get a list of current server versions.
  504. require_once($sourcedir . '/Subs-Admin.php');
  505. $checkFor = array(
  506. 'gd',
  507. 'imagick',
  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_lg.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_lg.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_lg.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. setMemoryLimit('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. setMemoryLimit('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. // All the files we need to include.
  664. $include_files = array(
  665. 'ManageSettings', 'ManageBoards', 'ManageNews', 'ManageAttachments', 'ManageCalendar', 'ManageMail', 'ManagePaid', 'ManagePermissions',
  666. 'ManagePosts', 'ManageRegistration', 'ManageSearch', 'ManageSearchEngines', 'ManageServer', 'ManageSmileys', 'ManageLanguages',
  667. );
  668. // This is a special array of functions that contain setting data - we query all these to simply pull all setting bits!
  669. $settings_search = array(
  670. array('ModifyCoreFeatures', 'area=corefeatures'),
  671. array('ModifyBasicSettings', 'area=featuresettings;sa=basic'),
  672. array('ModifyLayoutSettings', 'area=featuresettings;sa=layout'),
  673. array('ModifyKarmaSettings', 'area=featuresettings;sa=karma'),
  674. array('ModifySignatureSettings', 'area=featuresettings;sa=sig'),
  675. array('ModifyGeneralSecuritySettings', 'area=securitysettings;sa=general'),
  676. array('ModifySpamSettings', 'area=securitysettings;sa=spam'),
  677. array('ModifyModerationSettings', 'area=securitysettings;sa=moderation'),
  678. array('ModifyGeneralModSettings', 'area=modsettings;sa=general'),
  679. // Mod authors if you want to be "real freaking good" then add any setting pages for your mod BELOW this line!
  680. array('ManageAttachmentSettings', 'area=manageattachments;sa=attachments'),
  681. array('ManageAvatarSettings', 'area=manageattachments;sa=avatars'),
  682. array('ModifyCalendarSettings', 'area=managecalendar;sa=settings'),
  683. array('EditBoardSettings', 'area=manageboards;sa=settings'),
  684. array('ModifyMailSettings', 'area=mailqueue;sa=settings'),
  685. array('ModifyNewsSettings', 'area=news;sa=settings'),
  686. array('GeneralPermissionSettings', 'area=permissions;sa=settings'),
  687. array('ModifyPostSettings', 'area=postsettings;sa=posts'),
  688. array('ModifyBBCSettings', 'area=postsettings;sa=bbc'),
  689. array('ModifyTopicSettings', 'area=postsettings;sa=topics'),
  690. array('EditSearchSettings', 'area=managesearch;sa=settings'),
  691. array('EditSmileySettings', 'area=smileys;sa=settings'),
  692. array('ModifyGeneralSettings', 'area=serversettings;sa=general'),
  693. array('ModifyDatabaseSettings', 'area=serversettings;sa=database'),
  694. array('ModifyCookieSettings', 'area=serversettings;sa=cookie'),
  695. array('ModifyCacheSettings', 'area=serversettings;sa=cache'),
  696. array('ModifyLanguageSettings', 'area=languages;sa=settings'),
  697. array('ModifyRegistrationSettings', 'area=regcenter;sa=settings'),
  698. array('ManageSearchEngineSettings', 'area=sengines;sa=settings'),
  699. array('ModifySubscriptionSettings', 'area=paidsubscribe;sa=settings'),
  700. array('ModifyPruningSettings', 'area=logs;sa=pruning'),
  701. );
  702. call_integration_hook('integrate_admin_search', array(&$language_files, &$include_files, &$settings_search));
  703. loadLanguage(implode('+', $language_files));
  704. foreach ($include_files as $file)
  705. require_once($sourcedir . '/' . $file . '.php');
  706. /* This is the huge array that defines everything... it's a huge array of items formatted as follows:
  707. 0 = Language index (Can be array of indexes) to search through for this setting.
  708. 1 = URL for this indexes page.
  709. 2 = Help index for help associated with this item (If different from 0)
  710. */
  711. $search_data = array(
  712. // All the major sections of the forum.
  713. 'sections' => array(
  714. ),
  715. 'settings' => array(
  716. array('COPPA', 'area=regcenter;sa=settings'),
  717. array('CAPTCHA', 'area=securitysettings;sa=spam'),
  718. ),
  719. );
  720. // Go through the admin menu structure trying to find suitably named areas!
  721. foreach ($context[$context['admin_menu_name']]['sections'] as $section)
  722. {
  723. foreach ($section['areas'] as $menu_key => $menu_item)
  724. {
  725. $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
  726. if (!empty($menu_item['subsections']))
  727. foreach ($menu_item['subsections'] as $key => $sublabel)
  728. {
  729. if (isset($sublabel['label']))
  730. $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
  731. }
  732. }
  733. }
  734. foreach ($settings_search as $setting_area)
  735. {
  736. // Get a list of their variables.
  737. $config_vars = $setting_area[0](true);
  738. foreach ($config_vars as $var)
  739. if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch')))
  740. $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]);
  741. }
  742. $context['page_title'] = $txt['admin_search_results'];
  743. $context['search_results'] = array();
  744. $search_term = strtolower(un_htmlspecialchars($context['search_term']));
  745. // Go through all the search data trying to find this text!
  746. foreach ($search_data as $section => $data)
  747. {
  748. foreach ($data as $item)
  749. {
  750. $found = false;
  751. if (!is_array($item[0]))
  752. $item[0] = array($item[0]);
  753. foreach ($item[0] as $term)
  754. {
  755. 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))
  756. {
  757. $found = $term;
  758. break;
  759. }
  760. }
  761. if ($found)
  762. {
  763. // Format the name - and remove any descriptions the entry may have.
  764. $name = isset($txt[$found]) ? $txt[$found] : (isset($txt['setting_' . $found]) ? $txt['setting_' . $found] : $found);
  765. $name = preg_replace('~<(?:div|span)\sclass="smalltext">.+?</(?:div|span)>~', '', $name);
  766. $context['search_results'][] = array(
  767. '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] : '')),
  768. 'name' => $name,
  769. 'type' => $section,
  770. 'help' => shorten_subject(isset($item[2]) ? strip_tags($helptxt[$item[2]]) : (isset($helptxt[$found]) ? strip_tags($helptxt[$found]) : ''), 255),
  771. );
  772. }
  773. }
  774. }
  775. }
  776. /**
  777. * All this does is pass through to manage members.
  778. */
  779. function AdminSearchMember()
  780. {
  781. global $context, $sourcedir;
  782. require_once($sourcedir . '/ManageMembers.php');
  783. $_REQUEST['sa'] = 'query';
  784. $_POST['membername'] = un_htmlspecialchars($context['search_term']);
  785. $_POST['types'] = '';
  786. ViewMembers();
  787. }
  788. /**
  789. * This file allows the user to search the SM online manual for a little of help.
  790. * @todo wiki search
  791. */
  792. function AdminSearchOM()
  793. {
  794. global $context, $sourcedir;
  795. $context['doc_apiurl'] = 'http://wiki.simplemachines.org/api.php';
  796. $context['doc_scripturl'] = 'http://wiki.simplemachines.org/smf/';
  797. // Set all the parameters search might expect.
  798. $postVars = explode(' ', $context['search_term']);
  799. // Encode the search data.
  800. foreach ($postVars as $k => $v)
  801. $postVars[$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. // Demo URL:
  807. // http://wiki.simplemachines.org/api.php?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=template+eval
  808. $search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars);
  809. // If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
  810. if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?>\s*(<api>.+?</api>)~is', $search_results, $matches) != true)
  811. fatal_lang_error('cannot_connect_doc_site');
  812. $search_results = $matches[1];
  813. // Otherwise we simply walk through the XML and stick it in context for display.
  814. $context['search_results'] = array();
  815. require_once($sourcedir . '/Class-Package.php');
  816. // Get the results loaded into an array for processing!
  817. $results = new xmlArray($search_results, false);
  818. // Move through the api layer.
  819. if (!$results->exists('api'))
  820. fatal_lang_error('cannot_connect_doc_site');
  821. // Are there actually some results?
  822. if ($results->exists('api/query/search/p'))
  823. {
  824. $relevance = 0;
  825. foreach ($results->set('api/query/search/p') as $result)
  826. {
  827. $context['search_results'][$result->fetch('@title')] = array(
  828. 'title' => $result->fetch('@title'),
  829. 'relevance' => $relevance++,
  830. 'snippet' => str_replace('class=\'searchmatch\'', 'class="highlight"', un_htmlspecialchars($result->fetch('@snippet'))),
  831. );
  832. }
  833. }
  834. }
  835. /**
  836. * This function decides which log to load.
  837. */
  838. function AdminLogs()
  839. {
  840. global $sourcedir, $context, $txt, $scripturl;
  841. // These are the logs they can load.
  842. $log_functions = array(
  843. 'errorlog' => array('ManageErrors.php', 'ViewErrorLog'),
  844. 'adminlog' => array('Modlog.php', 'ViewModlog'),
  845. 'modlog' => array('Modlog.php', 'ViewModlog', 'disabled' => !in_array('ml', $context['admin_features'])),
  846. 'banlog' => array('ManageBans.php', 'BanLog'),
  847. 'spiderlog' => array('ManageSearchEngines.php', 'SpiderLogs'),
  848. 'tasklog' => array('ManageScheduledTasks.php', 'TaskLog'),
  849. 'pruning' => array('ManageSettings.php', 'ModifyPruningSettings'),
  850. );
  851. call_integration_hook('integrate_manage_logs', array(&$log_functions));
  852. $sub_action = isset($_REQUEST['sa']) && isset($log_functions[$_REQUEST['sa']]) && empty($log_functions[$_REQUEST['sa']]['disabled']) ? $_REQUEST['sa'] : 'errorlog';
  853. // If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
  854. if (!isset($_REQUEST['sa']))
  855. $_REQUEST['desc'] = true;
  856. // Setup some tab stuff.
  857. $context[$context['admin_menu_name']]['tab_data'] = array(
  858. 'title' => $txt['logs'],
  859. 'help' => '',
  860. 'description' => $txt['maintain_info'],
  861. 'tabs' => array(
  862. 'errorlog' => array(
  863. 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
  864. 'description' => sprintf($txt['errlog_desc'], $txt['remove']),
  865. ),
  866. 'adminlog' => array(
  867. 'description' => $txt['admin_log_desc'],
  868. ),
  869. 'modlog' => array(
  870. 'description' => $txt['moderation_log_desc'],
  871. ),
  872. 'banlog' => array(
  873. 'description' => $txt['ban_log_description'],
  874. ),
  875. 'spiderlog' => array(
  876. 'description' => $txt['spider_log_desc'],
  877. ),
  878. 'tasklog' => array(
  879. 'description' => $txt['scheduled_log_desc'],
  880. ),
  881. 'pruning' => array(
  882. 'description' => $txt['pruning_log_desc'],
  883. ),
  884. ),
  885. );
  886. require_once($sourcedir . '/' . $log_functions[$sub_action][0]);
  887. $log_functions[$sub_action][1]();
  888. }
  889. /**
  890. * This ends a admin session, requiring authentication to access the ACP again.
  891. */
  892. function AdminEndSession()
  893. {
  894. // This is so easy!
  895. unset($_SESSION['admin_time']);
  896. // Clean any admin tokens as well.
  897. foreach ($_SESSION['token'] as $key => $token)
  898. if (strpos($key, '-admin') !== false)
  899. unset($_SESSION['token'][$key]);
  900. redirectexit('?action=admin');
  901. }
  902. ?>