]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityobject.php
Merge branch 'master' of gitorious.org:statusnet/mainline
[quix0rs-gnu-social.git] / lib / activityobject.php
index 18e3e21ddb2bcd9749e276b23cf706fe45c76d8d..e89c8db4e9afee4e611a0e54d41ac150b9d14fc5 100644 (file)
@@ -49,7 +49,6 @@ if (!defined('STATUSNET')) {
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
  * @link      http://status.net/
  */
-
 class ActivityObject
 {
     const ARTICLE   = 'http://activitystrea.ms/schema/1.0/article';
@@ -100,6 +99,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
      *
@@ -109,7 +115,6 @@ class ActivityObject
      *
      * @param DOMElement $element DOM thing to turn into an Activity thing
      */
-
     function __construct($element = null)
     {
         if (empty($element)) {
@@ -150,13 +155,26 @@ 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);
@@ -176,7 +194,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);
 
@@ -184,15 +201,20 @@ class ActivityObject
 
         $title = ActivityUtils::childHtmlContent($element, self::TITLE);
 
-        $this->title = html_entity_decode(strip_tags($title));
+        $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8');
 
         $this->source  = $this->_getSource($element);
 
         $this->link = ActivityUtils::getPermalink($element);
-    }
 
-    // @fixme rationalize with Activity::_fromRssItem()
+        $this->id = $this->_childContent($element, self::ID);
+
+        if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
+            $this->id = $this->link;
+        }
+    }
 
+    // @todo FIXME: rationalize with Activity::_fromRssItem()
     private function _fromRssItem($item)
     {
         $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, Activity::RSS);
@@ -297,7 +319,10 @@ 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;
@@ -312,7 +337,9 @@ class ActivityObject
         $userImage = ActivityUtils::childContent($el, self::USERIMAGE, self::POSTEROUS);
 
         if (!empty($userImage)) {
-            $obj->avatarLinks[] = $userImage;
+            $al = new AvatarLink();
+            $al->url = $userImage;
+            $obj->avatarLinks[] = $al;
         }
 
         $obj->link = ActivityUtils::childContent($el, self::PROFILEURL, self::POSTEROUS);
@@ -387,7 +414,6 @@ class ActivityObject
         );
 
         foreach ($sizes as $size) {
-
             $alink  = null;
             $avatar = $profile->getAvatar($size);
 
@@ -399,6 +425,17 @@ class ActivityObject
                 $alink->height = $size;
                 $alink->width  = $size;
                 $alink->url    = Avatar::defaultImage($size);
+
+                if ($size == AVATAR_PROFILE_SIZE) {
+                    // Hack for Twitter import: we don't have a 96x96 image,
+                    // but we do have a 73x73 image. For now, fake it with that.
+                    $avatar = $profile->getAvatar(73);
+                    if ($avatar) {
+                        $alink = AvatarLink::fromAvatar($avatar);
+                        $alink->height= $size;
+                        $alink->width = $size;
+                    }
+                }
             }
 
             $object->avatarLinks[] = $alink;