From ea9d6f21ecaff6e26ebe30775d1ddcd6d68d0a11 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 20 Feb 2010 12:46:48 -0800 Subject: 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) --- plugins/OStatus/actions/ostatusinit.php | 78 ++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 25 deletions(-) (limited to 'plugins/OStatus/actions/ostatusinit.php') diff --git a/plugins/OStatus/actions/ostatusinit.php b/plugins/OStatus/actions/ostatusinit.php index d21774420..4afde2c36 100644 --- a/plugins/OStatus/actions/ostatusinit.php +++ b/plugins/OStatus/actions/ostatusinit.php @@ -37,7 +37,7 @@ class OStatusInitAction extends Action parent::prepare($args); if (common_logged_in()) { - $this->clientError(_('You can use the local subscription!')); + $this->clientError(_m('You can use the local subscription!')); return false; } @@ -55,7 +55,7 @@ class OStatusInitAction extends Action /* Use a session token for CSRF protection. */ $token = $this->trimmed('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.')); return; } @@ -73,7 +73,7 @@ class OStatusInitAction extends Action $this->xw->startDocument('1.0', 'UTF-8'); $this->elementStart('html'); $this->elementStart('head'); - $this->element('title', null, _('Subscribe to user')); + $this->element('title', null, _m('Subscribe to user')); $this->elementEnd('head'); $this->elementStart('body'); $this->showContent(); @@ -91,50 +91,78 @@ class OStatusInitAction extends Action 'class' => 'form_settings', 'action' => common_local_url('ostatusinit'))); $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->elementStart('ul', 'form_data'); $this->elementStart('li', array('id' => 'ostatus_nickname')); - $this->input('nickname', _('User nickname'), $this->nickname, - _('Nickname of the user you want to follow')); + $this->input('nickname', _m('User nickname'), $this->nickname, + _m('Nickname of the user you want to follow')); $this->elementEnd('li'); $this->elementStart('li', array('id' => 'ostatus_profile')); - $this->input('acct', _('Profile Account'), $this->acct, - _('Your account id (i.e. user@identi.ca)')); + $this->input('acct', _m('Profile Account'), $this->acct, + _m('Your account id (i.e. user@identi.ca)')); $this->elementEnd('li'); $this->elementEnd('ul'); - $this->submit('submit', _('Subscribe')); + $this->submit('submit', _m('Subscribe')); $this->elementEnd('fieldset'); $this->elementEnd('form'); } function ostatusConnect() { - $w = new Webfinger; + $opts = array('allowed_schemes' => array('http', 'https', 'acct')); + if (Validate::uri($this->acct, $opts)) { + $bits = parse_url($this->acct); + if ($bits['scheme'] == 'acct') { + $this->connectWebfinger($bits['path']); + } else { + $this->connectProfile($this->acct); + } + } elseif (strpos('@', $this->acct) !== false) { + $this->connectWebfinger($this->acct); + } + } + + 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)); - $result = $w->lookup($this->acct); - foreach ($result->links as $link) { - if ($link['rel'] == 'http://ostatus.org/schema/1.0/subscribe') { - // We found a URL - let's redirect! + $url = $w->applyTemplate($link['template'], $feed_url); - $user = User::staticGet('nickname', $this->nickname); + common_redirect($url, 303); + } + + } + + } - $feed_url = common_local_url('ApiTimelineUser', - array('id' => $user->id, - 'format' => 'atom')); - $url = $w->applyTemplate($link['template'], $feed_url); + function connectProfile($subscriber_profile) + { + $user = User::staticGet('nickname', $this->nickname); + $target_profile = common_local_url('userbyid', array('id' => $user->id)); - common_redirect($url, 303); - } + // @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() { - return _('OStatus Connect'); + return _m('OStatus Connect'); } } -- cgit v1.2.3-54-g00ecf From 17ed30dffc1c05259baf2f0387089547e39684d7 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 22 Feb 2010 06:00:13 +0000 Subject: OStatus: fix remote subscription when putting webfinger address in the little box --- plugins/OStatus/actions/ostatusinit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/OStatus/actions/ostatusinit.php') diff --git a/plugins/OStatus/actions/ostatusinit.php b/plugins/OStatus/actions/ostatusinit.php index 4afde2c36..abd8cb541 100644 --- a/plugins/OStatus/actions/ostatusinit.php +++ b/plugins/OStatus/actions/ostatusinit.php @@ -119,7 +119,7 @@ class OStatusInitAction extends Action } else { $this->connectProfile($this->acct); } - } elseif (strpos('@', $this->acct) !== false) { + } elseif (strpos($this->acct, '@') !== false) { $this->connectWebfinger($this->acct); } } @@ -139,7 +139,7 @@ class OStatusInitAction extends Action $user = User::staticGet('nickname', $this->nickname); $target_profile = common_local_url('userbyid', array('id' => $user->id)); - $url = $w->applyTemplate($link['template'], $feed_url); + $url = $w->applyTemplate($link['template'], $target_profile); common_redirect($url, 303); } -- cgit v1.2.3-54-g00ecf From 2b16532ffb77d683d32ca6a399b80949d7e6b1e4 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 22 Feb 2010 10:03:34 -0800 Subject: OStatus: use 'profile' consistently as param on ostatussub and ostatusinit to help us stay sane. --- plugins/OStatus/actions/ostatusinit.php | 28 +++++++++++++++++----------- plugins/OStatus/js/ostatus.js | 1 - 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'plugins/OStatus/actions/ostatusinit.php') diff --git a/plugins/OStatus/actions/ostatusinit.php b/plugins/OStatus/actions/ostatusinit.php index abd8cb541..3f2f6368f 100644 --- a/plugins/OStatus/actions/ostatusinit.php +++ b/plugins/OStatus/actions/ostatusinit.php @@ -29,7 +29,7 @@ class OStatusInitAction extends Action { var $nickname; - var $acct; + var $profile; var $err; function prepare($args) @@ -41,8 +41,11 @@ class OStatusInitAction extends Action return false; } - $this->nickname = $this->trimmed('nickname'); - $this->acct = $this->trimmed('acct'); + // Local user the remote wants to subscribe to + $this->nickname = $this->trimmed('nickname'); + + // Webfinger or profile URL of the remote user + $this->profile = $this->trimmed('profile'); return true; } @@ -100,7 +103,7 @@ class OStatusInitAction extends Action _m('Nickname of the user you want to follow')); $this->elementEnd('li'); $this->elementStart('li', array('id' => 'ostatus_profile')); - $this->input('acct', _m('Profile Account'), $this->acct, + $this->input('profile', _m('Profile Account'), $this->profile, _m('Your account id (i.e. user@identi.ca)')); $this->elementEnd('li'); $this->elementEnd('ul'); @@ -112,15 +115,17 @@ class OStatusInitAction extends Action function ostatusConnect() { $opts = array('allowed_schemes' => array('http', 'https', 'acct')); - if (Validate::uri($this->acct, $opts)) { - $bits = parse_url($this->acct); + if (Validate::uri($this->profile, $opts)) { + $bits = parse_url($this->profile); if ($bits['scheme'] == 'acct') { $this->connectWebfinger($bits['path']); } else { - $this->connectProfile($this->acct); + $this->connectProfile($this->profile); } - } elseif (strpos($this->acct, '@') !== false) { - $this->connectWebfinger($this->acct); + } elseif (strpos($this->profile, '@') !== false) { + $this->connectWebfinger($this->profile); + } else { + $this->clientError(_m("Must provide a remote profile.")); } } @@ -140,12 +145,12 @@ class OStatusInitAction extends Action $target_profile = common_local_url('userbyid', array('id' => $user->id)); $url = $w->applyTemplate($link['template'], $target_profile); - + common_log(LOG_INFO, "Sending remote subscriber $acct to $url"); common_redirect($url, 303); } } - + $this->clientError(_m("Couldn't confirm remote profile address.")); } function connectProfile($subscriber_profile) @@ -157,6 +162,7 @@ class OStatusInitAction extends Action $suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/ostatussub', $subscriber_profile); $suburl .= '?profile=' . urlencode($target_profile); + common_log(LOG_INFO, "Sending remote subscriber $subscriber_profile to $suburl"); common_redirect($suburl, 303); } diff --git a/plugins/OStatus/js/ostatus.js b/plugins/OStatus/js/ostatus.js index 4b4c32910..0daeb1a8b 100644 --- a/plugins/OStatus/js/ostatus.js +++ b/plugins/OStatus/js/ostatus.js @@ -40,7 +40,6 @@ SN.U.DialogBox = { return false; }); - form.find('#acct').focus(); form.find('#profile').focus(); } -- cgit v1.2.3-54-g00ecf