Xml.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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',
  68. 'newsletterpreview',
  69. 'sig_preview',
  70. 'warning_preview',
  71. );
  72. $context['sub_template'] = 'generic_xml';
  73. if (!isset($_POST['item']) || !in_array($_POST['item'], $subActions))
  74. return false;
  75. $_POST['item']();
  76. }
  77. function newspreview()
  78. {
  79. global $context, $sourcedir, $smcFunc;
  80. require_once($sourcedir . '/Subs-Post.php');
  81. $errors = array();
  82. $news = !isset($_POST['news'])? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES);
  83. if (empty($news))
  84. $errors[] = array('value' => 'no_news');
  85. else
  86. preparsecode($news);
  87. $context['xml_data'] = array(
  88. 'news' => array(
  89. 'identifier' => 'parsedNews',
  90. 'children' => array(
  91. array(
  92. 'value' => parse_bbc($news),
  93. ),
  94. ),
  95. ),
  96. 'errors' => array(
  97. 'identifier' => 'error',
  98. 'children' => $errors
  99. ),
  100. );
  101. }
  102. function newsletterpreview()
  103. {
  104. global $context, $sourcedir, $smcFunc, $txt;
  105. require_once($sourcedir . '/Subs-Post.php');
  106. require_once($sourcedir . '/ManageNews.php');
  107. loadLanguage('Errors');
  108. $context['post_error']['messages'] = array();
  109. $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
  110. $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0;
  111. if (empty($_POST['subject']))
  112. $context['post_error']['messages'][] = $txt['error_no_subject'];
  113. if (empty($_POST['message']))
  114. $context['post_error']['messages'][] = $txt['error_no_message'];
  115. prepareMailingForPreview();
  116. $context['sub_template'] = 'pm';
  117. }
  118. function sig_preview()
  119. {
  120. global $context, $sourcedir, $smcFunc, $txt, $user_info;
  121. require_once($sourcedir . '/Profile-Modify.php');
  122. loadLanguage('Profile');
  123. loadLanguage('Errors');
  124. $user = isset($_POST['user']) ? (int) $_POST['user'] : 0;
  125. $is_owner = $user == $user_info['id'];
  126. // @todo Temporary
  127. // Borrowed from loadAttachmentContext in Display.php
  128. $can_change = $is_owner ? allowedTo(array('profile_extra_any', 'profile_extra_own')) : allowedTo('profile_extra_any');
  129. $errors = array();
  130. if (!empty($user) && $can_change)
  131. {
  132. $request = $smcFunc['db_query']('', '
  133. SELECT signature
  134. FROM {db_prefix}members
  135. WHERE id_member = {int:id_member}
  136. LIMIT 1',
  137. array(
  138. 'id_member' => $user,
  139. )
  140. );
  141. list($current_signature) = $smcFunc['db_fetch_row']($request);
  142. $smcFunc['db_free_result']($request);
  143. censorText($current_signature);
  144. $current_signature = parse_bbc($current_signature, true, 'sig' . $user);
  145. $preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
  146. $validation = profileValidateSignature($preview_signature);
  147. if ($validation !== true && $validation !== false)
  148. $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error'));
  149. censorText($preview_signature);
  150. $preview_signature = parse_bbc($preview_signature, true, 'sig' . $user);
  151. }
  152. elseif (!$can_change)
  153. {
  154. if ($is_owner)
  155. $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error'));
  156. else
  157. $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error'));
  158. }
  159. else
  160. $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error'));
  161. $context['xml_data']['signatures'] = array(
  162. 'identifier' => 'signature',
  163. 'children' => array()
  164. );
  165. if (isset($current_signature))
  166. $context['xml_data']['signatures']['children'][] = array(
  167. 'value' => $current_signature,
  168. 'attributes' => array('type' => 'current'),
  169. );
  170. if (isset($preview_signature))
  171. $context['xml_data']['signatures']['children'][] = array(
  172. 'value' => $preview_signature,
  173. 'attributes' => array('type' => 'preview'),
  174. );
  175. if (!empty($errors))
  176. $context['xml_data']['errors'] = array(
  177. 'identifier' => 'error',
  178. 'children' => array_merge(
  179. array(
  180. array(
  181. 'value' => $txt['profile_errors_occurred'],
  182. 'attributes' => array('type' => 'errors_occurred'),
  183. ),
  184. ),
  185. $errors
  186. ),
  187. );
  188. }
  189. function warning_preview()
  190. {
  191. global $context, $sourcedir, $smcFunc, $txt, $user_info, $scripturl, $mbname;
  192. require_once($sourcedir . '/Subs-Post.php');
  193. loadLanguage('Errors');
  194. loadLanguage('ModerationCenter');
  195. $user = isset($_POST['user']) ? (int) $_POST['user'] : 0;
  196. $context['post_error']['messages'] = array();
  197. if (allowedTo('issue_warning'))
  198. {
  199. $warning_body = !empty($_POST['body']) ? trim(censorText($_POST['body'])) : '';
  200. $context['preview_subject'] = !empty($_POST['title']) ? trim($smcFunc['htmlspecialchars']($_POST['title'])) : '';
  201. if (isset($_POST['issuing']))
  202. {
  203. if (empty($_POST['title']) || empty($_POST['body']))
  204. $context['post_error']['messages'][] = $txt['warning_notify_blank'];
  205. }
  206. else
  207. {
  208. if (empty($_POST['title']))
  209. $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title'];
  210. if (empty($_POST['body']))
  211. $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body'];
  212. // Add in few replacements.
  213. /**
  214. * These are the defaults:
  215. * - {MEMBER} - Member Name. => current user for review
  216. * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced
  217. * - {FORUMNAME} - Forum Name.
  218. * - {SCRIPTURL} - Web address of forum.
  219. * - {REGARDS} - Standard email sign-off.
  220. */
  221. $find = array(
  222. '{MEMBER}',
  223. '{FORUMNAME}',
  224. '{SCRIPTURL}',
  225. '{REGARDS}',
  226. );
  227. $replace = array(
  228. $user_info['name'],
  229. $mbname,
  230. $scripturl,
  231. $txt['regards_team'],
  232. );
  233. $warning_body = str_replace($find, $replace, $warning_body);
  234. }
  235. if (!empty($_POST['body']))
  236. {
  237. preparsecode($warning_body);
  238. $warning_body = parse_bbc($warning_body, true);
  239. }
  240. $context['preview_message'] = $warning_body;
  241. }
  242. else
  243. $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error'));
  244. $context['sub_template'] = 'pm';
  245. }
  246. ?>