<?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
* @maintainer Brion Vibber <brion@status.net>
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
/**
* Key UI methods:
* 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
{
protected $profile_uri; // provided acct: or URI of remote entity
protected $oprofile; // Ostatus_profile of remote entity, if valid
+ protected function prepare(array $args=array())
+ {
+ parent::prepare($args);
+
+ if (!common_logged_in()) {
+ // XXX: selfURL() didn't work. :<
+ common_set_returnto($_SERVER['REQUEST_URI']);
+ if (Event::handle('RedirectToLogin', array($this, null))) {
+ common_redirect(common_local_url('login'), 303);
+ }
+ return false;
+ }
+
+ if ($this->pullRemoteProfile()) {
+ $this->validateRemoteProfile();
+ }
+ return true;
+ }
+
+ /**
+ * Handle the submission.
+ */
+ protected function handle()
+ {
+ parent::handle();
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->handlePost();
+ } else {
+ $this->showForm();
+ }
+ }
+
/**
* 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' =>
- common_local_url('ostatussub')));
+ 'action' => $this->selfLink()));
$this->hidden('token', common_session_token());
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->input('profile',
- _m('Address or profile URL'),
+ // TRANS: Field label for a field that takes an OStatus user address.
+ _m('Subscribe to'),
$this->profile_uri,
- _m('Enter the profile URL of a PubSubHubbub-enabled feed'));
+ // TRANS: Tooltip for field label "Subscribe to".
+ _m('OStatus user\'s address, like nickname@example.com or http://example.net/nickname.'));
$this->elementEnd('li');
$this->elementEnd('ul');
-
- $this->submit('validate', _m('Continue'));
+ // TRANS: Button text.
+ $this->submit('validate', _m('BUTTON','Continue'));
$this->elementEnd('fieldset');
*/
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?
+ // @todo FIXME maybe provide a cancel button or link back?
return;
}
'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);
if ($this->oprofile->isGroup()) {
+ // TRANS: Button text.
$this->submit('submit', _m('Join'), 'submit', null,
- _m('Join this group'));
+ // TRANS: Tooltip for button "Join".
+ _m('BUTTON','Join this group'));
} else {
- $this->submit('submit', _m('Subscribe'), 'submit', null,
+ // TRANS: Button text.
+ $this->submit('submit', _m('BUTTON','Confirm'), 'submit', null,
+ // TRANS: Tooltip for button "Confirm".
_m('Subscribe to this user'));
}
$this->elementEnd('fieldset');
* 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();
+ // Throws NoProfileException on localProfile when remote user's Profile not found
+ $profile = $this->oprofile->localProfile();
- $cur = common_current_user();
- if ($cur->isSubscribed($profile)) {
+ if ($this->scoped->isSubscribed($profile)) {
$this->element('div', array('class' => 'error'),
- _m("You are already subscribed to this user."));
+ // TRANS: Extra paragraph in remote profile view when already subscribed.
+ _m('You are already subscribed to this user.'));
$ok = false;
} else {
$ok = true;
}
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- $avatarUrl = $avatar ? $avatar->displayUrl() : false;
+ $avatarUrl = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
$this->showEntity($profile,
$profile->profileurl,
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;
$fullname = $entity->fullname;
$homepage = $entity->homepage;
$location = $entity->location;
-
- if (!$avatar) {
- $avatar = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
- }
$this->elementStart('div', 'entity_profile vcard');
- $this->elementStart('dl', 'entity_depiction');
- $this->element('dt', null, _('Photo'));
- $this->elementStart('dd');
$this->element('img', array('src' => $avatar,
- 'class' => 'photo avatar',
+ 'class' => 'photo avatar entity_depiction',
'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE,
'alt' => $nickname));
- $this->elementEnd('dd');
- $this->elementEnd('dl');
- $this->elementStart('dl', 'entity_nickname');
- $this->element('dt', null, _('Nickname'));
- $this->elementStart('dd');
- $hasFN = ($fullname !== '') ? 'nickname' : 'fn nickname';
+ $hasFN = ($fullname !== '') ? 'nickname' : 'fn nickname entity_nickname';
$this->elementStart('a', array('href' => $profile,
'class' => 'url '.$hasFN));
$this->raw($nickname);
$this->elementEnd('a');
- $this->elementEnd('dd');
- $this->elementEnd('dl');
if (!is_null($fullname)) {
- $this->elementStart('dl', 'entity_fn');
- $this->elementStart('dd');
- $this->elementStart('span', 'fn');
+ $this->elementStart('div', 'fn entity_fn');
$this->raw($fullname);
- $this->elementEnd('span');
- $this->elementEnd('dd');
- $this->elementEnd('dl');
+ $this->elementEnd('div');
}
+
if (!is_null($location)) {
- $this->elementStart('dl', 'entity_location');
- $this->element('dt', null, _('Location'));
- $this->elementStart('dd', 'label');
+ $this->elementStart('div', 'label entity_location');
$this->raw($location);
- $this->elementEnd('dd');
- $this->elementEnd('dl');
+ $this->elementEnd('div');
}
if (!is_null($homepage)) {
- $this->elementStart('dl', 'entity_url');
- $this->element('dt', null, _('URL'));
- $this->elementStart('dd');
$this->elementStart('a', array('href' => $homepage,
- 'class' => 'url'));
+ 'class' => 'url entity_url'));
$this->raw($homepage);
$this->elementEnd('a');
- $this->elementEnd('dd');
- $this->elementEnd('dl');
}
if (!is_null($note)) {
- $this->elementStart('dl', 'entity_note');
- $this->element('dt', null, _('Note'));
- $this->elementStart('dd', 'note');
+ $this->elementStart('div', 'note entity_note');
$this->raw($note);
- $this->elementEnd('dd');
- $this->elementEnd('dl');
+ $this->elementEnd('div');
}
$this->elementEnd('div');
}
/**
* Redirect on successful remote user subscription
*/
- function successUser()
- {
- $cur = common_current_user();
- $url = common_local_url('subscriptions', array('nickname' => $cur->nickname));
- common_redirect($url, 303);
- }
-
- /**
- * Redirect on successful remote group join
- */
- function successGroup()
+ function success()
{
- $cur = common_current_user();
- $url = common_local_url('usergroups', array('nickname' => $cur->nickname));
+ $url = common_local_url('subscriptions', array('nickname' => $this->scoped->nickname));
common_redirect($url, 303);
}
*
* @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;
-
- // @fixme validate, normalize bla bla
+ $this->profile_uri = $this->trimmed('profile');
try {
- $oprofile = Ostatus_profile::ensureProfile($this->profile_uri);
- $this->oprofile = $oprofile;
+ 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::ensureProfileURL($this->profile_uri);
+ } else {
+ // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
+ // TRANS: and example.net, as these are official standard domain names for use in examples.
+ $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.');
+ // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
+ // TRANS: and example.net, as these are official standard domain names for use in examples.
+ $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.');
+ // TRANS: Error text.
+ $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.');
+ // TRANS: Error text.
+ $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.');
+ // TRANS: Error text.
+ $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.');
+ // TRANS: Error text.
+ $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) {
+ // TRANS: Error text.
+ $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());
+ // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
+ // TRANS: and example.net, as these are official standard domain names for use in examples.
+ $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;
}
- /**
- * Attempt to finalize subscription.
- * validateFeed must have been run first.
- *
- * Calls showForm on failure or successUser/successGroup on success.
- */
- function saveFeed()
+ function validateRemoteProfile()
{
- // And subscribe the current user to the local profile
- $user = common_current_user();
-
+ // Send us to the respective subscription form for conf
if ($this->oprofile->isGroup()) {
- $group = $this->oprofile->localGroup();
- if ($user->isMember($group)) {
- $this->showForm(_m('Already a member!'));
- } elseif (Group_member::join($this->oprofile->group_id, $user->id)) {
- $this->successGroup();
- } else {
- $this->showForm(_m('Remote group join failed!'));
- }
- } else {
- $local = $this->oprofile->localProfile();
- if ($user->isSubscribed($local)) {
- $this->showForm(_m('Already subscribed!'));
- } elseif ($this->oprofile->subscribeLocalToRemote($user)) {
- $this->successUser();
- } else {
- $this->showForm(_m('Remote subscription failed!'));
- }
- }
- }
-
- function prepare($args)
- {
- parent::prepare($args);
-
- if (!common_logged_in()) {
- // XXX: selfURL() didn't work. :<
- common_set_returnto($_SERVER['REQUEST_URI']);
- if (Event::handle('RedirectToLogin', array($this, null))) {
- common_redirect(common_local_url('login'), 303);
- }
- return false;
+ $target = common_local_url('ostatusgroup', array(), array('profile' => $this->profile_uri));
+ common_redirect($target, 303);
+ } else if ($this->oprofile->isPeopletag()) {
+ $target = common_local_url('ostatuspeopletag', array(), array('profile' => $this->profile_uri));
+ common_redirect($target, 303);
}
-
- $this->profile_uri = $this->arg('profile');
-
- return true;
}
/**
- * Handle the submission.
+ * Attempt to finalize subscription.
+ * validateFeed must have been run first.
+ *
+ * Calls showForm on failure or success on success.
*/
- function handle($args)
+ function saveFeed()
{
- parent::handle($args);
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->handlePost();
+ // And subscribe the current user to the local profile
+ $local = $this->oprofile->localProfile();
+ if ($this->scoped->isSubscribed($local)) {
+ // TRANS: OStatus remote subscription dialog error.
+ $this->showForm(_m('Already subscribed!'));
+ } elseif (Subscription::start($this->scoped, $local)) {
+ $this->success();
} else {
- if ($this->arg('profile')) {
- $this->validateFeed();
- }
- $this->showForm();
+ // TRANS: OStatus remote subscription dialog error.
+ $this->showForm(_m('Remote subscription failed!'));
}
}
-
/**
* Handle posts to this form
*
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
- $this->showForm(_('There was a problem with your session token. '.
+ // TRANS: Client error displayed when the session token does not match or is not given.
+ $this->showForm(_m('There was a problem with your session token. '.
'Try again, please.'));
return;
}
- if ($this->validateFeed()) {
+ if ($this->oprofile) {
if ($this->arg('submit')) {
$this->saveFeed();
return;
$this->error = $err;
}
if ($this->boolean('ajax')) {
- header('Content-Type: text/xml;charset=utf-8');
- $this->xw->startDocument('1.0', 'UTF-8');
- $this->elementStart('html');
+ $this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
+ // TRANS: Form title.
$this->element('title', null, _m('Subscribe to user'));
$this->elementEnd('head');
$this->elementStart('body');
$this->showContent();
$this->elementEnd('body');
- $this->elementEnd('html');
+ $this->endHTML();
} else {
$this->showPage();
}
function title()
{
- return _m('Authorize subscription');
+ // TRANS: Page title for OStatus remote subscription form.
+ return _m('Confirm');
}
/**
function getInstructions()
{
+ // TRANS: Instructions.
return _m('You can subscribe to users from other supported sites. Paste their address or profile URI below:');
}
*
* @return void
*/
-
function showContent()
{
if ($this->oprofile) {
parent::showScripts();
$this->autofocus('feedurl');
}
+
+ function selfLink()
+ {
+ return common_local_url('ostatussub');
+ }
+
+ /**
+ * Disable the send-notice form at the top of the page.
+ * This is really just a hack for the broken CSS in the Cloudy theme,
+ * I think; copying from other non-notice-navigation pages that do this
+ * as well. There will be plenty of others also broken.
+ *
+ * @fixme fix the cloudy theme
+ * @fixme do this in a more general way
+ */
+ function showNoticeForm() {
+ // nop
+ }
}