summaryrefslogtreecommitdiff
path: root/plugins/OStatus/actions
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-03-04 06:07:28 -0800
committerBrion Vibber <brion@pobox.com>2010-03-04 06:07:28 -0800
commitb218aee94e581230e1efa14d4ae1a19756986ddf (patch)
treea832ddf3b4322b520fd20c4d8ea2d31720c3679b /plugins/OStatus/actions
parent358556057a87c0cb9291223a2026782e6548ff2e (diff)
parent14d7f4a598d0e24467fe3eafd9a02b0e651edad8 (diff)
Merge commit 'origin/testing' into 0.9.x
Conflicts: lib/action.php lib/adminpanelaction.php
Diffstat (limited to 'plugins/OStatus/actions')
-rw-r--r--plugins/OStatus/actions/hostmeta.php2
-rw-r--r--plugins/OStatus/actions/ostatusgroup.php181
-rw-r--r--plugins/OStatus/actions/ostatusinit.php51
-rw-r--r--plugins/OStatus/actions/ostatussub.php167
-rw-r--r--plugins/OStatus/actions/ownerxrd.php56
-rw-r--r--plugins/OStatus/actions/userxrd.php48
-rw-r--r--plugins/OStatus/actions/xrd.php113
7 files changed, 384 insertions, 234 deletions
diff --git a/plugins/OStatus/actions/hostmeta.php b/plugins/OStatus/actions/hostmeta.php
index 3d00b98ae..6d35ada6c 100644
--- a/plugins/OStatus/actions/hostmeta.php
+++ b/plugins/OStatus/actions/hostmeta.php
@@ -32,7 +32,7 @@ class HostMetaAction extends Action
parent::handle();
$domain = common_config('site', 'server');
- $url = common_local_url('xrd');
+ $url = common_local_url('userxrd');
$url.= '?uri={uri}';
$xrd = new XRD();
diff --git a/plugins/OStatus/actions/ostatusgroup.php b/plugins/OStatus/actions/ostatusgroup.php
new file mode 100644
index 000000000..f325ba053
--- /dev/null
+++ b/plugins/OStatus/actions/ostatusgroup.php
@@ -0,0 +1,181 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2009-2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @maintainer Brion Vibber <brion@status.net>
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+/**
+ * Key UI methods:
+ *
+ * showInputForm() - form asking for a remote profile account or URL
+ * We end up back here on errors
+ *
+ * showPreviewForm() - surrounding form for preview-and-confirm
+ * preview() - display profile for a remote group
+ *
+ * success() - redirects to groups page on join
+ */
+class OStatusGroupAction extends OStatusSubAction
+{
+ protected $profile_uri; // provided acct: or URI of remote entity
+ protected $oprofile; // Ostatus_profile of remote entity, if valid
+
+
+ function validateRemoteProfile()
+ {
+ if (!$this->oprofile->isGroup()) {
+ // Send us to the user subscription form for conf
+ $target = common_local_url('ostatussub', array(), array('profile' => $this->profile_uri));
+ common_redirect($target, 303);
+ }
+ }
+
+ /**
+ * Show the initial form, when we haven't yet been given a valid
+ * remote profile.
+ */
+ function showInputForm()
+ {
+ $user = common_current_user();
+
+ $profile = $user->getProfile();
+
+ $this->elementStart('form', array('method' => 'post',
+ 'id' => 'form_ostatus_sub',
+ 'class' => 'form_settings',
+ 'action' => $this->selfLink()));
+
+ $this->hidden('token', common_session_token());
+
+ $this->elementStart('fieldset', array('id' => 'settings_feeds'));
+
+ $this->elementStart('ul', 'form_data');
+ $this->elementStart('li');
+ $this->input('profile',
+ _m('Join group'),
+ $this->profile_uri,
+ _m("OStatus group's address, like http://example.net/group/nickname"));
+ $this->elementEnd('li');
+ $this->elementEnd('ul');
+
+ $this->submit('validate', _m('Continue'));
+
+ $this->elementEnd('fieldset');
+
+ $this->elementEnd('form');
+ }
+
+ /**
+ * Show a preview for a remote group's profile
+ * @return boolean true if we're ok to try joining
+ */
+ function preview()
+ {
+ $oprofile = $this->oprofile;
+ $group = $oprofile->localGroup();
+
+ $cur = common_current_user();
+ if ($cur->isMember($group)) {
+ $this->element('div', array('class' => 'error'),
+ _m("You are already a member of this group."));
+ $ok = false;
+ } else {
+ $ok = true;
+ }
+
+ $this->showEntity($group,
+ $group->getProfileUrl(),
+ $group->homepage_logo,
+ $group->description);
+ return $ok;
+ }
+
+ /**
+ * Redirect on successful remote group join
+ */
+ function success()
+ {
+ $cur = common_current_user();
+ $url = common_local_url('usergroups', array('nickname' => $cur->nickname));
+ common_redirect($url, 303);
+ }
+
+ /**
+ * Attempt to finalize subscription.
+ * validateFeed must have been run first.
+ *
+ * Calls showForm on failure or success on success.
+ */
+ function saveFeed()
+ {
+ $user = common_current_user();
+ $group = $this->oprofile->localGroup();
+ if ($user->isMember($group)) {
+ // TRANS: OStatus remote group subscription dialog error.
+ $this->showForm(_m('Already a member!'));
+ return;
+ }
+
+ if (Event::handle('StartJoinGroup', array($group, $user))) {
+ $ok = Group_member::join($this->oprofile->group_id, $user->id);
+ if ($ok) {
+ Event::handle('EndJoinGroup', array($group, $user));
+ $this->success();
+ } else {
+ // TRANS: OStatus remote group subscription dialog error.
+ $this->showForm(_m('Remote group join failed!'));
+ }
+ } else {
+ // TRANS: OStatus remote group subscription dialog error.
+ $this->showForm(_m('Remote group join aborted!'));
+ }
+ }
+
+ /**
+ * Title of the page
+ *
+ * @return string Title of the page
+ */
+
+ function title()
+ {
+ // TRANS: Page title for OStatus remote group join form
+ return _m('Confirm joining remote group');
+ }
+
+ /**
+ * Instructions for use
+ *
+ * @return instructions for use
+ */
+
+ function getInstructions()
+ {
+ return _m('You can subscribe to groups from other supported sites. Paste the group\'s profile URI below:');
+ }
+
+ function selfLink()
+ {
+ return common_local_url('ostatusgroup');
+ }
+}
diff --git a/plugins/OStatus/actions/ostatusinit.php b/plugins/OStatus/actions/ostatusinit.php
index 8ba8dcdcc..1e45025b0 100644
--- a/plugins/OStatus/actions/ostatusinit.php
+++ b/plugins/OStatus/actions/ostatusinit.php
@@ -29,6 +29,7 @@ class OStatusInitAction extends Action
{
var $nickname;
+ var $group;
var $profile;
var $err;
@@ -41,8 +42,9 @@ class OStatusInitAction extends Action
return false;
}
- // Local user the remote wants to subscribe to
+ // Local user or group the remote wants to subscribe to
$this->nickname = $this->trimmed('nickname');
+ $this->group = $this->trimmed('group');
// Webfinger or profile URL of the remote user
$this->profile = $this->trimmed('profile');
@@ -89,25 +91,33 @@ class OStatusInitAction extends Action
function showContent()
{
+ if ($this->group) {
+ $header = sprintf(_m('Join group %s'), $this->group);
+ $submit = _m('Join');
+ } else {
+ $header = sprintf(_m('Subscribe to %s'), $this->nickname);
+ $submit = _m('Subscribe');
+ }
$this->elementStart('form', array('id' => 'form_ostatus_connect',
'method' => 'post',
'class' => 'form_settings',
'action' => common_local_url('ostatusinit')));
$this->elementStart('fieldset');
- $this->element('legend', null, sprintf(_m('Subscribe to %s'), $this->nickname));
+ $this->element('legend', null, $header);
$this->hidden('token', common_session_token());
$this->elementStart('ul', 'form_data');
$this->elementStart('li', array('id' => 'ostatus_nickname'));
$this->input('nickname', _m('User nickname'), $this->nickname,
_m('Nickname of the user you want to follow'));
+ $this->hidden('group', $this->group); // pass-through for magic links
$this->elementEnd('li');
$this->elementStart('li', array('id' => 'ostatus_profile'));
$this->input('profile', _m('Profile Account'), $this->profile,
_m('Your account id (i.e. user@identi.ca)'));
$this->elementEnd('li');
$this->elementEnd('ul');
- $this->submit('submit', _m('Subscribe'));
+ $this->submit('submit', $submit);
$this->elementEnd('fieldset');
$this->elementEnd('form');
}
@@ -131,19 +141,17 @@ class OStatusInitAction extends Action
function connectWebfinger($acct)
{
- $disco = new Discovery;
+ $target_profile = $this->targetProfile();
+ $disco = new Discovery;
$result = $disco->lookup($acct);
if (!$result) {
$this->clientError(_m("Couldn't look up OStatus account profile."));
}
+
foreach ($result->links as $link) {
if ($link['rel'] == 'http://ostatus.org/schema/1.0/subscribe') {
// We found a URL - let's redirect!
-
- $user = User::staticGet('nickname', $this->nickname);
- $target_profile = common_local_url('userbyid', array('id' => $user->id));
-
$url = Discovery::applyTemplate($link['template'], $target_profile);
common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
common_redirect($url, 303);
@@ -155,8 +163,7 @@ class OStatusInitAction extends Action
function connectProfile($subscriber_profile)
{
- $user = User::staticGet('nickname', $this->nickname);
- $target_profile = common_local_url('userbyid', array('id' => $user->id));
+ $target_profile = $this->targetProfile();
// @fixme hack hack! We should look up the remote sub URL from XRDS
$suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/ostatussub', $subscriber_profile);
@@ -166,6 +173,30 @@ class OStatusInitAction extends Action
common_redirect($suburl, 303);
}
+ /**
+ * Build the canonical profile URI+URL of the requested user or group
+ */
+ function targetProfile()
+ {
+ if ($this->nickname) {
+ $user = User::staticGet('nickname', $this->nickname);
+ if ($user) {
+ return common_local_url('userbyid', array('id' => $user->id));
+ } else {
+ $this->clientError("No such user.");
+ }
+ } else if ($this->group) {
+ $group = Local_group::staticGet('id', $this->group);
+ if ($group) {
+ return common_local_url('groupbyid', array('id' => $group->group_id));
+ } else {
+ $this->clientError("No such group.");
+ }
+ } else {
+ $this->clientError("No local user or group nickname provided.");
+ }
+ }
+
function title()
{
return _m('OStatus Connect');
diff --git a/plugins/OStatus/actions/ostatussub.php b/plugins/OStatus/actions/ostatussub.php
index e318701a2..65dee2392 100644
--- a/plugins/OStatus/actions/ostatussub.php
+++ b/plugins/OStatus/actions/ostatussub.php
@@ -1,7 +1,7 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2009, StatusNet, Inc.
+ * Copyright (C) 2009-2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -31,11 +31,9 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
* We end up back here on errors
*
* showPreviewForm() - surrounding form for preview-and-confirm
- * previewUser() - display profile for a remote user
- * previewGroup() - display profile for a remote group
+ * preview() - display profile for a remote user
*
- * successUser() - redirects to subscriptions page on subscribe
- * successGroup() - redirects to groups page on join
+ * success() - redirects to subscriptions page on subscribe
*/
class OStatusSubAction extends Action
{
@@ -55,8 +53,7 @@ class OStatusSubAction extends Action
$this->elementStart('form', array('method' => 'post',
'id' => 'form_ostatus_sub',
'class' => 'form_settings',
- 'action' =>
- common_local_url('ostatussub')));
+ 'action' => $this->selfLink()));
$this->hidden('token', common_session_token());
@@ -65,9 +62,9 @@ class OStatusSubAction extends Action
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->input('profile',
- _m('Address or profile URL'),
+ _m('Subscribe to'),
$this->profile_uri,
- _m('Enter the profile URL of a PubSubHubbub-enabled feed'));
+ _m("OStatus user's address, like nickname@example.com or http://example.net/nickname"));
$this->elementEnd('li');
$this->elementEnd('ul');
@@ -87,11 +84,7 @@ class OStatusSubAction extends Action
*/
function showPreviewForm()
{
- if ($this->oprofile->isGroup()) {
- $ok = $this->previewGroup();
- } else {
- $ok = $this->previewUser();
- }
+ $ok = $this->preview();
if (!$ok) {
// @fixme maybe provide a cancel button or link back?
return;
@@ -104,7 +97,7 @@ class OStatusSubAction extends Action
'id' => 'form_ostatus_sub',
'class' => 'form_remote_authorize',
'action' =>
- common_local_url('ostatussub')));
+ $this->selfLink()));
$this->elementStart('fieldset');
$this->hidden('token', common_session_token());
$this->hidden('profile', $this->profile_uri);
@@ -126,7 +119,7 @@ class OStatusSubAction extends Action
* Show a preview for a remote user's profile
* @return boolean true if we're ok to try subscribing
*/
- function previewUser()
+ function preview()
{
$oprofile = $this->oprofile;
$profile = $oprofile->localProfile();
@@ -150,32 +143,6 @@ class OStatusSubAction extends Action
return $ok;
}
- /**
- * Show a preview for a remote group's profile
- * @return boolean true if we're ok to try joining
- */
- function previewGroup()
- {
- $oprofile = $this->oprofile;
- $group = $oprofile->localGroup();
-
- $cur = common_current_user();
- if ($cur->isMember($group)) {
- $this->element('div', array('class' => 'error'),
- _m("You are already a member of this group."));
- $ok = false;
- } else {
- $ok = true;
- }
-
- $this->showEntity($group,
- $group->getProfileUrl(),
- $group->homepage_logo,
- $group->description);
- return $ok;
- }
-
-
function showEntity($entity, $profile, $avatar, $note)
{
$nickname = $entity->nickname;
@@ -254,7 +221,7 @@ class OStatusSubAction extends Action
/**
* Redirect on successful remote user subscription
*/
- function successUser()
+ function success()
{
$cur = common_current_user();
$url = common_local_url('subscriptions', array('nickname' => $cur->nickname));
@@ -262,104 +229,81 @@ class OStatusSubAction extends Action
}
/**
- * Redirect on successful remote group join
- */
- function successGroup()
- {
- $cur = common_current_user();
- $url = common_local_url('usergroups', array('nickname' => $cur->nickname));
- common_redirect($url, 303);
- }
-
- /**
* Pull data for a remote profile and check if it's valid.
* Fills out error UI string in $this->error
* Fills out $this->oprofile on success.
*
* @return boolean
*/
- function validateFeed()
+ function pullRemoteProfile()
{
- $profile_uri = trim($this->arg('profile'));
-
- if ($profile_uri == '') {
- $this->showForm(_m('Empty remote profile URL!'));
- return;
- }
- $this->profile_uri = $profile_uri;
-
+ $this->profile_uri = $this->trimmed('profile');
try {
if (Validate::email($this->profile_uri)) {
$this->oprofile = Ostatus_profile::ensureWebfinger($this->profile_uri);
} else if (Validate::uri($this->profile_uri)) {
$this->oprofile = Ostatus_profile::ensureProfile($this->profile_uri);
} else {
- $this->error = _m("Invalid address format.");
+ $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ common_debug('Invalid address format.', __FILE__);
return false;
}
return true;
} catch (FeedSubBadURLException $e) {
- $this->error = _m('Invalid URL or could not reach server.');
+ $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ common_debug('Invalid URL or could not reach server.', __FILE__);
} catch (FeedSubBadResponseException $e) {
- $this->error = _m('Cannot read feed; server returned error.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Cannot read feed; server returned error.', __FILE__);
} catch (FeedSubEmptyException $e) {
- $this->error = _m('Cannot read feed; server returned an empty page.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Cannot read feed; server returned an empty page.', __FILE__);
} catch (FeedSubBadHTMLException $e) {
- $this->error = _m('Bad HTML, could not find feed link.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Bad HTML, could not find feed link.', __FILE__);
} catch (FeedSubNoFeedException $e) {
- $this->error = _m('Could not find a feed linked from this URL.');
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Could not find a feed linked from this URL.', __FILE__);
} catch (FeedSubUnrecognizedTypeException $e) {
- $this->error = _m('Not a recognized feed type.');
- } catch (FeedSubException $e) {
+ $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
+ common_debug('Not a recognized feed type.', __FILE__);
+ } catch (Exception $e) {
// Any new ones we forgot about
- $this->error = sprintf(_m('Bad feed URL: %s %s'), get_class($e), $e->getMessage());
+ $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname");
+ common_debug(sprintf('Bad feed URL: %s %s', get_class($e), $e->getMessage()), __FILE__);
}
return false;
}
+ function validateRemoteProfile()
+ {
+ if ($this->oprofile->isGroup()) {
+ // Send us to the group subscription form for conf
+ $target = common_local_url('ostatusgroup', array(), array('profile' => $this->profile_uri));
+ common_redirect($target, 303);
+ }
+ }
+
/**
* Attempt to finalize subscription.
* validateFeed must have been run first.
*
- * Calls showForm on failure or successUser/successGroup on success.
+ * Calls showForm on failure or success on success.
*/
function saveFeed()
{
// And subscribe the current user to the local profile
$user = common_current_user();
-
- if ($this->oprofile->isGroup()) {
- $group = $this->oprofile->localGroup();
- if ($user->isMember($group)) {
- // TRANS: OStatus remote group subscription dialog error.
- $this->showForm(_m('Already a member!'));
- return;
- }
- if (Event::handle('StartJoinGroup', array($group, $user))) {
- $ok = Group_member::join($this->oprofile->group_id, $user->id);
- if ($ok) {
- Event::handle('EndJoinGroup', array($group, $user));
- $this->successGroup();
- } else {
- // TRANS: OStatus remote group subscription dialog error.
- $this->showForm(_m('Remote group join failed!'));
- }
- } else {
- // TRANS: OStatus remote group subscription dialog error.
- $this->showForm(_m('Remote group join aborted!'));
- }
+ $local = $this->oprofile->localProfile();
+ if ($user->isSubscribed($local)) {
+ // TRANS: OStatus remote subscription dialog error.
+ $this->showForm(_m('Already subscribed!'));
+ } elseif ($this->oprofile->subscribeLocalToRemote($user)) {
+ $this->success();
} else {
- $local = $this->oprofile->localProfile();
- if ($user->isSubscribed($local)) {
- // TRANS: OStatus remote subscription dialog error.
- $this->showForm(_m('Already subscribed!'));
- } elseif ($this->oprofile->subscribeLocalToRemote($user)) {
- $this->successUser();
- } else {
- // TRANS: OStatus remote subscription dialog error.
- $this->showForm(_m('Remote subscription failed!'));
- }
+ // TRANS: OStatus remote subscription dialog error.
+ $this->showForm(_m('Remote subscription failed!'));
}
}
@@ -376,8 +320,9 @@ class OStatusSubAction extends Action
return false;
}
- $this->profile_uri = $this->arg('profile');
-
+ if ($this->pullRemoteProfile()) {
+ $this->validateRemoteProfile();
+ }
return true;
}
@@ -390,9 +335,6 @@ class OStatusSubAction extends Action
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost();
} else {
- if ($this->arg('profile')) {
- $this->validateFeed();
- }
$this->showForm();
}
}
@@ -414,7 +356,7 @@ class OStatusSubAction extends Action
return;
}
- if ($this->validateFeed()) {
+ if ($this->oprofile) {
if ($this->arg('submit')) {
$this->saveFeed();
return;
@@ -456,7 +398,7 @@ class OStatusSubAction extends Action
function title()
{
// TRANS: Page title for OStatus remote subscription form
- return _m('Authorize subscription');
+ return _m('Confirm');
}
/**
@@ -500,4 +442,9 @@ class OStatusSubAction extends Action
parent::showScripts();
$this->autofocus('feedurl');
}
+
+ function selfLink()
+ {
+ return common_local_url('ostatussub');
+ }
}
diff --git a/plugins/OStatus/actions/ownerxrd.php b/plugins/OStatus/actions/ownerxrd.php
new file mode 100644
index 000000000..9c141d8c7
--- /dev/null
+++ b/plugins/OStatus/actions/ownerxrd.php
@@ -0,0 +1,56 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @maintainer James Walker <james@status.net>
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+class OwnerxrdAction extends XrdAction
+{
+
+ public $uri;
+
+ function prepare($args)
+ {
+ $this->user = User::siteOwner();
+
+ if (!$this->user) {
+ $this->clientError(_('No such user.'), 404);
+ return false;
+ }
+
+ $nick = common_canonical_nickname($this->user->nickname);
+ $acct = 'acct:' . $nick . '@' . common_config('site', 'server');
+
+ $this->xrd = new XRD();
+
+ // Check to see if a $config['webfinger']['owner'] has been set
+ if ($owner = common_config('webfinger', 'owner')) {
+ $this->xrd->subject = Discovery::normalize($owner);
+ $this->xrd->alias[] = $acct;
+ } else {
+ $this->xrd->subject = $acct;
+ }
+
+ return true;
+ }
+}
diff --git a/plugins/OStatus/actions/userxrd.php b/plugins/OStatus/actions/userxrd.php
new file mode 100644
index 000000000..414de9364
--- /dev/null
+++ b/plugins/OStatus/actions/userxrd.php
@@ -0,0 +1,48 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @maintainer James Walker <james@status.net>
+ */
+
+if (!defined('STATUSNET')) { exit(1); }
+
+class UserxrdAction extends XrdAction
+{
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $this->uri = $this->trimmed('uri');
+ $acct = Discovery::normalize($this->uri);
+
+ list($nick, $domain) = explode('@', substr(urldecode($acct), 5));
+ $nick = common_canonical_nickname($nick);
+
+ $this->user = User::staticGet('nickname', $nick);
+ if (!$this->user) {
+ $this->clientError(_('No such user.'), 404);
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/plugins/OStatus/actions/xrd.php b/plugins/OStatus/actions/xrd.php
deleted file mode 100644
index f574b60ee..000000000
--- a/plugins/OStatus/actions/xrd.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-/*
- * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2010, StatusNet, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * @package OStatusPlugin
- * @maintainer James Walker <james@status.net>
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-class XrdAction extends Action
-{
-
- public $uri;
-
- function prepare($args)
- {
- parent::prepare($args);
-
- $this->uri = $this->trimmed('uri');
-
- return true;
- }
-
- function handle()
- {
- $acct = Discovery::normalize($this->uri);
-
- $xrd = new XRD();
-
- list($nick, $domain) = explode('@', substr(urldecode($acct), 5));
- $nick = common_canonical_nickname($nick);
-
- $this->user = User::staticGet('nickname', $nick);
- if (!$this->user) {
- $this->clientError(_('No such user.'), 404);
- return false;
- }
-
- $xrd->subject = $this->uri;
- $xrd->alias[] = common_profile_url($nick);
- $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
- 'type' => 'text/html',
- 'href' => common_profile_url($nick));
-
- $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
- 'href' => common_local_url('ApiTimelineUser',
- array('id' => $this->user->id,
- 'format' => 'atom')),
- 'type' => 'application/atom+xml');
-
- // hCard
- $xrd->links[] = array('rel' => Discovery::HCARD,
- 'type' => 'text/html',
- 'href' => common_local_url('hcard', array('nickname' => $nick)));
-
- // XFN
- $xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
- 'type' => 'text/html',
- 'href' => common_profile_url($nick));
- // FOAF
- $xrd->links[] = array('rel' => 'describedby',
- 'type' => 'application/rdf+xml',
- 'href' => common_local_url('foaf',
- array('nickname' => $nick)));
-
- // Salmon
- $salmon_url = common_local_url('usersalmon',
- array('id' => $this->user->id));
-
- $xrd->links[] = array('rel' => Salmon::NS_REPLIES,
- 'href' => $salmon_url);
-
- $xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
- 'href' => $salmon_url);
-
- // Get this user's keypair
- $magickey = Magicsig::staticGet('user_id', $this->user->id);
- if (!$magickey) {
- // No keypair yet, let's generate one.
- $magickey = new Magicsig();
- $magickey->generate($this->user->id);
- }
-
- $xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
- 'href' => 'data:application/magic-public-key;'. $magickey->toString(false));
-
- // TODO - finalize where the redirect should go on the publisher
- $url = common_local_url('ostatussub') . '?profile={uri}';
- $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
- 'template' => $url );
-
- header('Content-type: text/xml');
- print $xrd->toXML();
- }
-
-}