]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activity.php
throw an error that looks like mysql errors.. :-S
[quix0rs-gnu-social.git] / lib / activity.php
index 0f30e8bf517c84f1e26c0d93dbbbee9c46d0dd64..2cb80f9e1a26bba80f94c19822b41f4db67fc0b1 100644 (file)
@@ -344,22 +344,45 @@ class ActivityUtils
 
     static function getLink(DOMNode $element, $rel, $type=null)
     {
-        $links = $element->getElementsByTagnameNS(self::ATOM, self::LINK);
+        $els = $element->childNodes;
 
-        foreach ($links as $link) {
+        foreach ($els as $link) {
+            if ($link->localName == self::LINK && $link->namespaceURI == self::ATOM) {
 
-            $linkRel = $link->getAttribute(self::REL);
-            $linkType = $link->getAttribute(self::TYPE);
+                $linkRel = $link->getAttribute(self::REL);
+                $linkType = $link->getAttribute(self::TYPE);
 
-            if ($linkRel == $rel &&
-                (is_null($type) || $linkType == $type)) {
-                return $link->getAttribute(self::HREF);
+                if ($linkRel == $rel &&
+                    (is_null($type) || $linkType == $type)) {
+                    return $link->getAttribute(self::HREF);
+                }
             }
         }
 
         return null;
     }
 
+    static function getLinks(DOMNode $element, $rel, $type=null)
+    {
+        $els = $element->childNodes;
+        $out = array();
+
+        foreach ($els as $link) {
+            if ($link->localName == self::LINK && $link->namespaceURI == self::ATOM) {
+
+                $linkRel = $link->getAttribute(self::REL);
+                $linkType = $link->getAttribute(self::TYPE);
+
+                if ($linkRel == $rel &&
+                    (is_null($type) || $linkType == $type)) {
+                    $out[] = $link;
+                }
+            }
+        }
+
+        return $out;
+    }
+
     /**
      * Gets the first child element with the given tag
      *
@@ -472,6 +495,24 @@ class AvatarLink
     public $type;
     public $size;
     public $width;
+    public $height;
+
+    function __construct($element=null)
+    {
+        if ($element) {
+            // @fixme use correct namespaces
+            $this->url = $element->getAttribute('href');
+            $this->type = $element->getAttribute('type');
+            $width = $element->getAttribute('media:width');
+            if ($width != null) {
+                $this->width = intval($width);
+            }
+            $height = $element->getAttribute('media:height');
+            if ($height != null) {
+                $this->height = intval($height);
+            }
+        }
+    }
 
     static function fromAvatar($avatar)
     {
@@ -480,7 +521,7 @@ class AvatarLink
         }
         $alink = new AvatarLink();
         $alink->type   = $avatar->mediatype;
-        $alink->height = $avatar->mediatype;
+        $alink->height = $avatar->height;
         $alink->width  = $avatar->width;
         $alink->url    = $avatar->displayUrl();
         return $alink;
@@ -640,8 +681,10 @@ class ActivityObject
         if ($this->type == self::PERSON || $this->type == self::GROUP) {
             $this->displayName = $this->title;
 
-            // @fixme we may have multiple avatars with different resolutions specified
-            $this->avatar = ActivityUtils::getLink($element, 'avatar');
+            $avatars = ActivityUtils::getLinks($element, 'avatar');
+            foreach ($avatars as $link) {
+                $this->avatarLinks[] = new AvatarLink($link);
+            }
 
             $this->poco = new PoCo($element);
         }
@@ -1005,6 +1048,7 @@ class Activity
     public $id;      // ID of the activity
     public $title;   // title of the activity
     public $categories = array(); // list of AtomCategory objects
+    public $enclosures = array(); // list of enclosure URL references
 
     /**
      * Turns a regular old Atom <entry> into a magical activity
@@ -1020,6 +1064,18 @@ class Activity
         }
 
         $this->entry = $entry;
+
+        // @fixme Don't send in a DOMDocument
+        if ($feed instanceof DOMDocument) {
+            common_log(
+                LOG_WARNING,
+                'Activity::__construct() - '
+                . 'DOMDocument passed in for feed by mistake. '
+                . "Expecting a 'feed' DOMElement."
+            );
+            $feed = $feed->getElementsByTagName('feed')->item(0);
+        }
+
         $this->feed  = $feed;
 
         $pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM);
@@ -1101,6 +1157,10 @@ class Activity
                 $this->categories[] = new AtomCategory($catEl);
             }
         }
+
+        foreach (ActivityUtils::getLinks($entry, 'enclosure') as $link) {
+            $this->enclosures[] = $link->getAttribute('href');
+        }
     }
 
     /**