Avoid notifications for quotes with an external source
authorAlexander Ebert <ebert@woltlab.com>
Fri, 11 May 2018 10:21:01 +0000 (12:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 11 May 2018 10:21:01 +0000 (12:21 +0200)
wcfsetup/install/files/lib/util/MessageUtil.class.php

index 5a51e3d0d20f4ffcf83bd48aeaa3756a38daf469..589c06699399d7d386cce2c587c8f6fa80501fe9 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\util;
+use wcf\system\application\ApplicationHandler;
 use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\Regex;
 
@@ -70,13 +71,31 @@ class MessageUtil {
         * @return      string[]                quoted usernames
         */
        public static function getQuotedUsers(HtmlInputProcessor $htmlInputProcessor) {
+               static $ownHosts;
+               if ($ownHosts === null) {
+                       $ownHosts = [];
+                       foreach (ApplicationHandler::getInstance()->getApplications() as $application) {
+                               if (!in_array($application->domainName, $ownHosts)) $ownHosts[] = $application->domainName;
+                       }
+               }
+               
                $usernames = [];
                
                $elements = $htmlInputProcessor->getHtmlInputNodeProcessor()->getDocument()->getElementsByTagName('woltlab-quote');
                /** @var \DOMElement $element */
                foreach ($elements as $element) {
                        $username = $element->getAttribute('data-author');
-                       if (!empty($username)) $usernames[] = $username;
+                       if (!empty($username)) {
+                               // check if there is a link set and if it points to any of the apps
+                               $link = $element->getAttribute('data-link');
+                               $host = ($link) ? Url::parse($link)['host'] : '';
+                               if ($host && !in_array($host, $ownHosts)) {
+                                       // links mismatch, do not treat this occurrence as a username
+                                       continue;
+                               }
+                               
+                               $usernames[] = $username;
+                       }
                }
                
                return $usernames;