X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Factivityobject.php;h=87eea13727e3261c8829a8459dad19b42113caab;hb=3138fa0b4080c135f4e509992f3c5d7fd82538de;hp=530c9aba15c44c7f45266e6ed9fb59811720300f;hpb=802734d07eace79d3002e887d02d8585d3dd19f5;p=quix0rs-gnu-social.git diff --git a/lib/activityobject.php b/lib/activityobject.php index 530c9aba15..87eea13727 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -32,6 +32,8 @@ if (!defined('STATUSNET')) { exit(1); } +require_once(INSTALLDIR.'/lib/activitystreamjsondocument.php'); + /** * A noun-ish thing in the activity universe * @@ -193,15 +195,22 @@ class ActivityObject $this->type = self::PERSON; // XXX: is this fair? } - // start with - $title = ActivityUtils::childHtmlContent($element, self::TITLE); + // Start with + + $this->title = ActivityUtils::childContent($element, PoCo::DISPLAYNAME, PoCo::NS); + + // try falling back to + + if (empty($this->title)) { + $title = ActivityUtils::childHtmlContent($element, self::TITLE); - if (!empty($title)) { - $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8'); + if (!empty($title)) { + $this->title = common_strip_html($title); + } } - // fall back to + // fall back to as a last resort if (empty($this->title)) { $this->title = $this->_childContent($element, self::NAME); @@ -249,10 +258,7 @@ class ActivityObject $this->content = ActivityUtils::getContent($element); // We don't like HTML in our titles, although it's technically allowed - - $title = ActivityUtils::childHtmlContent($element, self::TITLE); - - $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8'); + $this->title = common_strip_html(ActivityUtils::childHtmlContent($element, self::TITLE)); $this->source = $this->_getSource($element); @@ -268,6 +274,10 @@ class ActivityObject // @todo FIXME: rationalize with Activity::_fromRssItem() private function _fromRssItem($item) { + if (empty($this->type)) { + $this->type = ActivityObject::NOTE; + } + $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, Activity::RSS); $contentEl = ActivityUtils::child($item, ActivityUtils::CONTENT, Activity::CONTENTNS); @@ -288,7 +298,7 @@ class ActivityObject if (!empty($guidEl)) { $this->id = $guidEl->textContent; - if ($guidEl->hasAttribute('isPermaLink')) { + if ($guidEl->hasAttribute('isPermaLink') && $guidEl->getAttribute('isPermaLink') != 'false') { // overwrites $this->link = $this->id; } @@ -429,83 +439,6 @@ class ActivityObject } } - static function fromNotice(Notice $notice) - { - $object = new ActivityObject(); - - if (Event::handle('StartActivityObjectFromNotice', array($notice, &$object))) { - - $object->type = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type; - - $object->id = $notice->uri; - $object->title = 'New ' . ActivityObject::canonicalType($notice->object_type); - $object->content = $notice->rendered; - $object->link = $notice->bestUrl(); - - $object->extra[] = array('status_net', array('notice_id' => $notice->id)); - - Event::handle('EndActivityObjectFromNotice', array($notice, &$object)); - } - - return $object; - } - - static function fromProfile(Profile $profile) - { - $object = new ActivityObject(); - - if (Event::handle('StartActivityObjectFromProfile', array($profile, &$object))) { - $object->type = ActivityObject::PERSON; - $object->id = $profile->getUri(); - $object->title = $profile->getBestName(); - $object->link = $profile->profileurl; - - try { - $avatar = Avatar::getUploaded($profile); - $object->avatarLinks[] = AvatarLink::fromAvatar($avatar); - } catch (NoAvatarException $e) { - // Could not find an original avatar to link - } - - $sizes = array( - AVATAR_PROFILE_SIZE, - AVATAR_STREAM_SIZE, - AVATAR_MINI_SIZE - ); - - foreach ($sizes as $size) { - $alink = null; - try { - $avatar = Avatar::byProfile($profile, $size); - $alink = AvatarLink::fromAvatar($avatar); - } catch (NoAvatarException $e) { - $alink = new AvatarLink(); - $alink->type = 'image/png'; - $alink->height = $size; - $alink->width = $size; - $alink->url = Avatar::defaultImage($size); - } - - $object->avatarLinks[] = $alink; - } - - if (isset($profile->lat) && isset($profile->lon)) { - $object->geopoint = (float)$profile->lat - . ' ' . (float)$profile->lon; - } - - $object->poco = PoCo::fromProfile($profile); - - if ($profile->isLocal()) { - $object->extra[] = array('followers', array('url' => common_local_url('subscribers', array('nickname' => $profile->nickname)))); - } - - Event::handle('EndActivityObjectFromProfile', array($profile, &$object)); - } - - return $object; - } - static function fromGroup(User_group $group) { $object = new ActivityObject(); @@ -568,19 +501,22 @@ class ActivityObject $object->date = $file->date; } - $thumbnail = $file->getThumbnail(); - - if (!empty($thumbnail)) { + try { + $thumbnail = $file->getThumbnail(); $object->thumbnail = $thumbnail; + } catch (UseFileAsThumbnailException $e) { + $object->thumbnail = null; + } catch (UnsupportedMediaException $e) { + $object->thumbnail = null; } - switch (ActivityObject::canonicalType($object->type)) { + switch (self::canonicalType($object->type)) { case 'image': - $object->largerImage = $file->url; + $object->largerImage = $file->getUrl(); break; case 'video': case 'audio': - $object->stream = $file->url; + $object->stream = $file->getUrl(); break; } @@ -701,11 +637,6 @@ class ActivityObject array('type' => 'html'), common_xml_safe_str($this->content) ); - $xo->element( - ActivityUtils::CONTENT, - array('type' => 'text'), - html_entity_decode(strip_tags($this->content), ENT_QUOTES, 'UTF-8') - ); } if (!empty($this->link)) { @@ -855,7 +786,7 @@ class ActivityObject // We can probably use the whole schema URL here but probably the // relative simple name is easier to parse - $object['objectType'] = ActivityObject::canonicalType($this->type); + $object['objectType'] = self::canonicalType($this->type); // summary $object['summary'] = $this->summary; @@ -930,7 +861,7 @@ class ActivityObject if (is_string($this->thumbnail)) { $object['image'] = array('url' => $this->thumbnail); } else { - $object['image'] = array('url' => $this->thumbnail->url); + $object['image'] = array('url' => $this->thumbnail->getUrl()); if ($this->thumbnail->width) { $object['image']['width'] = $this->thumbnail->width; } @@ -940,7 +871,7 @@ class ActivityObject } } - switch (ActivityObject::canonicalType($this->type)) { + switch (self::canonicalType($this->type)) { case 'image': if (!empty($this->largerImage)) { $object['fullImage'] = array('url' => $this->largerImage); @@ -959,13 +890,18 @@ class ActivityObject return array_filter($object); } - static function canonicalType($type) { - $ns = 'http://activitystrea.ms/schema/1.0/'; - if (substr($type, 0, mb_strlen($ns)) == $ns) { - return substr($type, mb_strlen($ns)); - } else { - return $type; + public function getIdentifiers() { + $ids = array(); + foreach(array('id', 'link', 'url') as $id) { + if (isset($this->$id)) { + $ids[] = $this->$id; + } } + return array_unique($ids); + } + + static function canonicalType($type) { + return ActivityUtils::resolveUri($type, true); } static function mimeTypeToObjectType($mimeType) {