From 863d7a7614a09dac545d3c3201e67c3beddb3960 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 12 Jun 2009 14:41:03 +0000 Subject: First ATOM Feed commit/integration - Idea and original RSS Feed 2.0 MOD (Version 1.0.8/9) by leviatan21 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9575 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 1001 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1001 insertions(+) create mode 100644 phpBB/feed.php (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php new file mode 100644 index 0000000000..1d4e26aaab --- /dev/null +++ b/phpBB/feed.php @@ -0,0 +1,1001 @@ +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', ''); + +// Feed date format for PHP > 5 and PHP4 +$feed_date_format = (PHP_VERSION >= 5) ? 'c' : "Y-m-d\TH:i:sO"; +$params = false; + +// We do not use a template, therefore we simply define the global template variables here +$global_vars = $item_vars = array(); + +// Generate params array for use in append_sid() to correctly link back to this page +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 +$feed->open(); + +// Some default assignments +// FEED_IMAGE is not used (atom) +$global_vars = array( + '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'], + 'FEED_UPDATED' => $user->format_date(time(), $feed_date_format, true), + 'FEED_LANG' => $user->lang['USER_LANG'], + 'FEED_AUTHOR' => $config['sitename'], +); + +// 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); + + $item_row = array( + 'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '', + 'pubdate' => $user->format_date($row[$feed->get('date')], $feed_date_format, true), + 'link' => '', + 'title' => censor_text($title), + 'category' => ($config['feed_item_statistics']) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', + 'category_name' => ($config['feed_item_statistics']) ? utf8_htmlspecialchars($row['forum_name']) : '', + '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; +} + +$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... +if (!defined('DEBUG_EXTRA') || !request_var('explain', 0) || !$auth->acl_get('a_')) +{ + header("Content-Type: application/atom+xml; charset=UTF-8"); + header("Last-Modified: " . gmdate('D, d M Y H:i:s', time()) . ' GMT'); +} +else +{ + 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(); +} + +echo '' . "\n"; +echo '' . "\n"; +echo '' . "\n\n"; + +echo (!empty($global_vars['FEED_TITLE'])) ? '' . $global_vars['FEED_TITLE'] . '' . "\n" : ''; +echo (!empty($global_vars['FEED_SUBTITLE'])) ? '' . $global_vars['FEED_SUBTITLE'] . '' . "\n" : ''; +echo (!empty($global_vars['FEED_LINK'])) ? '' . "\n" : ''; +echo '' . $global_vars['FEED_UPDATED'] . '' . "\n\n"; + +echo '' . $global_vars['FEED_AUTHOR'] . '' . "\n"; +echo '' . $global_vars['SELF_LINK'] . '' . "\n"; + +foreach ($item_vars as $row) +{ + echo '' . "\n"; + + if (!empty($row['author'])) + { + echo '' . $row['author'] . '' . "\n"; + } + + echo '' . $row['pubdate'] . '' . "\n"; + echo '' . $row['link'] . '' . "\n"; + echo '' . "\n"; + echo '' . $row['title'] . '' . "\n\n"; + + if (!empty($row['category'])) + { + echo '' . "\n"; + } + + echo '' . "\n"; + echo '
' . "\n"; + echo $row['description']; + + if (!empty($row['statistics'])) + { + echo '

' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '

'; + } + + echo '
' . "\n" . '
' . "\n"; + echo '
' . "\n"; +} + +echo '
'; + +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; + + $link = append_sid($board_url . $url, $params); + + // Remove added sid - not as easy as it sounds. ;) + return (strpos($link, 'sid=') !== false) ? trim(preg_replace('/(&|&|\?)sid=[a-z0-9]+(&|&)?/', '\1', $link), '?& ') : $link; +} + +/** +* 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]
$2
[/quote:$uid]", $content); + + $content = generate_text_for_display($content, $uid, $bitfield, $options); + + // Relative Path to Absolute path, Windows style + $content = str_replace('./', $board_url . '/', $content); + + // Remove "Select all" link and mouse events + $content = str_replace('' .$user->lang['SELECT_ALL_CODE'] . '', '', $content); + $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content); + + // Remove font sizes + $content = preg_replace('#([^>]+)#iU', '\1', $content); + + // Make text strong :P + $content = preg_replace('#([^<]+)#iU', '\1', $content); + + // Italic + $content = preg_replace('#([^<]+)#iU', '\1', $content); + + // Underline + $content = preg_replace('#([^<]+)#iU', '\1', $content); + + // Remove embed Windows Media Streams + $content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--#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',' $1 ',$content); + + // Remove some specials html tag, because somewhere there are a mod to allow html tags ;) + $content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' $1 ', $content); + + // Remove Comments from inline attachments [ia] + $content = preg_replace('#
(.*?)(.*?)(.*?)
#si','$4',$content); + + // Replace some entities with their unicode counterpart + $entities = array( + ' ' => ' ', + '•' => '•', + '·' => '·', + '©' => '©', + ); + + $content = str_replace(array_keys($entities), array_values($entities), $content); + + // 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': + if (empty($config['feed_news_id'])) + { + 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; + } + } +} + +/** +* Base/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 +{ + /** + * Forum id specified for forum feed. + */ + var $forum_id = 0; + + /** + * Topic id specified for topic feed. + */ + var $topic_id = 0; + + /** + * SQL Query to be executed to get feed items + */ + var $sql; + + /** + * Keys specified for retrieval of title, content, etc. + */ + var $keys = array(); + + /** + * An array of excluded forum ids. + */ + var $excluded_forums_ary = NULL; + + /** + * Number of items to fetch + */ + var $num_items; + + /** + * 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 + */ + var $sort_days = 100; + + /** + * Default cache time of entries in seconds + */ + var $cache_time = 300; + + /** + * Constructor. Set standard keys. + */ + function phpbb_feed($forum_id = 0, $topic_id = 0) + { + global $config; + + $this->forum_id = $forum_id; + $this->topic_id = $topic_id; + + $this->sql = array(); + + // Set some values for pagination + $this->num_items = $config['feed_limit']; + $this->set_keys(); + } + + function set_keys() + { + // Set keys for items... + $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'); + } + + function open() + { + if (!$this->forum_id && !$this->topic_id) + { + return; + } + else if ($this->forum_id && !$this->topic_id) + { + global $db, $user, $global_vars; + + $sql = 'SELECT forum_name + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $this->forum_id; + $result = $db->sql_query($sql); + + $global_vars['FEED_MODE'] = $user->lang['FORUM'] . ': ' . $db->sql_fetchfield('forum_name'); + + $db->sql_freeresult($result); + } + else if ($this->topic_id) + { + global $db, $user, $global_vars; + + $sql = 'SELECT topic_title + FROM ' . TOPICS_TABLE . ' + WHERE topic_id = ' . $this->topic_id; + $result = $db->sql_query($sql); + + $global_vars['FEED_MODE'] = $user->lang['TOPIC'] . ': ' . $db->sql_fetchfield('topic_title'); + + $db->sql_freeresult($result); + } + } + + function close() + { + if (!empty($this->result)) + { + global $db; + + $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 ? + $exclude_forums = (!empty($config['feed_exclude_id'])) ? unserialize(trim($config['feed_exclude_id'])) : array(); + + // Exclude forums the user is not able to read + $this->excluded_forums_ary = array_keys($auth->acl_getf('!f_read', true)); + $this->excluded_forums_ary = (sizeof($exclude_forums)) ? array_merge($exclude_forums, $this->excluded_forums_ary) : $this->excluded_forums_ary; + + $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'] . ')' : ''; + + $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, fa.user_id + FROM ' . FORUMS_TABLE . ' f + LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id + AND fa.session_id = '" . $db->sql_escape($user->session_id) . "') + $not_in_fid + ORDER BY f.left_id"; + $result = $db->sql_query($sql); + + $right_id = 0; + while ($row = $db->sql_fetchrow($result)) + { + // Exclude passworded forum completely + if ($row['forum_password'] && $row['user_id'] != $user->data['user_id']) + { + $this->excluded_forums_ary[] = (int) $row['forum_id']; + continue; + } + + if ($row['right_id'] > $right_id) + { + $right_id = (int) $row['right_id']; + } + else if ($row['right_id'] < $right_id) + { + continue; + } + } + $db->sql_freeresult($result); + + return $this->excluded_forums_ary; + } + + /** + * Get SQL query for fetching items + */ + function get_sql() + { + global $db; + + $post_ids = array(); + + // Search for topics in last 7 days + $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)) + { + $post_ids[] = $row['topic_last_post_id']; + } + $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 + $not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('f1.forum_id', $this->excluded_forums(), true) : ''; + + // 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)) + { + $forum_ids[] = $row['forum_id']; + } + $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)) + { + $post_ids[] = $row['topic_last_post_id']; + } + $db->sql_freeresult($result); + } + // Fetch last posts from specified topic... + else if ($this->topic_id) + { + // First of all, determine the forum... + $sql = 'SELECT forum_id + FROM ' . TOPICS_TABLE . ' + WHERE topic_id = ' . $this->topic_id; + $result = $db->sql_query_limit($sql, 1); + $this->forum_id = (int) $db->sql_fetchfield('forum_id'); + $db->sql_freeresult($result); + + // 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)) + { + $post_ids[] = $row['post_id']; + } + $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, ' . + 'u.username, u.user_id, u.user_email', + '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 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; + } + } + + function adjust_item(&$item_row, &$row) + { + global $phpEx, $config; + + $item_row['title'] = (!$this->topic_id) ? $row['forum_name'] . ' | ' . $item_row['title'] : $item_row['title']; + $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; + + $user_link = '' . $row['username'] . ''; + + $time = ($this->topic_id) ? $row['post_time'] : $row['topic_time']; + + $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']; + } + } +} + +class phpbb_feed_forums extends phpbb_feed +{ + 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'); + + $this->num_items = $config['feed_overall_forums_limit']; + } + + function open() + { + global $user, $global_vars; + + $global_vars['FEED_MODE'] = $user->lang['FORUMS']; + } + + 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; + + $item_row['statistics'] = sprintf($user->lang['TOTAL_TOPICS_OTHER'], $row['forum_topics']) . ' - ' . sprintf($user->lang['TOTAL_POSTS_OTHER'], $row['forum_posts']); + } + } +} + +class phpbb_feed_news extends phpbb_feed +{ + 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'); + + $this->num_items = $config['feed_overall_forums_limit']; + } + + function open() + { + global $user, $global_vars; + + $global_vars['FEED_MODE'] = $user->lang['FEED_NEWS']; + } + + function get_sql() + { + global $db, $config; + + $in_fid_ary = unserialize(trim($config['feed_news_id'])); + + if (!sizeof($in_fid_ary)) + { + return false; + } + + // Build SQL Query + $this->sql = array( + '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, + t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, + p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, + u.username, u.user_id, u.user_email', + 'FROM' => array( + TOPICS_TABLE => 't', + FORUMS_TABLE => 'f', + POSTS_TABLE => 'p', + USERS_TABLE => 'u', + ), + '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 + AND t.topic_poster = u.user_id', + '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; + + $user_link = '' . $row[$this->get('creator')] . ''; + + $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']; + } + } +} + +class phpbb_feed_topics extends phpbb_feed +{ + 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'); + + $this->num_items = $config['feed_overall_topics_limit']; + } + + function open() + { + global $user, $global_vars; + + $global_vars['FEED_MODE'] = $user->lang['TOPICS']; + } + + 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)) + { + $post_ids[] = $row['topic_first_post_id']; + } + $db->sql_freeresult($result); + + if (!sizeof($post_ids)) + { + return false; + } + + $this->sql = array( + '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, + t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, + p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, + u.username, u.user_id, u.user_email', + 'FROM' => array( + TOPICS_TABLE => 't', + FORUMS_TABLE => 'f', + POSTS_TABLE => 'p', + 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' => '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; + + $user_link = '' . $row[$this->get('creator')] . ''; + + $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']; + } + } +} + + +?> \ No newline at end of file -- cgit v1.2.1 From c0b4cf2f6e6e0953071fbdea189d58bf60c4f862 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 23 Jun 2009 17:15:53 +0000 Subject: fix feed generation git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9663 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 66 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 1d4e26aaab..9d9bf145b1 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -158,38 +158,40 @@ else exit_handler(); } +$namespace = 'phpbb'; + echo '' . "\n"; -echo '' . "\n"; -echo '' . "\n\n"; +echo '<' . $namespace . ':feed xmlns:' . $namespace . '="http://www.w3.org/2005/Atom" xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $global_vars['FEED_LANG'] . '">' . "\n"; +echo '<' . $namespace . ':link rel="self" type="application/atom+xml" href="' . $global_vars['SELF_LINK'] . '" />' . "\n\n"; -echo (!empty($global_vars['FEED_TITLE'])) ? '' . $global_vars['FEED_TITLE'] . '' . "\n" : ''; -echo (!empty($global_vars['FEED_SUBTITLE'])) ? '' . $global_vars['FEED_SUBTITLE'] . '' . "\n" : ''; -echo (!empty($global_vars['FEED_LINK'])) ? '' . "\n" : ''; -echo '' . $global_vars['FEED_UPDATED'] . '' . "\n\n"; +echo (!empty($global_vars['FEED_TITLE'])) ? '<' . $namespace . ':title>' . $global_vars['FEED_TITLE'] . '' . "\n" : ''; +echo (!empty($global_vars['FEED_SUBTITLE'])) ? '<' . $namespace . ':subtitle>' . $global_vars['FEED_SUBTITLE'] . '' . "\n" : ''; +echo (!empty($global_vars['FEED_LINK'])) ? '<' . $namespace . ':link href="' . $global_vars['FEED_LINK'] .'" />' . "\n" : ''; +echo '<' . $namespace . ':updated>' . $global_vars['FEED_UPDATED'] . '' . "\n\n"; -echo '' . $global_vars['FEED_AUTHOR'] . '' . "\n"; -echo '' . $global_vars['SELF_LINK'] . '' . "\n"; +echo '<' . $namespace . ':author><' . $namespace . ':name>' . $global_vars['FEED_AUTHOR'] . '' . "\n"; +echo '<' . $namespace . ':id>' . $global_vars['SELF_LINK'] . '' . "\n"; foreach ($item_vars as $row) { - echo '' . "\n"; + echo '<' . $namespace . ':entry>' . "\n"; if (!empty($row['author'])) { - echo '' . $row['author'] . '' . "\n"; + echo '<' . $namespace . ':author><' . $namespace . ':name>' . $row['author'] . '' . "\n"; } - echo '' . $row['pubdate'] . '' . "\n"; - echo '' . $row['link'] . '' . "\n"; - echo '' . "\n"; - echo '' . $row['title'] . '' . "\n\n"; + echo '<' . $namespace . ':updated>' . $row['pubdate'] . '' . "\n"; + echo '<' . $namespace . ':id>' . $row['link'] . '' . "\n"; + echo '<' . $namespace . ':link href="' . $row['link'] . '"/>' . "\n"; + echo '<' . $namespace . ':title type="xhtml">
' . $row['title'] . '
' . "\n\n"; if (!empty($row['category'])) { - echo '' . "\n"; + echo '<' . $namespace . ':category term="' . $row['category_name'] . '" scheme="' . $row['category'] . '" label="' . $row['category_name'] . '"/>' . "\n"; } - echo '' . "\n"; + echo '<' . $namespace . ':content type="xhtml" xml:base="' . $row['link'] . '">' . "\n"; echo '
' . "\n"; echo $row['description']; @@ -198,11 +200,11 @@ foreach ($item_vars as $row) echo '

' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '

'; } - echo '
' . "\n" . '
' . "\n"; - echo '
' . "\n"; + echo '
' . "\n" . '' . "\n"; + echo '' . "\n"; } -echo '
'; +echo ''; garbage_collection(); exit_handler(); @@ -217,7 +219,15 @@ function feed_append_sid($url, $params) $link = append_sid($board_url . $url, $params); // Remove added sid - not as easy as it sounds. ;) - return (strpos($link, 'sid=') !== false) ? trim(preg_replace('/(&|&|\?)sid=[a-z0-9]+(&|&)?/', '\1', $link), '?& ') : $link; + $link = (strpos($link, 'sid=') !== false) ? trim(preg_replace('/(&|&|\?)sid=[a-z0-9]+(&|&)?/', '\1', $link), '?& ') : $link; + + // Now the only thing remaining could be an empty & + if (substr($link, -5) === '&') + { + $link = substr($link, 0, -5); + } + + return $link; } /** @@ -237,6 +247,9 @@ function feed_generate_content($content, $uid, $bitfield, $options) $content = generate_text_for_display($content, $uid, $bitfield, $options); + // Add newlines + $content = str_replace('
', '
' . "\n", $content); + // Relative Path to Absolute path, Windows style $content = str_replace('./', $board_url . '/', $content); @@ -409,6 +422,11 @@ class phpbb_feed */ var $cache_time = 300; + /** + * Separator for title elements to separate items (for example forum / topic) + */ + var $separator = '•'; + /** * Constructor. Set standard keys. */ @@ -672,7 +690,7 @@ class phpbb_feed '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, ' . - 'u.username, u.user_id, u.user_email', + 'u.username, u.user_id, u.user_email, u.user_colour', 'FROM' => array( POSTS_TABLE => 'p', TOPICS_TABLE => 't', @@ -748,7 +766,7 @@ class phpbb_feed { global $phpEx, $config; - $item_row['title'] = (!$this->topic_id) ? $row['forum_name'] . ' | ' . $item_row['title'] : $item_row['title']; + $item_row['title'] = (!$this->topic_id) ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; $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']) @@ -865,7 +883,7 @@ class phpbb_feed_news extends phpbb_feed '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, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, - u.username, u.user_id, u.user_email', + u.username, u.user_id, u.user_email, u.user_colour', 'FROM' => array( TOPICS_TABLE => 't', FORUMS_TABLE => 'f', @@ -963,7 +981,7 @@ class phpbb_feed_topics extends phpbb_feed '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, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, - u.username, u.user_id, u.user_email', + u.username, u.user_id, u.user_email, u.user_colour', 'FROM' => array( TOPICS_TABLE => 't', FORUMS_TABLE => 'f', -- cgit v1.2.1 From 585d533f4dc4cefc7e3e5c06cc7d9f171a81772b Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 7 Jul 2009 11:05:50 +0000 Subject: commit changes suggested by Crise git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9721 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 9d9bf145b1..33549bcc56 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -158,41 +158,38 @@ else exit_handler(); } -$namespace = 'phpbb'; - echo '' . "\n"; -echo '<' . $namespace . ':feed xmlns:' . $namespace . '="http://www.w3.org/2005/Atom" xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $global_vars['FEED_LANG'] . '">' . "\n"; -echo '<' . $namespace . ':link rel="self" type="application/atom+xml" href="' . $global_vars['SELF_LINK'] . '" />' . "\n\n"; +echo '' . "\n"; +echo '' . "\n\n"; -echo (!empty($global_vars['FEED_TITLE'])) ? '<' . $namespace . ':title>' . $global_vars['FEED_TITLE'] . '' . "\n" : ''; -echo (!empty($global_vars['FEED_SUBTITLE'])) ? '<' . $namespace . ':subtitle>' . $global_vars['FEED_SUBTITLE'] . '' . "\n" : ''; -echo (!empty($global_vars['FEED_LINK'])) ? '<' . $namespace . ':link href="' . $global_vars['FEED_LINK'] .'" />' . "\n" : ''; -echo '<' . $namespace . ':updated>' . $global_vars['FEED_UPDATED'] . '' . "\n\n"; +echo (!empty($global_vars['FEED_TITLE'])) ? '' . $global_vars['FEED_TITLE'] . '' . "\n" : ''; +echo (!empty($global_vars['FEED_SUBTITLE'])) ? '' . $global_vars['FEED_SUBTITLE'] . '' . "\n" : ''; +echo (!empty($global_vars['FEED_LINK'])) ? '' . "\n" : ''; +echo '' . $global_vars['FEED_UPDATED'] . '' . "\n\n"; -echo '<' . $namespace . ':author><' . $namespace . ':name>' . $global_vars['FEED_AUTHOR'] . '' . "\n"; -echo '<' . $namespace . ':id>' . $global_vars['SELF_LINK'] . '' . "\n"; +echo '' . "\n"; +echo '' . $global_vars['SELF_LINK'] . '' . "\n"; foreach ($item_vars as $row) { - echo '<' . $namespace . ':entry>' . "\n"; + echo '' . "\n"; if (!empty($row['author'])) { - echo '<' . $namespace . ':author><' . $namespace . ':name>' . $row['author'] . '' . "\n"; + echo '' . "\n"; } - echo '<' . $namespace . ':updated>' . $row['pubdate'] . '' . "\n"; - echo '<' . $namespace . ':id>' . $row['link'] . '' . "\n"; - echo '<' . $namespace . ':link href="' . $row['link'] . '"/>' . "\n"; - echo '<' . $namespace . ':title type="xhtml">
' . $row['title'] . '
' . "\n\n"; + echo '' . $row['pubdate'] . '' . "\n"; + echo '' . $row['link'] . '' . "\n"; + echo '' . "\n"; + echo '<![CDATA[' . $row['title'] . ']]>' . "\n\n"; if (!empty($row['category'])) { - echo '<' . $namespace . ':category term="' . $row['category_name'] . '" scheme="' . $row['category'] . '" label="' . $row['category_name'] . '"/>' . "\n"; + echo '' . "\n"; } - echo '<' . $namespace . ':content type="xhtml" xml:base="' . $row['link'] . '">' . "\n"; - echo '
' . "\n"; + echo '' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '

