Xml.template.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2014 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;
  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;
  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;
  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, $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, $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, $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, $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_warning()
  151. {
  152. global $context, $txt;
  153. // @todo something could be removed...otherwise it can be merged again with template_post
  154. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  155. <smf>
  156. <preview>
  157. <subject><![CDATA[', $context['preview_subject'], ']]></subject>
  158. <body><![CDATA[', $context['preview_message'], ']]></body>
  159. </preview>
  160. <errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '">';
  161. if (!empty($context['post_error']['messages']))
  162. foreach ($context['post_error']['messages'] as $message)
  163. echo '
  164. <error><![CDATA[', cleanXml($message), ']]></error>';
  165. echo '
  166. </errors>';
  167. echo '
  168. </smf>';
  169. }
  170. function template_stats()
  171. {
  172. global $context, $txt, $modSettings;
  173. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  174. <smf>';
  175. foreach ($context['yearly'] as $year)
  176. foreach ($year['months'] as $month)
  177. {
  178. echo '
  179. <month id="', $month['date']['year'], $month['date']['month'], '">';
  180. foreach ($month['days'] as $day)
  181. echo '
  182. <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'] . '"', ' />';
  183. echo '
  184. </month>';
  185. }
  186. echo '
  187. </smf>';
  188. }
  189. function template_split()
  190. {
  191. global $context;
  192. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  193. <smf>
  194. <pageIndex section="not_selected" startFrom="', $context['not_selected']['start'], '"><![CDATA[', $context['not_selected']['page_index'], ']]></pageIndex>
  195. <pageIndex section="selected" startFrom="', $context['selected']['start'], '"><![CDATA[', $context['selected']['page_index'], ']]></pageIndex>';
  196. foreach ($context['changes'] as $change)
  197. {
  198. if ($change['type'] == 'remove')
  199. echo '
  200. <change id="', $change['id'], '" curAction="remove" section="', $change['section'], '" />';
  201. else
  202. echo '
  203. <change id="', $change['id'], '" curAction="insert" section="', $change['section'], '">
  204. <subject><![CDATA[', cleanXml($change['insert_value']['subject']), ']]></subject>
  205. <time><![CDATA[', cleanXml($change['insert_value']['time']), ']]></time>
  206. <body><![CDATA[', cleanXml($change['insert_value']['body']), ']]></body>
  207. <poster><![CDATA[', cleanXml($change['insert_value']['poster']), ']]></poster>
  208. </change>';
  209. }
  210. echo '
  211. </smf>';
  212. }
  213. // This is just to hold off some errors if people are stupid.
  214. if (!function_exists('template_button_strip'))
  215. {
  216. function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
  217. {
  218. }
  219. function template_menu()
  220. {
  221. }
  222. function theme_linktree()
  223. {
  224. }
  225. }
  226. function template_results()
  227. {
  228. global $context, $txt;
  229. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  230. <smf>';
  231. if (empty($context['topics']))
  232. echo '
  233. <noresults>', $txt['search_no_results'], '</noresults>';
  234. else
  235. {
  236. echo '
  237. <results>';
  238. while ($topic = $context['get_topics']())
  239. {
  240. echo '
  241. <result>
  242. <id>', $topic['id'], '</id>
  243. <relevance>', $topic['relevance'], '</relevance>
  244. <board>
  245. <id>', $topic['board']['id'], '</id>
  246. <name>', cleanXml($topic['board']['name']), '</name>
  247. <href>', $topic['board']['href'], '</href>
  248. </board>
  249. <category>
  250. <id>', $topic['category']['id'], '</id>
  251. <name>', cleanXml($topic['category']['name']), '</name>
  252. <href>', $topic['category']['href'], '</href>
  253. </category>
  254. <messages>';
  255. foreach ($topic['matches'] as $message)
  256. {
  257. echo '
  258. <message>
  259. <id>', $message['id'], '</id>
  260. <subject><![CDATA[', cleanXml($message['subject_highlighted'] != '' ? $message['subject_highlighted'] : $message['subject']), ']]></subject>
  261. <body><![CDATA[', cleanXml($message['body_highlighted'] != '' ? $message['body_highlighted'] : $message['body']), ']]></body>
  262. <time>', $message['time'], '</time>
  263. <timestamp>', $message['timestamp'], '</timestamp>
  264. <start>', $message['start'], '</start>
  265. <author>
  266. <id>', $message['member']['id'], '</id>
  267. <name>', cleanXml($message['member']['name']), '</name>
  268. <href>', $message['member']['href'], '</href>
  269. </author>
  270. </message>';
  271. }
  272. echo '
  273. </messages>
  274. </result>';
  275. }
  276. echo '
  277. </results>';
  278. }
  279. echo '
  280. </smf>';
  281. }
  282. function template_jump_to()
  283. {
  284. global $context;
  285. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  286. <smf>';
  287. foreach ($context['jump_to'] as $category)
  288. {
  289. echo '
  290. <item type="category" id="', $category['id'], '"><![CDATA[', cleanXml($category['name']), ']]></item>';
  291. foreach ($category['boards'] as $board)
  292. echo '
  293. <item type="board" id="', $board['id'], '" childlevel="', $board['child_level'], '"><![CDATA[', cleanXml($board['name']), ']]></item>';
  294. }
  295. echo '
  296. </smf>';
  297. }
  298. function template_message_icons()
  299. {
  300. global $context;
  301. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  302. <smf>';
  303. foreach ($context['icons'] as $icon)
  304. echo '
  305. <icon value="', $icon['value'], '" url="', $icon['url'], '"><![CDATA[', cleanXml($icon['name']), ']]></icon>';
  306. echo '
  307. </smf>';
  308. }
  309. function template_check_username()
  310. {
  311. global $context;
  312. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  313. <smf>
  314. <username valid="', $context['valid_username'] ? 1 : 0, '">', cleanXml($context['checked_username']), '</username>
  315. </smf>';
  316. }
  317. // This prints XML in it's most generic form.
  318. function template_generic_xml()
  319. {
  320. global $context;
  321. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>';
  322. // Show the data.
  323. template_generic_xml_recursive($context['xml_data'], 'smf', '', -1);
  324. }
  325. // Recursive function for displaying generic XML data.
  326. function template_generic_xml_recursive($xml_data, $parent_ident, $child_ident, $level)
  327. {
  328. // This is simply for neat indentation.
  329. $level++;
  330. echo "\n" . str_repeat("\t", $level), '<', $parent_ident, '>';
  331. foreach ($xml_data as $key => $data)
  332. {
  333. // A group?
  334. if (is_array($data) && isset($data['identifier']))
  335. template_generic_xml_recursive($data['children'], $key, $data['identifier'], $level);
  336. // An item...
  337. elseif (is_array($data) && isset($data['value']))
  338. {
  339. echo "\n", str_repeat("\t", $level), '<', $child_ident;
  340. if (!empty($data['attributes']))
  341. foreach ($data['attributes'] as $k => $v)
  342. echo ' ' . $k . '="' . $v . '"';
  343. echo '><![CDATA[', cleanXml($data['value']), ']]></', $child_ident, '>';
  344. }
  345. }
  346. echo "\n", str_repeat("\t", $level), '</', $parent_ident, '>';
  347. }
  348. function template_webslice_header_above()
  349. {
  350. global $settings;
  351. echo '
  352. <link rel="stylesheet" href="', $settings['default_theme_url'], '/css/wireless.css" type="text/css" />';
  353. }
  354. function template_webslice_header_below()
  355. {
  356. }
  357. // This shows a webslice of the recent posts.
  358. function template_webslice_recent_posts()
  359. {
  360. global $context, $scripturl, $txt;
  361. echo '
  362. <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;">
  363. <div style="background-color: #080436; color: #ffffff; padding: 4px;">
  364. ', cleanXml($txt['recent_posts']), '
  365. </div>';
  366. $alternate = 0;
  367. foreach ($context['recent_posts_data'] as $item)
  368. {
  369. echo '
  370. <div style="background-color: ', $alternate ? '#ECEDF3' : '#F6F6F6', '; font-size: 90%; padding: 2px;">
  371. <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'])), '
  372. </div>';
  373. $alternate = !$alternate;
  374. }
  375. echo '
  376. </div>
  377. <div style="width: 100%; height: 100%; border: 0; padding: 0; margin: 0 0 0 0; font: 100.01%/100% Verdana, Helvetica, sans-serif;">
  378. <div style="font-size: xx-small;" class="righttext">';
  379. if ($context['user']['is_guest'])
  380. echo '
  381. <a href="', $scripturl, '?action=login">', $txt['login'], '</a>';
  382. else
  383. echo '
  384. ', 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'])))) : '');
  385. echo '
  386. </div>
  387. </div>';
  388. }
  389. ?>