return !empty($notice);
}
+ /**
+ * Returns an XML string fragment with limited profile information
+ * as an Atom <author> element.
+ *
+ * Assumes that Atom has been previously set up as the base namespace.
+ *
+ * @return string
+ */
function asAtomAuthor()
{
$xs = new XMLStringer(true);
$xs->elementStart('author');
$xs->element('name', null, $this->nickname);
- $xs->element('uri', null, $this->profileurl);
+ $xs->element('uri', null, $this->getUri());
$xs->elementEnd('author');
return $xs->getString();
}
+ /**
+ * Returns an XML string fragment with profile information as an
+ * Activity Streams <activity:actor> element.
+ *
+ * Assumes that 'activity' namespace has been previously defined.
+ *
+ * @return string
+ */
function asActivityActor()
+ {
+ return $this->asActivityNoun('actor');
+ }
+
+ /**
+ * Returns an XML string fragment with profile information as an
+ * Activity Streams noun object with the given element type.
+ *
+ * Assumes that 'activity' namespace has been previously defined.
+ *
+ * @param string $element one of 'actor', 'subject', 'object', 'target'
+ * @return string
+ */
+ function asActivityNoun($element)
{
$xs = new XMLStringer(true);
- $xs->elementStart('activity:actor');
+ $xs->elementStart('activity:' . $element);
$xs->element(
'activity:object-type',
null,
$xs->element(
'id',
null,
- common_local_url(
- 'userbyid',
- array('id' => $this->id)
- )
+ $this->getUri()
);
$xs->element('title', null, $this->getBestName());
$xs->element(
'link', array(
'type' => empty($avatar) ? 'image/png' : $avatar->mediatype,
+ 'rel' => 'avatar',
'href' => empty($avatar)
? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
: $avatar->displayUrl()
''
);
- $xs->elementEnd('activity:actor');
+ $xs->elementEnd('activity:' . $element);
return $xs->getString();
}
- function getAcctUri()
+ /**
+ * Returns the best URI for a profile. Plugins may override.
+ *
+ * @return string $uri
+ */
+ function getUri()
{
- return $this->nickname . '@' . common_config('site', 'server');
+ $uri = null;
+
+ // check for a local user first
+ $user = User::staticGet('id', $this->id);
+
+ if (!empty($user)) {
+ $uri = common_local_url(
+ 'userbyid',
+ array('id' => $user->id)
+ );
+ } else {
+
+ // give plugins a chance to set the URI
+ if (Event::handle('StartGetProfileUri', array($this, &$uri))) {
+
+ // return OMB profile if any
+ $remote = Remote_profile::staticGet('id', $this->id);
+
+ if (!empty($remote)) {
+ $uri = $remote->uri;
+ }
+
+ Event::handle('EndGetProfileUri', array($this, &$uri));
+ }
+ }
+
+ return $uri;
}
}