header('Content-Type: application/atom+xml; charset=utf-8');
try {
- $atom->addAuthorRaw($this->group->asAtomAuthor());
- $atom->setActivitySubject($this->group->asActivitySubject());
- $atom->setId($self);
- $atom->setSelfLink($self);
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
} catch (Atom10FeedException $e) {
$xs->element('updated', null, $published);
if ($author) {
- $xs->elementStart('author');
- $xs->element('uri', array(), $this->actor->id);
- if ($this->actor->title) {
- $xs->element('name', array(), $this->actor->title);
- }
- $xs->elementEnd('author');
- $this->actor->outputTo($xs, 'activity:actor');
+ $this->actor->outputTo($xs, 'author');
}
if ($this->verb != ActivityVerb::POST || count($this->objects) != 1) {
}
foreach ($this->categories as $cat) {
- $xs->raw($cat->asString());
+ $cat->outputTo($xs);
}
// can be either URLs or enclosure objects
private function _fromAuthor($element)
{
- $this->type = self::PERSON; // XXX: is this fair?
- $this->title = $this->_childContent($element, self::NAME);
+ $this->type = $this->_childContent($element,
+ Activity::OBJECTTYPE,
+ Activity::SPEC);
- $this->id = $this->_childContent($element, self::URI);
+ if (empty($this->type)) {
+ $this->type = self::PERSON; // XXX: is this fair?
+ }
+
+ // start with <atom:title>
+
+ $title = ActivityUtils::childHtmlContent($element, self::TITLE);
+
+ if (!empty($title)) {
+ $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8');
+ }
+
+ // fall back to <atom:name>
+
+ 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);
$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;
+ }
}
private function _fromAtomEntry($element)
$xo->element('activity:object-type', null, $this->type);
- $xo->element(self::ID, null, $this->id);
+ // <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)) {
- $xo->element(
- self::TITLE,
- null,
- common_xml_safe_str($this->title)
- );
+ $name = common_xml_safe_str($this->title);
+ if ($tag == 'author') {
+ $xo->element(self::NAME, null, $name);
+ } else {
+ $xo->element(self::TITLE, null, $name);
+ }
}
if (!empty($this->summary)) {
}
if (!empty($this->poco)) {
- $xo->raw($this->poco->asString());
+ $this->poco->outputTo($xo);
}
foreach ($this->extra as $el) {
}
/**
- * Add a activity feed subject via raw XML string
+ * Deprecated <activity:subject>; ignored
*
* @param string $xmlSubject An XML string representation of the subject
*
* @return void
*/
+
function setActivitySubject($xmlSubject)
{
- $this->subject = $xmlSubject;
+ throw new ServerException(_('Don\'t use this method!'));
}
function getNamespaces()
}
function asString()
+ {
+ $xs = new XMLStringer();
+ $this->outputTo($xs);
+ return $xs->getString();
+ }
+
+ function outputTo($xo)
{
$attribs = array();
if ($this->term !== null) {
if ($this->label !== null) {
$attribs['label'] = $this->label;
}
- $xs = new XMLStringer();
- $xs->element('category', $attribs);
- return $xs->getString();
+ $xo->element('category', $attribs);
}
}
$this->setId($self);
$this->setSelfLink($self);
- $this->addAuthorRaw($group->asAtomAuthor());
- $this->setActivitySubject($group->asActivitySubject());
+ $ao = ActivityObject::fromGroup($group);
+
+ $this->addAuthorRaw($ao->asString('author'));
$this->addLink($group->homeUrl());
}
$this->user = $user;
if (!empty($user)) {
$profile = $user->getProfile();
- $this->addAuthor($profile->nickname, $user->uri);
- $this->setActivitySubject($profile->asActivityNoun('subject'));
+ $ao = ActivityObject::fromProfile($profile);
+ $this->addAuthorRaw($ao->asString('author'));
}
// TRANS: Title in atom user notice feed. %s is a user name.
function asString()
{
$xs = new XMLStringer(true);
- $xs->element(
+ $this->outputTo($xs);
+ return $xs->getString();
+ }
+
+ function outputTo($xo)
+ {
+ $xo->element(
'poco:preferredUsername',
null,
$this->preferredUsername
);
- $xs->element(
+ $xo->element(
'poco:displayName',
null,
$this->displayName
);
if (!empty($this->note)) {
- $xs->element('poco:note', null, common_xml_safe_str($this->note));
+ $xo->element('poco:note', null, common_xml_safe_str($this->note));
}
if (!empty($this->address)) {
- $xs->raw($this->address->asString());
+ $this->address->outputTo($xo);
}
foreach ($this->urls as $url) {
- $xs->raw($url->asString());
+ $url->outputTo($xo);
}
-
- return $xs->getString();
}
}
// @todo Other address fields
function asString()
+ {
+ $xs = new XMLStringer(true);
+ $this->outputTo($xs);
+ return $xs->getString();
+ }
+
+ function outputTo($xo)
{
if (!empty($this->formatted)) {
- $xs = new XMLStringer(true);
- $xs->elementStart('poco:address');
- $xs->element('poco:formatted', null, common_xml_safe_str($this->formatted));
- $xs->elementEnd('poco:address');
- return $xs->getString();
+ $xo->elementStart('poco:address');
+ $xo->element('poco:formatted', null, common_xml_safe_str($this->formatted));
+ $xo->elementEnd('poco:address');
}
-
- return null;
}
}
function asString()
{
$xs = new XMLStringer(true);
- $xs->elementStart('poco:urls');
- $xs->element('poco:type', null, $this->type);
- $xs->element('poco:value', null, $this->value);
+ $this->outputTo($xs);
+ return $xs->getString();
+ }
+
+ function outputTo($xo)
+ {
+ $xo->elementStart('poco:urls');
+ $xo->element('poco:type', null, $this->type);
+ $xo->element('poco:value', null, $this->value);
if (!empty($this->primary)) {
- $xs->element('poco:primary', null, 'true');
+ $xo->element('poco:primary', null, 'true');
}
- $xs->elementEnd('poco:urls');
- return $xs->getString();
+ $xo->elementEnd('poco:urls');
}
}
$user = $feed->getUser();
$id = $user->id;
$profile = $user->getProfile();
- $feed->setActivitySubject($profile->asActivityNoun('subject'));
} else if ($feed instanceof AtomGroupNoticeFeed) {
$salmonAction = 'groupsalmon';
$group = $feed->getGroup();
$id = $group->id;
- $feed->setActivitySubject($group->asActivitySubject());
} else {
return true;
}