From a839896ddd532268f96da25231efba0c0f311b29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:02:45 +0200 Subject: [PATCH 01/15] [ticket/11481] Move feed factory to own file PHPBB3-11481 --- phpBB/feed.php | 88 --------------------------- phpBB/includes/feed/factory.php | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 88 deletions(-) create mode 100644 phpBB/includes/feed/factory.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 0dce22fb0c..f2066b41a8 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,94 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) 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': - case 'topics_new': - if (!$config['feed_topics_new']) - { - return false; - } - - 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; - - // 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; - } - - return new phpbb_feed_news(); - break; - - default: - if ($topic_id && $config['feed_topic']) - { - return new phpbb_feed_topic($topic_id); - } - else if ($forum_id && $config['feed_forum']) - { - return new phpbb_feed_forum($forum_id); - } - else if ($config['feed_overall']) - { - return new phpbb_feed_overall(); - } - - return false; - break; - } - } -} - /** * Base class with some generic functions and settings. * diff --git a/phpBB/includes/feed/factory.php b/phpBB/includes/feed/factory.php new file mode 100644 index 0000000000..30a415cacb --- /dev/null +++ b/phpBB/includes/feed/factory.php @@ -0,0 +1,104 @@ +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; + } + + return new phpbb_feed_news(); + break; + + default: + if ($topic_id && $config['feed_topic']) + { + return new phpbb_feed_topic($topic_id); + } + else if ($forum_id && $config['feed_forum']) + { + return new phpbb_feed_forum($forum_id); + } + else if ($config['feed_overall']) + { + return new phpbb_feed_overall(); + } + + return false; + break; + } + } +} From 2916ddc38c964992b44fd5be50963521f59c1858 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:03:10 +0200 Subject: [PATCH 02/15] [ticket/11481] Move feed base to own file PHPBB3-11481 --- phpBB/feed.php | 214 -------------------------------- phpBB/includes/feed/base.php | 230 +++++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+), 214 deletions(-) create mode 100644 phpBB/includes/feed/base.php diff --git a/phpBB/feed.php b/phpBB/feed.php index f2066b41a8..3158e76110 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,220 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* Base class with some generic functions and settings. -* -* @package phpBB3 -*/ -class phpbb_feed_base -{ - /** - * SQL Query to be executed to get feed items - */ - var $sql = array(); - - /** - * Keys specified for retrieval of title, content, etc. - */ - var $keys = array(); - - /** - * Number of items to fetch. Usually overwritten by $config['feed_something'] - */ - var $num_items = 15; - - /** - * Separator for title elements to separate items (for example forum / topic) - */ - var $separator = "\xE2\x80\xA2"; // • - - /** - * Separator for the statistics row (Posted by, post date, replies, etc.) - */ - var $separator_stats = "\xE2\x80\x94"; // — - - /** - * Constructor - */ - 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; - } - } - } - - /** - * Set keys. - */ - function set_keys() - { - } - - /** - * Open feed - */ - function open() - { - } - - /** - * Close feed - */ - function close() - { - global $db; - - if (!empty($this->result)) - { - $db->sql_freeresult($this->result); - } - } - - /** - * Set key - */ - function set($key, $value) - { - $this->keys[$key] = $value; - } - - /** - * Get key - */ - function get($key) - { - return (isset($this->keys[$key])) ? $this->keys[$key] : NULL; - } - - function get_readable_forums() - { - global $auth; - static $forum_ids; - - if (!isset($forum_ids)) - { - $forum_ids = array_keys($auth->acl_getf('f_read', true)); - } - - return $forum_ids; - } - - function get_moderator_approve_forums() - { - global $auth; - static $forum_ids; - - if (!isset($forum_ids)) - { - $forum_ids = array_keys($auth->acl_getf('m_approve', true)); - } - - return $forum_ids; - } - - function is_moderator_approve_forum($forum_id) - { - static $forum_ids; - - if (!isset($forum_ids)) - { - $forum_ids = array_flip($this->get_moderator_approve_forums()); - } - - return (isset($forum_ids[$forum_id])) ? true : false; - } - - function get_excluded_forums() - { - global $db, $cache; - static $forum_ids; - - // Matches acp/acp_board.php - $cache_name = 'feed_excluded_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'); - $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); - } - - 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 $user; - - return $user->get_passworded_forums(); - } - - function get_item() - { - global $db, $cache; - static $result; - - if (!isset($result)) - { - if (!$this->get_sql()) - { - return false; - } - - // Query database - $sql = $db->sql_build_query('SELECT', $this->sql); - $result = $db->sql_query_limit($sql, $this->num_items); - } - - return $db->sql_fetchrow($result); - } - - 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')] . ''; - } -} - /** * Abstract class for post based feeds * diff --git a/phpBB/includes/feed/base.php b/phpBB/includes/feed/base.php new file mode 100644 index 0000000000..300ccf9b1e --- /dev/null +++ b/phpBB/includes/feed/base.php @@ -0,0 +1,230 @@ +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; + } + } + } + + /** + * Set keys. + */ + function set_keys() + { + } + + /** + * Open feed + */ + function open() + { + } + + /** + * Close feed + */ + function close() + { + global $db; + + if (!empty($this->result)) + { + $db->sql_freeresult($this->result); + } + } + + /** + * Set key + */ + function set($key, $value) + { + $this->keys[$key] = $value; + } + + /** + * Get key + */ + function get($key) + { + return (isset($this->keys[$key])) ? $this->keys[$key] : NULL; + } + + function get_readable_forums() + { + global $auth; + static $forum_ids; + + if (!isset($forum_ids)) + { + $forum_ids = array_keys($auth->acl_getf('f_read', true)); + } + + return $forum_ids; + } + + function get_moderator_approve_forums() + { + global $auth; + static $forum_ids; + + if (!isset($forum_ids)) + { + $forum_ids = array_keys($auth->acl_getf('m_approve', true)); + } + + return $forum_ids; + } + + function is_moderator_approve_forum($forum_id) + { + static $forum_ids; + + if (!isset($forum_ids)) + { + $forum_ids = array_flip($this->get_moderator_approve_forums()); + } + + return (isset($forum_ids[$forum_id])) ? true : false; + } + + function get_excluded_forums() + { + global $db, $cache; + static $forum_ids; + + // Matches acp/acp_board.php + $cache_name = 'feed_excluded_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'); + $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); + } + + 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 $user; + + return $user->get_passworded_forums(); + } + + function get_item() + { + global $db, $cache; + static $result; + + if (!isset($result)) + { + if (!$this->get_sql()) + { + return false; + } + + // Query database + $sql = $db->sql_build_query('SELECT', $this->sql); + $result = $db->sql_query_limit($sql, $this->num_items); + } + + return $db->sql_fetchrow($result); + } + + 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')] . ''; + } +} From 06a51b09f1414f350b0c199a7c79b81a96bb98a7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:03:40 +0200 Subject: [PATCH 03/15] [ticket/11481] Move feed post base to own file PHPBB3-11481 --- phpBB/feed.php | 43 ---------------------- phpBB/includes/feed/post_base.php | 59 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 phpBB/includes/feed/post_base.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 3158e76110..039d9fc80a 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,49 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* Abstract class for post based feeds -* -* @package phpBB3 -*/ -class phpbb_feed_post_base extends phpbb_feed_base -{ - var $num_items = 'feed_limit_post'; - - function set_keys() - { - $this->set('title', 'post_subject'); - $this->set('title2', 'topic_title'); - - $this->set('author_id', 'user_id'); - $this->set('creator', 'username'); - $this->set('published', 'post_time'); - $this->set('updated', 'post_edit_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[$this->get('published')]) - . (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : ''); - } - } -} - /** * Abstract class for topic based feeds * diff --git a/phpBB/includes/feed/post_base.php b/phpBB/includes/feed/post_base.php new file mode 100644 index 0000000000..5af30f686b --- /dev/null +++ b/phpBB/includes/feed/post_base.php @@ -0,0 +1,59 @@ +set('title', 'post_subject'); + $this->set('title2', 'topic_title'); + + $this->set('author_id', 'user_id'); + $this->set('creator', 'username'); + $this->set('published', 'post_time'); + $this->set('updated', 'post_edit_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[$this->get('published')]) + . (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : ''); + } + } +} From f592072b4b6253914dde4342ec163c6b427c58b2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:04:05 +0200 Subject: [PATCH 04/15] [ticket/11481] Move feed topic base to own file PHPBB3-11481 --- phpBB/feed.php | 45 ---------------------- phpBB/includes/feed/topic_base.php | 61 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 phpBB/includes/feed/topic_base.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 039d9fc80a..9c37ac3b72 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,51 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* Abstract class for topic based feeds -* -* @package phpBB3 -*/ -class phpbb_feed_topic_base extends phpbb_feed_base -{ - var $num_items = 'feed_limit_topic'; - - 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('published', 'post_time'); - $this->set('updated', 'post_edit_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[$this->get('published')]) - . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies']) - . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views'] - . (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $user->lang['POSTS_UNAPPROVED'] : ''); - } - } -} - /** * Board wide feed (aka overall feed) * diff --git a/phpBB/includes/feed/topic_base.php b/phpBB/includes/feed/topic_base.php new file mode 100644 index 0000000000..353b9cac15 --- /dev/null +++ b/phpBB/includes/feed/topic_base.php @@ -0,0 +1,61 @@ +set('title', 'topic_title'); + $this->set('title2', 'forum_name'); + + $this->set('author_id', 'topic_poster'); + $this->set('creator', 'topic_first_poster_name'); + $this->set('published', 'post_time'); + $this->set('updated', 'post_edit_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[$this->get('published')]) + . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies']) + . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views'] + . (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $user->lang['POSTS_UNAPPROVED'] : ''); + } + } +} From a995deb1897f3b6e21b3915c801835a9aac0663a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:04:37 +0200 Subject: [PATCH 05/15] [ticket/11481] Move overall feed to own file PHPBB3-11481 --- phpBB/feed.php | 83 --------------------------- phpBB/includes/feed/overall.php | 99 +++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 83 deletions(-) create mode 100644 phpBB/includes/feed/overall.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 9c37ac3b72..40f4c9e13e 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,89 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* 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_overall extends phpbb_feed_post_base -{ - function get_sql() - { - global $auth, $db; - - $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); - if (empty($forum_ids)) - { - return false; - } - - // 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 - ' . $sql_m_approve . ') - ORDER BY topic_last_post_time DESC'; - $result = $db->sql_query_limit($sql, $this->num_items); - - $topic_ids = array(); - $min_post_time = 0; - while ($row = $db->sql_fetchrow()) - { - $topic_ids[] = (int) $row['topic_id']; - - $min_post_time = (int) $row['topic_last_post_time']; - } - $db->sql_freeresult($result); - - if (empty($topic_ids)) - { - return false; - } - - // Get the actual data - $this->sql = array( - 'SELECT' => 'f.forum_id, f.forum_name, ' . - 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, 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( - USERS_TABLE => 'u', - POSTS_TABLE => 'p', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'f.forum_id = p.forum_id', - ), - ), - 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' - AND (p.post_approved = 1 - ' . 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', - ); - - 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']; - } -} - /** * Forum feed * diff --git a/phpBB/includes/feed/overall.php b/phpBB/includes/feed/overall.php new file mode 100644 index 0000000000..630f67660a --- /dev/null +++ b/phpBB/includes/feed/overall.php @@ -0,0 +1,99 @@ +num_items} posts +* from the whole board. +* +* @package phpBB3 +*/ +class phpbb_feed_overall extends phpbb_feed_post_base +{ + function get_sql() + { + global $auth, $db; + + $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); + if (empty($forum_ids)) + { + return false; + } + + // 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 + ' . $sql_m_approve . ') + ORDER BY topic_last_post_time DESC'; + $result = $db->sql_query_limit($sql, $this->num_items); + + $topic_ids = array(); + $min_post_time = 0; + while ($row = $db->sql_fetchrow()) + { + $topic_ids[] = (int) $row['topic_id']; + + $min_post_time = (int) $row['topic_last_post_time']; + } + $db->sql_freeresult($result); + + if (empty($topic_ids)) + { + return false; + } + + // Get the actual data + $this->sql = array( + 'SELECT' => 'f.forum_id, f.forum_name, ' . + 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, 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( + USERS_TABLE => 'u', + POSTS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'f.forum_id = p.forum_id', + ), + ), + 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' + AND (p.post_approved = 1 + ' . 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', + ); + + 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']; + } +} From d94ec8faab1b6c7e776d6ff24b91dd9d0a7a7cf8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:04:57 +0200 Subject: [PATCH 06/15] [ticket/11481] Move forum feed to own file PHPBB3-11481 --- phpBB/feed.php | 129 ------------------------------ phpBB/includes/feed/forum.php | 145 ++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 129 deletions(-) create mode 100644 phpBB/includes/feed/forum.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 40f4c9e13e..c9cc6196b7 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,135 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* Forum feed -* -* This will give you the last {$this->num_items} posts made -* within a specific forum. -* -* @package phpBB3 -*/ -class phpbb_feed_forum extends phpbb_feed_post_base -{ - var $forum_id = 0; - var $forum_data = array(); - - function phpbb_feed_forum($forum_id) - { - parent::phpbb_feed_base(); - - $this->forum_id = (int) $forum_id; - } - - function open() - { - global $db, $auth; - - // Check if forum exists - $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); - $this->forum_data = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (empty($this->forum_data)) - { - 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'])) - { - trigger_error('NO_FEED'); - } - - // Make sure we can read this forum - if (!$auth->acl_get('f_read', $this->forum_id)) - { - trigger_error('SORRY_AUTH_READ'); - } - - // Make sure forum is not passworded or user is authed - if ($this->forum_data['forum_password']) - { - $forum_ids_passworded = $this->get_passworded_forums(); - - if (isset($forum_ids_passworded[$this->forum_id])) - { - trigger_error('SORRY_AUTH_READ'); - } - - unset($forum_ids_passworded); - } - } - - function get_sql() - { - global $auth, $db; - - $m_approve = ($auth->acl_get('m_approve', $this->forum_id)) ? true : false; - - // Determine topics with recent activity - $sql = 'SELECT topic_id, topic_last_post_time - FROM ' . TOPICS_TABLE . ' - WHERE forum_id = ' . $this->forum_id . ' - 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); - - $topic_ids = array(); - $min_post_time = 0; - while ($row = $db->sql_fetchrow()) - { - $topic_ids[] = (int) $row['topic_id']; - - $min_post_time = (int) $row['topic_last_post_time']; - } - $db->sql_freeresult($result); - - if (empty($topic_ids)) - { - return false; - } - - $this->sql = array( - 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, 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', - ), - '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', - ); - - 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']; - } - - function get_item() - { - return ($row = parent::get_item()) ? array_merge($this->forum_data, $row) : $row; - } -} - /** * Topic feed for a specific topic * diff --git a/phpBB/includes/feed/forum.php b/phpBB/includes/feed/forum.php new file mode 100644 index 0000000000..d625751ec3 --- /dev/null +++ b/phpBB/includes/feed/forum.php @@ -0,0 +1,145 @@ +num_items} posts made +* within a specific forum. +* +* @package phpBB3 +*/ +class phpbb_feed_forum extends phpbb_feed_post_base +{ + var $forum_id = 0; + var $forum_data = array(); + + function __construct($forum_id) + { + parent::__construct(); + + $this->forum_id = (int) $forum_id; + } + + function open() + { + global $db, $auth; + + // Check if forum exists + $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); + $this->forum_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (empty($this->forum_data)) + { + 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'])) + { + trigger_error('NO_FEED'); + } + + // Make sure we can read this forum + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } + + // Make sure forum is not passworded or user is authed + if ($this->forum_data['forum_password']) + { + $forum_ids_passworded = $this->get_passworded_forums(); + + if (isset($forum_ids_passworded[$this->forum_id])) + { + trigger_error('SORRY_AUTH_READ'); + } + + unset($forum_ids_passworded); + } + } + + function get_sql() + { + global $auth, $db; + + $m_approve = ($auth->acl_get('m_approve', $this->forum_id)) ? true : false; + + // Determine topics with recent activity + $sql = 'SELECT topic_id, topic_last_post_time + FROM ' . TOPICS_TABLE . ' + WHERE forum_id = ' . $this->forum_id . ' + 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); + + $topic_ids = array(); + $min_post_time = 0; + while ($row = $db->sql_fetchrow()) + { + $topic_ids[] = (int) $row['topic_id']; + + $min_post_time = (int) $row['topic_last_post_time']; + } + $db->sql_freeresult($result); + + if (empty($topic_ids)) + { + return false; + } + + $this->sql = array( + 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, 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', + ), + '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', + ); + + 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']; + } + + function get_item() + { + return ($row = parent::get_item()) ? array_merge($this->forum_data, $row) : $row; + } +} From ffdb5c9388f345ee63c2df573638b267f091f033 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:05:22 +0200 Subject: [PATCH 07/15] [ticket/11481] Move topic feed to own file PHPBB3-11481 --- phpBB/feed.php | 98 ----------------------------- phpBB/includes/feed/topic.php | 114 ++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 98 deletions(-) create mode 100644 phpBB/includes/feed/topic.php diff --git a/phpBB/feed.php b/phpBB/feed.php index c9cc6196b7..f9e6146327 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,104 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* 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'); - } - - $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'])) - { - trigger_error('NO_FEED'); - } - - // Make sure we can read this forum - if (!$auth->acl_get('f_read', $this->forum_id)) - { - trigger_error('SORRY_AUTH_READ'); - } - - // Make sure forum is not passworded or user is authed - if ($this->topic_data['forum_password']) - { - $forum_ids_passworded = $this->get_passworded_forums(); - - if (isset($forum_ids_passworded[$this->forum_id])) - { - trigger_error('SORRY_AUTH_READ'); - } - - unset($forum_ids_passworded); - } - } - - function get_sql() - { - global $auth, $db; - - $this->sql = array( - 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_approved, 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', - ), - '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 get_item() - { - return ($row = parent::get_item()) ? array_merge($this->topic_data, $row) : $row; - } -} - /** * 'All Forums' feed * diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php new file mode 100644 index 0000000000..eb77eddb5c --- /dev/null +++ b/phpBB/includes/feed/topic.php @@ -0,0 +1,114 @@ +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 __construct($topic_id) + { + parent::__construct(); + + $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'); + } + + $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'])) + { + trigger_error('NO_FEED'); + } + + // Make sure we can read this forum + if (!$auth->acl_get('f_read', $this->forum_id)) + { + trigger_error('SORRY_AUTH_READ'); + } + + // Make sure forum is not passworded or user is authed + if ($this->topic_data['forum_password']) + { + $forum_ids_passworded = $this->get_passworded_forums(); + + if (isset($forum_ids_passworded[$this->forum_id])) + { + trigger_error('SORRY_AUTH_READ'); + } + + unset($forum_ids_passworded); + } + } + + function get_sql() + { + global $auth, $db; + + $this->sql = array( + 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_approved, 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', + ), + '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 get_item() + { + return ($row = parent::get_item()) ? array_merge($this->topic_data, $row) : $row; + } +} From caf7c45fb4c63eb138078a8d6c2da270d2dba935 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:05:41 +0200 Subject: [PATCH 08/15] [ticket/11481] Move forums feed to own file PHPBB3-11481 --- phpBB/feed.php | 62 --------------------------- phpBB/includes/feed/forums.php | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 62 deletions(-) create mode 100644 phpBB/includes/feed/forums.php diff --git a/phpBB/feed.php b/phpBB/feed.php index f9e6146327..1ca7768dfb 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,68 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* '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() - { - $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('updated', 'forum_last_post_time'); - $this->set('options', 'forum_desc_options'); - } - - function get_sql() - { - global $auth, $db; - - $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums()); - if (empty($in_fid_ary)) - { - return false; - } - - // Build SQL Query - $this->sql = array( - '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 ' . $db->sql_in_set('f.forum_id', $in_fid_ary), - 'ORDER_BY' => 'f.left_id ASC', - ); - - 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'] = $user->lang('TOTAL_TOPICS', (int) $row['forum_topics']) - . ' ' . $this->separator_stats . ' ' . $user->lang('TOTAL_POSTS_COUNT', (int) $row['forum_posts']); - } - } -} - /** * News feed * diff --git a/phpBB/includes/feed/forums.php b/phpBB/includes/feed/forums.php new file mode 100644 index 0000000000..f1c3e3531f --- /dev/null +++ b/phpBB/includes/feed/forums.php @@ -0,0 +1,78 @@ +set('title', 'forum_name'); + $this->set('text', 'forum_desc'); + $this->set('bitfield', 'forum_desc_bitfield'); + $this->set('bbcode_uid','forum_desc_uid'); + $this->set('updated', 'forum_last_post_time'); + $this->set('options', 'forum_desc_options'); + } + + function get_sql() + { + global $auth, $db; + + $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums()); + if (empty($in_fid_ary)) + { + return false; + } + + // Build SQL Query + $this->sql = array( + '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 ' . $db->sql_in_set('f.forum_id', $in_fid_ary), + 'ORDER_BY' => 'f.left_id ASC', + ); + + 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'] = $user->lang('TOTAL_TOPICS', (int) $row['forum_topics']) + . ' ' . $this->separator_stats . ' ' . $user->lang('TOTAL_POSTS_COUNT', (int) $row['forum_posts']); + } + } +} From 3e30c731b51178a4e8d6dec2a6643b65d616b2a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:05:59 +0200 Subject: [PATCH 09/15] [ticket/11481] Move news feed to own file PHPBB3-11481 --- phpBB/feed.php | 99 ------------------------------ phpBB/includes/feed/news.php | 115 +++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 99 deletions(-) create mode 100644 phpBB/includes/feed/news.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 1ca7768dfb..11284bab40 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,105 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* 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_topic_base -{ - function get_news_forums() - { - global $db, $cache; - static $forum_ids; - - // Matches acp/acp_board.php - $cache_name = 'feed_news_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_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); - } - - return $forum_ids; - } - - function get_sql() - { - global $auth, $config, $db; - - // Determine forum ids - $in_fid_ary = array_intersect($this->get_news_forums(), $this->get_readable_forums()); - if (empty($in_fid_ary)) - { - return false; - } - - $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums()); - if (empty($in_fid_ary)) - { - return false; - } - - // 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_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time, - p.post_id, p.post_time, p.post_edit_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', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'p.forum_id = f.forum_id', - ), - ), - '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; - } -} - /** * New Topics feed * diff --git a/phpBB/includes/feed/news.php b/phpBB/includes/feed/news.php new file mode 100644 index 0000000000..12deb69ae4 --- /dev/null +++ b/phpBB/includes/feed/news.php @@ -0,0 +1,115 @@ +num_items} first posts +* of all topics in the selected news forums. +* +* @package phpBB3 +*/ +class phpbb_feed_news extends phpbb_feed_topic_base +{ + function get_news_forums() + { + global $db, $cache; + static $forum_ids; + + // Matches acp/acp_board.php + $cache_name = 'feed_news_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_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); + } + + return $forum_ids; + } + + function get_sql() + { + global $auth, $config, $db; + + // Determine forum ids + $in_fid_ary = array_intersect($this->get_news_forums(), $this->get_readable_forums()); + if (empty($in_fid_ary)) + { + return false; + } + + $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums()); + if (empty($in_fid_ary)) + { + return false; + } + + // 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_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time, + p.post_id, p.post_time, p.post_edit_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', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'p.forum_id = f.forum_id', + ), + ), + '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; + } +} From 65a527f87744ccc4b02c7fecb98a565c59f76d39 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:06:24 +0200 Subject: [PATCH 10/15] [ticket/11481] Move topics feed to own file PHPBB3-11481 --- phpBB/feed.php | 77 ---------------------------- phpBB/includes/feed/topics.php | 93 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 77 deletions(-) create mode 100644 phpBB/includes/feed/topics.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 11284bab40..7ab9c6746f 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -335,83 +335,6 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } -/** -* New 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_topic_base -{ - function get_sql() - { - global $db, $config; - - $forum_ids_read = $this->get_readable_forums(); - if (empty($forum_ids_read)) - { - return false; - } - - $in_fid_ary = array_diff($forum_ids_read, $this->get_excluded_forums(), $this->get_passworded_forums()); - if (empty($in_fid_ary)) - { - return false; - } - - // 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_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time, - p.post_id, p.post_time, p.post_edit_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', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'p.forum_id = f.forum_id', - ), - ), - '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; - } - - 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']; - } -} - /** * Active Topics feed * diff --git a/phpBB/includes/feed/topics.php b/phpBB/includes/feed/topics.php new file mode 100644 index 0000000000..7cd557ffcc --- /dev/null +++ b/phpBB/includes/feed/topics.php @@ -0,0 +1,93 @@ +num_items} created topics +* including the first post. +* +* @package phpBB3 +*/ +class phpbb_feed_topics extends phpbb_feed_topic_base +{ + function get_sql() + { + global $db, $config; + + $forum_ids_read = $this->get_readable_forums(); + if (empty($forum_ids_read)) + { + return false; + } + + $in_fid_ary = array_diff($forum_ids_read, $this->get_excluded_forums(), $this->get_passworded_forums()); + if (empty($in_fid_ary)) + { + return false; + } + + // 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_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time, + p.post_id, p.post_time, p.post_edit_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', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'p.forum_id = f.forum_id', + ), + ), + '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; + } + + 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']; + } +} From b25af0fa683c84db1bea5b32953aa5a6e178b878 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 17:06:52 +0200 Subject: [PATCH 11/15] [ticket/11481] Move active topics feed to own file PHPBB3-11481 --- phpBB/feed.php | 123 ----------------------- phpBB/includes/feed/topics_active.php | 139 ++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 123 deletions(-) create mode 100644 phpBB/includes/feed/topics_active.php diff --git a/phpBB/feed.php b/phpBB/feed.php index 7ab9c6746f..676dd45c5a 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -334,126 +334,3 @@ function feed_generate_content($content, $uid, $bitfield, $options) return $content; } - -/** -* 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'); - } - - 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 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_replies_real, t.topic_views, - t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time, - p.post_id, p.post_time, p.post_edit_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', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(FORUMS_TABLE => 'f'), - 'ON' => 'p.forum_id = f.forum_id', - ), - ), - '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; - } - - 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 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); - - $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']; - } -} diff --git a/phpBB/includes/feed/topics_active.php b/phpBB/includes/feed/topics_active.php new file mode 100644 index 0000000000..36b6bcb1a2 --- /dev/null +++ b/phpBB/includes/feed/topics_active.php @@ -0,0 +1,139 @@ +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'); + } + + 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 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_replies_real, t.topic_views, + t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time, + p.post_id, p.post_time, p.post_edit_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', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'p.forum_id = f.forum_id', + ), + ), + '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; + } + + 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 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); + + $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']; + } +} From b5f148474450e6101e25ee0afbd04d945d21083d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 19:35:36 +0200 Subject: [PATCH 12/15] [ticket/11481] Move functions from feed into helper class PHPBB3-11481 --- phpBB/config/services.yml | 1 + phpBB/feed.php | 116 ++---------------------- phpBB/includes/feed/helper.php | 159 +++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 109 deletions(-) create mode 100644 phpBB/includes/feed/helper.php diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 7a0fddf0c1..bb96953bcf 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -4,6 +4,7 @@ imports: - { resource: notifications.yml } - { resource: migrator.yml } - { resource: avatars.yml } + - { resource: feed.yml } services: auth: diff --git a/phpBB/feed.php b/phpBB/feed.php index 676dd45c5a..c1940a5eb6 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -59,7 +59,8 @@ if ($forum_id || $topic_id || $mode) } // This boards URL -$board_url = generate_board_url(); +$phpbb_feed_helper = $phpbb_container->get('feed.helper'); +$board_url = $phpbb_feed_helper->get_board_url(); // Get correct feed object $feed = phpbb_feed_factory::init($mode, $forum_id, $topic_id); @@ -99,13 +100,13 @@ while ($row = $feed->get_item()) $item_row = array( 'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '', - 'published' => ($published > 0) ? feed_format_date($published) : '', - 'updated' => ($updated > 0) ? feed_format_date($updated) : '', + 'published' => ($published > 0) ? $phpbb_feed_helper->format_date($published) : '', + 'updated' => ($updated > 0) ? $phpbb_feed_helper->format_date($updated) : '', 'link' => '', 'title' => censor_text($title), '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)), + 'description' => censor_text($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)), 'statistics' => '', ); @@ -127,11 +128,11 @@ if (!$feed_updated_time) // FEED_IMAGE is not used (atom) $global_vars = array_merge($global_vars, array( 'FEED_IMAGE' => '', - 'SELF_LINK' => feed_append_sid('/feed.' . $phpEx, $params), + 'SELF_LINK' => $phpbb_feed_helper->append_sid('/feed.' . $phpEx, $params), 'FEED_LINK' => $board_url . '/index.' . $phpEx, 'FEED_TITLE' => $config['sitename'], 'FEED_SUBTITLE' => $config['site_desc'], - 'FEED_UPDATED' => feed_format_date($feed_updated_time), + 'FEED_UPDATED' => $phpbb_feed_helper->format_date($feed_updated_time), 'FEED_LANG' => $user->lang['USER_LANG'], 'FEED_AUTHOR' => $config['sitename'], )); @@ -231,106 +232,3 @@ 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; - - 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 = $user->create_datetime()->getOffset(); - $offset_string = phpbb_format_timezone_offset($zone_offset); - } - - return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string; -} - -/** -* 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); - - // Add newlines - $content = str_replace('
', '
' . "\n", $content); - - // Convert smiley Relative paths to Absolute path, Windows style - $content = str_replace($phpbb_root_path . $config['smilies_path'], $board_url . '/' . $config['smilies_path'], $content); - - // Remove "Select all" link and mouse events - $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); - - // 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( - ' ' => "\xC2\xA0", - '•' => "\xE2\x80\xA2", - '·' => "\xC2\xB7", - '©' => "\xC2\xA9", - ); - - $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); - - return $content; -} diff --git a/phpBB/includes/feed/helper.php b/phpBB/includes/feed/helper.php new file mode 100644 index 0000000000..20a399bcd7 --- /dev/null +++ b/phpBB/includes/feed/helper.php @@ -0,0 +1,159 @@ +config = $config; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * Run links through append_sid(), prepend generate_board_url() and remove session id + */ + public function get_board_url() + { + static $board_url; + + if (empty($board_url)) + { + $board_url = generate_board_url(); + } + + return $board_url; + } + + /** + * Run links through append_sid(), prepend generate_board_url() and remove session id + */ + public function append_sid($url, $params) + { + return append_sid($this->get_board_url() . $url, $params, true, ''); + } + + /** + * Generate ISO 8601 date string (RFC 3339) + */ + public function format_date($time) + { + static $zone_offset; + static $offset_string; + + if (empty($offset_string)) + { + $zone_offset = $this->user->create_datetime()->getOffset(); + $offset_string = phpbb_format_timezone_offset($zone_offset); + } + + return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string; + } + + /** + * Generate text content + */ + public function generate_content($content, $uid, $bitfield, $options) + { + 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); + + // Add newlines + $content = str_replace('
', '
' . "\n", $content); + + // Convert smiley Relative paths to Absolute path, Windows style + $content = str_replace($this->phpbb_root_path . $this->config['smilies_path'], $this->get_board_url() . '/' . $this->config['smilies_path'], $content); + + // Remove "Select all" link and mouse events + $content = str_replace('' . $this->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); + + // 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( + ' ' => "\xC2\xA0", + '•' => "\xE2\x80\xA2", + '·' => "\xC2\xB7", + '©' => "\xC2\xA9", + ); + + $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); + + return $content; + } +} From 3efe0eb24687a0e36e316b60887eff3ed45ae9b4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 20:04:23 +0200 Subject: [PATCH 13/15] [ticket/11481] Use container for all classes and inject dependencies PHPBB3-11481 --- phpBB/config/feed.yml | 56 ++++++++++++++++++++++++ phpBB/feed.php | 3 +- phpBB/includes/feed/base.php | 15 ++++++- phpBB/includes/feed/factory.php | 69 ++++++++++++++++++++---------- phpBB/includes/feed/forum.php | 12 ++++-- phpBB/includes/feed/forums.php | 2 +- phpBB/includes/feed/post_base.php | 2 +- phpBB/includes/feed/topic.php | 12 ++++-- phpBB/includes/feed/topic_base.php | 2 +- 9 files changed, 139 insertions(+), 34 deletions(-) create mode 100644 phpBB/config/feed.yml diff --git a/phpBB/config/feed.yml b/phpBB/config/feed.yml new file mode 100644 index 0000000000..218ce7a4e4 --- /dev/null +++ b/phpBB/config/feed.yml @@ -0,0 +1,56 @@ +services: + feed.helper: + class: phpbb_feed_helper + arguments: + - @config + - @user + - %core.root_path% + + feed.factory: + class: phpbb_feed_factory + arguments: + - @service_container + - @config + - @dbal.conn + + feed.forum: + class: phpbb_feed_forum + scope: prototype + arguments: + - @feed.helper + + feed.forums: + class: phpbb_feed_forums + scope: prototype + arguments: + - @feed.helper + + feed.news: + class: phpbb_feed_news + scope: prototype + arguments: + - @feed.helper + + feed.overall: + class: phpbb_feed_overall + scope: prototype + arguments: + - @feed.helper + + feed.topic: + class: phpbb_feed_topic + scope: prototype + arguments: + - @feed.helper + + feed.topics: + class: phpbb_feed_topics + scope: prototype + arguments: + - @feed.helper + + feed.topics_active: + class: phpbb_feed_topics_active + scope: prototype + arguments: + - @feed.helper diff --git a/phpBB/feed.php b/phpBB/feed.php index c1940a5eb6..38bb9de008 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -63,7 +63,8 @@ $phpbb_feed_helper = $phpbb_container->get('feed.helper'); $board_url = $phpbb_feed_helper->get_board_url(); // Get correct feed object -$feed = phpbb_feed_factory::init($mode, $forum_id, $topic_id); +$phpbb_feed_factory = $phpbb_container->get('feed.factory'); +$feed = $phpbb_feed_factory->get_feed($mode, $forum_id, $topic_id); // No feed found if ($feed === false) diff --git a/phpBB/includes/feed/base.php b/phpBB/includes/feed/base.php index 300ccf9b1e..2ffd20d31a 100644 --- a/phpBB/includes/feed/base.php +++ b/phpBB/includes/feed/base.php @@ -22,6 +22,12 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_feed_base { + /** + * Feed helper object + * @var phpbb_feed_helper + */ + protected $helper; + /** * SQL Query to be executed to get feed items */ @@ -49,8 +55,11 @@ abstract class phpbb_feed_base /** * Constructor + * + * @param phpbb_feed_helper $helper Feed helper + * @return null */ - function __construct() + function __construct(phpbb_feed_helper $helper) { global $config; @@ -67,6 +76,8 @@ abstract class phpbb_feed_base $this->num_items = 10; } } + + $this->helper = $helper; } /** @@ -225,6 +236,6 @@ abstract class phpbb_feed_base return $user->lang['GUEST']; } - return '' . $row[$this->get('creator')] . ''; + return '' . $row[$this->get('creator')] . ''; } } diff --git a/phpBB/includes/feed/factory.php b/phpBB/includes/feed/factory.php index 30a415cacb..346cf9d870 100644 --- a/phpBB/includes/feed/factory.php +++ b/phpBB/includes/feed/factory.php @@ -21,6 +21,33 @@ if (!defined('IN_PHPBB')) */ class phpbb_feed_factory { + /** + * Service container object + * @var object + */ + protected $container; + + /** @var phpbb_config */ + protected $config; + + /** @var phpbb_db_driver */ + protected $driver; + + /** + * Constructor + * + * @param objec $container Container object + * @param phpbb_config $config Config object + * @param phpbb_db_driver $db Database connection + * @return null + */ + public function __construct($container, phpbb_config $config, phpbb_db_driver $db) + { + $this->container = $container; + $this->config = $config; + $this->db = $db; + } + /** * Return correct object for specified mode * @@ -30,71 +57,69 @@ class phpbb_feed_factory * * @return object Returns correct feeds object for specified mode. */ - function init($mode, $forum_id, $topic_id) + function get_feed($mode, $forum_id, $topic_id) { - global $config; - switch ($mode) { case 'forums': - if (!$config['feed_overall_forums']) + if (!$this->config['feed_overall_forums']) { return false; } - return new phpbb_feed_forums(); + return $this->container->get('feed.forums'); break; case 'topics': case 'topics_new': - if (!$config['feed_topics_new']) + if (!$this->config['feed_topics_new']) { return false; } - return new phpbb_feed_topics(); + return $this->container->get('feed.topics'); break; case 'topics_active': - if (!$config['feed_topics_active']) + if (!$this->config['feed_topics_active']) { return false; } - return new phpbb_feed_topics_active(); + return $this->container->get('feed.topics_active'); break; case 'news': - 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); + WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0'); + $result = $this->db->sql_query_limit($sql, 1, 0, 600); + $s_feed_news = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); if (!$s_feed_news) { return false; } - return new phpbb_feed_news(); + return $this->container->get('feed.news'); break; default: - if ($topic_id && $config['feed_topic']) + if ($topic_id && $this->config['feed_topic']) { - return new phpbb_feed_topic($topic_id); + return $this->container->get('feed.topic') + ->set_topic_id($topic_id); } - else if ($forum_id && $config['feed_forum']) + else if ($forum_id && $this->config['feed_forum']) { - return new phpbb_feed_forum($forum_id); + return $this->container->get('feed.forum') + ->set_forum_id($forum_id); } - else if ($config['feed_overall']) + else if ($this->config['feed_overall']) { - return new phpbb_feed_overall(); + return $this->container->get('feed.overall'); } return false; diff --git a/phpBB/includes/feed/forum.php b/phpBB/includes/feed/forum.php index d625751ec3..ec95cabe89 100644 --- a/phpBB/includes/feed/forum.php +++ b/phpBB/includes/feed/forum.php @@ -28,11 +28,17 @@ class phpbb_feed_forum extends phpbb_feed_post_base var $forum_id = 0; var $forum_data = array(); - function __construct($forum_id) + /** + * Set the Forum ID + * + * @param int $forum_id Forum ID + * @return phpbb_feed_forum + */ + public function set_forum_id($topic_id) { - parent::__construct(); - $this->forum_id = (int) $forum_id; + + return $this; } function open() diff --git a/phpBB/includes/feed/forums.php b/phpBB/includes/feed/forums.php index f1c3e3531f..5f56d28d2c 100644 --- a/phpBB/includes/feed/forums.php +++ b/phpBB/includes/feed/forums.php @@ -65,7 +65,7 @@ class phpbb_feed_forums extends phpbb_feed_base { global $phpEx, $config; - $item_row['link'] = feed_append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']); + $item_row['link'] = $this->helper->append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']); if ($config['feed_item_statistics']) { diff --git a/phpBB/includes/feed/post_base.php b/phpBB/includes/feed/post_base.php index 5af30f686b..b4ce467b9c 100644 --- a/phpBB/includes/feed/post_base.php +++ b/phpBB/includes/feed/post_base.php @@ -47,7 +47,7 @@ abstract class phpbb_feed_post_base extends phpbb_feed_base { global $phpEx, $config, $user; - $item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"); + $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"); if ($config['feed_item_statistics']) { diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php index eb77eddb5c..e4805e5539 100644 --- a/phpBB/includes/feed/topic.php +++ b/phpBB/includes/feed/topic.php @@ -28,11 +28,17 @@ class phpbb_feed_topic extends phpbb_feed_post_base var $forum_id = 0; var $topic_data = array(); - function __construct($topic_id) + /** + * Set the Topic ID + * + * @param int $topic_id Topic ID + * @return phpbb_feed_topic + */ + public function set_topic_id($topic_id) { - parent::__construct(); - $this->topic_id = (int) $topic_id; + + return $this; } function open() diff --git a/phpBB/includes/feed/topic_base.php b/phpBB/includes/feed/topic_base.php index 353b9cac15..959ed5c469 100644 --- a/phpBB/includes/feed/topic_base.php +++ b/phpBB/includes/feed/topic_base.php @@ -47,7 +47,7 @@ abstract class phpbb_feed_topic_base extends phpbb_feed_base { global $phpEx, $config, $user; - $item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']); + $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']); if ($config['feed_item_statistics']) { From 63334514555acea665186f20046a49a5ed41c334 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 20:32:47 +0200 Subject: [PATCH 14/15] [ticket/11481] Remove globals and use dependency injection instead PHPBB3-11481 --- phpBB/config/feed.yml | 42 +++++++++++++++ phpBB/includes/feed/base.php | 78 ++++++++++++++++----------- phpBB/includes/feed/factory.php | 2 +- phpBB/includes/feed/forum.php | 22 ++++---- phpBB/includes/feed/forums.php | 16 ++---- phpBB/includes/feed/news.php | 25 ++++----- phpBB/includes/feed/overall.php | 14 +++-- phpBB/includes/feed/post_base.php | 12 ++--- phpBB/includes/feed/topic.php | 16 +++--- phpBB/includes/feed/topic_base.php | 16 +++--- phpBB/includes/feed/topics.php | 12 ++--- phpBB/includes/feed/topics_active.php | 27 +++++----- 12 files changed, 157 insertions(+), 125 deletions(-) diff --git a/phpBB/config/feed.yml b/phpBB/config/feed.yml index 218ce7a4e4..59eeafd458 100644 --- a/phpBB/config/feed.yml +++ b/phpBB/config/feed.yml @@ -18,39 +18,81 @@ services: scope: prototype arguments: - @feed.helper + - @config + - @dbal.conn + - @cache.driver + - @user + - @auth + - %core.php_ext% feed.forums: class: phpbb_feed_forums scope: prototype arguments: - @feed.helper + - @config + - @dbal.conn + - @cache.driver + - @user + - @auth + - %core.php_ext% feed.news: class: phpbb_feed_news scope: prototype arguments: - @feed.helper + - @config + - @dbal.conn + - @cache.driver + - @user + - @auth + - %core.php_ext% feed.overall: class: phpbb_feed_overall scope: prototype arguments: - @feed.helper + - @config + - @dbal.conn + - @cache.driver + - @user + - @auth + - %core.php_ext% feed.topic: class: phpbb_feed_topic scope: prototype arguments: - @feed.helper + - @config + - @dbal.conn + - @cache.driver + - @user + - @auth + - %core.php_ext% feed.topics: class: phpbb_feed_topics scope: prototype arguments: - @feed.helper + - @config + - @dbal.conn + - @cache.driver + - @user + - @auth + - %core.php_ext% feed.topics_active: class: phpbb_feed_topics_active scope: prototype arguments: - @feed.helper + - @config + - @dbal.conn + - @cache.driver + - @user + - @auth + - %core.php_ext% diff --git a/phpBB/includes/feed/base.php b/phpBB/includes/feed/base.php index 2ffd20d31a..c8015ab916 100644 --- a/phpBB/includes/feed/base.php +++ b/phpBB/includes/feed/base.php @@ -28,6 +28,24 @@ abstract class phpbb_feed_base */ protected $helper; + /** @var phpbb_config */ + protected $config; + + /** @var phpbb_db_driver */ + protected $db; + + /** @var phpbb_cache_driver_interface */ + protected $cache; + + /** @var phpbb_user */ + protected $user; + + /** @var phpbb_auth */ + protected $auth; + + /** @var string */ + protected $phpEx; + /** * SQL Query to be executed to get feed items */ @@ -57,18 +75,30 @@ abstract class phpbb_feed_base * Constructor * * @param phpbb_feed_helper $helper Feed helper + * @param phpbb_config $config Config object + * @param phpbb_db_driver $db Database connection + * @param phpbb_cache_driver_interface $cache Cache object + * @param phpbb_user $user User object + * @param phpbb_auth $auth Auth object + * @param string $phpEx php file extension * @return null */ - function __construct(phpbb_feed_helper $helper) + function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, $phpEx) { - global $config; + $this->config = $config; + $this->helper = $helper; + $this->db = $db; + $this->cache = $cache; + $this->user = $user; + $this->auth = $auth; + $this->phpEx = $phpEx; $this->set_keys(); // Allow num_items to be string if (is_string($this->num_items)) { - $this->num_items = (int) $config[$this->num_items]; + $this->num_items = (int) $this->config[$this->num_items]; // A precaution if (!$this->num_items) @@ -76,8 +106,6 @@ abstract class phpbb_feed_base $this->num_items = 10; } } - - $this->helper = $helper; } /** @@ -99,11 +127,9 @@ abstract class phpbb_feed_base */ function close() { - global $db; - if (!empty($this->result)) { - $db->sql_freeresult($this->result); + $this->db->sql_freeresult($this->result); } } @@ -125,12 +151,11 @@ abstract 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', true)); + $forum_ids = array_keys($this->auth->acl_getf('f_read', true)); } return $forum_ids; @@ -138,12 +163,11 @@ abstract class phpbb_feed_base function get_moderator_approve_forums() { - global $auth; static $forum_ids; if (!isset($forum_ids)) { - $forum_ids = array_keys($auth->acl_getf('m_approve', true)); + $forum_ids = array_keys($this->auth->acl_getf('m_approve', true)); } return $forum_ids; @@ -163,27 +187,26 @@ abstract class phpbb_feed_base function get_excluded_forums() { - global $db, $cache; static $forum_ids; // Matches acp/acp_board.php $cache_name = 'feed_excluded_forum_ids'; - if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false) + if (!isset($forum_ids) && ($forum_ids = $this->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); + WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0'); + $result = $this->db->sql_query($sql); $forum_ids = array(); - while ($forum_id = (int) $db->sql_fetchfield('forum_id')) + while ($forum_id = (int) $this->db->sql_fetchfield('forum_id')) { $forum_ids[$forum_id] = $forum_id; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $cache->put('_' . $cache_name, $forum_ids); + $this->cache->put('_' . $cache_name, $forum_ids); } return $forum_ids; @@ -198,14 +221,11 @@ abstract class phpbb_feed_base function get_passworded_forums() { - global $user; - - return $user->get_passworded_forums(); + return $this->user->get_passworded_forums(); } function get_item() { - global $db, $cache; static $result; if (!isset($result)) @@ -216,26 +236,24 @@ abstract class phpbb_feed_base } // Query database - $sql = $db->sql_build_query('SELECT', $this->sql); - $result = $db->sql_query_limit($sql, $this->num_items); + $sql = $this->db->sql_build_query('SELECT', $this->sql); + $result = $this->db->sql_query_limit($sql, $this->num_items); } - return $db->sql_fetchrow($result); + return $this->db->sql_fetchrow($result); } 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 $this->user->lang['GUEST']; } - return '' . $row[$this->get('creator')] . ''; + return '' . $row[$this->get('creator')] . ''; } } diff --git a/phpBB/includes/feed/factory.php b/phpBB/includes/feed/factory.php index 346cf9d870..63a1eb8ef0 100644 --- a/phpBB/includes/feed/factory.php +++ b/phpBB/includes/feed/factory.php @@ -31,7 +31,7 @@ class phpbb_feed_factory protected $config; /** @var phpbb_db_driver */ - protected $driver; + protected $db; /** * Constructor diff --git a/phpBB/includes/feed/forum.php b/phpBB/includes/feed/forum.php index ec95cabe89..7670fbeaaa 100644 --- a/phpBB/includes/feed/forum.php +++ b/phpBB/includes/feed/forum.php @@ -43,15 +43,13 @@ class phpbb_feed_forum extends phpbb_feed_post_base function open() { - global $db, $auth; - // Check if forum exists $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); - $this->forum_data = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->forum_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if (empty($this->forum_data)) { @@ -71,7 +69,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base } // Make sure we can read this forum - if (!$auth->acl_get('f_read', $this->forum_id)) + if (!$this->auth->acl_get('f_read', $this->forum_id)) { trigger_error('SORRY_AUTH_READ'); } @@ -92,9 +90,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base function get_sql() { - global $auth, $db; - - $m_approve = ($auth->acl_get('m_approve', $this->forum_id)) ? true : false; + $m_approve = ($this->auth->acl_get('m_approve', $this->forum_id)) ? true : false; // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time @@ -103,17 +99,17 @@ class phpbb_feed_forum extends phpbb_feed_post_base 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); + $result = $this->db->sql_query_limit($sql, $this->num_items); $topic_ids = array(); $min_post_time = 0; - while ($row = $db->sql_fetchrow()) + while ($row = $this->db->sql_fetchrow()) { $topic_ids[] = (int) $row['topic_id']; $min_post_time = (int) $row['topic_last_post_time']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($topic_ids)) { @@ -127,7 +123,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base POSTS_TABLE => 'p', USERS_TABLE => 'u', ), - 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' + 'WHERE' => $this->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', diff --git a/phpBB/includes/feed/forums.php b/phpBB/includes/feed/forums.php index 5f56d28d2c..130da1c56a 100644 --- a/phpBB/includes/feed/forums.php +++ b/phpBB/includes/feed/forums.php @@ -39,8 +39,6 @@ class phpbb_feed_forums extends phpbb_feed_base function get_sql() { - global $auth, $db; - $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums()); if (empty($in_fid_ary)) { @@ -54,7 +52,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_in_set('f.forum_id', $in_fid_ary), + AND ' . $this->db->sql_in_set('f.forum_id', $in_fid_ary), 'ORDER_BY' => 'f.left_id ASC', ); @@ -63,16 +61,12 @@ class phpbb_feed_forums extends phpbb_feed_base function adjust_item(&$item_row, &$row) { - global $phpEx, $config; + $item_row['link'] = $this->helper->append_sid('/viewforum.' . $this->phpEx, 'f=' . $row['forum_id']); - $item_row['link'] = $this->helper->append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']); - - if ($config['feed_item_statistics']) + if ($this->config['feed_item_statistics']) { - global $user; - - $item_row['statistics'] = $user->lang('TOTAL_TOPICS', (int) $row['forum_topics']) - . ' ' . $this->separator_stats . ' ' . $user->lang('TOTAL_POSTS_COUNT', (int) $row['forum_posts']); + $item_row['statistics'] = $this->user->lang('TOTAL_TOPICS', (int) $row['forum_topics']) + . ' ' . $this->separator_stats . ' ' . $this->user->lang('TOTAL_POSTS_COUNT', (int) $row['forum_posts']); } } } diff --git a/phpBB/includes/feed/news.php b/phpBB/includes/feed/news.php index 12deb69ae4..92cc18a3ab 100644 --- a/phpBB/includes/feed/news.php +++ b/phpBB/includes/feed/news.php @@ -27,27 +27,26 @@ class phpbb_feed_news extends phpbb_feed_topic_base { function get_news_forums() { - global $db, $cache; static $forum_ids; // Matches acp/acp_board.php $cache_name = 'feed_news_forum_ids'; - if (!isset($forum_ids) && ($forum_ids = $cache->get('_' . $cache_name)) === false) + if (!isset($forum_ids) && ($forum_ids = $this->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); + WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0'); + $result = $this->db->sql_query($sql); $forum_ids = array(); - while ($forum_id = (int) $db->sql_fetchfield('forum_id')) + while ($forum_id = (int) $this->db->sql_fetchfield('forum_id')) { $forum_ids[$forum_id] = $forum_id; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $cache->put('_' . $cache_name, $forum_ids); + $this->cache->put('_' . $cache_name, $forum_ids); } return $forum_ids; @@ -55,8 +54,6 @@ class phpbb_feed_news extends phpbb_feed_topic_base function get_sql() { - global $auth, $config, $db; - // Determine forum ids $in_fid_ary = array_intersect($this->get_news_forums(), $this->get_readable_forums()); if (empty($in_fid_ary)) @@ -73,18 +70,18 @@ class phpbb_feed_news extends phpbb_feed_topic_base // 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) . ' + WHERE ' . $this->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); + $result = $this->db->sql_query_limit($sql, $this->num_items); $post_ids = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $post_ids[] = (int) $row['topic_first_post_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($post_ids)) { @@ -106,7 +103,7 @@ class phpbb_feed_news extends phpbb_feed_topic_base ), ), 'WHERE' => 'p.topic_id = t.topic_id - AND ' . $db->sql_in_set('p.post_id', $post_ids), + AND ' . $this->db->sql_in_set('p.post_id', $post_ids), 'ORDER_BY' => 'p.post_time DESC', ); diff --git a/phpBB/includes/feed/overall.php b/phpBB/includes/feed/overall.php index 630f67660a..5fb922f6bb 100644 --- a/phpBB/includes/feed/overall.php +++ b/phpBB/includes/feed/overall.php @@ -27,8 +27,6 @@ class phpbb_feed_overall extends phpbb_feed_post_base { function get_sql() { - global $auth, $db; - $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); if (empty($forum_ids)) { @@ -37,27 +35,27 @@ class phpbb_feed_overall extends phpbb_feed_post_base // 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) : ''; + $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $this->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) . ' + WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . ' AND topic_moved_id = 0 AND (topic_approved = 1 ' . $sql_m_approve . ') ORDER BY topic_last_post_time DESC'; - $result = $db->sql_query_limit($sql, $this->num_items); + $result = $this->db->sql_query_limit($sql, $this->num_items); $topic_ids = array(); $min_post_time = 0; - while ($row = $db->sql_fetchrow()) + while ($row = $this->db->sql_fetchrow()) { $topic_ids[] = (int) $row['topic_id']; $min_post_time = (int) $row['topic_last_post_time']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($topic_ids)) { @@ -79,7 +77,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base 'ON' => 'f.forum_id = p.forum_id', ), ), - 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' + 'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . ' AND (p.post_approved = 1 ' . str_replace('forum_id', 'p.forum_id', $sql_m_approve) . ') AND p.post_time >= ' . $min_post_time . ' diff --git a/phpBB/includes/feed/post_base.php b/phpBB/includes/feed/post_base.php index b4ce467b9c..bfcb4141ec 100644 --- a/phpBB/includes/feed/post_base.php +++ b/phpBB/includes/feed/post_base.php @@ -45,15 +45,13 @@ abstract class phpbb_feed_post_base extends phpbb_feed_base function adjust_item(&$item_row, &$row) { - global $phpEx, $config, $user; + $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $this->phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"); - $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"); - - if ($config['feed_item_statistics']) + if ($this->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[$this->get('published')]) - . (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : ''); + $item_row['statistics'] = $this->user->lang['POSTED'] . ' ' . $this->user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) + . ' ' . $this->separator_stats . ' ' . $this->user->format_date($row[$this->get('published')]) + . (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POST_UNAPPROVED'] : ''); } } } diff --git a/phpBB/includes/feed/topic.php b/phpBB/includes/feed/topic.php index e4805e5539..7d9a344982 100644 --- a/phpBB/includes/feed/topic.php +++ b/phpBB/includes/feed/topic.php @@ -43,16 +43,14 @@ class phpbb_feed_topic extends phpbb_feed_post_base 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); + $result = $this->db->sql_query($sql); + $this->topic_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if (empty($this->topic_data)) { @@ -62,7 +60,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base $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)) + if (!$this->topic_data['topic_approved'] && !$this->auth->acl_get('m_approve', $this->forum_id)) { trigger_error('SORRY_AUTH_READ'); } @@ -74,7 +72,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base } // Make sure we can read this forum - if (!$auth->acl_get('f_read', $this->forum_id)) + if (!$this->auth->acl_get('f_read', $this->forum_id)) { trigger_error('SORRY_AUTH_READ'); } @@ -95,8 +93,6 @@ class phpbb_feed_topic extends phpbb_feed_post_base function get_sql() { - global $auth, $db; - $this->sql = array( 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_approved, 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', @@ -105,7 +101,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base USERS_TABLE => 'u', ), 'WHERE' => 'p.topic_id = ' . $this->topic_id . ' - ' . ($this->forum_id && !$auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . ' + ' . ($this->forum_id && !$this->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', ); diff --git a/phpBB/includes/feed/topic_base.php b/phpBB/includes/feed/topic_base.php index 959ed5c469..0c845c30bd 100644 --- a/phpBB/includes/feed/topic_base.php +++ b/phpBB/includes/feed/topic_base.php @@ -45,17 +45,15 @@ abstract class phpbb_feed_topic_base extends phpbb_feed_base function adjust_item(&$item_row, &$row) { - global $phpEx, $config, $user; + $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $this->phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']); - $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']); - - if ($config['feed_item_statistics']) + if ($this->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[$this->get('published')]) - . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies']) - . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views'] - . (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $user->lang['POSTS_UNAPPROVED'] : ''); + $item_row['statistics'] = $this->user->lang['POSTED'] . ' ' . $this->user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row) + . ' ' . $this->separator_stats . ' ' . $this->user->format_date($row[$this->get('published')]) + . ' ' . $this->separator_stats . ' ' . $this->user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies']) + . ' ' . $this->separator_stats . ' ' . $this->user->lang['VIEWS'] . ' ' . $row['topic_views'] + . (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POSTS_UNAPPROVED'] : ''); } } } diff --git a/phpBB/includes/feed/topics.php b/phpBB/includes/feed/topics.php index 7cd557ffcc..c8761d7176 100644 --- a/phpBB/includes/feed/topics.php +++ b/phpBB/includes/feed/topics.php @@ -27,8 +27,6 @@ class phpbb_feed_topics extends phpbb_feed_topic_base { function get_sql() { - global $db, $config; - $forum_ids_read = $this->get_readable_forums(); if (empty($forum_ids_read)) { @@ -44,18 +42,18 @@ class phpbb_feed_topics extends phpbb_feed_topic_base // 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) . ' + WHERE ' . $this->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); + $result = $this->db->sql_query_limit($sql, $this->num_items); $post_ids = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $post_ids[] = (int) $row['topic_first_post_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($post_ids)) { @@ -77,7 +75,7 @@ class phpbb_feed_topics extends phpbb_feed_topic_base ), ), 'WHERE' => 'p.topic_id = t.topic_id - AND ' . $db->sql_in_set('p.post_id', $post_ids), + AND ' . $this->db->sql_in_set('p.post_id', $post_ids), 'ORDER_BY' => 'p.post_time DESC', ); diff --git a/phpBB/includes/feed/topics_active.php b/phpBB/includes/feed/topics_active.php index 36b6bcb1a2..d1c920c136 100644 --- a/phpBB/includes/feed/topics_active.php +++ b/phpBB/includes/feed/topics_active.php @@ -38,8 +38,6 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base function get_sql() { - global $db, $config; - $forum_ids_read = $this->get_readable_forums(); if (empty($forum_ids_read)) { @@ -59,19 +57,19 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base // 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) . ' + WHERE ' . $this->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); + $result = $this->db->sql_query_limit($sql, $this->num_items); $post_ids = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $post_ids[] = (int) $row['topic_last_post_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($post_ids)) { @@ -94,7 +92,7 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base ), ), 'WHERE' => 'p.topic_id = t.topic_id - AND ' . $db->sql_in_set('p.post_id', $post_ids), + AND ' . $this->db->sql_in_set('p.post_id', $post_ids), 'ORDER_BY' => 'p.post_time DESC', ); @@ -103,28 +101,27 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base 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) + if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false) { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' 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); + AND ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' + AND ' . $this->db->sql_bit_and('forum_flags', log(FORUM_FLAG_ACTIVE_TOPICS, 2), '<> 0'); + $result = $this->db->sql_query($sql); $forum_ids = array(); - while ($forum_id = (int) $db->sql_fetchfield('forum_id')) + while ($forum_id = (int) $this->db->sql_fetchfield('forum_id')) { $forum_ids[$forum_id] = $forum_id; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $cache->put('_' . $cache_name, $forum_ids, 180); + $this->cache->put('_' . $cache_name, $forum_ids, 180); } return $forum_ids; From e36deed24f62f4fca0a3e82b2d58d97499ff7764 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 20:35:38 +0200 Subject: [PATCH 15/15] [ticket/11481] Move prepended slash from calls into function PHPBB3-11481 --- phpBB/feed.php | 2 +- phpBB/includes/feed/base.php | 2 +- phpBB/includes/feed/forums.php | 2 +- phpBB/includes/feed/helper.php | 2 +- phpBB/includes/feed/post_base.php | 2 +- phpBB/includes/feed/topic_base.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/feed.php b/phpBB/feed.php index 38bb9de008..35cd7fda3f 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -129,7 +129,7 @@ if (!$feed_updated_time) // FEED_IMAGE is not used (atom) $global_vars = array_merge($global_vars, array( 'FEED_IMAGE' => '', - 'SELF_LINK' => $phpbb_feed_helper->append_sid('/feed.' . $phpEx, $params), + 'SELF_LINK' => $phpbb_feed_helper->append_sid('feed.' . $phpEx, $params), 'FEED_LINK' => $board_url . '/index.' . $phpEx, 'FEED_TITLE' => $config['sitename'], 'FEED_SUBTITLE' => $config['site_desc'], diff --git a/phpBB/includes/feed/base.php b/phpBB/includes/feed/base.php index c8015ab916..af28ee8dc8 100644 --- a/phpBB/includes/feed/base.php +++ b/phpBB/includes/feed/base.php @@ -254,6 +254,6 @@ abstract class phpbb_feed_base return $this->user->lang['GUEST']; } - return '' . $row[$this->get('creator')] . ''; + return '' . $row[$this->get('creator')] . ''; } } diff --git a/phpBB/includes/feed/forums.php b/phpBB/includes/feed/forums.php index 130da1c56a..72f786aa6a 100644 --- a/phpBB/includes/feed/forums.php +++ b/phpBB/includes/feed/forums.php @@ -61,7 +61,7 @@ class phpbb_feed_forums extends phpbb_feed_base function adjust_item(&$item_row, &$row) { - $item_row['link'] = $this->helper->append_sid('/viewforum.' . $this->phpEx, 'f=' . $row['forum_id']); + $item_row['link'] = $this->helper->append_sid('viewforum.' . $this->phpEx, 'f=' . $row['forum_id']); if ($this->config['feed_item_statistics']) { diff --git a/phpBB/includes/feed/helper.php b/phpBB/includes/feed/helper.php index 20a399bcd7..93330aa2ad 100644 --- a/phpBB/includes/feed/helper.php +++ b/phpBB/includes/feed/helper.php @@ -65,7 +65,7 @@ class phpbb_feed_helper */ public function append_sid($url, $params) { - return append_sid($this->get_board_url() . $url, $params, true, ''); + return append_sid($this->get_board_url() . '/' . $url, $params, true, ''); } /** diff --git a/phpBB/includes/feed/post_base.php b/phpBB/includes/feed/post_base.php index bfcb4141ec..a25ed50263 100644 --- a/phpBB/includes/feed/post_base.php +++ b/phpBB/includes/feed/post_base.php @@ -45,7 +45,7 @@ abstract class phpbb_feed_post_base extends phpbb_feed_base function adjust_item(&$item_row, &$row) { - $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $this->phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"); + $item_row['link'] = $this->helper->append_sid('viewtopic.' . $this->phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"); if ($this->config['feed_item_statistics']) { diff --git a/phpBB/includes/feed/topic_base.php b/phpBB/includes/feed/topic_base.php index 0c845c30bd..e6a47b4c86 100644 --- a/phpBB/includes/feed/topic_base.php +++ b/phpBB/includes/feed/topic_base.php @@ -45,7 +45,7 @@ abstract class phpbb_feed_topic_base extends phpbb_feed_base function adjust_item(&$item_row, &$row) { - $item_row['link'] = $this->helper->append_sid('/viewtopic.' . $this->phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']); + $item_row['link'] = $this->helper->append_sid('viewtopic.' . $this->phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']); if ($this->config['feed_item_statistics']) {