diff options
author | Tristan Darricau <github@darricau.eu> | 2014-04-16 23:41:10 +0200 |
---|---|---|
committer | Nicofuma <github@nicofuma.fr> | 2014-05-02 13:25:33 +0200 |
commit | e7f970e26d636d69ea742bf591dc5fc9dc15a0a9 (patch) | |
tree | 49041efdbac7f89204fefa3f42f331a9781a5f2f /phpBB/phpbb/feed/attachments_base.php | |
parent | 76574d4b5e6c2f6de0faf175c745bcdc74c60f4e (diff) | |
download | forums-e7f970e26d636d69ea742bf591dc5fc9dc15a0a9.tar forums-e7f970e26d636d69ea742bf591dc5fc9dc15a0a9.tar.gz forums-e7f970e26d636d69ea742bf591dc5fc9dc15a0a9.tar.bz2 forums-e7f970e26d636d69ea742bf591dc5fc9dc15a0a9.tar.xz forums-e7f970e26d636d69ea742bf591dc5fc9dc15a0a9.zip |
[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
Diffstat (limited to 'phpBB/phpbb/feed/attachments_base.php')
-rw-r--r-- | phpBB/phpbb/feed/attachments_base.php | 81 |
1 files changed, 81 insertions, 0 deletions
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 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\feed; + +/** +* Abstract class for feeds displaying attachments +* +* @package phpBB3 +*/ +abstract class attachments_base extends \phpbb\feed\base +{ + /** + * Attachments that may be displayed + */ + protected $attachments = array(); + + function open() + { + $this->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]; + } +} |