1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-02 22:02:07 +02:00

[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
This commit is contained in:
erangamapa 2013-04-06 20:13:46 +05:30 committed by Dhruv
parent 098fdf95ae
commit 86d83f2bb2

View File

@ -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);
}
}
/**