Admin.php 35 KB

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