Admin.php 37 KB

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