mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00: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:
parent
91a14a9e63
commit
8586171187
1 changed files with 44 additions and 35 deletions
|
@ -72,39 +72,8 @@ if ($feed === false)
|
||||||
trigger_error('NO_FEED');
|
trigger_error('NO_FEED');
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql_array = array(
|
// Get attachments for this feed
|
||||||
'SELECT' => 'a.*',
|
$feed->fetch_attachments();
|
||||||
'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);
|
|
||||||
|
|
||||||
// Open Feed
|
// Open Feed
|
||||||
$feed->open();
|
$feed->open();
|
||||||
|
@ -141,7 +110,7 @@ while ($row = $feed->get_item())
|
||||||
'title' => censor_text($title),
|
'title' => censor_text($title),
|
||||||
'category' => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '',
|
'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'] : '',
|
'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' => '',
|
'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);
|
$content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
|
||||||
|
|
||||||
// Parse inline images to display with the feed
|
// Parse inline images to display with the feed
|
||||||
if ($post_attachments != null)
|
if (count($post_attachments) > 0)
|
||||||
{
|
{
|
||||||
$update_count = array();
|
$update_count = array();
|
||||||
parse_attachments($forum_id, $content, $post_attachments, $update_count);
|
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
|
class phpbb_feed_post_base extends phpbb_feed_base
|
||||||
{
|
{
|
||||||
var $num_items = 'feed_limit_post';
|
var $num_items = 'feed_limit_post';
|
||||||
|
var $attachments = array();
|
||||||
|
|
||||||
function set_keys()
|
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'] : '');
|
. (($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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue