]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityutils.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / lib / activityutils.php
index 07d8a86141a9456458bc73043cd753af40dd056b..a0fc4872328e0f5103aea0797727098e9f5196db 100644 (file)
@@ -300,7 +300,7 @@ class ActivityUtils
         return false;
     }
 
-    static function getFeedAuthor($feedEl)
+    static function getFeedAuthor(DOMElement $feedEl)
     {
         // Try old and deprecated activity:subject
 
@@ -347,10 +347,10 @@ class ActivityUtils
         return null;
     }
 
-    static function compareTypes($type, $objects)    // this does verbs too!
+    static function compareTypes($type, array $objects)    // this does verbs too!
     {
         $type = self::resolveUri($type);
-        foreach ((array)$objects as $object) {
+        foreach ($objects as $object) {
             if ($type === self::resolveUri($object)) {
                 return true;
             }
@@ -398,8 +398,49 @@ class ActivityUtils
         if (!empty($object)) {
             Event::handle('EndFindLocalActivityObject', array($object->getUri(), $type, $object));
         } else {
-            throw new Exception('Could not find any activityobject stored locally with given URI');
+            throw new ServerException('Could not find any activityobject stored locally with given URI');
         }
         return $object;
     }
+
+    // Check authorship by supplying a Profile as a default and letting plugins
+    // set it to something else if the activity's author is actually someone
+    // else (like with a group or peopletag feed as handled in OStatus).
+    //
+    // NOTE: Returned is not necessarily the supplied profile! For example,
+    // the "feed author" may be a group, but the "activity author" is a person!
+    static function checkAuthorship(Activity $activity, Profile $profile)
+    {
+        if (Event::handle('CheckActivityAuthorship', array($activity, &$profile))) {
+            // if (empty($activity->actor)), then we generated this Activity ourselves and can trust $profile
+
+            $actor_uri = $profile->getUri();
+
+            if (!in_array($actor_uri, array($activity->actor->id, $activity->actor->link))) {
+                // A mismatch between our locally stored URI and the supplied author?
+                // Probably not more than a blog feed or something (with multiple authors or so)
+                // but log it for future inspection.
+                common_log(LOG_WARNING, "Got an actor '{$activity->actor->title}' ({$activity->actor->id}) on single-user feed for " . $actor_uri);
+            } elseif (empty($activity->actor->id)) {
+                // Plain <author> without ActivityStreams actor info.
+                // We'll just ignore this info for now and save the update under the feed's identity.
+            }
+        }
+
+        if (!$profile instanceof Profile) {
+            throw new ServerException('Could not get an author Profile for activity');
+        }
+
+        return $profile;
+    }
+
+    static public function typeToTitle($type)
+    {
+        return ucfirst(self::resolveUri($type, true));
+    }
+
+    static public function verbToTitle($verb)
+    {
+        return ucfirst(self::resolveUri($verb, true));
+    }
 }