From e7f970e26d636d69ea742bf591dc5fc9dc15a0a9 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 16 Apr 2014 23:41:10 +0200 Subject: [ticket/12413] Fatal Error for feed.php?mode=forums https://tracker.phpbb.com/browse/PHPBB3-12413 http://area51.phpbb.com/phpBB/viewtopic.php?f=81&t=45475 PHPBB3-12413 --- phpBB/feed.php | 5 +-- phpBB/phpbb/feed/attachments_base.php | 81 +++++++++++++++++++++++++++++++++++ phpBB/phpbb/feed/forum.php | 2 + phpBB/phpbb/feed/post_base.php | 2 +- phpBB/phpbb/feed/topic.php | 2 + phpBB/phpbb/feed/topic_base.php | 2 +- 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 phpBB/phpbb/feed/attachments_base.php (limited to 'phpBB') diff --git a/phpBB/feed.php b/phpBB/feed.php index 9ff8c66b9d..0c4cc32fdb 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -73,9 +73,6 @@ if ($feed === false) trigger_error('NO_FEED'); } -// Get attachments for this feed -$feed->fetch_attachments(); - // Open Feed $feed->open(); @@ -111,7 +108,7 @@ while ($row = $feed->get_item()) '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($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], (($row['post_attachment']) ? $feed->attachments[$row['post_id']] : array()))), + 'description' => censor_text($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], ((isset($row['post_attachment']) && $row['post_attachment']) ? $feed->get_attachments($row['post_id']) : array()))), 'statistics' => '', ); diff --git a/phpBB/phpbb/feed/attachments_base.php b/phpBB/phpbb/feed/attachments_base.php new file mode 100644 index 0000000000..b497d3b3f7 --- /dev/null +++ b/phpBB/phpbb/feed/attachments_base.php @@ -0,0 +1,81 @@ +fetch_attachments(); + } + + /** + * Retrieve the list of attachments that may be displayed + */ + function fetch_attachments() + { + global $db; + + $sql_array = array( + 'SELECT' => 'a.*', + 'FROM' => array( + ATTACHMENTS_TABLE => 'a' + ), + 'WHERE' => 'a.in_message = 0 ', + 'ORDER_BY' => 'a.filetime DESC, a.post_msg_id ASC', + ); + + if (isset($this->topic_id)) + { + $sql_array['WHERE'] .= 'AND a.topic_id = ' . (int)$this->topic_id; + } + else if (isset($this->forum_id)) + { + $sql_array['LEFT_JOIN'] = array( + array( + 'FROM' => array(TOPICS_TABLE => 't'), + 'ON' => 'a.topic_id = t.topic_id', + ) + ); + $sql_array['WHERE'] .= 'AND t.forum_id = ' . (int)$this->forum_id; + } + + $sql = $db->sql_build_query('SELECT', $sql_array); + $result = $db->sql_query($sql); + + // Set attachments in feed items + while ($row = $db->sql_fetchrow($result)) + { + $this->attachments[$row['post_msg_id']][] = $row; + } + $db->sql_freeresult($result); + } + + /** + * Get attachments related to a given post + * + * @param $post_id Post id + * @return mixed Attachments related to $post_id + */ + function get_attachments($post_id) + { + return $this->attachments[$post_id]; + } +} diff --git a/phpBB/phpbb/feed/forum.php b/phpBB/phpbb/feed/forum.php index 85ecb60f7e..06e87ec21c 100644 --- a/phpBB/phpbb/feed/forum.php +++ b/phpBB/phpbb/feed/forum.php @@ -80,6 +80,8 @@ class forum extends \phpbb\feed\post_base unset($forum_ids_passworded); } + + $this->fetch_attachments(); } function get_sql() diff --git a/phpBB/phpbb/feed/post_base.php b/phpBB/phpbb/feed/post_base.php index c797d6a8ca..57eb70ea12 100644 --- a/phpBB/phpbb/feed/post_base.php +++ b/phpBB/phpbb/feed/post_base.php @@ -14,7 +14,7 @@ namespace phpbb\feed; * * @package phpBB3 */ -abstract class post_base extends \phpbb\feed\base +abstract class post_base extends \phpbb\feed\attachments_base { var $num_items = 'feed_limit_post'; var $attachments = array(); diff --git a/phpBB/phpbb/feed/topic.php b/phpBB/phpbb/feed/topic.php index a7acfb502f..3c2b3405f6 100644 --- a/phpBB/phpbb/feed/topic.php +++ b/phpBB/phpbb/feed/topic.php @@ -83,6 +83,8 @@ class topic extends \phpbb\feed\post_base unset($forum_ids_passworded); } + + $this->fetch_attachments(); } function get_sql() diff --git a/phpBB/phpbb/feed/topic_base.php b/phpBB/phpbb/feed/topic_base.php index 7e28e67b82..e8639a6fa6 100644 --- a/phpBB/phpbb/feed/topic_base.php +++ b/phpBB/phpbb/feed/topic_base.php @@ -14,7 +14,7 @@ namespace phpbb\feed; * * @package phpBB3 */ -abstract class topic_base extends \phpbb\feed\base +abstract class topic_base extends \phpbb\feed\attachments_base { var $num_items = 'feed_limit_topic'; -- cgit v1.2.1 From edf0fd0fbd4e76e57bb3899aaffeee730eec8261 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Tue, 22 Apr 2014 19:07:03 +0200 Subject: [ticket/12413] Adding the missing visibilities PHPBB3-12413 --- phpBB/phpbb/feed/attachments_base.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB') diff --git a/phpBB/phpbb/feed/attachments_base.php b/phpBB/phpbb/feed/attachments_base.php index b497d3b3f7..b8c72a7fb1 100644 --- a/phpBB/phpbb/feed/attachments_base.php +++ b/phpBB/phpbb/feed/attachments_base.php @@ -21,15 +21,10 @@ abstract class attachments_base extends \phpbb\feed\base */ protected $attachments = array(); - function open() - { - $this->fetch_attachments(); - } - /** * Retrieve the list of attachments that may be displayed */ - function fetch_attachments() + protected function fetch_attachments() { global $db; @@ -68,13 +63,18 @@ abstract class attachments_base extends \phpbb\feed\base $db->sql_freeresult($result); } + public function open() + { + $this->fetch_attachments(); + } + /** * Get attachments related to a given post * - * @param $post_id Post id - * @return mixed Attachments related to $post_id + * @param $post_id int Post id + * @return mixed Attachments related to $post_id */ - function get_attachments($post_id) + public function get_attachments($post_id) { return $this->attachments[$post_id]; } -- cgit v1.2.1 From 7d8d8394fc36b1564ea083447329ab9f54a3db01 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Fri, 25 Apr 2014 17:00:24 +0200 Subject: [ticket/12413] Fix: coding style PHPBB3-12413 --- phpBB/phpbb/feed/attachments_base.php | 19 +++++++++--------- phpBB/phpbb/feed/post_base.php | 37 ----------------------------------- 2 files changed, 10 insertions(+), 46 deletions(-) (limited to 'phpBB') diff --git a/phpBB/phpbb/feed/attachments_base.php b/phpBB/phpbb/feed/attachments_base.php index b8c72a7fb1..e61d637afa 100644 --- a/phpBB/phpbb/feed/attachments_base.php +++ b/phpBB/phpbb/feed/attachments_base.php @@ -26,8 +26,6 @@ abstract class attachments_base extends \phpbb\feed\base */ protected function fetch_attachments() { - global $db; - $sql_array = array( 'SELECT' => 'a.*', 'FROM' => array( @@ -39,7 +37,7 @@ abstract class attachments_base extends \phpbb\feed\base if (isset($this->topic_id)) { - $sql_array['WHERE'] .= 'AND a.topic_id = ' . (int)$this->topic_id; + $sql_array['WHERE'] .= 'AND a.topic_id = ' . (int) $this->topic_id; } else if (isset($this->forum_id)) { @@ -49,22 +47,25 @@ abstract class attachments_base extends \phpbb\feed\base 'ON' => 'a.topic_id = t.topic_id', ) ); - $sql_array['WHERE'] .= 'AND t.forum_id = ' . (int)$this->forum_id; + $sql_array['WHERE'] .= 'AND t.forum_id = ' . (int) $this->forum_id; } - $sql = $db->sql_build_query('SELECT', $sql_array); - $result = $db->sql_query($sql); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query($sql); // Set attachments in feed items - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $this->attachments[$row['post_msg_id']][] = $row; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } - + /** + * {@inheritDoc} + */ public function open() { + parent::open(); $this->fetch_attachments(); } diff --git a/phpBB/phpbb/feed/post_base.php b/phpBB/phpbb/feed/post_base.php index 57eb70ea12..de98f446f3 100644 --- a/phpBB/phpbb/feed/post_base.php +++ b/phpBB/phpbb/feed/post_base.php @@ -49,41 +49,4 @@ abstract class post_base extends \phpbb\feed\attachments_base . (($this->is_moderator_approve_forum($row['forum_id']) && $row['post_visibility'] !== ITEM_APPROVED) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POST_UNAPPROVED'] : ''); } } - - function fetch_attachments() - { - $sql_array = array( - 'SELECT' => 'a.*', - 'FROM' => array( - ATTACHMENTS_TABLE => 'a' - ), - 'WHERE' => 'a.in_message = 0 ', - 'ORDER_BY' => 'a.filetime DESC, a.post_msg_id ASC', - ); - - if (isset($this->topic_id)) - { - $sql_array['WHERE'] .= 'AND a.topic_id = ' . (int) $this->topic_id; - } - else if (isset($this->forum_id)) - { - $sql_array['LEFT_JOIN'] = array( - array( - 'FROM' => array(TOPICS_TABLE => 't'), - 'ON' => 'a.topic_id = t.topic_id', - ) - ); - $sql_array['WHERE'] .= 'AND t.forum_id = ' . (int) $this->forum_id; - } - - $sql = $this->db->sql_build_query('SELECT', $sql_array); - $result = $this->db->sql_query($sql); - - // Set attachments in feed items - while ($row = $this->db->sql_fetchrow($result)) - { - $this->attachments[$row['post_msg_id']][] = $row; - } - $this->db->sql_freeresult($result); - } } -- cgit v1.2.1 From 80b4a7f33726280f523ee84f11f11e852ef71db7 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Tue, 29 Apr 2014 23:27:43 +0200 Subject: [ticket/12413] Fix coding style PHPBB3-12413 --- phpBB/phpbb/feed/attachments_base.php | 1 + phpBB/phpbb/feed/forum.php | 4 ++-- phpBB/phpbb/feed/topic.php | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/phpbb/feed/attachments_base.php b/phpBB/phpbb/feed/attachments_base.php index e61d637afa..a9a8175928 100644 --- a/phpBB/phpbb/feed/attachments_base.php +++ b/phpBB/phpbb/feed/attachments_base.php @@ -60,6 +60,7 @@ abstract class attachments_base extends \phpbb\feed\base } $this->db->sql_freeresult($result); } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/feed/forum.php b/phpBB/phpbb/feed/forum.php index 06e87ec21c..5699a2632c 100644 --- a/phpBB/phpbb/feed/forum.php +++ b/phpBB/phpbb/feed/forum.php @@ -37,6 +37,8 @@ class forum extends \phpbb\feed\post_base function open() { + parent::open(); + // Check if forum exists $sql = 'SELECT forum_id, forum_name, forum_password, forum_type, forum_options FROM ' . FORUMS_TABLE . ' @@ -80,8 +82,6 @@ class forum extends \phpbb\feed\post_base unset($forum_ids_passworded); } - - $this->fetch_attachments(); } function get_sql() diff --git a/phpBB/phpbb/feed/topic.php b/phpBB/phpbb/feed/topic.php index 3c2b3405f6..627ae1ffeb 100644 --- a/phpBB/phpbb/feed/topic.php +++ b/phpBB/phpbb/feed/topic.php @@ -37,6 +37,8 @@ class topic extends \phpbb\feed\post_base function open() { + parent::open(); + $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_visibility, t.topic_title, t.topic_time, t.topic_views, t.topic_posts_approved, t.topic_type FROM ' . TOPICS_TABLE . ' t LEFT JOIN ' . FORUMS_TABLE . ' f @@ -83,8 +85,6 @@ class topic extends \phpbb\feed\post_base unset($forum_ids_passworded); } - - $this->fetch_attachments(); } function get_sql() -- cgit v1.2.1 From 21e2f5c517040e872507c0f6d7e2c10c8a8f51b2 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Tue, 29 Apr 2014 23:49:04 +0200 Subject: [ticket/12413] Move parent:open() call to the end of the function PHPBB3-12413 --- phpBB/phpbb/feed/forum.php | 4 ++-- phpBB/phpbb/feed/topic.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB') diff --git a/phpBB/phpbb/feed/forum.php b/phpBB/phpbb/feed/forum.php index 5699a2632c..8e6490923d 100644 --- a/phpBB/phpbb/feed/forum.php +++ b/phpBB/phpbb/feed/forum.php @@ -37,8 +37,6 @@ class forum extends \phpbb\feed\post_base function open() { - parent::open(); - // Check if forum exists $sql = 'SELECT forum_id, forum_name, forum_password, forum_type, forum_options FROM ' . FORUMS_TABLE . ' @@ -82,6 +80,8 @@ class forum extends \phpbb\feed\post_base unset($forum_ids_passworded); } + + parent::open(); } function get_sql() diff --git a/phpBB/phpbb/feed/topic.php b/phpBB/phpbb/feed/topic.php index 627ae1ffeb..fb49aa65cc 100644 --- a/phpBB/phpbb/feed/topic.php +++ b/phpBB/phpbb/feed/topic.php @@ -37,8 +37,6 @@ class topic extends \phpbb\feed\post_base function open() { - parent::open(); - $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_visibility, t.topic_title, t.topic_time, t.topic_views, t.topic_posts_approved, t.topic_type FROM ' . TOPICS_TABLE . ' t LEFT JOIN ' . FORUMS_TABLE . ' f @@ -85,6 +83,8 @@ class topic extends \phpbb\feed\post_base unset($forum_ids_passworded); } + + parent::open(); } function get_sql() -- cgit v1.2.1