]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/OStatusPlugin.php
Check that the user is in the context of a salmon slap
[quix0rs-gnu-social.git] / plugins / OStatus / OStatusPlugin.php
index 06aaa54ce6a1764378a591ebeb80b84c31064364..c108e78e6c13a262bf446c60271ede6400c2a39c 100644 (file)
@@ -285,6 +285,7 @@ class OStatusPlugin extends Plugin
     {
         $matches = array();
 
+        $wmatches = array();
         // Webfinger matches: @user@example.com or even @user--one.george_orwell@1984.biz
         if (preg_match_all('!(?:^|\s+)@((?:\w+[\w\-\_\.]?)*(?:[\w\-\_\.]*\w+)@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
                        $text,
@@ -293,26 +294,36 @@ class OStatusPlugin extends Plugin
             foreach ($wmatches[1] as $wmatch) {
                 list($target, $pos) = $wmatch;
                 $this->log(LOG_INFO, "Checking webfinger '$target'");
+                $profile = null;
                 try {
                     $oprofile = Ostatus_profile::ensureWebfinger($target);
-                    if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
-                        $profile = $oprofile->localProfile();
-                        $text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target) ?
-                                $profile->nickname : $target;
-                        $url = $profile->getUri();
-                        if (!common_valid_http_url($url)) {
-                            $url = $profile->getUrl();
-                        }
-                        $matches[$pos] = array('mentioned' => array($profile),
-                                               'type' => 'mention',
-                                               'text' => $text,
-                                               'position' => $pos,
-                                               'length' => mb_strlen($target),
-                                               'url' => $url);
+                    if (!$oprofile instanceof Ostatus_profile || !$oprofile->isPerson()) {
+                        continue;
                     }
+                    $profile = $oprofile->localProfile();
+                } catch (OStatusShadowException $e) {
+                    // This means we got a local user in the webfinger lookup
+                    $profile = $e->profile;
                 } catch (Exception $e) {
                     $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
+                    continue;
+                }
+
+                assert($profile instanceof Profile);
+
+                $text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target)
+                        ? $profile->getNickname()   // TODO: we could do getFancyName() or getFullname() here
+                        : $target;
+                $url = $profile->getUri();
+                if (!common_valid_http_url($url)) {
+                    $url = $profile->getUrl();
                 }
+                $matches[$pos] = array('mentioned' => array($profile),
+                                       'type' => 'mention',
+                                       'text' => $text,
+                                       'position' => $pos,
+                                       'length' => mb_strlen($target),
+                                       'url' => $url);
             }
         }