Admin.php 36 KB

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