// the surrounding feed.
$this->actor = new ActivityObject($authorEl);
- } else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
- self::ATOM)) {
-
- // If there's no <atom:author> on the entry, it's safe to assume
- // the containing feed's authorship info applies.
- $this->actor = new ActivityObject($authorEl);
} else if (!empty($feed) &&
$subjectEl = $this->_child($feed, self::SUBJECT)) {
// Feed subject is used for things like groups.
// Should actually possibly not be interpreted as an actor...?
$this->actor = new ActivityObject($subjectEl);
+
+ } else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
+ self::ATOM)) {
+
+ // If there's no <atom:author> on the entry, it's safe to assume
+ // the containing feed's authorship info applies.
+ $this->actor = new ActivityObject($authorEl);
}
$contextEl = $this->_child($entry, self::CONTEXT);
return null;
}
+ /**
+ * Returns an array based on this activity suitable
+ * for encoding as a JSON object
+ *
+ * @return array $activity
+ */
+
+ function asArray()
+ {
+ $activity = array();
+
+ // actor
+ $activity['actor'] = $this->actor->asArray();
+
+ // body
+ $activity['body'] = $this->content;
+
+ // generator <--- might be useful; might be too much junk
+
+ // icon <-- should we use this?
+
+ // object
+ if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) {
+ $activity['object'] = $this->objects[0]->asArray();
+ } else {
+ $activity['object'] = array();
+ foreach($this->objects as $object) {
+ $activity['object'][] = $object->asArray();
+ }
+ }
+
+ $activity['postedTime'] = self::iso8601Date($this->time); // Change to exactly be RFC3339?
+
+ // provider <--- again not sure we should use this
+
+ // target
+ if (!empty($this->target)) {
+ $activity['target'] = $this->target->asArray();
+ }
+
+ // title
+ $activity['title'] = $this->title;
+
+ // updatedTime <-- should we use? spec says activity MAY have this
+
+ // verb
+ $activity['verb'] = $this->verb;
+
+ // TODO: extensions (ActivityContext, OStatus stuff, etc.)
+
+ return array_filter($activity);
+ }
+
function asString($namespace=false, $author=true, $source=false)
{
$xs = new XMLStringer(true);
$xs->element('title', null, $this->title);
$xs->element('content', array('type' => 'html'), $this->content);
-
+
if (!empty($this->summary)) {
$xs->element('summary', null, $this->summary);
}
-
+
if (!empty($this->link)) {
$xs->element('link', array('rel' => 'alternate',
'type' => 'text/html'),
$xs->element('activity:verb', null, $this->verb);
$published = self::iso8601Date($this->time);
-
+
$xs->element('published', null, $published);
$xs->element('updated', null, $published);
-
+
if ($author) {
$this->actor->outputTo($xs, 'author');
+
+ // XXX: Remove <activity:actor> ASAP! Author information
+ // has been moved to the author element in the Activity
+ // Streams spec. We're outputting actor only for backward
+ // compatibility with clients that can only parse
+ // activities based on older versions of the spec.
+
+ $depMsg = 'Deprecation warning: activity:actor is present '
+ . 'only for backward compatibility. It will be '
+ . 'removed in the next version of StatusNet.';
+ $xs->comment($depMsg);
+ $this->actor->outputTo($xs, 'activity:actor');
}
if ($this->verb != ActivityVerb::POST || count($this->objects) != 1) {
}
// can be either URLs or enclosure objects
-
+
foreach ($this->enclosures as $enclosure) {
if (is_string($enclosure)) {
$xs->element('link', array('rel' => 'enclosure',
if ($source && !empty($this->source)) {
$xs->elementStart('source');
-
+
$xs->element('id', null, $this->source->id);
$xs->element('title', null, $this->source->title);
'type' => 'text/html',
'href' => $this->source->links['alternate']));
}
-
+
if (array_key_exists('self', $this->source->links)) {
$xs->element('link', array('rel' => 'self',
'type' => 'application/atom+xml',
if (!empty($this->source->updated)) {
$xs->element('updated', null, $this->source->updated);
}
-
+
$xs->elementEnd('source');
}
}
// For throwing in extra elements; used for statusnet:notice_info
-
+
foreach ($this->extra as $el) {
list($tag, $attrs, $content) = $el;
$xs->element($tag, $attrs, $content);