PageRenderTime 35ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 1ms

/sources/controllers/Xml.controller.php

https://github.com/Arantor/Elkarte
PHP | 399 lines | 309 code | 52 blank | 38 comment | 31 complexity | e33874418dc326d1b07701aed25cf771 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. * Maintains all XML-based interaction (mainly XMLhttp)
  16. *
  17. */
  18. if (!defined('ELKARTE'))
  19. die('No access...');
  20. /**
  21. * Main function for action=xmlhttp.
  22. */
  23. function action_xmlhttp()
  24. {
  25. loadTemplate('Xml');
  26. $sub_actions = array(
  27. 'jumpto' => array(
  28. 'function' => 'action_jumpto',
  29. ),
  30. 'messageicons' => array(
  31. 'function' => 'action_messageicons',
  32. ),
  33. 'corefeatures' => array(
  34. 'function' => 'action_corefeatures',
  35. ),
  36. 'previews' => array(
  37. 'function' => 'action_previews',
  38. ),
  39. );
  40. // Easy adding of sub actions
  41. call_integration_hook('integrate_xmlhttp', array($sub_actions));
  42. if (!isset($_REQUEST['sa'], $sub_actions[$_REQUEST['sa']]))
  43. fatal_lang_error('no_access', false);
  44. $sub_actions[$_REQUEST['sa']]['function']();
  45. }
  46. /**
  47. * Get a list of boards and categories used for the jumpto dropdown.
  48. */
  49. function action_jumpto()
  50. {
  51. global $user_info, $context, $smcFunc;
  52. // Find the boards/cateogories they can see.
  53. require_once(SUBSDIR . '/MessageIndex.subs.php');
  54. $boardListOptions = array(
  55. 'use_permissions' => true,
  56. 'selected_board' => isset($context['current_board']) ? $context['current_board'] : 0,
  57. );
  58. $context['jump_to'] = getBoardList($boardListOptions);
  59. // Make the board safe for display.
  60. foreach ($context['jump_to'] as $id_cat => $cat)
  61. {
  62. $context['jump_to'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name']));
  63. foreach ($cat['boards'] as $id_board => $board)
  64. $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name']));
  65. }
  66. $context['sub_template'] = 'jump_to';
  67. }
  68. function action_messageicons()
  69. {
  70. global $context, $board;
  71. require_once(SUBSDIR . '/Editor.subs.php');
  72. $context['icons'] = getMessageIcons($board);
  73. $context['sub_template'] = 'message_icons';
  74. }
  75. function action_corefeatures()
  76. {
  77. global $context, $smcFunc, $modSettings, $txt, $settings;
  78. $context['xml_data'] = array();
  79. // Just in case, maybe we don't need it
  80. loadLanguage('Errors');
  81. // We need (at least) this to ensure that mod files are included
  82. if (!empty($modSettings['integrate_admin_include']))
  83. {
  84. $admin_includes = explode(',', $modSettings['integrate_admin_include']);
  85. foreach ($admin_includes as $include)
  86. {
  87. $include = strtr(trim($include), array('BOARDDIR' => BOARDDIR, 'SOURCEDIR' => SOURCEDIR, '$themedir' => $settings['theme_dir']));
  88. if (file_exists($include))
  89. require_once($include);
  90. }
  91. }
  92. $errors = array();
  93. $returns = array();
  94. $tokens = array();
  95. if (allowedTo('admin_forum'))
  96. {
  97. $validation = validateSession();
  98. if (empty($validation))
  99. {
  100. require_once(ADMINDIR . '/ManageSettings.php');
  101. $result = ModifyCoreFeatures();
  102. if (empty($result))
  103. {
  104. $id = isset($_POST['feature_id']) ? $_POST['feature_id'] : '';
  105. if (!empty($id) && isset($context['features'][$id]))
  106. {
  107. $feature = $context['features'][$id];
  108. $returns[] = array(
  109. 'value' => (!empty($_POST['feature_' . $id]) && $feature['url'] ? '<a href="' . $feature['url'] . '">' . $feature['title'] . '</a>' : $feature['title']),
  110. );
  111. createToken('admin-core', 'post');
  112. $tokens = array(
  113. array(
  114. 'value' => $context['admin-core_token'],
  115. 'attributes' => array('type' => 'token_var'),
  116. ),
  117. array(
  118. 'value' => $context['admin-core_token_var'],
  119. 'attributes' => array('type' => 'token'),
  120. ),
  121. );
  122. }
  123. else
  124. {
  125. $errors[] = array(
  126. 'value' => $txt['feature_no_exists'],
  127. );
  128. }
  129. }
  130. else
  131. {
  132. $errors[] = array(
  133. 'value' => $txt[$result],
  134. );
  135. }
  136. }
  137. else
  138. {
  139. $errors[] = array(
  140. 'value' => $txt[$validation],
  141. );
  142. }
  143. }
  144. else
  145. {
  146. $errors[] = array(
  147. 'value' => $txt['cannot_admin_forum']
  148. );
  149. }
  150. $context['sub_template'] = 'generic_xml';
  151. $context['xml_data'] = array (
  152. 'corefeatures' => array (
  153. 'identifier' => 'corefeature',
  154. 'children' => $returns,
  155. ),
  156. 'tokens' => array (
  157. 'identifier' => 'token',
  158. 'children' => $tokens,
  159. ),
  160. 'errors' => array (
  161. 'identifier' => 'error',
  162. 'children' => $errors,
  163. ),
  164. );
  165. }
  166. function action_previews()
  167. {
  168. global $context;
  169. $items = array(
  170. 'newspreview',
  171. 'newsletterpreview',
  172. 'sig_preview',
  173. 'warning_preview',
  174. );
  175. $context['sub_template'] = 'generic_xml';
  176. if (!isset($_POST['item']) || !in_array($_POST['item'], $items))
  177. return false;
  178. $_POST['item']();
  179. }
  180. function newspreview()
  181. {
  182. global $context, $smcFunc;
  183. require_once(SUBSDIR . '/Post.subs.php');
  184. $errors = array();
  185. $news = !isset($_POST['news'])? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES);
  186. if (empty($news))
  187. $errors[] = array('value' => 'no_news');
  188. else
  189. preparsecode($news);
  190. $context['xml_data'] = array(
  191. 'news' => array(
  192. 'identifier' => 'parsedNews',
  193. 'children' => array(
  194. array(
  195. 'value' => parse_bbc($news),
  196. ),
  197. ),
  198. ),
  199. 'errors' => array(
  200. 'identifier' => 'error',
  201. 'children' => $errors
  202. ),
  203. );
  204. }
  205. function newsletterpreview()
  206. {
  207. global $context, $smcFunc, $txt;
  208. require_once(SUBSDIR . '/Mail.subs.php');
  209. loadLanguage('Errors');
  210. $context['post_error']['messages'] = array();
  211. $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
  212. $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0;
  213. if (empty($_POST['subject']))
  214. $context['post_error']['messages'][] = $txt['error_no_subject'];
  215. if (empty($_POST['message']))
  216. $context['post_error']['messages'][] = $txt['error_no_message'];
  217. prepareMailingForPreview();
  218. $context['sub_template'] = 'pm';
  219. }
  220. function sig_preview()
  221. {
  222. global $context, $smcFunc, $txt, $user_info;
  223. require_once(SUBSDIR . '/Profile.subs.php');
  224. loadLanguage('Profile');
  225. loadLanguage('Errors');
  226. $user = isset($_POST['user']) ? (int) $_POST['user'] : 0;
  227. $is_owner = $user == $user_info['id'];
  228. // @todo Temporary
  229. // Borrowed from loadAttachmentContext in Display.controller.php
  230. $can_change = $is_owner ? allowedTo(array('profile_extra_any', 'profile_extra_own')) : allowedTo('profile_extra_any');
  231. $errors = array();
  232. if (!empty($user) && $can_change)
  233. {
  234. $request = $smcFunc['db_query']('', '
  235. SELECT signature
  236. FROM {db_prefix}members
  237. WHERE id_member = {int:id_member}
  238. LIMIT 1',
  239. array(
  240. 'id_member' => $user,
  241. )
  242. );
  243. list($current_signature) = $smcFunc['db_fetch_row']($request);
  244. $smcFunc['db_free_result']($request);
  245. censorText($current_signature);
  246. $current_signature = parse_bbc($current_signature, true, 'sig' . $user);
  247. $preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
  248. $validation = profileValidateSignature($preview_signature);
  249. if ($validation !== true && $validation !== false)
  250. $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error'));
  251. censorText($preview_signature);
  252. $preview_signature = parse_bbc($preview_signature, true, 'sig' . $user);
  253. }
  254. elseif (!$can_change)
  255. {
  256. if ($is_owner)
  257. $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error'));
  258. else
  259. $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error'));
  260. }
  261. else
  262. $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error'));
  263. $context['xml_data']['signatures'] = array(
  264. 'identifier' => 'signature',
  265. 'children' => array()
  266. );
  267. if (isset($current_signature))
  268. $context['xml_data']['signatures']['children'][] = array(
  269. 'value' => $current_signature,
  270. 'attributes' => array('type' => 'current'),
  271. );
  272. if (isset($preview_signature))
  273. $context['xml_data']['signatures']['children'][] = array(
  274. 'value' => $preview_signature,
  275. 'attributes' => array('type' => 'preview'),
  276. );
  277. if (!empty($errors))
  278. $context['xml_data']['errors'] = array(
  279. 'identifier' => 'error',
  280. 'children' => array_merge(
  281. array(
  282. array(
  283. 'value' => $txt['profile_errors_occurred'],
  284. 'attributes' => array('type' => 'errors_occurred'),
  285. ),
  286. ),
  287. $errors
  288. ),
  289. );
  290. }
  291. function warning_preview()
  292. {
  293. global $context, $smcFunc, $txt, $user_info, $scripturl, $mbname;
  294. require_once(SUBSDIR . '/Post.subs.php');
  295. loadLanguage('Errors');
  296. loadLanguage('ModerationCenter');
  297. $user = isset($_POST['user']) ? (int) $_POST['user'] : 0;
  298. $context['post_error']['messages'] = array();
  299. if (allowedTo('issue_warning'))
  300. {
  301. $warning_body = !empty($_POST['body']) ? trim(censorText($_POST['body'])) : '';
  302. $context['preview_subject'] = !empty($_POST['title']) ? trim($smcFunc['htmlspecialchars']($_POST['title'])) : '';
  303. if (isset($_POST['issuing']))
  304. {
  305. if (empty($_POST['title']) || empty($_POST['body']))
  306. $context['post_error']['messages'][] = $txt['warning_notify_blank'];
  307. }
  308. else
  309. {
  310. if (empty($_POST['title']))
  311. $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title'];
  312. if (empty($_POST['body']))
  313. $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body'];
  314. // Add in few replacements.
  315. /**
  316. * These are the defaults:
  317. * - {MEMBER} - Member Name. => current user for review
  318. * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced
  319. * - {FORUMNAME} - Forum Name.
  320. * - {SCRIPTURL} - Web address of forum.
  321. * - {REGARDS} - Standard email sign-off.
  322. */
  323. $find = array(
  324. '{MEMBER}',
  325. '{FORUMNAME}',
  326. '{SCRIPTURL}',
  327. '{REGARDS}',
  328. );
  329. $replace = array(
  330. $user_info['name'],
  331. $mbname,
  332. $scripturl,
  333. $txt['regards_team'],
  334. );
  335. $warning_body = str_replace($find, $replace, $warning_body);
  336. }
  337. if (!empty($_POST['body']))
  338. {
  339. preparsecode($warning_body);
  340. $warning_body = parse_bbc($warning_body, true);
  341. }
  342. $context['preview_message'] = $warning_body;
  343. }
  344. else
  345. $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error'));
  346. $context['sub_template'] = 'pm';
  347. }