]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityobject.php
Always specify UTF-8 targt charset for html_entity_decode(); default is 8-bit ISO...
[quix0rs-gnu-social.git] / lib / activityobject.php
index 0a358ccabbe1c4ceb34199b7f0badc80485a64b3..c957933d04bff8c2e11ba75552e58faeaabe4b81 100644 (file)
@@ -100,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
      *
@@ -150,6 +157,18 @@ 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)
@@ -157,10 +176,7 @@ class ActivityObject
         $this->type  = self::PERSON; // XXX: is this fair?
         $this->title = $this->_childContent($element, self::NAME);
 
-        $id = $this->_childContent($element, self::URI);
-        if (ActivityUtils::validateUri($id)) {
-            $this->id = $id;
-        }
+        $this->id = $this->_childContent($element, self::URI);
 
         if (empty($this->id)) {
             $email = $this->_childContent($element, self::EMAIL);
@@ -173,15 +189,6 @@ class ActivityObject
 
     private function _fromAtomEntry($element)
     {
-        if ($element->localName == 'actor') {
-            // Old-fashioned <activity:actor>...
-            // First pull anything from <author>, then we'll add on top.
-            $author = ActivityUtils::child($element->parentNode, 'author');
-            if ($author) {
-                $this->_fromAuthor($author);
-            }
-        }
-
         $this->type = $this->_childContent($element, Activity::OBJECTTYPE,
                                            Activity::SPEC);
 
@@ -189,11 +196,6 @@ class ActivityObject
             $this->type = ActivityObject::NOTE;
         }
 
-        $id = $this->_childContent($element, self::ID);
-        if (ActivityUtils::validateUri($id)) {
-            $this->id = $id;
-        }
-
         $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
         $this->content = ActivityUtils::getContent($element);
 
@@ -201,11 +203,17 @@ 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);
+
+        $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()
@@ -409,7 +417,6 @@ class ActivityObject
         );
 
         foreach ($sizes as $size) {
-
             $alink  = null;
             $avatar = $profile->getAvatar($size);
 
@@ -421,6 +428,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;