Admin.php 37 KB

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