'; } - echo '
' . "\n" . '' . "\n"; - echo '' . "\n"; + echo '
' . "\n" . ']]>' . "\n"; + echo '
' . "\n"; } -echo ''; +echo '
'; garbage_collection(); exit_handler(); @@ -257,17 +254,19 @@ function feed_generate_content($content, $uid, $bitfield, $options) $content = str_replace('' .$user->lang['SELECT_ALL_CODE'] . '', '', $content); $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content); + // Firefox does not support CSS for feeds, though + // Remove font sizes - $content = preg_replace('#([^>]+)#iU', '\1', $content); +// $content = preg_replace('#([^>]+)#iU', '\1', $content); // Make text strong :P - $content = preg_replace('#([^<]+)#iU', '\1', $content); +// $content = preg_replace('#(.*?)#iU', '\1', $content); // Italic - $content = preg_replace('#([^<]+)#iU', '\1', $content); +// $content = preg_replace('#([^<]+)#iU', '\1', $content); // Underline - $content = preg_replace('#([^<]+)#iU', '\1', $content); +// $content = preg_replace('#([^<]+)#iU', '\1', $content); // Remove embed Windows Media Streams $content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--#si', '', $content); @@ -293,6 +292,9 @@ function feed_generate_content($content, $uid, $bitfield, $options) $content = str_replace(array_keys($entities), array_values($entities), $content); + // Remove CDATA blocks. ;) + $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content); + // Other control characters // $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content); -- cgit v1.2.1 From 0cb565dc0c49edb871393cf4ec15fa193ce7fccb Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 27 Jul 2009 09:56:31 +0000 Subject: do not cache results from registered users... git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9866 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 33549bcc56..ffce19746d 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -10,7 +10,6 @@ * MOD Author Profile: http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=345763 * MOD Author Homepage: http://www.mssti.com/phpbb3/ * -* @note remove cache if Authentication gets added **/ /** @@ -221,7 +220,7 @@ function feed_append_sid($url, $params) // Now the only thing remaining could be an empty & if (substr($link, -5) === '&') { - $link = substr($link, 0, -5); + $link = substr($link, 0, -5); } return $link; @@ -417,7 +416,7 @@ class phpbb_feed /** * Default setting for last x days */ - var $sort_days = 100; + var $sort_days = 30; /** * Default cache time of entries in seconds @@ -585,7 +584,7 @@ class phpbb_feed $post_ids = array(); - // Search for topics in last 7 days + // 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)) : ''; // Fetch latest post, grouped by topic... @@ -713,6 +712,18 @@ class phpbb_feed { global $db, $cache; + // Disable cache if it is not a guest or a bot but a registered user + if ($this->cache_time) + { + global $user; + + // We check this here because we call get_item() quite often + if (!empty($user) && $user->data['is_registered']) + { + $this->cache_time = 0; + } + } + if (!$this->cache_time) { if (empty($this->result)) -- cgit v1.2.1 From 3d8d213e8f57a9387b090c858fb831036b264ade Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 27 Jul 2009 10:24:42 +0000 Subject: Cast some array values and properties to integer. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9867 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index ffce19746d..5f19d0161b 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -604,7 +604,7 @@ class phpbb_feed while ($row = $db->sql_fetchrow($result)) { - $post_ids[] = $row['topic_last_post_id']; + $post_ids[] = (int) $row['topic_last_post_id']; } $db->sql_freeresult($result); } @@ -630,7 +630,7 @@ class phpbb_feed $forum_ids = array(); while ($row = $db->sql_fetchrow($result)) { - $forum_ids[] = $row['forum_id']; + $forum_ids[] = (int) $row['forum_id']; } $db->sql_freeresult($result); @@ -646,7 +646,7 @@ class phpbb_feed while ($row = $db->sql_fetchrow($result)) { - $post_ids[] = $row['topic_last_post_id']; + $post_ids[] = (int) $row['topic_last_post_id']; } $db->sql_freeresult($result); } @@ -676,7 +676,7 @@ class phpbb_feed while ($row = $db->sql_fetchrow($result)) { - $post_ids[] = $row['post_id']; + $post_ids[] = (int) $row['post_id']; } $db->sql_freeresult($result); } @@ -870,7 +870,7 @@ class phpbb_feed_news extends phpbb_feed $this->set('enable_smilies', 'enable_smilies'); $this->set('enable_magic_url', 'enable_magic_url'); - $this->num_items = $config['feed_overall_forums_limit']; + $this->num_items = (int) $config['feed_overall_forums_limit']; } function open() @@ -949,7 +949,7 @@ class phpbb_feed_topics extends phpbb_feed $this->set('enable_smilies', 'enable_smilies'); $this->set('enable_magic_url', 'enable_magic_url'); - $this->num_items = $config['feed_overall_topics_limit']; + $this->num_items = (int) $config['feed_overall_topics_limit']; } function open() @@ -981,7 +981,7 @@ class phpbb_feed_topics extends phpbb_feed while ($row = $db->sql_fetchrow($result)) { - $post_ids[] = $row['topic_first_post_id']; + $post_ids[] = (int) $row['topic_first_post_id']; } $db->sql_freeresult($result); -- cgit v1.2.1 From 4066849b726b279923d0518c4754f21b464186a4 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 27 Jul 2009 10:46:56 +0000 Subject: i hope this resolves the duplicate issues in feed readers git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9868 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 5f19d0161b..a84cc81940 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -218,10 +218,9 @@ function feed_append_sid($url, $params) $link = (strpos($link, 'sid=') !== false) ? trim(preg_replace('/(&|&|\?)sid=[a-z0-9]+(&|&)?/', '\1', $link), '?& ') : $link; // Now the only thing remaining could be an empty & - if (substr($link, -5) === '&') - { - $link = substr($link, 0, -5); - } + $link = (substr($link, -5) === '&') ? substr($link, 0, -5) : $link; + // And &#xxx + $link = str_replace('&#', '#', $link); return $link; } -- cgit v1.2.1 From a96986744dbe5819b42baacc929c23fc8e57c746 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 27 Jul 2009 12:18:09 +0000 Subject: Directly send UTF8 data instead of entities. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9870 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index a84cc81940..f0e4435956 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -282,10 +282,10 @@ function feed_generate_content($content, $uid, $bitfield, $options) // Replace some entities with their unicode counterpart $entities = array( - ' ' => ' ', - '•' => '•', - '·' => '·', - '©' => '©', + ' ' => "\xC2\xA0", + '•' => "\xE2\x80\xA2", + '·' => "\xC2\xB7", + '©' => "\xC2\xA9", ); $content = str_replace(array_keys($entities), array_values($entities), $content); @@ -425,7 +425,7 @@ class phpbb_feed /** * Separator for title elements to separate items (for example forum / topic) */ - var $separator = '•'; + var $separator = "\xE2\x80\xA2"; // • /** * Constructor. Set standard keys. -- cgit v1.2.1 From 09ad10a734c0993f9465e6ac3463951251602fc6 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 12 Aug 2009 15:00:47 +0000 Subject: ok, i am very sorry, but this needs to be fixed. Generally, our config table is not really suited for holding large datasets. Because feed settings for the forums to enable news feeds and excluded forums rely on the forums itself we have decided to introduce a forum_options table where custom options can be stored. Additionally, for this to work across all DBMS we support, we added a new method to the DBAL for the bitwise AND operator. Also moved the forum/topic feed template variable to the location where they belong to (forum and topic view) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9965 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index f0e4435956..9603b27301 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -339,7 +339,17 @@ class phpbb_feed_factory break; case 'news': - if (empty($config['feed_news_id'])) + 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) { return false; } @@ -534,7 +544,18 @@ class phpbb_feed global $auth, $db, $config, $phpbb_root_path, $phpEx, $user; // Which forums should not be searched ? - $exclude_forums = (!empty($config['feed_exclude_id'])) ? unserialize(trim($config['feed_exclude_id'])) : array(); + $exclude_forums = array(); + + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0'); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $exclude_forums[] = (int) $row['forum_id']; + } + $db->sql_freeresult($result); // Exclude forums the user is not able to read $this->excluded_forums_ary = array_keys($auth->acl_getf('!f_read', true)); @@ -883,7 +904,18 @@ class phpbb_feed_news extends phpbb_feed { global $db, $config; - $in_fid_ary = unserialize(trim($config['feed_news_id'])); + // 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)) + { + $in_fid_ary[] = (int) $row['forum_id']; + } + $db->sql_freeresult($result); if (!sizeof($in_fid_ary)) { @@ -905,7 +937,8 @@ class phpbb_feed_news extends phpbb_feed '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 - AND t.topic_poster = u.user_id', + AND t.topic_poster = u.user_id + AND t.topic_moved_id = 0', 'ORDER_BY' => 't.topic_time DESC', ); -- cgit v1.2.1 From 8661541d0dc8dbf95082e49180400ae81c4a1247 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 3 Oct 2009 13:23:10 +0000 Subject: Some nitpicks before we include this file in a final release. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10202 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 9603b27301..a6206d9203 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -249,7 +249,7 @@ function feed_generate_content($content, $uid, $bitfield, $options) $content = str_replace('./', $board_url . '/', $content); // Remove "Select all" link and mouse events - $content = str_replace('' .$user->lang['SELECT_ALL_CODE'] . '', '', $content); + $content = str_replace('' . $user->lang['SELECT_ALL_CODE'] . '', '', $content); $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content); // Firefox does not support CSS for feeds, though @@ -450,7 +450,7 @@ class phpbb_feed $this->sql = array(); // Set some values for pagination - $this->num_items = $config['feed_limit']; + $this->num_items = (int) $config['feed_limit']; $this->set_keys(); } @@ -828,7 +828,7 @@ class phpbb_feed_forums extends phpbb_feed $this->set('date', 'forum_last_post_time'); $this->set('options', 'forum_desc_options'); - $this->num_items = $config['feed_overall_forums_limit']; + $this->num_items = (int) $config['feed_overall_forums_limit']; } function open() -- cgit v1.2.1 From cc0eadb67feb8debcf38f8e102f1c3ed63368f33 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 12 Oct 2009 14:16:09 +0000 Subject: remove unused closing div tag (Bug #52735) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10221 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index a6206d9203..88539acbf1 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -196,7 +196,7 @@ foreach ($item_vars as $row) echo '

' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '

