Xml.template.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2013 Simple Machines and individual contributors
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. function template_sendbody()
  13. {
  14. global $context, $settings, $options, $txt;
  15. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  16. <smf>
  17. <message view="', $context['view'], '">', cleanXml($context['message']), '</message>
  18. </smf>';
  19. }
  20. function template_quotefast()
  21. {
  22. global $context, $settings, $options, $txt;
  23. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  24. <smf>
  25. <quote>', cleanXml($context['quote']['xml']), '</quote>
  26. </smf>';
  27. }
  28. function template_modifyfast()
  29. {
  30. global $context, $settings, $options, $txt;
  31. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  32. <smf>
  33. <subject><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>
  34. <message id="msg_', $context['message']['id'], '"><![CDATA[', cleanXml($context['message']['body']), ']]></message>
  35. </smf>';
  36. }
  37. function template_modifydone()
  38. {
  39. global $context, $settings, $options, $txt;
  40. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  41. <smf>
  42. <message id="msg_', $context['message']['id'], '">';
  43. if (empty($context['message']['errors']))
  44. {
  45. echo '
  46. <modified><![CDATA[', empty($context['message']['modified']['time']) ? '' : cleanXml('&#171; <em>' . sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']) . '</em> &#187;'), ']]></modified>
  47. <subject is_first="', $context['message']['first_in_topic'] ? '1' : '0', '"><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>
  48. <body><![CDATA[', $context['message']['body'], ']]></body>';
  49. }
  50. else
  51. echo '
  52. <error in_subject="', $context['message']['error_in_subject'] ? '1' : '0', '" in_body="', cleanXml($context['message']['error_in_body']) ? '1' : '0', '"><![CDATA[', implode('<br />', $context['message']['errors']), ']]></error>';
  53. echo '
  54. </message>
  55. </smf>';
  56. }
  57. function template_modifytopicdone()
  58. {
  59. global $context, $settings, $options, $txt;
  60. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  61. <smf>
  62. <message id="msg_', $context['message']['id'], '">';
  63. if (empty($context['message']['errors']))
  64. {
  65. echo '
  66. <modified><![CDATA[', empty($context['message']['modified']['time']) ? '' : cleanXml('&#171; <em>' . sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']) . '</em> &#187;'), ']]></modified>';
  67. if (!empty($context['message']['subject']))
  68. echo '
  69. <subject><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>';
  70. }
  71. else
  72. echo '
  73. <error in_subject="', $context['message']['error_in_subject'] ? '1' : '0', '"><![CDATA[', cleanXml(implode('<br />', $context['message']['errors'])), ']]></error>';
  74. echo '
  75. </message>
  76. </smf>';
  77. }
  78. function template_post()
  79. {
  80. global $context, $settings, $options, $txt;
  81. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  82. <smf>
  83. <preview>
  84. <subject><![CDATA[', $context['preview_subject'], ']]></subject>
  85. <body><![CDATA[', $context['preview_message'], ']]></body>
  86. </preview>
  87. <errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '" topic_locked="', $context['locked'] ? '1' : '0', '">';
  88. if (!empty($context['post_error']))
  89. foreach ($context['post_error'] as $message)
  90. echo '
  91. <error><![CDATA[', cleanXml($message), ']]></error>';
  92. echo '
  93. <caption name="guestname" class="', isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? 'error' : '', '" />
  94. <caption name="email" class="', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? 'error' : '', '" />
  95. <caption name="evtitle" class="', isset($context['post_error']['no_event']) ? 'error' : '', '" />
  96. <caption name="subject" class="', isset($context['post_error']['no_subject']) ? 'error' : '', '" />
  97. <caption name="question" class="', isset($context['post_error']['no_question']) ? 'error' : '', '" />', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? '
  98. <post_error />' : '', '
  99. </errors>
  100. <last_msg>', isset($context['topic_last_message']) ? $context['topic_last_message'] : '0', '</last_msg>';
  101. if (!empty($context['previous_posts']))
  102. {
  103. echo '
  104. <new_posts>';
  105. foreach ($context['previous_posts'] as $post)
  106. echo '
  107. <post id="', $post['id'], '">
  108. <time><![CDATA[', $post['time'], ']]></time>
  109. <poster><![CDATA[', cleanXml($post['poster']), ']]></poster>
  110. <message><![CDATA[', cleanXml($post['message']), ']]></message>
  111. <is_ignored>', $post['is_ignored'] ? '1' : '0', '</is_ignored>
  112. </post>';
  113. echo '
  114. </new_posts>';
  115. }
  116. echo '
  117. </smf>';
  118. }
  119. function template_pm()
  120. {
  121. global $context, $settings, $options, $txt;
  122. // @todo something could be removed...otherwise it can be merged again with template_post
  123. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  124. <smf>
  125. <preview>
  126. <subject><![CDATA[', $context['preview_subject'], ']]></subject>
  127. <body><![CDATA[', $context['preview_message'], ']]></body>
  128. </preview>
  129. <errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '">';
  130. if (!empty($context['post_error']['messages']))
  131. foreach ($context['post_error']['messages'] as $message)
  132. echo '
  133. <error><![CDATA[', cleanXml($message), ']]></error>';
  134. echo '
  135. <caption name="to" class="', isset($context['post_error']['no_to']) ? 'error' : '', '" />
  136. <caption name="bbc" class="', isset($context['post_error']['no_bbc']) ? 'error' : '', '" />
  137. <caption name="subject" class="', isset($context['post_error']['no_subject']) ? 'error' : '', '" />
  138. <caption name="question" class="', isset($context['post_error']['no_question']) ? 'error' : '', '" />', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? '
  139. <post_error />' : '', '
  140. </errors>';
  141. echo '
  142. </smf>';
  143. }
  144. function template_stats()
  145. {
  146. global $context, $settings, $options, $txt, $modSettings;
  147. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  148. <smf>';
  149. foreach ($context['yearly'] as $year)
  150. foreach ($year['months'] as $month)
  151. {
  152. echo '
  153. <month id="', $month['date']['year'], $month['date']['month'], '">';
  154. foreach ($month['days'] as $day)
  155. echo '
  156. <day date="', $day['year'], '-', $day['month'], '-', $day['day'], '" new_topics="', $day['new_topics'], '" new_posts="', $day['new_posts'], '" new_members="', $day['new_members'], '" most_members_online="', $day['most_members_online'], '"', empty($modSettings['hitStats']) ? '' : ' hits="' . $day['hits'] . '"', ' />';
  157. echo '
  158. </month>';
  159. }
  160. echo '
  161. </smf>';
  162. }
  163. function template_split()
  164. {
  165. global $context, $settings, $options;
  166. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  167. <smf>
  168. <pageIndex section="not_selected" startFrom="', $context['not_selected']['start'], '"><![CDATA[', $context['not_selected']['page_index'], ']]></pageIndex>
  169. <pageIndex section="selected" startFrom="', $context['selected']['start'], '"><![CDATA[', $context['selected']['page_index'], ']]></pageIndex>';
  170. foreach ($context['changes'] as $change)
  171. {
  172. if ($change['type'] == 'remove')
  173. echo '
  174. <change id="', $change['id'], '" curAction="remove" section="', $change['section'], '" />';
  175. else
  176. echo '
  177. <change id="', $change['id'], '" curAction="insert" section="', $change['section'], '">
  178. <subject><![CDATA[', cleanXml($change['insert_value']['subject']), ']]></subject>
  179. <time><![CDATA[', cleanXml($change['insert_value']['time']), ']]></time>
  180. <body><![CDATA[', cleanXml($change['insert_value']['body']), ']]></body>
  181. <poster><![CDATA[', cleanXml($change['insert_value']['poster']), ']]></poster>
  182. </change>';
  183. }
  184. echo '
  185. </smf>';
  186. }
  187. // This is just to hold off some errors if people are stupid.
  188. if (!function_exists('template_button_strip'))
  189. {
  190. function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
  191. {
  192. }
  193. function template_menu()
  194. {
  195. }
  196. function theme_linktree()
  197. {
  198. }
  199. }
  200. function template_results()
  201. {
  202. global $context, $settings, $options, $txt;
  203. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  204. <smf>';
  205. if (empty($context['topics']))
  206. echo '
  207. <noresults>', $txt['search_no_results'], '</noresults>';
  208. else
  209. {
  210. echo '
  211. <results>';
  212. while ($topic = $context['get_topics']())
  213. {
  214. echo '
  215. <result>
  216. <id>', $topic['id'], '</id>
  217. <relevance>', $topic['relevance'], '</relevance>
  218. <board>
  219. <id>', $topic['board']['id'], '</id>
  220. <name>', cleanXml($topic['board']['name']), '</name>
  221. <href>', $topic['board']['href'], '</href>
  222. </board>
  223. <category>
  224. <id>', $topic['category']['id'], '</id>
  225. <name>', cleanXml($topic['category']['name']), '</name>
  226. <href>', $topic['category']['href'], '</href>
  227. </category>
  228. <messages>';
  229. foreach ($topic['matches'] as $message)
  230. {
  231. echo '
  232. <message>
  233. <id>', $message['id'], '</id>
  234. <subject><![CDATA[', cleanXml($message['subject_highlighted'] != '' ? $message['subject_highlighted'] : $message['subject']), ']]></subject>
  235. <body><![CDATA[', cleanXml($message['body_highlighted'] != '' ? $message['body_highlighted'] : $message['body']), ']]></body>
  236. <time>', $message['time'], '</time>
  237. <timestamp>', $message['timestamp'], '</timestamp>
  238. <start>', $message['start'], '</start>
  239. <author>
  240. <id>', $message['member']['id'], '</id>
  241. <name>', cleanXml($message['member']['name']), '</name>
  242. <href>', $message['member']['href'], '</href>
  243. </author>
  244. </message>';
  245. }
  246. echo '
  247. </messages>
  248. </result>';
  249. }
  250. echo '
  251. </results>';
  252. }
  253. echo '
  254. </smf>';
  255. }
  256. function template_jump_to()
  257. {
  258. global $context, $settings, $options;
  259. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  260. <smf>';
  261. foreach ($context['jump_to'] as $category)
  262. {
  263. echo '
  264. <item type="category" id="', $category['id'], '"><![CDATA[', cleanXml($category['name']), ']]></item>';
  265. foreach ($category['boards'] as $board)
  266. echo '
  267. <item type="board" id="', $board['id'], '" childlevel="', $board['child_level'], '"><![CDATA[', cleanXml($board['name']), ']]></item>';
  268. }
  269. echo '
  270. </smf>';
  271. }
  272. function template_message_icons()
  273. {
  274. global $context, $settings, $options;
  275. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  276. <smf>';
  277. foreach ($context['icons'] as $icon)
  278. echo '
  279. <icon value="', $icon['value'], '" url="', $icon['url'], '"><![CDATA[', cleanXml($icon['name']), ']]></icon>';
  280. echo '
  281. </smf>';
  282. }
  283. function template_check_username()
  284. {
  285. global $context, $settings, $options, $txt;
  286. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  287. <smf>
  288. <username valid="', $context['valid_username'] ? 1 : 0, '">', cleanXml($context['checked_username']), '</username>
  289. </smf>';
  290. }
  291. // This prints XML in it's most generic form.
  292. function template_generic_xml()
  293. {
  294. global $context, $settings, $options, $txt;
  295. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>';
  296. // Show the data.
  297. template_generic_xml_recursive($context['xml_data'], 'smf', '', -1);
  298. }
  299. // Recursive function for displaying generic XML data.
  300. function template_generic_xml_recursive($xml_data, $parent_ident, $child_ident, $level)
  301. {
  302. // This is simply for neat indentation.
  303. $level++;
  304. echo "\n" . str_repeat("\t", $level), '<', $parent_ident, '>';
  305. foreach ($xml_data as $key => $data)
  306. {
  307. // A group?
  308. if (is_array($data) && isset($data['identifier']))
  309. template_generic_xml_recursive($data['children'], $key, $data['identifier'], $level);
  310. // An item...
  311. elseif (is_array($data) && isset($data['value']))
  312. {
  313. echo "\n", str_repeat("\t", $level), '<', $child_ident;
  314. if (!empty($data['attributes']))
  315. foreach ($data['attributes'] as $k => $v)
  316. echo ' ' . $k . '="' . $v . '"';
  317. echo '><![CDATA[', cleanXml($data['value']), ']]></', $child_ident, '>';
  318. }
  319. }
  320. echo "\n", str_repeat("\t", $level), '</', $parent_ident, '>';
  321. }
  322. function template_webslice_header_above()
  323. {
  324. global $settings;
  325. echo '
  326. <link rel="stylesheet" href="', $settings['default_theme_url'], '/css/wireless.css" type="text/css" />';
  327. }
  328. function template_webslice_header_below()
  329. {
  330. }
  331. // This shows a webslice of the recent posts.
  332. function template_webslice_recent_posts()
  333. {
  334. global $context, $scripturl, $txt;
  335. echo '
  336. <div style="width: 100%; height: 100%; border: 1px solid black; padding: 0; margin: 0 0 0 0; font: 100.01%/100% Verdana, Helvetica, sans-serif;">
  337. <div style="background-color: #080436; color: #ffffff; padding: 4px;">
  338. ', cleanXml($txt['recent_posts']), '
  339. </div>';
  340. $alternate = 0;
  341. foreach ($context['recent_posts_data'] as $item)
  342. {
  343. echo '
  344. <div style="background-color: ', $alternate ? '#ECEDF3' : '#F6F6F6', '; font-size: 90%; padding: 2px;">
  345. <strong><a href="', $item['link'], '">', cleanXml($item['subject']), '</a></strong> ', cleanXml($txt['by']), ' ', cleanXml(!empty($item['poster']['link']) ? '<a href="' . $item['poster']['link'] . '">' . $item['poster']['name'] . '</a>' : $item['poster']['name']), '
  346. </div>';
  347. $alternate = !$alternate;
  348. }
  349. echo '
  350. </div>
  351. <div style="width: 100%; height: 100%; border: 0; padding: 0; margin: 0 0 0 0; font: 100.01%/100% Verdana, Helvetica, sans-serif;">
  352. <div style="font-size: xx-small;" class="righttext">';
  353. if ($context['user']['is_guest'])
  354. echo '
  355. <a href="', $scripturl, '?action=login">', $txt['login'], '</a>';
  356. else
  357. echo '
  358. ', cleanXml($context['user']['name']), cleanXml(!empty($context['can_pm_read']) ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '');
  359. echo '
  360. </div>
  361. </div>';
  362. }
  363. ?>