]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/OStatusPlugin.php
Merge branch 'foolproof_file_redirection_branch' into 'nightly'
[quix0rs-gnu-social.git] / plugins / OStatus / OStatusPlugin.php
index 06aaa54ce6a1764378a591ebeb80b84c31064364..17ce8e46236200f5b954f1c44fbe00e58d4b9f99 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);
             }
         }
 
@@ -658,7 +669,7 @@ class OStatusPlugin extends Plugin
                                $other->getBestName());
 
         $act->actor   = $profile->asActivityObject();
-        $act->object  = $other->asActivityObject();
+        $act->objects[] = $other->asActivityObject();
 
         $oprofile->notifyActivity($act, $profile);
 
@@ -696,7 +707,7 @@ class OStatusPlugin extends Plugin
 
         $act->actor = $profile->asActivityObject();
         $act->verb = ActivityVerb::JOIN;
-        $act->object = $oprofile->asActivityObject();
+        $act->objects[] = $oprofile->asActivityObject();
 
         $act->time = time();
         // TRANS: Title for joining a remote groep.
@@ -750,7 +761,7 @@ class OStatusPlugin extends Plugin
 
         $act->actor = $member->asActivityObject();
         $act->verb = ActivityVerb::LEAVE;
-        $act->object = $oprofile->asActivityObject();
+        $act->objects[] = $oprofile->asActivityObject();
 
         $act->time = time();
         // TRANS: Title for leaving a remote group.
@@ -796,7 +807,7 @@ class OStatusPlugin extends Plugin
 
         $act->actor = $sub->asActivityObject();
         $act->verb = ActivityVerb::FOLLOW;
-        $act->object = $oprofile->asActivityObject();
+        $act->objects[] = $oprofile->asActivityObject();
 
         $act->time = time();
         // TRANS: Title for following a remote list.
@@ -848,7 +859,7 @@ class OStatusPlugin extends Plugin
 
         $act->actor = $member->asActivityObject();
         $act->verb = ActivityVerb::UNFOLLOW;
-        $act->object = $oprofile->asActivityObject();
+        $act->objects[] = $oprofile->asActivityObject();
 
         $act->time = time();
         // TRANS: Title for unfollowing a remote list.
@@ -1040,7 +1051,7 @@ class OStatusPlugin extends Plugin
                                $notice->getUrl());
 
         $act->actor   = $profile->asActivityObject();
-        $act->object  = $notice->asActivityObject();
+        $act->objects[]  = $notice->asActivityObject();
 
         $oprofile->notifyActivity($act, $profile);
 
@@ -1162,7 +1173,7 @@ class OStatusPlugin extends Plugin
                                $profile->getBestName());
 
         $act->actor   = $profile->asActivityObject();
-        $act->object  = $act->actor;
+        $act->objects[]  = $act->actor;
 
         while ($oprofile->fetch()) {
             $oprofile->notifyDeferred($act, $profile);
@@ -1218,7 +1229,7 @@ class OStatusPlugin extends Plugin
         $versions[] = array('name' => 'OStatus',
                             'version' => GNUSOCIAL_VERSION,
                             'author' => 'Evan Prodromou, James Walker, Brion Vibber, Zach Copley',
-                            'homepage' => 'http://status.net/wiki/Plugin:OStatus',
+                            'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/OStatus',
                             // TRANS: Plugin description.
                             'rawdescription' => _m('Follow people across social networks that implement '.
                                '<a href="http://ostatus.org/">OStatus</a>.'));