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

Merge branch 'ticket/11271' into ticket/11271-develop

# By erangamapa (7) and Dhruv (2)
* ticket/11271:
  [ticket/11271] Typecast forum and topic id to integer
  [ticket/11271] Use absolute path for displaying inline attachments in feeds
  [ticket/11271] Changed executable bit.
  [ticket/11271] Formatting code and removing null assignment.
  [ticket/11271] Removing unnecessary database object
  [ticket/11271] Separated attachment fetching query
  [ticket/11271] Fetched feed attachments before loop.
  [ticket/11271] Removed in-line attachment comments properly.
  [ticket/11271] Displaying in-line attached images in ATOM feed.

Conflicts:
	phpBB/feed.php
This commit is contained in:
Dhruv 2013-10-05 16:54:09 +05:30
commit 7a971f896d
9 changed files with 63 additions and 9 deletions

View File

@ -18,6 +18,7 @@ define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
if (!$config['feed_enable'])
{
@ -72,6 +73,9 @@ if ($feed === false)
trigger_error('NO_FEED');
}
// Get attachments for this feed
$feed->fetch_attachments();
// Open Feed
$feed->open();
@ -107,7 +111,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($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)),
'description' => censor_text($phpbb_feed_helper->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']] : array()))),
'statistics' => '',
);

View File

@ -117,7 +117,7 @@ class forum extends \phpbb\feed\post_base
}
$this->sql = array(
'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, ' .
'u.username, u.user_id',
'FROM' => array(
POSTS_TABLE => 'p',

View File

@ -90,7 +90,7 @@ class helper
/**
* Generate text content
*/
public function generate_content($content, $uid, $bitfield, $options)
public function generate_content($content, $uid, $bitfield, $options, $forum_id, $post_attachments)
{
if (empty($content))
{
@ -137,8 +137,15 @@ class helper
// Remove some specials html tag, because somewhere there are a mod to allow html tags ;)
$content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
// Parse inline images to display with the feed
if (count($post_attachments) > 0)
{
$update_count = array();
parse_attachments($forum_id, $content, $post_attachments, $update_count);
}
// Remove Comments from inline attachments [ia]
$content = preg_replace('#<div class="(inline-attachment|attachtitle)">(.*?)<!-- ia(.*?) -->(.*?)<!-- ia(.*?) -->(.*?)</div>#si','$4',$content);
$content = preg_replace('#<dd>(.*?)</dd>#','',$content);
// Replace some entities with their unicode counterpart
$entities = array(
@ -156,6 +163,9 @@ class helper
// Other control characters
$content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content);
// Convert attachments' relative path to absolute path
$content = str_replace($this->phpbb_root_path . 'download', $this->get_board_url() . '/download', $content);
return $content;
}
}

View File

@ -93,7 +93,7 @@ class news extends \phpbb\feed\topic_base
$this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name,
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views, t.topic_time, t.topic_last_post_time,
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment',
'FROM' => array(
TOPICS_TABLE => 't',
POSTS_TABLE => 'p',

View File

@ -61,7 +61,7 @@ class overall extends \phpbb\feed\post_base
// Get the actual data
$this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, ' .
'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, ' .
'u.username, u.user_id',
'FROM' => array(
USERS_TABLE => 'u',

View File

@ -25,6 +25,7 @@ if (!defined('IN_PHPBB'))
abstract class post_base extends \phpbb\feed\base
{
var $num_items = 'feed_limit_post';
var $attachments = array();
function set_keys()
{
@ -56,4 +57,43 @@ abstract class post_base extends \phpbb\feed\base
. (($this->is_moderator_approve_forum($row['forum_id']) && $row['post_visibility'] !== ITEM_APPROVED) ? ' ' . $this->separator_stats . ' ' . $this->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 = ' . (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);
}
}

View File

@ -96,7 +96,7 @@ class topic extends \phpbb\feed\post_base
function get_sql()
{
$this->sql = array(
'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, ' .
'u.username, u.user_id',
'FROM' => array(
POSTS_TABLE => 'p',

View File

@ -65,7 +65,7 @@ class topics extends \phpbb\feed\topic_base
$this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name,
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views, t.topic_time, t.topic_last_post_time,
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment',
'FROM' => array(
TOPICS_TABLE => 't',
POSTS_TABLE => 'p',

View File

@ -82,7 +82,7 @@ class topics_active extends \phpbb\feed\topic_base
'SELECT' => 'f.forum_id, f.forum_name,
t.topic_id, t.topic_title, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views,
t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time,
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment',
'FROM' => array(
TOPICS_TABLE => 't',
POSTS_TABLE => 'p',