[ticket/15245] Configure TextFormatter before rendering feeds

PHPBB3-15245
This commit is contained in:
Oliver Schramm 2017-09-28 20:02:15 +02:00
parent 4a7ead0239
commit 3da67ce581
3 changed files with 49 additions and 14 deletions

View file

@ -19,9 +19,8 @@ services:
arguments:
- '@config'
- '@path_helper'
- '@text_formatter.renderer'
- '@user'
- '%core.root_path%'
- '%core.php_ext%'
feed.forum:
class: phpbb\feed\forum

View file

@ -0,0 +1,35 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\feed;
/**
* Modified quote_helper for feeds (basically just removing all attributes)
*/
class feed_quote_helper extends \phpbb\textformatter\s9e\quote_helper
{
/**
* {@inheritdoc}
*/
public function inject_metadata($xml)
{
// In feeds we don't want any attributes, so delete all of them
return \s9e\TextFormatter\Utils::replaceAttributes(
$xml,
'QUOTE',
function () {
return [];
}
);
}
}

View file

@ -24,6 +24,9 @@ class helper
/** @var \phpbb\path_helper */
protected $path_helper;
/** @var \phpbb\textformatter\s9e\renderer */
protected $renderer;
/** @var \phpbb\user */
protected $user;
@ -32,12 +35,14 @@ class helper
*
* @param \phpbb\config\config $config Config object
* @param \phpbb\path_helper $path_helper Path helper object
* @param \phpbb\textformatter\s9e\renderer $renderer TextFormatter renderer object
* @param \phpbb\user $user User object
*/
public function __construct(\phpbb\config\config $config, \phpbb\path_helper $path_helper, \phpbb\user $user)
public function __construct(\phpbb\config\config $config, \phpbb\path_helper $path_helper, \phpbb\textformatter\s9e\renderer $renderer, \phpbb\user $user)
{
$this->config = $config;
$this->path_helper = $path_helper;
$this->renderer = $renderer;
$this->user = $user;
}
@ -99,17 +104,13 @@ class helper
return '';
}
// Prepare some bbcodes for better parsing
$content = preg_replace("#\[quote(=&quot;.*?&quot;)?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content);
// Setup our own quote_helper to remove all attributes from quotes
$this->renderer->configure_quote_helper(new feed_quote_helper($this->user, $this->path_helper->get_phpbb_root_path(), $this->path_helper->get_php_ext()));
$this->renderer->set_smilies_path($this->get_board_url() . '/' . $this->config['smilies_path']);
$content = generate_text_for_display($content, $uid, $bitfield, $options);
// Add newlines
$content = str_replace('<br />', '<br />' . "\n", $content);
// Convert smiley Relative paths to Absolute path, Windows style
$content = str_replace($this->path_helper->get_web_root_path() . $this->config['smilies_path'], $this->get_board_url() . '/' . $this->config['smilies_path'], $content);
// Remove "Select all" link and mouse events
$content = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $this->user->lang['SELECT_ALL_CODE'] . '</a>', '', $content);
$content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);