]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityobject.php
Fix to profile location in FOAF output: longitude was repeating the latitude by mistake
[quix0rs-gnu-social.git] / lib / activityobject.php
index b1e9071eda73ab238ec668cc2b49a16759bd6e73..677a48197fd9e0e6ff10ee0a14b4e532109c8f7c 100644 (file)
@@ -80,6 +80,13 @@ class ActivityObject
     const URI   = 'uri';
     const EMAIL = 'email';
 
+    const POSTEROUS   = 'http://posterous.com/help/rss/1.0';
+    const AUTHOR      = 'author';
+    const USERIMAGE   = 'userImage';
+    const PROFILEURL  = 'profileUrl';
+    const NICKNAME    = 'nickName';
+    const DISPLAYNAME = 'displayName';
+
     public $element;
     public $type;
     public $id;
@@ -93,6 +100,13 @@ class ActivityObject
     public $poco;
     public $displayName;
 
+    // @todo move this stuff to it's own PHOTO activity object
+    const MEDIA_DESCRIPTION = 'description';
+
+    public $thumbnail;
+    public $largerImage;
+    public $description;
+
     /**
      * Constructor
      *
@@ -143,13 +157,27 @@ class ActivityObject
 
             $this->poco = new PoCo($element);
         }
+
+        if ($this->type == self::PHOTO) {
+
+            $this->thumbnail   = ActivityUtils::getLink($element, 'preview');
+            $this->largerImage = ActivityUtils::getLink($element, 'enclosure');
+
+            $this->description = ActivityUtils::childContent(
+                $element,
+                ActivityObject::MEDIA_DESCRIPTION,
+                Activity::MEDIA
+            );
+
+        }
     }
 
     private function _fromAuthor($element)
     {
         $this->type  = self::PERSON; // XXX: is this fair?
         $this->title = $this->_childContent($element, self::NAME);
-        $this->id    = $this->_childContent($element, self::URI);
+
+        $this->id = $this->_childContent($element, self::URI);
 
         if (empty($this->id)) {
             $email = $this->_childContent($element, self::EMAIL);
@@ -169,7 +197,6 @@ class ActivityObject
             $this->type = ActivityObject::NOTE;
         }
 
-        $this->id      = $this->_childContent($element, self::ID);
         $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
         $this->content = ActivityUtils::getContent($element);
 
@@ -182,6 +209,12 @@ class ActivityObject
         $this->source  = $this->_getSource($element);
 
         $this->link = ActivityUtils::getPermalink($element);
+
+        $this->id = $this->_childContent($element, self::ID);
+
+        if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
+            $this->id = $this->link;
+        }
     }
 
     // @fixme rationalize with Activity::_fromRssItem()
@@ -290,12 +323,42 @@ class ActivityObject
         $imageEl = ActivityUtils::child($el, Activity::IMAGE, Activity::RSS);
 
         if (!empty($imageEl)) {
-            $obj->avatarLinks[] = ActivityUtils::childContent($imageEl, Activity::URL, Activity::RSS);
+            $url = ActivityUtils::childContent($imageEl, Activity::URL, Activity::RSS);
+            $al = new AvatarLink();
+            $al->url = $url;
+            $obj->avatarLinks[] = $al;
         }
 
         return $obj;
     }
 
+    public static function fromPosterousAuthor($el)
+    {
+        $obj = new ActivityObject();
+
+        $obj->type = ActivityObject::PERSON; // @fixme any others...?
+
+        $userImage = ActivityUtils::childContent($el, self::USERIMAGE, self::POSTEROUS);
+
+        if (!empty($userImage)) {
+            $al = new AvatarLink();
+            $al->url = $userImage;
+            $obj->avatarLinks[] = $al;
+        }
+
+        $obj->link = ActivityUtils::childContent($el, self::PROFILEURL, self::POSTEROUS);
+        $obj->id   = $obj->link;
+
+        $obj->poco = new PoCo();
+
+        $obj->poco->preferredUsername = ActivityUtils::childContent($el, self::NICKNAME, self::POSTEROUS);
+        $obj->poco->displayName       = ActivityUtils::childContent($el, self::DISPLAYNAME, self::POSTEROUS);
+
+        $obj->title = $obj->poco->displayName;
+
+        return $obj;
+    }
+
     private function _childContent($element, $tag, $namespace=ActivityUtils::ATOM)
     {
         return ActivityUtils::childContent($element, $tag, $namespace);