Xml.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 'previews' => array(
  27. 'function' => 'RetrievePreview',
  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 RetrievePreview()
  64. {
  65. global $context;
  66. $subActions = array(
  67. 'newspreview' => 'newspreview',
  68. );
  69. $context['sub_template'] = 'generic_xml';
  70. if (!isset($_POST['item']) || !in_array($_POST['item'], $subActions))
  71. return false;
  72. // echo $subActions[$_REQUEST['item']];die();
  73. $subActions[$_POST['item']]();
  74. }
  75. function newspreview()
  76. {
  77. global $context, $sourcedir, $smcFunc;
  78. require_once($sourcedir . '/Subs-Post.php');
  79. $errors = array();
  80. $news = !isset($_POST['news'])? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES);;
  81. if (empty($news))
  82. $errors[] = array('value' => 'no_news');
  83. else
  84. preparsecode($news);
  85. $context['xml_data'] = array(
  86. 'news' => array(
  87. 'identifier' => 'parsedNews',
  88. 'children' => array(
  89. array(
  90. 'value' => parse_bbc($news),
  91. ),
  92. ),
  93. ),
  94. 'errors' => array(
  95. 'identifier' => 'error',
  96. 'children' => $errors
  97. ),
  98. );
  99. }
  100. ?>