diff options
| author | Nicofuma <github@nicofuma.fr> | 2015-05-20 00:38:49 +0200 |
|---|---|---|
| committer | Nicofuma <github@nicofuma.fr> | 2015-05-20 00:38:49 +0200 |
| commit | c5493c2bb8e56e59cb3177d62a48a61fadf95303 (patch) | |
| tree | b6ecc2d6e5f1ae51dde98b5f145cb3cac72c0cf5 /phpBB/phpbb | |
| parent | fda5a83b6daa66d7080c8de04cfedc15279a1204 (diff) | |
| parent | f7ad2c2b32b309edba006a8d4b58727b50642ea2 (diff) | |
| download | forums-c5493c2bb8e56e59cb3177d62a48a61fadf95303.tar forums-c5493c2bb8e56e59cb3177d62a48a61fadf95303.tar.gz forums-c5493c2bb8e56e59cb3177d62a48a61fadf95303.tar.bz2 forums-c5493c2bb8e56e59cb3177d62a48a61fadf95303.tar.xz forums-c5493c2bb8e56e59cb3177d62a48a61fadf95303.zip | |
Merge pull request #3586 from s9e/ticket/13680
[ticket/13680] Updated quote notifications
Diffstat (limited to 'phpBB/phpbb')
| -rw-r--r-- | phpBB/phpbb/notification/type/quote.php | 31 | ||||
| -rw-r--r-- | phpBB/phpbb/textformatter/s9e/utils.php | 25 | ||||
| -rw-r--r-- | phpBB/phpbb/textformatter/utils_interface.php | 8 |
3 files changed, 52 insertions, 12 deletions
diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 141f90c7ae..51edfec6f7 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -21,6 +21,11 @@ namespace phpbb\notification\type; class quote extends \phpbb\notification\type\post { /** + * @var \phpbb\textformatter\utils_interface + */ + protected $utils; + + /** * Get notification type name * * @return string @@ -31,13 +36,6 @@ class quote extends \phpbb\notification\type\post } /** - * regular expression to match to find usernames - * - * @var string - */ - protected static $regular_expression_match = '#\[quote="(.+?)"#'; - - /** * Language key used to output the text * * @var string @@ -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_outermost_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; + } } diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 2018bbf519..e21dedecc4 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -35,6 +35,31 @@ class utils implements \phpbb\textformatter\utils_interface } /** + * Get a list of quote authors, limited to the outermost quotes + * + * @param string $xml Parsed text + * @return string[] List of authors + */ + public function get_outermost_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 * * @param string $xml Parsed text diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 132dc8ece4..6d3fd13021 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -29,6 +29,14 @@ interface utils_interface public function clean_formatting($text); /** + * Get a list of quote authors, limited to the outermost quotes + * + * @param string $text Parsed text + * @return string[] List of authors + */ + public function get_outermost_quote_authors($text); + + /** * Remove given BBCode and its content, at given nesting depth * * @param string $text Parsed text |
