]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
move code to get an author object for a feed to a library from Ostatus_profile
authorEvan Prodromou <evan@status.net>
Fri, 17 Dec 2010 18:09:37 +0000 (13:09 -0500)
committerEvan Prodromou <evan@status.net>
Fri, 17 Dec 2010 18:09:37 +0000 (13:09 -0500)
lib/activityutils.php
plugins/OStatus/classes/Ostatus_profile.php

index c462514c498e40b04cea0f26f0eb5a5cd11e3b16..11befc0ed4774925c2b499eb540da72cc98324c0 100644 (file)
@@ -270,4 +270,51 @@ class ActivityUtils
 
         return false;
     }
+
+    static function getFeedAuthor($feedEl)
+    {
+        // Try the feed author
+
+        $author = ActivityUtils::child($feedEl, Activity::AUTHOR, Activity::ATOM);
+
+        if (!empty($author)) {
+            return new ActivityObject($author);
+        }
+
+        // Try old and deprecated activity:subject
+
+        $subject = ActivityUtils::child($feedEl, Activity::SUBJECT, Activity::SPEC);
+
+        if (!empty($subject)) {
+            return new ActivityObject($subject);
+        }
+
+        // Sheesh. Not a very nice feed! Let's try fingerpoken in the
+        // entries.
+
+        $entries = $feedEl->getElementsByTagNameNS(Activity::ATOM, 'entry');
+
+        if (!empty($entries) && $entries->length > 0) {
+
+            $entry = $entries->item(0);
+
+            // Try the author
+
+            $author = ActivityUtils::child($entry, Activity::AUTHOR, Activity::ATOM);
+
+            if (!empty($author)) {
+                return new ActivityObject($author);
+            }
+
+            // Try the (deprecated) activity:actor
+
+            $actor = ActivityUtils::child($entry, Activity::ACTOR, Activity::SPEC);
+
+            if (!empty($actor)) {
+                return new ActivityObject($actor);
+            }
+        }
+
+        return null;
+    }
 }
index e5b8939a9d3a78b0d387ff9dadb8ef5e39dc2142..77cf57a6708b4b951a5808bbb7fcf49bdf981abd 100644 (file)
@@ -935,54 +935,19 @@ class Ostatus_profile extends Memcached_DataObject
      * @return Ostatus_profile
      * @throws Exception
      */
+
     public static function ensureAtomFeed($feedEl, $hints)
     {
-        // Try to get a profile from the feed activity:subject
-
-        $subject = ActivityUtils::child($feedEl, Activity::SUBJECT, Activity::SPEC);
-
-        if (!empty($subject)) {
-            $subjObject = new ActivityObject($subject);
-            return self::ensureActivityObjectProfile($subjObject, $hints);
-        }
-
-        // Otherwise, try the feed author
-
-        $author = ActivityUtils::child($feedEl, Activity::AUTHOR, Activity::ATOM);
-
-        if (!empty($author)) {
-            $authorObject = new ActivityObject($author);
-            return self::ensureActivityObjectProfile($authorObject, $hints);
-        }
-
-        // Sheesh. Not a very nice feed! Let's try fingerpoken in the
-        // entries.
+        $author = ActivityUtils::getFeedAuthor($feedEl);
 
-        $entries = $feedEl->getElementsByTagNameNS(Activity::ATOM, 'entry');
-
-        if (!empty($entries) && $entries->length > 0) {
-
-            $entry = $entries->item(0);
-
-            $actor = ActivityUtils::child($entry, Activity::ACTOR, Activity::SPEC);
-
-            if (!empty($actor)) {
-                $actorObject = new ActivityObject($actor);
-                return self::ensureActivityObjectProfile($actorObject, $hints);
-
-            }
-
-            $author = ActivityUtils::child($entry, Activity::AUTHOR, Activity::ATOM);
-
-            if (!empty($author)) {
-                $authorObject = new ActivityObject($author);
-                return self::ensureActivityObjectProfile($authorObject, $hints);
-            }
+        if (empty($author)) {
+            // XXX: make some educated guesses here
+            // TRANS: Feed sub exception.
+            throw new FeedSubException(_m('Can\'t find enough profile '.
+                                          'information to make a feed.'));
         }
 
-        // XXX: make some educated guesses here
-        // TRANS: Feed sub exception.
-        throw new FeedSubException(_m('Can\'t find enough profile information to make a feed.'));
+        return self::ensureActivityObjectProfile($author, $hints);
     }
 
     /**