mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 12:28:52 +00:00
[ticket/15245] Configure TextFormatter before rendering feeds
PHPBB3-15245
This commit is contained in:
parent
4a7ead0239
commit
3da67ce581
3 changed files with 49 additions and 14 deletions
|
@ -19,9 +19,8 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- '@config'
|
- '@config'
|
||||||
- '@path_helper'
|
- '@path_helper'
|
||||||
|
- '@text_formatter.renderer'
|
||||||
- '@user'
|
- '@user'
|
||||||
- '%core.root_path%'
|
|
||||||
- '%core.php_ext%'
|
|
||||||
|
|
||||||
feed.forum:
|
feed.forum:
|
||||||
class: phpbb\feed\forum
|
class: phpbb\feed\forum
|
||||||
|
|
35
phpBB/phpbb/feed/feed_quote_helper.php
Normal file
35
phpBB/phpbb/feed/feed_quote_helper.php
Normal 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 [];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,20 +24,25 @@ class helper
|
||||||
/** @var \phpbb\path_helper */
|
/** @var \phpbb\path_helper */
|
||||||
protected $path_helper;
|
protected $path_helper;
|
||||||
|
|
||||||
|
/** @var \phpbb\textformatter\s9e\renderer */
|
||||||
|
protected $renderer;
|
||||||
|
|
||||||
/** @var \phpbb\user */
|
/** @var \phpbb\user */
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param \phpbb\config\config $config Config object
|
* @param \phpbb\config\config $config Config object
|
||||||
* @param \phpbb\path_helper $path_helper Path helper object
|
* @param \phpbb\path_helper $path_helper Path helper object
|
||||||
* @param \phpbb\user $user User 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->config = $config;
|
||||||
$this->path_helper = $path_helper;
|
$this->path_helper = $path_helper;
|
||||||
|
$this->renderer = $renderer;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,17 +104,13 @@ class helper
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare some bbcodes for better parsing
|
// Setup our own quote_helper to remove all attributes from quotes
|
||||||
$content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content);
|
$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);
|
$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
|
// 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 = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $this->user->lang['SELECT_ALL_CODE'] . '</a>', '', $content);
|
||||||
$content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);
|
$content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);
|
||||||
|
|
Loading…
Add table
Reference in a new issue