Xml.template.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2011 Simple Machines
  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>' . $txt['last_edit'] . ': ' . $context['message']['modified']['time'] . ' ' . $txt['by'] . ' ' . $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>' . $txt['last_edit'] . ': ' . $context['message']['modified']['time'] . ' ' . $txt['by'] . ' ' . $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']['messages']))
  89. foreach ($context['post_error']['messages'] 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_stats()
  120. {
  121. global $context, $settings, $options, $txt, $modSettings;
  122. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  123. <smf>';
  124. foreach ($context['yearly'] as $year)
  125. foreach ($year['months'] as $month);
  126. {
  127. echo '
  128. <month id="', $month['date']['year'], $month['date']['month'], '">';
  129. foreach ($month['days'] as $day)
  130. echo '
  131. <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'] . '"', ' />';
  132. echo '
  133. </month>';
  134. }
  135. echo '
  136. </smf>';
  137. }
  138. function template_split()
  139. {
  140. global $context, $settings, $options;
  141. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  142. <smf>
  143. <pageIndex section="not_selected" startFrom="', $context['not_selected']['start'], '"><![CDATA[', $context['not_selected']['page_index'], ']]></pageIndex>
  144. <pageIndex section="selected" startFrom="', $context['selected']['start'], '"><![CDATA[', $context['selected']['page_index'], ']]></pageIndex>';
  145. foreach ($context['changes'] as $change)
  146. {
  147. if ($change['type'] == 'remove')
  148. echo '
  149. <change id="', $change['id'], '" curAction="remove" section="', $change['section'], '" />';
  150. else
  151. echo '
  152. <change id="', $change['id'], '" curAction="insert" section="', $change['section'], '">
  153. <subject><![CDATA[', cleanXml($change['insert_value']['subject']), ']]></subject>
  154. <time><![CDATA[', cleanXml($change['insert_value']['time']), ']]></time>
  155. <body><![CDATA[', cleanXml($change['insert_value']['body']), ']]></body>
  156. <poster><![CDATA[', cleanXml($change['insert_value']['poster']), ']]></poster>
  157. </change>';
  158. }
  159. echo '
  160. </smf>';
  161. }
  162. // This is just to hold off some errors if people are stupid.
  163. if (!function_exists('template_button_strip'))
  164. {
  165. function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
  166. {
  167. }
  168. function template_menu()
  169. {
  170. }
  171. function theme_linktree()
  172. {
  173. }
  174. }
  175. function template_results()
  176. {
  177. global $context, $settings, $options, $txt;
  178. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  179. <smf>';
  180. if (empty($context['topics']))
  181. echo '
  182. <noresults>', $txt['search_no_results'], '</noresults>';
  183. else
  184. {
  185. echo '
  186. <results>';
  187. while ($topic = $context['get_topics']())
  188. {
  189. echo '
  190. <result>
  191. <id>', $topic['id'], '</id>
  192. <relevance>', $topic['relevance'], '</relevance>
  193. <board>
  194. <id>', $topic['board']['id'], '</id>
  195. <name>', cleanXml($topic['board']['name']), '</name>
  196. <href>', $topic['board']['href'], '</href>
  197. </board>
  198. <category>
  199. <id>', $topic['category']['id'], '</id>
  200. <name>', cleanXml($topic['category']['name']), '</name>
  201. <href>', $topic['category']['href'], '</href>
  202. </category>
  203. <messages>';
  204. foreach ($topic['matches'] as $message)
  205. {
  206. echo '
  207. <message>
  208. <id>', $message['id'], '</id>
  209. <subject><![CDATA[', cleanXml($message['subject_highlighted'] != '' ? $message['subject_highlighted'] : $message['subject']), ']]></subject>
  210. <body><![CDATA[', cleanXml($message['body_highlighted'] != '' ? $message['body_highlighted'] : $message['body']), ']]></body>
  211. <time>', $message['time'], '</time>
  212. <timestamp>', $message['timestamp'], '</timestamp>
  213. <start>', $message['start'], '</start>
  214. <author>
  215. <id>', $message['member']['id'], '</id>
  216. <name>', cleanXml($message['member']['name']), '</name>
  217. <href>', $message['member']['href'], '</href>
  218. </author>
  219. </message>';
  220. }
  221. echo '
  222. </messages>
  223. </result>';
  224. }
  225. echo '
  226. </results>';
  227. }
  228. echo '
  229. </smf>';
  230. }
  231. function template_jump_to()
  232. {
  233. global $context, $settings, $options;
  234. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  235. <smf>';
  236. foreach ($context['jump_to'] as $category)
  237. {
  238. echo '
  239. <item type="category" id="', $category['id'], '"><![CDATA[', cleanXml($category['name']), ']]></item>';
  240. foreach ($category['boards'] as $board)
  241. echo '
  242. <item type="board" id="', $board['id'], '" childlevel="', $board['child_level'], '"><![CDATA[', cleanXml($board['name']), ']]></item>';
  243. }
  244. echo '
  245. </smf>';
  246. }
  247. function template_message_icons()
  248. {
  249. global $context, $settings, $options;
  250. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  251. <smf>';
  252. foreach ($context['icons'] as $icon)
  253. echo '
  254. <icon value="', $icon['value'], '" url="', $icon['url'], '"><![CDATA[', cleanXml($icon['name']), ']]></icon>';
  255. echo '
  256. </smf>';
  257. }
  258. function template_check_username()
  259. {
  260. global $context, $settings, $options, $txt;
  261. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
  262. <smf>
  263. <username valid="', $context['valid_username'] ? 1 : 0, '">', cleanXml($context['checked_username']), '</username>
  264. </smf>';
  265. }
  266. // This prints XML in it's most generic form.
  267. function template_generic_xml()
  268. {
  269. global $context, $settings, $options, $txt;
  270. echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>';
  271. // Show the data.
  272. template_generic_xml_recursive($context['xml_data'], 'smf', '', -1);
  273. }
  274. // Recursive function for displaying generic XML data.
  275. function template_generic_xml_recursive($xml_data, $parent_ident, $child_ident, $level)
  276. {
  277. // This is simply for neat indentation.
  278. $level++;
  279. echo "\n" . str_repeat("\t", $level), '<', $parent_ident, '>';
  280. foreach ($xml_data as $key => $data)
  281. {
  282. // A group?
  283. if (is_array($data) && isset($data['identifier']))
  284. template_generic_xml_recursive($data['children'], $key, $data['identifier'], $level);
  285. // An item...
  286. elseif (is_array($data) && isset($data['value']))
  287. {
  288. echo "\n", str_repeat("\t", $level), '<', $child_ident;
  289. if (!empty($data['attributes']))
  290. foreach ($data['attributes'] as $k => $v)
  291. echo ' ' . $k . '="' . $v . '"';
  292. echo '><![CDATA[', cleanXml($data['value']), ']]></', $child_ident, '>';
  293. }
  294. }
  295. echo "\n", str_repeat("\t", $level), '</', $parent_ident, '>';
  296. }
  297. function template_webslice_header_above()
  298. {
  299. global $settings;
  300. echo '
  301. <link rel="stylesheet" href="', $settings['default_theme_url'], '/css/wireless.css" type="text/css" />';
  302. }
  303. function template_webslice_header_below()
  304. {
  305. }
  306. // This shows a webslice of the recent posts.
  307. function template_webslice_recent_posts()
  308. {
  309. global $context, $scripturl, $txt;
  310. echo '
  311. <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;">
  312. <div style="background-color: #080436; color: #ffffff; padding: 4px;">
  313. ', cleanXml($txt['recent_posts']), '
  314. </div>';
  315. $alternate = 0;
  316. foreach ($context['recent_posts_data'] as $item)
  317. {
  318. echo '
  319. <div style="background-color: ', $alternate ? '#ECEDF3' : '#F6F6F6', '; font-size: 90%; padding: 2px;">
  320. <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']), '
  321. </div>';
  322. $alternate = !$alternate;
  323. }
  324. echo '
  325. </div>
  326. <div style="width: 100%; height: 100%; border: 0; padding: 0; margin: 0 0 0 0; font: 100.01%/100% Verdana, Helvetica, sans-serif;">
  327. <div style="font-size: xx-small;" class="righttext">';
  328. if ($context['user']['is_guest'])
  329. echo '
  330. <a href="', $scripturl, '?action=login">', $txt['login'], '</a>';
  331. else
  332. echo '
  333. ', cleanXml($context['user']['name']), ', ', cleanXml($txt['msg_alert_you_have']), ' <a href="', $scripturl, '?action=pm">', cleanXml($context['user']['messages']), ' ', cleanXml($context['user']['messages'] != 1 ? $txt['msg_alert_messages'] : $txt['message_lowercase']), '</a>', cleanXml($txt['newmessages4'] . ' ' . $context['user']['unread_messages']), ' ', cleanXml($context['user']['unread_messages'] == 1 ? $txt['newmessages0'] : $txt['newmessages1']);
  334. echo '
  335. </div>
  336. </div>';
  337. }
  338. ?>