1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/13680] Updated quote notifications

Added get_quote_authors() to text_formatter.utils service to retrieve
the names used in first-level quotes

PHPBB3-13680
This commit is contained in:
JoshyPHP
2015-05-03 16:06:42 +02:00
parent 98db63e8cc
commit f5ce9f2738
9 changed files with 126 additions and 31 deletions

View File

@@ -221,6 +221,8 @@ services:
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
calls:
- [set_utils, [@text_formatter.utils]]
tags:
- { name: notification.type }

View File

@@ -20,6 +20,11 @@ namespace phpbb\notification\type;
class quote extends \phpbb\notification\type\post
{
/**
* @var \phpbb\textformatter\utils_interface
*/
protected $utils;
/**
* Get notification type name
*
@@ -30,13 +35,6 @@ class quote extends \phpbb\notification\type\post
return 'notification.type.quote';
}
/**
* regular expression to match to find usernames
*
* @var string
*/
protected static $regular_expression_match = '#\[quote="(.+?)"#';
/**
* Language key used to output the text
*
@@ -77,17 +75,16 @@ class quote extends \phpbb\notification\type\post
'ignore_users' => array(),
), $options);
$usernames = false;
preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames);
$usernames = $this->utils->get_quote_authors($post['post_text']);
if (empty($usernames[1]))
if (empty($usernames))
{
return array();
}
$usernames[1] = array_unique($usernames[1]);
$usernames = array_unique($usernames);
$usernames = array_map('utf8_clean_string', $usernames[1]);
$usernames = array_map('utf8_clean_string', $usernames);
$users = array();
@@ -187,4 +184,14 @@ class quote extends \phpbb\notification\type\post
'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']),
));
}
/**
* Set the utils service used to retrieve quote authors
*
* @param \phpbb\textformatter\utils_interface $utils
*/
public function set_utils(\phpbb\textformatter\utils_interface $utils)
{
$this->utils = $utils;
}
}

View File

@@ -34,6 +34,31 @@ class utils implements \phpbb\textformatter\utils_interface
return \s9e\TextFormatter\Utils::removeFormatting($xml);
}
/**
* Get a list of quote authors, limited to the first level of quotes
*
* @param string $xml Parsed text
* @return string[] List of authors
*/
public function get_quote_authors($xml)
{
$authors = array();
if (strpos($xml, '<QUOTE ') === false)
{
return $authors;
}
$dom = new \DOMDocument;
$dom->loadXML($xml);
$xpath = new \DOMXPath($dom);
foreach ($xpath->query('//QUOTE[not(ancestor::QUOTE)]/@author') as $author)
{
$authors[] = $author->textContent;
}
return $authors;
}
/**
* Remove given BBCode and its content, at given nesting depth
*

View File

@@ -28,6 +28,14 @@ interface utils_interface
*/
public function clean_formatting($text);
/**
* Get a list of quote authors, limited to the first level of quotes
*
* @param string $text Parsed text
* @return string[] List of authors
*/
public function get_quote_authors($text);
/**
* Remove given BBCode and its content, at given nesting depth
*