PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/sources/admin/Admin.php

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