X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Factivityobject.php;h=fc47485c1892199fd84a92fe54383c7532e41189;hb=a70d43a685d72e2bad64efd02bdcc928b921d356;hp=1352b5bda82ca569ab67e64e7bd64aacbb00676a;hpb=6164940e8ca8aba0284efe0e07358699df378ee5;p=quix0rs-gnu-social.git diff --git a/lib/activityobject.php b/lib/activityobject.php index 1352b5bda8..fc47485c18 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 * @@ -72,6 +74,7 @@ class ActivityObject const SERVICE = 'http://activitystrea.ms/schema/1.0/service'; const IMAGE = 'http://activitystrea.ms/schema/1.0/image'; const COLLECTION = 'http://activitystrea.ms/schema/1.0/collection'; + const APPLICATION = 'http://activitystrea.ms/schema/1.0/application'; // Atom elements we snarf @@ -437,8 +440,16 @@ class ActivityObject $object->type = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type; $object->id = $notice->uri; + $object->title = 'New ' . ActivityObject::canonicalType($object->type) . ' by '; + try { + $object->title .= $notice->getProfile()->getAcctUri(); + } catch (ProfileNoAcctUriException $e) { + $object->title .= $e->profile->nickname; + } $object->content = $notice->rendered; - $object->link = $notice->bestUrl(); + $object->link = $notice->getUrl(); + + $object->extra[] = array('status_net', array('notice_id' => $notice->id)); Event::handle('EndActivityObjectFromNotice', array($notice, &$object)); } @@ -456,10 +467,11 @@ class ActivityObject $object->title = $profile->getBestName(); $object->link = $profile->profileurl; - $orig = $profile->getOriginalAvatar(); - - if (!empty($orig)) { - $object->avatarLinks[] = AvatarLink::fromAvatar($orig); + try { + $avatar = Avatar::getUploaded($profile); + $object->avatarLinks[] = AvatarLink::fromAvatar($avatar); + } catch (NoAvatarException $e) { + // Could not find an original avatar to link } $sizes = array( @@ -470,27 +482,15 @@ class ActivityObject foreach ($sizes as $size) { $alink = null; - $avatar = $profile->getAvatar($size); - - if (!empty($avatar)) { + try { + $avatar = Avatar::byProfile($profile, $size); $alink = AvatarLink::fromAvatar($avatar); - } else { + } catch (NoAvatarException $e) { $alink = new AvatarLink(); $alink->type = 'image/png'; $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; @@ -503,7 +503,7 @@ class ActivityObject $object->poco = PoCo::fromProfile($profile); - if ($profile->getUser()) { + if ($profile->isLocal()) { $object->extra[] = array('followers', array('url' => common_local_url('subscribers', array('nickname' => $profile->nickname)))); } @@ -513,7 +513,7 @@ class ActivityObject return $object; } - static function fromGroup($group) + static function fromGroup(User_group $group) { $object = new ActivityObject(); @@ -550,7 +550,7 @@ class ActivityObject $object->title = $ptag->tag; $object->summary = $ptag->description; $object->link = $ptag->homeUrl(); - $object->owner = Profile::staticGet('id', $ptag->tagger); + $object->owner = Profile::getKV('id', $ptag->tagger); $object->poco = PoCo::fromProfile($object->owner); Event::handle('EndActivityObjectFromPeopletag', array($ptag, &$object)); } @@ -575,10 +575,11 @@ class ActivityObject $object->date = $file->date; } - $thumbnail = $file->getThumbnail(); - - if (!empty($thumbnail)) { + try { + $thumbnail = $file->getThumbnail(); $object->thumbnail = $thumbnail; + } catch (UnsupportedMediaException $e) { + $object->thumbnail = null; } switch (ActivityObject::canonicalType($object->type)) { @@ -597,6 +598,73 @@ class ActivityObject return $object; } + static function fromNoticeSource(Notice_source $source) + { + $object = new ActivityObject(); + $wellKnown = array('web', 'xmpp', 'mail', 'omb', 'system', 'api', 'ostatus', + 'activity', 'feed', 'mirror', 'twitter', 'facebook'); + + if (Event::handle('StartActivityObjectFromNoticeSource', array($source, &$object))) { + $object->type = ActivityObject::APPLICATION; + + if (in_array($source->code, $wellKnown)) { + // We use one ID for all well-known StatusNet sources + $object->id = "tag:status.net,2009:notice-source:".$source->code; + } else if ($source->url) { + // They registered with an URL + $object->id = $source->url; + } else { + // Locally-registered, no URL + $object->id = TagURI::mint("notice-source:".$source->code); + } + + if ($source->url) { + $object->link = $source->url; + } + + if ($source->name) { + $object->title = $source->name; + } else { + $object->title = $source->code; + } + + if ($source->created) { + $object->date = $source->created; + } + + $object->extra[] = array('status_net', array('source_code' => $source->code)); + + Event::handle('EndActivityObjectFromNoticeSource', array($source, &$object)); + } + + return $object; + } + + static function fromMessage(Message $message) + { + $object = new ActivityObject(); + + if (Event::handle('StartActivityObjectFromMessage', array($message, &$object))) { + + $object->type = ActivityObject::NOTE; + $object->id = ($message->uri) ? $message->uri : (($message->url) ? $message->url : TagURI::mint(sprintf("message:%d", $message->id))); + $object->content = $message->rendered; + $object->date = $message->created; + + if ($message->url) { + $object->link = $message->url; + } else { + $object->link = common_local_url('showmessage', array('message' => $message->id)); + } + + $object->extra[] = array('status_net', array('message_id' => $message->id)); + + Event::handle('EndActivityObjectFromMessage', array($message, &$object)); + } + + return $object; + } + function outputTo($xo, $tag='activity:object') { if (!empty($tag)) { @@ -663,17 +731,16 @@ class ActivityObject if ($this->type == ActivityObject::PERSON || $this->type == ActivityObject::GROUP) { - foreach ($this->avatarLinks as $avatar) { - $xo->element( - 'link', array( - 'rel' => 'avatar', - 'type' => $avatar->type, - 'media:width' => $avatar->width, - 'media:height' => $avatar->height, - 'href' => $avatar->url - ), - null - ); + foreach ($this->avatarLinks as $alink) { + $xo->element('link', + array( + 'rel' => 'avatar', + 'type' => $alink->type, + 'media:width' => $alink->width, + 'media:height' => $alink->height, + 'href' => $alink->url, + ), + null); } } @@ -692,7 +759,7 @@ class ActivityObject // @fixme there's no way here to make a tree; elements can only contain plaintext // @fixme these may collide with JSON extensions foreach ($this->extra as $el) { - list($extraTag, $attrs, $content) = $el; + list($extraTag, $attrs, $content) = array_pad($el, 3, null); $xo->element($extraTag, $attrs, $content); } @@ -733,12 +800,6 @@ class ActivityObject // content (Add rendered version of the notice?) - // displayName - - if ($this->title) { - $object['displayName'] = $this->title; - } - // downstreamDuplicates // id @@ -752,6 +813,9 @@ class ActivityObject if ($this->type == ActivityObject::PERSON || $this->type == ActivityObject::GROUP) { + // displayName + $object['displayName'] = $this->title; + // XXX: Not sure what the best avatar is to use for the // author's "image". For now, I'm using the large size. @@ -799,7 +863,7 @@ class ActivityObject // summary $object['summary'] = $this->summary; - // summary + // content, usually rendered HTML $object['content'] = $this->content; // published (probably don't need. Might be useful for repeats.) @@ -818,7 +882,7 @@ class ActivityObject // @fixme text content from XML extensions will be lost foreach ($this->extra as $e) { - list($objectName, $props, $txt) = $e; + list($objectName, $props, $txt) = array_pad($e, 3, null); if (!empty($objectName)) { $parts = explode(":", $objectName); if (count($parts) == 2 && $parts[0] == "statusnet") { @@ -836,25 +900,27 @@ class ActivityObject list($lat, $lon) = explode(' ', $this->geopoint); - $object['location'] = array( - 'objectType' => 'place', - 'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon), - 'lat' => $lat, - 'lon' => $lon - ); + if (!empty($lat) && !empty($lon)) { + $object['location'] = array( + 'objectType' => 'place', + 'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon), + 'lat' => $lat, + 'lon' => $lon + ); - $loc = Location::fromLatLon($lat, $lon); + $loc = Location::fromLatLon((float)$lat, (float)$lon); - if ($loc) { - $name = $loc->getName(); + if ($loc) { + $name = $loc->getName(); - if ($name) { - $object['location']['displayName'] = $name; - } - $url = $loc->getURL(); + if ($name) { + $object['location']['displayName'] = $name; + } + $url = $loc->getURL(); - if ($url) { - $object['location']['url'] = $url; + if ($url) { + $object['location']['url'] = $url; + } } } }