Admin.php 34 KB

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