2
0

Xml.template.php 15 KB

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