// This is the document about the user
- $this->showPpd('', $this->user->uri);
+ $this->showPpd('', $this->user->getUri());
// Would be nice to tell if they were a Person or not (e.g. a #person usertag?)
- $this->elementStart('Agent', array('rdf:about' =>
- $this->user->uri));
+ $this->elementStart('Agent', array('rdf:about' => $this->user->getUri()));
if ($this->user->email) {
$this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email));
}
}
$person = $this->showMicrobloggingAccount($this->profile,
- common_root_url(), $this->user->uri,
+ common_root_url(), $this->user->getUri(),
/*$fetchSubscriptions*/true,
/*$isSubscriber*/false);
if ($sub->find()) {
while ($sub->fetch()) {
$profile = Profile::getKV('id', $sub->subscriber);
- if (empty($profile)) {
+ if (!$profile instanceof Profile) {
common_debug('Got a bad subscription: '.print_r($sub,true));
continue;
}
$profile = Profile::getKV($id);
$this->elementStart('Agent', array('rdf:about' => $uri));
if ($type == BOTH) {
- $this->element('knows', array('rdf:resource' => $this->user->uri));
+ $this->element('knows', array('rdf:resource' => $this->user->getUri()));
}
$this->showMicrobloggingAccount($profile,
($local == 'local') ? common_root_url() : null,
unset($sub);
} else if ($isSubscriber) {
// Just declare that they follow the user whose FOAF we're showing.
- $this->element('sioc:follows', array('rdf:resource' => $this->user->uri . '#acct'));
+ $this->element('sioc:follows', array('rdf:resource' => $this->user->getUri() . '#acct'));
}
$this->elementEnd('OnlineAccount');
return $this->profileurl;
}
+ public function getNickname()
+ {
+ return $this->nickname;
+ }
+
/**
* Returns the best URI for a profile. Plugins may override.
*
// check for a local user first
$user = User::getKV('id', $this->id);
-
- if (!empty($user)) {
- $uri = $user->uri;
+ if ($user instanceof User) {
+ $uri = $user->getUri();
}
Event::handle('EndGetProfileUri', array($this, &$uri));
return $this->_profile;
}
+ public function getUri()
+ {
+ return $this->uri;
+ }
+
function isSubscribed(Profile $other)
{
return $this->getProfile()->isSubscribed($other);
$qm = QueueManager::get();
foreach ($acts as $act) {
- $qm->enqueue(array($act, $sink, $user->uri, $remote), 'actmove');
+ $qm->enqueue(array($act, $sink, $user->getUri(), $remote), 'actmove');
}
$this->log(LOG_INFO,
* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- // This check helps protect against security problems;
- // your code file can't be executed directly from the web.
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Class comment
$other = $activity->actor;
$otherUser = User::getKV('uri', $other->id);
- if (!empty($otherUser)) {
- $otherProfile = $otherUser->getProfile();
- } else {
+ if (!$otherUser instanceof User) {
// TRANS: Client exception thrown when trying to force a remote user to subscribe.
throw new Exception(_('Cannot force remote user to subscribe.'));
}
+ $otherProfile = $otherUser->getProfile();
+
// XXX: don't do this for untrusted input!
Subscription::start($otherProfile, $profile);
$group = User_group::getKV('uri', $uri);
- if (empty($group)) {
+ if (!$group instanceof User_group) {
$oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]);
if (!$oprofile->isGroup()) {
// TRANS: Client exception thrown when trying to join a remote group that is not a group.
$notice = Notice::getKV('uri', $sourceUri);
- if (!empty($notice)) {
+ if ($notice instanceof Notice) {
common_log(LOG_INFO, "Notice {$sourceUri} already exists.");
$uri = $profile->getUri();
- if ($uri == $author->id) {
- common_log(LOG_INFO, "Updating notice author from $author->id to $user->uri");
+ if ($uri === $author->id) {
+ common_log(LOG_INFO, sprintf('Updating notice author from %s to %s', $author->id, $user->getUri()));
$orig = clone($notice);
$notice->profile_id = $user->id;
$notice->update($orig);
// Maintain direct reply associations
// @fixme what about conversation ID?
if (!empty($activity->context->replyToID)) {
- $orig = Notice::getKV('uri',
- $activity->context->replyToID);
- if (!empty($orig)) {
+ $orig = Notice::getKV('uri', $activity->context->replyToID);
+ if ($orig instanceof Notice) {
$options['reply_to'] = $orig->id;
}
}
}
break;
case ActivityVerb::FOLLOW:
- if ($act->actor->id == $user->uri) {
+ if ($act->actor->id === $user->getUri()) {
$this->log(LOG_INFO,
"Moving subscription to {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
try {
if ($format == Feed::ATOM) {
// Only show the author sub-element if it's different from default user
- $act->outputTo($this, false, ($act->actor->id != $this->user->uri));
+ $act->outputTo($this, false, ($act->actor->id != $this->user->getUri()));
} else {
if ($haveOne) {
fwrite($handle, ",");
if (Event::handle('StartCommonProfileURI', array($profile, &$uri))) {
$user = User::getKV('id', $profile->id);
if ($user instanceof User) {
- $uri = $user->uri;
+ $uri = $user->getUri();
}
Event::handle('EndCommonProfileURI', array($profile, &$uri));
}
if (isset($this->contact)) {
$contactuser = User::getKV('nickname', $this->contact);
- if (!empty($contactuser)) {
- $contactlink = "@<a href=\"$contactuser->uri\">$contactuser->nickname</a>";
+ if ($contactuser instanceof User) {
+ $contactlink = sprintf('@<a href="%s">%s</a>',
+ htmlspecialchars($contactuser->getProfile()->getUrl()),
+ htmlspecialchars($contactuser->getProfile()->getNickname()));
// TRANS: User instructions after registration.
- // TRANS: %s is a clickable e-mailaddress.
+ // TRANS: %s is a clickable OStatus profile URL.
$instr = sprintf(_m('Note you will initially be "sandboxed" so your posts will not appear in the public timeline. '.
'Send a message to %s to speed up the unsandboxing process.'),$contactlink);
}
throw new ClientException(_m('In reply to a notice not by this user and not mentioning this user.'));
}
} else if (!empty($context->attention)) {
- if (!array_key_exists($this->user->uri, $context->attention) &&
+ if (!array_key_exists($this->user->getUri(), $context->attention) &&
!array_key_exists(common_profile_url($this->user->nickname), $context->attention)) {
- common_log(LOG_ERR, "{$this->user->uri} not in attention list (".implode(',', array_keys($context->attention)).')');
+ common_log(LOG_ERR, $this->user->getUri() . "not in attention list (".implode(',', array_keys($context->attention)).')');
// TRANS: Client exception.
throw new ClientException(_m('To the attention of user(s), not including this one.'));
}
}
$existing = Notice::getKV('uri', $this->activity->objects[0]->id);
-
- if (!empty($existing)) {
- common_log(LOG_ERR, "Not saving notice '{$existing->uri}'; already exists.");
+ if ($existing instanceof Notice) {
+ common_log(LOG_ERR, "Not saving notice '".$existing->getUri()."'; already exists.");
return;
}
{
$oprofile = $this->ensureProfile();
if ($oprofile) {
- common_log(LOG_INFO, "Setting up subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+ common_log(LOG_INFO, sprintf('Setting up subscription from remote %s to local %s', $oprofile->getUri(), $this->user->getNickname()));
Subscription::start($oprofile->localProfile(),
$this->user->getProfile());
} else {
{
$oprofile = $this->ensureProfile();
if ($oprofile) {
- common_log(LOG_INFO, "Canceling subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+ common_log(LOG_INFO, sprintf('Canceling subscription from remote %s to local %s', $oprofile->getUri(), $this->user->getNickname()));
Subscription::cancel($oprofile->localProfile(), $this->user->getProfile());
} else {
common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile");
public function subscribe()
{
if ($this->sub_state && $this->sub_state != 'inactive') {
- common_log(LOG_WARNING, "Attempting to (re)start PuSH subscription to {$this->uri} in unexpected state {$this->sub_state}");
+ common_log(LOG_WARNING, sprintf('Attempting to (re)start PuSH subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state));
}
if (!Event::handle('FeedSubscribe', array($this))) {
*/
public function unsubscribe() {
if ($this->sub_state != 'active') {
- common_log(LOG_WARNING, "Attempting to (re)end PuSH subscription to {$this->uri} in unexpected state {$this->sub_state}");
+ common_log(LOG_WARNING, sprintf('Attempting to (re)end PuSH subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state));
}
if (!Event::handle('FeedUnsubscribe', array($this))) {
Event::handle('FeedSubSubscriberCount', array($this, &$count));
if ($count) {
- common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->uri);
+ common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->getUri());
return false;
} else {
- common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->uri);
+ common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->getUri());
return $this->unsubscribe();
}
}
'hub.verify_token' => 'Deprecated-since-PuSH-0.4', // TODO: rm!
'hub.secret' => $this->secret,
- 'hub.topic' => $this->uri);
+ 'hub.topic' => $this->getUri());
$client = new HTTPClient();
if ($this->huburi) {
$hub = $this->huburi;
}
} catch (Exception $e) {
// wtf!
- common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to $this->uri");
+ common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to " . $this->getUri());
$orig = clone($this);
$this->sub_state = 'inactive';
*/
public function receive($post, $hmac)
{
- common_log(LOG_INFO, __METHOD__ . ": packet for \"$this->uri\"! $hmac $post");
+ common_log(LOG_INFO, __METHOD__ . ": packet for \"" . $this->getUri() . "\"! $hmac $post");
if ($this->sub_state != 'active') {
- common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed $this->uri (in state '$this->sub_state')");
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed " . $this->getUri() . " (in state '$this->sub_state')");
return;
}
if ($tempfile) {
file_put_contents($tempfile, $post);
}
- common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed $this->uri on $this->huburi; saved to $tempfile");
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed " . $this->getUri() . " on $this->huburi; saved to $tempfile");
} else {
- common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed $this->uri on $this->huburi");
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac for feed " . $this->getUri() . " on $this->huburi");
}
} else {
common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bogus HMAC '$hmac'");
);
}
+ public function getUri()
+ {
+ return $this->uri;
+ }
+
/**
* Fetch the StatusNet-side profile for this feed
* @return Profile
return true;
} else if ($this->group_id && ($this->profile_id || $this->peopletag_id)) {
// TRANS: Server exception. %s is a URI
- throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->uri));
+ throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->getUri()));
} else {
// TRANS: Server exception. %s is a URI
- throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->uri));
+ throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->getUri()));
}
}
return true;
} else if ($this->peopletag_id && ($this->profile_id || $this->group_id)) {
// TRANS: Server exception. %s is a URI
- throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->uri));
+ throw new ServerException(sprintf(_m('Invalid ostatus_profile state: Two or more IDs set for %s.'), $this->getUri()));
} else {
// TRANS: Server exception. %s is a URI
- throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->uri));
+ throw new ServerException(sprintf(_m('Invalid ostatus_profile state: All IDs empty for %s.'), $this->getUri()));
}
}
$groups[] = $oprofile->group_id;
} else {
// may be canonicalized or something
- $replies[] = $oprofile->uri;
+ $replies[] = $oprofile->getUri();
}
continue;
} catch (Exception $e) {
throw new ServerException(sprintf(
// TRANS: Server exception. %s is a URI.
_m('Tried to update avatar for unsaved remote profile %s.'),
- $this->uri));
+ $this->getUri()));
}
// @todo FIXME: This should be better encapsulated
}
$user = User::getKV('uri', $homeuri);
- if ($user) {
+ if ($user instanceof User) {
// TRANS: Exception.
throw new Exception(_m('Local user cannot be referenced as remote.'));
}
$oprofile = Ostatus_profile::getKV('uri', 'acct:'.$addr);
if ($oprofile instanceof Ostatus_profile) {
- self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri());
return $oprofile;
}
try {
common_log(LOG_INFO, "Discovery on acct:$addr with feed URL " . $hints['feedurl']);
$oprofile = self::ensureFeedURL($hints['feedurl'], $hints);
- self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri());
return $oprofile;
} catch (Exception $e) {
common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage());
try {
common_log(LOG_INFO, "Discovery on acct:$addr with profile URL $profileUrl");
$oprofile = self::ensureProfileURL($hints['profileurl'], $hints);
- self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri());
return $oprofile;
} catch (OStatusShadowException $e) {
// We've ended up with a remote reference to a local user or group.
throw new Exception(sprintf(_m('Could not save OStatus profile for "%s".'),$addr));
}
- self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->getUri());
return $oprofile;
}
// Groups can't post notices in StatusNet.
common_log(LOG_WARNING,
"OStatus: skipping post with group listed ".
- "as author: $oprofile->uri in feed from $this->uri");
+ "as author: " . $oprofile->getUri() . " in feed from " . $this->getUri());
return false;
}
} else {
if (empty($actor)) {
// OK here! assume the default
- } else if ($actor->id == $this->uri || $actor->link == $this->uri) {
+ } else if ($actor->id == $this->getUri() || $actor->link == $this->getUri()) {
$this->updateFromActivityObject($actor);
} else if ($actor->id) {
// We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner.
// Most likely this is a plain ol' blog feed of some kind which
// doesn't match our expectations. We'll take the entry, but ignore
// the <author> info.
- common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}");
+ common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for " . $this->getUri());
} else {
// Plain <author> without ActivityStreams actor info.
// We'll just ignore this info for now and save the update under the feed's identity.
echo "Found $count...\n";
while ($user->fetch()) {
- $uri = $user->uri;
+ $uri = $user->getUri();
echo "user $user->id ($user->nickname) hidden by $uri";
if ($dry) {
echo " - skipping\n";
echo "Found $count...\n";
while ($group->fetch()) {
- $uri = $group->uri;
+ $uri = $group->getUri();
echo "group $group->id ($group->nickname) hidden by $uri";
if ($dry) {
echo " - skipping\n";
echo "Found $count...\n";
while ($group->fetch()) {
- $uri = $group->uri;
+ $uri = $group->getUri();
if (preg_match('!/group/(\d+)/id!', $uri, $matches)) {
$id = intval($matches[1]);
$local = Local_group::getKV('group_id', $id);
echo "Found $count...\n";
while ($oprofile->fetch()) {
- $uri = $oprofile->uri;
- if (preg_match('!/group/(\d+)/id!', $oprofile->uri, $matches)) {
+ $uri = $oprofile->getUri();
+ if (preg_match('!/group/(\d+)/id!', $oprofile->getUri(), $matches)) {
$id = intval($matches[1]);
$group = Local_group::getKV('group_id', $id);
if ($group) {
$element = $this->_entryToElement($entry, false);
- $this->assertEquals($notice->uri, ActivityUtils::childContent($element, 'id'));
+ $this->assertEquals($notice->getUri(), ActivityUtils::childContent($element, 'id'));
$this->assertEquals($notice->content, ActivityUtils::childContent($element, 'title'));
$this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content'));
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published')));
$author = ActivityUtils::child($element, 'author');
- $this->assertEquals($this->author1->nickname, ActivityUtils::childContent($author, 'name'));
- $this->assertEquals($this->author1->uri, ActivityUtils::childContent($author, 'uri'));
+ $this->assertEquals($this->author1->getNickname(), ActivityUtils::childContent($author, 'name'));
+ $this->assertEquals($this->author1->getUri(), ActivityUtils::childContent($author, 'uri'));
}
/**
$irt = ActivityUtils::child($element, 'in-reply-to', 'http://purl.org/syndication/thread/1.0');
$this->assertNotNull($irt);
- $this->assertEquals($orig->uri, $irt->getAttribute('ref'));
- $this->assertEquals($orig->bestUrl(), $irt->getAttribute('href'));
+ $this->assertEquals($orig->getUri(), $irt->getAttribute('ref'));
+ $this->assertEquals($orig->getUrl(), $irt->getAttribute('href'));
}
public function testReplyAttention()
$element = $this->_entryToElement($entry, true);
- $this->assertEquals($this->targetUser1->uri, ActivityUtils::getLink($element, 'mentioned'));
+ $this->assertEquals($this->targetUser1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
}
public function testMultipleReplyAttention()
$hrefs[] = $link->getAttribute('href');
}
- $this->assertTrue(in_array($this->targetUser1->uri, $hrefs));
- $this->assertTrue(in_array($this->targetUser2->uri, $hrefs));
+ $this->assertTrue(in_array($this->targetUser1->getUri(), $hrefs));
+ $this->assertTrue(in_array($this->targetUser2->getUri(), $hrefs));
$links = ActivityUtils::getLinks($element, 'mentioned');
$hrefs[] = $link->getAttribute('href');
}
- $this->assertTrue(in_array($this->targetUser1->uri, $hrefs));
- $this->assertTrue(in_array($this->targetUser2->uri, $hrefs));
+ $this->assertTrue(in_array($this->targetUser1->getUri(), $hrefs));
+ $this->assertTrue(in_array($this->targetUser2->getUri(), $hrefs));
}
public function testGroupPostAttention()
$element = $this->_entryToElement($entry, true);
- $this->assertEquals($this->targetGroup1->uri, ActivityUtils::getLink($element, 'mentioned'));
+ $this->assertEquals($this->targetGroup1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
}
public function testMultipleGroupPostAttention()
$hrefs[] = $link->getAttribute('href');
}
- $this->assertTrue(in_array($this->targetGroup1->uri, $hrefs));
- $this->assertTrue(in_array($this->targetGroup2->uri, $hrefs));
+ $this->assertTrue(in_array($this->targetGroup1->getUri(), $hrefs));
+ $this->assertTrue(in_array($this->targetGroup2->getUri(), $hrefs));
$links = ActivityUtils::getLinks($element, 'mentioned');
$hrefs[] = $link->getAttribute('href');
}
- $this->assertTrue(in_array($this->targetGroup1->uri, $hrefs));
- $this->assertTrue(in_array($this->targetGroup2->uri, $hrefs));
+ $this->assertTrue(in_array($this->targetGroup1->getUri(), $hrefs));
+ $this->assertTrue(in_array($this->targetGroup2->getUri(), $hrefs));
}
public function testRepeatLink()
$forward = ActivityUtils::child($element, 'forward', "http://ostatus.org/schema/1.0");
$this->assertNotNull($forward);
- $this->assertEquals($notice->uri, $forward->getAttribute('ref'));
+ $this->assertEquals($notice->getUri(), $forward->getAttribute('ref'));
$this->assertEquals($notice->bestUrl(), $forward->getAttribute('href'));
}