This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
/
Xml.template.php
474 lines (405 loc) · 14.4 KB
/
Xml.template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2020 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 RC2
*/
/**
* This defines the XML for sending the body of a message
*/
function template_sendbody()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<message view="', $context['view'], '">', cleanXml($context['message']), '</message>
</smf>';
}
/**
* This defines the XML for the AJAX quote feature
*/
function template_quotefast()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<quote>', cleanXml($context['quote']['xml']), '</quote>
</smf>';
}
/**
* This defines the XML for the inline edit feature
*/
function template_modifyfast()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<subject><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>
<message id="msg_', $context['message']['id'], '"><![CDATA[', cleanXml($context['message']['body']), ']]></message>
<reason time="', $context['message']['reason']['time'], '" name="', $context['message']['reason']['name'], '"><![CDATA[', cleanXml($context['message']['reason']['text']), ']]></reason>
</smf>';
}
/**
* The XML for handling things when you're done editing a post inline
*/
function template_modifydone()
{
global $context, $txt;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<message id="msg_', $context['message']['id'], '">';
if (empty($context['message']['errors']))
{
// Build our string of info about when and why it was modified
$modified = empty($context['message']['modified']['time']) ? '' : sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']);
$modified .= empty($context['message']['modified']['reason']) ? '' : ' ' . sprintf($txt['last_edit_reason'], $context['message']['modified']['reason']);
echo '
<modified><![CDATA[', empty($modified) ? '' : cleanXml($modified), ']]></modified>
<subject is_first="', $context['message']['first_in_topic'] ? '1' : '0', '"><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>
<body><![CDATA[', $context['message']['body'], ']]></body>
<success><![CDATA[', $txt['quick_modify_message'], ']]></success>';
}
else
echo '
<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>';
echo '
</message>
</smf>';
}
/**
* This handles things when editing a topic's subject from the messageindex.
*/
function template_modifytopicdone()
{
global $context, $txt;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<message id="msg_', $context['message']['id'], '">';
if (empty($context['message']['errors']))
{
// Build our string of info about when and why it was modified
$modified = empty($context['message']['modified']['time']) ? '' : sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']);
$modified .= empty($context['message']['modified']['reason']) ? '' : sprintf($txt['last_edit_reason'], $context['message']['modified']['reason']);
echo '
<modified><![CDATA[', empty($modified) ? '' : cleanXml('« <em>' . $modified . '</em>»'), ']]></modified>';
if (!empty($context['message']['subject']))
echo '
<subject><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>';
}
else
echo '
<error in_subject="', $context['message']['error_in_subject'] ? '1' : '0', '"><![CDATA[', cleanXml(implode('<br />', $context['message']['errors'])), ']]></error>';
echo '
</message>
</smf>';
}
/**
* The massive XML for previewing posts.
*/
function template_post()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<preview>
<subject><![CDATA[', $context['preview_subject'], ']]></subject>
<body><![CDATA[', $context['preview_message'], ']]></body>
</preview>
<errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '" topic_locked="', $context['locked'] ? '1' : '0', '">';
if (!empty($context['post_error']))
foreach ($context['post_error'] as $message)
echo '
<error><![CDATA[', cleanXml($message), ']]></error>';
echo '
<caption name="guestname" class="', isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? 'error' : '', '" />
<caption name="email" class="', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? 'error' : '', '" />
<caption name="evtitle" class="', isset($context['post_error']['no_event']) ? 'error' : '', '" />
<caption name="subject" class="', isset($context['post_error']['no_subject']) ? 'error' : '', '" />
<caption name="question" class="', isset($context['post_error']['no_question']) ? 'error' : '', '" />', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? '
<post_error />' : '', '
</errors>
<last_msg>', isset($context['topic_last_message']) ? $context['topic_last_message'] : '0', '</last_msg>';
if (!empty($context['previous_posts']))
{
echo '
<new_posts>';
foreach ($context['previous_posts'] as $post)
echo '
<post id="', $post['id'], '">
<time><![CDATA[', $post['time'], ']]></time>
<poster><![CDATA[', cleanXml($post['poster']), ']]></poster>
<message><![CDATA[', cleanXml($post['message']), ']]></message>
<is_ignored>', $post['is_ignored'] ? '1' : '0', '</is_ignored>
</post>';
echo '
</new_posts>';
}
echo '
</smf>';
}
/**
* All the XML for previewing a PM
*/
function template_pm()
{
global $context, $txt;
// @todo something could be removed...otherwise it can be merged again with template_post
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<preview>
<subject><![CDATA[', $txt['preview'], ' - ', !empty($context['preview_subject']) ? $context['preview_subject'] : $txt['no_subject'], ']]></subject>
<body><![CDATA[', $context['preview_message'], ']]></body>
</preview>
<errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '">';
if (!empty($context['post_error']['messages']))
foreach ($context['post_error']['messages'] as $message)
echo '
<error><![CDATA[', cleanXml($message), ']]></error>';
echo '
<caption name="to" class="', isset($context['post_error']['no_to']) ? 'error' : '', '" />
<caption name="bbc" class="', isset($context['post_error']['no_bbc']) ? 'error' : '', '" />
<caption name="subject" class="', isset($context['post_error']['no_subject']) ? 'error' : '', '" />
<caption name="question" class="', isset($context['post_error']['no_question']) ? 'error' : '', '" />', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? '
<post_error />' : '', '
</errors>';
echo '
</smf>';
}
/**
* The XML for previewing a warning
*/
function template_warning()
{
global $context;
// @todo something could be removed...otherwise it can be merged again with template_post
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<preview>
<subject><![CDATA[', $context['preview_subject'], ']]></subject>
<body><![CDATA[', $context['preview_message'], ']]></body>
</preview>
<errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '">';
if (!empty($context['post_error']['messages']))
foreach ($context['post_error']['messages'] as $message)
echo '
<error><![CDATA[', cleanXml($message), ']]></error>';
echo '
</errors>';
echo '
</smf>';
}
/**
* The XML for hiding/showing stats sections via AJAX
*/
function template_stats()
{
global $context, $modSettings;
if (empty($context['yearly']))
return;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>';
foreach ($context['yearly'] as $year)
foreach ($year['months'] as $month)
{
echo '
<month id="', $month['date']['year'], $month['date']['month'], '">';
foreach ($month['days'] as $day)
echo '
<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'] . '"', ' />';
echo '
</month>';
}
echo '
</smf>';
}
/**
* The XML for selecting items to split
*/
function template_split()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<pageIndex section="not_selected" startFrom="', $context['not_selected']['start'], '"><![CDATA[', $context['not_selected']['page_index'], ']]></pageIndex>
<pageIndex section="selected" startFrom="', $context['selected']['start'], '"><![CDATA[', $context['selected']['page_index'], ']]></pageIndex>';
foreach ($context['changes'] as $change)
{
if ($change['type'] == 'remove')
echo '
<change id="', $change['id'], '" curAction="remove" section="', $change['section'], '" />';
else
echo '
<change id="', $change['id'], '" curAction="insert" section="', $change['section'], '">
<subject><![CDATA[', cleanXml($change['insert_value']['subject']), ']]></subject>
<time><![CDATA[', cleanXml($change['insert_value']['time']), ']]></time>
<body><![CDATA[', cleanXml($change['insert_value']['body']), ']]></body>
<poster><![CDATA[', cleanXml($change['insert_value']['poster']), ']]></poster>
</change>';
}
echo '
</smf>';
}
/**
* This is just to hold off some errors if people are stupid.
*/
if (!function_exists('template_button_strip'))
{
function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
{
}
function template_menu()
{
}
function theme_linktree()
{
}
}
/**
* XML for search results
*/
function template_results()
{
global $context, $txt;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>';
if (empty($context['topics']))
echo '
<noresults>', $txt['search_no_results'], '</noresults>';
else
{
echo '
<results>';
while ($topic = $context['get_topics']())
{
echo '
<result>
<id>', $topic['id'], '</id>
<relevance>', $topic['relevance'], '</relevance>
<board>
<id>', $topic['board']['id'], '</id>
<name>', cleanXml($topic['board']['name']), '</name>
<href>', $topic['board']['href'], '</href>
</board>
<category>
<id>', $topic['category']['id'], '</id>
<name>', cleanXml($topic['category']['name']), '</name>
<href>', $topic['category']['href'], '</href>
</category>
<messages>';
foreach ($topic['matches'] as $message)
{
echo '
<message>
<id>', $message['id'], '</id>
<subject><![CDATA[', cleanXml($message['subject_highlighted'] != '' ? $message['subject_highlighted'] : $message['subject']), ']]></subject>
<body><![CDATA[', cleanXml($message['body_highlighted'] != '' ? $message['body_highlighted'] : $message['body']), ']]></body>
<time>', $message['time'], '</time>
<timestamp>', $message['timestamp'], '</timestamp>
<start>', $message['start'], '</start>
<author>
<id>', $message['member']['id'], '</id>
<name>', cleanXml($message['member']['name']), '</name>
<href>', $message['member']['href'], '</href>
</author>
</message>';
}
echo '
</messages>
</result>';
}
echo '
</results>';
}
echo '
</smf>';
}
/**
* The XML for the Jump To box
*/
function template_jump_to()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>';
foreach ($context['jump_to'] as $category)
{
echo '
<item type="category" id="', $category['id'], '"><![CDATA[', cleanXml($category['name']), ']]></item>';
foreach ($category['boards'] as $board)
echo '
<item type="board" id="', $board['id'], '" childlevel="', $board['child_level'], '"><![CDATA[', cleanXml($board['name']), ']]></item>';
}
echo '
</smf>';
}
/**
* The XML for displaying a column of message icons and selecting one via AJAX
*/
function template_message_icons()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>';
foreach ($context['icons'] as $icon)
echo '
<icon value="', $icon['value'], '" url="', $icon['url'], '"><![CDATA[', cleanXml($icon['name']), ']]></icon>';
echo '
</smf>';
}
/**
* The XML for instantly showing whether a username is valid on the registration page
*/
function template_check_username()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<username valid="', $context['valid_username'] ? 1 : 0, '">', cleanXml($context['checked_username']), '</username>
</smf>';
}
/**
* This prints XML in its most generic form.
*/
function template_generic_xml()
{
global $context;
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>';
// Show the data.
template_generic_xml_recursive($context['xml_data'], 'smf', '', -1);
}
/**
* Recursive function for displaying generic XML data.
*
* @param array $xml_data An array of XML data
* @param string $parent_ident The parent tag
* @param string $child_ident The child tag
* @param int $level How many levels to indent the code
*/
function template_generic_xml_recursive($xml_data, $parent_ident, $child_ident, $level)
{
// This is simply for neat indentation.
$level++;
echo "\n" . str_repeat("\t", $level), '<', $parent_ident, '>';
foreach ($xml_data as $key => $data)
{
// A group?
if (is_array($data) && isset($data['identifier']))
template_generic_xml_recursive($data['children'], $key, $data['identifier'], $level);
// An item...
elseif (is_array($data) && isset($data['value']))
{
echo "\n", str_repeat("\t", $level), '<', $child_ident;
if (!empty($data['attributes']))
foreach ($data['attributes'] as $k => $v)
echo ' ' . $k . '="' . $v . '"';
echo '><![CDATA[', cleanXml($data['value']), ']]></', $child_ident, '>';
}
}
echo "\n", str_repeat("\t", $level), '</', $parent_ident, '>';
}
?>