Xml.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * Maintains all XML-based interaction (mainly XMLhttp)
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2011 Simple Machines
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('Hacking attempt...');
  16. function XMLhttpMain()
  17. {
  18. loadTemplate('Xml');
  19. $sub_actions = array(
  20. 'jumpto' => array(
  21. 'function' => 'GetJumpTo',
  22. ),
  23. 'messageicons' => array(
  24. 'function' => 'ListMessageIcons',
  25. ),
  26. 'corefeatures' => array(
  27. 'function' => 'EnableCoreFeatures',
  28. ),
  29. );
  30. if (!isset($_REQUEST['sa'], $sub_actions[$_REQUEST['sa']]))
  31. fatal_lang_error('no_access', false);
  32. $sub_actions[$_REQUEST['sa']]['function']();
  33. }
  34. /**
  35. * Get a list of boards and categories used for the jumpto dropdown.
  36. */
  37. function GetJumpTo()
  38. {
  39. global $user_info, $context, $smcFunc, $sourcedir;
  40. // Find the boards/cateogories they can see.
  41. require_once($sourcedir . '/Subs-MessageIndex.php');
  42. $boardListOptions = array(
  43. 'use_permissions' => true,
  44. 'selected_board' => isset($context['current_board']) ? $context['current_board'] : 0,
  45. );
  46. $context['jump_to'] = getBoardList($boardListOptions);
  47. // Make the board safe for display.
  48. foreach ($context['jump_to'] as $id_cat => $cat)
  49. {
  50. $context['jump_to'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name']));
  51. foreach ($cat['boards'] as $id_board => $board)
  52. $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name']));
  53. }
  54. $context['sub_template'] = 'jump_to';
  55. }
  56. function ListMessageIcons()
  57. {
  58. global $context, $sourcedir, $board;
  59. require_once($sourcedir . '/Subs-Editor.php');
  60. $context['icons'] = getMessageIcons($board);
  61. $context['sub_template'] = 'message_icons';
  62. }
  63. function EnableCoreFeatures()
  64. {
  65. global $context, $smcFunc, $sourcedir, $modSettings, $txt;
  66. $context['xml_data'] = array();
  67. // Just in case, maybe we don't need it
  68. loadLanguage('Errors');
  69. $errors = array();
  70. $returns = array();
  71. $tokens = array();
  72. if (allowedTo('admin_forum'))
  73. {
  74. $validation = validateSession();
  75. if (empty($validation))
  76. {
  77. require_once($sourcedir . '/ManageSettings.php');
  78. $result = ModifyCoreFeatures();
  79. if (empty($result))
  80. {
  81. $id = isset($_POST['feature_id']) ? $_POST['feature_id'] : '';
  82. if (!empty($id) && isset($context['features'][$id]))
  83. {
  84. $feature = $context['features'][$id];
  85. $returns[] = array(
  86. 'value' => (!empty($_POST['feature_' . $id]) && $feature['url'] ? '<a href="' . $feature['url'] . '">' . $feature['title'] . '</a>' : $feature['title']),
  87. );
  88. createToken('admin-core', 'post');
  89. $tokens = array(
  90. array(
  91. 'value' => $context['admin-core_token'],
  92. 'attributes' => array('type' => 'token_var'),
  93. ),
  94. array(
  95. 'value' => $context['admin-core_token_var'],
  96. 'attributes' => array('type' => 'token'),
  97. ),
  98. );
  99. }
  100. else
  101. {
  102. $errors[] = array(
  103. 'value' => $txt['feature_no_exists'],
  104. );
  105. }
  106. }
  107. else
  108. {
  109. $errors[] = array(
  110. 'value' => $txt[$result],
  111. );
  112. }
  113. }
  114. else
  115. {
  116. $errors[] = array(
  117. 'value' => $txt[$validation],
  118. );
  119. }
  120. }
  121. else
  122. {
  123. $errors[] = array(
  124. 'value' => $txt['cannot_admin_forum']
  125. );
  126. }
  127. $context['sub_template'] = 'generic_xml';
  128. $context['xml_data'] = array (
  129. 'corefeatures' => array (
  130. 'identifier' => 'corefeature',
  131. 'children' => $returns,
  132. ),
  133. 'tokens' => array (
  134. 'identifier' => 'token',
  135. 'children' => $tokens,
  136. ),
  137. 'errors' => array (
  138. 'identifier' => 'error',
  139. 'children' => $errors,
  140. ),
  141. );
  142. }
  143. ?>