@@ -497,6 +497,7 @@ |
||
497 | 497 | * @param string $xml_format The format to use ('atom', 'rss', 'rss2' or empty for plain XML) |
498 | 498 | * @param array $forceCdataKeys A list of keys on which to force cdata wrapping (used by mods, maybe) |
499 | 499 | * @param array $nsKeys Key-value pairs of namespace prefixes to pass to cdata_parse() (used by mods, maybe) |
500 | + * @param string $tag |
|
500 | 501 | */ |
501 | 502 | function dumpTags($data, $i, $tag = null, $xml_format = '', $forceCdataKeys = array(), $nsKeys = array()) |
502 | 503 | { |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | { |
838 | 838 | uasort($loaded_attachments, function($a, $b) { |
839 | 839 | if ($a['filesize'] == $b['filesize']) |
840 | - return 0; |
|
840 | + return 0; |
|
841 | 841 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
842 | 842 | }); |
843 | 843 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
1242 | 1242 | { |
1243 | 1243 | uasort($loaded_attachments, function($a, $b) { |
1244 | 1244 | if ($a['filesize'] == $b['filesize']) |
1245 | - return 0; |
|
1245 | + return 0; |
|
1246 | 1246 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1247 | 1247 | }); |
1248 | 1248 | } |
@@ -346,7 +346,7 @@ |
||
346 | 346 | |
347 | 347 | foreach ($xml as $item) |
348 | 348 | { |
349 | - $link = array_filter($item['content'], function ($e) { return ($e['tag'] == 'link'); }); |
|
349 | + $link = array_filter($item['content'], function($e) { return ($e['tag'] == 'link'); }); |
|
350 | 350 | $link = array_pop($link); |
351 | 351 | |
352 | 352 | echo ' |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Outputs xml data representing recent information or a profile. |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | global $query_this_board, $smcFunc, $forum_version; |
38 | 39 | |
39 | 40 | // If it's not enabled, die. |
40 | - if (empty($modSettings['xmlnews_enable'])) |
|
41 | - obExit(false); |
|
41 | + if (empty($modSettings['xmlnews_enable'])) { |
|
42 | + obExit(false); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | loadLanguage('Stats'); |
44 | 46 | |
@@ -63,8 +65,9 @@ discard block |
||
63 | 65 | if (!empty($_REQUEST['c']) && empty($board)) |
64 | 66 | { |
65 | 67 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
66 | - foreach ($_REQUEST['c'] as $i => $c) |
|
67 | - $_REQUEST['c'][$i] = (int) $c; |
|
68 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
69 | + $_REQUEST['c'][$i] = (int) $c; |
|
70 | + } |
|
68 | 71 | |
69 | 72 | if (count($_REQUEST['c']) == 1) |
70 | 73 | { |
@@ -100,18 +103,20 @@ discard block |
||
100 | 103 | } |
101 | 104 | $smcFunc['db_free_result']($request); |
102 | 105 | |
103 | - if (!empty($boards)) |
|
104 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
106 | + if (!empty($boards)) { |
|
107 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
108 | + } |
|
105 | 109 | |
106 | 110 | // Try to limit the number of messages we look through. |
107 | - if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) |
|
108 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
109 | - } |
|
110 | - elseif (!empty($_REQUEST['boards'])) |
|
111 | + if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) { |
|
112 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
113 | + } |
|
114 | + } elseif (!empty($_REQUEST['boards'])) |
|
111 | 115 | { |
112 | 116 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
113 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
114 | - $_REQUEST['boards'][$i] = (int) $b; |
|
117 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
118 | + $_REQUEST['boards'][$i] = (int) $b; |
|
119 | + } |
|
115 | 120 | |
116 | 121 | $request = $smcFunc['db_query']('', ' |
117 | 122 | SELECT b.id_board, b.num_posts, b.name |
@@ -127,29 +132,32 @@ discard block |
||
127 | 132 | |
128 | 133 | // Either the board specified doesn't exist or you have no access. |
129 | 134 | $num_boards = $smcFunc['db_num_rows']($request); |
130 | - if ($num_boards == 0) |
|
131 | - fatal_lang_error('no_board'); |
|
135 | + if ($num_boards == 0) { |
|
136 | + fatal_lang_error('no_board'); |
|
137 | + } |
|
132 | 138 | |
133 | 139 | $total_posts = 0; |
134 | 140 | $boards = array(); |
135 | 141 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
136 | 142 | { |
137 | - if ($num_boards == 1) |
|
138 | - $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
143 | + if ($num_boards == 1) { |
|
144 | + $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
145 | + } |
|
139 | 146 | |
140 | 147 | $boards[] = $row['id_board']; |
141 | 148 | $total_posts += $row['num_posts']; |
142 | 149 | } |
143 | 150 | $smcFunc['db_free_result']($request); |
144 | 151 | |
145 | - if (!empty($boards)) |
|
146 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
152 | + if (!empty($boards)) { |
|
153 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
154 | + } |
|
147 | 155 | |
148 | 156 | // The more boards, the more we're going to look through... |
149 | - if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) |
|
150 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
151 | - } |
|
152 | - elseif (!empty($board)) |
|
157 | + if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) { |
|
158 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
159 | + } |
|
160 | + } elseif (!empty($board)) |
|
153 | 161 | { |
154 | 162 | $request = $smcFunc['db_query']('', ' |
155 | 163 | SELECT num_posts |
@@ -168,10 +176,10 @@ discard block |
||
168 | 176 | $query_this_board = 'b.id_board = ' . $board; |
169 | 177 | |
170 | 178 | // Try to look through just a few messages, if at all possible. |
171 | - if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) |
|
172 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
173 | - } |
|
174 | - else |
|
179 | + if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) { |
|
180 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
181 | + } |
|
182 | + } else |
|
175 | 183 | { |
176 | 184 | $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
177 | 185 | AND b.id_board != ' . $modSettings['recycle_board'] : ''); |
@@ -194,30 +202,35 @@ discard block |
||
194 | 202 | // Easy adding of sub actions |
195 | 203 | call_integration_hook('integrate_xmlfeeds', array(&$subActions)); |
196 | 204 | |
197 | - if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
198 | - $_GET['sa'] = 'recent'; |
|
205 | + if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
206 | + $_GET['sa'] = 'recent'; |
|
207 | + } |
|
199 | 208 | |
200 | 209 | // We only want some information, not all of it. |
201 | 210 | $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']); |
202 | - foreach (array('board', 'boards', 'c') as $var) |
|
203 | - if (isset($_REQUEST[$var])) |
|
211 | + foreach (array('board', 'boards', 'c') as $var) { |
|
212 | + if (isset($_REQUEST[$var])) |
|
204 | 213 | $cachekey[] = $_REQUEST[$var]; |
214 | + } |
|
205 | 215 | $cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : '')); |
206 | 216 | $cache_t = microtime(); |
207 | 217 | |
208 | 218 | // Get the associative array representing the xml. |
209 | - if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) |
|
210 | - $xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
219 | + if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) { |
|
220 | + $xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
221 | + } |
|
211 | 222 | if (empty($xml)) |
212 | 223 | { |
213 | 224 | $call = call_helper($subActions[$_GET['sa']][0], true); |
214 | 225 | |
215 | - if (!empty($call)) |
|
216 | - $xml = call_user_func($call, $xml_format); |
|
226 | + if (!empty($call)) { |
|
227 | + $xml = call_user_func($call, $xml_format); |
|
228 | + } |
|
217 | 229 | |
218 | 230 | if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3) |
219 | - || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) |
|
220 | - cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240); |
|
231 | + || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) { |
|
232 | + cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240); |
|
233 | + } |
|
221 | 234 | } |
222 | 235 | |
223 | 236 | $feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : ''); |
@@ -256,32 +269,36 @@ discard block |
||
256 | 269 | $ns_string = ''; |
257 | 270 | if (!empty($namespaces[$xml_format])) |
258 | 271 | { |
259 | - foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) |
|
260 | - $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
272 | + foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) { |
|
273 | + $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
274 | + } |
|
261 | 275 | } |
262 | 276 | |
263 | 277 | $extraFeedTags_string = ''; |
264 | 278 | if (!empty($extraFeedTags[$xml_format])) |
265 | 279 | { |
266 | - foreach ($extraFeedTags[$xml_format] as $extraTag) |
|
267 | - $extraFeedTags_string .= "\n\t\t" . $extraTag; |
|
280 | + foreach ($extraFeedTags[$xml_format] as $extraTag) { |
|
281 | + $extraFeedTags_string .= "\n\t\t" . $extraTag; |
|
282 | + } |
|
268 | 283 | } |
269 | 284 | |
270 | 285 | // This is an xml file.... |
271 | 286 | ob_end_clean(); |
272 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
273 | - @ob_start('ob_gzhandler'); |
|
274 | - else |
|
275 | - ob_start(); |
|
287 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
288 | + @ob_start('ob_gzhandler'); |
|
289 | + } else { |
|
290 | + ob_start(); |
|
291 | + } |
|
276 | 292 | |
277 | - if ($xml_format == 'smf' || isset($_REQUEST['debug'])) |
|
278 | - header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
279 | - elseif ($xml_format == 'rss' || $xml_format == 'rss2') |
|
280 | - header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
281 | - elseif ($xml_format == 'atom') |
|
282 | - header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
283 | - elseif ($xml_format == 'rdf') |
|
284 | - header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
293 | + if ($xml_format == 'smf' || isset($_REQUEST['debug'])) { |
|
294 | + header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
295 | + } elseif ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
296 | + header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
297 | + } elseif ($xml_format == 'atom') { |
|
298 | + header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
299 | + } elseif ($xml_format == 'rdf') { |
|
300 | + header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
301 | + } |
|
285 | 302 | |
286 | 303 | // First, output the xml header. |
287 | 304 | echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>'; |
@@ -289,10 +306,11 @@ discard block |
||
289 | 306 | // Are we outputting an rss feed or one with more information? |
290 | 307 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
291 | 308 | { |
292 | - if ($xml_format == 'rss2') |
|
293 | - foreach ($_REQUEST as $var => $val) |
|
309 | + if ($xml_format == 'rss2') { |
|
310 | + foreach ($_REQUEST as $var => $val) |
|
294 | 311 | if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
295 | 312 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
313 | + } |
|
296 | 314 | |
297 | 315 | // Start with an RSS 2.0 header. |
298 | 316 | echo ' |
@@ -303,9 +321,10 @@ discard block |
||
303 | 321 | <description>', cdata_parse(strip_tags($feed_meta['desc'])), '</description>'; |
304 | 322 | |
305 | 323 | // RSS2 calls for this. |
306 | - if ($xml_format == 'rss2') |
|
307 | - echo ' |
|
324 | + if ($xml_format == 'rss2') { |
|
325 | + echo ' |
|
308 | 326 | <atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />'; |
327 | + } |
|
309 | 328 | |
310 | 329 | echo $extraFeedTags_string; |
311 | 330 | |
@@ -316,12 +335,12 @@ discard block |
||
316 | 335 | echo ' |
317 | 336 | </channel> |
318 | 337 | </rss>'; |
319 | - } |
|
320 | - elseif ($xml_format == 'atom') |
|
338 | + } elseif ($xml_format == 'atom') |
|
321 | 339 | { |
322 | - foreach ($_REQUEST as $var => $val) |
|
323 | - if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
340 | + foreach ($_REQUEST as $var => $val) { |
|
341 | + if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
324 | 342 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
343 | + } |
|
325 | 344 | |
326 | 345 | echo ' |
327 | 346 | <feed', $ns_string, '> |
@@ -343,8 +362,7 @@ discard block |
||
343 | 362 | |
344 | 363 | echo ' |
345 | 364 | </feed>'; |
346 | - } |
|
347 | - elseif ($xml_format == 'rdf') |
|
365 | + } elseif ($xml_format == 'rdf') |
|
348 | 366 | { |
349 | 367 | echo ' |
350 | 368 | <rdf:RDF', $ns_string, '> |
@@ -409,13 +427,15 @@ discard block |
||
409 | 427 | { |
410 | 428 | global $modSettings, $context, $scripturl; |
411 | 429 | |
412 | - if (substr($val, 0, strlen($scripturl)) != $scripturl) |
|
413 | - return $val; |
|
430 | + if (substr($val, 0, strlen($scripturl)) != $scripturl) { |
|
431 | + return $val; |
|
432 | + } |
|
414 | 433 | |
415 | 434 | call_integration_hook('integrate_fix_url', array(&$val)); |
416 | 435 | |
417 | - 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'])) |
|
418 | - return $val; |
|
436 | + 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'])) { |
|
437 | + return $val; |
|
438 | + } |
|
419 | 439 | |
420 | 440 | $val = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl) |
421 | 441 | { |
@@ -438,8 +458,9 @@ discard block |
||
438 | 458 | global $smcFunc; |
439 | 459 | |
440 | 460 | // Do we even need to do this? |
441 | - if (strpbrk($data, '<>&') == false && $force !== true) |
|
442 | - return $data; |
|
461 | + if (strpbrk($data, '<>&') == false && $force !== true) { |
|
462 | + return $data; |
|
463 | + } |
|
443 | 464 | |
444 | 465 | $cdata = '<, |
450 | 471 | $smcFunc['strpos']($data, ']', $pos), |
451 | 472 | ); |
452 | - if ($ns != '') |
|
453 | - $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
473 | + if ($ns != '') { |
|
474 | + $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
475 | + } |
|
454 | 476 | foreach ($positions as $k => $dummy) |
455 | 477 | { |
456 | - if ($dummy === false) |
|
457 | - unset($positions[$k]); |
|
478 | + if ($dummy === false) { |
|
479 | + unset($positions[$k]); |
|
480 | + } |
|
458 | 481 | } |
459 | 482 | |
460 | 483 | $old = $pos; |
461 | 484 | $pos = empty($positions) ? $n : min($positions); |
462 | 485 | |
463 | - if ($pos - $old > 0) |
|
464 | - $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
465 | - if ($pos >= $n) |
|
466 | - break; |
|
486 | + if ($pos - $old > 0) { |
|
487 | + $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
488 | + } |
|
489 | + if ($pos >= $n) { |
|
490 | + break; |
|
491 | + } |
|
467 | 492 | |
468 | 493 | if ($smcFunc['substr']($data, $pos, 1) == '<') |
469 | 494 | { |
470 | 495 | $pos2 = $smcFunc['strpos']($data, '>', $pos); |
471 | - if ($pos2 === false) |
|
472 | - $pos2 = $n; |
|
473 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '/') |
|
474 | - $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
475 | - else |
|
476 | - $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == '/') { |
|
500 | + $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
501 | + } else { |
|
502 | + $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']') |
|
505 | + } elseif ($smcFunc['substr']($data, $pos, 1) == ']') |
|
480 | 506 | { |
481 | 507 | $cdata .= ']]>]< == '&') |
|
509 | + } elseif ($smcFunc['substr']($data, $pos, 1) == '&') |
|
485 | 510 | { |
486 | 511 | $pos2 = $smcFunc['strpos']($data, ';', $pos); |
487 | - if ($pos2 === false) |
|
488 | - $pos2 = $n; |
|
512 | + if ($pos2 === false) { |
|
513 | + $pos2 = $n; |
|
514 | + } |
|
489 | 515 | $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1); |
490 | 516 | |
491 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '#') |
|
492 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
493 | - elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) |
|
494 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '< == '#') { |
|
518 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
519 | + } elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) { |
|
520 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
521 | + } |
|
495 | 522 | |
496 | 523 | $pos = $pos2 + 1; |
497 | 524 | } |
@@ -530,8 +557,9 @@ discard block |
||
530 | 557 | 'gender', |
531 | 558 | 'blurb', |
532 | 559 | ); |
533 | - if ($xml_format != 'atom') |
|
534 | - $keysToCdata[] = 'category'; |
|
560 | + if ($xml_format != 'atom') { |
|
561 | + $keysToCdata[] = 'category'; |
|
562 | + } |
|
535 | 563 | |
536 | 564 | if (!empty($forceCdataKeys)) |
537 | 565 | { |
@@ -547,8 +575,9 @@ discard block |
||
547 | 575 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
548 | 576 | |
549 | 577 | // Skip it, it's been set to null. |
550 | - if ($val === null && $attrs === null) |
|
551 | - continue; |
|
578 | + if ($val === null && $attrs === null) { |
|
579 | + continue; |
|
580 | + } |
|
552 | 581 | |
553 | 582 | // If a tag was passed, use it instead of the key. |
554 | 583 | $key = isset($tag) ? $tag : $key; |
@@ -557,8 +586,9 @@ discard block |
||
557 | 586 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
558 | 587 | |
559 | 588 | // If the value should maybe be CDATA, do that now. |
560 | - if (!is_array($val) && in_array($key, $keysToCdata)) |
|
561 | - $val = cdata_parse($val, $ns, $forceCdata); |
|
589 | + if (!is_array($val) && in_array($key, $keysToCdata)) { |
|
590 | + $val = cdata_parse($val, $ns, $forceCdata); |
|
591 | + } |
|
562 | 592 | |
563 | 593 | // First let's indent! |
564 | 594 | echo "\n", str_repeat("\t", $i); |
@@ -570,21 +600,22 @@ discard block |
||
570 | 600 | |
571 | 601 | if (!empty($attrs)) |
572 | 602 | { |
573 | - foreach ($attrs as $attr_key => $attr_value) |
|
574 | - echo ' ', $attr_key, '="', $attr_value, '"'; |
|
603 | + foreach ($attrs as $attr_key => $attr_value) { |
|
604 | + echo ' ', $attr_key, '="', $attr_value, '"'; |
|
605 | + } |
|
575 | 606 | } |
576 | 607 | |
577 | 608 | echo ' />'; |
578 | - } |
|
579 | - else |
|
609 | + } else |
|
580 | 610 | { |
581 | 611 | // Beginning tag. |
582 | 612 | echo '<', $key; |
583 | 613 | |
584 | 614 | if (!empty($attrs)) |
585 | 615 | { |
586 | - foreach ($attrs as $attr_key => $attr_value) |
|
587 | - echo ' ', $attr_key, '="', $attr_value, '"'; |
|
616 | + foreach ($attrs as $attr_key => $attr_value) { |
|
617 | + echo ' ', $attr_key, '="', $attr_value, '"'; |
|
618 | + } |
|
588 | 619 | } |
589 | 620 | |
590 | 621 | echo '>'; |
@@ -597,11 +628,13 @@ discard block |
||
597 | 628 | echo "\n", str_repeat("\t", $i); |
598 | 629 | } |
599 | 630 | // A string with returns in it.... show this as a multiline element. |
600 | - elseif (strpos($val, "\n") !== false) |
|
601 | - echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
631 | + elseif (strpos($val, "\n") !== false) { |
|
632 | + echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
633 | + } |
|
602 | 634 | // A simple string. |
603 | - else |
|
604 | - echo fix_possible_url($val); |
|
635 | + else { |
|
636 | + echo fix_possible_url($val); |
|
637 | + } |
|
605 | 638 | |
606 | 639 | // Ending tag. |
607 | 640 | echo '</', $key, '>'; |
@@ -621,8 +654,9 @@ discard block |
||
621 | 654 | { |
622 | 655 | global $scripturl, $smcFunc; |
623 | 656 | |
624 | - if (!allowedTo('view_mlist')) |
|
625 | - return array(); |
|
657 | + if (!allowedTo('view_mlist')) { |
|
658 | + return array(); |
|
659 | + } |
|
626 | 660 | |
627 | 661 | // Find the most recent members. |
628 | 662 | $request = $smcFunc['db_query']('', ' |
@@ -638,8 +672,8 @@ discard block |
||
638 | 672 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
639 | 673 | { |
640 | 674 | // Make the data look rss-ish. |
641 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
642 | - $data[] = array( |
|
675 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
676 | + $data[] = array( |
|
643 | 677 | 'tag' => 'item', |
644 | 678 | 'content' => array( |
645 | 679 | array( |
@@ -664,8 +698,8 @@ discard block |
||
664 | 698 | ), |
665 | 699 | ), |
666 | 700 | ); |
667 | - elseif ($xml_format == 'rdf') |
|
668 | - $data[] = array( |
|
701 | + } elseif ($xml_format == 'rdf') { |
|
702 | + $data[] = array( |
|
669 | 703 | 'tag' => 'item', |
670 | 704 | 'attributes' => array('rdf:about' => fix_possible_url($scripturl . '?action=profile;u=' . $row['id_member'])), |
671 | 705 | 'content' => array( |
@@ -683,8 +717,8 @@ discard block |
||
683 | 717 | ), |
684 | 718 | ), |
685 | 719 | ); |
686 | - elseif ($xml_format == 'atom') |
|
687 | - $data[] = array( |
|
720 | + } elseif ($xml_format == 'atom') { |
|
721 | + $data[] = array( |
|
688 | 722 | 'tag' => 'entry', |
689 | 723 | 'content' => array( |
690 | 724 | array( |
@@ -713,9 +747,10 @@ discard block |
||
713 | 747 | ), |
714 | 748 | ), |
715 | 749 | ); |
750 | + } |
|
716 | 751 | // More logical format for the data, but harder to apply. |
717 | - else |
|
718 | - $data[] = array( |
|
752 | + else { |
|
753 | + $data[] = array( |
|
719 | 754 | 'tag' => 'member', |
720 | 755 | 'content' => array( |
721 | 756 | array( |
@@ -736,6 +771,7 @@ discard block |
||
736 | 771 | ), |
737 | 772 | ), |
738 | 773 | ); |
774 | + } |
|
739 | 775 | } |
740 | 776 | $smcFunc['db_free_result']($request); |
741 | 777 | |
@@ -796,22 +832,24 @@ discard block |
||
796 | 832 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
797 | 833 | { |
798 | 834 | $smcFunc['db_free_result']($request); |
799 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
800 | - unset($context['optimize_msg']['lowest']); |
|
801 | - else |
|
802 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
835 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
836 | + unset($context['optimize_msg']['lowest']); |
|
837 | + } else { |
|
838 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
839 | + } |
|
803 | 840 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
804 | 841 | $loops++; |
842 | + } else { |
|
843 | + $done = true; |
|
805 | 844 | } |
806 | - else |
|
807 | - $done = true; |
|
808 | 845 | } |
809 | 846 | $data = array(); |
810 | 847 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
811 | 848 | { |
812 | 849 | // Limit the length of the message, if the option is set. |
813 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
814 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
850 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
851 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
852 | + } |
|
815 | 853 | |
816 | 854 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
817 | 855 | |
@@ -838,8 +876,9 @@ discard block |
||
838 | 876 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
839 | 877 | { |
840 | 878 | // Include approved attachments only |
841 | - if ($attach['approved']) |
|
842 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
879 | + if ($attach['approved']) { |
|
880 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
881 | + } |
|
843 | 882 | } |
844 | 883 | $smcFunc['db_free_result']($attach_request); |
845 | 884 | |
@@ -847,16 +886,17 @@ discard block |
||
847 | 886 | if (!empty($loaded_attachments)) |
848 | 887 | { |
849 | 888 | uasort($loaded_attachments, function($a, $b) { |
850 | - if ($a['filesize'] == $b['filesize']) |
|
851 | - return 0; |
|
889 | + if ($a['filesize'] == $b['filesize']) { |
|
890 | + return 0; |
|
891 | + } |
|
852 | 892 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
853 | 893 | }); |
894 | + } else { |
|
895 | + $loaded_attachments = null; |
|
854 | 896 | } |
855 | - else |
|
856 | - $loaded_attachments = null; |
|
897 | + } else { |
|
898 | + $loaded_attachments = null; |
|
857 | 899 | } |
858 | - else |
|
859 | - $loaded_attachments = null; |
|
860 | 900 | |
861 | 901 | // Being news, this actually makes sense in rss format. |
862 | 902 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
@@ -870,9 +910,9 @@ discard block |
||
870 | 910 | 'length' => $attachment['filesize'], |
871 | 911 | 'type' => $attachment['mime_type'], |
872 | 912 | ); |
913 | + } else { |
|
914 | + $enclosure = null; |
|
873 | 915 | } |
874 | - else |
|
875 | - $enclosure = null; |
|
876 | 916 | |
877 | 917 | $data[] = array( |
878 | 918 | 'tag' => 'item', |
@@ -915,8 +955,7 @@ discard block |
||
915 | 955 | ), |
916 | 956 | ), |
917 | 957 | ); |
918 | - } |
|
919 | - elseif ($xml_format == 'rdf') |
|
958 | + } elseif ($xml_format == 'rdf') |
|
920 | 959 | { |
921 | 960 | $data[] = array( |
922 | 961 | 'tag' => 'item', |
@@ -940,8 +979,7 @@ discard block |
||
940 | 979 | ), |
941 | 980 | ), |
942 | 981 | ); |
943 | - } |
|
944 | - elseif ($xml_format == 'atom') |
|
982 | + } elseif ($xml_format == 'atom') |
|
945 | 983 | { |
946 | 984 | // Only one attachment allowed |
947 | 985 | if (!empty($loaded_attachments)) |
@@ -953,9 +991,9 @@ discard block |
||
953 | 991 | 'length' => $attachment['filesize'], |
954 | 992 | 'type' => $attachment['mime_type'], |
955 | 993 | ); |
994 | + } else { |
|
995 | + $enclosure = null; |
|
956 | 996 | } |
957 | - else |
|
958 | - $enclosure = null; |
|
959 | 997 | |
960 | 998 | $data[] = array( |
961 | 999 | 'tag' => 'entry', |
@@ -1055,9 +1093,9 @@ discard block |
||
1055 | 1093 | ) |
1056 | 1094 | ); |
1057 | 1095 | } |
1096 | + } else { |
|
1097 | + $attachments = null; |
|
1058 | 1098 | } |
1059 | - else |
|
1060 | - $attachments = null; |
|
1061 | 1099 | |
1062 | 1100 | $data[] = array( |
1063 | 1101 | 'tag' => 'article', |
@@ -1175,22 +1213,25 @@ discard block |
||
1175 | 1213 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
1176 | 1214 | { |
1177 | 1215 | $smcFunc['db_free_result']($request); |
1178 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
1179 | - unset($context['optimize_msg']['lowest']); |
|
1180 | - else |
|
1181 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1216 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
1217 | + unset($context['optimize_msg']['lowest']); |
|
1218 | + } else { |
|
1219 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1220 | + } |
|
1182 | 1221 | $loops++; |
1222 | + } else { |
|
1223 | + $done = true; |
|
1183 | 1224 | } |
1184 | - else |
|
1185 | - $done = true; |
|
1186 | 1225 | } |
1187 | 1226 | $messages = array(); |
1188 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1189 | - $messages[] = $row['id_msg']; |
|
1227 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1228 | + $messages[] = $row['id_msg']; |
|
1229 | + } |
|
1190 | 1230 | $smcFunc['db_free_result']($request); |
1191 | 1231 | |
1192 | - if (empty($messages)) |
|
1193 | - return array(); |
|
1232 | + if (empty($messages)) { |
|
1233 | + return array(); |
|
1234 | + } |
|
1194 | 1235 | |
1195 | 1236 | // Find the most recent posts this user can see. |
1196 | 1237 | $request = $smcFunc['db_query']('', ' |
@@ -1220,8 +1261,9 @@ discard block |
||
1220 | 1261 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1221 | 1262 | { |
1222 | 1263 | // Limit the length of the message, if the option is set. |
1223 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
1224 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1264 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
1265 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1266 | + } |
|
1225 | 1267 | |
1226 | 1268 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
1227 | 1269 | |
@@ -1248,8 +1290,9 @@ discard block |
||
1248 | 1290 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
1249 | 1291 | { |
1250 | 1292 | // Include approved attachments only |
1251 | - if ($attach['approved']) |
|
1252 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1293 | + if ($attach['approved']) { |
|
1294 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1295 | + } |
|
1253 | 1296 | } |
1254 | 1297 | $smcFunc['db_free_result']($attach_request); |
1255 | 1298 | |
@@ -1257,16 +1300,17 @@ discard block |
||
1257 | 1300 | if (!empty($loaded_attachments)) |
1258 | 1301 | { |
1259 | 1302 | uasort($loaded_attachments, function($a, $b) { |
1260 | - if ($a['filesize'] == $b['filesize']) |
|
1261 | - return 0; |
|
1303 | + if ($a['filesize'] == $b['filesize']) { |
|
1304 | + return 0; |
|
1305 | + } |
|
1262 | 1306 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1263 | 1307 | }); |
1308 | + } else { |
|
1309 | + $loaded_attachments = null; |
|
1264 | 1310 | } |
1265 | - else |
|
1266 | - $loaded_attachments = null; |
|
1311 | + } else { |
|
1312 | + $loaded_attachments = null; |
|
1267 | 1313 | } |
1268 | - else |
|
1269 | - $loaded_attachments = null; |
|
1270 | 1314 | |
1271 | 1315 | // Doesn't work as well as news, but it kinda does.. |
1272 | 1316 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
@@ -1280,9 +1324,9 @@ discard block |
||
1280 | 1324 | 'length' => $attachment['filesize'], |
1281 | 1325 | 'type' => $attachment['mime_type'], |
1282 | 1326 | ); |
1327 | + } else { |
|
1328 | + $enclosure = null; |
|
1283 | 1329 | } |
1284 | - else |
|
1285 | - $enclosure = null; |
|
1286 | 1330 | |
1287 | 1331 | $data[] = array( |
1288 | 1332 | 'tag' => 'item', |
@@ -1325,8 +1369,7 @@ discard block |
||
1325 | 1369 | ), |
1326 | 1370 | ), |
1327 | 1371 | ); |
1328 | - } |
|
1329 | - elseif ($xml_format == 'rdf') |
|
1372 | + } elseif ($xml_format == 'rdf') |
|
1330 | 1373 | { |
1331 | 1374 | $data[] = array( |
1332 | 1375 | 'tag' => 'item', |
@@ -1350,8 +1393,7 @@ discard block |
||
1350 | 1393 | ), |
1351 | 1394 | ), |
1352 | 1395 | ); |
1353 | - } |
|
1354 | - elseif ($xml_format == 'atom') |
|
1396 | + } elseif ($xml_format == 'atom') |
|
1355 | 1397 | { |
1356 | 1398 | // Only one attachment allowed |
1357 | 1399 | if (!empty($loaded_attachments)) |
@@ -1363,9 +1405,9 @@ discard block |
||
1363 | 1405 | 'length' => $attachment['filesize'], |
1364 | 1406 | 'type' => $attachment['mime_type'], |
1365 | 1407 | ); |
1408 | + } else { |
|
1409 | + $enclosure = null; |
|
1366 | 1410 | } |
1367 | - else |
|
1368 | - $enclosure = null; |
|
1369 | 1411 | |
1370 | 1412 | $data[] = array( |
1371 | 1413 | 'tag' => 'entry', |
@@ -1465,9 +1507,9 @@ discard block |
||
1465 | 1507 | ) |
1466 | 1508 | ); |
1467 | 1509 | } |
1510 | + } else { |
|
1511 | + $attachments = null; |
|
1468 | 1512 | } |
1469 | - else |
|
1470 | - $attachments = null; |
|
1471 | 1513 | |
1472 | 1514 | $data[] = array( |
1473 | 1515 | 'tag' => 'recent-post', |
@@ -1586,14 +1628,16 @@ discard block |
||
1586 | 1628 | global $scripturl, $memberContext, $user_profile, $user_info; |
1587 | 1629 | |
1588 | 1630 | // You must input a valid user.... |
1589 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
1590 | - return array(); |
|
1631 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
1632 | + return array(); |
|
1633 | + } |
|
1591 | 1634 | |
1592 | 1635 | // Make sure the id is a number and not "I like trying to hack the database". |
1593 | 1636 | $_GET['u'] = (int) $_GET['u']; |
1594 | 1637 | // Load the member's contextual information! |
1595 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
1596 | - return array(); |
|
1638 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
1639 | + return array(); |
|
1640 | + } |
|
1597 | 1641 | |
1598 | 1642 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
1599 | 1643 | $profile = &$memberContext[$_GET['u']]; |
@@ -1629,8 +1673,7 @@ discard block |
||
1629 | 1673 | ), |
1630 | 1674 | ) |
1631 | 1675 | ); |
1632 | - } |
|
1633 | - elseif ($xml_format == 'rdf') |
|
1676 | + } elseif ($xml_format == 'rdf') |
|
1634 | 1677 | { |
1635 | 1678 | $data[] = array( |
1636 | 1679 | 'tag' => 'item', |
@@ -1654,8 +1697,7 @@ discard block |
||
1654 | 1697 | ), |
1655 | 1698 | ) |
1656 | 1699 | ); |
1657 | - } |
|
1658 | - elseif ($xml_format == 'atom') |
|
1700 | + } elseif ($xml_format == 'atom') |
|
1659 | 1701 | { |
1660 | 1702 | $data[] = array( |
1661 | 1703 | 'tag' => 'entry', |
@@ -1708,8 +1750,7 @@ discard block |
||
1708 | 1750 | ), |
1709 | 1751 | ) |
1710 | 1752 | ); |
1711 | - } |
|
1712 | - else |
|
1753 | + } else |
|
1713 | 1754 | { |
1714 | 1755 | $data = array( |
1715 | 1756 | array( |