123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970 |
- <?php
- /**
- * StatusNet, the distributed open-source microblogging tool
- *
- * An activity
- *
- * PHP version 5
- *
- * LICENCE: This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category Feed
- * @package StatusNet
- * @author Evan Prodromou <evan@status.net>
- * @author Zach Copley <zach@status.net>
- * @copyright 2010 StatusNet, Inc.
- * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
- * @link http://status.net/
- */
- if (!defined('GNUSOCIAL')) {
- exit(1);
- }
- require_once(INSTALLDIR . '/lib/activitystreamjsondocument.php');
- /**
- * A noun-ish thing in the activity universe
- *
- * The activity streams spec talks about activity objects, while also having
- * a tag activity:object, which is in fact an activity object. Aaaaaah!
- *
- * This is just a thing in the activity universe. Can be the subject, object,
- * or indirect object (target!) of an activity verb. Rotten name, and I'm
- * propagating it. *sigh*
- *
- * @category OStatus
- * @package StatusNet
- * @author Evan Prodromou <evan@status.net>
- * @copyright 2010 StatusNet, Inc.
- * @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';
- const BLOGENTRY = 'http://activitystrea.ms/schema/1.0/blog-entry';
- const NOTE = 'http://activitystrea.ms/schema/1.0/note';
- const STATUS = 'http://activitystrea.ms/schema/1.0/status';
- const FILE = 'http://activitystrea.ms/schema/1.0/file';
- const PHOTO = 'http://activitystrea.ms/schema/1.0/photo';
- const ALBUM = 'http://activitystrea.ms/schema/1.0/photo-album';
- const PLAYLIST = 'http://activitystrea.ms/schema/1.0/playlist';
- const VIDEO = 'http://activitystrea.ms/schema/1.0/video';
- const AUDIO = 'http://activitystrea.ms/schema/1.0/audio';
- const BOOKMARK = 'http://activitystrea.ms/schema/1.0/bookmark';
- const PERSON = 'http://activitystrea.ms/schema/1.0/person';
- const GROUP = 'http://activitystrea.ms/schema/1.0/group';
- const _LIST = 'http://activitystrea.ms/schema/1.0/list'; // LIST is reserved
- const PLACE = 'http://activitystrea.ms/schema/1.0/place';
- const COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
- // ^^^^^^^^^^ tea!
- const ACTIVITY = 'http://activitystrea.ms/schema/1.0/activity';
- 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
- const TITLE = 'title';
- const SUMMARY = 'summary';
- const ID = 'id';
- const SOURCE = 'source';
- const NAME = 'name';
- 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';
- const MEDIA_DESCRIPTION = 'description';
- public $element;
- public $type;
- public $id;
- public $title;
- public $summary;
- public $content;
- public $owner;
- public $link; // think APP (Atom Publishing Protocol)
- public $selfLink;
- public $source;
- public $avatarLinks = [];
- public $geopoint;
- public $poco;
- // @todo move this stuff to it's own PHOTO activity object
- public $displayName;
- public $thumbnail;
- public $largerImage;
- public $description;
- public $extra = [];
- public $stream;
- /**
- * Constructor
- *
- * This probably needs to be refactored
- * to generate a local class (ActivityPerson, ActivityFile, ...)
- * based on the object type.
- *
- * @param DOMElement $element DOM thing to turn into an Activity thing
- */
- public function __construct($element = null)
- {
- if (empty($element)) {
- return;
- }
- $this->element = $element;
- $this->geopoint = $this->_childContent(
- $element,
- ActivityContext::POINT,
- ActivityContext::GEORSS
- );
- if ($element->tagName == 'author') {
- $this->_fromAuthor($element);
- } elseif ($element->tagName == 'item') {
- $this->_fromRssItem($element);
- } else {
- $this->_fromAtomEntry($element);
- }
- // Some per-type attributes...
- if ($this->type == self::PERSON || $this->type == self::GROUP) {
- $this->displayName = $this->title;
- $photos = ActivityUtils::getLinks($element, 'photo');
- if (count($photos)) {
- foreach ($photos as $link) {
- $this->avatarLinks[] = new AvatarLink($link);
- }
- } else {
- $avatars = ActivityUtils::getLinks($element, 'avatar');
- foreach ($avatars as $link) {
- $this->avatarLinks[] = new AvatarLink($link);
- }
- }
- $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
- );
- }
- if ($this->type == self::_LIST) {
- $owner = ActivityUtils::child($this->element, Activity::AUTHOR, Activity::SPEC);
- $this->owner = new ActivityObject($owner);
- }
- }
- private function _childContent($element, $tag, $namespace = ActivityUtils::ATOM)
- {
- return ActivityUtils::childContent($element, $tag, $namespace);
- }
- private function _fromAuthor($element)
- {
- $this->type = $this->_childContent(
- $element,
- Activity::OBJECTTYPE,
- Activity::SPEC
- );
- if (empty($this->type)) {
- $this->type = self::PERSON; // XXX: is this fair?
- }
- // Start with <poco::displayName>
- $this->title = ActivityUtils::childContent($element, PoCo::DISPLAYNAME, PoCo::NS);
- // try falling back to <atom:title>
- if (empty($this->title)) {
- $title = ActivityUtils::childHtmlContent($element, self::TITLE);
- if (!empty($title)) {
- $this->title = common_strip_html($title);
- }
- }
- // fall back to <atom:name> as a last resort
- if (empty($this->title)) {
- $this->title = $this->_childContent($element, self::NAME);
- }
- // start with <atom:id>
- $this->id = $this->_childContent($element, self::ID);
- // fall back to <atom:uri>
- if (empty($this->id)) {
- $this->id = $this->_childContent($element, self::URI);
- }
- // fall further back to <atom:email>
- if (empty($this->id)) {
- $email = $this->_childContent($element, self::EMAIL);
- if (!empty($email)) {
- // XXX: acct: ?
- $this->id = 'mailto:' . $email;
- }
- }
- $this->link = ActivityUtils::getPermalink($element);
- // fall finally back to <link rel=alternate>
- 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)
- {
- 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);
- if (!empty($contentEl)) {
- $this->content = htmlspecialchars_decode($contentEl->textContent, ENT_QUOTES);
- } else {
- $descriptionEl = ActivityUtils::child($item, Activity::DESCRIPTION, Activity::RSS);
- if (!empty($descriptionEl)) {
- $this->content = htmlspecialchars_decode($descriptionEl->textContent, ENT_QUOTES);
- }
- }
- $this->link = ActivityUtils::childContent($item, ActivityUtils::LINK, Activity::RSS);
- $guidEl = ActivityUtils::child($item, Activity::GUID, Activity::RSS);
- if (!empty($guidEl)) {
- $this->id = $guidEl->textContent;
- if ($guidEl->hasAttribute('isPermaLink') && $guidEl->getAttribute('isPermaLink') != 'false') {
- // overwrites <link>
- $this->link = $this->id;
- }
- }
- }
- private function _fromAtomEntry($element)
- {
- $this->type = $this->_childContent(
- $element,
- Activity::OBJECTTYPE,
- Activity::SPEC
- );
- if (empty($this->type)) {
- $this->type = ActivityObject::NOTE;
- }
- $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
- $this->content = ActivityUtils::getContent($element);
- // We don't like HTML in our titles, although it's technically allowed
- $this->title = common_strip_html(ActivityUtils::childHtmlContent($element, self::TITLE));
- $this->source = $this->_getSource($element);
- $this->link = ActivityUtils::getPermalink($element);
- $this->selfLink = ActivityUtils::getSelfLink($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;
- }
- $els = $element->childNodes;
- for ($i = 0; $i < $els->length; $i++) {
- $link = $els->item($i);
- if ($link->localName == ActivityUtils::LINK && $link->namespaceURI == ActivityUtils::ATOM) {
- $attrs = [];
- foreach ($link->attributes as $attrName => $attrNode) {
- $attrs[$attrName] = $attrNode->nodeValue;
- }
- $this->extra[] = [$link->localName,
- $attrs,
- $link->nodeValue];
- }
- }
- }
- private function _getSource($element)
- {
- $sourceEl = ActivityUtils::child($element, 'source');
- if (empty($sourceEl)) {
- return null;
- } else {
- $href = ActivityUtils::getLink($sourceEl, 'self');
- if (!empty($href)) {
- return $href;
- } else {
- return ActivityUtils::childContent($sourceEl, 'id');
- }
- }
- }
- public static function fromRssAuthor($el)
- {
- $text = $el->textContent;
- if (preg_match('/^(.*?) \((.*)\)$/', $text, $match)) {
- $email = $match[1];
- $name = $match[2];
- } elseif (preg_match('/^(.*?) <(.*)>$/', $text, $match)) {
- $name = $match[1];
- $email = $match[2];
- } elseif (preg_match('/.*@.*/', $text)) {
- $email = $text;
- $name = null;
- } else {
- $name = $text;
- $email = null;
- }
- // Not really enough info
- $obj = new ActivityObject();
- $obj->element = $el;
- $obj->type = ActivityObject::PERSON;
- $obj->title = $name;
- if (!empty($email)) {
- $obj->id = 'mailto:' . $email;
- }
- return $obj;
- }
- public static function fromDcCreator($el)
- {
- // Not really enough info
- $text = $el->textContent;
- $obj = new ActivityObject();
- $obj->element = $el;
- $obj->title = $text;
- $obj->type = ActivityObject::PERSON;
- return $obj;
- }
- public static function fromRssChannel($el)
- {
- $obj = new ActivityObject();
- $obj->element = $el;
- $obj->type = ActivityObject::PERSON; // @fixme guess better
- $obj->title = ActivityUtils::childContent($el, ActivityObject::TITLE, Activity::RSS);
- $obj->link = ActivityUtils::childContent($el, ActivityUtils::LINK, Activity::RSS);
- $obj->id = ActivityUtils::getLink($el, Activity::SELF);
- if (empty($obj->id)) {
- $obj->id = $obj->link;
- }
- $desc = ActivityUtils::childContent($el, Activity::DESCRIPTION, Activity::RSS);
- if (!empty($desc)) {
- $obj->content = htmlspecialchars_decode($desc, ENT_QUOTES);
- }
- $imageEl = ActivityUtils::child($el, Activity::IMAGE, Activity::RSS);
- if (!empty($imageEl)) {
- $url = ActivityUtils::childContent($imageEl, Activity::URL, Activity::RSS);
- $al = new AvatarLink();
- $al->url = $url;
- $obj->avatarLinks[] = $al;
- }
- return $obj;
- }
- // Try to get a unique id for the source feed
- 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;
- }
- public static function fromGroup(User_group $group)
- {
- $object = new ActivityObject();
- if (Event::handle('StartActivityObjectFromGroup', [$group, &$object])) {
- $object->type = ActivityObject::GROUP;
- $object->id = $group->getUri();
- $object->title = $group->getBestName();
- $object->link = $group->getUri();
- $object->avatarLinks[] = AvatarLink::fromFilename(
- $group->homepage_logo,
- AVATAR_PROFILE_SIZE
- );
- $object->avatarLinks[] = AvatarLink::fromFilename(
- $group->stream_logo,
- AVATAR_STREAM_SIZE
- );
- $object->avatarLinks[] = AvatarLink::fromFilename(
- $group->mini_logo,
- AVATAR_MINI_SIZE
- );
- $object->poco = PoCo::fromGroup($group);
- Event::handle('EndActivityObjectFromGroup', [$group, &$object]);
- }
- return $object;
- }
- public static function fromPeopletag($ptag)
- {
- $object = new ActivityObject();
- if (Event::handle('StartActivityObjectFromPeopletag', [$ptag, &$object])) {
- $object->type = ActivityObject::_LIST;
- $object->id = $ptag->getUri();
- $object->title = $ptag->tag;
- $object->summary = $ptag->description;
- $object->link = $ptag->homeUrl();
- $object->owner = Profile::getKV('id', $ptag->tagger);
- $object->poco = PoCo::fromProfile($object->owner);
- Event::handle('EndActivityObjectFromPeopletag', [$ptag, &$object]);
- }
- return $object;
- }
- public static function fromFile(File $file)
- {
- $object = new ActivityObject();
- if (Event::handle('StartActivityObjectFromFile', [$file, &$object])) {
- $object->type = self::mimeTypeToObjectType($file->mimetype);
- $object->id = TagURI::mint(sprintf("file:%d", $file->id));
- $object->link = $file->getAttachmentUrl();
- if ($file->title) {
- $object->title = $file->title;
- }
- if ($file->date) {
- $object->date = $file->date;
- }
- try {
- $thumbnail = $file->getThumbnail();
- $object->thumbnail = $thumbnail;
- } catch (UseFileAsThumbnailException $e) {
- $object->thumbnail = null;
- } catch (UnsupportedMediaException $e) {
- $object->thumbnail = null;
- }
- switch (self::canonicalType($object->type)) {
- case 'image':
- $object->largerImage = $file->getUrl();
- break;
- case 'video':
- case 'audio':
- $object->stream = $file->getUrl();
- break;
- }
- Event::handle('EndActivityObjectFromFile', [$file, &$object]);
- }
- return $object;
- }
- public static function mimeTypeToObjectType($mimeType)
- {
- $ot = null;
- // Default
- if (empty($mimeType)) {
- return self::FILE;
- }
- $parts = explode('/', $mimeType);
- switch ($parts[0]) {
- case 'image':
- $ot = self::IMAGE;
- break;
- case 'audio':
- $ot = self::AUDIO;
- break;
- case 'video':
- $ot = self::VIDEO;
- break;
- default:
- $ot = self::FILE;
- }
- return $ot;
- }
- public static function canonicalType($type)
- {
- return ActivityUtils::resolveUri($type, true);
- }
- public static function fromNoticeSource(Notice_source $source)
- {
- $object = new ActivityObject();
- $wellKnown = ['web', 'xmpp', 'mail', 'omb', 'system', 'api', 'ostatus',
- 'activity', 'feed', 'mirror', 'twitter', 'facebook'];
- if (Event::handle('StartActivityObjectFromNoticeSource', [$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;
- } elseif ($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[] = ['status_net', ['source_code' => $source->code]];
- Event::handle('EndActivityObjectFromNoticeSource', [$source, &$object]);
- }
- return $object;
- }
- public static function fromMessage(Message $message)
- {
- $object = new ActivityObject();
- if (Event::handle('StartActivityObjectFromMessage', [$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', ['message' => $message->id]);
- }
- $object->extra[] = ['status_net', ['message_id' => $message->id]];
- Event::handle('EndActivityObjectFromMessage', [$message, &$object]);
- }
- return $object;
- }
- /*
- * Returns an array based on this Activity Object suitable for
- * encoding as JSON.
- *
- * @return array $object the activity object array
- */
- public function asString($tag = 'activity:object')
- {
- $xs = new XMLStringer(true);
- $this->outputTo($xs, $tag);
- return $xs->getString();
- }
- public function outputTo($xo, $tag = 'activity:object')
- {
- if (!empty($tag)) {
- $xo->elementStart($tag);
- }
- if (Event::handle('StartActivityObjectOutputAtom', [$this, $xo])) {
- $xo->element('activity:object-type', null, $this->type);
- // <author> uses URI
- if ($tag == 'author') {
- $xo->element(self::URI, null, $this->id);
- } else {
- $xo->element(self::ID, null, $this->id);
- }
- if (!empty($this->title)) {
- $name = common_xml_safe_str($this->title);
- if ($tag == 'author') {
- // XXX: Backward compatibility hack -- atom:name should contain
- // full name here, instead of nickname, i.e.: $name. Change
- // this in the next version.
- $xo->element(self::NAME, null, $this->poco->preferredUsername);
- } else {
- $xo->element(self::TITLE, null, $name);
- }
- }
- if (!empty($this->summary)) {
- $xo->element(
- self::SUMMARY,
- null,
- common_xml_safe_str($this->summary)
- );
- }
- if (!empty($this->content)) {
- // XXX: assuming HTML content here
- $xo->element(
- ActivityUtils::CONTENT,
- ['type' => 'html'],
- common_xml_safe_str($this->content)
- );
- }
- if (!empty($this->link)) {
- $xo->element(
- 'link',
- [
- 'rel' => 'alternate',
- 'type' => 'text/html',
- 'href' => $this->link
- ]
- );
- }
- if (!empty($this->selfLink)) {
- $xo->element(
- 'link',
- [
- 'rel' => 'self',
- 'type' => 'application/atom+xml',
- 'href' => $this->selfLink
- ]
- );
- }
- if (!empty($this->owner)) {
- $owner = $this->owner->asActivityNoun(self::AUTHOR);
- $xo->raw($owner);
- }
- if ($this->type == ActivityObject::PERSON
- || $this->type == ActivityObject::GROUP) {
- foreach ($this->avatarLinks as $alink) {
- $xo->element(
- 'link',
- [
- 'rel' => 'avatar',
- 'type' => $alink->type,
- 'media:width' => $alink->width,
- 'media:height' => $alink->height,
- 'href' => $alink->url,
- ]
- );
- }
- }
- if (!empty($this->geopoint)) {
- $xo->element(
- 'georss:point',
- null,
- $this->geopoint
- );
- }
- if (!empty($this->poco)) {
- $this->poco->outputTo($xo);
- }
- // @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) = array_pad($el, 3, null);
- $xo->element($extraTag, $attrs, $content);
- }
- Event::handle('EndActivityObjectOutputAtom', [$this, $xo]);
- }
- if (!empty($tag)) {
- $xo->elementEnd($tag);
- }
- return;
- }
- public function asArray()
- {
- $object = [];
- if (Event::handle('StartActivityObjectOutputJson', [$this, &$object])) {
- // XXX: attachments are added by Activity
- // author (Add object for author? Could be useful for repeats.)
- // content (Add rendered version of the notice?)
- // downstreamDuplicates
- // id
- if ($this->id) {
- $object['id'] = $this->id;
- } elseif ($this->link) {
- $object['id'] = $this->link;
- }
- 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.
- $imgLink = null;
- $avatarMediaLinks = [];
- foreach ($this->avatarLinks as $a) {
- // Make a MediaLink for every other Avatar
- $avatar = new ActivityStreamsMediaLink(
- $a->url,
- $a->width,
- $a->height,
- $a->type,
- 'avatar'
- );
- // Find the big avatar to use as the "image"
- if ($a->height == AVATAR_PROFILE_SIZE) {
- $imgLink = $avatar;
- }
- $avatarMediaLinks[] = $avatar->asArray();
- }
- if (!array_key_exists('status_net', $object)) {
- $object['status_net'] = [];
- }
- $object['status_net']['avatarLinks'] = $avatarMediaLinks; // extension
- // image
- if (!empty($imgLink)) {
- $object['image'] = $imgLink->asArray();
- }
- }
- // objectType
- //
- // We can probably use the whole schema URL here but probably the
- // relative simple name is easier to parse
- $object['objectType'] = self::canonicalType($this->type);
- // summary
- $object['summary'] = $this->summary;
- // content, usually rendered HTML
- $object['content'] = $this->content;
- // published (probably don't need. Might be useful for repeats.)
- // updated (probably don't need this)
- // TODO: upstreamDuplicates
- if ($this->link) {
- $object['url'] = $this->link;
- }
- /* Extensions */
- // @fixme these may collide with XML extensions
- // @fixme multiple tags of same name will overwrite each other
- // @fixme text content from XML extensions will be lost
- foreach ($this->extra as $e) {
- list($objectName, $props, $txt) = array_pad($e, 3, null);
- if (!empty($objectName)) {
- $parts = explode(":", $objectName);
- if (count($parts) == 2 && $parts[0] == "statusnet") {
- if (!array_key_exists('status_net', $object)) {
- $object['status_net'] = [];
- }
- $object['status_net'][$parts[1]] = $props;
- } else {
- $object[$objectName] = $props;
- }
- }
- }
- if (!empty($this->geopoint)) {
- list($lat, $lon) = explode(' ', $this->geopoint);
- if (!empty($lat) && !empty($lon)) {
- $object['location'] = [
- 'objectType' => 'place',
- 'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon),
- 'lat' => $lat,
- 'lon' => $lon
- ];
- $loc = Location::fromLatLon((float)$lat, (float)$lon);
- if ($loc) {
- $name = $loc->getName();
- if ($name) {
- $object['location']['displayName'] = $name;
- }
- $url = $loc->getURL();
- if ($url) {
- $object['location']['url'] = $url;
- }
- }
- }
- }
- if (!empty($this->poco)) {
- $object['portablecontacts_net'] = array_filter($this->poco->asArray());
- }
- if (!empty($this->thumbnail)) {
- if (is_string($this->thumbnail)) {
- $object['image'] = ['url' => $this->thumbnail];
- } else {
- $object['image'] = ['url' => $this->thumbnail->getUrl()];
- if ($this->thumbnail->width) {
- $object['image']['width'] = $this->thumbnail->width;
- }
- if ($this->thumbnail->height) {
- $object['image']['height'] = $this->thumbnail->height;
- }
- }
- }
- switch (self::canonicalType($this->type)) {
- case 'image':
- if (!empty($this->largerImage)) {
- $object['fullImage'] = ['url' => $this->largerImage];
- }
- break;
- case 'audio':
- case 'video':
- if (!empty($this->stream)) {
- $object['stream'] = ['url' => $this->stream];
- }
- break;
- }
- Event::handle('EndActivityObjectOutputJson', [$this, &$object]);
- }
- return array_filter($object);
- }
- public function getIdentifiers()
- {
- $ids = [];
- foreach (['id', 'link', 'url'] as $id) {
- if (isset($this->$id)) {
- $ids[] = $this->$id;
- }
- }
- return array_unique($ids);
- }
- }
|