* @maintainer Brion Vibber <brion@status.net>
*/
-if (!defined('STATUSNET')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
/**
* Key UI methods:
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',
*/
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'),
// TRANS: Extra paragraph in remote profile view when already subscribed.
_m('You are already subscribed to this user.'));
$ok = true;
}
- $avatar = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
+ $avatarUrl = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
$this->showEntity($profile,
$profile->profileurl,
$hasFN = ($fullname !== '') ? 'nickname' : 'fn nickname entity_nickname';
$this->elementStart('a', array('href' => $profile,
'class' => 'url '.$hasFN));
- $this->raw($nickname);
+ $this->text($nickname);
$this->elementEnd('a');
if (!is_null($fullname)) {
$this->elementStart('div', 'fn entity_fn');
- $this->raw($fullname);
+ $this->text($fullname);
$this->elementEnd('div');
}
if (!is_null($location)) {
$this->elementStart('div', 'label entity_location');
- $this->raw($location);
+ $this->text($location);
$this->elementEnd('div');
}
if (!is_null($homepage)) {
$this->elementStart('a', array('href' => $homepage,
'class' => 'url entity_url'));
- $this->raw($homepage);
+ $this->text($homepage);
$this->elementEnd('a');
}
if (!is_null($note)) {
$this->elementStart('div', 'note entity_note');
- $this->raw($note);
+ $this->text($note);
$this->elementEnd('div');
}
$this->elementEnd('div');
*/
function success()
{
- $cur = common_current_user();
- $url = common_local_url('subscriptions', array('nickname' => $cur->nickname));
+ $url = common_local_url('subscriptions', array('nickname' => $this->scoped->nickname));
common_redirect($url, 303);
}
*/
function pullRemoteProfile()
{
- $this->profile_uri = $this->trimmed('profile');
+ $validate = new Validate();
try {
- if (Validate::email($this->profile_uri)) {
+ $this->profile_uri = Discovery::normalize($this->trimmed('profile'));
+ } catch (Exception $e) {
+ $this->profile_uri = null;
+ }
+ try {
+ if (Discovery::isAcct($this->profile_uri) && $validate->email(mb_substr($this->profile_uri, 5))) {
$this->oprofile = Ostatus_profile::ensureWebfinger($this->profile_uri);
- } else if (Validate::uri($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: 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 (FeedSubNoHubException $e) {
+ // TRANS: Error text.
+ $this->error = _m("Sorry, that feed is not Pubsubhubub enabled.");
+ common_debug('No hub found.', __FILE__);
} catch (Exception $e) {
// Any new ones we forgot about
// TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
function saveFeed()
{
// And subscribe the current user to the local profile
- $user = common_current_user();
$local = $this->oprofile->localProfile();
- if ($user->isSubscribed($local)) {
+ if ($this->scoped->isSubscribed($local)) {
// TRANS: OStatus remote subscription dialog error.
$this->showForm(_m('Already subscribed!'));
- } elseif (Subscription::start($user->getProfile(), $local)) {
+ } elseif (Subscription::start($this->scoped, $local)) {
$this->success();
} else {
// TRANS: OStatus remote subscription dialog error.
}
}
- 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;
- }
-
- if ($this->pullRemoteProfile()) {
- $this->validateRemoteProfile();
- }
- return true;
- }
-
- /**
- * Handle the submission.
- */
- function handle($args)
- {
- parent::handle($args);
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->handlePost();
- } else {
- $this->showForm();
- }
- }
-
/**
* Handle posts to this form
*