1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-19 07:08:09 +01:00

Merge remote-tracking branch 'dhruvgoel92/ticket/11271-develop' into develop

* dhruvgoel92/ticket/11271-develop: (25 commits)
  [ticket/11271] Make path conversion more precise
  [ticket/11271] limit absolute path conversion to attachment links only
  [ticket/11271] Add docblock of feed_generate_content( )
  [ticket/11271] Fix tabs and use !empty( ) instead of count( )
  [ticket/11271] Remove unnecessary inclusion of functions_display
  [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.
  [ticket/11271] Add the inline images html to content
  [ticket/11271] Use class variable $db instead of global
  [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.
  ...
This commit is contained in:
Joas Schilling 2014-03-11 09:53:52 +01:00
commit 296af6c679
10 changed files with 78 additions and 10 deletions

View File

@ -5,6 +5,7 @@ services:
- @config - @config
- @user - @user
- %core.root_path% - %core.root_path%
- %core.php_ext%
feed.factory: feed.factory:
class: phpbb\feed\factory class: phpbb\feed\factory

View File

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

View File

@ -109,7 +109,7 @@ class forum extends \phpbb\feed\post_base
} }
$this->sql = array( $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', 'u.username, u.user_id',
'FROM' => array( 'FROM' => array(
POSTS_TABLE => 'p', POSTS_TABLE => 'p',

View File

@ -24,6 +24,9 @@ class helper
/** @var string */ /** @var string */
protected $phpbb_root_path; protected $phpbb_root_path;
/** @var string */
protected $phpEx;
/** /**
* Constructor * Constructor
* *
@ -32,11 +35,12 @@ class helper
* @param string $phpbb_root_path Root path * @param string $phpbb_root_path Root path
* @return null * @return null
*/ */
public function __construct(\phpbb\config\config $config, \phpbb\user $user, $phpbb_root_path) public function __construct(\phpbb\config\config $config, \phpbb\user $user, $phpbb_root_path, $phpEx)
{ {
$this->config = $config; $this->config = $config;
$this->user = $user; $this->user = $user;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
} }
/** /**
@ -81,8 +85,16 @@ class helper
/** /**
* Generate text content * Generate text content
*
* @param string $content is feed text content
* @param string $uid is bbcode_uid
* @param string $bitfield is bbcode bitfield
* @param int $options bbcode flag options
* @param int $forum_id is the forum id
* @param array $post_attachments is an array containing the attachments and their respective info
* @return string the html content to be printed for the feed
*/ */
public function generate_content($content, $uid, $bitfield, $options) public function generate_content($content, $uid, $bitfield, $options, $forum_id, $post_attachments)
{ {
if (empty($content)) if (empty($content))
{ {
@ -129,8 +141,21 @@ class helper
// Remove some specials html tag, because somewhere there are a mod to allow html tags ;) // 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); $content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
// Parse inline images to display with the feed
if (!empty($post_attachments))
{
$update_count = array();
parse_attachments($forum_id, $content, $post_attachments, $update_count);
$post_attachments = implode('<br />', $post_attachments);
// Convert attachments' relative path to absolute path
$post_attachments = str_replace($this->phpbb_root_path . 'download/file.' . $this->phpEx, $this->get_board_url() . '/download/file.' . $this->phpEx, $post_attachments);
$content .= $post_attachments;
}
// Remove Comments from inline attachments [ia] // 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 // Replace some entities with their unicode counterpart
$entities = array( $entities = array(

View File

@ -85,7 +85,7 @@ class news extends \phpbb\feed\topic_base
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, '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, 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( 'FROM' => array(
TOPICS_TABLE => 't', TOPICS_TABLE => 't',
POSTS_TABLE => 'p', POSTS_TABLE => 'p',

View File

@ -53,7 +53,7 @@ class overall extends \phpbb\feed\post_base
// Get the actual data // Get the actual data
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, ' . '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', 'u.username, u.user_id',
'FROM' => array( 'FROM' => array(
USERS_TABLE => 'u', USERS_TABLE => 'u',

View File

@ -17,6 +17,7 @@ namespace phpbb\feed;
abstract class post_base extends \phpbb\feed\base abstract class 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()
{ {
@ -48,4 +49,41 @@ 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'] : ''); . (($this->is_moderator_approve_forum($row['forum_id']) && $row['post_visibility'] !== ITEM_APPROVED) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POST_UNAPPROVED'] : '');
} }
} }
function fetch_attachments()
{
$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 = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query($sql);
// Set attachments in feed items
while ($row = $this->db->sql_fetchrow($result))
{
$this->attachments[$row['post_msg_id']][] = $row;
}
$this->db->sql_freeresult($result);
}
} }

View File

@ -88,7 +88,7 @@ class topic extends \phpbb\feed\post_base
function get_sql() function get_sql()
{ {
$this->sql = array( $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', 'u.username, u.user_id',
'FROM' => array( 'FROM' => array(
POSTS_TABLE => 'p', POSTS_TABLE => 'p',

View File

@ -57,7 +57,7 @@ class topics extends \phpbb\feed\topic_base
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, '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, 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( 'FROM' => array(
TOPICS_TABLE => 't', TOPICS_TABLE => 't',
POSTS_TABLE => 'p', POSTS_TABLE => 'p',

View File

@ -74,7 +74,7 @@ class topics_active extends \phpbb\feed\topic_base
'SELECT' => 'f.forum_id, f.forum_name, '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_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, 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( 'FROM' => array(
TOPICS_TABLE => 't', TOPICS_TABLE => 't',
POSTS_TABLE => 'p', POSTS_TABLE => 'p',