]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityutils.php
Merge commit 'refs/merge-requests/165' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / lib / activityutils.php
index 11befc0ed4774925c2b499eb540da72cc98324c0..c2c239f1d3cc68ef32872da97835f7d8ec58710c 100644 (file)
@@ -104,8 +104,9 @@ class ActivityUtils
     {
         $els = $element->childNodes;
         $out = array();
-
-        foreach ($els as $link) {
+        
+        for ($i = 0; $i < $els->length; $i++) {
+            $link = $els->item($i);
             if ($link->localName == self::LINK && $link->namespaceURI == self::ATOM) {
                 $linkRel = $link->getAttribute(self::REL);
                 $linkType = $link->getAttribute(self::TYPE);
@@ -144,6 +145,34 @@ class ActivityUtils
         }
     }
 
+    /**
+     * Gets all immediate child elements with the given tag
+     *
+     * @param DOMElement $element   element to pick at
+     * @param string     $tag       tag to look for
+     * @param string     $namespace Namespace to look under
+     *
+     * @return array found element or null
+     */
+
+    static function children(DOMNode $element, $tag, $namespace=self::ATOM)
+    {
+        $results = array();
+
+        $els = $element->childNodes;
+
+        if (!empty($els) && $els->length > 0) {
+            for ($i = 0; $i < $els->length; $i++) {
+                $el = $els->item($i);
+                if ($el->localName == $tag && $el->namespaceURI == $namespace) {
+                    $results[] = $el;
+                }
+            }
+        }
+
+        return $results;
+    }
+
     /**
      * Grab the text content of a DOM element child of the current element
      *
@@ -273,14 +302,6 @@ class ActivityUtils
 
     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);
@@ -289,6 +310,14 @@ class ActivityUtils
             return new ActivityObject($subject);
         }
 
+        // Try the feed author
+
+        $author = ActivityUtils::child($feedEl, Activity::AUTHOR, Activity::ATOM);
+
+        if (!empty($author)) {
+            return new ActivityObject($author);
+        }
+
         // Sheesh. Not a very nice feed! Let's try fingerpoken in the
         // entries.
 
@@ -298,14 +327,6 @@ class ActivityUtils
 
             $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);
@@ -313,6 +334,14 @@ class ActivityUtils
             if (!empty($actor)) {
                 return new ActivityObject($actor);
             }
+
+            // Try the author
+
+            $author = ActivityUtils::child($entry, Activity::AUTHOR, Activity::ATOM);
+
+            if (!empty($author)) {
+                return new ActivityObject($author);
+            }
         }
 
         return null;