diff options
author | erangamapa <erangamapa@gmail.com> | 2013-04-06 20:13:46 +0530 |
---|---|---|
committer | Dhruv <dhruv.goel92@gmail.com> | 2013-12-27 00:22:21 +0530 |
commit | 85861711872c0f9a9064e0043764f6c752a915d7 (patch) | |
tree | efd0abcf02e121970bc3ae6459fb0b7576caf868 /phpBB | |
parent | 91a14a9e636e761ef18632e850518d4ba5b7eb90 (diff) | |
download | forums-85861711872c0f9a9064e0043764f6c752a915d7.tar forums-85861711872c0f9a9064e0043764f6c752a915d7.tar.gz forums-85861711872c0f9a9064e0043764f6c752a915d7.tar.bz2 forums-85861711872c0f9a9064e0043764f6c752a915d7.tar.xz forums-85861711872c0f9a9064e0043764f6c752a915d7.zip |
[ticket/11271] Separated attachment fetching query
Removed external query used to fetch related attachments.
Added attachments fetching method with database query to
post based feed.
PHPBB3-11271
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/feed.php | 79 |
1 files changed, 44 insertions, 35 deletions
diff --git a/phpBB/feed.php b/phpBB/feed.php index 570240fe93..6a83bba562 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -72,39 +72,8 @@ if ($feed === false) trigger_error('NO_FEED'); } -$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 ($topic_id) -{ - $sql_array['WHERE'] .= 'AND a.topic_id = ' . $topic_id; -} -else if ($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 = ' . $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)) -{ - $attachments[$row['post_msg_id']][] = $row; -} -$db->sql_freeresult($result); +// Get attachments for this feed +$feed->fetch_attachments(); // Open Feed $feed->open(); @@ -141,7 +110,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(feed_generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], (($row['post_attachment']) ? $attachments[$row['post_id']] : null))), + 'description' => censor_text(feed_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']] : null))), 'statistics' => '', ); @@ -358,7 +327,7 @@ function feed_generate_content($content, $uid, $bitfield, $options, $forum_id, $ $content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content); // Parse inline images to display with the feed - if ($post_attachments != null) + if (count($post_attachments) > 0) { $update_count = array(); parse_attachments($forum_id, $content, $post_attachments, $update_count); @@ -702,6 +671,7 @@ class phpbb_feed_base class phpbb_feed_post_base extends phpbb_feed_base { var $num_items = 'feed_limit_post'; + var $attachments = array(); function set_keys() { @@ -735,6 +705,45 @@ class phpbb_feed_post_base extends phpbb_feed_base . (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POST_UNAPPROVED'] : ''); } } + + 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 = ' . $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 = ' . $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); + } } /** |