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/phpbb/feed/attachments_base.php | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 phpBB/phpbb/feed/attachments_base.php (limited to 'phpBB/phpbb/feed/attachments_base.php') 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]; + } +} -- cgit v1.2.1