* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+require_once(INSTALLDIR.'/lib/activitystreamjsondocument.php');
/**
* A noun-ish thing in the activity universe
$this->type = self::PERSON; // XXX: is this fair?
}
- // start with <atom:title>
- $title = ActivityUtils::childHtmlContent($element, self::TITLE);
+ // Start with <poco::displayName>
+
+ $this->title = ActivityUtils::childContent($element, PoCo::DISPLAYNAME, PoCo::NS);
- if (!empty($title)) {
- $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8');
+ // 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>
+ // fall back to <atom:name> as a last resort
if (empty($this->title)) {
$this->title = $this->_childContent($element, self::NAME);
$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);
if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
$this->id = $this->link;
}
+
+ $els = $element->childNodes;
+ $out = array();
+
+ for ($i = 0; $i < $els->length; $i++) {
+ $link = $els->item($i);
+ if ($link->localName == ActivityUtils::LINK && $link->namespaceURI == ActivityUtils::ATOM) {
+ $attrs = array();
+ foreach ($link->attributes as $attrName=>$attrNode) {
+ $attrs[$attrName] = $attrNode->nodeValue;
+ }
+ $this->extra[] = [$link->localName,
+ $attrs,
+ $link->nodeValue];
+ }
+ }
}
// @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($guidEl)) {
$this->id = $guidEl->textContent;
- if ($guidEl->hasAttribute('isPermaLink')) {
+ if ($guidEl->hasAttribute('isPermaLink') && $guidEl->getAttribute('isPermaLink') != 'false') {
// overwrites <link>
$this->link = $this->id;
}
}
}
- 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->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 {
- $orig = Avatar::getOriginal($profile);
- $object->avatarLinks[] = AvatarLink::fromAvatar($orig);
- } catch (Exception $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;
- $avatar = $profile->getAvatar($size);
-
- if (!empty($avatar)) {
- $alink = AvatarLink::fromAvatar($avatar);
- } else {
- $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;
- }
-
- 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($group)
+ static function fromGroup(User_group $group)
{
$object = new ActivityObject();
$object->type = self::mimeTypeToObjectType($file->mimetype);
$object->id = TagURI::mint(sprintf("file:%d", $file->id));
- $object->link = common_local_url('attachment', array('attachment' => $file->id));
+ $object->link = $file->getAttachmentUrl();
if ($file->title) {
$object->title = $file->title;
$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;
}
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);
}
}
// content (Add rendered version of the notice?)
- // displayName
-
- if ($this->title) {
- $object['displayName'] = $this->title;
- }
-
// downstreamDuplicates
// id
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.
// 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;
- // content
+ // content, usually rendered HTML
$object['content'] = $this->content;
// published (probably don't need. Might be useful for repeats.)
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;
}
}
}
- switch (ActivityObject::canonicalType($this->type)) {
+ switch (self::canonicalType($this->type)) {
case 'image':
if (!empty($this->largerImage)) {
$object['fullImage'] = array('url' => $this->largerImage);
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) {