Admin.php 37 KB

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