Admin.php 35 KB

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