Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
14a111189d
@ -1508,7 +1508,6 @@ class Notice extends Managed_DataObject
|
|||||||
$act->time = strtotime($this->created);
|
$act->time = strtotime($this->created);
|
||||||
$act->link = $this->bestUrl();
|
$act->link = $this->bestUrl();
|
||||||
$act->content = common_xml_safe_str($this->rendered);
|
$act->content = common_xml_safe_str($this->rendered);
|
||||||
$act->title = common_xml_safe_str($this->content);
|
|
||||||
|
|
||||||
$profile = $this->getProfile();
|
$profile = $this->getProfile();
|
||||||
|
|
||||||
@ -1545,9 +1544,9 @@ class Notice extends Managed_DataObject
|
|||||||
$attachments = $this->attachments();
|
$attachments = $this->attachments();
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
foreach ($attachments as $attachment) {
|
||||||
$enclosure = $attachment->getEnclosure();
|
// Save local attachments
|
||||||
if ($enclosure) {
|
if (!empty($attachment->filename)) {
|
||||||
$act->enclosures[] = $enclosure;
|
$act->attachments[] = ActivityObject::fromFile($attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1578,6 +1577,7 @@ class Notice extends Managed_DataObject
|
|||||||
$rprofile = Profile::staticGet('id', $id);
|
$rprofile = Profile::staticGet('id', $id);
|
||||||
if (!empty($rprofile)) {
|
if (!empty($rprofile)) {
|
||||||
$ctx->attention[] = $rprofile->getUri();
|
$ctx->attention[] = $rprofile->getUri();
|
||||||
|
$ctx->attentionType[$rprofile->getUri()] = ActivityObject::PERSON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1585,6 +1585,19 @@ class Notice extends Managed_DataObject
|
|||||||
|
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
$ctx->attention[] = $group->getUri();
|
$ctx->attention[] = $group->getUri();
|
||||||
|
$ctx->attentionType[$group->getUri()] = ActivityObject::GROUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($this->scope) {
|
||||||
|
case Notice::PUBLIC_SCOPE:
|
||||||
|
$ctx->attention[] = "http://activityschema.org/collection/public";
|
||||||
|
$ctx->attentionType["http://activityschema.org/collection/public"] = ActivityObject::COLLECTION;
|
||||||
|
break;
|
||||||
|
case Notice::FOLLOWER_SCOPE:
|
||||||
|
$surl = common_local_url("subscribers", array('nickname' => $profile->nickname));
|
||||||
|
$ctx->attention[] = $surl;
|
||||||
|
$ctx->attentionType[$surl] = ActivityObject::COLLECTION;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: deprecated; use ActivityVerb::SHARE instead
|
// XXX: deprecated; use ActivityVerb::SHARE instead
|
||||||
@ -1601,6 +1614,12 @@ class Notice extends Managed_DataObject
|
|||||||
|
|
||||||
$act->context = $ctx;
|
$act->context = $ctx;
|
||||||
|
|
||||||
|
$source = $this->getSource();
|
||||||
|
|
||||||
|
if ($source) {
|
||||||
|
$act->generator = ActivityObject::fromNoticeSource($source);
|
||||||
|
}
|
||||||
|
|
||||||
// Source
|
// Source
|
||||||
|
|
||||||
$atom_feed = $profile->getAtomFeed();
|
$atom_feed = $profile->getAtomFeed();
|
||||||
|
@ -1187,14 +1187,16 @@ class User extends Managed_DataObject
|
|||||||
|
|
||||||
$service = new ActivityObject();
|
$service = new ActivityObject();
|
||||||
|
|
||||||
$service->type = "service";
|
$service->type = ActivityObject::SERVICE;
|
||||||
$service->displayName = common_config('site', 'name');
|
$service->title = common_config('site', 'name');
|
||||||
$service->url = common_root_url();
|
$service->link = common_root_url();
|
||||||
|
$service->id = $service->link;
|
||||||
|
|
||||||
$act = new Activity();
|
$act = new Activity();
|
||||||
|
|
||||||
$act->actor = ActivityObject::fromProfile($profile);
|
$act->actor = ActivityObject::fromProfile($profile);
|
||||||
$act->verb = ActivityVerb::JOIN;
|
$act->verb = ActivityVerb::JOIN;
|
||||||
|
|
||||||
$act->objects[] = $service;
|
$act->objects[] = $service;
|
||||||
|
|
||||||
$act->id = TagURI::mint('user:register:%d',
|
$act->id = TagURI::mint('user:register:%d',
|
||||||
@ -1205,9 +1207,8 @@ class User extends Managed_DataObject
|
|||||||
$act->title = _("Register");
|
$act->title = _("Register");
|
||||||
|
|
||||||
$act->content = sprintf(_('%1$s joined %2$s.'),
|
$act->content = sprintf(_('%1$s joined %2$s.'),
|
||||||
$profile->getBestName(),
|
$profile->getBestName(),
|
||||||
$service->displayName);
|
$service->title);
|
||||||
|
|
||||||
return $act;
|
return $act;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
196
lib/activity.php
196
lib/activity.php
@ -100,12 +100,13 @@ class Activity
|
|||||||
public $title; // title of the activity
|
public $title; // title of the activity
|
||||||
public $categories = array(); // list of AtomCategory objects
|
public $categories = array(); // list of AtomCategory objects
|
||||||
public $enclosures = array(); // list of enclosure URL references
|
public $enclosures = array(); // list of enclosure URL references
|
||||||
|
public $attachments = array(); // list of attachments
|
||||||
|
|
||||||
public $extra = array(); // extra elements as array(tag, attrs, content)
|
public $extra = array(); // extra elements as array(tag, attrs, content)
|
||||||
public $source; // ActivitySource object representing 'home feed'
|
public $source; // ActivitySource object representing 'home feed'
|
||||||
public $selfLink; // <link rel='self' type='application/atom+xml'>
|
public $selfLink; // <link rel='self' type='application/atom+xml'>
|
||||||
public $editLink; // <link rel='edit' type='application/atom+xml'>
|
public $editLink; // <link rel='edit' type='application/atom+xml'>
|
||||||
|
public $generator; // ActivityObject representing the generating application
|
||||||
/**
|
/**
|
||||||
* Turns a regular old Atom <entry> into a magical activity
|
* Turns a regular old Atom <entry> into a magical activity
|
||||||
*
|
*
|
||||||
@ -365,8 +366,11 @@ class Activity
|
|||||||
// content
|
// content
|
||||||
$activity['content'] = $this->content;
|
$activity['content'] = $this->content;
|
||||||
|
|
||||||
// generator <-- We could use this when we know a notice is created
|
// generator
|
||||||
// locally. Or if we know the upstream Generator.
|
|
||||||
|
if (!empty($this->generator)) {
|
||||||
|
$activity['generator'] = $this->generator->asArray();
|
||||||
|
}
|
||||||
|
|
||||||
// icon <-- possibly a mini object representing verb?
|
// icon <-- possibly a mini object representing verb?
|
||||||
|
|
||||||
@ -374,101 +378,79 @@ class Activity
|
|||||||
$activity['id'] = $this->id;
|
$activity['id'] = $this->id;
|
||||||
|
|
||||||
// object
|
// object
|
||||||
if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) {
|
|
||||||
$activity['object'] = $this->objects[0]->asArray();
|
|
||||||
|
|
||||||
// Context stuff. For now I'm just sticking most of it
|
|
||||||
// in a property called "context"
|
|
||||||
|
|
||||||
if (!empty($this->context)) {
|
|
||||||
|
|
||||||
if (!empty($this->context->location)) {
|
|
||||||
$loc = $this->context->location;
|
|
||||||
|
|
||||||
// GeoJSON
|
|
||||||
|
|
||||||
$activity['geopoint'] = array(
|
|
||||||
'type' => 'Point',
|
|
||||||
'coordinates' => array($loc->lat, $loc->lon),
|
|
||||||
'deprecated' => true,
|
|
||||||
);
|
|
||||||
|
|
||||||
$activity['location'] = array(
|
|
||||||
'objectType' => 'place',
|
|
||||||
'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
|
|
||||||
'lat' => $loc->lat,
|
|
||||||
'lon' => $loc->lon
|
|
||||||
);
|
|
||||||
|
|
||||||
$name = $loc->getName();
|
|
||||||
|
|
||||||
if ($name) {
|
|
||||||
$activity['location']['displayName'] = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = $loc->getURL();
|
|
||||||
|
|
||||||
if ($url) {
|
|
||||||
$activity['location']['url'] = $url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$activity['to'] = $this->context->getToArray();
|
|
||||||
$activity['context'] = $this->context->asArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instead of adding enclosures as an extension to JSON
|
|
||||||
// Activities, it seems like we should be using the
|
|
||||||
// attachements property of ActivityObject
|
|
||||||
|
|
||||||
$attachments = array();
|
|
||||||
|
|
||||||
// XXX: OK, this is kinda cheating. We should probably figure out
|
|
||||||
// what kind of objects these are based on mime-type and then
|
|
||||||
// create specific object types. Right now this rely on
|
|
||||||
// duck-typing. Also, we should include an embed code for
|
|
||||||
// video attachments.
|
|
||||||
|
|
||||||
foreach ($this->enclosures as $enclosure) {
|
|
||||||
|
|
||||||
if (is_string($enclosure)) {
|
|
||||||
|
|
||||||
$attachments[]['id'] = $enclosure;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$attachments[]['id'] = $enclosure->url;
|
|
||||||
|
|
||||||
$mediaLink = new ActivityStreamsMediaLink(
|
|
||||||
$enclosure->url,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$enclosure->mimetype
|
|
||||||
// XXX: Add 'size' as an extension to MediaLink?
|
|
||||||
);
|
|
||||||
|
|
||||||
$attachments[]['mediaLink'] = $mediaLink->asArray(); // extension
|
|
||||||
|
|
||||||
if ($enclosure->title) {
|
|
||||||
$attachments[]['displayName'] = $enclosure->title;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($attachments)) {
|
|
||||||
$activity['object']['attachments'] = $attachments;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (count($this->objects) == 0) {
|
||||||
|
common_log(LOG_ERR, "Can't save " . $this->id);
|
||||||
} else {
|
} else {
|
||||||
$activity['object'] = array();
|
if (count($this->objects) > 1) {
|
||||||
foreach($this->objects as $object) {
|
common_log(LOG_WARNING, "Ignoring " . (count($this->objects) - 1) . " extra objects in JSON output for activity " . $this->id);
|
||||||
$oa = $object->asArray();
|
}
|
||||||
if ($object instanceof Activity) {
|
$object = $this->objects[0];
|
||||||
// throw in a type
|
|
||||||
// XXX: hackety-hack
|
if ($object instanceof Activity) {
|
||||||
$oa['objectType'] = 'activity';
|
// Sharing a post activity is more like sharing the original object
|
||||||
|
if ($this->verb == 'share' && $object->verb == 'post') {
|
||||||
|
// XXX: Here's one for the obfuscation record books
|
||||||
|
$object = $object->object;
|
||||||
}
|
}
|
||||||
$activity['object'][] = $oa;
|
}
|
||||||
|
|
||||||
|
$activity['object'] = $object->asArray();
|
||||||
|
|
||||||
|
if ($object instanceof Activity) {
|
||||||
|
$activity['object']['objectType'] = 'activity';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->attachments as $attachment) {
|
||||||
|
if (empty($activity['object']['attachments'])) {
|
||||||
|
$activity['object']['attachments'] = array();
|
||||||
|
}
|
||||||
|
$activity['object']['attachments'][] = $attachment->asArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context stuff.
|
||||||
|
|
||||||
|
if (!empty($this->context)) {
|
||||||
|
|
||||||
|
if (!empty($this->context->location)) {
|
||||||
|
$loc = $this->context->location;
|
||||||
|
|
||||||
|
$activity['location'] = array(
|
||||||
|
'objectType' => 'place',
|
||||||
|
'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
|
||||||
|
'lat' => $loc->lat,
|
||||||
|
'lon' => $loc->lon
|
||||||
|
);
|
||||||
|
|
||||||
|
$name = $loc->getName();
|
||||||
|
|
||||||
|
if ($name) {
|
||||||
|
$activity['location']['displayName'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $loc->getURL();
|
||||||
|
|
||||||
|
if ($url) {
|
||||||
|
$activity['location']['url'] = $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$activity['to'] = $this->context->getToArray();
|
||||||
|
|
||||||
|
$ctxarr = $this->context->asArray();
|
||||||
|
|
||||||
|
if (array_key_exists('inReplyTo', $ctxarr)) {
|
||||||
|
$activity['object']['inReplyTo'] = $ctxarr['inReplyTo'];
|
||||||
|
unset($ctxarr['inReplyTo']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists('status_net', $activity)) {
|
||||||
|
$activity['status_net'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($ctxarr as $key => $value) {
|
||||||
|
$activity['status_net'][$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,10 +478,8 @@ class Activity
|
|||||||
// eceived a remote notice? Probably not.
|
// eceived a remote notice? Probably not.
|
||||||
|
|
||||||
// verb
|
// verb
|
||||||
//
|
|
||||||
// We can probably use the whole schema URL here but probably the
|
$activity['verb'] = ActivityVerb::canonical($this->verb);
|
||||||
// relative simple name is easier to parse
|
|
||||||
$activity['verb'] = substr($this->verb, strrpos($this->verb, '/') + 1);
|
|
||||||
|
|
||||||
// url
|
// url
|
||||||
$activity['url'] = $this->id;
|
$activity['url'] = $this->id;
|
||||||
@ -527,7 +507,15 @@ class Activity
|
|||||||
foreach ($this->extra as $e) {
|
foreach ($this->extra as $e) {
|
||||||
list($objectName, $props, $txt) = $e;
|
list($objectName, $props, $txt) = $e;
|
||||||
if (!empty($objectName)) {
|
if (!empty($objectName)) {
|
||||||
$activity[$objectName] = $props;
|
$parts = explode(":", $objectName);
|
||||||
|
if (count($parts) == 2 && $parts[0] == "statusnet") {
|
||||||
|
if (!array_key_exists('status_net', $activity)) {
|
||||||
|
$activity['status_net'] = array();
|
||||||
|
}
|
||||||
|
$activity['status_net'][$parts[1]] = $props;
|
||||||
|
} else {
|
||||||
|
$activity[$objectName] = $props;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +557,13 @@ class Activity
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
$xs->element('id', null, $this->id);
|
$xs->element('id', null, $this->id);
|
||||||
$xs->element('title', null, $this->title);
|
|
||||||
|
if ($this->title) {
|
||||||
|
$xs->element('title', null, $this->title);
|
||||||
|
} else {
|
||||||
|
// Require element
|
||||||
|
$xs->element('title', null, "");
|
||||||
|
}
|
||||||
|
|
||||||
$xs->element('content', array('type' => 'html'), $this->content);
|
$xs->element('content', array('type' => 'html'), $this->content);
|
||||||
|
|
||||||
|
@ -38,9 +38,11 @@ class ActivityContext
|
|||||||
public $replyToUrl;
|
public $replyToUrl;
|
||||||
public $location;
|
public $location;
|
||||||
public $attention = array();
|
public $attention = array();
|
||||||
|
public $attentionType = array();
|
||||||
public $conversation;
|
public $conversation;
|
||||||
public $forwardID; // deprecated, use ActivityVerb::SHARE instead
|
public $forwardID; // deprecated, use ActivityVerb::SHARE instead
|
||||||
public $forwardUrl; // deprecated, use ActivityVerb::SHARE instead
|
public $forwardUrl; // deprecated, use ActivityVerb::SHARE instead
|
||||||
|
public $scope;
|
||||||
|
|
||||||
const THR = 'http://purl.org/syndication/thread/1.0';
|
const THR = 'http://purl.org/syndication/thread/1.0';
|
||||||
const GEORSS = 'http://www.georss.org/georss';
|
const GEORSS = 'http://www.georss.org/georss';
|
||||||
@ -167,10 +169,14 @@ class ActivityContext
|
|||||||
$tos = array();
|
$tos = array();
|
||||||
|
|
||||||
foreach ($this->attention as $attnUrl) {
|
foreach ($this->attention as $attnUrl) {
|
||||||
|
if (array_key_exists($attnUrl, $this->attentionType)) {
|
||||||
|
$type = ActivityObject::canonicalType($this->attentionType[$attnUrl]);
|
||||||
|
} else {
|
||||||
|
$type = ActivityObject::canonicalType(ActivityObject::PERSON);
|
||||||
|
}
|
||||||
$to = array(
|
$to = array(
|
||||||
'objectType' => 'person',
|
'objectType' => $type,
|
||||||
'id' => $attnUrl,
|
'id' => $attnUrl
|
||||||
'url' => $attnUrl
|
|
||||||
);
|
);
|
||||||
$tos[] = $to;
|
$tos[] = $to;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,10 @@ class ActivityObject
|
|||||||
const COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
|
const COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
|
||||||
// ^^^^^^^^^^ tea!
|
// ^^^^^^^^^^ tea!
|
||||||
const ACTIVITY = 'http://activitystrea.ms/schema/1.0/activity';
|
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
|
// Atom elements we snarf
|
||||||
|
|
||||||
@ -110,6 +114,8 @@ class ActivityObject
|
|||||||
public $description;
|
public $description;
|
||||||
public $extra = array();
|
public $extra = array();
|
||||||
|
|
||||||
|
public $stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -432,7 +438,6 @@ class ActivityObject
|
|||||||
$object->type = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type;
|
$object->type = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type;
|
||||||
|
|
||||||
$object->id = $notice->uri;
|
$object->id = $notice->uri;
|
||||||
$object->title = $notice->content;
|
|
||||||
$object->content = $notice->rendered;
|
$object->content = $notice->rendered;
|
||||||
$object->link = $notice->bestUrl();
|
$object->link = $notice->bestUrl();
|
||||||
|
|
||||||
@ -499,6 +504,10 @@ class ActivityObject
|
|||||||
|
|
||||||
$object->poco = PoCo::fromProfile($profile);
|
$object->poco = PoCo::fromProfile($profile);
|
||||||
|
|
||||||
|
if ($profile->getUser()) {
|
||||||
|
$object->extra[] = array('followers', array('url' => common_local_url('subscribers', array('nickname' => $profile->nickname))));
|
||||||
|
}
|
||||||
|
|
||||||
Event::handle('EndActivityObjectFromProfile', array($profile, &$object));
|
Event::handle('EndActivityObjectFromProfile', array($profile, &$object));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,6 +558,86 @@ class ActivityObject
|
|||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function fromFile(File $file)
|
||||||
|
{
|
||||||
|
$object = new ActivityObject();
|
||||||
|
|
||||||
|
if (Event::handle('StartActivityObjectFromFile', array($file, &$object))) {
|
||||||
|
|
||||||
|
$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));
|
||||||
|
|
||||||
|
if ($file->title) {
|
||||||
|
$object->title = $file->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($file->date) {
|
||||||
|
$object->date = $file->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
$thumbnail = $file->getThumbnail();
|
||||||
|
|
||||||
|
if (!empty($thumbnail)) {
|
||||||
|
$object->thumbnail = $thumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (ActivityObject::canonicalType($object->type)) {
|
||||||
|
case 'image':
|
||||||
|
$object->largerImage = $file->url;
|
||||||
|
break;
|
||||||
|
case 'video':
|
||||||
|
case 'audio':
|
||||||
|
$object->stream = $file->url;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Event::handle('EndActivityObjectFromFile', array($file, &$object));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function fromNoticeSource(Notice_source $source)
|
||||||
|
{
|
||||||
|
$object = new ActivityObject();
|
||||||
|
|
||||||
|
if (Event::handle('StartActivityObjectFromNoticeSource', array($source, &$object))) {
|
||||||
|
$object->type = ActivityObject::APPLICATION;
|
||||||
|
|
||||||
|
if (in_array($source->code, array('web', 'xmpp', 'mail', 'omb', 'system', 'api'))) {
|
||||||
|
// 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->extras[] = array('status_net', array('source_code' => $source->code));
|
||||||
|
|
||||||
|
Event::handle('EndActivityObjectFromNoticeSource', array($source, &$object));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
|
||||||
function outputTo($xo, $tag='activity:object')
|
function outputTo($xo, $tag='activity:object')
|
||||||
{
|
{
|
||||||
if (!empty($tag)) {
|
if (!empty($tag)) {
|
||||||
@ -686,12 +775,20 @@ class ActivityObject
|
|||||||
// content (Add rendered version of the notice?)
|
// content (Add rendered version of the notice?)
|
||||||
|
|
||||||
// displayName
|
// displayName
|
||||||
$object['displayName'] = $this->title;
|
|
||||||
|
if ($this->title) {
|
||||||
|
$object['displayName'] = $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
// downstreamDuplicates
|
// downstreamDuplicates
|
||||||
|
|
||||||
// id
|
// id
|
||||||
$object['id'] = $this->id;
|
|
||||||
|
if ($this->id) {
|
||||||
|
$object['id'] = $this->id;
|
||||||
|
} else if ($this->link) {
|
||||||
|
$object['id'] = $this->link;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->type == ActivityObject::PERSON
|
if ($this->type == ActivityObject::PERSON
|
||||||
|| $this->type == ActivityObject::GROUP) {
|
|| $this->type == ActivityObject::GROUP) {
|
||||||
@ -721,7 +818,11 @@ class ActivityObject
|
|||||||
$avatarMediaLinks[] = $avatar->asArray();
|
$avatarMediaLinks[] = $avatar->asArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
$object['avatarLinks'] = $avatarMediaLinks; // extension
|
if (!array_key_exists('status_net', $object)) {
|
||||||
|
$object['status_net'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$object['status_net']['avatarLinks'] = $avatarMediaLinks; // extension
|
||||||
|
|
||||||
// image
|
// image
|
||||||
if (!empty($imgLink)) {
|
if (!empty($imgLink)) {
|
||||||
@ -733,13 +834,13 @@ class ActivityObject
|
|||||||
//
|
//
|
||||||
// We can probably use the whole schema URL here but probably the
|
// We can probably use the whole schema URL here but probably the
|
||||||
// relative simple name is easier to parse
|
// relative simple name is easier to parse
|
||||||
// @fixme this breaks extension URIs
|
|
||||||
$object['objectType'] = substr($this->type, strrpos($this->type, '/') + 1);
|
$object['objectType'] = ActivityObject::canonicalType($this->type);
|
||||||
|
|
||||||
// summary
|
// summary
|
||||||
$object['summary'] = $this->summary;
|
$object['summary'] = $this->summary;
|
||||||
|
|
||||||
// summary
|
// content
|
||||||
$object['content'] = $this->content;
|
$object['content'] = $this->content;
|
||||||
|
|
||||||
// published (probably don't need. Might be useful for repeats.)
|
// published (probably don't need. Might be useful for repeats.)
|
||||||
@ -748,33 +849,128 @@ class ActivityObject
|
|||||||
|
|
||||||
// TODO: upstreamDuplicates
|
// TODO: upstreamDuplicates
|
||||||
|
|
||||||
// url (XXX: need to put the right thing here...)
|
if ($this->link) {
|
||||||
$object['url'] = $this->id;
|
$object['url'] = $this->link;
|
||||||
|
}
|
||||||
|
|
||||||
/* Extensions */
|
/* Extensions */
|
||||||
// @fixme these may collide with XML extensions
|
// @fixme these may collide with XML extensions
|
||||||
// @fixme multiple tags of same name will overwrite each other
|
// @fixme multiple tags of same name will overwrite each other
|
||||||
// @fixme text content from XML extensions will be lost
|
// @fixme text content from XML extensions will be lost
|
||||||
|
|
||||||
foreach ($this->extra as $e) {
|
foreach ($this->extra as $e) {
|
||||||
list($objectName, $props, $txt) = $e;
|
list($objectName, $props, $txt) = $e;
|
||||||
$object[$objectName] = $props;
|
if (!empty($objectName)) {
|
||||||
|
$parts = explode(":", $objectName);
|
||||||
|
if (count($parts) == 2 && $parts[0] == "statusnet") {
|
||||||
|
if (!array_key_exists('status_net', $object)) {
|
||||||
|
$object['status_net'] = array();
|
||||||
|
}
|
||||||
|
$object['status_net'][$parts[1]] = $props;
|
||||||
|
} else {
|
||||||
|
$object[$objectName] = $props;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->geopoint)) {
|
if (!empty($this->geopoint)) {
|
||||||
|
|
||||||
list($lat, $long) = explode(' ', $this->geopoint);
|
list($lat, $lon) = explode(' ', $this->geopoint);
|
||||||
|
|
||||||
$object['geopoint'] = array(
|
$object['location'] = array(
|
||||||
'type' => 'Point',
|
'objectType' => 'place',
|
||||||
'coordinates' => array($lat, $long)
|
'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon),
|
||||||
|
'lat' => $lat,
|
||||||
|
'lon' => $lon
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$loc = Location::fromLatLon($lat, $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)) {
|
if (!empty($this->poco)) {
|
||||||
$object['contact'] = array_filter($this->poco->asArray());
|
$object['portablecontacts_net'] = array_filter($this->poco->asArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->thumbnail)) {
|
||||||
|
if (is_string($this->thumbnail)) {
|
||||||
|
$object['image'] = array('url' => $this->thumbnail);
|
||||||
|
} else {
|
||||||
|
$object['image'] = array('url' => $this->thumbnail->url);
|
||||||
|
if ($this->thumbnail->width) {
|
||||||
|
$object['image']['width'] = $this->thumbnail->width;
|
||||||
|
}
|
||||||
|
if ($this->thumbnail->height) {
|
||||||
|
$object['image']['height'] = $this->thumbnail->height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (ActivityObject::canonicalType($this->type)) {
|
||||||
|
case 'image':
|
||||||
|
if (!empty($this->largerImage)) {
|
||||||
|
$object['fullImage'] = array('url' => $this->largerImage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'audio':
|
||||||
|
case 'video':
|
||||||
|
if (!empty($this->stream)) {
|
||||||
|
$object['stream'] = array('url' => $this->stream);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Event::handle('EndActivityObjectOutputJson', array($this, &$object));
|
Event::handle('EndActivityObjectOutputJson', array($this, &$object));
|
||||||
}
|
}
|
||||||
return array_filter($object);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,9 +201,9 @@ class ActivityStreamsMediaLink extends ActivityStreamsLink
|
|||||||
{
|
{
|
||||||
parent::__construct($url, $rel, $mediaType);
|
parent::__construct($url, $rel, $mediaType);
|
||||||
$this->linkDict = array(
|
$this->linkDict = array(
|
||||||
'width' => $width,
|
'width' => intval($width),
|
||||||
'height' => $height,
|
'height' => intval($height),
|
||||||
'duration' => $duration
|
'duration' => intval($duration)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,4 +63,13 @@ class ActivityVerb
|
|||||||
|
|
||||||
// For simple profile-update pings; no content to share.
|
// For simple profile-update pings; no content to share.
|
||||||
const UPDATE_PROFILE = 'http://ostatus.org/schema/1.0/update-profile';
|
const UPDATE_PROFILE = 'http://ostatus.org/schema/1.0/update-profile';
|
||||||
|
|
||||||
|
static function canonical($verb) {
|
||||||
|
$ns = 'http://activitystrea.ms/schema/1.0/';
|
||||||
|
if (substr($verb, 0, mb_strlen($ns)) == $ns) {
|
||||||
|
return substr($verb, mb_strlen($ns));
|
||||||
|
} else {
|
||||||
|
return $verb;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user