5 * @copyright (c) 2009 phpBB Group
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * Idea and original RSS Feed 2.0 MOD (Version 1.0.8/9) by leviatan21
9 * Original MOD: http://www.phpbb.com/community/viewtopic.php?f=69&t=1214645
10 * MOD Author Profile: http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=345763
11 * MOD Author Homepage: http://www.mssti.com/phpbb3/
18 define('IN_PHPBB', true);
19 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH
: './';
20 $phpEx = substr(strrchr(__FILE__
, '.'), 1);
21 include($phpbb_root_path . 'common.' . $phpEx);
23 if (!$config['feed_enable'])
25 trigger_error('NO_FEED_ENABLED');
29 $user->session_begin();
30 $auth->acl($user->data
);
34 $forum_id = request_var('f', 0);
35 $topic_id = request_var('t', 0);
36 $mode = request_var('mode', '');
38 // Feed date format for PHP > 5 and PHP4
39 $feed_date_format = (PHP_VERSION
>= 5) ?
'c' : "Y-m-d\TH:i:sO";
42 // We do not use a template, therefore we simply define the global template variables here
43 $global_vars = $item_vars = array();
45 // Generate params array for use in append_sid() to correctly link back to this page
46 if ($forum_id ||
$topic_id ||
$mode)
49 'f' => ($forum_id) ?
$forum_id : NULL,
50 't' => ($topic_id) ?
$topic_id : NULL,
51 'mode' => ($mode) ?
$mode : NULL,
56 $board_url = generate_board_url();
58 // Get correct feed object
59 $feed = phpbb_feed_factory
::init($mode, $forum_id, $topic_id);
64 trigger_error('NO_FEED');
70 // Some default assignments
71 // FEED_IMAGE is not used (atom)
73 'FEED_IMAGE' => ($user->img('site_logo', '', false, '', 'src')) ?
$board_url . '/' . substr($user->img('site_logo', '', false, '', 'src'), strlen($phpbb_root_path)) : '',
74 'SELF_LINK' => feed_append_sid('/feed.' . $phpEx, $params),
75 'FEED_LINK' => $board_url . '/index.' . $phpEx,
76 'FEED_TITLE' => $config['sitename'],
77 'FEED_SUBTITLE' => $config['site_desc'],
78 'FEED_UPDATED' => $user->format_date(time(), $feed_date_format, true),
79 'FEED_LANG' => $user->lang
['USER_LANG'],
80 'FEED_AUTHOR' => $config['sitename'],
83 // Iterate through items
84 while ($row = $feed->get_item())
86 // BBCode options to correctly disable urls, smilies, bbcode...
87 if ($feed->get('options') === NULL)
89 // Allow all combinations
92 if ($feed->get('enable_bbcode') !== NULL && $feed->get('enable_smilies') !== NULL && $feed->get('enable_magic_url') !== NULL)
94 $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);
99 $options = $row[$feed->get('options')];
102 $title = ($row[$feed->get('title')]) ?
$row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ?
$row[$feed->get('title2')] : '');
103 $title = censor_text($title);
106 'author' => ($feed->get('creator') !== NULL) ?
$row[$feed->get('creator')] : '',
107 'pubdate' => $user->format_date($row[$feed->get('date')], $feed_date_format, true),
109 'title' => censor_text($title),
110 'category' => ($config['feed_item_statistics']) ?
$board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '',
111 'category_name' => ($config['feed_item_statistics']) ?
utf8_htmlspecialchars($row['forum_name']) : '',
112 'description' => censor_text(feed_generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)),
116 // Adjust items, fill link, etc.
117 $feed->adjust_item($item_row, $row);
119 $item_vars[] = $item_row;
127 if ($config['gzip_compress'])
129 if (@extension_loaded
('zlib') && !headers_sent())
131 ob_start('ob_gzhandler');
135 // IF debug extra is enabled and admin want to "explain" the page we need to set other headers...
136 if (!defined('DEBUG_EXTRA') ||
!request_var('explain', 0) ||
!$auth->acl_get('a_'))
138 header("Content-Type: application/atom+xml; charset=UTF-8");
139 header("Last-Modified: " . gmdate('D, d M Y H:i:s', time()) . ' GMT');
143 header('Content-type: text/html; charset=UTF-8');
144 header('Cache-Control: private, no-cache="set-cookie"');
145 header('Expires: 0');
146 header('Pragma: no-cache');
148 $mtime = explode(' ', microtime());
149 $totaltime = $mtime[0] +
$mtime[1] - $starttime;
151 if (method_exists($db, 'sql_report'))
153 $db->sql_report('display');
156 garbage_collection();
160 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
161 echo '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="' . $global_vars['FEED_LANG'] . '">' . "\n";
162 echo '<link rel="self" type="application/atom+xml" href="' . $global_vars['SELF_LINK'] . '" />' . "\n\n";
164 echo (!empty($global_vars['FEED_TITLE'])) ?
'<title>' . $global_vars['FEED_TITLE'] . '</title>' . "\n" : '';
165 echo (!empty($global_vars['FEED_SUBTITLE'])) ?
'<subtitle>' . $global_vars['FEED_SUBTITLE'] . '</subtitle>' . "\n" : '';
166 echo (!empty($global_vars['FEED_LINK'])) ?
'<link href="' . $global_vars['FEED_LINK'] .'" />' . "\n" : '';
167 echo '<updated>' . $global_vars['FEED_UPDATED'] . '</updated>' . "\n\n";
169 echo '<author><name><![CDATA[' . $global_vars['FEED_AUTHOR'] . ']]></name></author>' . "\n";
170 echo '<id>' . $global_vars['SELF_LINK'] . '</id>' . "\n";
172 foreach ($item_vars as $row)
174 echo '<entry>' . "\n";
176 if (!empty($row['author']))
178 echo '<author><name><![CDATA[' . $row['author'] . ']]></name></author>' . "\n";
181 echo '<updated>' . $row['pubdate'] . '</updated>' . "\n";
182 echo '<id>' . $row['link'] . '</id>' . "\n";
183 echo '<link href="' . $row['link'] . '"/>' . "\n";
184 echo '<title type="html"><![CDATA[' . $row['title'] . ']]></title>' . "\n\n";
186 if (!empty($row['category']))
188 echo '<category term="' . $row['category_name'] . '" scheme="' . $row['category'] . '" label="' . $row['category_name'] . '"/>' . "\n";
191 echo '<content type="html" xml:base="' . $row['link'] . '"><![CDATA[' . "\n";
192 echo $row['description'];
194 if (!empty($row['statistics']))
196 echo '<p>' . $user->lang
['STATISTICS'] . ': ' . $row['statistics'] . '</p>';
199 echo '<hr /></div>' . "\n" . ']]></content>' . "\n";
200 echo '</entry>' . "\n";
205 garbage_collection();
209 * Run links through append_sid(), prepend generate_board_url() and remove session id
211 function feed_append_sid($url, $params)
215 $link = append_sid($board_url . $url, $params);
217 // Remove added sid - not as easy as it sounds. ;)
218 $link = (strpos($link, 'sid=') !== false) ?
trim(preg_replace('/(&|&|\?)sid=[a-z0-9]+(&|&)?/', '\1', $link), '?& ') : $link;
220 // Now the only thing remaining could be an empty &
221 $link = (substr($link, -5) === '&') ?
substr($link, 0, -5) : $link;
223 $link = str_replace('&#', '#', $link);
229 * Generate text content
231 function feed_generate_content($content, $uid, $bitfield, $options)
233 global $user, $config, $phpbb_root_path, $phpEx, $board_url;
240 // Prepare some bbcodes for better parsing
241 $content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content);
243 $content = generate_text_for_display($content, $uid, $bitfield, $options);
246 $content = str_replace('<br />', '<br />' . "\n", $content);
248 // Relative Path to Absolute path, Windows style
249 $content = str_replace('./', $board_url . '/', $content);
251 // Remove "Select all" link and mouse events
252 $content = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $user->lang
['SELECT_ALL_CODE'] . '</a>', '', $content);
253 $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);
255 // Firefox does not support CSS for feeds, though
258 // $content = preg_replace('#<span style="font-size: [0-9]+%; line-height: [0-9]+%;">([^>]+)</span>#iU', '\1', $content);
260 // Make text strong :P
261 // $content = preg_replace('#<span style="font-weight: bold?">(.*?)</span>#iU', '<strong>\1</strong>', $content);
264 // $content = preg_replace('#<span style="font-style: italic?">([^<]+)</span>#iU', '<em>\1</em>', $content);
267 // $content = preg_replace('#<span style="text-decoration: underline?">([^<]+)</span>#iU', '<u>\1</u>', $content);
269 // Remove embed Windows Media Streams
270 $content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--<!\[endif\]-->#si', '', $content);
272 // Do not use < and >, because we want to retain code contained in [code][/code]
274 // Remove embed and objects
275 $content = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' <a href=$4 target="_blank"><strong>$1</strong></a> ',$content);
277 // Remove some specials html tag, because somewhere there are a mod to allow html tags ;)
278 $content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
280 // Remove Comments from inline attachments [ia]
281 $content = preg_replace('#<div class="(inline-attachment|attachtitle)">(.*?)<!-- ia(.*?) -->(.*?)<!-- ia(.*?) -->(.*?)</div>#si','$4',$content);
283 // Replace some entities with their unicode counterpart
285 ' ' => "\xC2\xA0",
286 '•' => "\xE2\x80\xA2",
287 '·' => "\xC2\xB7",
288 '©' => "\xC2\xA9",
291 $content = str_replace(array_keys($entities), array_values($entities), $content);
293 // Remove CDATA blocks. ;)
294 $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content);
296 // Other control characters
297 // $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content);
303 * Factory class to return correct object
306 class phpbb_feed_factory
309 * Return correct object for specified mode
311 * @param string $mode The feeds mode.
312 * @param int $forum_id Forum id specified by the script if forum feed provided.
313 * @param int $topic_id Topic id specified by the script if topic feed provided.
315 * @return object Returns correct feeds object for specified mode.
317 function init($mode, $forum_id, $topic_id)
324 if (!$config['feed_overall_forums'])
329 return new phpbb_feed_forums();
333 if (!$config['feed_overall_topics'])
338 return new phpbb_feed_topics();
344 // Get at least one news forum
345 $sql = 'SELECT forum_id
346 FROM ' . FORUMS_TABLE
. '
347 WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS
, '<> 0');
348 $result = $db->sql_query_limit($sql, 1, 0, 600);
349 $s_feed_news = (int) $db->sql_fetchfield('forum_id');
350 $db->sql_freeresult($result);
357 return new phpbb_feed_news();
361 // Forum and/or topic specified?
362 if ($topic_id && !$config['feed_topic'])
367 if ($forum_id && !$topic_id && !$config['feed_forum'])
372 return new phpbb_feed($forum_id, $topic_id);
379 * Base/default Feed class if no mode is specified.
380 * This can be the overall site feed or a forum/topic feed.
386 * Forum id specified for forum feed.
391 * Topic id specified for topic feed.
396 * SQL Query to be executed to get feed items
401 * Keys specified for retrieval of title, content, etc.
406 * An array of excluded forum ids.
408 var $excluded_forums_ary = NULL;
411 * Number of items to fetch
416 * boolean to determine if items array is filled or not
418 var $items_filled = false;
421 * array holding items
423 var $items = array();
426 * Default setting for last x days
431 * Default cache time of entries in seconds
433 var $cache_time = 300;
436 * Separator for title elements to separate items (for example forum / topic)
438 var $separator = "\xE2\x80\xA2"; // •
441 * Constructor. Set standard keys.
443 function phpbb_feed($forum_id = 0, $topic_id = 0)
447 $this->forum_id
= $forum_id;
448 $this->topic_id
= $topic_id;
450 $this->sql
= array();
452 // Set some values for pagination
453 $this->num_items
= (int) $config['feed_limit'];
459 // Set keys for items...
460 $this->set('title', 'post_subject');
461 $this->set('title2', 'topic_title');
462 $this->set('author_id', 'user_id');
463 $this->set('creator', 'username');
464 $this->set('text', 'post_text');
465 $this->set('bitfield', 'bbcode_bitfield');
466 $this->set('bbcode_uid','bbcode_uid');
467 $this->set('date', 'post_time');
469 $this->set('enable_bbcode', 'enable_bbcode');
470 $this->set('enable_smilies', 'enable_smilies');
471 $this->set('enable_magic_url', 'enable_magic_url');
476 if (!$this->forum_id
&& !$this->topic_id
)
480 else if ($this->forum_id
&& !$this->topic_id
)
482 global $db, $user, $global_vars;
484 $sql = 'SELECT forum_name
485 FROM ' . FORUMS_TABLE
. '
486 WHERE forum_id = ' . $this->forum_id
;
487 $result = $db->sql_query($sql);
489 $global_vars['FEED_MODE'] = $user->lang
['FORUM'] . ': ' . $db->sql_fetchfield('forum_name');
491 $db->sql_freeresult($result);
493 else if ($this->topic_id
)
495 global $db, $user, $global_vars;
497 $sql = 'SELECT topic_title
498 FROM ' . TOPICS_TABLE
. '
499 WHERE topic_id = ' . $this->topic_id
;
500 $result = $db->sql_query($sql);
502 $global_vars['FEED_MODE'] = $user->lang
['TOPIC'] . ': ' . $db->sql_fetchfield('topic_title');
504 $db->sql_freeresult($result);
510 if (!empty($this->result
))
514 $db->sql_freeresult($this->result
);
521 function set($key, $value)
523 $this->keys
[$key] = $value;
531 return (isset($this->keys
[$key])) ?
$this->keys
[$key] : NULL;
535 * Return array of excluded forums
537 function excluded_forums()
539 if ($this->excluded_forums_ary
!== NULL)
541 return $this->excluded_forums_ary
;
544 global $auth, $db, $config, $phpbb_root_path, $phpEx, $user;
546 // Which forums should not be searched ?
547 $exclude_forums = array();
549 $sql = 'SELECT forum_id
550 FROM ' . FORUMS_TABLE
. '
551 WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE
, '<> 0');
552 $result = $db->sql_query($sql);
554 while ($row = $db->sql_fetchrow($result))
556 $exclude_forums[] = (int) $row['forum_id'];
558 $db->sql_freeresult($result);
560 // Exclude forums the user is not able to read
561 $this->excluded_forums_ary
= array_keys($auth->acl_getf('!f_read', true));
562 $this->excluded_forums_ary
= (sizeof($exclude_forums)) ?
array_merge($exclude_forums, $this->excluded_forums_ary
) : $this->excluded_forums_ary
;
564 $not_in_fid = (sizeof($this->excluded_forums_ary
)) ?
'WHERE (' . $db->sql_in_set('f.forum_id', $this->excluded_forums_ary
, true) . ' AND ' . $db->sql_in_set('f.parent_id', $this->excluded_forums_ary
, true) . ") OR (f.forum_password <> '' AND fa.user_id <> " . (int) $user->data
['user_id'] . ')' : '';
566 $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, fa.user_id
567 FROM ' . FORUMS_TABLE
. ' f
568 LEFT JOIN ' . FORUMS_ACCESS_TABLE
. " fa ON (fa.forum_id = f.forum_id
569 AND fa.session_id = '" . $db->sql_escape($user->session_id
) . "')
572 $result = $db->sql_query($sql);
575 while ($row = $db->sql_fetchrow($result))
577 // Exclude passworded forum completely
578 if ($row['forum_password'] && $row['user_id'] != $user->data
['user_id'])
580 $this->excluded_forums_ary
[] = (int) $row['forum_id'];
584 if ($row['right_id'] > $right_id)
586 $right_id = (int) $row['right_id'];
588 else if ($row['right_id'] < $right_id)
593 $db->sql_freeresult($result);
595 return $this->excluded_forums_ary
;
599 * Get SQL query for fetching items
607 // Search for topics in last X days
608 $last_post_time_sql = ($this->sort_days
) ?
' AND t.topic_last_post_time > ' . (time() - ($this->sort_days
* 24 * 3600)) : '';
610 // Fetch latest post, grouped by topic...
611 if (!$this->forum_id
&& !$this->topic_id
)
613 // First of all, the post ids...
614 $not_in_fid = (sizeof($this->excluded_forums())) ?
' AND ' . $db->sql_in_set('t.forum_id', $this->excluded_forums(), true) : '';
616 $sql = 'SELECT t.topic_last_post_id
617 FROM ' . TOPICS_TABLE
. ' t
618 WHERE t.topic_approved = 1
619 AND t.topic_moved_id = 0' .
621 $last_post_time_sql . '
622 ORDER BY t.topic_last_post_time DESC';
623 $result = $db->sql_query_limit($sql, $this->num_items
);
625 while ($row = $db->sql_fetchrow($result))
627 $post_ids[] = (int) $row['topic_last_post_id'];
629 $db->sql_freeresult($result);
631 // Fetch latest posts from forum
632 else if (!$this->topic_id
&& $this->forum_id
)
634 // Make sure the forum is not listed within the forbidden ones. ;)
635 if (in_array($this->forum_id
, $this->excluded_forums()))
640 // Determine which forums to fetch
641 $not_in_fid = (sizeof($this->excluded_forums())) ?
' AND ' . $db->sql_in_set('f1.forum_id', $this->excluded_forums(), true) : '';
643 // Determine forum childs...
644 $sql = 'SELECT f2.forum_id
645 FROM ' . FORUMS_TABLE
. ' f1, ' . FORUMS_TABLE
. ' f2
646 WHERE f1.forum_id = ' . $this->forum_id
. '
647 AND (f2.left_id BETWEEN f1.left_id AND f1.right_id' . $not_in_fid . ')';
648 $result = $db->sql_query($sql);
650 $forum_ids = array();
651 while ($row = $db->sql_fetchrow($result))
653 $forum_ids[] = (int) $row['forum_id'];
655 $db->sql_freeresult($result);
657 // Now select from forums...
658 $sql = 'SELECT t.topic_last_post_id
659 FROM ' . TOPICS_TABLE
. ' t
660 WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
661 AND t.topic_approved = 1
662 AND t.topic_moved_id = 0' .
663 $last_post_time_sql . '
664 ORDER BY t.topic_last_post_time DESC';
665 $result = $db->sql_query_limit($sql, $this->num_items
);
667 while ($row = $db->sql_fetchrow($result))
669 $post_ids[] = (int) $row['topic_last_post_id'];
671 $db->sql_freeresult($result);
673 // Fetch last posts from specified topic...
674 else if ($this->topic_id
)
676 // First of all, determine the forum...
677 $sql = 'SELECT forum_id
678 FROM ' . TOPICS_TABLE
. '
679 WHERE topic_id = ' . $this->topic_id
;
680 $result = $db->sql_query_limit($sql, 1);
681 $this->forum_id
= (int) $db->sql_fetchfield('forum_id');
682 $db->sql_freeresult($result);
684 // non-global announcement
685 if ($this->forum_id
&& in_array($this->forum_id
, $this->excluded_forums()))
690 $sql = 'SELECT post_id
691 FROM ' . POSTS_TABLE
. '
692 WHERE topic_id = ' . $this->topic_id
. '
693 AND post_approved = 1
694 ORDER BY post_time DESC';
695 $result = $db->sql_query_limit($sql, $this->num_items
);
697 while ($row = $db->sql_fetchrow($result))
699 $post_ids[] = (int) $row['post_id'];
701 $db->sql_freeresult($result);
704 if (!sizeof($post_ids))
709 // Now build sql query for obtaining items
711 'SELECT' => 'f.forum_id, f.forum_name, f.forum_desc_options, ' .
712 't.topic_last_post_time, t.topic_id, t.topic_title, t.topic_time, t.topic_replies, t.topic_views, ' .
713 '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, ' .
714 'u.username, u.user_id, u.user_email, u.user_colour',
721 'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . '
722 AND f.forum_id = p.forum_id
723 AND t.topic_id = p.topic_id
724 AND u.user_id = p.poster_id',
725 'ORDER_BY' => 'p.post_time DESC',
735 // Disable cache if it is not a guest or a bot but a registered user
736 if ($this->cache_time
)
740 // We check this here because we call get_item() quite often
741 if (!empty($user) && $user->data
['is_registered'])
743 $this->cache_time
= 0;
747 if (!$this->cache_time
)
749 if (empty($this->result
))
751 if (!$this->get_sql())
757 $sql = $db->sql_build_query('SELECT', $this->sql
);
758 $this->result
= $db->sql_query_limit($sql, $this->num_items
);
761 return $db->sql_fetchrow($this->result
);
765 if (empty($this->items_filled
))
767 // Try to load result set...
768 $cache_filename = substr(get_class($this), strlen('phpbb_'));
770 if (($this->items
= $cache->get('_' . $cache_filename)) === false)
772 $this->items
= array();
774 if ($this->get_sql())
777 $sql = $db->sql_build_query('SELECT', $this->sql
);
778 $result = $db->sql_query_limit($sql, $this->num_items
);
780 while ($row = $db->sql_fetchrow($result))
782 $this->items
[] = $row;
784 $db->sql_freeresult($result);
787 $cache->put('_' . $cache_filename, $this->items
, $this->cache_time
);
790 $this->items_filled
= true;
793 $row = array_shift($this->items
);
794 return (!$row) ?
false : $row;
798 function adjust_item(&$item_row, &$row)
800 global $phpEx, $config;
802 $item_row['title'] = (!$this->topic_id
) ?
$row['forum_name'] . ' ' . $this->separator
. ' ' . $item_row['title'] : $item_row['title'];
803 $item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}");
805 if ($config['feed_item_statistics'])
809 $user_link = '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $row['user_id']) . '">' . $row['username'] . '</a>';
811 $time = ($this->topic_id
) ?
$row['post_time'] : $row['topic_time'];
813 $item_row['statistics'] = $user->lang
['POSTED'] . ' ' . $user->lang
['POST_BY_AUTHOR'] . ' ' . $user_link . ' - ' . $user->format_date($time). ' - ' . $user->lang
['REPLIES'] . ' ' . $row['topic_replies'] . ' - ' . $user->lang
['VIEWS'] . ' ' . $row['topic_views'];
818 class phpbb_feed_forums
extends phpbb_feed
824 $this->set('title', 'forum_name');
825 $this->set('text', 'forum_desc');
826 $this->set('bitfield', 'forum_desc_bitfield');
827 $this->set('bbcode_uid','forum_desc_uid');
828 $this->set('date', 'forum_last_post_time');
829 $this->set('options', 'forum_desc_options');
831 $this->num_items
= (int) $config['feed_overall_forums_limit'];
836 global $user, $global_vars;
838 $global_vars['FEED_MODE'] = $user->lang
['FORUMS'];
845 $not_in_fid = (sizeof($this->excluded_forums())) ?
' AND ' . $db->sql_in_set('f.forum_id', $this->excluded_forums(), true) : '';
850 'FROM' => array(FORUMS_TABLE
=> 'f'),
851 'WHERE' => 'f.forum_type = ' . FORUM_POST
. '
852 AND (f.forum_last_post_id > 0' . $not_in_fid . ')',
853 'ORDER_BY' => 'f.left_id',
859 function adjust_item(&$item_row, &$row)
861 global $phpEx, $config;
863 $item_row['link'] = feed_append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']);
865 if ($config['feed_item_statistics'])
869 $item_row['statistics'] = sprintf($user->lang
['TOTAL_TOPICS_OTHER'], $row['forum_topics']) . ' - ' . sprintf($user->lang
['TOTAL_POSTS_OTHER'], $row['forum_posts']);
874 class phpbb_feed_news
extends phpbb_feed
880 $this->set('title', 'topic_title');
881 $this->set('title2', 'forum_name');
882 $this->set('author_id', 'topic_poster');
883 $this->set('creator', 'topic_first_poster_name');
884 $this->set('text', 'post_text');
885 $this->set('bitfield', 'bbcode_bitfield');
886 $this->set('bbcode_uid','bbcode_uid');
887 $this->set('date', 'topic_time');
889 $this->set('enable_bbcode', 'enable_bbcode');
890 $this->set('enable_smilies', 'enable_smilies');
891 $this->set('enable_magic_url', 'enable_magic_url');
893 $this->num_items
= (int) $config['feed_overall_forums_limit'];
898 global $user, $global_vars;
900 $global_vars['FEED_MODE'] = $user->lang
['FEED_NEWS'];
907 // Get news forums...
908 $sql = 'SELECT forum_id
909 FROM ' . FORUMS_TABLE
. '
910 WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS
, '<> 0');
911 $result = $db->sql_query($sql);
913 $in_fid_ary = array();
914 while ($row = $db->sql_fetchrow($result))
916 $in_fid_ary[] = (int) $row['forum_id'];
918 $db->sql_freeresult($result);
920 if (!sizeof($in_fid_ary))
927 'SELECT' => 'f.forum_id, f.forum_password, f.forum_name, f.forum_topics, f.forum_posts, f.parent_id, f.left_id, f.right_id,
928 t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time,
929 p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url,
930 u.username, u.user_id, u.user_email, u.user_colour',
937 'WHERE' => $db->sql_in_set('t.forum_id', $in_fid_ary) . '
938 AND f.forum_id = t.forum_id
939 AND p.post_id = t.topic_first_post_id
940 AND t.topic_poster = u.user_id
941 AND t.topic_moved_id = 0',
942 'ORDER_BY' => 't.topic_time DESC',
948 function adjust_item(&$item_row, &$row)
950 global $phpEx, $config;
952 $item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']);
954 if ($config['feed_item_statistics'])
958 $user_link = '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $row[$this->get('author_id')]) . '">' . $row[$this->get('creator')] . '</a>';
960 $item_row['statistics'] = $user->lang
['POSTED'] . ' ' . $user->lang
['POST_BY_AUTHOR'] . ' ' . $user_link . ' - ' . $user->format_date($row['topic_time']). ' - ' . $user->lang
['REPLIES'] . ' ' . $row['topic_replies'] . ' - ' . $user->lang
['VIEWS'] . ' ' . $row['topic_views'];
965 class phpbb_feed_topics
extends phpbb_feed
971 $this->set('title', 'topic_title');
972 $this->set('title2', 'forum_name');
973 $this->set('author_id', 'topic_poster');
974 $this->set('creator', 'topic_first_poster_name');
975 $this->set('text', 'post_text');
976 $this->set('bitfield', 'bbcode_bitfield');
977 $this->set('bbcode_uid','bbcode_uid');
978 $this->set('date', 'topic_time');
980 $this->set('enable_bbcode', 'enable_bbcode');
981 $this->set('enable_smilies', 'enable_smilies');
982 $this->set('enable_magic_url', 'enable_magic_url');
984 $this->num_items
= (int) $config['feed_overall_topics_limit'];
989 global $user, $global_vars;
991 $global_vars['FEED_MODE'] = $user->lang
['TOPICS'];
999 $not_in_fid = (sizeof($this->excluded_forums())) ?
' AND ' . $db->sql_in_set('t.forum_id', $this->excluded_forums(), true) : '';
1001 // Search for topics in last x days
1002 $last_post_time_sql = ($this->sort_days
) ?
' AND t.topic_last_post_time > ' . (time() - ($this->sort_days
* 24 * 3600)) : '';
1004 // Last x topics from all forums, with first post from topic...
1005 $sql = 'SELECT t.topic_first_post_id
1006 FROM ' . TOPICS_TABLE
. ' t
1007 WHERE t.topic_approved = 1
1008 AND t.topic_moved_id = 0' .
1010 $last_post_time_sql . '
1011 ORDER BY t.topic_last_post_time DESC';
1012 $result = $db->sql_query_limit($sql, $this->num_items
);
1014 while ($row = $db->sql_fetchrow($result))
1016 $post_ids[] = (int) $row['topic_first_post_id'];
1018 $db->sql_freeresult($result);
1020 if (!sizeof($post_ids))
1026 'SELECT' => 'f.forum_id, f.forum_password, f.forum_name, f.forum_topics, f.forum_posts, f.parent_id, f.left_id, f.right_id,
1027 t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time,
1028 p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url,
1029 u.username, u.user_id, u.user_email, u.user_colour',
1031 TOPICS_TABLE
=> 't',
1032 FORUMS_TABLE
=> 'f',
1036 'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . '
1037 AND f.forum_id = p.forum_id
1038 AND t.topic_id = p.topic_id
1039 AND u.user_id = p.poster_id',
1040 'ORDER_BY' => 't.topic_last_post_time DESC',
1046 function adjust_item(&$item_row, &$row)
1048 global $phpEx, $config;
1050 $item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']);
1052 if ($config['feed_item_statistics'])
1056 $user_link = '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $row[$this->get('author_id')]) . '">' . $row[$this->get('creator')] . '</a>';
1058 $item_row['statistics'] = $user->lang
['POSTED'] . ' ' . $user->lang
['POST_BY_AUTHOR'] . ' ' . $user_link . ' - ' . $user->format_date($row['topic_time']). ' - ' . $user->lang
['REPLIES'] . ' ' . $row['topic_replies'] . ' - ' . $user->lang
['VIEWS'] . ' ' . $row['topic_views'];