Chris@76
|
1 <?php
|
Chris@76
|
2
|
Chris@76
|
3 /**
|
Chris@76
|
4 * Simple Machines Forum (SMF)
|
Chris@76
|
5 *
|
Chris@76
|
6 * @package SMF
|
Chris@76
|
7 * @author Simple Machines http://www.simplemachines.org
|
Chris@76
|
8 * @copyright 2011 Simple Machines
|
Chris@76
|
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
|
Chris@76
|
10 *
|
Chris@76
|
11 * @version 2.0
|
Chris@76
|
12 */
|
Chris@76
|
13
|
Chris@76
|
14 if (!defined('SMF'))
|
Chris@76
|
15 die('Hacking attempt...');
|
Chris@76
|
16
|
Chris@76
|
17 /* This file contains the files necessary to display news as an XML feed.
|
Chris@76
|
18
|
Chris@76
|
19 void ShowXmlFeed()
|
Chris@76
|
20 - is called to output xml information.
|
Chris@76
|
21 - can be passed four subactions which decide what is output: 'recent'
|
Chris@76
|
22 for recent posts, 'news' for news topics, 'members' for recently
|
Chris@76
|
23 registered members, and 'profile' for a member's profile.
|
Chris@76
|
24 - To display a member's profile, a user id has to be given. (;u=1)
|
Chris@76
|
25 - uses the Stats language file.
|
Chris@76
|
26 - outputs an rss feed instead of a proprietary one if the 'type' get
|
Chris@76
|
27 parameter is 'rss' or 'rss2'.
|
Chris@76
|
28 - does not use any templates, sub templates, or template layers.
|
Chris@76
|
29 - is accessed via ?action=.xml.
|
Chris@76
|
30
|
Chris@76
|
31 void dumpTags(array data, int indentation, string tag = use_array,
|
Chris@76
|
32 string format)
|
Chris@76
|
33 - formats data retrieved in other functions into xml format.
|
Chris@76
|
34 - additionally formats data based on the specific format passed.
|
Chris@76
|
35 - the data parameter is the array to output as xml data.
|
Chris@76
|
36 - indentation is the amount of indentation to use.
|
Chris@76
|
37 - if a tag is specified, it will be used instead of the keys of data.
|
Chris@76
|
38 - this function is recursively called to handle sub arrays of data.
|
Chris@76
|
39
|
Chris@76
|
40 array getXmlMembers(string format)
|
Chris@76
|
41 - is called to retrieve list of members from database.
|
Chris@76
|
42 - the array will be generated to match the format.
|
Chris@76
|
43 - returns array of data.
|
Chris@76
|
44
|
Chris@76
|
45 array getXmlNews(string format)
|
Chris@76
|
46 - is called to retrieve news topics from database.
|
Chris@76
|
47 - the array will be generated to match the format.
|
Chris@76
|
48 - returns array of topics.
|
Chris@76
|
49
|
Chris@76
|
50 array getXmlRecent(string format)
|
Chris@76
|
51 - is called to retrieve list of recent topics.
|
Chris@76
|
52 - the array will be generated to match the format.
|
Chris@76
|
53 - returns an array of recent posts.
|
Chris@76
|
54
|
Chris@76
|
55 array getXmlProfile(string format)
|
Chris@76
|
56 - is called to retrieve profile information for member into array.
|
Chris@76
|
57 - the array will be generated to match the format.
|
Chris@76
|
58 - returns an array of data.
|
Chris@76
|
59 */
|
Chris@76
|
60
|
Chris@76
|
61 // Show an xml file representing recent information or a profile.
|
Chris@76
|
62 function ShowXmlFeed()
|
Chris@76
|
63 {
|
Chris@76
|
64 global $board, $board_info, $context, $scripturl, $txt, $modSettings, $user_info;
|
Chris@76
|
65 global $query_this_board, $smcFunc, $forum_version, $cdata_override;
|
Chris@76
|
66
|
Chris@76
|
67 // If it's not enabled, die.
|
Chris@76
|
68 if (empty($modSettings['xmlnews_enable']))
|
Chris@76
|
69 obExit(false);
|
Chris@76
|
70
|
Chris@76
|
71 loadLanguage('Stats');
|
Chris@76
|
72
|
Chris@76
|
73 // Default to latest 5. No more than 255, please.
|
Chris@76
|
74 $_GET['limit'] = empty($_GET['limit']) || (int) $_GET['limit'] < 1 ? 5 : min((int) $_GET['limit'], 255);
|
Chris@76
|
75
|
Chris@76
|
76 // Handle the cases where a board, boards, or category is asked for.
|
Chris@76
|
77 $query_this_board = 1;
|
Chris@76
|
78 $context['optimize_msg'] = array(
|
Chris@76
|
79 'highest' => 'm.id_msg <= b.id_last_msg',
|
Chris@76
|
80 );
|
Chris@76
|
81 if (!empty($_REQUEST['c']) && empty($board))
|
Chris@76
|
82 {
|
Chris@76
|
83 $_REQUEST['c'] = explode(',', $_REQUEST['c']);
|
Chris@76
|
84 foreach ($_REQUEST['c'] as $i => $c)
|
Chris@76
|
85 $_REQUEST['c'][$i] = (int) $c;
|
Chris@76
|
86
|
Chris@76
|
87 if (count($_REQUEST['c']) == 1)
|
Chris@76
|
88 {
|
Chris@76
|
89 $request = $smcFunc['db_query']('', '
|
Chris@76
|
90 SELECT name
|
Chris@76
|
91 FROM {db_prefix}categories
|
Chris@76
|
92 WHERE id_cat = {int:current_category}',
|
Chris@76
|
93 array(
|
Chris@76
|
94 'current_category' => (int) $_REQUEST['c'][0],
|
Chris@76
|
95 )
|
Chris@76
|
96 );
|
Chris@76
|
97 list ($feed_title) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
98 $smcFunc['db_free_result']($request);
|
Chris@76
|
99
|
Chris@76
|
100 $feed_title = ' - ' . strip_tags($feed_title);
|
Chris@76
|
101 }
|
Chris@76
|
102
|
Chris@76
|
103 $request = $smcFunc['db_query']('', '
|
Chris@76
|
104 SELECT b.id_board, b.num_posts
|
Chris@76
|
105 FROM {db_prefix}boards AS b
|
Chris@76
|
106 WHERE b.id_cat IN ({array_int:current_category_list})
|
Chris@76
|
107 AND {query_see_board}',
|
Chris@76
|
108 array(
|
Chris@76
|
109 'current_category_list' => $_REQUEST['c'],
|
Chris@76
|
110 )
|
Chris@76
|
111 );
|
Chris@76
|
112 $total_cat_posts = 0;
|
Chris@76
|
113 $boards = array();
|
Chris@76
|
114 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
115 {
|
Chris@76
|
116 $boards[] = $row['id_board'];
|
Chris@76
|
117 $total_cat_posts += $row['num_posts'];
|
Chris@76
|
118 }
|
Chris@76
|
119 $smcFunc['db_free_result']($request);
|
Chris@76
|
120
|
Chris@76
|
121 if (!empty($boards))
|
Chris@76
|
122 $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
|
Chris@76
|
123
|
Chris@76
|
124 // Try to limit the number of messages we look through.
|
Chris@76
|
125 if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
|
Chris@76
|
126 $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
|
Chris@76
|
127 }
|
Chris@76
|
128 elseif (!empty($_REQUEST['boards']))
|
Chris@76
|
129 {
|
Chris@76
|
130 $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
|
Chris@76
|
131 foreach ($_REQUEST['boards'] as $i => $b)
|
Chris@76
|
132 $_REQUEST['boards'][$i] = (int) $b;
|
Chris@76
|
133
|
Chris@76
|
134 $request = $smcFunc['db_query']('', '
|
Chris@76
|
135 SELECT b.id_board, b.num_posts, b.name
|
Chris@76
|
136 FROM {db_prefix}boards AS b
|
Chris@76
|
137 WHERE b.id_board IN ({array_int:board_list})
|
Chris@76
|
138 AND {query_see_board}
|
Chris@76
|
139 LIMIT ' . count($_REQUEST['boards']),
|
Chris@76
|
140 array(
|
Chris@76
|
141 'board_list' => $_REQUEST['boards'],
|
Chris@76
|
142 )
|
Chris@76
|
143 );
|
Chris@76
|
144
|
Chris@76
|
145 // Either the board specified doesn't exist or you have no access.
|
Chris@76
|
146 $num_boards = $smcFunc['db_num_rows']($request);
|
Chris@76
|
147 if ($num_boards == 0)
|
Chris@76
|
148 fatal_lang_error('no_board');
|
Chris@76
|
149
|
Chris@76
|
150 $total_posts = 0;
|
Chris@76
|
151 $boards = array();
|
Chris@76
|
152 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
153 {
|
Chris@76
|
154 if ($num_boards == 1)
|
Chris@76
|
155 $feed_title = ' - ' . strip_tags($row['name']);
|
Chris@76
|
156
|
Chris@76
|
157 $boards[] = $row['id_board'];
|
Chris@76
|
158 $total_posts += $row['num_posts'];
|
Chris@76
|
159 }
|
Chris@76
|
160 $smcFunc['db_free_result']($request);
|
Chris@76
|
161
|
Chris@76
|
162 if (!empty($boards))
|
Chris@76
|
163 $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
|
Chris@76
|
164
|
Chris@76
|
165 // The more boards, the more we're going to look through...
|
Chris@76
|
166 if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
|
Chris@76
|
167 $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
|
Chris@76
|
168 }
|
Chris@76
|
169 elseif (!empty($board))
|
Chris@76
|
170 {
|
Chris@76
|
171 $request = $smcFunc['db_query']('', '
|
Chris@76
|
172 SELECT num_posts
|
Chris@76
|
173 FROM {db_prefix}boards
|
Chris@76
|
174 WHERE id_board = {int:current_board}
|
Chris@76
|
175 LIMIT 1',
|
Chris@76
|
176 array(
|
Chris@76
|
177 'current_board' => $board,
|
Chris@76
|
178 )
|
Chris@76
|
179 );
|
Chris@76
|
180 list ($total_posts) = $smcFunc['db_fetch_row']($request);
|
Chris@76
|
181 $smcFunc['db_free_result']($request);
|
Chris@76
|
182
|
Chris@76
|
183 $feed_title = ' - ' . strip_tags($board_info['name']);
|
Chris@76
|
184
|
Chris@76
|
185 $query_this_board = 'b.id_board = ' . $board;
|
Chris@76
|
186
|
Chris@76
|
187 // Try to look through just a few messages, if at all possible.
|
Chris@76
|
188 if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
|
Chris@76
|
189 $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
|
Chris@76
|
190 }
|
Chris@76
|
191 else
|
Chris@76
|
192 {
|
Chris@76
|
193 $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
|
Chris@76
|
194 AND b.id_board != ' . $modSettings['recycle_board'] : '');
|
Chris@76
|
195 $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 100 - $_GET['limit'] * 5);
|
Chris@76
|
196 }
|
Chris@76
|
197
|
Chris@76
|
198 // Show in rss or proprietary format?
|
Chris@76
|
199 $xml_format = isset($_GET['type']) && in_array($_GET['type'], array('smf', 'rss', 'rss2', 'atom', 'rdf', 'webslice')) ? $_GET['type'] : 'smf';
|
Chris@76
|
200
|
Chris@76
|
201 // !!! Birthdays?
|
Chris@76
|
202
|
Chris@76
|
203 // List all the different types of data they can pull.
|
Chris@76
|
204 $subActions = array(
|
Chris@76
|
205 'recent' => array('getXmlRecent', 'recent-post'),
|
Chris@76
|
206 'news' => array('getXmlNews', 'article'),
|
Chris@76
|
207 'members' => array('getXmlMembers', 'member'),
|
Chris@76
|
208 'profile' => array('getXmlProfile', null),
|
Chris@76
|
209 );
|
Chris@76
|
210 if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
|
Chris@76
|
211 $_GET['sa'] = 'recent';
|
Chris@76
|
212
|
Chris@76
|
213 //!!! Temp - webslices doesn't do everything yet.
|
Chris@76
|
214 if ($xml_format == 'webslice' && $_GET['sa'] != 'recent')
|
Chris@76
|
215 $xml_format = 'rss2';
|
Chris@76
|
216 // If this is webslices we kinda cheat - we allow a template that we call direct for the HTML, and we override the CDATA.
|
Chris@76
|
217 elseif ($xml_format == 'webslice')
|
Chris@76
|
218 {
|
Chris@76
|
219 $context['user'] += $user_info;
|
Chris@76
|
220 $cdata_override = true;
|
Chris@76
|
221 loadTemplate('Xml');
|
Chris@76
|
222 }
|
Chris@76
|
223
|
Chris@76
|
224 // We only want some information, not all of it.
|
Chris@76
|
225 $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
|
Chris@76
|
226 foreach (array('board', 'boards', 'c') as $var)
|
Chris@76
|
227 if (isset($_REQUEST[$var]))
|
Chris@76
|
228 $cachekey[] = $_REQUEST[$var];
|
Chris@76
|
229 $cachekey = md5(serialize($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
|
Chris@76
|
230 $cache_t = microtime();
|
Chris@76
|
231
|
Chris@76
|
232 // Get the associative array representing the xml.
|
Chris@76
|
233 if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
|
Chris@76
|
234 $xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
|
Chris@76
|
235 if (empty($xml))
|
Chris@76
|
236 {
|
Chris@76
|
237 $xml = $subActions[$_GET['sa']][0]($xml_format);
|
Chris@76
|
238
|
Chris@76
|
239 if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
|
Chris@76
|
240 || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
|
Chris@76
|
241 cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
|
Chris@76
|
242 }
|
Chris@76
|
243
|
Chris@76
|
244 $feed_title = htmlspecialchars(strip_tags($context['forum_name'])) . (isset($feed_title) ? $feed_title : '');
|
Chris@76
|
245
|
Chris@76
|
246 // This is an xml file....
|
Chris@76
|
247 ob_end_clean();
|
Chris@76
|
248 if (!empty($modSettings['enableCompressedOutput']))
|
Chris@76
|
249 @ob_start('ob_gzhandler');
|
Chris@76
|
250 else
|
Chris@76
|
251 ob_start();
|
Chris@76
|
252
|
Chris@76
|
253 if ($xml_format == 'smf' || isset($_REQUEST['debug']))
|
Chris@76
|
254 header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
|
Chris@76
|
255 elseif ($xml_format == 'rss' || $xml_format == 'rss2' || $xml_format == 'webslice')
|
Chris@76
|
256 header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
|
Chris@76
|
257 elseif ($xml_format == 'atom')
|
Chris@76
|
258 header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
|
Chris@76
|
259 elseif ($xml_format == 'rdf')
|
Chris@76
|
260 header('Content-Type: ' . ($context['browser']['is_ie'] ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
|
Chris@76
|
261
|
Chris@76
|
262 // First, output the xml header.
|
Chris@76
|
263 echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>';
|
Chris@76
|
264
|
Chris@76
|
265 // Are we outputting an rss feed or one with more information?
|
Chris@76
|
266 if ($xml_format == 'rss' || $xml_format == 'rss2')
|
Chris@76
|
267 {
|
Chris@76
|
268 // Start with an RSS 2.0 header.
|
Chris@76
|
269 echo '
|
Chris@76
|
270 <rss version=', $xml_format == 'rss2' ? '"2.0"' : '"0.92"', ' xml:lang="', strtr($txt['lang_locale'], '_', '-'), '">
|
Chris@76
|
271 <channel>
|
Chris@76
|
272 <title>', $feed_title, '</title>
|
Chris@76
|
273 <link>', $scripturl, '</link>
|
Chris@76
|
274 <description><![CDATA[', strip_tags($txt['xml_rss_desc']), ']]></description>';
|
Chris@76
|
275
|
Chris@76
|
276 // Output all of the associative array, start indenting with 2 tabs, and name everything "item".
|
Chris@76
|
277 dumpTags($xml, 2, 'item', $xml_format);
|
Chris@76
|
278
|
Chris@76
|
279 // Output the footer of the xml.
|
Chris@76
|
280 echo '
|
Chris@76
|
281 </channel>
|
Chris@76
|
282 </rss>';
|
Chris@76
|
283 }
|
Chris@76
|
284 elseif ($xml_format == 'webslice')
|
Chris@76
|
285 {
|
Chris@76
|
286 $context['recent_posts_data'] = $xml;
|
Chris@76
|
287
|
Chris@76
|
288 // This always has RSS 2
|
Chris@76
|
289 echo '
|
Chris@76
|
290 <rss version="2.0" xmlns:mon="http://www.microsoft.com/schemas/rss/monitoring/2007" xml:lang="', strtr($txt['lang_locale'], '_', '-'), '">
|
Chris@76
|
291 <channel>
|
Chris@76
|
292 <title>', $feed_title, ' - ', $txt['recent_posts'], '</title>
|
Chris@76
|
293 <link>', $scripturl, '?action=recent</link>
|
Chris@76
|
294 <description><![CDATA[', strip_tags($txt['xml_rss_desc']), ']]></description>
|
Chris@76
|
295 <item>
|
Chris@76
|
296 <title>', $feed_title, ' - ', $txt['recent_posts'], '</title>
|
Chris@76
|
297 <link>', $scripturl, '?action=recent</link>
|
Chris@76
|
298 <description><![CDATA[
|
Chris@76
|
299 ', template_webslice_header_above(), '
|
Chris@76
|
300 ', template_webslice_recent_posts(), '
|
Chris@76
|
301 ', template_webslice_header_below(), '
|
Chris@76
|
302 ]]></description>
|
Chris@76
|
303 </item>
|
Chris@76
|
304 </channel>
|
Chris@76
|
305 </rss>';
|
Chris@76
|
306 }
|
Chris@76
|
307 elseif ($xml_format == 'atom')
|
Chris@76
|
308 {
|
Chris@76
|
309 echo '
|
Chris@76
|
310 <feed xmlns="http://www.w3.org/2005/Atom">
|
Chris@76
|
311 <title>', $feed_title, '</title>
|
Chris@76
|
312 <link rel="alternate" type="text/html" href="', $scripturl, '" />
|
Chris@76
|
313
|
Chris@76
|
314 <modified>', gmstrftime('%Y-%m-%dT%H:%M:%SZ'), '</modified>
|
Chris@76
|
315 <tagline><![CDATA[', strip_tags($txt['xml_rss_desc']), ']]></tagline>
|
Chris@76
|
316 <generator uri="http://www.simplemachines.org" version="', strtr($forum_version, array('SMF' => '')), '">SMF</generator>
|
Chris@76
|
317 <author>
|
Chris@76
|
318 <name>', strip_tags($context['forum_name']), '</name>
|
Chris@76
|
319 </author>';
|
Chris@76
|
320
|
Chris@76
|
321 dumpTags($xml, 2, 'entry', $xml_format);
|
Chris@76
|
322
|
Chris@76
|
323 echo '
|
Chris@76
|
324 </feed>';
|
Chris@76
|
325 }
|
Chris@76
|
326 elseif ($xml_format == 'rdf')
|
Chris@76
|
327 {
|
Chris@76
|
328 echo '
|
Chris@76
|
329 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/">
|
Chris@76
|
330 <channel rdf:about="', $scripturl, '">
|
Chris@76
|
331 <title>', $feed_title, '</title>
|
Chris@76
|
332 <link>', $scripturl, '</link>
|
Chris@76
|
333 <description><![CDATA[', strip_tags($txt['xml_rss_desc']), ']]></description>
|
Chris@76
|
334 <items>
|
Chris@76
|
335 <rdf:Seq>';
|
Chris@76
|
336
|
Chris@76
|
337 foreach ($xml as $item)
|
Chris@76
|
338 echo '
|
Chris@76
|
339 <rdf:li rdf:resource="', $item['link'], '" />';
|
Chris@76
|
340
|
Chris@76
|
341 echo '
|
Chris@76
|
342 </rdf:Seq>
|
Chris@76
|
343 </items>
|
Chris@76
|
344 </channel>
|
Chris@76
|
345 ';
|
Chris@76
|
346
|
Chris@76
|
347 dumpTags($xml, 1, 'item', $xml_format);
|
Chris@76
|
348
|
Chris@76
|
349 echo '
|
Chris@76
|
350 </rdf:RDF>';
|
Chris@76
|
351 }
|
Chris@76
|
352 // Otherwise, we're using our proprietary formats - they give more data, though.
|
Chris@76
|
353 else
|
Chris@76
|
354 {
|
Chris@76
|
355 echo '
|
Chris@76
|
356 <smf:xml-feed xmlns:smf="http://www.simplemachines.org/" xmlns="http://www.simplemachines.org/xml/', $_GET['sa'], '" xml:lang="', strtr($txt['lang_locale'], '_', '-'), '">';
|
Chris@76
|
357
|
Chris@76
|
358 // Dump out that associative array. Indent properly.... and use the right names for the base elements.
|
Chris@76
|
359 dumpTags($xml, 1, $subActions[$_GET['sa']][1], $xml_format);
|
Chris@76
|
360
|
Chris@76
|
361 echo '
|
Chris@76
|
362 </smf:xml-feed>';
|
Chris@76
|
363 }
|
Chris@76
|
364
|
Chris@76
|
365 obExit(false);
|
Chris@76
|
366 }
|
Chris@76
|
367
|
Chris@76
|
368 function fix_possible_url($val)
|
Chris@76
|
369 {
|
Chris@76
|
370 global $modSettings, $context, $scripturl;
|
Chris@76
|
371
|
Chris@76
|
372 if (substr($val, 0, strlen($scripturl)) != $scripturl)
|
Chris@76
|
373 return $val;
|
Chris@76
|
374
|
Chris@76
|
375 call_integration_hook('integrate_fix_url', array(&$val));
|
Chris@76
|
376
|
Chris@76
|
377 if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && @ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd']))
|
Chris@76
|
378 return $val;
|
Chris@76
|
379
|
Chris@76
|
380 $val = preg_replace('/^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$/e', '\'\' . $scripturl . \'/\' . strtr(\'$1\', \'&;=\', \'//,\') . \'.html$2\'', $val);
|
Chris@76
|
381 return $val;
|
Chris@76
|
382 }
|
Chris@76
|
383
|
Chris@76
|
384 function cdata_parse($data, $ns = '')
|
Chris@76
|
385 {
|
Chris@76
|
386 global $smcFunc, $cdata_override;
|
Chris@76
|
387
|
Chris@76
|
388 // Are we not doing it?
|
Chris@76
|
389 if (!empty($cdata_override))
|
Chris@76
|
390 return $data;
|
Chris@76
|
391
|
Chris@76
|
392 $cdata = '<; $pos < $n; null)
|
Chris@76
|
395 {
|
Chris@76
|
396 $positions = array(
|
Chris@76
|
397 $smcFunc['strpos']($data, '&', $pos),
|
Chris@76
|
398 $smcFunc['strpos']($data, ']', $pos),
|
Chris@76
|
399 );
|
Chris@76
|
400 if ($ns != '')
|
Chris@76
|
401 $positions[] = $smcFunc['strpos']($data, '<', $pos);
|
Chris@76
|
402 foreach ($positions as $k => $dummy)
|
Chris@76
|
403 {
|
Chris@76
|
404 if ($dummy === false)
|
Chris@76
|
405 unset($positions[$k]);
|
Chris@76
|
406 }
|
Chris@76
|
407
|
Chris@76
|
408 $old = $pos;
|
Chris@76
|
409 $pos = empty($positions) ? $n : min($positions);
|
Chris@76
|
410
|
Chris@76
|
411 if ($pos - $old > 0)
|
Chris@76
|
412 $cdata .= $smcFunc['substr']($data, $old, $pos - $old);
|
Chris@76
|
413 if ($pos >= $n)
|
Chris@76
|
414 break;
|
Chris@76
|
415
|
Chris@76
|
416 if ($smcFunc['substr']($data, $pos, 1) == '<')
|
Chris@76
|
417 {
|
Chris@76
|
418 $pos2 = $smcFunc['strpos']($data, '>', $pos);
|
Chris@76
|
419 if ($pos2 === false)
|
Chris@76
|
420 $pos2 = $n;
|
Chris@76
|
421 if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
|
Chris@76
|
422 $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
|
Chris@76
|
423 else
|
Chris@76
|
424 $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']')
|
Chris@76
|
428 {
|
Chris@76
|
429 $cdata .= ']]>]< == '&')
|
Chris@76
|
433 {
|
Chris@76
|
434 $pos2 = $smcFunc['strpos']($data, ';', $pos);
|
Chris@76
|
435 if ($pos2 === false)
|
Chris@76
|
436 $pos2 = $n;
|
Chris@76
|
437 $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1);
|
Chris@76
|
438
|
Chris@76
|
439 if ($smcFunc['substr']($data, $pos + 1, 1) == '#')
|
Chris@76
|
440 $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
|
Chris@76
|
441 elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot')))
|
Chris@76
|
442 $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
|
Chris@76
|
443 // !!! ??
|
Chris@76
|
444
|
Chris@76
|
445 $pos = $pos2 + 1;
|
Chris@76
|
446 }
|
Chris@76
|
447 }
|
Chris@76
|
448
|
Chris@76
|
449 $cdata .= ']]>';
|
Chris@76
|
450
|
Chris@76
|
451 return strtr($cdata, array('<![CDATA[]]>' => ''));
|
Chris@76
|
452 }
|
Chris@76
|
453
|
Chris@76
|
454 function dumpTags($data, $i, $tag = null, $xml_format = '')
|
Chris@76
|
455 {
|
Chris@76
|
456 global $modSettings, $context, $scripturl;
|
Chris@76
|
457
|
Chris@76
|
458 // For every array in the data...
|
Chris@76
|
459 foreach ($data as $key => $val)
|
Chris@76
|
460 {
|
Chris@76
|
461 // Skip it, it's been set to null.
|
Chris@76
|
462 if ($val === null)
|
Chris@76
|
463 continue;
|
Chris@76
|
464
|
Chris@76
|
465 // If a tag was passed, use it instead of the key.
|
Chris@76
|
466 $key = isset($tag) ? $tag : $key;
|
Chris@76
|
467
|
Chris@76
|
468 // First let's indent!
|
Chris@76
|
469 echo "\n", str_repeat("\t", $i);
|
Chris@76
|
470
|
Chris@76
|
471 // Grr, I hate kludges... almost worth doing it properly, here, but not quite.
|
Chris@76
|
472 if ($xml_format == 'atom' && $key == 'link')
|
Chris@76
|
473 {
|
Chris@76
|
474 echo '<link rel="alternate" type="text/html" href="', fix_possible_url($val), '" />';
|
Chris@76
|
475 continue;
|
Chris@76
|
476 }
|
Chris@76
|
477
|
Chris@76
|
478 // If it's empty/0/nothing simply output an empty tag.
|
Chris@76
|
479 if ($val == '')
|
Chris@76
|
480 echo '<', $key, ' />';
|
Chris@76
|
481 else
|
Chris@76
|
482 {
|
Chris@76
|
483 // Beginning tag.
|
Chris@76
|
484 if ($xml_format == 'rdf' && $key == 'item' && isset($val['link']))
|
Chris@76
|
485 {
|
Chris@76
|
486 echo '<', $key, ' rdf:about="', fix_possible_url($val['link']), '">';
|
Chris@76
|
487 echo "\n", str_repeat("\t", $i + 1);
|
Chris@76
|
488 echo '<dc:format>text/html</dc:format>';
|
Chris@76
|
489 }
|
Chris@76
|
490 elseif ($xml_format == 'atom' && $key == 'summary')
|
Chris@76
|
491 echo '<', $key, ' type="html">';
|
Chris@76
|
492 else
|
Chris@76
|
493 echo '<', $key, '>';
|
Chris@76
|
494
|
Chris@76
|
495 if (is_array($val))
|
Chris@76
|
496 {
|
Chris@76
|
497 // An array. Dump it, and then indent the tag.
|
Chris@76
|
498 dumpTags($val, $i + 1, null, $xml_format);
|
Chris@76
|
499 echo "\n", str_repeat("\t", $i), '</', $key, '>';
|
Chris@76
|
500 }
|
Chris@76
|
501 // A string with returns in it.... show this as a multiline element.
|
Chris@76
|
502 elseif (strpos($val, "\n") !== false || strpos($val, '<br />') !== false)
|
Chris@76
|
503 echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i), '</', $key, '>';
|
Chris@76
|
504 // A simple string.
|
Chris@76
|
505 else
|
Chris@76
|
506 echo fix_possible_url($val), '</', $key, '>';
|
Chris@76
|
507 }
|
Chris@76
|
508 }
|
Chris@76
|
509 }
|
Chris@76
|
510
|
Chris@76
|
511 function getXmlMembers($xml_format)
|
Chris@76
|
512 {
|
Chris@76
|
513 global $scripturl, $smcFunc;
|
Chris@76
|
514
|
Chris@76
|
515 if (!allowedTo('view_mlist'))
|
Chris@76
|
516 return array();
|
Chris@76
|
517
|
Chris@76
|
518 // Find the most recent members.
|
Chris@76
|
519 $request = $smcFunc['db_query']('', '
|
Chris@76
|
520 SELECT id_member, member_name, real_name, date_registered, last_login
|
Chris@76
|
521 FROM {db_prefix}members
|
Chris@76
|
522 ORDER BY id_member DESC
|
Chris@76
|
523 LIMIT {int:limit}',
|
Chris@76
|
524 array(
|
Chris@76
|
525 'limit' => $_GET['limit'],
|
Chris@76
|
526 )
|
Chris@76
|
527 );
|
Chris@76
|
528 $data = array();
|
Chris@76
|
529 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
530 {
|
Chris@76
|
531 // Make the data look rss-ish.
|
Chris@76
|
532 if ($xml_format == 'rss' || $xml_format == 'rss2')
|
Chris@76
|
533 $data[] = array(
|
Chris@76
|
534 'title' => cdata_parse($row['real_name']),
|
Chris@76
|
535 'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
|
Chris@76
|
536 'comments' => $scripturl . '?action=pm;sa=send;u=' . $row['id_member'],
|
Chris@76
|
537 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['date_registered']),
|
Chris@76
|
538 'guid' => $scripturl . '?action=profile;u=' . $row['id_member'],
|
Chris@76
|
539 );
|
Chris@76
|
540 elseif ($xml_format == 'rdf')
|
Chris@76
|
541 $data[] = array(
|
Chris@76
|
542 'title' => cdata_parse($row['real_name']),
|
Chris@76
|
543 'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
|
Chris@76
|
544 );
|
Chris@76
|
545 elseif ($xml_format == 'atom')
|
Chris@76
|
546 $data[] = array(
|
Chris@76
|
547 'title' => cdata_parse($row['real_name']),
|
Chris@76
|
548 'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
|
Chris@76
|
549 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['date_registered']),
|
Chris@76
|
550 'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['last_login']),
|
Chris@76
|
551 'id' => $scripturl . '?action=profile;u=' . $row['id_member'],
|
Chris@76
|
552 );
|
Chris@76
|
553 // More logical format for the data, but harder to apply.
|
Chris@76
|
554 else
|
Chris@76
|
555 $data[] = array(
|
Chris@76
|
556 'name' => cdata_parse($row['real_name']),
|
Chris@76
|
557 'time' => htmlspecialchars(strip_tags(timeformat($row['date_registered']))),
|
Chris@76
|
558 'id' => $row['id_member'],
|
Chris@76
|
559 'link' => $scripturl . '?action=profile;u=' . $row['id_member']
|
Chris@76
|
560 );
|
Chris@76
|
561 }
|
Chris@76
|
562 $smcFunc['db_free_result']($request);
|
Chris@76
|
563
|
Chris@76
|
564 return $data;
|
Chris@76
|
565 }
|
Chris@76
|
566
|
Chris@76
|
567 function getXmlNews($xml_format)
|
Chris@76
|
568 {
|
Chris@76
|
569 global $user_info, $scripturl, $modSettings, $board;
|
Chris@76
|
570 global $query_this_board, $smcFunc, $settings, $context;
|
Chris@76
|
571
|
Chris@76
|
572 /* Find the latest posts that:
|
Chris@76
|
573 - are the first post in their topic.
|
Chris@76
|
574 - are on an any board OR in a specified board.
|
Chris@76
|
575 - can be seen by this user.
|
Chris@76
|
576 - are actually the latest posts. */
|
Chris@76
|
577
|
Chris@76
|
578 $done = false;
|
Chris@76
|
579 $loops = 0;
|
Chris@76
|
580 while (!$done)
|
Chris@76
|
581 {
|
Chris@76
|
582 $optimize_msg = implode(' AND ', $context['optimize_msg']);
|
Chris@76
|
583 $request = $smcFunc['db_query']('', '
|
Chris@76
|
584 SELECT
|
Chris@76
|
585 m.smileys_enabled, m.poster_time, m.id_msg, m.subject, m.body, m.modified_time,
|
Chris@76
|
586 m.icon, t.id_topic, t.id_board, t.num_replies,
|
Chris@76
|
587 b.name AS bname,
|
Chris@76
|
588 mem.hide_email, IFNULL(mem.id_member, 0) AS id_member,
|
Chris@76
|
589 IFNULL(mem.email_address, m.poster_email) AS poster_email,
|
Chris@76
|
590 IFNULL(mem.real_name, m.poster_name) AS poster_name
|
Chris@76
|
591 FROM {db_prefix}topics AS t
|
Chris@76
|
592 INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
|
Chris@76
|
593 INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
|
Chris@76
|
594 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
|
Chris@76
|
595 WHERE ' . $query_this_board . (empty($optimize_msg) ? '' : '
|
Chris@76
|
596 AND {raw:optimize_msg}') . (empty($board) ? '' : '
|
Chris@76
|
597 AND t.id_board = {int:current_board}') . ($modSettings['postmod_active'] ? '
|
Chris@76
|
598 AND t.approved = {int:is_approved}' : '') . '
|
Chris@76
|
599 ORDER BY t.id_first_msg DESC
|
Chris@76
|
600 LIMIT {int:limit}',
|
Chris@76
|
601 array(
|
Chris@76
|
602 'current_board' => $board,
|
Chris@76
|
603 'is_approved' => 1,
|
Chris@76
|
604 'limit' => $_GET['limit'],
|
Chris@76
|
605 'optimize_msg' => $optimize_msg,
|
Chris@76
|
606 )
|
Chris@76
|
607 );
|
Chris@76
|
608 // If we don't have $_GET['limit'] results, try again with an unoptimized version covering all rows.
|
Chris@76
|
609 if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
|
Chris@76
|
610 {
|
Chris@76
|
611 $smcFunc['db_free_result']($request);
|
Chris@76
|
612 if (empty($_REQUEST['boards']) && empty($board))
|
Chris@76
|
613 unset($context['optimize_msg']['lowest']);
|
Chris@76
|
614 else
|
Chris@76
|
615 $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
|
Chris@76
|
616 $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
|
Chris@76
|
617 $loops++;
|
Chris@76
|
618 }
|
Chris@76
|
619 else
|
Chris@76
|
620 $done = true;
|
Chris@76
|
621 }
|
Chris@76
|
622 $data = array();
|
Chris@76
|
623 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
624 {
|
Chris@76
|
625 // Limit the length of the message, if the option is set.
|
Chris@76
|
626 if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br />', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
|
Chris@76
|
627 $row['body'] = strtr($smcFunc['substr'](str_replace('<br />', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br />')) . '...';
|
Chris@76
|
628
|
Chris@76
|
629 $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
|
Chris@76
|
630
|
Chris@76
|
631 censorText($row['body']);
|
Chris@76
|
632 censorText($row['subject']);
|
Chris@76
|
633
|
Chris@76
|
634 // Being news, this actually makes sense in rss format.
|
Chris@76
|
635 if ($xml_format == 'rss' || $xml_format == 'rss2')
|
Chris@76
|
636 $data[] = array(
|
Chris@76
|
637 'title' => cdata_parse($row['subject']),
|
Chris@76
|
638 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
639 'description' => cdata_parse($row['body']),
|
Chris@76
|
640 'author' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
|
Chris@76
|
641 'comments' => $scripturl . '?action=post;topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
642 'category' => '<![CDATA[' . $row['bname'] . ']]>',
|
Chris@76
|
643 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
|
Chris@76
|
644 'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
645 );
|
Chris@76
|
646 elseif ($xml_format == 'rdf')
|
Chris@76
|
647 $data[] = array(
|
Chris@76
|
648 'title' => cdata_parse($row['subject']),
|
Chris@76
|
649 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
650 'description' => cdata_parse($row['body']),
|
Chris@76
|
651 );
|
Chris@76
|
652 elseif ($xml_format == 'atom')
|
Chris@76
|
653 $data[] = array(
|
Chris@76
|
654 'title' => cdata_parse($row['subject']),
|
Chris@76
|
655 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
656 'summary' => cdata_parse($row['body']),
|
Chris@76
|
657 'category' => array('term' => $row['id_board'], 'label' => cdata_parse($row['bname'])),
|
Chris@76
|
658 'author' => array(
|
Chris@76
|
659 'name' => $row['poster_name'],
|
Chris@76
|
660 'email' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
|
Chris@76
|
661 'uri' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
|
Chris@76
|
662 ),
|
Chris@76
|
663 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['poster_time']),
|
Chris@76
|
664 'modified' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
|
Chris@76
|
665 'id' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
666 'icon' => $settings['images_url'] . '/icons/' . $row['icon'] . '.gif',
|
Chris@76
|
667 );
|
Chris@76
|
668 // The biggest difference here is more information.
|
Chris@76
|
669 else
|
Chris@76
|
670 $data[] = array(
|
Chris@76
|
671 'time' => htmlspecialchars(strip_tags(timeformat($row['poster_time']))),
|
Chris@76
|
672 'id' => $row['id_topic'],
|
Chris@76
|
673 'subject' => cdata_parse($row['subject']),
|
Chris@76
|
674 'body' => cdata_parse($row['body']),
|
Chris@76
|
675 'poster' => array(
|
Chris@76
|
676 'name' => cdata_parse($row['poster_name']),
|
Chris@76
|
677 'id' => $row['id_member'],
|
Chris@76
|
678 'link' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
|
Chris@76
|
679 ),
|
Chris@76
|
680 'topic' => $row['id_topic'],
|
Chris@76
|
681 'board' => array(
|
Chris@76
|
682 'name' => cdata_parse($row['bname']),
|
Chris@76
|
683 'id' => $row['id_board'],
|
Chris@76
|
684 'link' => $scripturl . '?board=' . $row['id_board'] . '.0',
|
Chris@76
|
685 ),
|
Chris@76
|
686 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
687 );
|
Chris@76
|
688 }
|
Chris@76
|
689 $smcFunc['db_free_result']($request);
|
Chris@76
|
690
|
Chris@76
|
691 return $data;
|
Chris@76
|
692 }
|
Chris@76
|
693
|
Chris@76
|
694 function getXmlRecent($xml_format)
|
Chris@76
|
695 {
|
Chris@76
|
696 global $user_info, $scripturl, $modSettings, $board;
|
Chris@76
|
697 global $query_this_board, $smcFunc, $settings, $context;
|
Chris@76
|
698
|
Chris@76
|
699 $done = false;
|
Chris@76
|
700 $loops = 0;
|
Chris@76
|
701 while (!$done)
|
Chris@76
|
702 {
|
Chris@76
|
703 $optimize_msg = implode(' AND ', $context['optimize_msg']);
|
Chris@76
|
704 $request = $smcFunc['db_query']('', '
|
Chris@76
|
705 SELECT m.id_msg
|
Chris@76
|
706 FROM {db_prefix}messages AS m
|
Chris@76
|
707 INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
|
Chris@76
|
708 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
|
Chris@76
|
709 WHERE ' . $query_this_board . (empty($optimize_msg) ? '' : '
|
Chris@76
|
710 AND {raw:optimize_msg}') . (empty($board) ? '' : '
|
Chris@76
|
711 AND m.id_board = {int:current_board}') . ($modSettings['postmod_active'] ? '
|
Chris@76
|
712 AND m.approved = {int:is_approved}' : '') . '
|
Chris@76
|
713 ORDER BY m.id_msg DESC
|
Chris@76
|
714 LIMIT {int:limit}',
|
Chris@76
|
715 array(
|
Chris@76
|
716 'limit' => $_GET['limit'],
|
Chris@76
|
717 'current_board' => $board,
|
Chris@76
|
718 'is_approved' => 1,
|
Chris@76
|
719 'optimize_msg' => $optimize_msg,
|
Chris@76
|
720 )
|
Chris@76
|
721 );
|
Chris@76
|
722 // If we don't have $_GET['limit'] results, try again with an unoptimized version covering all rows.
|
Chris@76
|
723 if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
|
Chris@76
|
724 {
|
Chris@76
|
725 $smcFunc['db_free_result']($request);
|
Chris@76
|
726 if (empty($_REQUEST['boards']) && empty($board))
|
Chris@76
|
727 unset($context['optimize_msg']['lowest']);
|
Chris@76
|
728 else
|
Chris@76
|
729 $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
|
Chris@76
|
730 $loops++;
|
Chris@76
|
731 }
|
Chris@76
|
732 else
|
Chris@76
|
733 $done = true;
|
Chris@76
|
734 }
|
Chris@76
|
735 $messages = array();
|
Chris@76
|
736 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
737 $messages[] = $row['id_msg'];
|
Chris@76
|
738 $smcFunc['db_free_result']($request);
|
Chris@76
|
739
|
Chris@76
|
740 if (empty($messages))
|
Chris@76
|
741 return array();
|
Chris@76
|
742
|
Chris@76
|
743 // Find the most recent posts this user can see.
|
Chris@76
|
744 $request = $smcFunc['db_query']('', '
|
Chris@76
|
745 SELECT
|
Chris@76
|
746 m.smileys_enabled, m.poster_time, m.id_msg, m.subject, m.body, m.id_topic, t.id_board,
|
Chris@76
|
747 b.name AS bname, t.num_replies, m.id_member, m.icon, mf.id_member AS id_first_member,
|
Chris@76
|
748 IFNULL(mem.real_name, m.poster_name) AS poster_name, mf.subject AS first_subject,
|
Chris@76
|
749 IFNULL(memf.real_name, mf.poster_name) AS first_poster_name, mem.hide_email,
|
Chris@76
|
750 IFNULL(mem.email_address, m.poster_email) AS poster_email, m.modified_time
|
Chris@76
|
751 FROM {db_prefix}messages AS m
|
Chris@76
|
752 INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
|
Chris@76
|
753 INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
|
Chris@76
|
754 INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
|
Chris@76
|
755 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
|
Chris@76
|
756 LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
|
Chris@76
|
757 WHERE m.id_msg IN ({array_int:message_list})
|
Chris@76
|
758 ' . (empty($board) ? '' : 'AND t.id_board = {int:current_board}') . '
|
Chris@76
|
759 ORDER BY m.id_msg DESC
|
Chris@76
|
760 LIMIT {int:limit}',
|
Chris@76
|
761 array(
|
Chris@76
|
762 'limit' => $_GET['limit'],
|
Chris@76
|
763 'current_board' => $board,
|
Chris@76
|
764 'message_list' => $messages,
|
Chris@76
|
765 )
|
Chris@76
|
766 );
|
Chris@76
|
767 $data = array();
|
Chris@76
|
768 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
769 {
|
Chris@76
|
770 // Limit the length of the message, if the option is set.
|
Chris@76
|
771 if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br />', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
|
Chris@76
|
772 $row['body'] = strtr($smcFunc['substr'](str_replace('<br />', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br />')) . '...';
|
Chris@76
|
773
|
Chris@76
|
774 $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
|
Chris@76
|
775
|
Chris@76
|
776 censorText($row['body']);
|
Chris@76
|
777 censorText($row['subject']);
|
Chris@76
|
778
|
Chris@76
|
779 // Doesn't work as well as news, but it kinda does..
|
Chris@76
|
780 if ($xml_format == 'rss' || $xml_format == 'rss2')
|
Chris@76
|
781 $data[] = array(
|
Chris@76
|
782 'title' => $row['subject'],
|
Chris@76
|
783 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
|
Chris@76
|
784 'description' => cdata_parse($row['body']),
|
Chris@76
|
785 'author' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
|
Chris@76
|
786 'category' => cdata_parse($row['bname']),
|
Chris@76
|
787 'comments' => $scripturl . '?action=post;topic=' . $row['id_topic'] . '.0',
|
Chris@76
|
788 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
|
Chris@76
|
789 'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
|
Chris@76
|
790 );
|
Chris@76
|
791 elseif ($xml_format == 'rdf')
|
Chris@76
|
792 $data[] = array(
|
Chris@76
|
793 'title' => $row['subject'],
|
Chris@76
|
794 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
|
Chris@76
|
795 'description' => cdata_parse($row['body']),
|
Chris@76
|
796 );
|
Chris@76
|
797 elseif ($xml_format == 'atom')
|
Chris@76
|
798 $data[] = array(
|
Chris@76
|
799 'title' => $row['subject'],
|
Chris@76
|
800 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
|
Chris@76
|
801 'summary' => cdata_parse($row['body']),
|
Chris@76
|
802 'category' => array(
|
Chris@76
|
803 'term' => $row['id_board'],
|
Chris@76
|
804 'label' => cdata_parse($row['bname'])
|
Chris@76
|
805 ),
|
Chris@76
|
806 'author' => array(
|
Chris@76
|
807 'name' => $row['poster_name'],
|
Chris@76
|
808 'email' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
|
Chris@76
|
809 'uri' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : ''
|
Chris@76
|
810 ),
|
Chris@76
|
811 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['poster_time']),
|
Chris@76
|
812 'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
|
Chris@76
|
813 'id' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
|
Chris@76
|
814 'icon' => $settings['images_url'] . '/icons/' . $row['icon'] . '.gif',
|
Chris@76
|
815 );
|
Chris@76
|
816 // A lot of information here. Should be enough to please the rss-ers.
|
Chris@76
|
817 else
|
Chris@76
|
818 $data[] = array(
|
Chris@76
|
819 'time' => htmlspecialchars(strip_tags(timeformat($row['poster_time']))),
|
Chris@76
|
820 'id' => $row['id_msg'],
|
Chris@76
|
821 'subject' => cdata_parse($row['subject']),
|
Chris@76
|
822 'body' => cdata_parse($row['body']),
|
Chris@76
|
823 'starter' => array(
|
Chris@76
|
824 'name' => cdata_parse($row['first_poster_name']),
|
Chris@76
|
825 'id' => $row['id_first_member'],
|
Chris@76
|
826 'link' => !empty($row['id_first_member']) ? $scripturl . '?action=profile;u=' . $row['id_first_member'] : ''
|
Chris@76
|
827 ),
|
Chris@76
|
828 'poster' => array(
|
Chris@76
|
829 'name' => cdata_parse($row['poster_name']),
|
Chris@76
|
830 'id' => $row['id_member'],
|
Chris@76
|
831 'link' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : ''
|
Chris@76
|
832 ),
|
Chris@76
|
833 'topic' => array(
|
Chris@76
|
834 'subject' => cdata_parse($row['first_subject']),
|
Chris@76
|
835 'id' => $row['id_topic'],
|
Chris@76
|
836 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.new#new'
|
Chris@76
|
837 ),
|
Chris@76
|
838 'board' => array(
|
Chris@76
|
839 'name' => cdata_parse($row['bname']),
|
Chris@76
|
840 'id' => $row['id_board'],
|
Chris@76
|
841 'link' => $scripturl . '?board=' . $row['id_board'] . '.0'
|
Chris@76
|
842 ),
|
Chris@76
|
843 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
|
Chris@76
|
844 );
|
Chris@76
|
845 }
|
Chris@76
|
846 $smcFunc['db_free_result']($request);
|
Chris@76
|
847
|
Chris@76
|
848 return $data;
|
Chris@76
|
849 }
|
Chris@76
|
850
|
Chris@76
|
851 function getXmlProfile($xml_format)
|
Chris@76
|
852 {
|
Chris@76
|
853 global $scripturl, $memberContext, $user_profile, $modSettings, $user_info;
|
Chris@76
|
854
|
Chris@76
|
855 // You must input a valid user....
|
Chris@76
|
856 if (empty($_GET['u']) || loadMemberData((int) $_GET['u']) === false)
|
Chris@76
|
857 return array();
|
Chris@76
|
858
|
Chris@76
|
859 // Make sure the id is a number and not "I like trying to hack the database".
|
Chris@76
|
860 $_GET['u'] = (int) $_GET['u'];
|
Chris@76
|
861 // Load the member's contextual information!
|
Chris@76
|
862 if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view_any'))
|
Chris@76
|
863 return array();
|
Chris@76
|
864
|
Chris@76
|
865 // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type.
|
Chris@76
|
866 $profile = &$memberContext[$_GET['u']];
|
Chris@76
|
867
|
Chris@76
|
868 if ($xml_format == 'rss' || $xml_format == 'rss2')
|
Chris@76
|
869 $data = array(array(
|
Chris@76
|
870 'title' => cdata_parse($profile['name']),
|
Chris@76
|
871 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
|
Chris@76
|
872 'description' => cdata_parse(isset($profile['group']) ? $profile['group'] : $profile['post_group']),
|
Chris@76
|
873 'comments' => $scripturl . '?action=pm;sa=send;u=' . $profile['id'],
|
Chris@76
|
874 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['date_registered']),
|
Chris@76
|
875 'guid' => $scripturl . '?action=profile;u=' . $profile['id'],
|
Chris@76
|
876 ));
|
Chris@76
|
877 elseif ($xml_format == 'rdf')
|
Chris@76
|
878 $data = array(array(
|
Chris@76
|
879 'title' => cdata_parse($profile['name']),
|
Chris@76
|
880 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
|
Chris@76
|
881 'description' => cdata_parse(isset($profile['group']) ? $profile['group'] : $profile['post_group']),
|
Chris@76
|
882 ));
|
Chris@76
|
883 elseif ($xml_format == 'atom')
|
Chris@76
|
884 $data[] = array(
|
Chris@76
|
885 'title' => cdata_parse($profile['name']),
|
Chris@76
|
886 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
|
Chris@76
|
887 'summary' => cdata_parse(isset($profile['group']) ? $profile['group'] : $profile['post_group']),
|
Chris@76
|
888 'author' => array(
|
Chris@76
|
889 'name' => $profile['real_name'],
|
Chris@76
|
890 'email' => in_array(showEmailAddress(!empty($profile['hide_email']), $profile['id']), array('yes', 'yes_permission_override')) ? $profile['email'] : null,
|
Chris@76
|
891 'uri' => !empty($profile['website']) ? $profile['website']['url'] : ''
|
Chris@76
|
892 ),
|
Chris@76
|
893 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $user_profile[$profile['id']]['date_registered']),
|
Chris@76
|
894 'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $user_profile[$profile['id']]['last_login']),
|
Chris@76
|
895 'id' => $scripturl . '?action=profile;u=' . $profile['id'],
|
Chris@76
|
896 'logo' => !empty($profile['avatar']) ? $profile['avatar']['url'] : '',
|
Chris@76
|
897 );
|
Chris@76
|
898 else
|
Chris@76
|
899 {
|
Chris@76
|
900 $data = array(
|
Chris@76
|
901 'username' => $user_info['is_admin'] || $user_info['id'] == $profile['id'] ? cdata_parse($profile['username']) : '',
|
Chris@76
|
902 'name' => cdata_parse($profile['name']),
|
Chris@76
|
903 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
|
Chris@76
|
904 'posts' => $profile['posts'],
|
Chris@76
|
905 'post-group' => cdata_parse($profile['post_group']),
|
Chris@76
|
906 'language' => cdata_parse($profile['language']),
|
Chris@76
|
907 'last-login' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['last_login']),
|
Chris@76
|
908 'registered' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['date_registered'])
|
Chris@76
|
909 );
|
Chris@76
|
910
|
Chris@76
|
911 // Everything below here might not be set, and thus maybe shouldn't be displayed.
|
Chris@76
|
912 if ($profile['gender']['name'] != '')
|
Chris@76
|
913 $data['gender'] = cdata_parse($profile['gender']['name']);
|
Chris@76
|
914
|
Chris@76
|
915 if ($profile['avatar']['name'] != '')
|
Chris@76
|
916 $data['avatar'] = $profile['avatar']['url'];
|
Chris@76
|
917
|
Chris@76
|
918 // If they are online, show an empty tag... no reason to put anything inside it.
|
Chris@76
|
919 if ($profile['online']['is_online'])
|
Chris@76
|
920 $data['online'] = '';
|
Chris@76
|
921
|
Chris@76
|
922 if ($profile['signature'] != '')
|
Chris@76
|
923 $data['signature'] = cdata_parse($profile['signature']);
|
Chris@76
|
924 if ($profile['blurb'] != '')
|
Chris@76
|
925 $data['blurb'] = cdata_parse($profile['blurb']);
|
Chris@76
|
926 if ($profile['location'] != '')
|
Chris@76
|
927 $data['location'] = cdata_parse($profile['location']);
|
Chris@76
|
928 if ($profile['title'] != '')
|
Chris@76
|
929 $data['title'] = cdata_parse($profile['title']);
|
Chris@76
|
930
|
Chris@76
|
931 if (!empty($profile['icq']['name']) && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
|
Chris@76
|
932 $data['icq'] = $profile['icq']['name'];
|
Chris@76
|
933 if ($profile['aim']['name'] != '' && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
|
Chris@76
|
934 $data['aim'] = $profile['aim']['name'];
|
Chris@76
|
935 if ($profile['msn']['name'] != '' && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
|
Chris@76
|
936 $data['msn'] = $profile['msn']['name'];
|
Chris@76
|
937 if ($profile['yim']['name'] != '' && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
|
Chris@76
|
938 $data['yim'] = $profile['yim']['name'];
|
Chris@76
|
939
|
Chris@76
|
940 if ($profile['website']['title'] != '')
|
Chris@76
|
941 $data['website'] = array(
|
Chris@76
|
942 'title' => cdata_parse($profile['website']['title']),
|
Chris@76
|
943 'link' => $profile['website']['url']
|
Chris@76
|
944 );
|
Chris@76
|
945
|
Chris@76
|
946 if ($profile['group'] != '')
|
Chris@76
|
947 $data['position'] = cdata_parse($profile['group']);
|
Chris@76
|
948
|
Chris@76
|
949 if (!empty($modSettings['karmaMode']))
|
Chris@76
|
950 $data['karma'] = array(
|
Chris@76
|
951 'good' => $profile['karma']['good'],
|
Chris@76
|
952 'bad' => $profile['karma']['bad']
|
Chris@76
|
953 );
|
Chris@76
|
954
|
Chris@76
|
955 if (in_array($profile['show_email'], array('yes', 'yes_permission_override')))
|
Chris@76
|
956 $data['email'] = $profile['email'];
|
Chris@76
|
957
|
Chris@76
|
958 if (!empty($profile['birth_date']) && substr($profile['birth_date'], 0, 4) != '0000')
|
Chris@76
|
959 {
|
Chris@76
|
960 list ($birth_year, $birth_month, $birth_day) = sscanf($profile['birth_date'], '%d-%d-%d');
|
Chris@76
|
961 $datearray = getdate(forum_time());
|
Chris@76
|
962 $data['age'] = $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1);
|
Chris@76
|
963 }
|
Chris@76
|
964 }
|
Chris@76
|
965
|
Chris@76
|
966 // Save some memory.
|
Chris@76
|
967 unset($profile, $memberContext[$_GET['u']]);
|
Chris@76
|
968
|
Chris@76
|
969 return $data;
|
Chris@76
|
970 }
|
Chris@76
|
971
|
Chris@76
|
972 ?> |