[ticket/13713] Remove unneeded code in helper

PHPBB3-13713
This commit is contained in:
lavigor 2018-08-06 14:17:34 +03:00 committed by Marc Alexander
parent d91e3bd66a
commit 89d65f5da0
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
2 changed files with 10 additions and 26 deletions

View file

@ -75,7 +75,7 @@ class mention extends \phpbb\notification\type\post
'ignore_users' => array(), 'ignore_users' => array(),
), $options); ), $options);
$user_ids = $this->helper->get_mentioned_ids($post['post_text']); $user_ids = $this->helper->get_mentioned_user_ids($post['post_text']);
$user_ids = array_unique($user_ids); $user_ids = array_unique($user_ids);

View file

@ -242,14 +242,12 @@ class mention_helper
} }
/** /**
* Get a list of mentioned names * Get a list of mentioned user IDs
* *
* @param string $xml Parsed text * @param string $xml Parsed text
* @param string $type Name type ('u' for users, 'g' for groups, * @return int[] List of user IDs
* 'ug' for usernames mentioned separately or as group members)
* @return int[] List of IDs
*/ */
public function get_mentioned_ids($xml, $type = 'ug') public function get_mentioned_user_ids($xml)
{ {
$ids = array(); $ids = array();
if (strpos($xml, '<MENTION ') === false) if (strpos($xml, '<MENTION ') === false)
@ -261,30 +259,16 @@ class mention_helper
$dom->loadXML($xml); $dom->loadXML($xml);
$xpath = new \DOMXPath($dom); $xpath = new \DOMXPath($dom);
if ($type === 'ug') /** @var \DOMElement $mention */
foreach ($xpath->query('//MENTION') as $mention)
{ {
/** @var \DOMElement $mention */ if ($mention->getAttribute('type') === 'u')
foreach ($xpath->query('//MENTION') as $mention)
{ {
if ($mention->getAttribute('type') === 'u') $ids[] = (int) $mention->getAttribute('id');
{
$ids[] = (int) $mention->getAttribute('id');
}
else if ($mention->getAttribute('type') === 'g')
{
$this->get_user_ids_for_group($ids, (int) $mention->getAttribute('id'));
}
} }
} else if ($mention->getAttribute('type') === 'g')
else
{
/** @var \DOMElement $mention */
foreach ($xpath->query('//MENTION') as $mention)
{ {
if ($mention->getAttribute('type') === $type) $this->get_user_ids_for_group($ids, (int) $mention->getAttribute('id'));
{
$ids[] = (int) $mention->getAttribute('id');
}
} }
} }