forked from GNUsocial/gnu-social
OStatus subscription page fixups; works but needs lots of UI loving!
- ostatussub via subscribe button now works again (changed to take profile instead of feed, patched up to the new discovery) - added a quickie hack to allow putting your remote profile URI in place of webfinger acct through the remote-sub button (needs to be patched up to do proper discovery via XRDS or a link or something)
This commit is contained in:
parent
f891b135fb
commit
ea9d6f21ec
@ -37,7 +37,7 @@ class OStatusInitAction extends Action
|
|||||||
parent::prepare($args);
|
parent::prepare($args);
|
||||||
|
|
||||||
if (common_logged_in()) {
|
if (common_logged_in()) {
|
||||||
$this->clientError(_('You can use the local subscription!'));
|
$this->clientError(_m('You can use the local subscription!'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ class OStatusInitAction extends Action
|
|||||||
/* Use a session token for CSRF protection. */
|
/* Use a session token for CSRF protection. */
|
||||||
$token = $this->trimmed('token');
|
$token = $this->trimmed('token');
|
||||||
if (!$token || $token != common_session_token()) {
|
if (!$token || $token != common_session_token()) {
|
||||||
$this->showForm(_('There was a problem with your session token. '.
|
$this->showForm(_m('There was a problem with your session token. '.
|
||||||
'Try again, please.'));
|
'Try again, please.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ class OStatusInitAction extends Action
|
|||||||
$this->xw->startDocument('1.0', 'UTF-8');
|
$this->xw->startDocument('1.0', 'UTF-8');
|
||||||
$this->elementStart('html');
|
$this->elementStart('html');
|
||||||
$this->elementStart('head');
|
$this->elementStart('head');
|
||||||
$this->element('title', null, _('Subscribe to user'));
|
$this->element('title', null, _m('Subscribe to user'));
|
||||||
$this->elementEnd('head');
|
$this->elementEnd('head');
|
||||||
$this->elementStart('body');
|
$this->elementStart('body');
|
||||||
$this->showContent();
|
$this->showContent();
|
||||||
@ -91,50 +91,78 @@ class OStatusInitAction extends Action
|
|||||||
'class' => 'form_settings',
|
'class' => 'form_settings',
|
||||||
'action' => common_local_url('ostatusinit')));
|
'action' => common_local_url('ostatusinit')));
|
||||||
$this->elementStart('fieldset');
|
$this->elementStart('fieldset');
|
||||||
$this->element('legend', null, sprintf(_('Subscribe to %s'), $this->nickname));
|
$this->element('legend', null, sprintf(_m('Subscribe to %s'), $this->nickname));
|
||||||
$this->hidden('token', common_session_token());
|
$this->hidden('token', common_session_token());
|
||||||
|
|
||||||
$this->elementStart('ul', 'form_data');
|
$this->elementStart('ul', 'form_data');
|
||||||
$this->elementStart('li', array('id' => 'ostatus_nickname'));
|
$this->elementStart('li', array('id' => 'ostatus_nickname'));
|
||||||
$this->input('nickname', _('User nickname'), $this->nickname,
|
$this->input('nickname', _m('User nickname'), $this->nickname,
|
||||||
_('Nickname of the user you want to follow'));
|
_m('Nickname of the user you want to follow'));
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
$this->elementStart('li', array('id' => 'ostatus_profile'));
|
$this->elementStart('li', array('id' => 'ostatus_profile'));
|
||||||
$this->input('acct', _('Profile Account'), $this->acct,
|
$this->input('acct', _m('Profile Account'), $this->acct,
|
||||||
_('Your account id (i.e. user@identi.ca)'));
|
_m('Your account id (i.e. user@identi.ca)'));
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
$this->elementEnd('ul');
|
$this->elementEnd('ul');
|
||||||
$this->submit('submit', _('Subscribe'));
|
$this->submit('submit', _m('Subscribe'));
|
||||||
$this->elementEnd('fieldset');
|
$this->elementEnd('fieldset');
|
||||||
$this->elementEnd('form');
|
$this->elementEnd('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
function ostatusConnect()
|
function ostatusConnect()
|
||||||
{
|
{
|
||||||
$w = new Webfinger;
|
$opts = array('allowed_schemes' => array('http', 'https', 'acct'));
|
||||||
|
if (Validate::uri($this->acct, $opts)) {
|
||||||
$result = $w->lookup($this->acct);
|
$bits = parse_url($this->acct);
|
||||||
foreach ($result->links as $link) {
|
if ($bits['scheme'] == 'acct') {
|
||||||
if ($link['rel'] == 'http://ostatus.org/schema/1.0/subscribe') {
|
$this->connectWebfinger($bits['path']);
|
||||||
// We found a URL - let's redirect!
|
} else {
|
||||||
|
$this->connectProfile($this->acct);
|
||||||
$user = User::staticGet('nickname', $this->nickname);
|
}
|
||||||
|
} elseif (strpos('@', $this->acct) !== false) {
|
||||||
$feed_url = common_local_url('ApiTimelineUser',
|
$this->connectWebfinger($this->acct);
|
||||||
array('id' => $user->id,
|
}
|
||||||
'format' => 'atom'));
|
|
||||||
$url = $w->applyTemplate($link['template'], $feed_url);
|
|
||||||
|
|
||||||
common_redirect($url, 303);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function connectWebfinger($acct)
|
||||||
|
{
|
||||||
|
$w = new Webfinger;
|
||||||
|
|
||||||
|
$result = $w->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 = $w->applyTemplate($link['template'], $feed_url);
|
||||||
|
|
||||||
|
common_redirect($url, 303);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectProfile($subscriber_profile)
|
||||||
|
{
|
||||||
|
$user = User::staticGet('nickname', $this->nickname);
|
||||||
|
$target_profile = common_local_url('userbyid', array('id' => $user->id));
|
||||||
|
|
||||||
|
// @fixme hack hack! We should look up the remote sub URL from XRDS
|
||||||
|
$suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/ostatussub', $subscriber_profile);
|
||||||
|
$suburl .= '?profile=' . urlencode($target_profile);
|
||||||
|
|
||||||
|
common_redirect($suburl, 303);
|
||||||
|
}
|
||||||
|
|
||||||
function title()
|
function title()
|
||||||
{
|
{
|
||||||
return _('OStatus Connect');
|
return _m('OStatus Connect');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* StatusNet - the distributed open-source microblogging tool
|
* StatusNet - the distributed open-source microblogging tool
|
||||||
* Copyright (C) 2010, StatusNet, Inc.
|
* Copyright (C) 2009, StatusNet, Inc.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -19,57 +19,71 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @package OStatusPlugin
|
* @package OStatusPlugin
|
||||||
* @maintainer James Walker <james@status.net>
|
* @maintainer Brion Vibber <brion@status.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
||||||
|
|
||||||
class OStatusSubAction extends Action
|
class OStatusSubAction extends Action
|
||||||
{
|
{
|
||||||
|
protected $profile_uri;
|
||||||
|
protected $preview;
|
||||||
|
protected $munger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title of the page
|
||||||
|
*
|
||||||
|
* @return string Title of the page
|
||||||
|
*/
|
||||||
|
|
||||||
protected $feedurl;
|
|
||||||
|
|
||||||
function title()
|
function title()
|
||||||
{
|
{
|
||||||
return _m("OStatus Subscribe");
|
return _m('Authorize subscription');
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle($args)
|
/**
|
||||||
|
* Instructions for use
|
||||||
|
*
|
||||||
|
* @return instructions for use
|
||||||
|
*/
|
||||||
|
|
||||||
|
function getInstructions()
|
||||||
{
|
{
|
||||||
if ($this->validateFeed()) {
|
return _m('You can subscribe to users from other supported sites. Paste their address or profile URI below:');
|
||||||
$this->showForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showForm($err = null)
|
function showForm($error=null)
|
||||||
{
|
{
|
||||||
$this->err = $err;
|
$this->error = $error;
|
||||||
$this->showPage();
|
$this->showPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content area of the page
|
||||||
|
*
|
||||||
|
* Shows a form for associating a remote OStatus account with this
|
||||||
|
* StatusNet account.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
function showContent()
|
function showContent()
|
||||||
{
|
{
|
||||||
|
// @fixme is this right place?
|
||||||
|
if ($this->error) {
|
||||||
|
$this->text($this->error);
|
||||||
|
}
|
||||||
|
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
|
|
||||||
$profile = $user->getProfile();
|
$profile = $user->getProfile();
|
||||||
|
|
||||||
$fuser = null;
|
|
||||||
|
|
||||||
$flink = Foreign_link::getByUserID($user->id, FEEDSUB_SERVICE);
|
|
||||||
|
|
||||||
if (!empty($flink)) {
|
|
||||||
$fuser = $flink->getForeignUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->elementStart('form', array('method' => 'post',
|
$this->elementStart('form', array('method' => 'post',
|
||||||
'id' => 'form_settings_feedsub',
|
'id' => 'ostatus_sub',
|
||||||
'class' => 'form_settings',
|
'class' => 'form_settings',
|
||||||
'action' =>
|
'action' =>
|
||||||
common_local_url('feedsubsettings')));
|
common_local_url('ostatussub')));
|
||||||
|
|
||||||
$this->hidden('token', common_session_token());
|
$this->hidden('token', common_session_token());
|
||||||
|
|
||||||
@ -77,17 +91,47 @@ class OStatusSubAction extends Action
|
|||||||
|
|
||||||
$this->elementStart('ul', 'form_data');
|
$this->elementStart('ul', 'form_data');
|
||||||
$this->elementStart('li');
|
$this->elementStart('li');
|
||||||
$this->input('feedurl', _('Feed URL'), $this->feedurl, _('Enter the URL of a PubSubHubbub-enabled feed'));
|
$this->input('profile',
|
||||||
|
_m('Address or profile URL'),
|
||||||
|
$this->profile_uri,
|
||||||
|
_m('Enter the profile URL of a PubSubHubbub-enabled feed'));
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
$this->elementEnd('ul');
|
$this->elementEnd('ul');
|
||||||
|
|
||||||
$this->submit('subscribe', _m('Subscribe'));
|
if ($this->preview) {
|
||||||
|
$this->submit('subscribe', _m('Subscribe'));
|
||||||
|
} else {
|
||||||
|
$this->submit('validate', _m('Continue'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->elementEnd('fieldset');
|
$this->elementEnd('fieldset');
|
||||||
|
|
||||||
$this->elementEnd('form');
|
$this->elementEnd('form');
|
||||||
|
|
||||||
$this->previewFeed();
|
if ($this->preview) {
|
||||||
|
$this->previewFeed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepare($args)
|
||||||
|
{
|
||||||
|
parent::prepare($args);
|
||||||
|
$this->profile_uri = $this->arg('profile');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle($args)
|
||||||
|
{
|
||||||
|
parent::handle($args);
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
|
$this->handlePost();
|
||||||
|
} else {
|
||||||
|
if ($this->profile_uri) {
|
||||||
|
$this->validateAndPreview();
|
||||||
|
} else {
|
||||||
|
$this->showPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,14 +155,15 @@ class OStatusSubAction extends Action
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->arg('subscribe')) {
|
if ($this->arg('validate')) {
|
||||||
|
$this->validateAndPreview();
|
||||||
|
} else if ($this->arg('subscribe')) {
|
||||||
$this->saveFeed();
|
$this->saveFeed();
|
||||||
} else {
|
} else {
|
||||||
$this->showForm(_('Unexpected form submission.'));
|
$this->showForm(_('Unexpected form submission.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up and add a feed
|
* Set up and add a feed
|
||||||
*
|
*
|
||||||
@ -127,100 +172,91 @@ class OStatusSubAction extends Action
|
|||||||
*/
|
*/
|
||||||
function validateFeed()
|
function validateFeed()
|
||||||
{
|
{
|
||||||
$feedurl = $this->trimmed('feed');
|
$profile_uri = trim($this->arg('profile'));
|
||||||
|
|
||||||
if ($feedurl == '') {
|
if ($profile_uri == '') {
|
||||||
$this->showForm(_m('Empty feed URL!'));
|
$this->showForm(_m('Empty remote profile URL!'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->feedurl = $feedurl;
|
$this->profile_uri = $profile_uri;
|
||||||
|
|
||||||
// Get the canonical feed URI and check it
|
// @fixme validate, normalize bla bla
|
||||||
try {
|
try {
|
||||||
$discover = new FeedDiscovery();
|
$oprofile = Ostatus_profile::ensureProfile($this->profile_uri);
|
||||||
$uri = $discover->discoverFromURL($feedurl);
|
$this->oprofile = $oprofile;
|
||||||
|
return true;
|
||||||
} catch (FeedSubBadURLException $e) {
|
} catch (FeedSubBadURLException $e) {
|
||||||
$this->showForm(_m('Invalid URL or could not reach server.'));
|
$err = _m('Invalid URL or could not reach server.');
|
||||||
return false;
|
|
||||||
} catch (FeedSubBadResponseException $e) {
|
} catch (FeedSubBadResponseException $e) {
|
||||||
$this->showForm(_m('Cannot read feed; server returned error.'));
|
$err = _m('Cannot read feed; server returned error.');
|
||||||
return false;
|
|
||||||
} catch (FeedSubEmptyException $e) {
|
} catch (FeedSubEmptyException $e) {
|
||||||
$this->showForm(_m('Cannot read feed; server returned an empty page.'));
|
$err = _m('Cannot read feed; server returned an empty page.');
|
||||||
return false;
|
|
||||||
} catch (FeedSubBadHTMLException $e) {
|
} catch (FeedSubBadHTMLException $e) {
|
||||||
$this->showForm(_m('Bad HTML, could not find feed link.'));
|
$err = _m('Bad HTML, could not find feed link.');
|
||||||
return false;
|
|
||||||
} catch (FeedSubNoFeedException $e) {
|
} catch (FeedSubNoFeedException $e) {
|
||||||
$this->showForm(_m('Could not find a feed linked from this URL.'));
|
$err = _m('Could not find a feed linked from this URL.');
|
||||||
return false;
|
|
||||||
} catch (FeedSubUnrecognizedTypeException $e) {
|
} catch (FeedSubUnrecognizedTypeException $e) {
|
||||||
$this->showForm(_m('Not a recognized feed type.'));
|
$err = _m('Not a recognized feed type.');
|
||||||
return false;
|
|
||||||
} catch (FeedSubException $e) {
|
} catch (FeedSubException $e) {
|
||||||
// Any new ones we forgot about
|
// Any new ones we forgot about
|
||||||
$this->showForm(_m('Bad feed URL.'));
|
$err = sprintf(_m('Bad feed URL: %s %s'), get_class($e), $e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->munger = $discover->feedMunger();
|
|
||||||
$this->profile = $this->munger->ostatusProfile();
|
|
||||||
|
|
||||||
if ($this->profile->huburi == '') {
|
$this->showForm($err);
|
||||||
$this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.'));
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveFeed()
|
function saveFeed()
|
||||||
{
|
{
|
||||||
if ($this->validateFeed()) {
|
if ($this->validateFeed()) {
|
||||||
$this->preview = true;
|
$this->preview = true;
|
||||||
$this->profile = Ostatus_profile::ensureProfile($this->munger);
|
|
||||||
|
|
||||||
// If not already in use, subscribe to updates via the hub
|
|
||||||
if ($this->profile->sub_start) {
|
|
||||||
common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->profile->feeduri} last subbed {$this->profile->sub_start}");
|
|
||||||
} else {
|
|
||||||
$ok = $this->profile->subscribe();
|
|
||||||
common_log(LOG_INFO, __METHOD__ . ": sub was $ok");
|
|
||||||
if (!$ok) {
|
|
||||||
$this->showForm(_m('Feed subscription failed! Bad response from hub.'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// And subscribe the current user to the local profile
|
// And subscribe the current user to the local profile
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
$profile = $this->profile->getProfile();
|
|
||||||
|
if (!$this->oprofile->subscribe()) {
|
||||||
if ($user->isSubscribed($profile)) {
|
$this->showForm(_m("Failed to set up server-to-server subscription."));
|
||||||
$this->showForm(_m('Already subscribed!'));
|
return;
|
||||||
} elseif ($user->subscribeTo($profile)) {
|
}
|
||||||
$this->showForm(_m('Feed subscribed!'));
|
|
||||||
|
if ($this->oprofile->isGroup()) {
|
||||||
|
$group = $this->oprofile->localGroup();
|
||||||
|
if ($user->isMember($group)) {
|
||||||
|
$this->showForm(_m('Already a member!'));
|
||||||
|
} elseif (Group_member::join($this->profile->group_id, $user->id)) {
|
||||||
|
$this->showForm(_m('Joined remote group!'));
|
||||||
|
} else {
|
||||||
|
$this->showForm(_m('Remote group join failed!'));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->showForm(_m('Feed subscription failed!'));
|
$local = $this->oprofile->localProfile();
|
||||||
|
if ($user->isSubscribed($local)) {
|
||||||
|
$this->showForm(_m('Already subscribed!'));
|
||||||
|
} elseif ($this->oprofile->subscribeLocalToRemote($user)) {
|
||||||
|
$this->showForm(_m('Remote user subscribed!'));
|
||||||
|
} else {
|
||||||
|
$this->showForm(_m('Remote subscription failed!'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateAndPreview()
|
||||||
function previewFeed()
|
|
||||||
{
|
{
|
||||||
$profile = $this->munger->ostatusProfile();
|
if ($this->validateFeed()) {
|
||||||
$notice = $this->munger->notice(0, true); // preview
|
$this->preview = true;
|
||||||
|
$this->showForm(_m('Previewing feed:'));
|
||||||
if ($notice) {
|
|
||||||
$this->element('b', null, 'Preview of latest post from this feed:');
|
|
||||||
|
|
||||||
$item = new NoticeList($notice, $this);
|
|
||||||
$item->show();
|
|
||||||
} else {
|
|
||||||
$this->element('b', null, 'No posts in this feed yet.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function previewFeed()
|
||||||
|
{
|
||||||
|
$this->text('Profile preview should go here');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showScripts()
|
||||||
|
{
|
||||||
|
parent::showScripts();
|
||||||
|
$this->autofocus('feedurl');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class WebfingerAction extends Action
|
|||||||
'href' => $salmon_url);
|
'href' => $salmon_url);
|
||||||
|
|
||||||
// TODO - finalize where the redirect should go on the publisher
|
// TODO - finalize where the redirect should go on the publisher
|
||||||
$url = common_local_url('ostatussub') . '?feed={uri}';
|
$url = common_local_url('ostatussub') . '?profile={uri}';
|
||||||
$xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
|
$xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
|
||||||
'template' => $url );
|
'template' => $url );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user