2009-06-12 14:41:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package phpBB3
|
|
|
|
* @version $Id$
|
|
|
|
* @copyright (c) 2009 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*
|
|
|
|
* Idea and original RSS Feed 2.0 MOD (Version 1.0.8/9) by leviatan21
|
|
|
|
* Original MOD: http://www.phpbb.com/community/viewtopic.php?f=69&t=1214645
|
|
|
|
* MOD Author Profile: http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=345763
|
|
|
|
* MOD Author Homepage: http://www.mssti.com/phpbb3/
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
**/
|
|
|
|
define('IN_PHPBB', true);
|
|
|
|
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
|
|
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
|
|
include($phpbb_root_path . 'common.' . $phpEx);
|
|
|
|
|
|
|
|
if (!$config['feed_enable'])
|
|
|
|
{
|
|
|
|
trigger_error('NO_FEED_ENABLED');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start session
|
|
|
|
$user->session_begin();
|
|
|
|
$auth->acl($user->data);
|
|
|
|
$user->setup();
|
|
|
|
|
|
|
|
// Initial var setup
|
|
|
|
$forum_id = request_var('f', 0);
|
|
|
|
$topic_id = request_var('t', 0);
|
|
|
|
$mode = request_var('mode', '');
|
|
|
|
|
|
|
|
// We do not use a template, therefore we simply define the global template variables here
|
|
|
|
$global_vars = $item_vars = array();
|
2009-11-20 21:14:34 +00:00
|
|
|
$feed_updated_time = 0;
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
// Generate params array for use in append_sid() to correctly link back to this page
|
2009-12-10 01:12:54 +00:00
|
|
|
$params = false;
|
2009-06-12 14:41:03 +00:00
|
|
|
if ($forum_id || $topic_id || $mode)
|
|
|
|
{
|
|
|
|
$params = array(
|
|
|
|
'f' => ($forum_id) ? $forum_id : NULL,
|
|
|
|
't' => ($topic_id) ? $topic_id : NULL,
|
|
|
|
'mode' => ($mode) ? $mode : NULL,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This boards URL
|
|
|
|
$board_url = generate_board_url();
|
|
|
|
|
|
|
|
// Get correct feed object
|
|
|
|
$feed = phpbb_feed_factory::init($mode, $forum_id, $topic_id);
|
|
|
|
|
|
|
|
// No feed found
|
|
|
|
if ($feed === false)
|
|
|
|
{
|
|
|
|
trigger_error('NO_FEED');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open Feed
|
2009-12-09 21:33:25 +00:00
|
|
|
$feed->open();
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
// Iterate through items
|
|
|
|
while ($row = $feed->get_item())
|
|
|
|
{
|
|
|
|
// BBCode options to correctly disable urls, smilies, bbcode...
|
|
|
|
if ($feed->get('options') === NULL)
|
|
|
|
{
|
|
|
|
// Allow all combinations
|
|
|
|
$options = 7;
|
|
|
|
|
|
|
|
if ($feed->get('enable_bbcode') !== NULL && $feed->get('enable_smilies') !== NULL && $feed->get('enable_magic_url') !== NULL)
|
|
|
|
{
|
|
|
|
$options = (($row[$feed->get('enable_bbcode')]) ? OPTION_FLAG_BBCODE : 0) + (($row[$feed->get('enable_smilies')]) ? OPTION_FLAG_SMILIES : 0) + (($row[$feed->get('enable_magic_url')]) ? OPTION_FLAG_LINKS : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$options = $row[$feed->get('options')];
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = ($row[$feed->get('title')]) ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : '');
|
|
|
|
$title = censor_text($title);
|
|
|
|
|
2009-11-20 21:14:34 +00:00
|
|
|
$item_time = (int) $row[$feed->get('date')];
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
$item_row = array(
|
|
|
|
'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '',
|
2009-12-10 01:12:54 +00:00
|
|
|
'pubdate' => feed_format_date($item_time),
|
2009-06-12 14:41:03 +00:00
|
|
|
'link' => '',
|
|
|
|
'title' => censor_text($title),
|
|
|
|
'category' => ($config['feed_item_statistics']) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '',
|
2009-12-10 03:05:33 +00:00
|
|
|
'category_name' => ($config['feed_item_statistics']) ? $row['forum_name'] : '',
|
2009-06-12 14:41:03 +00:00
|
|
|
'description' => censor_text(feed_generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)),
|
|
|
|
'statistics' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Adjust items, fill link, etc.
|
|
|
|
$feed->adjust_item($item_row, $row);
|
|
|
|
|
|
|
|
$item_vars[] = $item_row;
|
2009-11-20 21:14:34 +00:00
|
|
|
|
|
|
|
$feed_updated_time = max($feed_updated_time, $item_time);
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 21:14:34 +00:00
|
|
|
// If we do not have any items at all, sending the current time is better than sending no time.
|
|
|
|
if (!$feed_updated_time)
|
|
|
|
{
|
|
|
|
$feed_updated_time = time();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some default assignments
|
|
|
|
// FEED_IMAGE is not used (atom)
|
2009-11-24 18:47:42 +00:00
|
|
|
$global_vars = array_merge($global_vars, array(
|
2009-11-20 21:14:34 +00:00
|
|
|
'FEED_IMAGE' => ($user->img('site_logo', '', false, '', 'src')) ? $board_url . '/' . substr($user->img('site_logo', '', false, '', 'src'), strlen($phpbb_root_path)) : '',
|
|
|
|
'SELF_LINK' => feed_append_sid('/feed.' . $phpEx, $params),
|
|
|
|
'FEED_LINK' => $board_url . '/index.' . $phpEx,
|
|
|
|
'FEED_TITLE' => $config['sitename'],
|
|
|
|
'FEED_SUBTITLE' => $config['site_desc'],
|
2009-12-10 01:12:54 +00:00
|
|
|
'FEED_UPDATED' => feed_format_date($feed_updated_time),
|
2009-11-20 21:14:34 +00:00
|
|
|
'FEED_LANG' => $user->lang['USER_LANG'],
|
|
|
|
'FEED_AUTHOR' => $config['sitename'],
|
2009-11-24 18:47:42 +00:00
|
|
|
));
|
2009-11-20 21:14:34 +00:00
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
$feed->close();
|
|
|
|
|
|
|
|
// Output page
|
|
|
|
|
|
|
|
// gzip_compression
|
|
|
|
if ($config['gzip_compress'])
|
|
|
|
{
|
|
|
|
if (@extension_loaded('zlib') && !headers_sent())
|
|
|
|
{
|
|
|
|
ob_start('ob_gzhandler');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IF debug extra is enabled and admin want to "explain" the page we need to set other headers...
|
2009-11-25 13:12:32 +00:00
|
|
|
if (defined('DEBUG_EXTRA') && request_var('explain', 0) && $auth->acl_get('a_'))
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
|
|
|
header('Content-type: text/html; charset=UTF-8');
|
|
|
|
header('Cache-Control: private, no-cache="set-cookie"');
|
|
|
|
header('Expires: 0');
|
|
|
|
header('Pragma: no-cache');
|
|
|
|
|
|
|
|
$mtime = explode(' ', microtime());
|
|
|
|
$totaltime = $mtime[0] + $mtime[1] - $starttime;
|
|
|
|
|
|
|
|
if (method_exists($db, 'sql_report'))
|
|
|
|
{
|
|
|
|
$db->sql_report('display');
|
|
|
|
}
|
|
|
|
|
|
|
|
garbage_collection();
|
|
|
|
exit_handler();
|
|
|
|
}
|
|
|
|
|
2009-11-25 13:12:32 +00:00
|
|
|
header("Content-Type: application/atom+xml; charset=UTF-8");
|
|
|
|
header("Last-Modified: " . gmdate('D, d M Y H:i:s', $feed_updated_time) . ' GMT');
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="' . $global_vars['FEED_LANG'] . '">' . "\n";
|
|
|
|
echo '<link rel="self" type="application/atom+xml" href="' . $global_vars['SELF_LINK'] . '" />' . "\n\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-07-07 11:05:50 +00:00
|
|
|
echo (!empty($global_vars['FEED_TITLE'])) ? '<title>' . $global_vars['FEED_TITLE'] . '</title>' . "\n" : '';
|
|
|
|
echo (!empty($global_vars['FEED_SUBTITLE'])) ? '<subtitle>' . $global_vars['FEED_SUBTITLE'] . '</subtitle>' . "\n" : '';
|
|
|
|
echo (!empty($global_vars['FEED_LINK'])) ? '<link href="' . $global_vars['FEED_LINK'] .'" />' . "\n" : '';
|
|
|
|
echo '<updated>' . $global_vars['FEED_UPDATED'] . '</updated>' . "\n\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '<author><name><![CDATA[' . $global_vars['FEED_AUTHOR'] . ']]></name></author>' . "\n";
|
|
|
|
echo '<id>' . $global_vars['SELF_LINK'] . '</id>' . "\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
foreach ($item_vars as $row)
|
|
|
|
{
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '<entry>' . "\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
if (!empty($row['author']))
|
|
|
|
{
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '<author><name><![CDATA[' . $row['author'] . ']]></name></author>' . "\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '<updated>' . $row['pubdate'] . '</updated>' . "\n";
|
|
|
|
echo '<id>' . $row['link'] . '</id>' . "\n";
|
|
|
|
echo '<link href="' . $row['link'] . '"/>' . "\n";
|
|
|
|
echo '<title type="html"><![CDATA[' . $row['title'] . ']]></title>' . "\n\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
if (!empty($row['category']))
|
|
|
|
{
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '<category term="' . $row['category_name'] . '" scheme="' . $row['category'] . '" label="' . $row['category_name'] . '"/>' . "\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '<content type="html" xml:base="' . $row['link'] . '"><![CDATA[' . "\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
echo $row['description'];
|
|
|
|
|
|
|
|
if (!empty($row['statistics']))
|
|
|
|
{
|
|
|
|
echo '<p>' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '</p>';
|
|
|
|
}
|
|
|
|
|
2009-10-12 14:16:09 +00:00
|
|
|
echo '<hr />' . "\n" . ']]></content>' . "\n";
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '</entry>' . "\n";
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 11:05:50 +00:00
|
|
|
echo '</feed>';
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
garbage_collection();
|
|
|
|
exit_handler();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run links through append_sid(), prepend generate_board_url() and remove session id
|
|
|
|
**/
|
|
|
|
function feed_append_sid($url, $params)
|
|
|
|
{
|
|
|
|
global $board_url;
|
|
|
|
|
2009-10-29 14:00:43 +00:00
|
|
|
return append_sid($board_url . $url, $params, true, '');
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
2009-12-10 01:12:54 +00:00
|
|
|
/**
|
|
|
|
* Generate ISO 8601 date string (RFC 3339)
|
|
|
|
**/
|
|
|
|
function feed_format_date($time)
|
|
|
|
{
|
|
|
|
static $zone_offset;
|
|
|
|
static $offset_string;
|
|
|
|
|
|
|
|
if (empty($offset_string))
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
|
|
|
$zone_offset = (int) $user->timezone + (int) $user->dst;
|
|
|
|
|
|
|
|
$sign = ($zone_offset < 0) ? '-' : '+';
|
|
|
|
$time_offset = abs($zone_offset);
|
|
|
|
|
|
|
|
$offset_seconds = $time_offset % 3600;
|
|
|
|
$offset_minutes = $offset_seconds / 60;
|
|
|
|
$offset_hours = ($time_offset - $offset_seconds) / 3600;
|
|
|
|
|
|
|
|
$offset_string = sprintf("%s%02d:%02d", $sign, $offset_hours, $offset_minutes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string;
|
|
|
|
}
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
/**
|
|
|
|
* Generate text content
|
|
|
|
**/
|
|
|
|
function feed_generate_content($content, $uid, $bitfield, $options)
|
|
|
|
{
|
|
|
|
global $user, $config, $phpbb_root_path, $phpEx, $board_url;
|
|
|
|
|
|
|
|
if (empty($content))
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare some bbcodes for better parsing
|
|
|
|
$content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content);
|
|
|
|
|
|
|
|
$content = generate_text_for_display($content, $uid, $bitfield, $options);
|
|
|
|
|
2009-06-23 17:15:53 +00:00
|
|
|
// Add newlines
|
|
|
|
$content = str_replace('<br />', '<br />' . "\n", $content);
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
// Relative Path to Absolute path, Windows style
|
|
|
|
$content = str_replace('./', $board_url . '/', $content);
|
|
|
|
|
|
|
|
// Remove "Select all" link and mouse events
|
2009-10-03 13:23:10 +00:00
|
|
|
$content = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $user->lang['SELECT_ALL_CODE'] . '</a>', '', $content);
|
2009-06-12 14:41:03 +00:00
|
|
|
$content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);
|
|
|
|
|
2009-07-07 11:05:50 +00:00
|
|
|
// Firefox does not support CSS for feeds, though
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
// Remove font sizes
|
2009-07-07 11:05:50 +00:00
|
|
|
// $content = preg_replace('#<span style="font-size: [0-9]+%; line-height: [0-9]+%;">([^>]+)</span>#iU', '\1', $content);
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
// Make text strong :P
|
2009-07-07 11:05:50 +00:00
|
|
|
// $content = preg_replace('#<span style="font-weight: bold?">(.*?)</span>#iU', '<strong>\1</strong>', $content);
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
// Italic
|
2009-07-07 11:05:50 +00:00
|
|
|
// $content = preg_replace('#<span style="font-style: italic?">([^<]+)</span>#iU', '<em>\1</em>', $content);
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
// Underline
|
2009-07-07 11:05:50 +00:00
|
|
|
// $content = preg_replace('#<span style="text-decoration: underline?">([^<]+)</span>#iU', '<u>\1</u>', $content);
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
// Remove embed Windows Media Streams
|
|
|
|
$content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--<!\[endif\]-->#si', '', $content);
|
|
|
|
|
|
|
|
// Do not use < and >, because we want to retain code contained in [code][/code]
|
|
|
|
|
|
|
|
// Remove embed and objects
|
|
|
|
$content = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' <a href=$4 target="_blank"><strong>$1</strong></a> ',$content);
|
|
|
|
|
|
|
|
// Remove some specials html tag, because somewhere there are a mod to allow html tags ;)
|
|
|
|
$content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
|
|
|
|
|
|
|
|
// Remove Comments from inline attachments [ia]
|
|
|
|
$content = preg_replace('#<div class="(inline-attachment|attachtitle)">(.*?)<!-- ia(.*?) -->(.*?)<!-- ia(.*?) -->(.*?)</div>#si','$4',$content);
|
|
|
|
|
|
|
|
// Replace some entities with their unicode counterpart
|
|
|
|
$entities = array(
|
2009-07-27 12:18:09 +00:00
|
|
|
' ' => "\xC2\xA0",
|
|
|
|
'•' => "\xE2\x80\xA2",
|
|
|
|
'·' => "\xC2\xB7",
|
|
|
|
'©' => "\xC2\xA9",
|
2009-06-12 14:41:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$content = str_replace(array_keys($entities), array_values($entities), $content);
|
|
|
|
|
2009-07-07 11:05:50 +00:00
|
|
|
// Remove CDATA blocks. ;)
|
|
|
|
$content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content);
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
// Other control characters
|
|
|
|
// $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory class to return correct object
|
|
|
|
* @package phpBB3
|
|
|
|
*/
|
|
|
|
class phpbb_feed_factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Return correct object for specified mode
|
|
|
|
*
|
|
|
|
* @param string $mode The feeds mode.
|
|
|
|
* @param int $forum_id Forum id specified by the script if forum feed provided.
|
|
|
|
* @param int $topic_id Topic id specified by the script if topic feed provided.
|
|
|
|
*
|
|
|
|
* @return object Returns correct feeds object for specified mode.
|
|
|
|
*/
|
|
|
|
function init($mode, $forum_id, $topic_id)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
switch ($mode)
|
|
|
|
{
|
|
|
|
case 'forums':
|
|
|
|
if (!$config['feed_overall_forums'])
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new phpbb_feed_forums();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'topics':
|
|
|
|
if (!$config['feed_overall_topics'])
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new phpbb_feed_topics();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'news':
|
2009-08-12 15:00:47 +00:00
|
|
|
global $db;
|
|
|
|
|
|
|
|
// Get at least one news forum
|
|
|
|
$sql = 'SELECT forum_id
|
|
|
|
FROM ' . FORUMS_TABLE . '
|
|
|
|
WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
|
|
|
|
$result = $db->sql_query_limit($sql, 1, 0, 600);
|
|
|
|
$s_feed_news = (int) $db->sql_fetchfield('forum_id');
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
if (!$s_feed_news)
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new phpbb_feed_news();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Forum and/or topic specified?
|
|
|
|
if ($topic_id && !$config['feed_topic'])
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($forum_id && !$topic_id && !$config['feed_forum'])
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new phpbb_feed($forum_id, $topic_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-11 13:42:38 +00:00
|
|
|
* Base class with some generic functions and settings.
|
|
|
|
*
|
2009-06-12 14:41:03 +00:00
|
|
|
* @package phpBB3
|
|
|
|
*/
|
2009-12-11 13:42:38 +00:00
|
|
|
class phpbb_feed_base
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* SQL Query to be executed to get feed items
|
|
|
|
*/
|
2009-12-11 13:42:38 +00:00
|
|
|
var $sql = array();
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Keys specified for retrieval of title, content, etc.
|
|
|
|
*/
|
|
|
|
var $keys = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of excluded forum ids.
|
|
|
|
*/
|
|
|
|
var $excluded_forums_ary = NULL;
|
|
|
|
|
|
|
|
/**
|
2009-12-11 13:42:38 +00:00
|
|
|
* Number of items to fetch. Usually overwritten by $config['feed_something']
|
2009-06-12 14:41:03 +00:00
|
|
|
*/
|
2009-12-11 13:42:38 +00:00
|
|
|
var $num_items = 15;
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* boolean to determine if items array is filled or not
|
|
|
|
*/
|
|
|
|
var $items_filled = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* array holding items
|
|
|
|
*/
|
|
|
|
var $items = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default setting for last x days
|
|
|
|
*/
|
2009-07-27 09:56:31 +00:00
|
|
|
var $sort_days = 30;
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default cache time of entries in seconds
|
|
|
|
*/
|
2009-12-11 14:46:06 +00:00
|
|
|
var $cache_time = 90;
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-06-23 17:15:53 +00:00
|
|
|
/**
|
|
|
|
* Separator for title elements to separate items (for example forum / topic)
|
|
|
|
*/
|
2009-07-27 12:18:09 +00:00
|
|
|
var $separator = "\xE2\x80\xA2"; // •
|
2009-06-23 17:15:53 +00:00
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
/**
|
2009-11-24 16:00:18 +00:00
|
|
|
* Separator for the statistics row (Posted by, post date, replies, etc.)
|
|
|
|
*/
|
|
|
|
var $separator_stats = "\xE2\x80\x94"; // —
|
|
|
|
|
2009-11-24 17:58:22 +00:00
|
|
|
/**
|
2009-12-11 13:42:38 +00:00
|
|
|
* Constructor
|
2009-06-12 14:41:03 +00:00
|
|
|
*/
|
2009-12-11 13:42:38 +00:00
|
|
|
function phpbb_feed_base()
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
2009-12-11 14:46:06 +00:00
|
|
|
global $user;
|
|
|
|
|
|
|
|
// Disable cache if it is not a guest or a bot but a registered user
|
|
|
|
if ($this->cache_time && !empty($user) && $user->data['is_registered'])
|
|
|
|
{
|
|
|
|
$this->cache_time = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
$this->set_keys();
|
|
|
|
}
|
|
|
|
|
2009-12-11 13:42:38 +00:00
|
|
|
/**
|
|
|
|
* Set keys.
|
|
|
|
*/
|
2009-06-12 14:41:03 +00:00
|
|
|
function set_keys()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-11 13:42:38 +00:00
|
|
|
/**
|
|
|
|
* Open feed
|
|
|
|
*/
|
2009-06-12 14:41:03 +00:00
|
|
|
function open()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-11 13:42:38 +00:00
|
|
|
/**
|
|
|
|
* Close feed
|
|
|
|
*/
|
2009-06-12 14:41:03 +00:00
|
|
|
function close()
|
|
|
|
{
|
2009-12-11 13:42:38 +00:00
|
|
|
global $db;
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
if (!empty($this->result))
|
|
|
|
{
|
|
|
|
$db->sql_freeresult($this->result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set key
|
|
|
|
*/
|
|
|
|
function set($key, $value)
|
|
|
|
{
|
|
|
|
$this->keys[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get key
|
|
|
|
*/
|
|
|
|
function get($key)
|
|
|
|
{
|
|
|
|
return (isset($this->keys[$key])) ? $this->keys[$key] : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return array of excluded forums
|
|
|
|
*/
|
|
|
|
function excluded_forums()
|
|
|
|
{
|
|
|
|
if ($this->excluded_forums_ary !== NULL)
|
|
|
|
{
|
|
|
|
return $this->excluded_forums_ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
global $auth, $db, $config, $phpbb_root_path, $phpEx, $user;
|
|
|
|
|
|
|
|
// Which forums should not be searched ?
|
2009-12-10 16:59:25 +00:00
|
|
|
$this->excluded_forums_ary = array();
|
|
|
|
|
|
|
|
// Exclude excluded forums and forums we cannot read
|
|
|
|
$forum_ids_read = array_keys($auth->acl_getf('f_read', true));
|
|
|
|
$sql_or = (!empty($forum_ids_read)) ? 'OR ' . $db->sql_in_set('forum_id', $forum_ids_read, true) : '';
|
2009-08-12 15:00:47 +00:00
|
|
|
|
|
|
|
$sql = 'SELECT forum_id
|
|
|
|
FROM ' . FORUMS_TABLE . '
|
2009-12-10 16:59:25 +00:00
|
|
|
WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0') . "
|
|
|
|
$sql_or";
|
2009-08-12 15:00:47 +00:00
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-12-10 16:59:25 +00:00
|
|
|
$this->excluded_forums_ary[(int) $row['forum_id']] = (int) $row['forum_id'];
|
2009-08-12 15:00:47 +00:00
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-12-11 16:41:37 +00:00
|
|
|
// Include passworded forums
|
|
|
|
$this->excluded_forums_ary = array_unique(array_merge($this->excluded_forums_ary, $this->get_passworded_forums()));
|
|
|
|
|
|
|
|
return $this->excluded_forums_ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_passworded_forums()
|
|
|
|
{
|
|
|
|
global $db, $user;
|
|
|
|
|
2009-12-10 16:59:25 +00:00
|
|
|
// Exclude passworded forums
|
|
|
|
$sql = 'SELECT f.forum_id, fa.user_id
|
2009-06-12 14:41:03 +00:00
|
|
|
FROM ' . FORUMS_TABLE . ' f
|
2009-12-10 16:59:25 +00:00
|
|
|
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa
|
|
|
|
ON (fa.forum_id = f.forum_id
|
|
|
|
AND fa.session_id = '" . $db->sql_escape($user->session_id) . "')
|
|
|
|
WHERE f.forum_password <> ''";
|
2009-06-12 14:41:03 +00:00
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
2009-12-11 16:41:37 +00:00
|
|
|
$forum_ids = array();
|
2009-06-12 14:41:03 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-12-11 16:41:37 +00:00
|
|
|
$forum_id = (int) $row['forum_id'];
|
|
|
|
|
2009-12-10 16:59:25 +00:00
|
|
|
if ($row['user_id'] != $user->data['user_id'])
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
2009-12-11 16:41:37 +00:00
|
|
|
$forum_ids[$forum_id] = $forum_id;
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
2009-12-11 16:41:37 +00:00
|
|
|
return $forum_ids;
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 13:42:38 +00:00
|
|
|
function get_item()
|
|
|
|
{
|
|
|
|
global $db, $cache;
|
|
|
|
|
|
|
|
if (!$this->cache_time)
|
|
|
|
{
|
|
|
|
if (empty($this->result))
|
|
|
|
{
|
|
|
|
if (!$this->get_sql())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query database
|
|
|
|
$sql = $db->sql_build_query('SELECT', $this->sql);
|
|
|
|
$this->result = $db->sql_query_limit($sql, $this->num_items);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $db->sql_fetchrow($this->result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (empty($this->items_filled))
|
|
|
|
{
|
|
|
|
// Try to load result set...
|
|
|
|
$cache_filename = substr(get_class($this), strlen('phpbb_'));
|
|
|
|
|
|
|
|
if (($this->items = $cache->get('_' . $cache_filename)) === false)
|
|
|
|
{
|
|
|
|
$this->items = array();
|
|
|
|
|
|
|
|
if ($this->get_sql())
|
|
|
|
{
|
|
|
|
// Query database
|
|
|
|
$sql = $db->sql_build_query('SELECT', $this->sql);
|
|
|
|
$result = $db->sql_query_limit($sql, $this->num_items);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$this->items[] = $row;
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache->put('_' . $cache_filename, $this->items, $this->cache_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->items_filled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$row = array_shift($this->items);
|
|
|
|
return (!$row) ? false : $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default feed class if no mode is specified.
|
|
|
|
* This can be the overall site feed or a forum/topic feed.
|
|
|
|
*
|
|
|
|
* @package phpBB3
|
|
|
|
*/
|
|
|
|
class phpbb_feed extends phpbb_feed_base
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Forum id specified for forum feed.
|
|
|
|
*/
|
|
|
|
var $forum_id = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Topic id specified for topic feed.
|
|
|
|
*/
|
|
|
|
var $topic_id = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
function phpbb_feed($forum_id = 0, $topic_id = 0)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
// Call parent constructor.
|
|
|
|
parent::phpbb_feed_base();
|
|
|
|
|
|
|
|
$this->forum_id = $forum_id;
|
|
|
|
$this->topic_id = $topic_id;
|
|
|
|
|
|
|
|
$this->sql = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_keys()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$this->set('title', 'post_subject');
|
|
|
|
$this->set('title2', 'topic_title');
|
|
|
|
$this->set('author_id', 'user_id');
|
|
|
|
$this->set('creator', 'username');
|
|
|
|
$this->set('text', 'post_text');
|
|
|
|
$this->set('bitfield', 'bbcode_bitfield');
|
|
|
|
$this->set('bbcode_uid','bbcode_uid');
|
|
|
|
$this->set('date', 'post_time');
|
|
|
|
|
|
|
|
$this->set('enable_bbcode', 'enable_bbcode');
|
|
|
|
$this->set('enable_smilies', 'enable_smilies');
|
|
|
|
$this->set('enable_magic_url', 'enable_magic_url');
|
|
|
|
|
|
|
|
$this->num_items = (int) $config['feed_limit'];
|
|
|
|
}
|
|
|
|
|
|
|
|
function open()
|
|
|
|
{
|
|
|
|
global $auth, $db, $user;
|
|
|
|
|
|
|
|
if ($this->topic_id)
|
|
|
|
{
|
|
|
|
// Topic feed
|
|
|
|
$sql = 'SELECT forum_id
|
|
|
|
FROM ' . TOPICS_TABLE . '
|
|
|
|
WHERE topic_id = ' . $this->topic_id;
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
$row = $db->sql_fetchrow($result);
|
|
|
|
$this->forum_id = (int) $row['forum_id'];
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
if (empty($row))
|
|
|
|
{
|
|
|
|
trigger_error('NO_TOPIC');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($this->forum_id)
|
|
|
|
{
|
|
|
|
// Forum feed
|
|
|
|
$sql = 'SELECT forum_id
|
|
|
|
FROM ' . FORUMS_TABLE . '
|
|
|
|
WHERE forum_id = ' . $this->forum_id;
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
$row = $db->sql_fetchrow($result);
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
if (empty($row))
|
|
|
|
{
|
|
|
|
trigger_error('NO_FORUM');
|
|
|
|
}
|
2009-12-11 14:46:06 +00:00
|
|
|
}
|
2009-12-11 13:42:38 +00:00
|
|
|
|
2009-12-11 14:46:06 +00:00
|
|
|
// Topic/Forum feed
|
|
|
|
if ($this->topic_id || $this->forum_id)
|
|
|
|
{
|
2009-12-11 13:42:38 +00:00
|
|
|
if (!$auth->acl_get('f_read', $this->forum_id))
|
|
|
|
{
|
|
|
|
trigger_error('SORRY_AUTH_READ');
|
|
|
|
}
|
2009-12-11 14:46:06 +00:00
|
|
|
|
|
|
|
// Disable caching
|
|
|
|
$this->cache_time = 0;
|
2009-12-11 13:42:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
/**
|
|
|
|
* Get SQL query for fetching items
|
|
|
|
*/
|
|
|
|
function get_sql()
|
|
|
|
{
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
$post_ids = array();
|
|
|
|
|
2009-07-27 09:56:31 +00:00
|
|
|
// Search for topics in last X days
|
2009-06-12 14:41:03 +00:00
|
|
|
$last_post_time_sql = ($this->sort_days) ? ' AND t.topic_last_post_time > ' . (time() - ($this->sort_days * 24 * 3600)) : '';
|
|
|
|
|
|
|
|
// Fetch latest post, grouped by topic...
|
|
|
|
if (!$this->forum_id && !$this->topic_id)
|
|
|
|
{
|
|
|
|
// First of all, the post ids...
|
|
|
|
$not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('t.forum_id', $this->excluded_forums(), true) : '';
|
|
|
|
|
|
|
|
$sql = 'SELECT t.topic_last_post_id
|
|
|
|
FROM ' . TOPICS_TABLE . ' t
|
|
|
|
WHERE t.topic_approved = 1
|
|
|
|
AND t.topic_moved_id = 0' .
|
|
|
|
$not_in_fid .
|
|
|
|
$last_post_time_sql . '
|
|
|
|
ORDER BY t.topic_last_post_time DESC';
|
|
|
|
$result = $db->sql_query_limit($sql, $this->num_items);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-07-27 10:24:42 +00:00
|
|
|
$post_ids[] = (int) $row['topic_last_post_id'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
// Fetch latest posts from forum
|
|
|
|
else if (!$this->topic_id && $this->forum_id)
|
|
|
|
{
|
|
|
|
// Make sure the forum is not listed within the forbidden ones. ;)
|
|
|
|
if (in_array($this->forum_id, $this->excluded_forums()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine which forums to fetch
|
2009-11-24 18:26:15 +00:00
|
|
|
$not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('f2.forum_id', $this->excluded_forums(), true) : '';
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
// Determine forum childs...
|
|
|
|
$sql = 'SELECT f2.forum_id
|
|
|
|
FROM ' . FORUMS_TABLE . ' f1, ' . FORUMS_TABLE . ' f2
|
|
|
|
WHERE f1.forum_id = ' . $this->forum_id . '
|
|
|
|
AND (f2.left_id BETWEEN f1.left_id AND f1.right_id' . $not_in_fid . ')';
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
$forum_ids = array();
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-07-27 10:24:42 +00:00
|
|
|
$forum_ids[] = (int) $row['forum_id'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
// Now select from forums...
|
|
|
|
$sql = 'SELECT t.topic_last_post_id
|
|
|
|
FROM ' . TOPICS_TABLE . ' t
|
|
|
|
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
|
|
|
|
AND t.topic_approved = 1
|
|
|
|
AND t.topic_moved_id = 0' .
|
|
|
|
$last_post_time_sql . '
|
|
|
|
ORDER BY t.topic_last_post_time DESC';
|
|
|
|
$result = $db->sql_query_limit($sql, $this->num_items);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-07-27 10:24:42 +00:00
|
|
|
$post_ids[] = (int) $row['topic_last_post_id'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
// Fetch last posts from specified topic...
|
|
|
|
else if ($this->topic_id)
|
|
|
|
{
|
|
|
|
// non-global announcement
|
|
|
|
if ($this->forum_id && in_array($this->forum_id, $this->excluded_forums()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = 'SELECT post_id
|
|
|
|
FROM ' . POSTS_TABLE . '
|
|
|
|
WHERE topic_id = ' . $this->topic_id . '
|
|
|
|
AND post_approved = 1
|
|
|
|
ORDER BY post_time DESC';
|
|
|
|
$result = $db->sql_query_limit($sql, $this->num_items);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-07-27 10:24:42 +00:00
|
|
|
$post_ids[] = (int) $row['post_id'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sizeof($post_ids))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now build sql query for obtaining items
|
|
|
|
$this->sql = array(
|
|
|
|
'SELECT' => 'f.forum_id, f.forum_name, f.forum_desc_options, ' .
|
|
|
|
't.topic_last_post_time, t.topic_id, t.topic_title, t.topic_time, t.topic_replies, t.topic_views, ' .
|
|
|
|
'p.post_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
|
2009-12-08 03:53:41 +00:00
|
|
|
'u.username, u.user_id',
|
2009-06-12 14:41:03 +00:00
|
|
|
'FROM' => array(
|
|
|
|
POSTS_TABLE => 'p',
|
|
|
|
TOPICS_TABLE => 't',
|
|
|
|
FORUMS_TABLE => 'f',
|
|
|
|
USERS_TABLE => 'u',
|
|
|
|
),
|
|
|
|
'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . '
|
|
|
|
AND f.forum_id = p.forum_id
|
|
|
|
AND t.topic_id = p.topic_id
|
|
|
|
AND u.user_id = p.poster_id',
|
|
|
|
'ORDER_BY' => 'p.post_time DESC',
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjust_item(&$item_row, &$row)
|
|
|
|
{
|
|
|
|
global $phpEx, $config;
|
|
|
|
|
2009-06-23 17:15:53 +00:00
|
|
|
$item_row['title'] = (!$this->topic_id) ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
|
2009-06-12 14:41:03 +00:00
|
|
|
$item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}");
|
|
|
|
|
|
|
|
if ($config['feed_item_statistics'])
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
2009-11-24 18:28:46 +00:00
|
|
|
$user_link = ($row['user_id'] != ANONYMOUS) ? '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $row['user_id']) . '">' . $row['username'] . '</a>' : $row['username'];
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-11-24 16:00:18 +00:00
|
|
|
$item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link
|
2009-12-08 01:53:26 +00:00
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->format_date($row['post_time'])
|
2009-11-24 16:00:18 +00:00
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies']
|
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 13:42:38 +00:00
|
|
|
class phpbb_feed_forums extends phpbb_feed_base
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
|
|
|
function set_keys()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$this->set('title', 'forum_name');
|
|
|
|
$this->set('text', 'forum_desc');
|
|
|
|
$this->set('bitfield', 'forum_desc_bitfield');
|
|
|
|
$this->set('bbcode_uid','forum_desc_uid');
|
|
|
|
$this->set('date', 'forum_last_post_time');
|
|
|
|
$this->set('options', 'forum_desc_options');
|
|
|
|
|
2009-10-03 13:23:10 +00:00
|
|
|
$this->num_items = (int) $config['feed_overall_forums_limit'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_sql()
|
|
|
|
{
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
$not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('f.forum_id', $this->excluded_forums(), true) : '';
|
|
|
|
|
|
|
|
// Build SQL Query
|
|
|
|
$this->sql = array(
|
|
|
|
'SELECT' => 'f.*',
|
|
|
|
'FROM' => array(FORUMS_TABLE => 'f'),
|
|
|
|
'WHERE' => 'f.forum_type = ' . FORUM_POST . '
|
|
|
|
AND (f.forum_last_post_id > 0' . $not_in_fid . ')',
|
|
|
|
'ORDER_BY' => 'f.left_id',
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjust_item(&$item_row, &$row)
|
|
|
|
{
|
|
|
|
global $phpEx, $config;
|
|
|
|
|
|
|
|
$item_row['link'] = feed_append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']);
|
|
|
|
|
|
|
|
if ($config['feed_item_statistics'])
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
2009-11-24 16:00:18 +00:00
|
|
|
$item_row['statistics'] = sprintf($user->lang['TOTAL_TOPICS_OTHER'], $row['forum_topics'])
|
|
|
|
. ' ' . $this->separator_stats . ' ' . sprintf($user->lang['TOTAL_POSTS_OTHER'], $row['forum_posts']);
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 13:42:38 +00:00
|
|
|
class phpbb_feed_news extends phpbb_feed_base
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
2009-12-11 14:46:06 +00:00
|
|
|
/**
|
|
|
|
* Longer cache time for the news feed
|
|
|
|
*/
|
|
|
|
var $cache_time = 180;
|
|
|
|
|
2009-06-12 14:41:03 +00:00
|
|
|
function set_keys()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$this->set('title', 'topic_title');
|
|
|
|
$this->set('title2', 'forum_name');
|
|
|
|
$this->set('author_id', 'topic_poster');
|
|
|
|
$this->set('creator', 'topic_first_poster_name');
|
|
|
|
$this->set('text', 'post_text');
|
|
|
|
$this->set('bitfield', 'bbcode_bitfield');
|
|
|
|
$this->set('bbcode_uid','bbcode_uid');
|
|
|
|
$this->set('date', 'topic_time');
|
|
|
|
|
|
|
|
$this->set('enable_bbcode', 'enable_bbcode');
|
|
|
|
$this->set('enable_smilies', 'enable_smilies');
|
|
|
|
$this->set('enable_magic_url', 'enable_magic_url');
|
|
|
|
|
2009-07-27 10:24:42 +00:00
|
|
|
$this->num_items = (int) $config['feed_overall_forums_limit'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_sql()
|
|
|
|
{
|
2009-12-11 16:18:56 +00:00
|
|
|
global $auth, $config, $db;
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-12-11 16:41:37 +00:00
|
|
|
// Get passworded forums
|
|
|
|
$forum_ids_passworded = $this->get_passworded_forums();
|
|
|
|
|
2009-08-12 15:00:47 +00:00
|
|
|
// Get news forums...
|
|
|
|
$sql = 'SELECT forum_id
|
|
|
|
FROM ' . FORUMS_TABLE . '
|
|
|
|
WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
$in_fid_ary = array();
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-12-11 16:41:37 +00:00
|
|
|
$forum_id = (int) $row['forum_id'];
|
|
|
|
|
|
|
|
// Passworded forum
|
|
|
|
if (isset($forum_ids_passworded[$forum_id]))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-12-11 16:18:56 +00:00
|
|
|
// Make sure we can read this forum
|
2009-12-11 16:41:37 +00:00
|
|
|
if (!$auth->acl_get('f_read', $forum_id))
|
2009-12-11 16:18:56 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-12 15:00:47 +00:00
|
|
|
$in_fid_ary[] = (int) $row['forum_id'];
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
2009-06-12 14:41:03 +00:00
|
|
|
|
|
|
|
if (!sizeof($in_fid_ary))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build SQL Query
|
|
|
|
$this->sql = array(
|
2009-12-08 03:53:41 +00:00
|
|
|
'SELECT' => 'f.forum_id, f.forum_name, f.forum_topics, f.forum_posts,
|
2009-06-12 14:41:03 +00:00
|
|
|
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time,
|
2009-12-08 03:53:41 +00:00
|
|
|
p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
|
2009-06-12 14:41:03 +00:00
|
|
|
'FROM' => array(
|
|
|
|
TOPICS_TABLE => 't',
|
|
|
|
FORUMS_TABLE => 'f',
|
|
|
|
POSTS_TABLE => 'p',
|
|
|
|
),
|
|
|
|
'WHERE' => $db->sql_in_set('t.forum_id', $in_fid_ary) . '
|
|
|
|
AND f.forum_id = t.forum_id
|
|
|
|
AND p.post_id = t.topic_first_post_id
|
2009-08-12 15:00:47 +00:00
|
|
|
AND t.topic_moved_id = 0',
|
2009-06-12 14:41:03 +00:00
|
|
|
'ORDER_BY' => 't.topic_time DESC',
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjust_item(&$item_row, &$row)
|
|
|
|
{
|
|
|
|
global $phpEx, $config;
|
|
|
|
|
|
|
|
$item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']);
|
|
|
|
|
|
|
|
if ($config['feed_item_statistics'])
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
2009-11-24 18:28:46 +00:00
|
|
|
$user_link = ($row[$this->get('author_id')] != ANONYMOUS) ? '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $row[$this->get('author_id')]) . '">' . $row[$this->get('creator')] . '</a>' : $row[$this->get('creator')];
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-11-24 16:00:18 +00:00
|
|
|
$item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link
|
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->format_date($row['topic_time'])
|
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies']
|
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 13:42:38 +00:00
|
|
|
class phpbb_feed_topics extends phpbb_feed_base
|
2009-06-12 14:41:03 +00:00
|
|
|
{
|
|
|
|
function set_keys()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$this->set('title', 'topic_title');
|
|
|
|
$this->set('title2', 'forum_name');
|
|
|
|
$this->set('author_id', 'topic_poster');
|
|
|
|
$this->set('creator', 'topic_first_poster_name');
|
|
|
|
$this->set('text', 'post_text');
|
|
|
|
$this->set('bitfield', 'bbcode_bitfield');
|
|
|
|
$this->set('bbcode_uid','bbcode_uid');
|
|
|
|
$this->set('date', 'topic_time');
|
|
|
|
|
|
|
|
$this->set('enable_bbcode', 'enable_bbcode');
|
|
|
|
$this->set('enable_smilies', 'enable_smilies');
|
|
|
|
$this->set('enable_magic_url', 'enable_magic_url');
|
|
|
|
|
2009-07-27 10:24:42 +00:00
|
|
|
$this->num_items = (int) $config['feed_overall_topics_limit'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_sql()
|
|
|
|
{
|
|
|
|
global $db, $config;
|
|
|
|
|
|
|
|
$post_ids = array();
|
|
|
|
$not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('t.forum_id', $this->excluded_forums(), true) : '';
|
|
|
|
|
|
|
|
// Search for topics in last x days
|
|
|
|
$last_post_time_sql = ($this->sort_days) ? ' AND t.topic_last_post_time > ' . (time() - ($this->sort_days * 24 * 3600)) : '';
|
|
|
|
|
|
|
|
// Last x topics from all forums, with first post from topic...
|
|
|
|
$sql = 'SELECT t.topic_first_post_id
|
|
|
|
FROM ' . TOPICS_TABLE . ' t
|
|
|
|
WHERE t.topic_approved = 1
|
|
|
|
AND t.topic_moved_id = 0' .
|
|
|
|
$not_in_fid .
|
|
|
|
$last_post_time_sql . '
|
|
|
|
ORDER BY t.topic_last_post_time DESC';
|
|
|
|
$result = $db->sql_query_limit($sql, $this->num_items);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2009-07-27 10:24:42 +00:00
|
|
|
$post_ids[] = (int) $row['topic_first_post_id'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
if (!sizeof($post_ids))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->sql = array(
|
2009-12-08 03:53:41 +00:00
|
|
|
'SELECT' => 'f.forum_id, f.forum_name, f.forum_topics, f.forum_posts,
|
2009-06-12 14:41:03 +00:00
|
|
|
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time,
|
2009-12-08 03:53:41 +00:00
|
|
|
p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
|
2009-06-12 14:41:03 +00:00
|
|
|
'FROM' => array(
|
|
|
|
TOPICS_TABLE => 't',
|
|
|
|
FORUMS_TABLE => 'f',
|
|
|
|
POSTS_TABLE => 'p',
|
|
|
|
),
|
|
|
|
'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . '
|
|
|
|
AND f.forum_id = p.forum_id
|
2009-12-08 03:53:41 +00:00
|
|
|
AND t.topic_id = p.topic_id',
|
2009-06-12 14:41:03 +00:00
|
|
|
'ORDER_BY' => 't.topic_last_post_time DESC',
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjust_item(&$item_row, &$row)
|
|
|
|
{
|
|
|
|
global $phpEx, $config;
|
|
|
|
|
|
|
|
$item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']);
|
|
|
|
|
|
|
|
if ($config['feed_item_statistics'])
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
2009-11-24 18:28:46 +00:00
|
|
|
$user_link = ($row[$this->get('author_id')] != ANONYMOUS) ? '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $row[$this->get('author_id')]) . '">' . $row[$this->get('creator')] . '</a>' : $row[$this->get('creator')];
|
2009-06-12 14:41:03 +00:00
|
|
|
|
2009-11-24 16:00:18 +00:00
|
|
|
$item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link
|
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->format_date($row['topic_time'])
|
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies']
|
|
|
|
. ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views'];
|
2009-06-12 14:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|