Admin.php 37 KB

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