'; } - echo '
' . "\n" . ']]>' . "\n"; + echo '
' . "\n" . ']]>' . "\n"; echo '' . "\n"; } -- cgit v1.2.1 From cdc780b798d309c5d7c8e0402c88dc760a1bfdb6 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 20 Oct 2009 11:04:00 +0000 Subject: fix bug #53045 the simple way. ;) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10225 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 88539acbf1..263f6f9272 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -430,7 +430,7 @@ class phpbb_feed /** * Default cache time of entries in seconds */ - var $cache_time = 300; + var $cache_time = 0; /** * Separator for title elements to separate items (for example forum / topic) -- cgit v1.2.1 From 2258d856235b29222ee82c17d9f6490c8dc7284c Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 29 Oct 2009 14:00:43 +0000 Subject: Implement suggestion in ticket #52155 - Better way to generate SID-free links in feed.php git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10244 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 263f6f9272..b9d6e1959a 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -212,17 +212,7 @@ function feed_append_sid($url, $params) { global $board_url; - $link = append_sid($board_url . $url, $params); - - // Remove added sid - not as easy as it sounds. ;) - $link = (strpos($link, 'sid=') !== false) ? trim(preg_replace('/(&|&|\?)sid=[a-z0-9]+(&|&)?/', '\1', $link), '?& ') : $link; - - // Now the only thing remaining could be an empty & - $link = (substr($link, -5) === '&') ? substr($link, 0, -5) : $link; - // And &#xxx - $link = str_replace('&#', '#', $link); - - return $link; + return append_sid($board_url . $url, $params, true, ''); } /** -- cgit v1.2.1 From f5cbd9ea0e408d5b0e6764ff167b260410acce81 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 20 Nov 2009 21:14:34 +0000 Subject: Implement suggestion as per Bug #53305 - Send time of last item instead of current time in ATOM Feeds. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10281 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index b9d6e1959a..cbc7cb60d1 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -41,6 +41,7 @@ $params = false; // We do not use a template, therefore we simply define the global template variables here $global_vars = $item_vars = array(); +$feed_updated_time = 0; // Generate params array for use in append_sid() to correctly link back to this page if ($forum_id || $topic_id || $mode) @@ -67,19 +68,6 @@ if ($feed === false) // Open Feed $feed->open(); -// Some default assignments -// FEED_IMAGE is not used (atom) -$global_vars = array( - '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'], - 'FEED_UPDATED' => $user->format_date(time(), $feed_date_format, true), - 'FEED_LANG' => $user->lang['USER_LANG'], - 'FEED_AUTHOR' => $config['sitename'], -); - // Iterate through items while ($row = $feed->get_item()) { @@ -102,9 +90,11 @@ while ($row = $feed->get_item()) $title = ($row[$feed->get('title')]) ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : ''); $title = censor_text($title); + $item_time = (int) $row[$feed->get('date')]; + $item_row = array( 'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '', - 'pubdate' => $user->format_date($row[$feed->get('date')], $feed_date_format, true), + 'pubdate' => $user->format_date($item_time, $feed_date_format, true), 'link' => '', 'title' => censor_text($title), 'category' => ($config['feed_item_statistics']) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', @@ -117,8 +107,29 @@ while ($row = $feed->get_item()) $feed->adjust_item($item_row, $row); $item_vars[] = $item_row; + + $feed_updated_time = max($feed_updated_time, $item_time); } +// 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) +$global_vars = array( + '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'], + 'FEED_UPDATED' => $user->format_date($feed_updated_time, $feed_date_format, true), + 'FEED_LANG' => $user->lang['USER_LANG'], + 'FEED_AUTHOR' => $config['sitename'], +); + $feed->close(); // Output page @@ -136,7 +147,7 @@ if ($config['gzip_compress']) if (!defined('DEBUG_EXTRA') || !request_var('explain', 0) || !$auth->acl_get('a_')) { header("Content-Type: application/atom+xml; charset=UTF-8"); - header("Last-Modified: " . gmdate('D, d M Y H:i:s', time()) . ' GMT'); + header("Last-Modified: " . gmdate('D, d M Y H:i:s', $feed_updated_time) . ' GMT'); } else { -- cgit v1.2.1 From 2d83f5be708d650b5c5ffa1ddb0a0d8ffad62467 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 24 Nov 2009 16:00:18 +0000 Subject: Bug #53565 - Use em dash instead of hyphen/minus as separator in ATOM Feeds item statistics. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10285 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index cbc7cb60d1..dfa584956c 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -439,6 +439,11 @@ class phpbb_feed var $separator = "\xE2\x80\xA2"; // • /** + * Separator for the statistics row (Posted by, post date, replies, etc.) + */ + var $separator_stats = "\xE2\x80\x94"; // — + +/** * Constructor. Set standard keys. */ function phpbb_feed($forum_id = 0, $topic_id = 0) @@ -811,7 +816,10 @@ class phpbb_feed $time = ($this->topic_id) ? $row['post_time'] : $row['topic_time']; - $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']; + $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link + . ' ' . $this->separator_stats . ' ' . $user->format_date($time) + . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies'] + . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']; } } } @@ -867,7 +875,8 @@ class phpbb_feed_forums extends phpbb_feed { global $user; - $item_row['statistics'] = sprintf($user->lang['TOTAL_TOPICS_OTHER'], $row['forum_topics']) . ' - ' . sprintf($user->lang['TOTAL_POSTS_OTHER'], $row['forum_posts']); + $item_row['statistics'] = sprintf($user->lang['TOTAL_TOPICS_OTHER'], $row['forum_topics']) + . ' ' . $this->separator_stats . ' ' . sprintf($user->lang['TOTAL_POSTS_OTHER'], $row['forum_posts']); } } } @@ -958,7 +967,10 @@ class phpbb_feed_news extends phpbb_feed $user_link = '' . $row[$this->get('creator')] . ''; - $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']; + $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']; } } } @@ -1056,7 +1068,10 @@ class phpbb_feed_topics extends phpbb_feed $user_link = '' . $row[$this->get('creator')] . ''; - $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']; + $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']; } } } -- cgit v1.2.1 From f864e75174be78eb3ebac2235c8e73738d2065fb Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 24 Nov 2009 17:58:22 +0000 Subject: Nitpicks. r10283, r10285 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10286 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index dfa584956c..5668d297ad 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -443,7 +443,7 @@ class phpbb_feed */ var $separator_stats = "\xE2\x80\x94"; // — -/** + /** * Constructor. Set standard keys. */ function phpbb_feed($forum_id = 0, $topic_id = 0) -- cgit v1.2.1 From 4f0db631d91f050c0baf0f6090026b76532b8072 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 24 Nov 2009 18:26:15 +0000 Subject: Bug #54285 - Correctly exclude subforums from ATOM Feeds. Authorised by: bantu git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10287 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 5668d297ad..a3f194ea33 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -644,7 +644,7 @@ class phpbb_feed } // Determine which forums to fetch - $not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('f1.forum_id', $this->excluded_forums(), true) : ''; + $not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('f2.forum_id', $this->excluded_forums(), true) : ''; // Determine forum childs... $sql = 'SELECT f2.forum_id -- cgit v1.2.1 From 02235a87cdd1f77cc651784fd1d3846fda4183d7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 24 Nov 2009 18:28:46 +0000 Subject: Bug #54275 - Do not link to user profile in ATOM feed entry if post has been made by the guest user. Authorised by: bantu git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10288 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index a3f194ea33..767922676f 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -812,7 +812,7 @@ class phpbb_feed { global $user; - $user_link = '' . $row['username'] . ''; + $user_link = ($row['user_id'] != ANONYMOUS) ? '' . $row['username'] . '' : $row['username']; $time = ($this->topic_id) ? $row['post_time'] : $row['topic_time']; @@ -965,7 +965,7 @@ class phpbb_feed_news extends phpbb_feed { global $user; - $user_link = '' . $row[$this->get('creator')] . ''; + $user_link = ($row[$this->get('author_id')] != ANONYMOUS) ? '' . $row[$this->get('creator')] . '' : $row[$this->get('creator')]; $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link . ' ' . $this->separator_stats . ' ' . $user->format_date($row['topic_time']) @@ -1066,7 +1066,7 @@ class phpbb_feed_topics extends phpbb_feed { global $user; - $user_link = '' . $row[$this->get('creator')] . ''; + $user_link = ($row[$this->get('author_id')] != ANONYMOUS) ? '' . $row[$this->get('creator')] . '' : $row[$this->get('creator')]; $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link . ' ' . $this->separator_stats . ' ' . $user->format_date($row['topic_time']) -- cgit v1.2.1 From 00859fa47c770baee81210d4bcedfe91b889efac Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 24 Nov 2009 18:47:42 +0000 Subject: We've got to use array_merge() as long as we want to be able to write to $global_vars. r10281 didn't change this, btw. ;-) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10289 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 767922676f..425545a0dd 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -119,7 +119,7 @@ if (!$feed_updated_time) // Some default assignments // FEED_IMAGE is not used (atom) -$global_vars = array( +$global_vars = array_merge($global_vars, array( '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, @@ -128,7 +128,7 @@ $global_vars = array( 'FEED_UPDATED' => $user->format_date($feed_updated_time, $feed_date_format, true), 'FEED_LANG' => $user->lang['USER_LANG'], 'FEED_AUTHOR' => $config['sitename'], -); +)); $feed->close(); -- cgit v1.2.1 From 40bc220a415c20205c93f9a8786a3b6ccee952d6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 25 Nov 2009 13:12:32 +0000 Subject: Adjust logic to what the comment says. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10290 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 425545a0dd..5edaf2281f 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -144,12 +144,7 @@ if ($config['gzip_compress']) } // IF debug extra is enabled and admin want to "explain" the page we need to set other headers... -if (!defined('DEBUG_EXTRA') || !request_var('explain', 0) || !$auth->acl_get('a_')) -{ - header("Content-Type: application/atom+xml; charset=UTF-8"); - header("Last-Modified: " . gmdate('D, d M Y H:i:s', $feed_updated_time) . ' GMT'); -} -else +if (defined('DEBUG_EXTRA') && request_var('explain', 0) && $auth->acl_get('a_')) { header('Content-type: text/html; charset=UTF-8'); header('Cache-Control: private, no-cache="set-cookie"'); @@ -168,6 +163,9 @@ else exit_handler(); } +header("Content-Type: application/atom+xml; charset=UTF-8"); +header("Last-Modified: " . gmdate('D, d M Y H:i:s', $feed_updated_time) . ' GMT'); + echo '' . "\n"; echo '' . "\n"; echo '' . "\n\n"; -- cgit v1.2.1 From 1de328e2fe74dfe23b071d55bbbb167b2abc40af Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 1 Dec 2009 12:25:34 +0000 Subject: Fix Bug #54295 - Cleanly handle forum/topic not found in ATOM Feeds. Also related: Bug #54735 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10296 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 5edaf2281f..b7d681c092 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -66,7 +66,10 @@ if ($feed === false) } // Open Feed -$feed->open(); +if ($feed->open() === false) +{ + trigger_error('NO_FEED'); +} // Iterate through items while ($row = $feed->get_item()) @@ -479,34 +482,42 @@ class phpbb_feed { if (!$this->forum_id && !$this->topic_id) { - return; + return false; } else if ($this->forum_id && !$this->topic_id) { - global $db, $user, $global_vars; + global $db, $user; $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $this->forum_id; $result = $db->sql_query($sql); - - $global_vars['FEED_MODE'] = $user->lang['FORUM'] . ': ' . $db->sql_fetchfield('forum_name'); - + $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + + if (empty($row)) + { + return false; + } } else if ($this->topic_id) { - global $db, $user, $global_vars; + global $db, $user; $sql = 'SELECT topic_title FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . $this->topic_id; $result = $db->sql_query($sql); - - $global_vars['FEED_MODE'] = $user->lang['TOPIC'] . ': ' . $db->sql_fetchfield('topic_title'); - + $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + + if (empty($row)) + { + return false; + } } + + return true; } function close() @@ -517,6 +528,8 @@ class phpbb_feed $db->sql_freeresult($this->result); } + + return true; } /** @@ -840,9 +853,7 @@ class phpbb_feed_forums extends phpbb_feed function open() { - global $user, $global_vars; - - $global_vars['FEED_MODE'] = $user->lang['FORUMS']; + return true; } function get_sql() @@ -903,9 +914,7 @@ class phpbb_feed_news extends phpbb_feed function open() { - global $user, $global_vars; - - $global_vars['FEED_MODE'] = $user->lang['FEED_NEWS']; + return true; } function get_sql() @@ -997,9 +1006,7 @@ class phpbb_feed_topics extends phpbb_feed function open() { - global $user, $global_vars; - - $global_vars['FEED_MODE'] = $user->lang['TOPICS']; + return true; } function get_sql() -- cgit v1.2.1 From 57ddd53d592a381ab933b19bca84f78d9405bb8f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 1 Dec 2009 12:54:25 +0000 Subject: #54295 - Thanks Paul.J.Murphy git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10297 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index b7d681c092..2ac08c8517 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -482,7 +482,7 @@ class phpbb_feed { if (!$this->forum_id && !$this->topic_id) { - return false; + return true; } else if ($this->forum_id && !$this->topic_id) { -- cgit v1.2.1 From b5dcc21280bf925a9e420b40e6aabbd374687a68 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 8 Dec 2009 01:23:40 +0000 Subject: Make things easier. #54295, r10296 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10301 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 2ac08c8517..ec1f03092f 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -480,17 +480,13 @@ class phpbb_feed function open() { - if (!$this->forum_id && !$this->topic_id) - { - return true; - } - else if ($this->forum_id && !$this->topic_id) - { - global $db, $user; + global $db, $user; - $sql = 'SELECT forum_name - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $this->forum_id; + if ($this->topic_id) + { + $sql = 'SELECT topic_title + FROM ' . TOPICS_TABLE . ' + WHERE topic_id = ' . $this->topic_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -500,13 +496,11 @@ class phpbb_feed return false; } } - else if ($this->topic_id) + else if ($this->forum_id) { - global $db, $user; - - $sql = 'SELECT topic_title - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $this->topic_id; + $sql = 'SELECT forum_name + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $this->forum_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); -- cgit v1.2.1 From 0fbea43f4b6456c87694c06a4a075f0ca006f395 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 8 Dec 2009 01:53:26 +0000 Subject: Fix Bug #55005 - Correctly take post time instead of topic time for the overall forum feed statistics row. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10302 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index ec1f03092f..79848437c5 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -819,10 +819,8 @@ class phpbb_feed $user_link = ($row['user_id'] != ANONYMOUS) ? '' . $row['username'] . '' : $row['username']; - $time = ($this->topic_id) ? $row['post_time'] : $row['topic_time']; - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link - . ' ' . $this->separator_stats . ' ' . $user->format_date($time) + . ' ' . $this->separator_stats . ' ' . $user->format_date($row['post_time']) . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies'] . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']; } -- cgit v1.2.1 From ccc774412e69ceb73f8cbc82cb842860389cb7de Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 8 Dec 2009 03:53:41 +0000 Subject: Optimize SQL queries 'a little'. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10304 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 79848437c5..ef1bfd48d1 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -722,7 +722,7 @@ class phpbb_feed '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, ' . - 'u.username, u.user_id, u.user_email, u.user_colour', + 'u.username, u.user_id', 'FROM' => array( POSTS_TABLE => 'p', TOPICS_TABLE => 't', @@ -933,20 +933,17 @@ class phpbb_feed_news extends phpbb_feed // Build SQL Query $this->sql = array( - '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, + 'SELECT' => 'f.forum_id, f.forum_name, f.forum_topics, f.forum_posts, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, - p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, - u.username, u.user_id, u.user_email, u.user_colour', + p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', 'FROM' => array( TOPICS_TABLE => 't', FORUMS_TABLE => 'f', POSTS_TABLE => 'p', - USERS_TABLE => 'u', ), '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 - AND t.topic_poster = u.user_id AND t.topic_moved_id = 0', 'ORDER_BY' => 't.topic_time DESC', ); @@ -1033,20 +1030,17 @@ class phpbb_feed_topics extends phpbb_feed } $this->sql = array( - '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, + 'SELECT' => 'f.forum_id, f.forum_name, f.forum_topics, f.forum_posts, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, - p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, - u.username, u.user_id, u.user_email, u.user_colour', + p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', 'FROM' => array( TOPICS_TABLE => 't', FORUMS_TABLE => 'f', POSTS_TABLE => 'p', - 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', + AND t.topic_id = p.topic_id', 'ORDER_BY' => 't.topic_last_post_time DESC', ); -- cgit v1.2.1 From 25545c06b25644a093f442b42bd97bab627aa3e5 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 9 Dec 2009 21:33:25 +0000 Subject: Let's add some more checks. #54295 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10308 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index ef1bfd48d1..d658e2993b 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -66,10 +66,7 @@ if ($feed === false) } // Open Feed -if ($feed->open() === false) -{ - trigger_error('NO_FEED'); -} +$feed->open(); // Iterate through items while ($row = $feed->get_item()) @@ -480,25 +477,33 @@ class phpbb_feed function open() { - global $db, $user; + global $auth, $db, $user; if ($this->topic_id) { - $sql = 'SELECT topic_title + // 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)) { - return false; + trigger_error('NO_TOPIC'); + } + + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); } } else if ($this->forum_id) { - $sql = 'SELECT forum_name + // Forum feed + $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $this->forum_id; $result = $db->sql_query($sql); @@ -507,7 +512,12 @@ class phpbb_feed if (empty($row)) { - return false; + trigger_error('NO_FORUM'); + } + + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); } } -- cgit v1.2.1 From 56cc34602b7bae811165ce7697e200af47b0e6f8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 10 Dec 2009 01:12:54 +0000 Subject: Correctly use RFC 3339 date in ATOM feeds. Bug #55005 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10312 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index d658e2993b..2670c022cb 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -35,15 +35,12 @@ $forum_id = request_var('f', 0); $topic_id = request_var('t', 0); $mode = request_var('mode', ''); -// Feed date format for PHP > 5 and PHP4 -$feed_date_format = (PHP_VERSION >= 5) ? 'c' : "Y-m-d\TH:i:sO"; -$params = false; - // We do not use a template, therefore we simply define the global template variables here $global_vars = $item_vars = array(); $feed_updated_time = 0; // Generate params array for use in append_sid() to correctly link back to this page +$params = false; if ($forum_id || $topic_id || $mode) { $params = array( @@ -94,7 +91,7 @@ while ($row = $feed->get_item()) $item_row = array( 'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '', - 'pubdate' => $user->format_date($item_time, $feed_date_format, true), + 'pubdate' => feed_format_date($item_time), 'link' => '', 'title' => censor_text($title), 'category' => ($config['feed_item_statistics']) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', @@ -125,7 +122,7 @@ $global_vars = array_merge($global_vars, array( 'FEED_LINK' => $board_url . '/index.' . $phpEx, 'FEED_TITLE' => $config['sitename'], 'FEED_SUBTITLE' => $config['site_desc'], - 'FEED_UPDATED' => $user->format_date($feed_updated_time, $feed_date_format, true), + 'FEED_UPDATED' => feed_format_date($feed_updated_time), 'FEED_LANG' => $user->lang['USER_LANG'], 'FEED_AUTHOR' => $config['sitename'], )); @@ -224,6 +221,33 @@ function feed_append_sid($url, $params) return append_sid($board_url . $url, $params, true, ''); } +/** +* 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; +} + /** * Generate text content **/ -- cgit v1.2.1 From 3f35de4c63b2420b3a6b32113765fd217e91128a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 10 Dec 2009 03:05:33 +0000 Subject: Database input, already specialchared. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10313 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 2670c022cb..56c2cab8ae 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -95,7 +95,7 @@ while ($row = $feed->get_item()) 'link' => '', 'title' => censor_text($title), 'category' => ($config['feed_item_statistics']) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', - 'category_name' => ($config['feed_item_statistics']) ? utf8_htmlspecialchars($row['forum_name']) : '', + 'category_name' => ($config['feed_item_statistics']) ? $row['forum_name'] : '', 'description' => censor_text(feed_generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)), 'statistics' => '', ); -- cgit v1.2.1 From b63cad6b89a38888a4646fcea9f6447c6d5ba1f0 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 10 Dec 2009 16:59:25 +0000 Subject: Remove some unnecessary code and join two queries. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10314 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 56c2cab8ae..617195b486 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -589,50 +589,38 @@ class phpbb_feed global $auth, $db, $config, $phpbb_root_path, $phpEx, $user; // Which forums should not be searched ? - $exclude_forums = array(); + $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) : ''; $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' - WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0'); + WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0') . " + $sql_or"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $exclude_forums[] = (int) $row['forum_id']; + $this->excluded_forums_ary[(int) $row['forum_id']] = (int) $row['forum_id']; } $db->sql_freeresult($result); - // Exclude forums the user is not able to read - $this->excluded_forums_ary = array_keys($auth->acl_getf('!f_read', true)); - $this->excluded_forums_ary = (sizeof($exclude_forums)) ? array_merge($exclude_forums, $this->excluded_forums_ary) : $this->excluded_forums_ary; - - $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'] . ')' : ''; - - $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, fa.user_id + // Exclude passworded forums + $sql = 'SELECT f.forum_id, fa.user_id FROM ' . FORUMS_TABLE . ' f - LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id - AND fa.session_id = '" . $db->sql_escape($user->session_id) . "') - $not_in_fid - ORDER BY f.left_id"; + 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 <> ''"; $result = $db->sql_query($sql); - $right_id = 0; while ($row = $db->sql_fetchrow($result)) { - // Exclude passworded forum completely - if ($row['forum_password'] && $row['user_id'] != $user->data['user_id']) - { - $this->excluded_forums_ary[] = (int) $row['forum_id']; - continue; - } - - if ($row['right_id'] > $right_id) - { - $right_id = (int) $row['right_id']; - } - else if ($row['right_id'] < $right_id) + if ($row['user_id'] != $user->data['user_id']) { - continue; + $this->excluded_forums_ary[(int) $row['forum_id']] = (int) $row['forum_id']; } } $db->sql_freeresult($result); -- cgit v1.2.1 From 9189b8203ab2123d6d800676527d7aacda679518 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 11 Dec 2009 13:42:38 +0000 Subject: Add another layer of abstraction. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10315 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 365 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 191 insertions(+), 174 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 617195b486..83875f5843 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -399,26 +399,16 @@ class phpbb_feed_factory } /** -* Base/default Feed class if no mode is specified. -* This can be the overall site feed or a forum/topic feed. +* Base class with some generic functions and settings. +* * @package phpBB3 */ -class phpbb_feed +class phpbb_feed_base { - /** - * Forum id specified for forum feed. - */ - var $forum_id = 0; - - /** - * Topic id specified for topic feed. - */ - var $topic_id = 0; - /** * SQL Query to be executed to get feed items */ - var $sql; + var $sql = array(); /** * Keys specified for retrieval of title, content, etc. @@ -431,9 +421,9 @@ class phpbb_feed var $excluded_forums_ary = NULL; /** - * Number of items to fetch + * Number of items to fetch. Usually overwritten by $config['feed_something'] */ - var $num_items; + var $num_items = 15; /** * boolean to determine if items array is filled or not @@ -466,98 +456,38 @@ class phpbb_feed var $separator_stats = "\xE2\x80\x94"; // — /** - * Constructor. Set standard keys. + * Constructor */ - function phpbb_feed($forum_id = 0, $topic_id = 0) + function phpbb_feed_base() { - global $config; - - $this->forum_id = $forum_id; - $this->topic_id = $topic_id; - - $this->sql = array(); - - // Set some values for pagination - $this->num_items = (int) $config['feed_limit']; $this->set_keys(); } + /** + * Set keys. + */ function set_keys() { - // Set keys for items... - $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'); } + /** + * Open feed + */ 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'); - } - - if (!$auth->acl_get('f_read', $this->forum_id)) - { - trigger_error('SORRY_AUTH_READ'); - } - } - 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'); - } - - if (!$auth->acl_get('f_read', $this->forum_id)) - { - trigger_error('SORRY_AUTH_READ'); - } - } - - return true; } + /** + * Close feed + */ function close() { + global $db; + if (!empty($this->result)) { - global $db; - $db->sql_freeresult($this->result); } - - return true; } /** @@ -628,6 +558,175 @@ class phpbb_feed return $this->excluded_forums_ary; } + function get_item() + { + global $db, $cache; + + // Disable cache if it is not a guest or a bot but a registered user + if ($this->cache_time) + { + global $user; + + // We check this here because we call get_item() quite often + if (!empty($user) && $user->data['is_registered']) + { + $this->cache_time = 0; + } + } + + 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'); + } + + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } + } + 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'); + } + + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } + } + } + /** * Get SQL query for fetching items */ @@ -761,73 +860,6 @@ class phpbb_feed return true; } - function get_item() - { - global $db, $cache; - - // Disable cache if it is not a guest or a bot but a registered user - if ($this->cache_time) - { - global $user; - - // We check this here because we call get_item() quite often - if (!empty($user) && $user->data['is_registered']) - { - $this->cache_time = 0; - } - } - - 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; - } - } - function adjust_item(&$item_row, &$row) { global $phpEx, $config; @@ -849,7 +881,7 @@ class phpbb_feed } } -class phpbb_feed_forums extends phpbb_feed +class phpbb_feed_forums extends phpbb_feed_base { function set_keys() { @@ -865,11 +897,6 @@ class phpbb_feed_forums extends phpbb_feed $this->num_items = (int) $config['feed_overall_forums_limit']; } - function open() - { - return true; - } - function get_sql() { global $db; @@ -904,7 +931,7 @@ class phpbb_feed_forums extends phpbb_feed } } -class phpbb_feed_news extends phpbb_feed +class phpbb_feed_news extends phpbb_feed_base { function set_keys() { @@ -926,11 +953,6 @@ class phpbb_feed_news extends phpbb_feed $this->num_items = (int) $config['feed_overall_forums_limit']; } - function open() - { - return true; - } - function get_sql() { global $db, $config; @@ -993,7 +1015,7 @@ class phpbb_feed_news extends phpbb_feed } } -class phpbb_feed_topics extends phpbb_feed +class phpbb_feed_topics extends phpbb_feed_base { function set_keys() { @@ -1015,11 +1037,6 @@ class phpbb_feed_topics extends phpbb_feed $this->num_items = (int) $config['feed_overall_topics_limit']; } - function open() - { - return true; - } - function get_sql() { global $db, $config; -- cgit v1.2.1 From c207c530b770385f1b8f5003d38ebe87e95f1dba Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 11 Dec 2009 14:46:06 +0000 Subject: Bring back caching. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10316 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 83875f5843..e644afe642 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -443,7 +443,7 @@ class phpbb_feed_base /** * Default cache time of entries in seconds */ - var $cache_time = 0; + var $cache_time = 90; /** * Separator for title elements to separate items (for example forum / topic) @@ -460,6 +460,14 @@ class phpbb_feed_base */ function phpbb_feed_base() { + 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; + } + $this->set_keys(); } @@ -562,18 +570,6 @@ class phpbb_feed_base { global $db, $cache; - // Disable cache if it is not a guest or a bot but a registered user - if ($this->cache_time) - { - global $user; - - // We check this here because we call get_item() quite often - if (!empty($user) && $user->data['is_registered']) - { - $this->cache_time = 0; - } - } - if (!$this->cache_time) { if (empty($this->result)) @@ -699,11 +695,6 @@ class phpbb_feed extends phpbb_feed_base { trigger_error('NO_TOPIC'); } - - if (!$auth->acl_get('f_read', $this->forum_id)) - { - trigger_error('SORRY_AUTH_READ'); - } } else if ($this->forum_id) { @@ -719,11 +710,18 @@ class phpbb_feed extends phpbb_feed_base { trigger_error('NO_FORUM'); } + } + // Topic/Forum feed + if ($this->topic_id || $this->forum_id) + { if (!$auth->acl_get('f_read', $this->forum_id)) { trigger_error('SORRY_AUTH_READ'); } + + // Disable caching + $this->cache_time = 0; } } @@ -933,6 +931,11 @@ class phpbb_feed_forums extends phpbb_feed_base class phpbb_feed_news extends phpbb_feed_base { + /** + * Longer cache time for the news feed + */ + var $cache_time = 180; + function set_keys() { global $config; -- cgit v1.2.1 From afa8dcb42a5a264d1f6e1f7a3f4a5889c3b5aa66 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 11 Dec 2009 16:18:56 +0000 Subject: Bug #54345 - Do not deliver topics from unreadable forums in the news feed. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10317 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index e644afe642..98e8e61349 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -958,7 +958,7 @@ class phpbb_feed_news extends phpbb_feed_base function get_sql() { - global $db, $config; + global $auth, $config, $db; // Get news forums... $sql = 'SELECT forum_id @@ -969,6 +969,12 @@ class phpbb_feed_news extends phpbb_feed_base $in_fid_ary = array(); while ($row = $db->sql_fetchrow($result)) { + // Make sure we can read this forum + if (!$auth->acl_get('f_read', (int) $row['forum_id'])) + { + continue; + } + $in_fid_ary[] = (int) $row['forum_id']; } $db->sql_freeresult($result); -- cgit v1.2.1 From d3cd9ce01ef27c50226b61ae1e0f9ff2e8c2573d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 11 Dec 2009 16:41:37 +0000 Subject: #54345 - Passworded forums git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10318 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 98e8e61349..26bfbb0d51 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -545,6 +545,16 @@ class phpbb_feed_base } $db->sql_freeresult($result); + // 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; + // Exclude passworded forums $sql = 'SELECT f.forum_id, fa.user_id FROM ' . FORUMS_TABLE . ' f @@ -554,16 +564,19 @@ class phpbb_feed_base WHERE f.forum_password <> ''"; $result = $db->sql_query($sql); + $forum_ids = array(); while ($row = $db->sql_fetchrow($result)) { + $forum_id = (int) $row['forum_id']; + if ($row['user_id'] != $user->data['user_id']) { - $this->excluded_forums_ary[(int) $row['forum_id']] = (int) $row['forum_id']; + $forum_ids[$forum_id] = $forum_id; } } $db->sql_freeresult($result); - return $this->excluded_forums_ary; + return $forum_ids; } function get_item() @@ -960,6 +973,9 @@ class phpbb_feed_news extends phpbb_feed_base { global $auth, $config, $db; + // Get passworded forums + $forum_ids_passworded = $this->get_passworded_forums(); + // Get news forums... $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' @@ -969,8 +985,16 @@ class phpbb_feed_news extends phpbb_feed_base $in_fid_ary = array(); while ($row = $db->sql_fetchrow($result)) { + $forum_id = (int) $row['forum_id']; + + // Passworded forum + if (isset($forum_ids_passworded[$forum_id])) + { + continue; + } + // Make sure we can read this forum - if (!$auth->acl_get('f_read', (int) $row['forum_id'])) + if (!$auth->acl_get('f_read', $forum_id)) { continue; } -- cgit v1.2.1 From 07c990302c9bdcd98dfbc8d5db2cae764cc7aa6e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 12 Dec 2009 21:27:05 +0000 Subject: We don't need this anymore. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10327 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 26bfbb0d51..960ada589e 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -816,14 +816,6 @@ class phpbb_feed extends phpbb_feed_base // Fetch last posts from specified topic... else if ($this->topic_id) { - // First of all, determine the forum... - $sql = 'SELECT forum_id - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $this->topic_id; - $result = $db->sql_query_limit($sql, 1); - $this->forum_id = (int) $db->sql_fetchfield('forum_id'); - $db->sql_freeresult($result); - // non-global announcement if ($this->forum_id && in_array($this->forum_id, $this->excluded_forums())) { -- cgit v1.2.1 From b6f9a1a6e881241fa16b24a3a7bd30017fb52d0e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 13 Dec 2009 13:02:37 +0000 Subject: Topic/Forum Feed: Also throw NO_FEED if forum has been excluded from feeds. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10328 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 63 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 960ada589e..13eb0698bc 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -693,41 +693,50 @@ class phpbb_feed extends phpbb_feed_base { global $auth, $db, $user; - if ($this->topic_id) + // Topic/Forum feed + if ($this->topic_id || $this->forum_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 ($this->topic_id) + { + // Topic feed + $sql = 'SELECT t.forum_id, f.forum_options + FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f + WHERE t.topic_id = ' . $this->topic_id . ' + AND t.forum_id = f.forum_id'; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - if (empty($row)) + if (empty($row)) + { + trigger_error('NO_TOPIC'); + } + + $this->forum_id = (int) $row['forum_id']; + } + else { - trigger_error('NO_TOPIC'); + // Forum feed + $sql = 'SELECT forum_options + 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'); + } } - } - 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)) + // Make sure forum is not excluded from feed + if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options'])) { - trigger_error('NO_FORUM'); + trigger_error('NO_FEED'); } - } - // Topic/Forum feed - if ($this->topic_id || $this->forum_id) - { + // Make sure we can read this forum if (!$auth->acl_get('f_read', $this->forum_id)) { trigger_error('SORRY_AUTH_READ'); -- cgit v1.2.1 From 1f2f658920de4b8593629165a57ca9e6670f085c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 13 Dec 2009 23:58:51 +0000 Subject: title already censored lower down. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10336 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 13eb0698bc..20f0d7e7b0 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -85,7 +85,6 @@ while ($row = $feed->get_item()) } $title = ($row[$feed->get('title')]) ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : ''); - $title = censor_text($title); $item_time = (int) $row[$feed->get('date')]; -- cgit v1.2.1 From 2ac753b7258504d53a158a89ea36dbff6df0ca3e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 14 Dec 2009 12:59:07 +0000 Subject: "0" is a valid title. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10338 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 20f0d7e7b0..a7c6f831a3 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -84,7 +84,7 @@ while ($row = $feed->get_item()) $options = $row[$feed->get('options')]; } - $title = ($row[$feed->get('title')]) ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : ''); + $title = (isset($row[$feed->get('title')]) && $row[$feed->get('title')] !== '') ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : ''); $item_time = (int) $row[$feed->get('date')]; -- cgit v1.2.1 From d5c16e4c8f5fe0859e127d979a1988c96e6bba8a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 16 Dec 2009 18:13:41 +0000 Subject: I've got to take this back. Revert r10316 partly. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10343 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index a7c6f831a3..ffaeaa5bf1 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -442,7 +442,7 @@ class phpbb_feed_base /** * Default cache time of entries in seconds */ - var $cache_time = 90; + var $cache_time = 0; // 0 important /** * Separator for title elements to separate items (for example forum / topic) @@ -944,11 +944,6 @@ class phpbb_feed_forums extends phpbb_feed_base class phpbb_feed_news extends phpbb_feed_base { - /** - * Longer cache time for the news feed - */ - var $cache_time = 180; - function set_keys() { global $config; -- cgit v1.2.1 From 6cc60ee8c23fdd1f9b9ff9df81ed0a7f05ce1d2f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 17 Dec 2009 00:12:51 +0000 Subject: Improve 'All forums' feed: Remove limit, display all forums. Join all queries to one. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10344 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index ffaeaa5bf1..2036d0ea00 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -892,35 +892,48 @@ class phpbb_feed extends phpbb_feed_base } } +/** +* 'All Forums' feed +* +* This will give you a list of all postable forums where feeds are enabled +* including forum description, topic stats and post stats +* +* @package phpBB3 +*/ class phpbb_feed_forums extends phpbb_feed_base { + var $num_items = 0; + 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'); - - $this->num_items = (int) $config['feed_overall_forums_limit']; } function get_sql() { - global $db; + global $auth, $db; - $not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('f.forum_id', $this->excluded_forums(), true) : ''; + $f_read_ids = array_keys($auth->acl_getf('f_read')); + if (empty($f_read_ids)) + { + return false; + } // Build SQL Query $this->sql = array( - 'SELECT' => 'f.*', + 'SELECT' => 'f.forum_id, f.left_id, f.forum_name, f.forum_last_post_time, + f.forum_desc, f.forum_desc_bitfield, f.forum_desc_uid, f.forum_desc_options, + f.forum_topics, f.forum_posts', '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', + AND ' . $db->sql_bit_and('f.forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' + AND ' . $db->sql_in_set('f.forum_id', $f_read_ids), + 'ORDER_BY' => 'f.left_id ASC', ); return true; -- cgit v1.2.1 From 69c07b83302f477d6209812a612e2da6a6bf3101 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 17 Dec 2009 00:39:41 +0000 Subject: News feed: Correctly handle global announcements. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10345 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 2036d0ea00..0393a55037 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -93,8 +93,8 @@ while ($row = $feed->get_item()) 'pubdate' => feed_format_date($item_time), 'link' => '', 'title' => censor_text($title), - 'category' => ($config['feed_item_statistics']) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', - 'category_name' => ($config['feed_item_statistics']) ? $row['forum_name'] : '', + 'category' => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', + 'category_name' => ($config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '', 'description' => censor_text(feed_generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)), 'statistics' => '', ); @@ -188,7 +188,7 @@ foreach ($item_vars as $row) echo '' . "\n"; echo '<![CDATA[' . $row['title'] . ']]>' . "\n\n"; - if (!empty($row['category'])) + if (!empty($row['category']) && isset($row['category_name'])) { echo '' . "\n"; } @@ -955,6 +955,14 @@ class phpbb_feed_forums extends phpbb_feed_base } } +/** +* News feed +* +* This will give you {$this->num_items} first posts +* of all topics in the selected news forums. +* +* @package phpBB3 +*/ class phpbb_feed_news extends phpbb_feed_base { function set_keys() @@ -1016,20 +1024,24 @@ class phpbb_feed_news extends phpbb_feed_base return false; } - // Build SQL Query $this->sql = array( - 'SELECT' => 'f.forum_id, f.forum_name, f.forum_topics, f.forum_posts, + 'SELECT' => 'f.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', '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 - AND t.topic_moved_id = 0', + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'f.forum_id = t.forum_id', + ), + ), + 'WHERE' => 'p.post_id = t.topic_first_post_id + AND t.topic_moved_id = 0 + AND (' . $db->sql_in_set('t.forum_id', $in_fid_ary) . ' + OR t.topic_type = ' . POST_GLOBAL . ')', 'ORDER_BY' => 't.topic_time DESC', ); -- cgit v1.2.1 From 4e4915252971aa3270044ce793d9e5af2417df67 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 17 Dec 2009 00:41:30 +0000 Subject: Use correct limit config parameter in the News feed. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10346 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 0393a55037..5043c89572 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -982,7 +982,7 @@ class phpbb_feed_news extends phpbb_feed_base $this->set('enable_smilies', 'enable_smilies'); $this->set('enable_magic_url', 'enable_magic_url'); - $this->num_items = (int) $config['feed_overall_forums_limit']; + $this->num_items = (int) $config['feed_limit']; } function get_sql() -- cgit v1.2.1 From 437c66e8c818becb7a04c5b224f6c060aa55459e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 17 Dec 2009 00:55:55 +0000 Subject: #54275 - Let's use a method for that. Also return ->lang['GUEST'] instead of ['username']. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10347 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 5043c89572..a5ffbf3412 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -632,6 +632,22 @@ class phpbb_feed_base return (!$row) ? false : $row; } } + + function user_viewprofile($row) + { + global $phpEx, $user; + + $author_id = (int) $row[$this->get('author_id')]; + + if ($author_id == ANONYMOUS) + { + // Since we cannot link to a profile, we just return GUEST + // instead of $row['username'] + return $user->lang['GUEST']; + } + + return '' . $row[$this->get('creator')] . ''; + } } /** @@ -882,9 +898,7 @@ class phpbb_feed extends phpbb_feed_base { global $user; - $user_link = ($row['user_id'] != ANONYMOUS) ? '' . $row['username'] . '' : $row['username']; - - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link + $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) . ' ' . $this->separator_stats . ' ' . $user->format_date($row['post_time']) . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies'] . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']; @@ -1058,9 +1072,7 @@ class phpbb_feed_news extends phpbb_feed_base { global $user; - $user_link = ($row[$this->get('author_id')] != ANONYMOUS) ? '' . $row[$this->get('creator')] . '' : $row[$this->get('creator')]; - - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link + $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) . ' ' . $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']; @@ -1149,9 +1161,7 @@ class phpbb_feed_topics extends phpbb_feed_base { global $user; - $user_link = ($row[$this->get('author_id')] != ANONYMOUS) ? '' . $row[$this->get('creator')] . '' : $row[$this->get('creator')]; - - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $user_link + $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) . ' ' . $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']; -- cgit v1.2.1 From 9d436a33f655c2ddbbed96b9cf6ac7f39c884390 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 17 Dec 2009 01:06:01 +0000 Subject: Some corrections for r10347 and r10345. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10348 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index a5ffbf3412..8b241176b8 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -188,7 +188,7 @@ foreach ($item_vars as $row) echo '' . "\n"; echo '<![CDATA[' . $row['title'] . ']]>' . "\n\n"; - if (!empty($row['category']) && isset($row['category_name'])) + if (!empty($row['category']) && isset($row['category_name']) && $row['category_name'] !== '') { echo '' . "\n"; } @@ -1161,7 +1161,7 @@ class phpbb_feed_topics extends phpbb_feed_base { global $user; - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) + $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) . ' ' . $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']; -- cgit v1.2.1 From 2eb337ba41a4ecb264f03a07c92f0fba9b5a57c6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 19 Dec 2009 23:47:35 +0000 Subject: Topic has to be approved. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10349 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 8b241176b8..c02f7ee855 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -1054,6 +1054,7 @@ class phpbb_feed_news extends phpbb_feed_base ), 'WHERE' => 'p.post_id = t.topic_first_post_id AND t.topic_moved_id = 0 + AND t.topic_approved = 1 AND (' . $db->sql_in_set('t.forum_id', $in_fid_ary) . ' OR t.topic_type = ' . POST_GLOBAL . ')', 'ORDER_BY' => 't.topic_time DESC', -- cgit v1.2.1 From 7d406a36cdb3b66cbc2d3c4c4ebdcf10564917d7 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 00:05:47 +0000 Subject: All topics feed now returns newest board topics. Reduce required queries and complexity. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10350 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 57 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index c02f7ee855..eae4207cd0 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -1081,6 +1081,14 @@ class phpbb_feed_news extends phpbb_feed_base } } +/** +* 'All Topics' feed +* +* This will give you the last {$this->num_items} created topics +* including the first post. +* +* @package phpBB3 +*/ class phpbb_feed_topics extends phpbb_feed_base { function set_keys() @@ -1107,46 +1115,38 @@ class phpbb_feed_topics extends phpbb_feed_base { 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)) + $excluded_forum_ids = $this->excluded_forums(); + if (empty($excluded_forum_ids)) { - $post_ids[] = (int) $row['topic_first_post_id']; + // Whole board + $sql_where_more = ''; } - $db->sql_freeresult($result); - - if (!sizeof($post_ids)) + else { - return false; + // Not excluded forums or global topic + $sql_where_more = 'AND (' . $db->sql_in_set('t.forum_id', $excluded_forum_ids, true) . ' + OR t.topic_type = ' . POST_GLOBAL . ')'; } $this->sql = array( - 'SELECT' => 'f.forum_id, f.forum_name, f.forum_topics, f.forum_posts, + 'SELECT' => 'f.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', '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 - AND t.topic_id = p.topic_id', - 'ORDER_BY' => 't.topic_last_post_time DESC', + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'f.forum_id = t.forum_id', + ), + ), + 'WHERE' => "p.post_id = t.topic_first_post_id + AND t.topic_moved_id = 0 + AND t.topic_approved = 1 + $sql_where_more", + 'ORDER_BY' => 't.topic_time DESC', ); return true; @@ -1156,6 +1156,7 @@ class phpbb_feed_topics extends phpbb_feed_base { global $phpEx, $config; + $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; $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']) -- cgit v1.2.1 From 28c33de6d9bb72e23b653656594627f3f9529712 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 13:18:04 +0000 Subject: Provide some more generic methods. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10351 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index eae4207cd0..014d768fc4 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -550,6 +550,48 @@ class phpbb_feed_base return $this->excluded_forums_ary; } + function get_readable_forums() + { + global $auth; + + return array_keys($auth->acl_getf('f_read')); + } + + function get_excluded_forums() + { + global $db, $cache; + static $forum_ids; + + $cache_name = 'feed_excluded_forum_ids'; + $cache_ttl = 300; + + if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false) + { + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0'); + $result = $db->sql_query($sql); + + $forum_ids = array(); + while ($forum_id = (int) $db->sql_fetchfield('forum_id')) + { + $forum_ids[$forum_id] = $forum_id; + } + $db->sql_freeresult($result); + + $cache->put('_' . $cache_name, $forum_ids, $cache_ttl); + } + + return $forum_ids; + } + + function is_excluded_forum($forum_id) + { + $forum_ids = $this->get_excluded_forums(); + + return isset($forum_ids[$forum_id]) ? true : false; + } + function get_passworded_forums() { global $db, $user; -- cgit v1.2.1 From 7ac774432e3cc22051d8e5c448690979e9e55c0f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 13:52:56 +0000 Subject: Improve news feed. It basically only runs two queries now for the main content. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10352 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 014d768fc4..04b6b09af4 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -1041,41 +1041,68 @@ class phpbb_feed_news extends phpbb_feed_base $this->num_items = (int) $config['feed_limit']; } + function get_news_forums() + { + global $db, $cache; + static $forum_ids; + + $cache_name = 'feed_news_forum_ids'; + $cache_ttl = 300; + + if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false) + { + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0'); + $result = $db->sql_query($sql); + + $forum_ids = array(); + while ($forum_id = (int) $db->sql_fetchfield('forum_id')) + { + $forum_ids[$forum_id] = $forum_id; + } + $db->sql_freeresult($result); + + $cache->put('_' . $cache_name, $forum_ids, $cache_ttl); + } + + return $forum_ids; + } + function get_sql() { global $auth, $config, $db; + // Determine forum ids + $forum_ids_news = $this->get_news_forums(); + + // Very very unlikely, check anyway + if (empty($forum_ids_news)) + { + return false; + } + // Get passworded forums $forum_ids_passworded = $this->get_passworded_forums(); - // 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); - + // Check forum_ids $in_fid_ary = array(); - while ($row = $db->sql_fetchrow($result)) + foreach ($forum_ids_news as $forum_id) { - $forum_id = (int) $row['forum_id']; - - // Passworded forum if (isset($forum_ids_passworded[$forum_id])) { continue; } - // Make sure we can read this forum if (!$auth->acl_get('f_read', $forum_id)) { continue; } - $in_fid_ary[] = (int) $row['forum_id']; + $in_fid_ary[] = $forum_id; } - $db->sql_freeresult($result); - if (!sizeof($in_fid_ary)) + if (empty($in_fid_ary)) { return false; } -- cgit v1.2.1 From d64516057fef276a9ba435bd20e7223015376a95 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 14:22:51 +0000 Subject: Also improve topics feed. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10353 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 04b6b09af4..63c3fe083f 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -1184,17 +1184,16 @@ class phpbb_feed_topics extends phpbb_feed_base { global $db, $config; - $excluded_forum_ids = $this->excluded_forums(); - if (empty($excluded_forum_ids)) + $forum_ids_read = $this->get_readable_forums(); + if (empty($forum_ids_read)) { - // Whole board - $sql_where_more = ''; + return false; } - else + + $in_fid_ary = array_diff($forum_ids_read, $this->get_excluded_forums(), $this->get_passworded_forums()); + if (empty($in_fid_ary)) { - // Not excluded forums or global topic - $sql_where_more = 'AND (' . $db->sql_in_set('t.forum_id', $excluded_forum_ids, true) . ' - OR t.topic_type = ' . POST_GLOBAL . ')'; + return false; } $this->sql = array( @@ -1211,10 +1210,11 @@ class phpbb_feed_topics extends phpbb_feed_base 'ON' => 'f.forum_id = t.forum_id', ), ), - 'WHERE' => "p.post_id = t.topic_first_post_id + 'WHERE' => 'p.post_id = t.topic_first_post_id AND t.topic_moved_id = 0 AND t.topic_approved = 1 - $sql_where_more", + AND (' . $db->sql_in_set('t.forum_id', $in_fid_ary) . ' + OR t.topic_type = ' . POST_GLOBAL . ')', 'ORDER_BY' => 't.topic_time DESC', ); -- cgit v1.2.1 From 183045072f04f907aebc4e932a847123ac8a9019 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 14:31:37 +0000 Subject: Cache forever, destroy on change. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10354 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 63c3fe083f..ea7ad243d8 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -562,8 +562,8 @@ class phpbb_feed_base global $db, $cache; static $forum_ids; + // Matches acp/acp_board.php $cache_name = 'feed_excluded_forum_ids'; - $cache_ttl = 300; if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false) { @@ -579,7 +579,7 @@ class phpbb_feed_base } $db->sql_freeresult($result); - $cache->put('_' . $cache_name, $forum_ids, $cache_ttl); + $cache->put('_' . $cache_name, $forum_ids); } return $forum_ids; @@ -1046,8 +1046,8 @@ class phpbb_feed_news extends phpbb_feed_base global $db, $cache; static $forum_ids; + // Matches acp/acp_board.php $cache_name = 'feed_news_forum_ids'; - $cache_ttl = 300; if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false) { @@ -1063,7 +1063,7 @@ class phpbb_feed_news extends phpbb_feed_base } $db->sql_freeresult($result); - $cache->put('_' . $cache_name, $forum_ids, $cache_ttl); + $cache->put('_' . $cache_name, $forum_ids); } return $forum_ids; -- cgit v1.2.1 From 2f0d9f7d3d3d85f825b4e117d59b89a820e82fe6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 15:09:27 +0000 Subject: Abstract class for topic based feeds. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10355 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 101 ++++++++++++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 55 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index ea7ad243d8..2474db0e13 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -692,6 +692,47 @@ class phpbb_feed_base } } +/** +* Abstract class for topic based feeds +* +* @package phpBB3 +*/ +class phpbb_feed_topic_base extends phpbb_feed_base +{ + function set_keys() + { + $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('date', 'topic_time'); + $this->set('text', 'post_text'); + + $this->set('bitfield', 'bbcode_bitfield'); + $this->set('bbcode_uid','bbcode_uid'); + + $this->set('enable_bbcode', 'enable_bbcode'); + $this->set('enable_smilies', 'enable_smilies'); + $this->set('enable_magic_url', 'enable_magic_url'); + } + + function adjust_item(&$item_row, &$row) + { + global $phpEx, $config, $user; + + $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']) + { + $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) + . ' ' . $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']; + } + } +} + /** * Default feed class if no mode is specified. * This can be the overall site feed or a forum/topic feed. @@ -1019,24 +1060,13 @@ class phpbb_feed_forums extends phpbb_feed_base * * @package phpBB3 */ -class phpbb_feed_news extends phpbb_feed_base +class phpbb_feed_news extends phpbb_feed_topic_base { 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'); + parent::set_keys(); $this->num_items = (int) $config['feed_limit']; } @@ -1131,23 +1161,6 @@ class phpbb_feed_news extends phpbb_feed_base 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; - - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) - . ' ' . $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']; - } - } } /** @@ -1158,24 +1171,13 @@ class phpbb_feed_news extends phpbb_feed_base * * @package phpBB3 */ -class phpbb_feed_topics extends phpbb_feed_base +class phpbb_feed_topics extends phpbb_feed_topic_base { 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'); + parent::set_keys(); $this->num_items = (int) $config['feed_overall_topics_limit']; } @@ -1223,20 +1225,9 @@ class phpbb_feed_topics extends phpbb_feed_base function adjust_item(&$item_row, &$row) { - global $phpEx, $config; + parent::adjust_item($item_row, $row); $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; - $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; - - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) - . ' ' . $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']; - } } } -- cgit v1.2.1 From 773f3727de943e8c38c9dc0621b98dc52a3355c6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 15:18:32 +0000 Subject: Let forums feed use the new methods. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10356 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 2474db0e13..006790d7d7 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -1015,8 +1015,8 @@ class phpbb_feed_forums extends phpbb_feed_base { global $auth, $db; - $f_read_ids = array_keys($auth->acl_getf('f_read')); - if (empty($f_read_ids)) + $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums()); + if (empty($in_fid_ary)) { return false; } @@ -1028,8 +1028,7 @@ class phpbb_feed_forums extends phpbb_feed_base f.forum_topics, f.forum_posts', 'FROM' => array(FORUMS_TABLE => 'f'), 'WHERE' => 'f.forum_type = ' . FORUM_POST . ' - AND ' . $db->sql_bit_and('f.forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' - AND ' . $db->sql_in_set('f.forum_id', $f_read_ids), + AND ' . $db->sql_in_set('f.forum_id', $in_fid_ary), 'ORDER_BY' => 'f.left_id ASC', ); -- cgit v1.2.1 From 757afe0b76d1714b3276cc92160307cc944655e6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 19:23:06 +0000 Subject: Abstract class for post based feeds. Separate overall, forum and topic feed. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10357 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 510 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 326 insertions(+), 184 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 006790d7d7..1c9482f32e 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -380,18 +380,16 @@ class phpbb_feed_factory break; default: - // Forum and/or topic specified? - if ($topic_id && !$config['feed_topic']) + if ($topic_id && $config['feed_topic']) { - return false; + return new phpbb_feed_topic($topic_id); } - - if ($forum_id && !$topic_id && !$config['feed_forum']) + else if ($forum_id && $config['feed_forum']) { - return false; + return new phpbb_feed_forum($forum_id); } - return new phpbb_feed($forum_id, $topic_id); + return new phpbb_feed_overall(); break; } } @@ -692,6 +690,49 @@ class phpbb_feed_base } } +/** +* Abstract class for post based feeds +* +* @package phpBB3 +*/ +class phpbb_feed_post_base extends phpbb_feed_base +{ + 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('date', 'post_time'); + $this->set('text', 'post_text'); + + $this->set('bitfield', 'bbcode_bitfield'); + $this->set('bbcode_uid','bbcode_uid'); + + $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 adjust_item(&$item_row, &$row) + { + global $phpEx, $config, $user; + + $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']) + { + $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) + . ' ' . $this->separator_stats . ' ' . $user->format_date($row['post_time']); + } + } +} + /** * Abstract class for topic based feeds * @@ -734,258 +775,359 @@ class phpbb_feed_topic_base extends phpbb_feed_base } /** -* Default feed class if no mode is specified. -* This can be the overall site feed or a forum/topic feed. +* Board wide feed (aka overall feed) +* +* This will give you the newest {$this->num_items} posts +* from the whole board. * * @package phpBB3 */ -class phpbb_feed extends phpbb_feed_base +class phpbb_feed_overall extends phpbb_feed_post_base { - /** - * Forum id specified for forum feed. - */ - var $forum_id = 0; + function get_sql() + { + global $db; - /** - * Topic id specified for topic feed. - */ - var $topic_id = 0; + $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); + if (empty($forum_ids)) + { + return false; + } - /** - * Constructor. - */ - function phpbb_feed($forum_id = 0, $topic_id = 0) - { - global $config; + // Add global forum id + $forum_ids[] = 0; - // Call parent constructor. - parent::phpbb_feed_base(); + // Determine post ids first for optimization + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + WHERE post_approved = 1 + AND ' . $db->sql_in_set('forum_id', $forum_ids) . ' + ORDER BY post_time DESC'; + $result = $db->sql_query_limit($sql, $this->num_items); - $this->forum_id = $forum_id; - $this->topic_id = $topic_id; + $post_ids = array(); + while ($post_id = (int) $db->sql_fetchfield('post_id')) + { + $post_ids[] = $post_id; + } + $db->sql_freeresult($result); - $this->sql = array(); + $this->sql = array( + 'SELECT' => 'f.forum_id, f.forum_name, f.forum_desc_options, ' . + '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, ' . + 'u.username, u.user_id', + 'FROM' => array( + POSTS_TABLE => 'p', + TOPICS_TABLE => 't', + USERS_TABLE => 'u', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'f.forum_id = p.forum_id', + ), + ), + 'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . ' + AND t.topic_id = p.topic_id + AND u.user_id = p.poster_id', + 'ORDER_BY' => 'p.post_time DESC', + ); + + return true; } - function set_keys() + function adjust_item(&$item_row, &$row) { - global $config; + parent::adjust_item($item_row, $row); - $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'); + $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; + } +} - $this->set('enable_bbcode', 'enable_bbcode'); - $this->set('enable_smilies', 'enable_smilies'); - $this->set('enable_magic_url', 'enable_magic_url'); +/** +* Forum feed +* +* This will give you the last {$this->num_items} posts made +* within this forum and all its subforums. +* +* @package phpBB3 +*/ +class phpbb_feed_forum extends phpbb_feed_post_base +{ + var $forum_id = 0; + var $forum_data = array(); + var $forum_ids = array(); - $this->num_items = (int) $config['feed_limit']; + function phpbb_feed_forum($forum_id) + { + parent::phpbb_feed_base(); + + $this->forum_id = (int) $forum_id; } function open() { - global $auth, $db, $user; + global $db, $auth; - // Topic/Forum feed - if ($this->topic_id || $this->forum_id) + // Check if forum exists + $sql = 'SELECT forum_id, forum_name, forum_options, forum_password + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $this->forum_id; + $result = $db->sql_query($sql); + $this->forum_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (empty($this->forum_data)) { - if ($this->topic_id) - { - // Topic feed - $sql = 'SELECT t.forum_id, f.forum_options - FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f - WHERE t.topic_id = ' . $this->topic_id . ' - AND t.forum_id = f.forum_id'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + trigger_error('NO_FORUM'); + } - if (empty($row)) - { - trigger_error('NO_TOPIC'); - } + // Make sure forum is not excluded from feed + if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->forum_data['forum_options'])) + { + trigger_error('NO_FEED'); + } - $this->forum_id = (int) $row['forum_id']; - } - else - { - // Forum feed - $sql = 'SELECT forum_options - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $this->forum_id; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + // Make sure we can read this forum + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } - if (empty($row)) - { - trigger_error('NO_FORUM'); - } - } + // Make sure forum is not passworded or user is authed + if ($this->forum_data['forum_password']) + { + $forum_ids_passworded = $this->get_passworded_forums(); - // Make sure forum is not excluded from feed - if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options'])) - { - trigger_error('NO_FEED'); - } - - // Make sure we can read this forum - if (!$auth->acl_get('f_read', $this->forum_id)) + if (isset($forum_ids_passworded[$this->forum_id])) { trigger_error('SORRY_AUTH_READ'); } - // Disable caching - $this->cache_time = 0; + unset($forum_ids_passworded); } } - /** - * Get SQL query for fetching items - */ function get_sql() { - global $db; + global $auth, $db; - $post_ids = array(); + $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); + if (empty($in_fid_ary)) + { + return false; + } - // 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)) : ''; + // Determine subforums + $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) + AND ' . $db->sql_in_set('f2.forum_id', $in_fid_ary); + $result = $db->sql_query($sql); - // Fetch latest post, grouped by topic... - if (!$this->forum_id && !$this->topic_id) + $in_fid_ary = array(); + while ($row = $db->sql_fetchrow($result)) { - // 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)) - { - $post_ids[] = (int) $row['topic_last_post_id']; - } - $db->sql_freeresult($result); + $in_fid_ary[] = (int) $row['forum_id']; + } + $db->sql_freeresult($result); + + if (empty($in_fid_ary)) + { + return false; + } + + // Add global topics forum '0' to forum ids + // This is kind of hackish, but therefore we don't need the topic table (t.topic_type) + $in_fid_ary[] = 0; + + $this->sql = array( + 'SELECT' => 'f.forum_id, f.forum_name, ' . + 'p.post_id, p.topic_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, ' . + 'u.username, u.user_id', + 'FROM' => array( + POSTS_TABLE => 'p', + USERS_TABLE => 'u', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'f.forum_id = p.forum_id', + ), + ), + 'WHERE' => $db->sql_in_set('p.forum_id', $in_fid_ary) . ' + AND p.poster_id = u.user_id + AND p.post_approved = 1', + 'ORDER_BY' => 'p.post_time DESC', + ); + + return true; + } + + function adjust_item(&$item_row, &$row) + { + parent::adjust_item($item_row, $row); + + $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; + } +} + +/** +* Topic feed for a specific topic +* +* This will give you the last {$this->num_items} posts made within this topic. +* +* @package phpBB3 +*/ +class phpbb_feed_topic extends phpbb_feed_post_base +{ + var $topic_id = 0; + var $forum_id = 0; + var $topic_data = array(); + + function phpbb_feed_topic($topic_id) + { + parent::phpbb_feed_base(); + + $this->topic_id = (int) $topic_id; + } + + function open() + { + global $auth, $db, $user; + + $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_approved, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type + FROM ' . TOPICS_TABLE . ' t + LEFT JOIN ' . FORUMS_TABLE . ' f + ON (f.forum_id = t.forum_id) + WHERE t.topic_id = ' . $this->topic_id; + $result = $db->sql_query($sql); + $this->topic_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (empty($this->topic_data)) + { + trigger_error('NO_TOPIC'); } - // Fetch latest posts from forum - else if (!$this->topic_id && $this->forum_id) + + if ($this->topic_data['topic_type'] == POST_GLOBAL) { - // Make sure the forum is not listed within the forbidden ones. ;) - if (in_array($this->forum_id, $this->excluded_forums())) + // We need to find at least one postable forum where feeds are enabled, + // that the user can read and maybe also has approve permissions. + $in_fid_ary = $this->get_readable_forums(); + + if (empty($in_fid_ary)) { - return false; + // User cannot read any forums + trigger_error('SORRY_AUTH_READ'); } - // Determine which forums to fetch - $not_in_fid = (sizeof($this->excluded_forums())) ? ' AND ' . $db->sql_in_set('f2.forum_id', $this->excluded_forums(), true) : ''; + if (!$this->topic_data['topic_approved']) + { + // Also require m_approve + $in_fid_ary = array_intersect($in_fid_ary, array_keys($auth->acl_getf('m_approve'))); - // 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); + if (empty($in_fid_ary)) + { + trigger_error('SORRY_AUTH_READ'); + } + } - $forum_ids = array(); - while ($row = $db->sql_fetchrow($result)) + // Diff excluded forums + $in_fid_ary = array_diff($in_fid_ary, $this->get_excluded_forums()); + + if (empty($in_fid_ary)) { - $forum_ids[] = (int) $row['forum_id']; + trigger_error('SORRY_AUTH_READ'); } - $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)) + // Also exclude passworded forums + $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums()); + + if (empty($in_fid_ary)) { - $post_ids[] = (int) $row['topic_last_post_id']; + trigger_error('SORRY_AUTH_READ'); } + + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST . ' + AND ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' + ORDER BY left_id ASC'; + $result = $db->sql_query_limit($sql, 1); + $this->forum_data = $db->sql_fetchrow($result); $db->sql_freeresult($result); + + if (empty($this->forum_data)) + { + // No forum found. + trigger_error('SORRY_AUTH_READ'); + } + + unset($in_fid_ary); } - // Fetch last posts from specified topic... - else if ($this->topic_id) + else { - // non-global announcement - if ($this->forum_id && in_array($this->forum_id, $this->excluded_forums())) + $this->forum_id = (int) $this->topic_data['forum_id']; + + // Make sure topic is either approved or user authed + if (!$this->topic_data['topic_approved'] && !$auth->acl_get('m_approve', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } + + // Make sure forum is not excluded from feed + if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->topic_data['forum_options'])) { - return false; + trigger_error('NO_FEED'); } - $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); + // Make sure we can read this forum + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } - while ($row = $db->sql_fetchrow($result)) + // Make sure forum is not passworded or user is authed + if ($this->topic_data['forum_password']) { - $post_ids[] = (int) $row['post_id']; + $forum_ids_passworded = $this->get_passworded_forums(); + + if (isset($forum_ids_passworded[$this->forum_id])) + { + trigger_error('SORRY_AUTH_READ'); + } + + unset($forum_ids_passworded); } - $db->sql_freeresult($result); } + } - if (!sizeof($post_ids)) - { - return false; - } + function get_sql() + { + global $auth, $db; - // 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, ' . + 'SELECT' => '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, ' . 'u.username, u.user_id', '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', + 'WHERE' => 'p.topic_id = ' . $this->topic_id . ' + ' . ($this->forum_id && !$auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . ' + AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', ); return true; } - function adjust_item(&$item_row, &$row) + function get_item() { - global $phpEx, $config; - - $item_row['title'] = (!$this->topic_id) ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; - $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; - - $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) - . ' ' . $this->separator_stats . ' ' . $user->format_date($row['post_time']) - . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies'] - . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']; - } + return ($row = parent::get_item()) ? array_merge($this->topic_data, $row) : $row; } } -- cgit v1.2.1 From d7e8e4d9cb8c6a8a61345605152a9c18f4a3a564 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 19:40:13 +0000 Subject: Cleanup. Remove unused methods and logic. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10358 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 148 +++++---------------------------------------------------- 1 file changed, 11 insertions(+), 137 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 1c9482f32e..7f9e3dfcb2 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -412,36 +412,11 @@ class phpbb_feed_base */ var $keys = array(); - /** - * An array of excluded forum ids. - */ - var $excluded_forums_ary = NULL; - /** * Number of items to fetch. Usually overwritten by $config['feed_something'] */ var $num_items = 15; - /** - * 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 - */ - var $sort_days = 30; - - /** - * Default cache time of entries in seconds - */ - var $cache_time = 0; // 0 important - /** * Separator for title elements to separate items (for example forum / topic) */ @@ -457,14 +432,6 @@ class phpbb_feed_base */ function phpbb_feed_base() { - 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; - } - $this->set_keys(); } @@ -511,43 +478,6 @@ class phpbb_feed_base 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 ? - $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) : ''; - - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0') . " - $sql_or"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $this->excluded_forums_ary[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $db->sql_freeresult($result); - - // 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_readable_forums() { global $auth; @@ -621,56 +551,21 @@ class phpbb_feed_base function get_item() { global $db, $cache; + static $result; - if (!$this->cache_time) + if (!isset($result)) { - if (empty($this->result)) + if (!$this->get_sql()) { - 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 false; } - return $db->sql_fetchrow($this->result); + // Query database + $sql = $db->sql_build_query('SELECT', $this->sql); + $result = $db->sql_query_limit($sql, $this->num_items); } - 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; - } + return $db->sql_fetchrow($result); } function user_viewprofile($row) @@ -1245,34 +1140,13 @@ class phpbb_feed_news extends phpbb_feed_topic_base global $auth, $config, $db; // Determine forum ids - $forum_ids_news = $this->get_news_forums(); - - // Very very unlikely, check anyway - if (empty($forum_ids_news)) + $in_fid_ary = array_intersect($this->get_news_forums(), $this->get_readable_forums()); + if (empty($in_fid_ary)) { return false; } - // Get passworded forums - $forum_ids_passworded = $this->get_passworded_forums(); - - // Check forum_ids - $in_fid_ary = array(); - foreach ($forum_ids_news as $forum_id) - { - if (isset($forum_ids_passworded[$forum_id])) - { - continue; - } - - if (!$auth->acl_get('f_read', $forum_id)) - { - continue; - } - - $in_fid_ary[] = $forum_id; - } - + $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums()); if (empty($in_fid_ary)) { return false; -- cgit v1.2.1 From 64898803af78a1d73be34c1ea85608f7fd293444 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 20 Dec 2009 19:46:48 +0000 Subject: Automatically lookup num_items in the config array if it is a string. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10359 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 7f9e3dfcb2..0ab7d42fce 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -432,7 +432,21 @@ class phpbb_feed_base */ function phpbb_feed_base() { + global $config; + $this->set_keys(); + + // Allow num_items to be string + if (is_string($this->num_items)) + { + $this->num_items = (int) $config[$this->num_items]; + + // A precaution + if (!$this->num_items) + { + $this->num_items = 10; + } + } } /** @@ -592,10 +606,10 @@ class phpbb_feed_base */ class phpbb_feed_post_base extends phpbb_feed_base { + var $num_items = 'feed_limit'; + function set_keys() { - global $config; - $this->set('title', 'post_subject'); $this->set('title2', 'topic_title'); @@ -610,8 +624,6 @@ class phpbb_feed_post_base extends phpbb_feed_base $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 adjust_item(&$item_row, &$row) @@ -1098,14 +1110,7 @@ class phpbb_feed_forums extends phpbb_feed_base */ class phpbb_feed_news extends phpbb_feed_topic_base { - function set_keys() - { - global $config; - - parent::set_keys(); - - $this->num_items = (int) $config['feed_limit']; - } + var $num_items = 'feed_limit'; function get_news_forums() { @@ -1188,14 +1193,7 @@ class phpbb_feed_news extends phpbb_feed_topic_base */ class phpbb_feed_topics extends phpbb_feed_topic_base { - function set_keys() - { - global $config; - - parent::set_keys(); - - $this->num_items = (int) $config['feed_overall_topics_limit']; - } + var $num_items = 'feed_overall_topics_limit'; function get_sql() { -- cgit v1.2.1 From cc43a909966e697a7a710c6efade1bcffc24db2e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 22 Dec 2009 19:26:25 +0000 Subject: Forgot to add this to the commit list. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10364 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 0ab7d42fce..f7349a21cf 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -388,8 +388,12 @@ class phpbb_feed_factory { return new phpbb_feed_forum($forum_id); } + else if ($config['feed_overall']) + { + return new phpbb_feed_overall(); + } - return new phpbb_feed_overall(); + return false; break; } } -- cgit v1.2.1 From a4cee51de51bfbdfe4af52ac00d9fa62857d6a92 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Dec 2009 02:30:37 +0000 Subject: Split feed_limit into feed_limit_post and feed_limit_topic. Drop feed_overall_topics_limit. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10366 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index f7349a21cf..f2d823de99 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -610,7 +610,7 @@ class phpbb_feed_base */ class phpbb_feed_post_base extends phpbb_feed_base { - var $num_items = 'feed_limit'; + var $num_items = 'feed_limit_post'; function set_keys() { @@ -651,6 +651,8 @@ class phpbb_feed_post_base extends phpbb_feed_base */ class phpbb_feed_topic_base extends phpbb_feed_base { + var $num_items = 'feed_limit_topic'; + function set_keys() { $this->set('title', 'topic_title'); @@ -1114,8 +1116,6 @@ class phpbb_feed_forums extends phpbb_feed_base */ class phpbb_feed_news extends phpbb_feed_topic_base { - var $num_items = 'feed_limit'; - function get_news_forums() { global $db, $cache; @@ -1197,8 +1197,6 @@ class phpbb_feed_news extends phpbb_feed_topic_base */ class phpbb_feed_topics extends phpbb_feed_topic_base { - var $num_items = 'feed_overall_topics_limit'; - function get_sql() { global $db, $config; -- cgit v1.2.1 From f94b24bc62dc61784a5dcfff261c4ee205c7ce37 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Dec 2009 16:27:11 +0000 Subject: Draft for active topics feed. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10380 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index f2d823de99..4966793176 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -360,6 +360,15 @@ class phpbb_feed_factory return new phpbb_feed_topics(); break; + case 'topics_active': + if (!$config['feed_topics_active']) + { + return false; + } + + return new phpbb_feed_topics_active(); + break; + case 'news': global $db; @@ -680,7 +689,7 @@ class phpbb_feed_topic_base extends phpbb_feed_base if ($config['feed_item_statistics']) { $item_row['statistics'] = $user->lang['POSTED'] . ' ' . $user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) - . ' ' . $this->separator_stats . ' ' . $user->format_date($row['topic_time']) + . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('date')]) . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . $row['topic_replies'] . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']; } @@ -1188,7 +1197,7 @@ class phpbb_feed_news extends phpbb_feed_topic_base } /** -* 'All Topics' feed +* New Topics feed * * This will give you the last {$this->num_items} created topics * including the first post. @@ -1246,5 +1255,111 @@ class phpbb_feed_topics extends phpbb_feed_topic_base } } +/** +* Active Topics feed +* +* This will give you the last {$this->num_items} topics +* with replies made withing the last {$this->sort_days} days +* including the last post. +* +* @package phpBB3 +*/ +class phpbb_feed_topics_active extends phpbb_feed_topic_base +{ + var $sort_days = 7; + + function set_keys() + { + parent::set_keys(); + + $this->set('author_id', 'topic_last_poster_id'); + $this->set('creator', 'topic_last_poster_name'); + $this->set('date', 'topic_last_post_time'); + $this->set('text', 'post_text'); + } + + function get_sql() + { + global $db, $config; + + $forum_ids_read = $this->get_readable_forums(); + if (empty($forum_ids_read)) + { + return false; + } + + $in_fid_ary = array_intersect($forum_ids_read, $this->get_forum_ids()); + $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums()); + if (empty($in_fid_ary)) + { + return false; + } + + // 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)) : ''; + + $this->sql = array( + 'SELECT' => 'f.forum_id, f.forum_name, + t.topic_id, t.topic_title, t.topic_replies, t.topic_views, + t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time, + p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', + 'FROM' => array( + TOPICS_TABLE => 't', + POSTS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'f.forum_id = t.forum_id', + ), + ), + 'WHERE' => 'p.post_id = t.topic_last_post_id + ' . $last_post_time_sql . ' + AND t.topic_moved_id = 0 + AND t.topic_approved = 1 + AND (' . $db->sql_in_set('t.forum_id', $in_fid_ary) . ' + OR t.topic_type = ' . POST_GLOBAL . ')', + 'ORDER_BY' => 't.topic_last_post_time DESC', + ); + + return true; + } + + function get_forum_ids() + { + global $db, $cache; + static $forum_ids; + + $cache_name = 'feed_topic_active_forum_ids'; + + if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false) + { + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' + AND ' . $db->sql_bit_and('forum_flags', log(FORUM_FLAG_ACTIVE_TOPICS, 2), '<> 0'); + $result = $db->sql_query($sql); + + $forum_ids = array(); + while ($forum_id = (int) $db->sql_fetchfield('forum_id')) + { + $forum_ids[$forum_id] = $forum_id; + } + $db->sql_freeresult($result); + + $cache->put('_' . $cache_name, $forum_ids, 180); + } + + return $forum_ids; + } + + function adjust_item(&$item_row, &$row) + { + parent::adjust_item($item_row, $row); + + $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; + } +} + ?> \ No newline at end of file -- cgit v1.2.1 From d7261a5425fab26a4ac5b39697fe2c987cb5e066 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Dec 2009 16:34:27 +0000 Subject: Reduce amount of forums by selecting postable forums only. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10381 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 4966793176..3a3cd988b6 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -1336,7 +1336,8 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' - WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' + WHERE forum_type = ' . FORUM_POST . ' + AND ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' AND ' . $db->sql_bit_and('forum_flags', log(FORUM_FLAG_ACTIVE_TOPICS, 2), '<> 0'); $result = $db->sql_query($sql); -- cgit v1.2.1 From ad7e3ccf4c8d233744cd7408f42484405f7d9c48 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 27 Dec 2009 00:48:52 +0000 Subject: Integrate active topics feed. Some language adjustments and rearrangements. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10382 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 3a3cd988b6..4522f2f940 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -352,7 +352,8 @@ class phpbb_feed_factory break; case 'topics': - if (!$config['feed_overall_topics']) + case 'topics_new': + if (!$config['feed_topics_new']) { return false; } -- cgit v1.2.1 From 4729046bf469684d44d66fb6e6f8f009bca8a858 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 29 Dec 2009 02:37:16 +0000 Subject: #54235 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10388 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 4522f2f940..ab3fea51ec 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -316,7 +316,7 @@ function feed_generate_content($content, $uid, $bitfield, $options) $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content); // Other control characters - // $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content); + $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content); return $content; } -- cgit v1.2.1 From fffe43691434d4bbc1dc314f6e86553752c0816f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 8 Jan 2010 22:30:30 +0000 Subject: We have to prefetch post ids from other tables where possible. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10397 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 118 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 92 insertions(+), 26 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index ab3fea51ec..d12f66b29b 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -10,6 +10,9 @@ * MOD Author Profile: http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=345763 * MOD Author Homepage: http://www.mssti.com/phpbb3/ * +* Warning: Querying the posts table can be very expensive and time consuming on very large boards. +* Where possible post ids should be prefetched from another table using a separate query. +* **/ /** @@ -1171,10 +1174,34 @@ class phpbb_feed_news extends phpbb_feed_topic_base return false; } + // Add global forum + $in_fid_ary[] = 0; + + // We really have to get the post ids first! + $sql = 'SELECT topic_first_post_id, topic_time + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' + AND topic_moved_id = 0 + AND topic_approved = 1 + ORDER BY topic_time DESC'; + $result = $db->sql_query_limit($sql, $this->num_items); + + $post_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $post_ids[] = (int) $row['topic_first_post_id']; + } + $db->sql_freeresult($result); + + if (empty($post_ids)) + { + return false; + } + $this->sql = array( 'SELECT' => 'f.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, - p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', + p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', 'FROM' => array( TOPICS_TABLE => 't', POSTS_TABLE => 'p', @@ -1182,15 +1209,12 @@ class phpbb_feed_news extends phpbb_feed_topic_base 'LEFT_JOIN' => array( array( 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'f.forum_id = t.forum_id', + 'ON' => 'p.forum_id = f.forum_id', ), ), - 'WHERE' => 'p.post_id = t.topic_first_post_id - AND t.topic_moved_id = 0 - AND t.topic_approved = 1 - AND (' . $db->sql_in_set('t.forum_id', $in_fid_ary) . ' - OR t.topic_type = ' . POST_GLOBAL . ')', - 'ORDER_BY' => 't.topic_time DESC', + 'WHERE' => 'p.topic_id = t.topic_id + AND ' . $db->sql_in_set('p.post_id', $post_ids), + 'ORDER_BY' => 'p.post_time DESC', ); return true; @@ -1223,10 +1247,34 @@ class phpbb_feed_topics extends phpbb_feed_topic_base return false; } + // Add global forum + $in_fid_ary[] = 0; + + // We really have to get the post ids first! + $sql = 'SELECT topic_first_post_id, topic_time + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' + AND topic_moved_id = 0 + AND topic_approved = 1 + ORDER BY topic_time DESC'; + $result = $db->sql_query_limit($sql, $this->num_items); + + $post_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $post_ids[] = (int) $row['topic_first_post_id']; + } + $db->sql_freeresult($result); + + if (empty($post_ids)) + { + return false; + } + $this->sql = array( 'SELECT' => 'f.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_views, t.topic_time, - p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', + p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', 'FROM' => array( TOPICS_TABLE => 't', POSTS_TABLE => 'p', @@ -1234,15 +1282,12 @@ class phpbb_feed_topics extends phpbb_feed_topic_base 'LEFT_JOIN' => array( array( 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'f.forum_id = t.forum_id', + 'ON' => 'p.forum_id = f.forum_id', ), ), - 'WHERE' => 'p.post_id = t.topic_first_post_id - AND t.topic_moved_id = 0 - AND t.topic_approved = 1 - AND (' . $db->sql_in_set('t.forum_id', $in_fid_ary) . ' - OR t.topic_type = ' . POST_GLOBAL . ')', - 'ORDER_BY' => 't.topic_time DESC', + 'WHERE' => 'p.topic_id = t.topic_id + AND ' . $db->sql_in_set('p.post_id', $post_ids), + 'ORDER_BY' => 'p.post_time DESC', ); return true; @@ -1296,14 +1341,39 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base return false; } + // Add global forum + $in_fid_ary[] = 0; + // 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_post_time_sql = ($this->sort_days) ? ' AND topic_last_post_time > ' . (time() - ($this->sort_days * 24 * 3600)) : ''; + + // We really have to get the post ids first! + $sql = 'SELECT topic_last_post_id, topic_last_post_time + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' + AND topic_moved_id = 0 + AND topic_approved = 1 + ' . $last_post_time_sql . ' + ORDER BY topic_last_post_time DESC'; + $result = $db->sql_query_limit($sql, $this->num_items); + + $post_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $post_ids[] = (int) $row['topic_last_post_id']; + } + $db->sql_freeresult($result); + + if (empty($post_ids)) + { + return false; + } $this->sql = array( 'SELECT' => 'f.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_replies, t.topic_views, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time, - p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', + p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', 'FROM' => array( TOPICS_TABLE => 't', POSTS_TABLE => 'p', @@ -1311,16 +1381,12 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base 'LEFT_JOIN' => array( array( 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'f.forum_id = t.forum_id', + 'ON' => 'p.forum_id = f.forum_id', ), ), - 'WHERE' => 'p.post_id = t.topic_last_post_id - ' . $last_post_time_sql . ' - AND t.topic_moved_id = 0 - AND t.topic_approved = 1 - AND (' . $db->sql_in_set('t.forum_id', $in_fid_ary) . ' - OR t.topic_type = ' . POST_GLOBAL . ')', - 'ORDER_BY' => 't.topic_last_post_time DESC', + 'WHERE' => 'p.topic_id = t.topic_id + AND ' . $db->sql_in_set('p.post_id', $post_ids), + 'ORDER_BY' => 'p.post_time DESC', ); return true; -- cgit v1.2.1 From e5c228d564b26ea39a499f3139590eaf39ef7d12 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 8 Jan 2010 22:38:02 +0000 Subject: Make sure ORDER BY is SELECTed git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10398 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index d12f66b29b..63e62e0dde 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -724,7 +724,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base $forum_ids[] = 0; // Determine post ids first for optimization - $sql = 'SELECT post_id + $sql = 'SELECT post_id, post_time FROM ' . POSTS_TABLE . ' WHERE post_approved = 1 AND ' . $db->sql_in_set('forum_id', $forum_ids) . ' @@ -738,6 +738,11 @@ class phpbb_feed_overall extends phpbb_feed_post_base } $db->sql_freeresult($result); + if (empty($post_ids)) + { + return false; + } + $this->sql = array( 'SELECT' => 'f.forum_id, f.forum_name, f.forum_desc_options, ' . 't.topic_id, t.topic_title, t.topic_time, t.topic_replies, t.topic_views, ' . @@ -977,7 +982,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base trigger_error('SORRY_AUTH_READ'); } - $sql = 'SELECT forum_id + $sql = 'SELECT forum_id, left_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST . ' AND ' . $db->sql_in_set('forum_id', $in_fid_ary) . ' -- cgit v1.2.1 From 2be2a2eb63338767948271bf01b1116fe775a7ed Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 12 Jan 2010 00:12:06 +0000 Subject: Improve overall feed performance git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10400 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 63e62e0dde..b527d7c20e 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -516,6 +516,13 @@ class phpbb_feed_base return array_keys($auth->acl_getf('f_read')); } + function get_m_approve_forums() + { + global $auth; + + return array_keys($auth->acl_getf('m_approve')); + } + function get_excluded_forums() { global $db, $cache; @@ -712,7 +719,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base { function get_sql() { - global $db; + global $auth, $db; $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); if (empty($forum_ids)) @@ -723,34 +730,39 @@ class phpbb_feed_overall extends phpbb_feed_post_base // Add global forum id $forum_ids[] = 0; - // Determine post ids first for optimization - $sql = 'SELECT post_id, post_time - FROM ' . POSTS_TABLE . ' - WHERE post_approved = 1 - AND ' . $db->sql_in_set('forum_id', $forum_ids) . ' - ORDER BY post_time DESC'; + // Forums with m_approve + $m_approve_fids = array_keys($auth->acl_getf('m_approve')); + + // Determine topics with recent activity + $sql = 'SELECT topic_id, topic_last_post_time + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' + AND (topic_approved = 1 + OR ' . $db->sql_in_set('forum_id', $m_approve_fids) . ') + ORDER BY topic_last_post_time DESC'; $result = $db->sql_query_limit($sql, $this->num_items); - $post_ids = array(); - while ($post_id = (int) $db->sql_fetchfield('post_id')) + $topic_ids = array(); + $topic_last_post_time = PHP_INT_MAX; + while ($row = $db->sql_fetchrow()) { - $post_ids[] = $post_id; + $topic_ids[] = (int) $row['topic_id']; + $topic_last_post_time = min($topic_last_post_time, (int) $row['topic_last_post_time']); } $db->sql_freeresult($result); - if (empty($post_ids)) + if (empty($topic_ids)) { return false; } + // Get the actual data $this->sql = array( - 'SELECT' => 'f.forum_id, f.forum_name, f.forum_desc_options, ' . - '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, ' . + 'SELECT' => 'f.forum_id, f.forum_name, ' . + 'p.post_id, p.topic_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, ' . 'u.username, u.user_id', 'FROM' => array( POSTS_TABLE => 'p', - TOPICS_TABLE => 't', USERS_TABLE => 'u', ), 'LEFT_JOIN' => array( @@ -759,8 +771,10 @@ class phpbb_feed_overall extends phpbb_feed_post_base 'ON' => 'f.forum_id = p.forum_id', ), ), - 'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . ' - AND t.topic_id = p.topic_id + 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' + AND (p.post_approved = 1 + OR ' . $db->sql_in_set('p.forum_id', $m_approve_fids) . ') + AND p.post_time >= ' . $topic_last_post_time . ' AND u.user_id = p.poster_id', 'ORDER_BY' => 'p.post_time DESC', ); -- cgit v1.2.1 From aa14d12abb0bb7c441a426d2a8a346c0f4a56686 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 12 Jan 2010 00:24:39 +0000 Subject: Actually use the new method. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10401 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index b527d7c20e..b11a0fd386 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -512,15 +512,27 @@ class phpbb_feed_base function get_readable_forums() { global $auth; + static $forum_ids; + + if (!isset($forum_ids)) + { + $forum_ids = array_keys($auth->acl_getf('f_read')); + } - return array_keys($auth->acl_getf('f_read')); + return $forum_ids; } - function get_m_approve_forums() + function get_moderator_approve_forums() { global $auth; + static $forum_ids; - return array_keys($auth->acl_getf('m_approve')); + if (!isset($forum_ids)) + { + $forum_ids = array_keys($auth->acl_getf('m_approve')); + } + + return $forum_ids; } function get_excluded_forums() @@ -730,15 +742,12 @@ class phpbb_feed_overall extends phpbb_feed_post_base // Add global forum id $forum_ids[] = 0; - // Forums with m_approve - $m_approve_fids = array_keys($auth->acl_getf('m_approve')); - // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' AND (topic_approved = 1 - OR ' . $db->sql_in_set('forum_id', $m_approve_fids) . ') + OR ' . $db->sql_in_set('forum_id', $this->get_moderator_approve_forums()) . ') ORDER BY topic_last_post_time DESC'; $result = $db->sql_query_limit($sql, $this->num_items); @@ -773,7 +782,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base ), 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' AND (p.post_approved = 1 - OR ' . $db->sql_in_set('p.forum_id', $m_approve_fids) . ') + OR ' . $db->sql_in_set('p.forum_id', $this->get_moderator_approve_forums()) . ') AND p.post_time >= ' . $topic_last_post_time . ' AND u.user_id = p.poster_id', 'ORDER_BY' => 'p.post_time DESC', -- cgit v1.2.1 From 085f89e1c14153c8bcc4084e5c7a1a8438bb1a0e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 12 Jan 2010 00:45:56 +0000 Subject: min() is actually pointless there. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10402 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index b11a0fd386..6dc237d8dd 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -752,11 +752,12 @@ class phpbb_feed_overall extends phpbb_feed_post_base $result = $db->sql_query_limit($sql, $this->num_items); $topic_ids = array(); - $topic_last_post_time = PHP_INT_MAX; + $min_post_time = 0; while ($row = $db->sql_fetchrow()) { $topic_ids[] = (int) $row['topic_id']; - $topic_last_post_time = min($topic_last_post_time, (int) $row['topic_last_post_time']); + + $min_post_time = (int) $row['topic_last_post_time']; } $db->sql_freeresult($result); @@ -783,7 +784,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $this->get_moderator_approve_forums()) . ') - AND p.post_time >= ' . $topic_last_post_time . ' + AND p.post_time >= ' . $min_post_time . ' AND u.user_id = p.poster_id', 'ORDER_BY' => 'p.post_time DESC', ); -- cgit v1.2.1 From 35dc866cf522c1b95b532fd79af4117ff3699b22 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 12 Jan 2010 00:53:16 +0000 Subject: Exclude moved topics. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10403 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 6dc237d8dd..f21d8dfe63 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -746,6 +746,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' + AND topic_moved_id = 0 AND (topic_approved = 1 OR ' . $db->sql_in_set('forum_id', $this->get_moderator_approve_forums()) . ') ORDER BY topic_last_post_time DESC'; -- cgit v1.2.1 From 7462724a2488881e50006ce8815bebbd71ff5618 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 12 Jan 2010 01:18:33 +0000 Subject: m_approve array can be empty git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10404 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index f21d8dfe63..22778b66fa 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -742,13 +742,17 @@ class phpbb_feed_overall extends phpbb_feed_post_base // Add global forum id $forum_ids[] = 0; + // m_approve forums + $fid_m_approve = $this->get_moderator_approve_forums(); + $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', $fid_m_approve) : ''; + // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' AND topic_moved_id = 0 AND (topic_approved = 1 - OR ' . $db->sql_in_set('forum_id', $this->get_moderator_approve_forums()) . ') + ' . $sql_m_approve . ') ORDER BY topic_last_post_time DESC'; $result = $db->sql_query_limit($sql, $this->num_items); @@ -784,7 +788,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base ), 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' AND (p.post_approved = 1 - OR ' . $db->sql_in_set('p.forum_id', $this->get_moderator_approve_forums()) . ') + ' . str_replace('forum_id', 'p.forum_id', $sql_m_approve) . ') AND p.post_time >= ' . $min_post_time . ' AND u.user_id = p.poster_id', 'ORDER_BY' => 'p.post_time DESC', -- cgit v1.2.1 From 0f5856ce5b4b41572c4a819865b339e8137eeae1 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 12 Jan 2010 21:15:32 +0000 Subject: No longer include subforums in forum feed. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10405 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 69 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 22778b66fa..a783f83ffd 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -809,7 +809,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base * Forum feed * * This will give you the last {$this->num_items} posts made -* within this forum and all its subforums. +* within a specific forum. * * @package phpBB3 */ @@ -817,7 +817,6 @@ class phpbb_feed_forum extends phpbb_feed_post_base { var $forum_id = 0; var $forum_data = array(); - var $forum_ids = array(); function phpbb_feed_forum($forum_id) { @@ -831,7 +830,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base global $db, $auth; // Check if forum exists - $sql = 'SELECT forum_id, forum_name, forum_options, forum_password + $sql = 'SELECT forum_id, forum_name, forum_password, forum_type, forum_options FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $this->forum_id; $result = $db->sql_query($sql); @@ -843,6 +842,12 @@ class phpbb_feed_forum extends phpbb_feed_post_base trigger_error('NO_FORUM'); } + // Forum needs to be postable + if ($this->forum_data['forum_type'] != FORUM_POST) + { + trigger_error('NO_FEED'); + } + // Make sure forum is not excluded from feed if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->forum_data['forum_options'])) { @@ -873,53 +878,44 @@ class phpbb_feed_forum extends phpbb_feed_post_base { global $auth, $db; - $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); - if (empty($in_fid_ary)) - { - return false; - } + $m_approve = ($auth->acl_get('m_approve')) ? true : false; + $forum_ids = array(0, $this->forum_id); - // Determine subforums - $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) - AND ' . $db->sql_in_set('f2.forum_id', $in_fid_ary); - $result = $db->sql_query($sql); + // Determine topics with recent activity + $sql = 'SELECT topic_id, topic_last_post_time + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' + AND topic_moved_id = 0 + ' . ((!$m_approve) ? 'AND topic_approved = 1' : '') . ' + ORDER BY topic_last_post_time DESC'; + $result = $db->sql_query_limit($sql, $this->num_items); - $in_fid_ary = array(); - while ($row = $db->sql_fetchrow($result)) + $topic_ids = array(); + $min_post_time = 0; + while ($row = $db->sql_fetchrow()) { - $in_fid_ary[] = (int) $row['forum_id']; + $topic_ids[] = (int) $row['topic_id']; + + $min_post_time = (int) $row['topic_last_post_time']; } $db->sql_freeresult($result); - if (empty($in_fid_ary)) + if (empty($topic_ids)) { return false; } - // Add global topics forum '0' to forum ids - // This is kind of hackish, but therefore we don't need the topic table (t.topic_type) - $in_fid_ary[] = 0; - $this->sql = array( - 'SELECT' => 'f.forum_id, f.forum_name, ' . - 'p.post_id, p.topic_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, ' . + 'SELECT' => 'p.post_id, p.topic_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, ' . 'u.username, u.user_id', 'FROM' => array( POSTS_TABLE => 'p', USERS_TABLE => 'u', ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'f.forum_id = p.forum_id', - ), - ), - 'WHERE' => $db->sql_in_set('p.forum_id', $in_fid_ary) . ' - AND p.poster_id = u.user_id - AND p.post_approved = 1', + 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' + ' . ((!$m_approve) ? 'AND p.post_approved = 1' : '') . ' + AND p.post_time >= ' . $min_post_time . ' + AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', ); @@ -932,6 +928,11 @@ class phpbb_feed_forum extends phpbb_feed_post_base $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title']; } + + function get_item() + { + return ($row = parent::get_item()) ? array_merge($this->forum_data, $row) : $row; + } } /** -- cgit v1.2.1 From 77af6caed7300c7498016b4b3d30d31f2bcca730 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 19 Jan 2010 19:08:51 +0000 Subject: [Feature] Ability to use HTTP authentication in ATOM feeds by passing the GET parameter auth=http git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10430 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index a783f83ffd..812b667868 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -30,6 +30,15 @@ if (!$config['feed_enable']) // Start session $user->session_begin(); + +if (!empty($config['feed_http_auth']) && request_var('auth', '') == 'http') +{ + phpbb_http_login(array( + 'auth_message' => 'Feed', + 'viewonline' => request_var('viewonline', true), + )); +} + $auth->acl($user->data); $user->setup(); -- cgit v1.2.1 From c496d2561e07e456a30f61997fe397f8c7a9dfd7 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Jan 2010 16:03:32 +0000 Subject: acl_get() of course requires the forum_id there. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10434 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 812b667868..4d1a6e94f1 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -887,7 +887,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base { global $auth, $db; - $m_approve = ($auth->acl_get('m_approve')) ? true : false; + $m_approve = ($auth->acl_get('m_approve', $this->forum_id)) ? true : false; $forum_ids = array(0, $this->forum_id); // Determine topics with recent activity -- cgit v1.2.1 From 71366a2ad279a1bb941c0bfa80505c1c8deecf84 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Jan 2010 16:06:23 +0000 Subject: Let's remove this warning again, since it for example also works quite well with the topic_id. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10435 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/feed.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/feed.php') diff --git a/phpBB/feed.php b/phpBB/feed.php index 4d1a6e94f1..1832efbc61 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -10,9 +10,6 @@ * MOD Author Profile: http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=345763 * MOD Author Homepage: http://www.mssti.com/phpbb3/ * -* Warning: Querying the posts table can be very expensive and time consuming on very large boards. -* Where possible post ids should be prefetched from another table using a separate query. -* **/ /** -- cgit v1.2.1