Chris@76: 'm.id_msg <= b.id_last_msg',
Chris@76: );
Chris@76: if (!empty($_REQUEST['c']) && empty($board))
Chris@76: {
Chris@76: $_REQUEST['c'] = explode(',', $_REQUEST['c']);
Chris@76: foreach ($_REQUEST['c'] as $i => $c)
Chris@76: $_REQUEST['c'][$i] = (int) $c;
Chris@76:
Chris@76: if (count($_REQUEST['c']) == 1)
Chris@76: {
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT name
Chris@76: FROM {db_prefix}categories
Chris@76: WHERE id_cat = {int:current_category}',
Chris@76: array(
Chris@76: 'current_category' => (int) $_REQUEST['c'][0],
Chris@76: )
Chris@76: );
Chris@76: list ($feed_title) = $smcFunc['db_fetch_row']($request);
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: $feed_title = ' - ' . strip_tags($feed_title);
Chris@76: }
Chris@76:
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT b.id_board, b.num_posts
Chris@76: FROM {db_prefix}boards AS b
Chris@76: WHERE b.id_cat IN ({array_int:current_category_list})
Chris@76: AND {query_see_board}',
Chris@76: array(
Chris@76: 'current_category_list' => $_REQUEST['c'],
Chris@76: )
Chris@76: );
Chris@76: $total_cat_posts = 0;
Chris@76: $boards = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: $boards[] = $row['id_board'];
Chris@76: $total_cat_posts += $row['num_posts'];
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: if (!empty($boards))
Chris@76: $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
Chris@76:
Chris@76: // Try to limit the number of messages we look through.
Chris@76: if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
Chris@76: $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
Chris@76: }
Chris@76: elseif (!empty($_REQUEST['boards']))
Chris@76: {
Chris@76: $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
Chris@76: foreach ($_REQUEST['boards'] as $i => $b)
Chris@76: $_REQUEST['boards'][$i] = (int) $b;
Chris@76:
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT b.id_board, b.num_posts, b.name
Chris@76: FROM {db_prefix}boards AS b
Chris@76: WHERE b.id_board IN ({array_int:board_list})
Chris@76: AND {query_see_board}
Chris@76: LIMIT ' . count($_REQUEST['boards']),
Chris@76: array(
Chris@76: 'board_list' => $_REQUEST['boards'],
Chris@76: )
Chris@76: );
Chris@76:
Chris@76: // Either the board specified doesn't exist or you have no access.
Chris@76: $num_boards = $smcFunc['db_num_rows']($request);
Chris@76: if ($num_boards == 0)
Chris@76: fatal_lang_error('no_board');
Chris@76:
Chris@76: $total_posts = 0;
Chris@76: $boards = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: if ($num_boards == 1)
Chris@76: $feed_title = ' - ' . strip_tags($row['name']);
Chris@76:
Chris@76: $boards[] = $row['id_board'];
Chris@76: $total_posts += $row['num_posts'];
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: if (!empty($boards))
Chris@76: $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
Chris@76:
Chris@76: // The more boards, the more we're going to look through...
Chris@76: if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
Chris@76: $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
Chris@76: }
Chris@76: elseif (!empty($board))
Chris@76: {
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT num_posts
Chris@76: FROM {db_prefix}boards
Chris@76: WHERE id_board = {int:current_board}
Chris@76: LIMIT 1',
Chris@76: array(
Chris@76: 'current_board' => $board,
Chris@76: )
Chris@76: );
Chris@76: list ($total_posts) = $smcFunc['db_fetch_row']($request);
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: $feed_title = ' - ' . strip_tags($board_info['name']);
Chris@76:
Chris@76: $query_this_board = 'b.id_board = ' . $board;
Chris@76:
Chris@76: // Try to look through just a few messages, if at all possible.
Chris@76: if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
Chris@76: $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
Chris@76: }
Chris@76: else
Chris@76: {
Chris@76: $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
Chris@76: AND b.id_board != ' . $modSettings['recycle_board'] : '');
Chris@76: $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 100 - $_GET['limit'] * 5);
Chris@76: }
Chris@76:
Chris@76: // Show in rss or proprietary format?
Chris@76: $xml_format = isset($_GET['type']) && in_array($_GET['type'], array('smf', 'rss', 'rss2', 'atom', 'rdf', 'webslice')) ? $_GET['type'] : 'smf';
Chris@76:
Chris@76: // !!! Birthdays?
Chris@76:
Chris@76: // List all the different types of data they can pull.
Chris@76: $subActions = array(
Chris@76: 'recent' => array('getXmlRecent', 'recent-post'),
Chris@76: 'news' => array('getXmlNews', 'article'),
Chris@76: 'members' => array('getXmlMembers', 'member'),
Chris@76: 'profile' => array('getXmlProfile', null),
Chris@76: );
Chris@76: if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
Chris@76: $_GET['sa'] = 'recent';
Chris@76:
Chris@76: //!!! Temp - webslices doesn't do everything yet.
Chris@76: if ($xml_format == 'webslice' && $_GET['sa'] != 'recent')
Chris@76: $xml_format = 'rss2';
Chris@76: // 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: elseif ($xml_format == 'webslice')
Chris@76: {
Chris@76: $context['user'] += $user_info;
Chris@76: $cdata_override = true;
Chris@76: loadTemplate('Xml');
Chris@76: }
Chris@76:
Chris@76: // We only want some information, not all of it.
Chris@76: $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
Chris@76: foreach (array('board', 'boards', 'c') as $var)
Chris@76: if (isset($_REQUEST[$var]))
Chris@76: $cachekey[] = $_REQUEST[$var];
Chris@76: $cachekey = md5(serialize($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
Chris@76: $cache_t = microtime();
Chris@76:
Chris@76: // Get the associative array representing the xml.
Chris@76: if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
Chris@76: $xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
Chris@76: if (empty($xml))
Chris@76: {
Chris@76: $xml = $subActions[$_GET['sa']][0]($xml_format);
Chris@76:
Chris@76: if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
Chris@76: || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
Chris@76: cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
Chris@76: }
Chris@76:
Chris@76: $feed_title = htmlspecialchars(strip_tags($context['forum_name'])) . (isset($feed_title) ? $feed_title : '');
Chris@76:
Chris@76: // This is an xml file....
Chris@76: ob_end_clean();
Chris@76: if (!empty($modSettings['enableCompressedOutput']))
Chris@76: @ob_start('ob_gzhandler');
Chris@76: else
Chris@76: ob_start();
Chris@76:
Chris@76: if ($xml_format == 'smf' || isset($_REQUEST['debug']))
Chris@76: header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
Chris@76: elseif ($xml_format == 'rss' || $xml_format == 'rss2' || $xml_format == 'webslice')
Chris@76: header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
Chris@76: elseif ($xml_format == 'atom')
Chris@76: header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
Chris@76: elseif ($xml_format == 'rdf')
Chris@76: 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:
Chris@76: // First, output the xml header.
Chris@76: echo '';
Chris@76:
Chris@76: // Are we outputting an rss feed or one with more information?
Chris@76: if ($xml_format == 'rss' || $xml_format == 'rss2')
Chris@76: {
Chris@76: // Start with an RSS 2.0 header.
Chris@76: echo '
Chris@76:
Chris@76:
Chris@76: ', $feed_title, '
Chris@76: ', $scripturl, '
Chris@76: ';
Chris@76:
Chris@76: // Output all of the associative array, start indenting with 2 tabs, and name everything "item".
Chris@76: dumpTags($xml, 2, 'item', $xml_format);
Chris@76:
Chris@76: // Output the footer of the xml.
Chris@76: echo '
Chris@76:
Chris@76: ';
Chris@76: }
Chris@76: elseif ($xml_format == 'webslice')
Chris@76: {
Chris@76: $context['recent_posts_data'] = $xml;
Chris@76:
Chris@76: // This always has RSS 2
Chris@76: echo '
Chris@76:
Chris@76:
Chris@76: ', $feed_title, ' - ', $txt['recent_posts'], '
Chris@76: ', $scripturl, '?action=recent
Chris@76:
Chris@76: -
Chris@76: ', $feed_title, ' - ', $txt['recent_posts'], '
Chris@76: ', $scripturl, '?action=recent
Chris@76:
Chris@76:
Chris@76:
Chris@76: ';
Chris@76: }
Chris@76: elseif ($xml_format == 'atom')
Chris@76: {
Chris@76: echo '
Chris@76:
Chris@76: ', $feed_title, '
Chris@76:
Chris@76:
Chris@76: ', gmstrftime('%Y-%m-%dT%H:%M:%SZ'), '
Chris@76:
Chris@76: SMF
Chris@76:
Chris@76: ', strip_tags($context['forum_name']), '
Chris@76: ';
Chris@76:
Chris@76: dumpTags($xml, 2, 'entry', $xml_format);
Chris@76:
Chris@76: echo '
Chris@76: ';
Chris@76: }
Chris@76: elseif ($xml_format == 'rdf')
Chris@76: {
Chris@76: echo '
Chris@76:
Chris@76:
Chris@76: ', $feed_title, '
Chris@76: ', $scripturl, '
Chris@76:
Chris@76:
Chris@76: ';
Chris@76:
Chris@76: foreach ($xml as $item)
Chris@76: echo '
Chris@76: ';
Chris@76:
Chris@76: echo '
Chris@76:
Chris@76:
Chris@76:
Chris@76: ';
Chris@76:
Chris@76: dumpTags($xml, 1, 'item', $xml_format);
Chris@76:
Chris@76: echo '
Chris@76: ';
Chris@76: }
Chris@76: // Otherwise, we're using our proprietary formats - they give more data, though.
Chris@76: else
Chris@76: {
Chris@76: echo '
Chris@76: ';
Chris@76:
Chris@76: // Dump out that associative array. Indent properly.... and use the right names for the base elements.
Chris@76: dumpTags($xml, 1, $subActions[$_GET['sa']][1], $xml_format);
Chris@76:
Chris@76: echo '
Chris@76: ';
Chris@76: }
Chris@76:
Chris@76: obExit(false);
Chris@76: }
Chris@76:
Chris@76: function fix_possible_url($val)
Chris@76: {
Chris@76: global $modSettings, $context, $scripturl;
Chris@76:
Chris@76: if (substr($val, 0, strlen($scripturl)) != $scripturl)
Chris@76: return $val;
Chris@76:
Chris@76: call_integration_hook('integrate_fix_url', array(&$val));
Chris@76:
Chris@76: 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: return $val;
Chris@76:
Chris@76: $val = preg_replace('/^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$/e', '\'\' . $scripturl . \'/\' . strtr(\'$1\', \'&;=\', \'//,\') . \'.html$2\'', $val);
Chris@76: return $val;
Chris@76: }
Chris@76:
Chris@76: function cdata_parse($data, $ns = '')
Chris@76: {
Chris@76: global $smcFunc, $cdata_override;
Chris@76:
Chris@76: // Are we not doing it?
Chris@76: if (!empty($cdata_override))
Chris@76: return $data;
Chris@76:
Chris@76: $cdata = ' $dummy)
Chris@76: {
Chris@76: if ($dummy === false)
Chris@76: unset($positions[$k]);
Chris@76: }
Chris@76:
Chris@76: $old = $pos;
Chris@76: $pos = empty($positions) ? $n : min($positions);
Chris@76:
Chris@76: if ($pos - $old > 0)
Chris@76: $cdata .= $smcFunc['substr']($data, $old, $pos - $old);
Chris@76: if ($pos >= $n)
Chris@76: break;
Chris@76:
Chris@76: if ($smcFunc['substr']($data, $pos, 1) == '<')
Chris@76: {
Chris@76: $pos2 = $smcFunc['strpos']($data, '>', $pos);
Chris@76: if ($pos2 === false)
Chris@76: $pos2 = $n;
Chris@76: if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
Chris@76: $cdata .= ']]>' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . ']' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '';
Chris@76:
Chris@76: return strtr($cdata, array('' => ''));
Chris@76: }
Chris@76:
Chris@76: function dumpTags($data, $i, $tag = null, $xml_format = '')
Chris@76: {
Chris@76: global $modSettings, $context, $scripturl;
Chris@76:
Chris@76: // For every array in the data...
Chris@76: foreach ($data as $key => $val)
Chris@76: {
Chris@76: // Skip it, it's been set to null.
Chris@76: if ($val === null)
Chris@76: continue;
Chris@76:
Chris@76: // If a tag was passed, use it instead of the key.
Chris@76: $key = isset($tag) ? $tag : $key;
Chris@76:
Chris@76: // First let's indent!
Chris@76: echo "\n", str_repeat("\t", $i);
Chris@76:
Chris@76: // Grr, I hate kludges... almost worth doing it properly, here, but not quite.
Chris@76: if ($xml_format == 'atom' && $key == 'link')
Chris@76: {
Chris@76: echo '';
Chris@76: continue;
Chris@76: }
Chris@76:
Chris@76: // If it's empty/0/nothing simply output an empty tag.
Chris@76: if ($val == '')
Chris@76: echo '<', $key, ' />';
Chris@76: else
Chris@76: {
Chris@76: // Beginning tag.
Chris@76: if ($xml_format == 'rdf' && $key == 'item' && isset($val['link']))
Chris@76: {
Chris@76: echo '<', $key, ' rdf:about="', fix_possible_url($val['link']), '">';
Chris@76: echo "\n", str_repeat("\t", $i + 1);
Chris@76: echo 'text/html';
Chris@76: }
Chris@76: elseif ($xml_format == 'atom' && $key == 'summary')
Chris@76: echo '<', $key, ' type="html">';
Chris@76: else
Chris@76: echo '<', $key, '>';
Chris@76:
Chris@76: if (is_array($val))
Chris@76: {
Chris@76: // An array. Dump it, and then indent the tag.
Chris@76: dumpTags($val, $i + 1, null, $xml_format);
Chris@76: echo "\n", str_repeat("\t", $i), '', $key, '>';
Chris@76: }
Chris@76: // A string with returns in it.... show this as a multiline element.
Chris@76: elseif (strpos($val, "\n") !== false || strpos($val, '
') !== false)
Chris@76: echo "\n", fix_possible_url($val), "\n", str_repeat("\t", $i), '', $key, '>';
Chris@76: // A simple string.
Chris@76: else
Chris@76: echo fix_possible_url($val), '', $key, '>';
Chris@76: }
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: function getXmlMembers($xml_format)
Chris@76: {
Chris@76: global $scripturl, $smcFunc;
Chris@76:
Chris@76: if (!allowedTo('view_mlist'))
Chris@76: return array();
Chris@76:
Chris@76: // Find the most recent members.
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT id_member, member_name, real_name, date_registered, last_login
Chris@76: FROM {db_prefix}members
Chris@76: ORDER BY id_member DESC
Chris@76: LIMIT {int:limit}',
Chris@76: array(
Chris@76: 'limit' => $_GET['limit'],
Chris@76: )
Chris@76: );
Chris@76: $data = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: // Make the data look rss-ish.
Chris@76: if ($xml_format == 'rss' || $xml_format == 'rss2')
Chris@76: $data[] = array(
Chris@76: 'title' => cdata_parse($row['real_name']),
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
Chris@76: 'comments' => $scripturl . '?action=pm;sa=send;u=' . $row['id_member'],
Chris@76: 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['date_registered']),
Chris@76: 'guid' => $scripturl . '?action=profile;u=' . $row['id_member'],
Chris@76: );
Chris@76: elseif ($xml_format == 'rdf')
Chris@76: $data[] = array(
Chris@76: 'title' => cdata_parse($row['real_name']),
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
Chris@76: );
Chris@76: elseif ($xml_format == 'atom')
Chris@76: $data[] = array(
Chris@76: 'title' => cdata_parse($row['real_name']),
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $row['id_member'],
Chris@76: 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['date_registered']),
Chris@76: 'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['last_login']),
Chris@76: 'id' => $scripturl . '?action=profile;u=' . $row['id_member'],
Chris@76: );
Chris@76: // More logical format for the data, but harder to apply.
Chris@76: else
Chris@76: $data[] = array(
Chris@76: 'name' => cdata_parse($row['real_name']),
Chris@76: 'time' => htmlspecialchars(strip_tags(timeformat($row['date_registered']))),
Chris@76: 'id' => $row['id_member'],
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $row['id_member']
Chris@76: );
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: return $data;
Chris@76: }
Chris@76:
Chris@76: function getXmlNews($xml_format)
Chris@76: {
Chris@76: global $user_info, $scripturl, $modSettings, $board;
Chris@76: global $query_this_board, $smcFunc, $settings, $context;
Chris@76:
Chris@76: /* Find the latest posts that:
Chris@76: - are the first post in their topic.
Chris@76: - are on an any board OR in a specified board.
Chris@76: - can be seen by this user.
Chris@76: - are actually the latest posts. */
Chris@76:
Chris@76: $done = false;
Chris@76: $loops = 0;
Chris@76: while (!$done)
Chris@76: {
Chris@76: $optimize_msg = implode(' AND ', $context['optimize_msg']);
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT
Chris@76: m.smileys_enabled, m.poster_time, m.id_msg, m.subject, m.body, m.modified_time,
Chris@76: m.icon, t.id_topic, t.id_board, t.num_replies,
Chris@76: b.name AS bname,
Chris@76: mem.hide_email, IFNULL(mem.id_member, 0) AS id_member,
Chris@76: IFNULL(mem.email_address, m.poster_email) AS poster_email,
Chris@76: IFNULL(mem.real_name, m.poster_name) AS poster_name
Chris@76: FROM {db_prefix}topics AS t
Chris@76: INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
Chris@76: INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
Chris@76: WHERE ' . $query_this_board . (empty($optimize_msg) ? '' : '
Chris@76: AND {raw:optimize_msg}') . (empty($board) ? '' : '
Chris@76: AND t.id_board = {int:current_board}') . ($modSettings['postmod_active'] ? '
Chris@76: AND t.approved = {int:is_approved}' : '') . '
Chris@76: ORDER BY t.id_first_msg DESC
Chris@76: LIMIT {int:limit}',
Chris@76: array(
Chris@76: 'current_board' => $board,
Chris@76: 'is_approved' => 1,
Chris@76: 'limit' => $_GET['limit'],
Chris@76: 'optimize_msg' => $optimize_msg,
Chris@76: )
Chris@76: );
Chris@76: // If we don't have $_GET['limit'] results, try again with an unoptimized version covering all rows.
Chris@76: if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
Chris@76: {
Chris@76: $smcFunc['db_free_result']($request);
Chris@76: if (empty($_REQUEST['boards']) && empty($board))
Chris@76: unset($context['optimize_msg']['lowest']);
Chris@76: else
Chris@76: $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
Chris@76: $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
Chris@76: $loops++;
Chris@76: }
Chris@76: else
Chris@76: $done = true;
Chris@76: }
Chris@76: $data = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: // Limit the length of the message, if the option is set.
Chris@76: if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('
', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
Chris@76: $row['body'] = strtr($smcFunc['substr'](str_replace('
', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '
')) . '...';
Chris@76:
Chris@76: $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
Chris@76:
Chris@76: censorText($row['body']);
Chris@76: censorText($row['subject']);
Chris@76:
Chris@76: // Being news, this actually makes sense in rss format.
Chris@76: if ($xml_format == 'rss' || $xml_format == 'rss2')
Chris@76: $data[] = array(
Chris@76: 'title' => cdata_parse($row['subject']),
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
Chris@76: 'description' => cdata_parse($row['body']),
Chris@76: 'author' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
Chris@76: 'comments' => $scripturl . '?action=post;topic=' . $row['id_topic'] . '.0',
Chris@76: 'category' => '',
Chris@76: 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
Chris@76: 'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
Chris@76: );
Chris@76: elseif ($xml_format == 'rdf')
Chris@76: $data[] = array(
Chris@76: 'title' => cdata_parse($row['subject']),
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
Chris@76: 'description' => cdata_parse($row['body']),
Chris@76: );
Chris@76: elseif ($xml_format == 'atom')
Chris@76: $data[] = array(
Chris@76: 'title' => cdata_parse($row['subject']),
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
Chris@76: 'summary' => cdata_parse($row['body']),
Chris@76: 'category' => array('term' => $row['id_board'], 'label' => cdata_parse($row['bname'])),
Chris@76: 'author' => array(
Chris@76: 'name' => $row['poster_name'],
Chris@76: 'email' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
Chris@76: 'uri' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
Chris@76: ),
Chris@76: 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['poster_time']),
Chris@76: 'modified' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
Chris@76: 'id' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
Chris@76: 'icon' => $settings['images_url'] . '/icons/' . $row['icon'] . '.gif',
Chris@76: );
Chris@76: // The biggest difference here is more information.
Chris@76: else
Chris@76: $data[] = array(
Chris@76: 'time' => htmlspecialchars(strip_tags(timeformat($row['poster_time']))),
Chris@76: 'id' => $row['id_topic'],
Chris@76: 'subject' => cdata_parse($row['subject']),
Chris@76: 'body' => cdata_parse($row['body']),
Chris@76: 'poster' => array(
Chris@76: 'name' => cdata_parse($row['poster_name']),
Chris@76: 'id' => $row['id_member'],
Chris@76: 'link' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
Chris@76: ),
Chris@76: 'topic' => $row['id_topic'],
Chris@76: 'board' => array(
Chris@76: 'name' => cdata_parse($row['bname']),
Chris@76: 'id' => $row['id_board'],
Chris@76: 'link' => $scripturl . '?board=' . $row['id_board'] . '.0',
Chris@76: ),
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
Chris@76: );
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: return $data;
Chris@76: }
Chris@76:
Chris@76: function getXmlRecent($xml_format)
Chris@76: {
Chris@76: global $user_info, $scripturl, $modSettings, $board;
Chris@76: global $query_this_board, $smcFunc, $settings, $context;
Chris@76:
Chris@76: $done = false;
Chris@76: $loops = 0;
Chris@76: while (!$done)
Chris@76: {
Chris@76: $optimize_msg = implode(' AND ', $context['optimize_msg']);
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT m.id_msg
Chris@76: FROM {db_prefix}messages AS m
Chris@76: INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
Chris@76: WHERE ' . $query_this_board . (empty($optimize_msg) ? '' : '
Chris@76: AND {raw:optimize_msg}') . (empty($board) ? '' : '
Chris@76: AND m.id_board = {int:current_board}') . ($modSettings['postmod_active'] ? '
Chris@76: AND m.approved = {int:is_approved}' : '') . '
Chris@76: ORDER BY m.id_msg DESC
Chris@76: LIMIT {int:limit}',
Chris@76: array(
Chris@76: 'limit' => $_GET['limit'],
Chris@76: 'current_board' => $board,
Chris@76: 'is_approved' => 1,
Chris@76: 'optimize_msg' => $optimize_msg,
Chris@76: )
Chris@76: );
Chris@76: // If we don't have $_GET['limit'] results, try again with an unoptimized version covering all rows.
Chris@76: if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
Chris@76: {
Chris@76: $smcFunc['db_free_result']($request);
Chris@76: if (empty($_REQUEST['boards']) && empty($board))
Chris@76: unset($context['optimize_msg']['lowest']);
Chris@76: else
Chris@76: $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: $loops++;
Chris@76: }
Chris@76: else
Chris@76: $done = true;
Chris@76: }
Chris@76: $messages = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: $messages[] = $row['id_msg'];
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: if (empty($messages))
Chris@76: return array();
Chris@76:
Chris@76: // Find the most recent posts this user can see.
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT
Chris@76: m.smileys_enabled, m.poster_time, m.id_msg, m.subject, m.body, m.id_topic, t.id_board,
Chris@76: b.name AS bname, t.num_replies, m.id_member, m.icon, mf.id_member AS id_first_member,
Chris@76: IFNULL(mem.real_name, m.poster_name) AS poster_name, mf.subject AS first_subject,
Chris@76: IFNULL(memf.real_name, mf.poster_name) AS first_poster_name, mem.hide_email,
Chris@76: IFNULL(mem.email_address, m.poster_email) AS poster_email, m.modified_time
Chris@76: FROM {db_prefix}messages AS m
Chris@76: INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
Chris@76: INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
Chris@76: INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
Chris@76: LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
Chris@76: LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
Chris@76: WHERE m.id_msg IN ({array_int:message_list})
Chris@76: ' . (empty($board) ? '' : 'AND t.id_board = {int:current_board}') . '
Chris@76: ORDER BY m.id_msg DESC
Chris@76: LIMIT {int:limit}',
Chris@76: array(
Chris@76: 'limit' => $_GET['limit'],
Chris@76: 'current_board' => $board,
Chris@76: 'message_list' => $messages,
Chris@76: )
Chris@76: );
Chris@76: $data = array();
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: // Limit the length of the message, if the option is set.
Chris@76: if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('
', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
Chris@76: $row['body'] = strtr($smcFunc['substr'](str_replace('
', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '
')) . '...';
Chris@76:
Chris@76: $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
Chris@76:
Chris@76: censorText($row['body']);
Chris@76: censorText($row['subject']);
Chris@76:
Chris@76: // Doesn't work as well as news, but it kinda does..
Chris@76: if ($xml_format == 'rss' || $xml_format == 'rss2')
Chris@76: $data[] = array(
Chris@76: 'title' => $row['subject'],
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
Chris@76: 'description' => cdata_parse($row['body']),
Chris@76: 'author' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
Chris@76: 'category' => cdata_parse($row['bname']),
Chris@76: 'comments' => $scripturl . '?action=post;topic=' . $row['id_topic'] . '.0',
Chris@76: 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $row['poster_time']),
Chris@76: 'guid' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
Chris@76: );
Chris@76: elseif ($xml_format == 'rdf')
Chris@76: $data[] = array(
Chris@76: 'title' => $row['subject'],
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
Chris@76: 'description' => cdata_parse($row['body']),
Chris@76: );
Chris@76: elseif ($xml_format == 'atom')
Chris@76: $data[] = array(
Chris@76: 'title' => $row['subject'],
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
Chris@76: 'summary' => cdata_parse($row['body']),
Chris@76: 'category' => array(
Chris@76: 'term' => $row['id_board'],
Chris@76: 'label' => cdata_parse($row['bname'])
Chris@76: ),
Chris@76: 'author' => array(
Chris@76: 'name' => $row['poster_name'],
Chris@76: 'email' => in_array(showEmailAddress(!empty($row['hide_email']), $row['id_member']), array('yes', 'yes_permission_override')) ? $row['poster_email'] : null,
Chris@76: 'uri' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : ''
Chris@76: ),
Chris@76: 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['poster_time']),
Chris@76: 'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
Chris@76: 'id' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
Chris@76: 'icon' => $settings['images_url'] . '/icons/' . $row['icon'] . '.gif',
Chris@76: );
Chris@76: // A lot of information here. Should be enough to please the rss-ers.
Chris@76: else
Chris@76: $data[] = array(
Chris@76: 'time' => htmlspecialchars(strip_tags(timeformat($row['poster_time']))),
Chris@76: 'id' => $row['id_msg'],
Chris@76: 'subject' => cdata_parse($row['subject']),
Chris@76: 'body' => cdata_parse($row['body']),
Chris@76: 'starter' => array(
Chris@76: 'name' => cdata_parse($row['first_poster_name']),
Chris@76: 'id' => $row['id_first_member'],
Chris@76: 'link' => !empty($row['id_first_member']) ? $scripturl . '?action=profile;u=' . $row['id_first_member'] : ''
Chris@76: ),
Chris@76: 'poster' => array(
Chris@76: 'name' => cdata_parse($row['poster_name']),
Chris@76: 'id' => $row['id_member'],
Chris@76: 'link' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : ''
Chris@76: ),
Chris@76: 'topic' => array(
Chris@76: 'subject' => cdata_parse($row['first_subject']),
Chris@76: 'id' => $row['id_topic'],
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.new#new'
Chris@76: ),
Chris@76: 'board' => array(
Chris@76: 'name' => cdata_parse($row['bname']),
Chris@76: 'id' => $row['id_board'],
Chris@76: 'link' => $scripturl . '?board=' . $row['id_board'] . '.0'
Chris@76: ),
Chris@76: 'link' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']
Chris@76: );
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: return $data;
Chris@76: }
Chris@76:
Chris@76: function getXmlProfile($xml_format)
Chris@76: {
Chris@76: global $scripturl, $memberContext, $user_profile, $modSettings, $user_info;
Chris@76:
Chris@76: // You must input a valid user....
Chris@76: if (empty($_GET['u']) || loadMemberData((int) $_GET['u']) === false)
Chris@76: return array();
Chris@76:
Chris@76: // Make sure the id is a number and not "I like trying to hack the database".
Chris@76: $_GET['u'] = (int) $_GET['u'];
Chris@76: // Load the member's contextual information!
Chris@76: if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view_any'))
Chris@76: return array();
Chris@76:
Chris@76: // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type.
Chris@76: $profile = &$memberContext[$_GET['u']];
Chris@76:
Chris@76: if ($xml_format == 'rss' || $xml_format == 'rss2')
Chris@76: $data = array(array(
Chris@76: 'title' => cdata_parse($profile['name']),
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
Chris@76: 'description' => cdata_parse(isset($profile['group']) ? $profile['group'] : $profile['post_group']),
Chris@76: 'comments' => $scripturl . '?action=pm;sa=send;u=' . $profile['id'],
Chris@76: 'pubDate' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['date_registered']),
Chris@76: 'guid' => $scripturl . '?action=profile;u=' . $profile['id'],
Chris@76: ));
Chris@76: elseif ($xml_format == 'rdf')
Chris@76: $data = array(array(
Chris@76: 'title' => cdata_parse($profile['name']),
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
Chris@76: 'description' => cdata_parse(isset($profile['group']) ? $profile['group'] : $profile['post_group']),
Chris@76: ));
Chris@76: elseif ($xml_format == 'atom')
Chris@76: $data[] = array(
Chris@76: 'title' => cdata_parse($profile['name']),
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
Chris@76: 'summary' => cdata_parse(isset($profile['group']) ? $profile['group'] : $profile['post_group']),
Chris@76: 'author' => array(
Chris@76: 'name' => $profile['real_name'],
Chris@76: 'email' => in_array(showEmailAddress(!empty($profile['hide_email']), $profile['id']), array('yes', 'yes_permission_override')) ? $profile['email'] : null,
Chris@76: 'uri' => !empty($profile['website']) ? $profile['website']['url'] : ''
Chris@76: ),
Chris@76: 'published' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $user_profile[$profile['id']]['date_registered']),
Chris@76: 'updated' => gmstrftime('%Y-%m-%dT%H:%M:%SZ', $user_profile[$profile['id']]['last_login']),
Chris@76: 'id' => $scripturl . '?action=profile;u=' . $profile['id'],
Chris@76: 'logo' => !empty($profile['avatar']) ? $profile['avatar']['url'] : '',
Chris@76: );
Chris@76: else
Chris@76: {
Chris@76: $data = array(
Chris@76: 'username' => $user_info['is_admin'] || $user_info['id'] == $profile['id'] ? cdata_parse($profile['username']) : '',
Chris@76: 'name' => cdata_parse($profile['name']),
Chris@76: 'link' => $scripturl . '?action=profile;u=' . $profile['id'],
Chris@76: 'posts' => $profile['posts'],
Chris@76: 'post-group' => cdata_parse($profile['post_group']),
Chris@76: 'language' => cdata_parse($profile['language']),
Chris@76: 'last-login' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['last_login']),
Chris@76: 'registered' => gmdate('D, d M Y H:i:s \G\M\T', $user_profile[$profile['id']]['date_registered'])
Chris@76: );
Chris@76:
Chris@76: // Everything below here might not be set, and thus maybe shouldn't be displayed.
Chris@76: if ($profile['gender']['name'] != '')
Chris@76: $data['gender'] = cdata_parse($profile['gender']['name']);
Chris@76:
Chris@76: if ($profile['avatar']['name'] != '')
Chris@76: $data['avatar'] = $profile['avatar']['url'];
Chris@76:
Chris@76: // If they are online, show an empty tag... no reason to put anything inside it.
Chris@76: if ($profile['online']['is_online'])
Chris@76: $data['online'] = '';
Chris@76:
Chris@76: if ($profile['signature'] != '')
Chris@76: $data['signature'] = cdata_parse($profile['signature']);
Chris@76: if ($profile['blurb'] != '')
Chris@76: $data['blurb'] = cdata_parse($profile['blurb']);
Chris@76: if ($profile['location'] != '')
Chris@76: $data['location'] = cdata_parse($profile['location']);
Chris@76: if ($profile['title'] != '')
Chris@76: $data['title'] = cdata_parse($profile['title']);
Chris@76:
Chris@76: if (!empty($profile['icq']['name']) && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
Chris@76: $data['icq'] = $profile['icq']['name'];
Chris@76: if ($profile['aim']['name'] != '' && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
Chris@76: $data['aim'] = $profile['aim']['name'];
Chris@76: if ($profile['msn']['name'] != '' && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
Chris@76: $data['msn'] = $profile['msn']['name'];
Chris@76: if ($profile['yim']['name'] != '' && !(!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']))
Chris@76: $data['yim'] = $profile['yim']['name'];
Chris@76:
Chris@76: if ($profile['website']['title'] != '')
Chris@76: $data['website'] = array(
Chris@76: 'title' => cdata_parse($profile['website']['title']),
Chris@76: 'link' => $profile['website']['url']
Chris@76: );
Chris@76:
Chris@76: if ($profile['group'] != '')
Chris@76: $data['position'] = cdata_parse($profile['group']);
Chris@76:
Chris@76: if (!empty($modSettings['karmaMode']))
Chris@76: $data['karma'] = array(
Chris@76: 'good' => $profile['karma']['good'],
Chris@76: 'bad' => $profile['karma']['bad']
Chris@76: );
Chris@76:
Chris@76: if (in_array($profile['show_email'], array('yes', 'yes_permission_override')))
Chris@76: $data['email'] = $profile['email'];
Chris@76:
Chris@76: if (!empty($profile['birth_date']) && substr($profile['birth_date'], 0, 4) != '0000')
Chris@76: {
Chris@76: list ($birth_year, $birth_month, $birth_day) = sscanf($profile['birth_date'], '%d-%d-%d');
Chris@76: $datearray = getdate(forum_time());
Chris@76: $data['age'] = $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1);
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Save some memory.
Chris@76: unset($profile, $memberContext[$_GET['u']]);
Chris@76:
Chris@76: return $data;
Chris@76: }
Chris@76:
Chris@76: ?>