summaryrefslogtreecommitdiff
path: root/plugins/OStatus
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2010-03-08 17:22:23 -0500
committerCraig Andrews <candrews@integralblue.com>2010-03-08 17:22:23 -0500
commit714d920faea302b55857cc3bec4e9e6160ea136a (patch)
treecffa5ee7a3261ad24b272cb3ced16a6c1dcafad1 /plugins/OStatus
parentc187bf55974347f7ddb4f28714af57861dce8f08 (diff)
parent51a245f18c1e4a830c5eb94f3e60c6b4b3e560ee (diff)
Merge branch '0.9.x' into 1.0.x
Conflicts: classes/statusnet.ini db/statusnet.sql lib/jabber.php lib/xmppmanager.php
Diffstat (limited to 'plugins/OStatus')
-rw-r--r--plugins/OStatus/OStatusPlugin.php224
-rw-r--r--plugins/OStatus/actions/hostmeta.php16
-rw-r--r--plugins/OStatus/actions/ostatusgroup.php181
-rw-r--r--plugins/OStatus/actions/ostatusinit.php55
-rw-r--r--plugins/OStatus/actions/ostatussub.php157
-rw-r--r--plugins/OStatus/actions/ownerxrd.php56
-rw-r--r--plugins/OStatus/actions/pushhub.php2
-rw-r--r--plugins/OStatus/actions/userxrd.php48
-rw-r--r--plugins/OStatus/classes/HubSub.php10
-rw-r--r--plugins/OStatus/classes/Magicsig.php28
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php563
-rw-r--r--plugins/OStatus/extlib/hkit/hcard.profile.php105
-rw-r--r--plugins/OStatus/extlib/hkit/hkit.class.php475
-rw-r--r--plugins/OStatus/lib/discovery.php310
-rw-r--r--plugins/OStatus/lib/magicenvelope.php63
-rw-r--r--plugins/OStatus/lib/ostatusqueuehandler.php47
-rw-r--r--plugins/OStatus/lib/pushinqueuehandler.php6
-rw-r--r--plugins/OStatus/lib/salmon.php45
-rw-r--r--plugins/OStatus/lib/salmonaction.php27
-rw-r--r--plugins/OStatus/lib/salmonqueuehandler.php4
-rw-r--r--plugins/OStatus/lib/webfinger.php151
-rw-r--r--plugins/OStatus/lib/xrd.php32
-rw-r--r--plugins/OStatus/lib/xrdaction.php (renamed from plugins/OStatus/actions/webfinger.php)62
-rw-r--r--plugins/OStatus/locale/OStatus.po280
-rw-r--r--plugins/OStatus/scripts/updateostatus.php127
-rw-r--r--plugins/OStatus/theme/base/css/ostatus.css32
26 files changed, 2451 insertions, 655 deletions
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index e7ffd6cc2..efb630297 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -43,16 +43,20 @@ class OStatusPlugin extends Plugin
// Discovery actions
$m->connect('.well-known/host-meta',
array('action' => 'hostmeta'));
- $m->connect('main/webfinger',
- array('action' => 'webfinger'));
+ $m->connect('main/xrd',
+ array('action' => 'userxrd'));
+ $m->connect('main/ownerxrd',
+ array('action' => 'ownerxrd'));
$m->connect('main/ostatus',
array('action' => 'ostatusinit'));
$m->connect('main/ostatus?nickname=:nickname',
array('action' => 'ostatusinit'), array('nickname' => '[A-Za-z0-9_-]+'));
+ $m->connect('main/ostatus?group=:group',
+ array('action' => 'ostatusinit'), array('group' => '[A-Za-z0-9_-]+'));
$m->connect('main/ostatussub',
array('action' => 'ostatussub'));
- $m->connect('main/ostatussub',
- array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+'));
+ $m->connect('main/ostatusgroup',
+ array('action' => 'ostatusgroup'));
// PuSH actions
$m->connect('main/push/hub', array('action' => 'pushhub'));
@@ -103,6 +107,20 @@ class OStatusPlugin extends Plugin
}
/**
+ * Add a link header for LRDD Discovery
+ */
+ function onStartShowHTML($action)
+ {
+ if ($action instanceof ShowstreamAction) {
+ $acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
+ $url = common_local_url('userxrd');
+ $url.= '?uri='. $acct;
+
+ header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
+ }
+ }
+
+ /**
* Set up a PuSH hub link to our internal link for canonical timeline
* Atom feeds for users and groups.
*/
@@ -135,7 +153,8 @@ class OStatusPlugin extends Plugin
// Also, we'll add in the salmon link
$salmon = common_local_url($salmonAction, array('id' => $id));
- $feed->addLink($salmon, array('rel' => 'salmon'));
+ $feed->addLink($salmon, array('rel' => Salmon::NS_REPLIES));
+ $feed->addLink($salmon, array('rel' => Salmon::NS_MENTIONS));
}
return true;
@@ -195,6 +214,22 @@ class OStatusPlugin extends Plugin
return false;
}
+ function onStartGroupSubscribe($output, $group)
+ {
+ $cur = common_current_user();
+
+ if (empty($cur)) {
+ // Add an OStatus subscribe
+ $url = common_local_url('ostatusinit',
+ array('group' => $group->nickname));
+ $output->element('a', array('href' => $url,
+ 'class' => 'entity_remote_subscribe'),
+ _m('Join'));
+ }
+
+ return true;
+ }
+
/**
* Check if we've got remote replies to send via Salmon.
*
@@ -207,40 +242,81 @@ class OStatusPlugin extends Plugin
}
/**
- *
+ * Find any explicit remote mentions. Accepted forms:
+ * Webfinger: @user@example.com
+ * Profile link: @example.com/mublog/user
+ * @param Profile $sender (os user?)
+ * @param string $text input markup text
+ * @param array &$mention in/out param: set of found mentions
+ * @return boolean hook return value
*/
- function onStartFindMentions($sender, $text, &$mentions)
+ function onEndFindMentions($sender, $text, &$mentions)
{
- preg_match_all('/(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)/',
+ $matches = array();
+
+ // Webfinger matches: @user@example.com
+ if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
$text,
$wmatches,
- PREG_OFFSET_CAPTURE);
-
- foreach ($wmatches[1] as $wmatch) {
-
- $webfinger = $wmatch[0];
-
- $this->log(LOG_INFO, "Checking Webfinger for address '$webfinger'");
-
- $oprofile = Ostatus_profile::ensureWebfinger($webfinger);
-
- if (empty($oprofile)) {
-
- $this->log(LOG_INFO, "No Ostatus_profile found for address '$webfinger'");
-
- } else {
-
- $this->log(LOG_INFO, "Ostatus_profile found for address '$webfinger'");
+ PREG_OFFSET_CAPTURE)) {
+ foreach ($wmatches[1] as $wmatch) {
+ list($target, $pos) = $wmatch;
+ $this->log(LOG_INFO, "Checking webfinger '$target'");
+ try {
+ $oprofile = Ostatus_profile::ensureWebfinger($target);
+ if ($oprofile && !$oprofile->isGroup()) {
+ $profile = $oprofile->localProfile();
+ $matches[$pos] = array('mentioned' => array($profile),
+ 'text' => $target,
+ 'position' => $pos,
+ 'url' => $profile->profileurl);
+ }
+ } catch (Exception $e) {
+ $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
+ }
+ }
+ }
- $profile = $oprofile->localProfile();
+ // Profile matches: @example.com/mublog/user
+ if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)!',
+ $text,
+ $wmatches,
+ PREG_OFFSET_CAPTURE)) {
+ foreach ($wmatches[1] as $wmatch) {
+ list($target, $pos) = $wmatch;
+ $schemes = array('http', 'https');
+ foreach ($schemes as $scheme) {
+ $url = "$scheme://$target";
+ $this->log(LOG_INFO, "Checking profile address '$url'");
+ try {
+ $oprofile = Ostatus_profile::ensureProfile($url);
+ if ($oprofile && !$oprofile->isGroup()) {
+ $profile = $oprofile->localProfile();
+ $matches[$pos] = array('mentioned' => array($profile),
+ 'text' => $target,
+ 'position' => $pos,
+ 'url' => $profile->profileurl);
+ break;
+ }
+ } catch (Exception $e) {
+ $this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
+ }
+ }
+ }
+ }
- $mentions[] = array('mentioned' => array($profile),
- 'text' => $wmatch[0],
- 'position' => $wmatch[1],
- 'url' => $profile->profileurl);
+ foreach ($mentions as $i => $other) {
+ // If we share a common prefix with a local user, override it!
+ $pos = $other['position'];
+ if (isset($matches[$pos])) {
+ $mentions[$i] = $matches[$pos];
+ unset($matches[$pos]);
}
}
+ foreach ($matches as $mention) {
+ $mentions[] = $mention;
+ }
return true;
}
@@ -390,7 +466,7 @@ class OStatusPlugin extends Plugin
$act->actor = ActivityObject::fromProfile($subscriber);
$act->object = ActivityObject::fromProfile($other);
- $oprofile->notifyActivity($act);
+ $oprofile->notifyActivity($act, $subscriber);
return true;
}
@@ -438,7 +514,7 @@ class OStatusPlugin extends Plugin
$act->actor = ActivityObject::fromProfile($profile);
$act->object = ActivityObject::fromProfile($other);
- $oprofile->notifyActivity($act);
+ $oprofile->notifyActivity($act, $profile);
return true;
}
@@ -480,7 +556,7 @@ class OStatusPlugin extends Plugin
$member->getBestName(),
$oprofile->getBestName());
- if ($oprofile->notifyActivity($act)) {
+ if ($oprofile->notifyActivity($act, $member)) {
return true;
} else {
$oprofile->garbageCollect();
@@ -511,7 +587,6 @@ class OStatusPlugin extends Plugin
// Drop the PuSH subscription if there are no other subscribers.
$oprofile->garbageCollect();
-
$member = Profile::staticGet($user->id);
$act = new Activity();
@@ -530,7 +605,7 @@ class OStatusPlugin extends Plugin
$member->getBestName(),
$oprofile->getBestName());
- $oprofile->notifyActivity($act);
+ $oprofile->notifyActivity($act, $member);
}
}
@@ -573,7 +648,7 @@ class OStatusPlugin extends Plugin
$act->actor = ActivityObject::fromProfile($profile);
$act->object = ActivityObject::fromNotice($notice);
- $oprofile->notifyActivity($act);
+ $oprofile->notifyActivity($act, $profile);
return true;
}
@@ -617,7 +692,7 @@ class OStatusPlugin extends Plugin
$act->actor = ActivityObject::fromProfile($profile);
$act->object = ActivityObject::fromNotice($notice);
- $oprofile->notifyActivity($act);
+ $oprofile->notifyActivity($act, $profile);
return true;
}
@@ -634,7 +709,7 @@ class OStatusPlugin extends Plugin
function onStartUserGroupHomeUrl($group, &$url)
{
- return $this->onStartUserGroupPermalink($group, &$url);
+ return $this->onStartUserGroupPermalink($group, $url);
}
function onStartUserGroupPermalink($group, &$url)
@@ -650,19 +725,45 @@ class OStatusPlugin extends Plugin
function onStartShowSubscriptionsContent($action)
{
+ $this->showEntityRemoteSubscribe($action);
+
+ return true;
+ }
+
+ function onStartShowUserGroupsContent($action)
+ {
+ $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
+
+ return true;
+ }
+
+ function onEndShowSubscriptionsMiniList($action)
+ {
+ $this->showEntityRemoteSubscribe($action);
+
+ return true;
+ }
+
+ function onEndShowGroupsMiniList($action)
+ {
+ $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
+
+ return true;
+ }
+
+ function showEntityRemoteSubscribe($action, $target='ostatussub')
+ {
$user = common_current_user();
if ($user && ($user->id == $action->profile->id)) {
$action->elementStart('div', 'entity_actions');
$action->elementStart('p', array('id' => 'entity_remote_subscribe',
'class' => 'entity_subscribe'));
- $action->element('a', array('href' => common_local_url('ostatussub'),
+ $action->element('a', array('href' => common_local_url($target),
'class' => 'entity_remote_subscribe')
- , _m('Subscribe to remote user'));
+ , _m('Remote'));
$action->elementEnd('p');
$action->elementEnd('div');
}
-
- return true;
}
/**
@@ -706,9 +807,46 @@ class OStatusPlugin extends Plugin
$act->object = $act->actor;
while ($oprofile->fetch()) {
- $oprofile->notifyDeferred($act);
+ $oprofile->notifyDeferred($act, $profile);
+ }
+
+ return true;
+ }
+
+ function onStartProfileListItemActionElements($item)
+ {
+ if (!common_logged_in()) {
+
+ $profileUser = User::staticGet('id', $item->profile->id);
+
+ if (!empty($profileUser)) {
+
+ $output = $item->out;
+
+ // Add an OStatus subscribe
+ $output->elementStart('li', 'entity_subscribe');
+ $url = common_local_url('ostatusinit',
+ array('nickname' => $profileUser->nickname));
+ $output->element('a', array('href' => $url,
+ 'class' => 'entity_remote_subscribe'),
+ _m('Subscribe'));
+ $output->elementEnd('li');
+ }
}
return true;
}
+
+ function onPluginVersion(&$versions)
+ {
+ $versions[] = array('name' => 'OStatus',
+ 'version' => STATUSNET_VERSION,
+ 'author' => 'Evan Prodromou, James Walker, Brion Vibber, Zach Copley',
+ 'homepage' => 'http://status.net/wiki/Plugin:OStatus',
+ 'rawdescription' =>
+ _m('Follow people across social networks that implement '.
+ '<a href="http://ostatus.org/">OStatus</a>.'));
+
+ return true;
+ }
}
diff --git a/plugins/OStatus/actions/hostmeta.php b/plugins/OStatus/actions/hostmeta.php
index 850b8a0fe..6d35ada6c 100644
--- a/plugins/OStatus/actions/hostmeta.php
+++ b/plugins/OStatus/actions/hostmeta.php
@@ -31,12 +31,18 @@ class HostMetaAction extends Action
{
parent::handle();
- $w = new Webfinger();
-
-
$domain = common_config('site', 'server');
- $url = common_local_url('webfinger');
+ $url = common_local_url('userxrd');
$url.= '?uri={uri}';
- print $w->getHostMeta($domain, $url);
+
+ $xrd = new XRD();
+
+ $xrd = new XRD();
+ $xrd->host = $domain;
+ $xrd->links[] = array('rel' => Discovery::LRDD_REL,
+ 'template' => $url,
+ 'title' => array('Resource Descriptor'));
+
+ print $xrd->toXML();
}
}
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 3f2f6368f..22aea9f70 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,20 +141,18 @@ class OStatusInitAction extends Action
function connectWebfinger($acct)
{
- $w = new Webfinger;
+ $target_profile = $this->targetProfile();
- $result = $w->lookup($acct);
+ $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 = $w->applyTemplate($link['template'], $target_profile);
+ $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('nickname', $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 12832cdcf..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);
@@ -112,7 +105,7 @@ class OStatusSubAction extends Action
$this->submit('submit', _m('Join'), 'submit', null,
_m('Join this group'));
} else {
- $this->submit('submit', _m('Subscribe'), 'submit', null,
+ $this->submit('submit', _m('Confirm'), 'submit', null,
_m('Subscribe to this user'));
}
$this->elementEnd('fieldset');
@@ -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,91 +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)) {
- $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!'));
- }
+ $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)) {
- $this->showForm(_m('Already subscribed!'));
- } elseif ($this->oprofile->subscribeLocalToRemote($user)) {
- $this->successUser();
- } else {
- $this->showForm(_m('Remote subscription failed!'));
- }
+ // TRANS: OStatus remote subscription dialog error.
+ $this->showForm(_m('Remote subscription failed!'));
}
}
@@ -363,8 +320,9 @@ class OStatusSubAction extends Action
return false;
}
- $this->profile_uri = $this->arg('profile');
-
+ if ($this->pullRemoteProfile()) {
+ $this->validateRemoteProfile();
+ }
return true;
}
@@ -377,9 +335,6 @@ class OStatusSubAction extends Action
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost();
} else {
- if ($this->arg('profile')) {
- $this->validateFeed();
- }
$this->showForm();
}
}
@@ -401,7 +356,7 @@ class OStatusSubAction extends Action
return;
}
- if ($this->validateFeed()) {
+ if ($this->oprofile) {
if ($this->arg('submit')) {
$this->saveFeed();
return;
@@ -442,7 +397,8 @@ class OStatusSubAction extends Action
function title()
{
- return _m('Authorize subscription');
+ // TRANS: Page title for OStatus remote subscription form
+ return _m('Confirm');
}
/**
@@ -486,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/pushhub.php b/plugins/OStatus/actions/pushhub.php
index f33690bc4..842d65e7d 100644
--- a/plugins/OStatus/actions/pushhub.php
+++ b/plugins/OStatus/actions/pushhub.php
@@ -104,7 +104,7 @@ class PushHubAction extends Action
throw new ClientException("Invalid hub.secret $secret; must be under 200 bytes.");
}
- $sub = HubSub::staticGet($sub->topic, $sub->callback);
+ $sub = HubSub::staticGet($topic, $callback);
if (!$sub) {
// Creating a new one!
$sub = new HubSub();
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/classes/HubSub.php b/plugins/OStatus/classes/HubSub.php
index 1ac181fee..3120a70f9 100644
--- a/plugins/OStatus/classes/HubSub.php
+++ b/plugins/OStatus/classes/HubSub.php
@@ -99,7 +99,7 @@ class HubSub extends Memcached_DataObject
return array_keys($this->keyTypes());
}
- function sequenceKeys()
+ function sequenceKey()
{
return array(false, false, false);
}
@@ -260,9 +260,15 @@ class HubSub extends Memcached_DataObject
$retries = intval(common_config('ostatus', 'hub_retries'));
}
- $data = array('sub' => clone($this),
+ // We dare not clone() as when the clone is discarded it'll
+ // destroy the result data for the parent query.
+ // @fixme use clone() again when it's safe to copy an
+ // individual item from a multi-item query again.
+ $sub = HubSub::staticGet($this->topic, $this->callback);
+ $data = array('sub' => $sub,
'atom' => $atom,
'retries' => $retries);
+ common_log(LOG_INFO, "Queuing PuSH: $this->topic to $this->callback");
$qm = QueueManager::get();
$qm->enqueue($data, 'hubout');
}
diff --git a/plugins/OStatus/classes/Magicsig.php b/plugins/OStatus/classes/Magicsig.php
index 681aec184..5a46aeeb6 100644
--- a/plugins/OStatus/classes/Magicsig.php
+++ b/plugins/OStatus/classes/Magicsig.php
@@ -49,7 +49,12 @@ class Magicsig extends Memcached_DataObject
public /*static*/ function staticGet($k, $v=null)
{
- return parent::staticGet(__CLASS__, $k, $v);
+ $obj = parent::staticGet(__CLASS__, $k, $v);
+ if (!empty($obj)) {
+ return Magicsig::fromString($obj->keypair);
+ }
+
+ return $obj;
}
@@ -83,6 +88,10 @@ class Magicsig extends Memcached_DataObject
return array('user_id' => 'K');
}
+ function sequenceKey() {
+ return array(false, false, false);
+ }
+
function insert()
{
$this->keypair = $this->toString();
@@ -90,7 +99,7 @@ class Magicsig extends Memcached_DataObject
return parent::insert();
}
- public function generate($key_length = 512)
+ public function generate($user_id, $key_length = 512)
{
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
@@ -101,6 +110,7 @@ class Magicsig extends Memcached_DataObject
$this->_rsa = new Crypt_RSA($params);
PEAR::popErrorHandling();
+ $this->user_id = $user_id;
$this->insert();
}
@@ -136,8 +146,10 @@ class Magicsig extends Memcached_DataObject
$mod = base64_url_decode($matches[1]);
$exp = base64_url_decode($matches[2]);
- if ($matches[4]) {
+ if (!empty($matches[4])) {
$private_exp = base64_url_decode($matches[4]);
+ } else {
+ $private_exp = false;
}
$params['public_key'] = new Crypt_RSA_KEY($mod, $exp, 'public');
@@ -171,14 +183,15 @@ class Magicsig extends Memcached_DataObject
switch ($this->alg) {
case 'RSA-SHA256':
- return 'sha256';
+ return 'magicsig_sha256';
}
}
public function sign($bytes)
{
- $sig = $this->_rsa->createSign($bytes, null, 'sha256');
+ $hash = $this->getHash();
+ $sig = $this->_rsa->createSign($bytes, null, $hash);
if ($this->_rsa->isError()) {
$error = $this->_rsa->getLastError();
common_log(LOG_DEBUG, 'RSA Error: '. $error->getMessage());
@@ -190,7 +203,8 @@ class Magicsig extends Memcached_DataObject
public function verify($signed_bytes, $signature)
{
- $result = $this->_rsa->validateSign($signed_bytes, $signature, null, 'sha256');
+ $hash = $this->getHash();
+ $result = $this->_rsa->validateSign($signed_bytes, $signature, null, $hash);
if ($this->_rsa->isError()) {
$error = $this->keypair->getLastError();
common_log(LOG_DEBUG, 'RSA Error: '. $error->getMessage());
@@ -203,7 +217,7 @@ class Magicsig extends Memcached_DataObject
// Define a sha256 function for hashing
// (Crypt_RSA should really be updated to use hash() )
-function sha256($bytes)
+function magicsig_sha256($bytes)
{
return hash('sha256', $bytes);
}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index a366c1c2c..abc8100ce 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -150,27 +150,7 @@ class Ostatus_profile extends Memcached_DataObject
function asActivityObject()
{
if ($this->isGroup()) {
- $object = new ActivityObject();
- $object->type = 'http://activitystrea.ms/schema/1.0/group';
- $object->id = $this->uri;
- $self = $this->localGroup();
-
- // @fixme put a standard getAvatar() interface on groups too
- if ($self->homepage_logo) {
- $object->avatar = $self->homepage_logo;
- $map = array('png' => 'image/png',
- 'jpg' => 'image/jpeg',
- 'jpeg' => 'image/jpeg',
- 'gif' => 'image/gif');
- $extension = pathinfo(parse_url($avatarHref, PHP_URL_PATH), PATHINFO_EXTENSION);
- if (isset($map[$extension])) {
- // @fixme this ain't used/saved yet
- $object->avatarType = $map[$extension];
- }
- }
-
- $object->link = $this->uri; // @fixme accurate?
- return $object;
+ return ActivityObject::fromGroup($this->localGroup());
} else {
return ActivityObject::fromProfile($this->localProfile());
}
@@ -189,57 +169,13 @@ class Ostatus_profile extends Memcached_DataObject
*/
function asActivityNoun($element)
{
- $xs = new XMLStringer(true);
- $avatarHref = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
- $avatarType = 'image/png';
if ($this->isGroup()) {
- $type = 'http://activitystrea.ms/schema/1.0/group';
- $self = $this->localGroup();
-
- // @fixme put a standard getAvatar() interface on groups too
- if ($self->homepage_logo) {
- $avatarHref = $self->homepage_logo;
- $map = array('png' => 'image/png',
- 'jpg' => 'image/jpeg',
- 'jpeg' => 'image/jpeg',
- 'gif' => 'image/gif');
- $extension = pathinfo(parse_url($avatarHref, PHP_URL_PATH), PATHINFO_EXTENSION);
- if (isset($map[$extension])) {
- $avatarType = $map[$extension];
- }
- }
+ $noun = ActivityObject::fromGroup($this->localGroup());
+ return $noun->asString('activity:' . $element);
} else {
- $type = 'http://activitystrea.ms/schema/1.0/person';
- $self = $this->localProfile();
- $avatar = $self->getAvatar(AVATAR_PROFILE_SIZE);
- if ($avatar) {
- $avatarHref = $avatar->url;
- $avatarType = $avatar->mediatype;
- }
+ $noun = ActivityObject::fromProfile($this->localProfile());
+ return $noun->asString('activity:' . $element);
}
- $xs->elementStart('activity:' . $element);
- $xs->element(
- 'activity:object-type',
- null,
- $type
- );
- $xs->element(
- 'id',
- null,
- $this->uri); // ?
- $xs->element('title', null, $self->getBestName());
-
- $xs->element(
- 'link', array(
- 'type' => $avatarType,
- 'href' => $avatarHref
- ),
- ''
- );
-
- $xs->elementEnd('activity:' . $element);
-
- return $xs->getString();
}
/**
@@ -332,6 +268,9 @@ class Ostatus_profile extends Memcached_DataObject
*/
public function unsubscribe() {
$feedsub = FeedSub::staticGet('uri', $this->feeduri);
+ if (!$feedsub) {
+ return true;
+ }
if ($feedsub->sub_state == 'active') {
return $feedsub->unsubscribe();
} else if ($feedsub->sub_state == '' || $feedsub->sub_state == 'inactive' || $feedsub->sub_state == 'unsubscribe') {
@@ -356,7 +295,7 @@ class Ostatus_profile extends Memcached_DataObject
$count = $this->localProfile()->subscriberCount();
}
if ($count == 0) {
- common_log(LOG_INFO, "Unsubscribing from now-unused remote feed $oprofile->feeduri");
+ common_log(LOG_INFO, "Unsubscribing from now-unused remote feed $this->feeduri");
$this->unsubscribe();
return true;
} else {
@@ -398,7 +337,8 @@ class Ostatus_profile extends Memcached_DataObject
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
'xmlns:georss' => 'http://www.georss.org/georss',
'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
- 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0');
+ 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
+ 'xmlns:media' => 'http://purl.org/syndication/atommedia');
$entry = new XMLStringer();
$entry->elementStart('entry', $attributes);
@@ -417,7 +357,7 @@ class Ostatus_profile extends Memcached_DataObject
common_log(LOG_INFO, "Posting to Salmon endpoint $this->salmonuri: $xml");
$salmon = new Salmon(); // ?
- return $salmon->post($this->salmonuri, $xml);
+ return $salmon->post($this->salmonuri, $xml, $actor);
}
return false;
}
@@ -429,11 +369,11 @@ class Ostatus_profile extends Memcached_DataObject
* @param mixed $entry XML string, Notice, or Activity
* @return boolean success
*/
- public function notifyActivity($entry)
+ public function notifyActivity($entry, $actor)
{
if ($this->salmonuri) {
$salmon = new Salmon();
- return $salmon->post($this->salmonuri, $this->notifyPrepXml($entry));
+ return $salmon->post($this->salmonuri, $this->notifyPrepXml($entry), $actor);
}
return false;
@@ -446,11 +386,12 @@ class Ostatus_profile extends Memcached_DataObject
* @param mixed $entry XML string, Notice, or Activity
* @return boolean success
*/
- public function notifyDeferred($entry)
+ public function notifyDeferred($entry, $actor)
{
if ($this->salmonuri) {
$data = array('salmonuri' => $this->salmonuri,
- 'entry' => $this->notifyPrepXml($entry));
+ 'entry' => $this->notifyPrepXml($entry),
+ 'actor' => $actor->id);
$qm = QueueManager::get();
return $qm->enqueue($data, 'salmon');
@@ -482,45 +423,23 @@ class Ostatus_profile extends Memcached_DataObject
}
}
- function atomFeed($actor)
- {
- $feed = new Atom10Feed();
- // @fixme should these be set up somewhere else?
- $feed->addNamespace('activity', 'http://activitystrea.ms/spec/1.0/');
- $feed->addNamespace('thr', 'http://purl.org/syndication/thread/1.0');
- $feed->addNamespace('georss', 'http://www.georss.org/georss');
- $feed->addNamespace('ostatus', 'http://ostatus.org/schema/1.0');
-
- $taguribase = common_config('integration', 'taguri');
- $feed->setId("tag:{$taguribase}:UserTimeline:{$actor->id}"); // ???
-
- $feed->setTitle($actor->getBestName() . ' timeline'); // @fixme
- $feed->setUpdated(time());
- $feed->setPublished(time());
-
- $feed->addLink(common_local_url('ApiTimelineUser',
- array('id' => $actor->id,
- 'type' => 'atom')),
- array('rel' => 'self',
- 'type' => 'application/atom+xml'));
-
- $feed->addLink(common_local_url('userbyid',
- array('id' => $actor->id)),
- array('rel' => 'alternate',
- 'type' => 'text/html'));
-
- return $feed;
- }
-
/**
* Read and post notices for updates from the feed.
* Currently assumes that all items in the feed are new,
* coming from a PuSH hub.
*
- * @param DOMDocument $feed
+ * @param DOMDocument $doc
+ * @param string $source identifier ("push")
*/
- public function processFeed($feed, $source)
+ public function processFeed(DOMDocument $doc, $source)
{
+ $feed = $doc->documentElement;
+
+ if ($feed->localName != 'feed' || $feed->namespaceURI != Activity::ATOM) {
+ common_log(LOG_ERR, __METHOD__ . ": not an Atom feed, ignoring");
+ return;
+ }
+
$entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
if ($entries->length == 0) {
common_log(LOG_ERR, __METHOD__ . ": no entries in feed update, ignoring");
@@ -538,6 +457,7 @@ class Ostatus_profile extends Memcached_DataObject
*
* @param DOMElement $entry
* @param DOMElement $feed for context
+ * @param string $source identifier ("push" or "salmon")
*/
public function processEntry($entry, $feed, $source)
{
@@ -607,12 +527,40 @@ class Ostatus_profile extends Memcached_DataObject
$rendered = $this->purify($activity->object->content);
$content = html_entity_decode(strip_tags($rendered));
+ $shortened = common_shorten_links($content);
+
+ // If it's too long, try using the summary, and make the
+ // HTML an attachment.
+
+ $attachment = null;
+
+ if (Notice::contentTooLong($shortened)) {
+ $attachment = $this->saveHTMLFile($activity->object->title, $rendered);
+ $summary = $activity->object->summary;
+ if (empty($summary)) {
+ $summary = $content;
+ }
+ $shortSummary = common_shorten_links($summary);
+ if (Notice::contentTooLong($shortSummary)) {
+ $url = common_shorten_url(common_local_url('attachment',
+ array('attachment' => $attachment->id)));
+ $shortSummary = substr($shortSummary,
+ 0,
+ Notice::maxContent() - (mb_strlen($url) + 2));
+ $shortSummary .= '… ' . $url;
+ $content = $shortSummary;
+ $rendered = common_render_text($content);
+ }
+ }
+
$options = array('is_local' => Notice::REMOTE_OMB,
'url' => $sourceUrl,
'uri' => $sourceUri,
'rendered' => $rendered,
'replies' => array(),
- 'groups' => array());
+ 'groups' => array(),
+ 'tags' => array(),
+ 'urls' => array());
// Check for optional attributes...
@@ -647,6 +595,22 @@ class Ostatus_profile extends Memcached_DataObject
}
}
+ // Atom categories <-> hashtags
+ foreach ($activity->categories as $cat) {
+ if ($cat->term) {
+ $term = common_canonical_tag($cat->term);
+ if ($term) {
+ $options['tags'][] = $term;
+ }
+ }
+ }
+
+ // Atom enclosures -> attachment URLs
+ foreach ($activity->enclosures as $href) {
+ // @fixme save these locally or....?
+ $options['urls'][] = $href;
+ }
+
try {
$saved = Notice::saveNew($oprofile->profile_id,
$content,
@@ -654,6 +618,9 @@ class Ostatus_profile extends Memcached_DataObject
$options);
if ($saved) {
Ostatus_source::saveNew($saved, $this, $method);
+ if (!empty($attachment)) {
+ File_to_post::processNew($attachment->id, $saved->id);
+ }
}
} catch (Exception $e) {
common_log(LOG_ERR, "OStatus save of remote message $sourceUri failed: " . $e->getMessage());
@@ -669,7 +636,8 @@ class Ostatus_profile extends Memcached_DataObject
protected function purify($html)
{
require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
- $config = array('safe' => 1);
+ $config = array('safe' => 1,
+ 'deny_attribute' => 'id,style,on*');
return htmLawed($html, $config);
}
@@ -747,11 +715,18 @@ class Ostatus_profile extends Memcached_DataObject
{
// Get the canonical feed URI and check it
$discover = new FeedDiscovery();
- $feeduri = $discover->discoverFromURL($profile_uri);
+ if (isset($hints['feedurl'])) {
+ $feeduri = $hints['feedurl'];
+ $feeduri = $discover->discoverFromFeedURL($feeduri);
+ } else {
+ $feeduri = $discover->discoverFromURL($profile_uri);
+ $hints['feedurl'] = $feeduri;
+ }
- //$feedsub = FeedSub::ensureFeed($feeduri, $discover->feed);
$huburi = $discover->getAtomLink('hub');
- $salmonuri = $discover->getAtomLink('salmon');
+ $hints['hub'] = $huburi;
+ $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
+ $hints['salmon'] = $salmonuri;
if (!$huburi) {
// We can only deal with folks with a PuSH hub
@@ -766,7 +741,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($subject)) {
$subjObject = new ActivityObject($subject);
- return self::ensureActivityObjectProfile($subjObject, $feeduri, $salmonuri, $hints);
+ return self::ensureActivityObjectProfile($subjObject, $hints);
}
// Otherwise, try the feed author
@@ -775,7 +750,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($author)) {
$authorObject = new ActivityObject($author);
- return self::ensureActivityObjectProfile($authorObject, $feeduri, $salmonuri, $hints);
+ return self::ensureActivityObjectProfile($authorObject, $hints);
}
// Sheesh. Not a very nice feed! Let's try fingerpoken in the
@@ -791,7 +766,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($actor)) {
$actorObject = new ActivityObject($actor);
- return self::ensureActivityObjectProfile($actorObject, $feeduri, $salmonuri, $hints);
+ return self::ensureActivityObjectProfile($actorObject, $hints);
}
@@ -799,7 +774,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($author)) {
$authorObject = new ActivityObject($author);
- return self::ensureActivityObjectProfile($authorObject, $feeduri, $salmonuri, $hints);
+ return self::ensureActivityObjectProfile($authorObject, $hints);
}
}
@@ -868,8 +843,20 @@ class Ostatus_profile extends Memcached_DataObject
protected static function getActivityObjectAvatar($object, $hints=array())
{
- if ($object->avatar) {
- return $object->avatar;
+ if ($object->avatarLinks) {
+ $best = false;
+ // Take the exact-size avatar, or the largest avatar, or the first avatar if all sizeless
+ foreach ($object->avatarLinks as $avatar) {
+ if ($avatar->width == AVATAR_PROFILE_SIZE && $avatar->height = AVATAR_PROFILE_SIZE) {
+ // Exact match!
+ $best = $avatar;
+ break;
+ }
+ if (!$best || $avatar->width > $best->width) {
+ $best = $avatar;
+ }
+ }
+ return $best->url;
} else if (array_key_exists('avatar', $hints)) {
return $hints['avatar'];
}
@@ -932,18 +919,18 @@ class Ostatus_profile extends Memcached_DataObject
* @return Ostatus_profile
*/
- public static function ensureActorProfile($activity, $feeduri=null, $salmonuri=null)
+ public static function ensureActorProfile($activity, $hints=array())
{
- return self::ensureActivityObjectProfile($activity->actor, $feeduri, $salmonuri);
+ return self::ensureActivityObjectProfile($activity->actor, $hints);
}
- public static function ensureActivityObjectProfile($object, $feeduri=null, $salmonuri=null, $hints=array())
+ public static function ensureActivityObjectProfile($object, $hints=array())
{
$profile = self::getActivityObjectProfile($object);
if ($profile) {
$profile->updateFromActivityObject($object, $hints);
} else {
- $profile = self::createActivityObjectProfile($object, $feeduri, $salmonuri, $hints);
+ $profile = self::createActivityObjectProfile($object, $hints);
}
return $profile;
}
@@ -989,58 +976,55 @@ class Ostatus_profile extends Memcached_DataObject
* @fixme validate stuff somewhere
*/
- protected static function createActorProfile($activity, $feeduri=null, $salmonuri=null)
- {
- $actor = $activity->actor;
-
- self::createActivityObjectProfile($actor, $feeduri, $salmonuri);
- }
-
/**
* Create local ostatus_profile and profile/user_group entries for
* the provided remote user or group.
*
* @param ActivityObject $object
- * @param string $feeduri
- * @param string $salmonuri
* @param array $hints
*
- * @fixme fold $feeduri/$salmonuri into $hints
* @return Ostatus_profile
*/
- protected static function createActivityObjectProfile($object, $feeduri=null, $salmonuri=null, $hints=array())
+ protected static function createActivityObjectProfile($object, $hints=array())
{
- $homeuri = $object->id;
+ $homeuri = $object->id;
+ $discover = false;
if (!$homeuri) {
common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true));
throw new ServerException("No profile URI");
}
- if (empty($feeduri)) {
- if (array_key_exists('feedurl', $hints)) {
- $feeduri = $hints['feedurl'];
- }
+ if (array_key_exists('feedurl', $hints)) {
+ $feeduri = $hints['feedurl'];
+ } else {
+ $discover = new FeedDiscovery();
+ $feeduri = $discover->discoverFromURL($homeuri);
}
- if (empty($salmonuri)) {
- if (array_key_exists('salmon', $hints)) {
- $salmonuri = $hints['salmon'];
+ if (array_key_exists('salmon', $hints)) {
+ $salmonuri = $hints['salmon'];
+ } else {
+ if (!$discover) {
+ $discover = new FeedDiscovery();
+ $discover->discoverFromFeedURL($hints['feedurl']);
}
+ $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
}
- if (!$feeduri || !$salmonuri) {
- // Get the canonical feed URI and check it
- $discover = new FeedDiscovery();
- $feeduri = $discover->discoverFromURL($homeuri);
-
+ if (array_key_exists('hub', $hints)) {
+ $huburi = $hints['hub'];
+ } else {
+ if (!$discover) {
+ $discover = new FeedDiscovery();
+ $discover->discoverFromFeedURL($hints['feedurl']);
+ }
$huburi = $discover->getAtomLink('hub');
- $salmonuri = $discover->getAtomLink('salmon');
+ }
- if (!$huburi) {
- // We can only deal with folks with a PuSH hub
- throw new FeedSubNoHubException();
- }
+ if (!$huburi) {
+ // We can only deal with folks with a PuSH hub
+ throw new FeedSubNoHubException();
}
$oprofile = new Ostatus_profile();
@@ -1054,8 +1038,8 @@ class Ostatus_profile extends Memcached_DataObject
if ($object->type == ActivityObject::PERSON) {
$profile = new Profile();
+ $profile->created = common_sql_now();
self::updateProfile($profile, $object, $hints);
- $profile->created = common_sql_now();
$oprofile->profile_id = $profile->insert();
if (!$oprofile->profile_id) {
@@ -1063,6 +1047,7 @@ class Ostatus_profile extends Memcached_DataObject
}
} else {
$group = new User_group();
+ $group->uri = $homeuri;
$group->created = common_sql_now();
self::updateGroup($group, $object, $hints);
@@ -1110,18 +1095,35 @@ class Ostatus_profile extends Memcached_DataObject
$orig = clone($profile);
$profile->nickname = self::getActivityObjectNickname($object, $hints);
- $profile->fullname = $object->title;
+
+ if (!empty($object->title)) {
+ $profile->fullname = $object->title;
+ } else if (array_key_exists('fullname', $hints)) {
+ $profile->fullname = $hints['fullname'];
+ }
+
if (!empty($object->link)) {
$profile->profileurl = $object->link;
} else if (array_key_exists('profileurl', $hints)) {
$profile->profileurl = $hints['profileurl'];
+ } else if (Validate::uri($object->id, array('allowed_schemes' => array('http', 'https')))) {
+ $profile->profileurl = $object->id;
+ }
+
+ $profile->bio = self::getActivityObjectBio($object, $hints);
+ $profile->location = self::getActivityObjectLocation($object, $hints);
+ $profile->homepage = self::getActivityObjectHomepage($object, $hints);
+
+ if (!empty($object->geopoint)) {
+ $location = ActivityContext::locationFromPoint($object->geopoint);
+ if (!empty($location)) {
+ $profile->lat = $location->lat;
+ $profile->lon = $location->lon;
+ }
}
- // @fixme bio
// @fixme tags/categories
- // @fixme location?
// @todo tags from categories
- // @todo lat/lon/location?
if ($profile->id) {
common_log(LOG_DEBUG, "Updating OStatus profile $profile->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
@@ -1133,19 +1135,19 @@ class Ostatus_profile extends Memcached_DataObject
{
$orig = clone($group);
- // @fixme need to make nick unique etc *hack hack*
$group->nickname = self::getActivityObjectNickname($object, $hints);
$group->fullname = $object->title;
- // @fixme no canonical profileurl; using homepage instead for now
- $group->homepage = $object->id;
+ if (!empty($object->link)) {
+ $group->mainpage = $object->link;
+ } else if (array_key_exists('profileurl', $hints)) {
+ $group->mainpage = $hints['profileurl'];
+ }
- // @fixme homepage
- // @fixme bio
- // @fixme tags/categories
- // @fixme location?
// @todo tags from categories
- // @todo lat/lon/location?
+ $group->description = self::getActivityObjectBio($object, $hints);
+ $group->location = self::getActivityObjectLocation($object, $hints);
+ $group->homepage = self::getActivityObjectHomepage($object, $hints);
if ($group->id) {
common_log(LOG_DEBUG, "Updating OStatus group $group->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
@@ -1153,6 +1155,69 @@ class Ostatus_profile extends Memcached_DataObject
}
}
+ protected static function getActivityObjectHomepage($object, $hints=array())
+ {
+ $homepage = null;
+ $poco = $object->poco;
+
+ if (!empty($poco)) {
+ $url = $poco->getPrimaryURL();
+ if ($url && $url->type == 'homepage') {
+ $homepage = $url->value;
+ }
+ }
+
+ // @todo Try for a another PoCo URL?
+
+ return $homepage;
+ }
+
+ protected static function getActivityObjectLocation($object, $hints=array())
+ {
+ $location = null;
+
+ if (!empty($object->poco) &&
+ isset($object->poco->address->formatted)) {
+ $location = $object->poco->address->formatted;
+ } else if (array_key_exists('location', $hints)) {
+ $location = $hints['location'];
+ }
+
+ if (!empty($location)) {
+ if (mb_strlen($location) > 255) {
+ $location = mb_substr($note, 0, 255 - 3) . ' … ';
+ }
+ }
+
+ // @todo Try to find location some othe way? Via goerss point?
+
+ return $location;
+ }
+
+ protected static function getActivityObjectBio($object, $hints=array())
+ {
+ $bio = null;
+
+ if (!empty($object->poco)) {
+ $note = $object->poco->note;
+ } else if (array_key_exists('bio', $hints)) {
+ $note = $hints['bio'];
+ }
+
+ if (!empty($note)) {
+ if (Profile::bioTooLong($note)) {
+ // XXX: truncate ok?
+ $bio = mb_substr($note, 0, Profile::maxBio() - 3) . ' … ';
+ } else {
+ $bio = $note;
+ }
+ }
+
+ // @todo Try to get bio info some other way?
+
+ return $bio;
+ }
+
protected static function getActivityObjectNickname($object, $hints=array())
{
if ($object->poco) {
@@ -1160,10 +1225,15 @@ class Ostatus_profile extends Memcached_DataObject
return common_nicknamize($object->poco->preferredUsername);
}
}
+
if (!empty($object->nickname)) {
return common_nicknamize($object->nickname);
}
+ if (array_key_exists('nickname', $hints)) {
+ return $hints['nickname'];
+ }
+
// Try the definitive ID
$nickname = self::nicknameFromURI($object->id);
@@ -1206,36 +1276,65 @@ class Ostatus_profile extends Memcached_DataObject
}
}
+ /**
+ * @param string $addr webfinger address
+ * @return Ostatus_profile
+ * @throws Exception on error conditions
+ */
public static function ensureWebfinger($addr)
{
+ // First, try the cache
+
+ $uri = self::cacheGet(sprintf('ostatus_profile:webfinger:%s', $addr));
+
+ if ($uri !== false) {
+ if (is_null($uri)) {
+ // Negative cache entry
+ throw new Exception('Not a valid webfinger address.');
+ }
+ $oprofile = Ostatus_profile::staticGet('uri', $uri);
+ if (!empty($oprofile)) {
+ return $oprofile;
+ }
+ }
+
// First, look it up
$oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr);
if (!empty($oprofile)) {
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
}
// Now, try some discovery
- $wf = new Webfinger();
+ $disco = new Discovery();
- $result = $wf->lookup($addr);
-
- if (!$result) {
- return null;
+ try {
+ $result = $disco->lookup($addr);
+ } catch (Exception $e) {
+ // Save negative cache entry so we don't waste time looking it up again.
+ // @fixme distinguish temporary failures?
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), null);
+ throw new Exception('Not a valid webfinger address.');
}
+ $hints = array('webfinger' => $addr);
+
foreach ($result->links as $link) {
switch ($link['rel']) {
- case Webfinger::PROFILEPAGE:
- $profileUrl = $link['href'];
+ case Discovery::PROFILEPAGE:
+ $hints['profileurl'] = $profileUrl = $link['href'];
break;
- case 'salmon':
- $salmonEndpoint = $link['href'];
+ case Salmon::NS_REPLIES:
+ $hints['salmon'] = $salmonEndpoint = $link['href'];
break;
- case Webfinger::UPDATESFROM:
- $feedUrl = $link['href'];
+ case Discovery::UPDATESFROM:
+ $hints['feedurl'] = $feedUrl = $link['href'];
+ break;
+ case Discovery::HCARD:
+ $hcardUrl = $link['href'];
break;
default:
common_log(LOG_NOTICE, "Don't know what to do with rel = '{$link['rel']}'");
@@ -1243,16 +1342,19 @@ class Ostatus_profile extends Memcached_DataObject
}
}
- $hints = array('webfinger' => $addr,
- 'profileurl' => $profileUrl,
- 'feedurl' => $feedUrl,
- 'salmon' => $salmonEndpoint);
+ if (isset($hcardUrl)) {
+ $hcardHints = self::slurpHcard($hcardUrl);
+ // Note: Webfinger > hcard
+ $hints = array_merge($hcardHints, $hints);
+ }
// If we got a feed URL, try that
if (isset($feedUrl)) {
try {
+ common_log(LOG_INFO, "Discovery on acct:$addr with feed URL $feedUrl");
$oprofile = self::ensureProfile($feedUrl, $hints);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
} catch (Exception $e) {
common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage());
@@ -1264,7 +1366,9 @@ class Ostatus_profile extends Memcached_DataObject
if (isset($profileUrl)) {
try {
+ common_log(LOG_INFO, "Discovery on acct:$addr with profile URL $profileUrl");
$oprofile = self::ensureProfile($profileUrl, $hints);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
} catch (Exception $e) {
common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage());
@@ -1316,9 +1420,106 @@ class Ostatus_profile extends Memcached_DataObject
throw new Exception("Couldn't save ostatus_profile for '$addr'");
}
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
}
- return null;
+ throw new Exception("Couldn't find a valid profile for '$addr'");
+ }
+
+ function saveHTMLFile($title, $rendered)
+ {
+ $final = sprintf("<!DOCTYPE html>\n<html><head><title>%s</title></head>".
+ '<body><div>%s</div></body></html>',
+ htmlspecialchars($title),
+ $rendered);
+
+ $filename = File::filename($this->localProfile(),
+ 'ostatus', // ignored?
+ 'text/html');
+
+ $filepath = File::path($filename);
+
+ file_put_contents($filepath, $final);
+
+ $file = new File;
+
+ $file->filename = $filename;
+ $file->url = File::url($filename);
+ $file->size = filesize($filepath);
+ $file->date = time();
+ $file->mimetype = 'text/html';
+
+ $file_id = $file->insert();
+
+ if ($file_id === false) {
+ common_log_db_error($file, "INSERT", __FILE__);
+ throw new ServerException(_('Could not store HTML content of long post as file.'));
+ }
+
+ return $file;
+ }
+
+ protected static function slurpHcard($url)
+ {
+ set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/plugins/OStatus/extlib/hkit/');
+ require_once('hkit.class.php');
+
+ $h = new hKit;
+
+ // Google Buzz hcards need to be tidied. Probably others too.
+
+ $h->tidy_mode = 'proxy'; // 'proxy', 'exec', 'php' or 'none'
+
+ // Get by URL
+ $hcards = $h->getByURL('hcard', $url);
+
+ if (empty($hcards)) {
+ return array();
+ }
+
+ // @fixme more intelligent guess on multi-hcard pages
+ $hcard = $hcards[0];
+
+ $hints = array();
+
+ $hints['profileurl'] = $url;
+
+ if (array_key_exists('nickname', $hcard)) {
+ $hints['nickname'] = $hcard['nickname'];
+ }
+
+ if (array_key_exists('fn', $hcard)) {
+ $hints['fullname'] = $hcard['fn'];
+ } else if (array_key_exists('n', $hcard)) {
+ $hints['fullname'] = implode(' ', $hcard['n']);
+ }
+
+ if (array_key_exists('photo', $hcard)) {
+ $hints['avatar'] = $hcard['photo'];
+ }
+
+ if (array_key_exists('note', $hcard)) {
+ $hints['bio'] = $hcard['note'];
+ }
+
+ if (array_key_exists('adr', $hcard)) {
+ if (is_string($hcard['adr'])) {
+ $hints['location'] = $hcard['adr'];
+ } else if (is_array($hcard['adr'])) {
+ $hints['location'] = implode(' ', $hcard['adr']);
+ }
+ }
+
+ if (array_key_exists('url', $hcard)) {
+ if (is_string($hcard['url'])) {
+ $hints['homepage'] = $hcard['url'];
+ } else if (is_array($hcard['url'])) {
+ // HACK get the last one; that's how our hcards look
+ $hints['homepage'] = $hcard['url'][count($hcard['url'])-1];
+ }
+ }
+
+ return $hints;
}
}
diff --git a/plugins/OStatus/extlib/hkit/hcard.profile.php b/plugins/OStatus/extlib/hkit/hcard.profile.php
new file mode 100644
index 000000000..6ec0dc890
--- /dev/null
+++ b/plugins/OStatus/extlib/hkit/hcard.profile.php
@@ -0,0 +1,105 @@
+<?php
+ // hcard profile for hkit
+
+ $this->root_class = 'vcard';
+
+ $this->classes = array(
+ 'fn', array('honorific-prefix', 'given-name', 'additional-name', 'family-name', 'honorific-suffix'),
+ 'n', array('honorific-prefix', 'given-name', 'additional-name', 'family-name', 'honorific-suffix'),
+ 'adr', array('post-office-box', 'extended-address', 'street-address', 'postal-code', 'country-name', 'type', 'region', 'locality'),
+ 'label', 'bday', 'agent', 'nickname', 'photo', 'class',
+ 'email', array('type', 'value'),
+ 'category', 'key', 'logo', 'mailer', 'note',
+ 'org', array('organization-name', 'organization-unit'),
+ 'tel', array('type', 'value'),
+ 'geo', array('latitude', 'longitude'),
+ 'tz', 'uid', 'url', 'rev', 'role', 'sort-string', 'sound', 'title'
+ );
+
+ // classes that must only appear once per card
+ $this->singles = array(
+ 'fn'
+ );
+
+ // classes that are required (not strictly enforced - give at least one!)
+ $this->required = array(
+ 'fn'
+ );
+
+ $this->att_map = array(
+ 'fn' => array('IMG|alt'),
+ 'url' => array('A|href', 'IMG|src', 'AREA|href'),
+ 'photo' => array('IMG|src'),
+ 'bday' => array('ABBR|title'),
+ 'logo' => array('IMG|src'),
+ 'email' => array('A|href'),
+ 'geo' => array('ABBR|title')
+ );
+
+
+ $this->callbacks = array(
+ 'url' => array($this, 'resolvePath'),
+ 'photo' => array($this, 'resolvePath'),
+ 'logo' => array($this, 'resolvePath'),
+ 'email' => array($this, 'resolveEmail')
+ );
+
+
+
+ function hKit_hcard_post($a)
+ {
+
+ foreach ($a as &$vcard){
+
+ hKit_implied_n_optimization($vcard);
+ hKit_implied_n_from_fn($vcard);
+
+ }
+
+ return $a;
+
+ }
+
+
+ function hKit_implied_n_optimization(&$vcard)
+ {
+ if (array_key_exists('fn', $vcard) && !is_array($vcard['fn']) &&
+ !array_key_exists('n', $vcard) && (!array_key_exists('org', $vcard) || $vcard['fn'] != $vcard['org'])){
+
+ if (sizeof(explode(' ', $vcard['fn'])) == 2){
+ $patterns = array();
+ $patterns[] = array('/^(\S+),\s*(\S{1})$/', 2, 1); // Lastname, Initial
+ $patterns[] = array('/^(\S+)\s*(\S{1})\.*$/', 2, 1); // Lastname Initial(.)
+ $patterns[] = array('/^(\S+),\s*(\S+)$/', 2, 1); // Lastname, Firstname
+ $patterns[] = array('/^(\S+)\s*(\S+)$/', 1, 2); // Firstname Lastname
+
+ foreach ($patterns as $pattern){
+ if (preg_match($pattern[0], $vcard['fn'], $matches) === 1){
+ $n = array();
+ $n['given-name'] = $matches[$pattern[1]];
+ $n['family-name'] = $matches[$pattern[2]];
+ $vcard['n'] = $n;
+
+
+ break;
+ }
+ }
+ }
+ }
+ }
+
+
+ function hKit_implied_n_from_fn(&$vcard)
+ {
+ if (array_key_exists('fn', $vcard) && is_array($vcard['fn'])
+ && !array_key_exists('n', $vcard) && (!array_key_exists('org', $vcard) || $vcard['fn'] != $vcard['org'])){
+
+ $vcard['n'] = $vcard['fn'];
+ }
+
+ if (array_key_exists('fn', $vcard) && is_array($vcard['fn'])){
+ $vcard['fn'] = $vcard['fn']['text'];
+ }
+ }
+
+?> \ No newline at end of file
diff --git a/plugins/OStatus/extlib/hkit/hkit.class.php b/plugins/OStatus/extlib/hkit/hkit.class.php
new file mode 100644
index 000000000..c3a54cff6
--- /dev/null
+++ b/plugins/OStatus/extlib/hkit/hkit.class.php
@@ -0,0 +1,475 @@
+<?php
+
+ /*
+
+ hKit Library for PHP5 - a generic library for parsing Microformats
+ Copyright (C) 2006 Drew McLellan
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Author
+ Drew McLellan - http://allinthehead.com/
+
+ Contributors:
+ Scott Reynen - http://www.randomchaos.com/
+
+ Version 0.5, 22-Jul-2006
+ fixed by-ref issue cropping up in PHP 5.0.5
+ fixed a bug with a@title
+ added support for new fn=n optimisation
+ added support for new a.include include-pattern
+ Version 0.4, 23-Jun-2006
+ prevented nested includes from causing infinite loops
+ returns false if URL can't be fetched
+ added pre-flight check for base support level
+ added deduping of once-only classnames
+ prevented accumulation of multiple 'value' values
+ tuned whitespace handling and treatment of DEL elements
+ Version 0.3, 21-Jun-2006
+ added post-processor callback method into profiles
+ fixed minor problems raised by hcard testsuite
+ added support for include-pattern
+ added support for td@headers pattern
+ added implied-n optimization into default hcard profile
+ Version 0.2, 20-Jun-2006
+ added class callback mechanism
+ added resolvePath & resolveEmail
+ added basic BASE support
+ Version 0.1.1, 19-Jun-2006 (different timezone, no time machine)
+ added external Tidy option
+ Version 0.1, 20-Jun-2006
+ initial release
+
+
+
+
+ */
+
+ class hKit
+ {
+
+ public $tidy_mode = 'proxy'; // 'proxy', 'exec', 'php' or 'none'
+ public $tidy_proxy = 'http://cgi.w3.org/cgi-bin/tidy?forceXML=on&docAddr='; // required only for tidy_mode=proxy
+ public $tmp_dir = '/path/to/writable/dir/'; // required only for tidy_mode=exec
+
+ private $root_class = '';
+ private $classes = '';
+ private $singles = '';
+ private $required = '';
+ private $att_map = '';
+ private $callbacks = '';
+ private $processor = '';
+
+ private $url = '';
+ private $base = '';
+ private $doc = '';
+
+
+ public function hKit()
+ {
+ // pre-flight checks
+ $pass = true;
+ $required = array('dom_import_simplexml', 'file_get_contents', 'simplexml_load_string');
+ $missing = array();
+
+ foreach ($required as $f){
+ if (!function_exists($f)){
+ $pass = false;
+ $missing[] = $f . '()';
+ }
+ }
+
+ if (!$pass)
+ die('hKit error: these required functions are not available: <strong>' . implode(', ', $missing) . '</strong>');
+
+ }
+
+
+ public function getByURL($profile='', $url='')
+ {
+
+ if ($profile=='' || $url == '') return false;
+
+ $this->loadProfile($profile);
+
+ $source = $this->loadURL($url);
+
+ if ($source){
+ $tidy_xhtml = $this->tidyThis($source);
+
+ $fragment = false;
+
+ if (strrchr($url, '#'))
+ $fragment = array_pop(explode('#', $url));
+
+ $doc = $this->loadDoc($tidy_xhtml, $fragment);
+ $s = $this->processNodes($doc, $this->classes);
+ $s = $this->postProcess($profile, $s);
+
+ return $s;
+ }else{
+ return false;
+ }
+ }
+
+ public function getByString($profile='', $input_xml='')
+ {
+ if ($profile=='' || $input_xml == '') return false;
+
+ $this->loadProfile($profile);
+
+ $doc = $this->loadDoc($input_xml);
+ $s = $this->processNodes($doc, $this->classes);
+ $s = $this->postProcess($profile, $s);
+
+ return $s;
+
+ }
+
+ private function processNodes($items, $classes, $allow_includes=true){
+
+ $out = array();
+
+ foreach($items as $item){
+ $data = array();
+
+ for ($i=0; $i<sizeof($classes); $i++){
+
+ if (!is_array($classes[$i])){
+
+ $xpath = ".//*[contains(concat(' ',normalize-space(@class),' '),' " . $classes[$i] . " ')]";
+ $results = $item->xpath($xpath);
+
+ if ($results){
+ foreach ($results as $result){
+ if (isset($classes[$i+1]) && is_array($classes[$i+1])){
+ $nodes = $this->processNodes($results, $classes[$i+1]);
+ if (sizeof($nodes) > 0){
+ $nodes = array_merge(array('text'=>$this->getNodeValue($result, $classes[$i])), $nodes);
+ $data[$classes[$i]] = $nodes;
+ }else{
+ $data[$classes[$i]] = $this->getNodeValue($result, $classes[$i]);
+ }
+
+ }else{
+ if (isset($data[$classes[$i]])){
+ if (is_array($data[$classes[$i]])){
+ // is already an array - append
+ $data[$classes[$i]][] = $this->getNodeValue($result, $classes[$i]);
+
+ }else{
+ // make it an array
+ if ($classes[$i] == 'value'){ // unless it's the 'value' of a type/value pattern
+ $data[$classes[$i]] .= $this->getNodeValue($result, $classes[$i]);
+ }else{
+ $old_val = $data[$classes[$i]];
+ $data[$classes[$i]] = array($old_val, $this->getNodeValue($result, $classes[$i]));
+ $old_val = false;
+ }
+ }
+ }else{
+ // set as normal value
+ $data[$classes[$i]] = $this->getNodeValue($result, $classes[$i]);
+
+ }
+ }
+
+ // td@headers pattern
+ if (strtoupper(dom_import_simplexml($result)->tagName)== "TD" && $result['headers']){
+ $include_ids = explode(' ', $result['headers']);
+ $doc = $this->doc;
+ foreach ($include_ids as $id){
+ $xpath = "//*[@id='$id']/..";
+ $includes = $doc->xpath($xpath);
+ foreach ($includes as $include){
+ $tmp = $this->processNodes($include, $this->classes);
+ if (is_array($tmp)) $data = array_merge($data, $tmp);
+ }
+ }
+ }
+ }
+ }
+ }
+ $result = false;
+ }
+
+ // include-pattern
+ if ($allow_includes){
+ $xpath = ".//*[contains(concat(' ',normalize-space(@class),' '),' include ')]";
+ $results = $item->xpath($xpath);
+
+ if ($results){
+ foreach ($results as $result){
+ $tagName = strtoupper(dom_import_simplexml($result)->tagName);
+ if ((($tagName == "OBJECT" && $result['data']) || ($tagName == "A" && $result['href']))
+ && preg_match('/\binclude\b/', $result['class'])){
+ $att = ($tagName == "OBJECT" ? 'data' : 'href');
+ $id = str_replace('#', '', $result[$att]);
+ $doc = $this->doc;
+ $xpath = "//*[@id='$id']";
+ $includes = $doc->xpath($xpath);
+ foreach ($includes as $include){
+ $include = simplexml_load_string('<root1><root2>'.$include->asXML().'</root2></root1>'); // don't ask.
+ $tmp = $this->processNodes($include, $this->classes, false);
+ if (is_array($tmp)) $data = array_merge($data, $tmp);
+ }
+ }
+ }
+ }
+ }
+ $out[] = $data;
+ }
+
+ if (sizeof($out) > 1){
+ return $out;
+ }else if (isset($data)){
+ return $data;
+ }else{
+ return array();
+ }
+ }
+
+
+ private function getNodeValue($node, $className)
+ {
+
+ $tag_name = strtoupper(dom_import_simplexml($node)->tagName);
+ $s = false;
+
+ // ignore DEL tags
+ if ($tag_name == 'DEL') return $s;
+
+ // look up att map values
+ if (array_key_exists($className, $this->att_map)){
+
+ foreach ($this->att_map[$className] as $map){
+ if (preg_match("/$tag_name\|/", $map)){
+ $s = ''.$node[array_pop($foo = explode('|', $map))];
+ }
+ }
+ }
+
+ // if nothing and OBJ, try data.
+ if (!$s && $tag_name=='OBJECT' && $node['data']) $s = ''.$node['data'];
+
+ // if nothing and IMG, try alt.
+ if (!$s && $tag_name=='IMG' && $node['alt']) $s = ''.$node['alt'];
+
+ // if nothing and AREA, try alt.
+ if (!$s && $tag_name=='AREA' && $node['alt']) $s = ''.$node['alt'];
+
+ //if nothing and not A, try title.
+ if (!$s && $tag_name!='A' && $node['title']) $s = ''.$node['title'];
+
+
+ // if nothing found, go with node text
+ $s = ($s ? $s : implode(array_filter($node->xpath('child::node()'), array(&$this, "filterBlankValues")), ' '));
+
+ // callbacks
+ if (array_key_exists($className, $this->callbacks)){
+ $s = preg_replace_callback('/.*/', $this->callbacks[$className], $s, 1);
+ }
+
+ // trim and remove line breaks
+ if ($tag_name != 'PRE'){
+ $s = trim(preg_replace('/[\r\n\t]+/', '', $s));
+ $s = trim(preg_replace('/(\s{2})+/', ' ', $s));
+ }
+
+ return $s;
+ }
+
+ private function filterBlankValues($s){
+ return preg_match("/\w+/", $s);
+ }
+
+
+ private function tidyThis($source)
+ {
+ switch ( $this->tidy_mode )
+ {
+ case 'exec':
+ $tmp_file = $this->tmp_dir.md5($source).'.txt';
+ file_put_contents($tmp_file, $source);
+ exec("tidy -utf8 -indent -asxhtml -numeric -bare -quiet $tmp_file", $tidy);
+ unlink($tmp_file);
+ return implode("\n", $tidy);
+ break;
+
+ case 'php':
+ $tidy = tidy_parse_string($source);
+ return tidy_clean_repair($tidy);
+ break;
+
+ default:
+ return $source;
+ break;
+ }
+
+ }
+
+
+ private function loadProfile($profile)
+ {
+ require_once("$profile.profile.php");
+ }
+
+
+ private function loadDoc($input_xml, $fragment=false)
+ {
+ $xml = simplexml_load_string($input_xml);
+
+ $this->doc = $xml;
+
+ if ($fragment){
+ $doc = $xml->xpath("//*[@id='$fragment']");
+ $xml = simplexml_load_string($doc[0]->asXML());
+ $doc = null;
+ }
+
+ // base tag
+ if ($xml->head->base['href']) $this->base = $xml->head->base['href'];
+
+ // xml:base attribute - PITA with SimpleXML
+ preg_match('/xml:base="(.*)"/', $xml->asXML(), $matches);
+ if (is_array($matches) && sizeof($matches)>1) $this->base = $matches[1];
+
+ return $xml->xpath("//*[contains(concat(' ',normalize-space(@class),' '),' $this->root_class ')]");
+
+ }
+
+
+ private function loadURL($url)
+ {
+ $this->url = $url;
+
+ if ($this->tidy_mode == 'proxy' && $this->tidy_proxy != ''){
+ $url = $this->tidy_proxy . $url;
+ }
+
+ return @file_get_contents($url);
+
+ }
+
+
+ private function postProcess($profile, $s)
+ {
+ $required = $this->required;
+
+ if (is_array($s) && array_key_exists($required[0], $s)){
+ $s = array($s);
+ }
+
+ $s = $this->dedupeSingles($s);
+
+ if (function_exists('hKit_'.$profile.'_post')){
+ $s = call_user_func('hKit_'.$profile.'_post', $s);
+ }
+
+ $s = $this->removeTextVals($s);
+
+ return $s;
+ }
+
+
+ private function resolvePath($filepath)
+ { // ugly code ahoy: needs a serious tidy up
+
+ $filepath = $filepath[0];
+
+ $base = $this->base;
+ $url = $this->url;
+
+ if ($base != '' && strpos($base, '://') !== false)
+ $url = $base;
+
+ $r = parse_url($url);
+ $domain = $r['scheme'] . '://' . $r['host'];
+
+ if (!isset($r['path'])) $r['path'] = '/';
+ $path = explode('/', $r['path']);
+ $file = explode('/', $filepath);
+ $new = array('');
+
+ if (strpos($filepath, '://') !== false || strpos($filepath, 'data:') !== false){
+ return $filepath;
+ }
+
+ if ($file[0] == ''){
+ // absolute path
+ return ''.$domain . implode('/', $file);
+ }else{
+ // relative path
+ if ($path[sizeof($path)-1] == '') array_pop($path);
+ if (strpos($path[sizeof($path)-1], '.') !== false) array_pop($path);
+
+ foreach ($file as $segment){
+ if ($segment == '..'){
+ array_pop($path);
+ }else{
+ $new[] = $segment;
+ }
+ }
+ return ''.$domain . implode('/', $path) . implode('/', $new);
+ }
+ }
+
+ private function resolveEmail($v)
+ {
+ $parts = parse_url($v[0]);
+ return ($parts['path']);
+ }
+
+
+ private function dedupeSingles($s)
+ {
+ $singles = $this->singles;
+
+ foreach ($s as &$item){
+ foreach ($singles as $classname){
+ if (array_key_exists($classname, $item) && is_array($item[$classname])){
+ if (isset($item[$classname][0])) $item[$classname] = $item[$classname][0];
+ }
+ }
+ }
+
+ return $s;
+ }
+
+ private function removeTextVals($s)
+ {
+ foreach ($s as $key => &$val){
+ if ($key){
+ $k = $key;
+ }else{
+ $k = '';
+ }
+
+ if (is_array($val)){
+ $val = $this->removeTextVals($val);
+ }else{
+ if ($k == 'text'){
+ $val = '';
+ }
+ }
+ }
+
+ return array_filter($s);
+ }
+
+ }
+
+
+?> \ No newline at end of file
diff --git a/plugins/OStatus/lib/discovery.php b/plugins/OStatus/lib/discovery.php
new file mode 100644
index 000000000..f8449b309
--- /dev/null
+++ b/plugins/OStatus/lib/discovery.php
@@ -0,0 +1,310 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * A sample module to show best practices for StatusNet plugins
+ *
+ * PHP version 5
+ *
+ * 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 StatusNet
+ * @author James Walker <james@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+/**
+ * This class implements LRDD-based service discovery based on the "Hammer Draft"
+ * (including webfinger)
+ *
+ * @see http://groups.google.com/group/webfinger/browse_thread/thread/9f3d93a479e91bbf
+ */
+class Discovery
+{
+
+ const LRDD_REL = 'lrdd';
+ const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
+ const UPDATESFROM = 'http://schemas.google.com/g/2010#updates-from';
+ const HCARD = 'http://microformats.org/profile/hcard';
+
+ public $methods = array();
+
+ public function __construct()
+ {
+ $this->registerMethod('Discovery_LRDD_Host_Meta');
+ $this->registerMethod('Discovery_LRDD_Link_Header');
+ $this->registerMethod('Discovery_LRDD_Link_HTML');
+ }
+
+
+ public function registerMethod($class)
+ {
+ $this->methods[] = $class;
+ }
+
+ /**
+ * Given a "user id" make sure it's normalized to either a webfinger
+ * acct: uri or a profile HTTP URL.
+ */
+ public static function normalize($user_id)
+ {
+ if (substr($user_id, 0, 5) == 'http:' ||
+ substr($user_id, 0, 6) == 'https:' ||
+ substr($user_id, 0, 5) == 'acct:') {
+ return $user_id;
+ }
+
+ if (strpos($user_id, '@') !== FALSE) {
+ return 'acct:' . $user_id;
+ }
+
+ return 'http://' . $user_id;
+ }
+
+ public static function isWebfinger($user_id)
+ {
+ $uri = Discovery::normalize($user_id);
+
+ return (substr($uri, 0, 5) == 'acct:');
+ }
+
+ /**
+ * This implements the actual lookup procedure
+ */
+ public function lookup($id)
+ {
+ // Normalize the incoming $id to make sure we have a uri
+ $uri = $this->normalize($id);
+
+ foreach ($this->methods as $class) {
+ $links = call_user_func(array($class, 'discover'), $uri);
+ if ($link = Discovery::getService($links, Discovery::LRDD_REL)) {
+ // Load the LRDD XRD
+ if (!empty($link['template'])) {
+ $xrd_uri = Discovery::applyTemplate($link['template'], $uri);
+ } else {
+ $xrd_uri = $link['href'];
+ }
+
+ $xrd = $this->fetchXrd($xrd_uri);
+ if ($xrd) {
+ return $xrd;
+ }
+ }
+ }
+
+ throw new Exception('Unable to find services for '. $id);
+ }
+
+ public static function getService($links, $service) {
+ if (!is_array($links)) {
+ return false;
+ }
+
+ foreach ($links as $link) {
+ if ($link['rel'] == $service) {
+ return $link;
+ }
+ }
+ }
+
+
+ public static function applyTemplate($template, $id)
+ {
+ $template = str_replace('{uri}', urlencode($id), $template);
+
+ return $template;
+ }
+
+
+ public static function fetchXrd($url)
+ {
+ try {
+ $client = new HTTPClient();
+ $response = $client->get($url);
+ } catch (HTTP_Request2_Exception $e) {
+ return false;
+ }
+
+ if ($response->getStatus() != 200) {
+ return false;
+ }
+
+ return XRD::parse($response->getBody());
+ }
+}
+
+interface Discovery_LRDD
+{
+ public function discover($uri);
+}
+
+class Discovery_LRDD_Host_Meta implements Discovery_LRDD
+{
+ public function discover($uri)
+ {
+ if (!Discovery::isWebfinger($uri)) {
+ return false;
+ }
+
+ // We have a webfinger acct: - start with host-meta
+ list($name, $domain) = explode('@', $uri);
+ $url = 'http://'. $domain .'/.well-known/host-meta';
+
+ $xrd = Discovery::fetchXrd($url);
+
+ if ($xrd) {
+ if ($xrd->host != $domain) {
+ return false;
+ }
+
+ return $xrd->links;
+ }
+ }
+}
+
+class Discovery_LRDD_Link_Header implements Discovery_LRDD
+{
+ public function discover($uri)
+ {
+ try {
+ $client = new HTTPClient();
+ $response = $client->get($uri);
+ } catch (HTTP_Request2_Exception $e) {
+ return false;
+ }
+
+ if ($response->getStatus() != 200) {
+ return false;
+ }
+
+ $link_header = $response->getHeader('Link');
+ if (!$link_header) {
+ // return false;
+ }
+
+ return Discovery_LRDD_Link_Header::parseHeader($link_header);
+ }
+
+ protected static function parseHeader($header)
+ {
+ preg_match('/^<[^>]+>/', $header, $uri_reference);
+ //if (empty($uri_reference)) return;
+
+ $links = array();
+
+ $link_uri = trim($uri_reference[0], '<>');
+ $link_rel = array();
+ $link_type = null;
+
+ // remove uri-reference from header
+ $header = substr($header, strlen($uri_reference[0]));
+
+ // parse link-params
+ $params = explode(';', $header);
+
+ foreach ($params as $param) {
+ if (empty($param)) continue;
+ list($param_name, $param_value) = explode('=', $param, 2);
+ $param_name = trim($param_name);
+ $param_value = preg_replace('(^"|"$)', '', trim($param_value));
+
+ // for now we only care about 'rel' and 'type' link params
+ // TODO do something with the other links-params
+ switch ($param_name) {
+ case 'rel':
+ $link_rel = trim($param_value);
+ break;
+
+ case 'type':
+ $link_type = trim($param_value);
+ }
+ }
+
+ $links[] = array(
+ 'href' => $link_uri,
+ 'rel' => $link_rel,
+ 'type' => $link_type);
+
+ return $links;
+ }
+}
+
+class Discovery_LRDD_Link_HTML implements Discovery_LRDD
+{
+ public function discover($uri)
+ {
+ try {
+ $client = new HTTPClient();
+ $response = $client->get($uri);
+ } catch (HTTP_Request2_Exception $e) {
+ return false;
+ }
+
+ if ($response->getStatus() != 200) {
+ return false;
+ }
+
+ return Discovery_LRDD_Link_HTML::parse($response->getBody());
+ }
+
+
+ public function parse($html)
+ {
+ $links = array();
+
+ preg_match('/<head(\s[^>]*)?>(.*?)<\/head>/is', $html, $head_matches);
+ $head_html = $head_matches[2];
+
+ preg_match_all('/<link\s[^>]*>/i', $head_html, $link_matches);
+
+ foreach ($link_matches[0] as $link_html) {
+ $link_url = null;
+ $link_rel = null;
+ $link_type = null;
+
+ preg_match('/\srel=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $rel_matches);
+ if ( isset($rel_matches[3]) ) {
+ $link_rel = $rel_matches[3];
+ } else if ( isset($rel_matches[1]) ) {
+ $link_rel = $rel_matches[1];
+ }
+
+ preg_match('/\shref=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $href_matches);
+ if ( isset($href_matches[3]) ) {
+ $link_uri = $href_matches[3];
+ } else if ( isset($href_matches[1]) ) {
+ $link_uri = $href_matches[1];
+ }
+
+ preg_match('/\stype=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $type_matches);
+ if ( isset($type_matches[3]) ) {
+ $link_type = $type_matches[3];
+ } else if ( isset($type_matches[1]) ) {
+ $link_type = $type_matches[1];
+ }
+
+ $links[] = array(
+ 'href' => $link_url,
+ 'rel' => $link_rel,
+ 'type' => $link_type,
+ );
+ }
+
+ return $links;
+ }
+}
diff --git a/plugins/OStatus/lib/magicenvelope.php b/plugins/OStatus/lib/magicenvelope.php
index 81f4609c5..fb8c57c71 100644
--- a/plugins/OStatus/lib/magicenvelope.php
+++ b/plugins/OStatus/lib/magicenvelope.php
@@ -50,19 +50,26 @@ class MagicEnvelope
public function getKeyPair($signer_uri)
{
- return 'RSA.79_L2gq-TD72Nsb5yGS0r9stLLpJZF5AHXyxzWmQmlqKl276LEJEs8CppcerLcR90MbYQUwt-SX9slx40Yq3vA==.AQAB.AR-jo5KMfSISmDAT2iMs2_vNFgWRjl5rbJVvA0SpGIEWyPdCGxlPtCbTexp8-0ZEIe8a4SyjatBECH5hxgMTpw==';
- }
-
-
- public function signMessage($text, $mimetype, $signer_uri)
- {
- $signer_uri = $this->normalizeUser($signer_uri);
+ $disco = new Discovery();
- if (!$this->checkAuthor($text, $signer_uri)) {
+ try {
+ $xrd = $disco->lookup($signer_uri);
+ } catch (Exception $e) {
return false;
}
+ if ($xrd->links) {
+ if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) {
+ list($type, $keypair) = explode(';', $link['href']);
+ return $keypair;
+ }
+ }
+ throw new Exception('Unable to locate signer public key');
+ }
+
- $signature_alg = Magicsig::fromString($this->getKeyPair($signer_uri));
+ public function signMessage($text, $mimetype, $keypair)
+ {
+ $signature_alg = Magicsig::fromString($keypair);
$armored_text = base64_encode($text);
return array(
@@ -76,6 +83,28 @@ class MagicEnvelope
}
+ public function toXML($env) {
+ $dom = new DOMDocument();
+
+ $envelope = $dom->createElementNS(MagicEnvelope::NS, 'me:env');
+ $envelope->setAttribute('xmlns:me', MagicEnvelope::NS);
+ $data = $dom->createElementNS(MagicEnvelope::NS, 'me:data', $env['data']);
+ $data->setAttribute('type', $env['data_type']);
+ $envelope->appendChild($data);
+ $enc = $dom->createElementNS(MagicEnvelope::NS, 'me:encoding', $env['encoding']);
+ $envelope->appendChild($enc);
+ $alg = $dom->createElementNS(MagicEnvelope::NS, 'me:alg', $env['alg']);
+ $envelope->appendChild($alg);
+ $sig = $dom->createElementNS(MagicEnvelope::NS, 'me:sig', $env['sig']);
+ $envelope->appendChild($sig);
+
+ $dom->appendChild($envelope);
+
+
+ return $dom->saveXML();
+ }
+
+
public function unfold($env)
{
$dom = new DOMDocument();
@@ -127,18 +156,32 @@ class MagicEnvelope
public function verify($env)
{
if ($env['alg'] != 'RSA-SHA256') {
+ common_log(LOG_DEBUG, "Salmon error: bad algorithm");
return false;
}
if ($env['encoding'] != MagicEnvelope::ENCODING) {
+ common_log(LOG_DEBUG, "Salmon error: bad encoding");
return false;
}
$text = base64_decode($env['data']);
$signer_uri = $this->getAuthor($text);
- $verifier = Magicsig::fromString($this->getKeyPair($signer_uri));
+ try {
+ $keypair = $this->getKeyPair($signer_uri);
+ } catch (Exception $e) {
+ common_log(LOG_DEBUG, "Salmon error: ".$e->getMessage());
+ return false;
+ }
+
+ $verifier = Magicsig::fromString($keypair);
+ if (!$verifier) {
+ common_log(LOG_DEBUG, "Salmon error: unable to parse keypair");
+ return false;
+ }
+
return $verifier->verify($env['data'], $env['sig']);
}
diff --git a/plugins/OStatus/lib/ostatusqueuehandler.php b/plugins/OStatus/lib/ostatusqueuehandler.php
index 0da85600f..d1e58f1d6 100644
--- a/plugins/OStatus/lib/ostatusqueuehandler.php
+++ b/plugins/OStatus/lib/ostatusqueuehandler.php
@@ -87,7 +87,7 @@ class OStatusQueueHandler extends QueueHandler
// remote user or group.
// @fixme as an optimization we can skip this if the
// remote profile is subscribed to the author.
- $oprofile->notifyDeferred($this->notice);
+ $oprofile->notifyDeferred($this->notice, $this->user);
}
}
@@ -164,46 +164,21 @@ class OStatusQueueHandler extends QueueHandler
*/
function userFeedForNotice()
{
- // @fixme this feels VERY hacky...
- // should probably be a cleaner way to do it
-
- ob_start();
- $api = new ApiTimelineUserAction();
- $api->prepare(array('id' => $this->notice->profile_id,
- 'format' => 'atom',
- 'max_id' => $this->notice->id,
- 'since_id' => $this->notice->id - 1));
- $api->showTimeline();
- $feed = ob_get_clean();
-
- // ...and override the content-type back to something normal... eww!
- // hope there's no other headers that got set while we weren't looking.
- header('Content-Type: text/html; charset=utf-8');
-
- common_log(LOG_DEBUG, $feed);
+ $atom = new AtomUserNoticeFeed($this->user);
+ $atom->addEntryFromNotice($this->notice);
+ $feed = $atom->getString();
+
return $feed;
}
function groupFeedForNotice($group_id)
{
- // @fixme this feels VERY hacky...
- // should probably be a cleaner way to do it
-
- ob_start();
- $api = new ApiTimelineGroupAction();
- $args = array('id' => $group_id,
- 'format' => 'atom',
- 'max_id' => $this->notice->id,
- 'since_id' => $this->notice->id - 1);
- $api->prepare($args);
- $api->handle($args);
- $feed = ob_get_clean();
-
- // ...and override the content-type back to something normal... eww!
- // hope there's no other headers that got set while we weren't looking.
- header('Content-Type: text/html; charset=utf-8');
-
- common_log(LOG_DEBUG, $feed);
+ $group = User_group::staticGet('id', $group_id);
+
+ $atom = new AtomGroupNoticeFeed($group);
+ $atom->addEntryFromNotice($this->notice);
+ $feed = $atom->getString();
+
return $feed;
}
diff --git a/plugins/OStatus/lib/pushinqueuehandler.php b/plugins/OStatus/lib/pushinqueuehandler.php
index a90f52df2..1fd29ae30 100644
--- a/plugins/OStatus/lib/pushinqueuehandler.php
+++ b/plugins/OStatus/lib/pushinqueuehandler.php
@@ -40,7 +40,11 @@ class PushInQueueHandler extends QueueHandler
$feedsub = FeedSub::staticGet('id', $feedsub_id);
if ($feedsub) {
- $feedsub->receive($post, $hmac);
+ try {
+ $feedsub->receive($post, $hmac);
+ } catch(Exception $e) {
+ common_log(LOG_ERR, "Exception during PuSH input processing for $feedsub->uri: " . $e->getMessage());
+ }
} else {
common_log(LOG_ERR, "Discarding POST to unknown feed subscription id $feedsub_id");
}
diff --git a/plugins/OStatus/lib/salmon.php b/plugins/OStatus/lib/salmon.php
index b5f178cc6..3d3341bc6 100644
--- a/plugins/OStatus/lib/salmon.php
+++ b/plugins/OStatus/lib/salmon.php
@@ -28,6 +28,11 @@
*/
class Salmon
{
+
+ const NS_REPLIES = "http://salmon-protocol.org/ns/salmon-replies";
+
+ const NS_MENTIONS = "http://salmon-protocol.org/ns/salmon-mention";
+
/**
* Sign and post the given Atom entry as a Salmon message.
*
@@ -37,17 +42,20 @@ class Salmon
* @param string $xml
* @return boolean success
*/
- public function post($endpoint_uri, $xml)
+ public function post($endpoint_uri, $xml, $actor)
{
if (empty($endpoint_uri)) {
return false;
}
- if (!common_config('ostatus', 'skip_signatures')) {
- $xml = $this->createMagicEnv($xml);
+ try {
+ $xml = $this->createMagicEnv($xml, $actor);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage());
+ return false;
}
- $headers = array('Content-Type: application/atom+xml');
+ $headers = array('Content-Type: application/magic-envelope+xml');
try {
$client = new HTTPClient();
@@ -65,24 +73,37 @@ class Salmon
return true;
}
- public function createMagicEnv($text)
+ public function createMagicEnv($text, $actor)
{
$magic_env = new MagicEnvelope();
- // TODO: Should probably be getting the signer uri as an argument?
- $signer_uri = $magic_env->getAuthor($text);
-
- $env = $magic_env->signMessage($text, 'application/atom+xml', $signer_uri);
+ $user = User::staticGet('id', $actor->id);
+ if ($user->id) {
+ // Use local key
+ $magickey = Magicsig::staticGet('user_id', $user->id);
+ if (!$magickey) {
+ // No keypair yet, let's generate one.
+ $magickey = new Magicsig();
+ $magickey->generate($user->id);
+ }
+ } else {
+ throw new Exception("Salmon invalid actor for signing");
+ }
- return $magic_env->unfold($env);
+ try {
+ $env = $magic_env->signMessage($text, 'application/atom+xml', $magickey->toString());
+ } catch (Exception $e) {
+ return $text;
+ }
+ return $magic_env->toXML($env);
}
- public function verifyMagicEnv($dom)
+ public function verifyMagicEnv($text)
{
$magic_env = new MagicEnvelope();
- $env = $magic_env->fromDom($dom);
+ $env = $magic_env->parse($text);
return $magic_env->verify($env);
}
diff --git a/plugins/OStatus/lib/salmonaction.php b/plugins/OStatus/lib/salmonaction.php
index a03169101..fa9dc3b1d 100644
--- a/plugins/OStatus/lib/salmonaction.php
+++ b/plugins/OStatus/lib/salmonaction.php
@@ -41,29 +41,32 @@ class SalmonAction extends Action
$this->clientError(_m('This method requires a POST.'));
}
- if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/atom+xml') {
- $this->clientError(_m('Salmon requires application/atom+xml'));
+ if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/magic-envelope+xml') {
+ $this->clientError(_m('Salmon requires application/magic-envelope+xml'));
}
$xml = file_get_contents('php://input');
- $dom = DOMDocument::loadXML($xml);
+ // Check the signature
+ $salmon = new Salmon;
+ if (!$salmon->verifyMagicEnv($xml)) {
+ common_log(LOG_DEBUG, "Salmon signature verification failed.");
+ $this->clientError(_m('Salmon signature verification failed.'));
+ } else {
+ $magic_env = new MagicEnvelope();
+ $env = $magic_env->parse($xml);
+ $xml = $magic_env->unfold($env);
+ }
+
+
+ $dom = DOMDocument::loadXML($xml);
if ($dom->documentElement->namespaceURI != Activity::ATOM ||
$dom->documentElement->localName != 'entry') {
common_log(LOG_DEBUG, "Got invalid Salmon post: $xml");
$this->clientError(_m('Salmon post must be an Atom entry.'));
}
- // Check the signature
- $salmon = new Salmon;
- if (!common_config('ostatus', 'skip_signatures')) {
- if (!$salmon->verifyMagicEnv($dom)) {
- common_log(LOG_DEBUG, "Salmon signature verification failed.");
- $this->clientError(_m('Salmon signature verification failed.'));
- }
- }
-
$this->act = new Activity($dom->documentElement);
return true;
}
diff --git a/plugins/OStatus/lib/salmonqueuehandler.php b/plugins/OStatus/lib/salmonqueuehandler.php
index aa97018dc..7eeb5f8e9 100644
--- a/plugins/OStatus/lib/salmonqueuehandler.php
+++ b/plugins/OStatus/lib/salmonqueuehandler.php
@@ -35,8 +35,10 @@ class SalmonQueueHandler extends QueueHandler
assert(is_string($data['salmonuri']));
assert(is_string($data['entry']));
+ $actor = Profile::staticGet($data['actor']);
+
$salmon = new Salmon();
- $salmon->post($data['salmonuri'], $data['entry']);
+ $salmon->post($data['salmonuri'], $data['entry'], $actor);
// @fixme detect failure and attempt to resend
return true;
diff --git a/plugins/OStatus/lib/webfinger.php b/plugins/OStatus/lib/webfinger.php
deleted file mode 100644
index 8a5037629..000000000
--- a/plugins/OStatus/lib/webfinger.php
+++ /dev/null
@@ -1,151 +0,0 @@
-<?php
-/**
- * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2010, StatusNet, Inc.
- *
- * A sample module to show best practices for StatusNet plugins
- *
- * PHP version 5
- *
- * 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 StatusNet
- * @author James Walker <james@status.net>
- * @copyright 2010 StatusNet, Inc.
- * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
- * @link http://status.net/
- */
-
-define('WEBFINGER_SERVICE_REL_VALUE', 'lrdd');
-
-/**
- * Implement the webfinger protocol.
- */
-
-class Webfinger
-{
- const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
- const UPDATESFROM = 'http://schemas.google.com/g/2010#updates-from';
-
- /**
- * Perform a webfinger lookup given an account.
- */
-
- public function lookup($id)
- {
- $id = $this->normalize($id);
- list($name, $domain) = explode('@', $id);
-
- $links = $this->getServiceLinks($domain);
- if (!$links) {
- return false;
- }
-
- $services = array();
- foreach ($links as $link) {
- if ($link['template']) {
- return $this->getServiceDescription($link['template'], $id);
- }
- if ($link['href']) {
- return $this->getServiceDescription($link['href'], $id);
- }
- }
- }
-
- /**
- * Normalize an account ID
- */
- function normalize($id)
- {
- if (substr($id, 0, 7) == 'acct://') {
- return substr($id, 7);
- } else if (substr($id, 0, 5) == 'acct:') {
- return substr($id, 5);
- }
-
- return $id;
- }
-
- function getServiceLinks($domain)
- {
- $url = 'http://'. $domain .'/.well-known/host-meta';
- $content = $this->fetchURL($url);
- if (empty($content)) {
- common_log(LOG_DEBUG, 'Error fetching host-meta');
- return false;
- }
- $result = XRD::parse($content);
-
- // Ensure that the host == domain (spec may include signing later)
- if ($result->host != $domain) {
- return false;
- }
-
- $links = array();
- foreach ($result->links as $link) {
- if ($link['rel'] == WEBFINGER_SERVICE_REL_VALUE) {
- $links[] = $link;
- }
-
- }
- return $links;
- }
-
- function getServiceDescription($template, $id)
- {
- $url = $this->applyTemplate($template, 'acct:' . $id);
-
- $content = $this->fetchURL($url);
-
- if (!$content) {
- return false;
- }
-
- return XRD::parse($content);
- }
-
- function fetchURL($url)
- {
- try {
- $client = new HTTPClient();
- $response = $client->get($url);
- } catch (HTTP_Request2_Exception $e) {
- return false;
- }
-
- if ($response->getStatus() != 200) {
- return false;
- }
-
- return $response->getBody();
- }
-
- function applyTemplate($template, $id)
- {
- $template = str_replace('{uri}', urlencode($id), $template);
-
- return $template;
- }
-
- function getHostMeta($domain, $template) {
- $xrd = new XRD();
- $xrd->host = $domain;
- $xrd->links[] = array('rel' => 'lrdd',
- 'template' => $template,
- 'title' => array('Resource Descriptor'));
-
- return $xrd->toXML();
- }
-}
-
diff --git a/plugins/OStatus/lib/xrd.php b/plugins/OStatus/lib/xrd.php
index 16d27f8eb..aa13ef024 100644
--- a/plugins/OStatus/lib/xrd.php
+++ b/plugins/OStatus/lib/xrd.php
@@ -53,17 +53,25 @@ class XRD
$xrd = new XRD();
$dom = new DOMDocument();
- $dom->loadXML($xml);
+ if (!$dom->loadXML($xml)) {
+ throw new Exception("Invalid XML");
+ }
$xrd_element = $dom->getElementsByTagName('XRD')->item(0);
+ if (!$xrd_element) {
+ throw new Exception("Invalid XML, missing XRD root");
+ }
// Check for host-meta host
- $host = $xrd_element->getElementsByTagName('Host')->item(0)->nodeValue;
+ $host = $xrd_element->getElementsByTagName('Host')->item(0);
if ($host) {
- $xrd->host = $host;
+ $xrd->host = $host->nodeValue;
}
// Loop through other elements
foreach ($xrd_element->childNodes as $node) {
+ if (!($node instanceof DOMElement)) {
+ continue;
+ }
switch ($node->tagName) {
case 'Expires':
$xrd->expires = $node->nodeValue;
@@ -144,9 +152,11 @@ class XRD
$link['href'] = $element->getAttribute('href');
$link['template'] = $element->getAttribute('template');
foreach ($element->childNodes as $node) {
- switch($node->tagName) {
- case 'Title':
- $link['title'][] = $node->nodeValue;
+ if ($node instanceof DOMElement) {
+ switch($node->tagName) {
+ case 'Title':
+ $link['title'][] = $node->nodeValue;
+ }
}
}
@@ -156,20 +166,20 @@ class XRD
function saveLink($doc, $link)
{
$link_element = $doc->createElement('Link');
- if ($link['rel']) {
+ if (!empty($link['rel'])) {
$link_element->setAttribute('rel', $link['rel']);
}
- if ($link['type']) {
+ if (!empty($link['type'])) {
$link_element->setAttribute('type', $link['type']);
}
- if ($link['href']) {
+ if (!empty($link['href'])) {
$link_element->setAttribute('href', $link['href']);
}
- if ($link['template']) {
+ if (!empty($link['template'])) {
$link_element->setAttribute('template', $link['template']);
}
- if (is_array($link['title'])) {
+ if (!empty($link['title']) && is_array($link['title'])) {
foreach($link['title'] as $title) {
$title = $doc->createElement('Title', $title);
$link_element->appendChild($title);
diff --git a/plugins/OStatus/actions/webfinger.php b/plugins/OStatus/lib/xrdaction.php
index 34336a903..6881292ad 100644
--- a/plugins/OStatus/actions/webfinger.php
+++ b/plugins/OStatus/lib/xrdaction.php
@@ -24,51 +24,43 @@
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-class WebfingerAction extends Action
+class XrdAction extends Action
{
public $uri;
+
+ public $user;
- function prepare($args)
- {
- parent::prepare($args);
-
- $this->uri = $this->trimmed('uri');
-
- return true;
- }
-
+ public $xrd;
+
function handle()
{
- $acct = Webfinger::normalize($this->uri);
-
- $xrd = new XRD();
-
- list($nick, $domain) = explode('@', urldecode($acct));
- $nick = common_canonical_nickname($nick);
+ $nick = $this->user->nickname;
- $this->user = User::staticGet('nickname', $nick);
- if (!$this->user) {
- $this->clientError(_('No such user.'), 404);
- return false;
+ if (empty($this->xrd)) {
+ $xrd = new XRD();
+ } else {
+ $xrd = $this->xrd;
}
- $xrd->subject = $this->uri;
+ if (empty($xrd->subject)) {
+ $xrd->subject = Discovery::normalize($this->uri);
+ }
$xrd->alias[] = common_profile_url($nick);
- $xrd->links[] = array('rel' => Webfinger::PROFILEPAGE,
+ $xrd->links[] = array('rel' => Discovery::PROFILEPAGE,
'type' => 'text/html',
'href' => common_profile_url($nick));
- $xrd->links[] = array('rel' => Webfinger::UPDATESFROM,
+ $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' => 'http://microformats.org/profile/hcard',
+ $xrd->links[] = array('rel' => Discovery::HCARD,
'type' => 'text/html',
- 'href' => common_profile_url($nick));
+ 'href' => common_local_url('hcard', array('nickname' => $nick)));
// XFN
$xrd->links[] = array('rel' => 'http://gmpg.org/xfn/11',
@@ -78,12 +70,16 @@ class WebfingerAction extends Action
$xrd->links[] = array('rel' => 'describedby',
'type' => 'application/rdf+xml',
'href' => common_local_url('foaf',
- array('nickname' => $nick)));
-
- $salmon_url = common_local_url('salmon',
+ array('nickname' => $nick)));
+
+ // Salmon
+ $salmon_url = common_local_url('usersalmon',
array('id' => $this->user->id));
- $xrd->links[] = array('rel' => 'salmon',
+ $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
@@ -91,12 +87,12 @@ class WebfingerAction extends Action
if (!$magickey) {
// No keypair yet, let's generate one.
$magickey = new Magicsig();
- $magickey->generate();
+ $magickey->generate($this->user->id);
}
-
+
$xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
- 'href' => 'data:application/magic-public-key;'. $magickey->keypair);
-
+ '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',
diff --git a/plugins/OStatus/locale/OStatus.po b/plugins/OStatus/locale/OStatus.po
index dedc018e3..7e33a0eed 100644
--- a/plugins/OStatus/locale/OStatus.po
+++ b/plugins/OStatus/locale/OStatus.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-12-07 20:38-0800\n"
+"POT-Creation-Date: 2010-03-01 14:58-0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -16,89 +16,297 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: tests/gettext-speedtest.php:57 FeedSubPlugin.php:76
-msgid "Feeds"
+#: actions/groupsalmon.php:51
+msgid "Can't accept remote posts for a remote group."
+msgstr ""
+
+#: actions/groupsalmon.php:123
+msgid "Can't read profile to set up group membership."
msgstr ""
-#: FeedSubPlugin.php:77
-msgid "Feed subscription options"
+#: actions/groupsalmon.php:126 actions/groupsalmon.php:169
+msgid "Groups can't join groups."
msgstr ""
-#: feedmunger.php:215
+#: actions/groupsalmon.php:153
#, php-format
-msgid "New post: \"%1$s\" %2$s"
+msgid "Could not join remote user %1$s to group %2$s."
msgstr ""
-#: actions/feedsubsettings.php:41
-msgid "Feed subscriptions"
+#: actions/groupsalmon.php:166
+msgid "Can't read profile to cancel group membership."
msgstr ""
-#: actions/feedsubsettings.php:52
-msgid ""
-"You can subscribe to feeds from other sites; updates will appear in your "
-"personal timeline."
+#: actions/groupsalmon.php:182
+#, php-format
+msgid "Could not remove remote user %1$s from group %2$s."
+msgstr ""
+
+#: actions/ostatusinit.php:40
+msgid "You can use the local subscription!"
+msgstr ""
+
+#: actions/ostatusinit.php:61
+msgid "There was a problem with your session token. Try again, please."
+msgstr ""
+
+#: actions/ostatusinit.php:79 actions/ostatussub.php:439
+msgid "Subscribe to user"
+msgstr ""
+
+#: actions/ostatusinit.php:97
+#, php-format
+msgid "Subscribe to %s"
msgstr ""
-#: actions/feedsubsettings.php:96
+#: actions/ostatusinit.php:102
+msgid "User nickname"
+msgstr ""
+
+#: actions/ostatusinit.php:103
+msgid "Nickname of the user you want to follow"
+msgstr ""
+
+#: actions/ostatusinit.php:106
+msgid "Profile Account"
+msgstr ""
+
+#: actions/ostatusinit.php:107
+msgid "Your account id (i.e. user@identi.ca)"
+msgstr ""
+
+#: actions/ostatusinit.php:110 actions/ostatussub.php:115
+#: OStatusPlugin.php:205
msgid "Subscribe"
msgstr ""
-#: actions/feedsubsettings.php:98
+#: actions/ostatusinit.php:128
+msgid "Must provide a remote profile."
+msgstr ""
+
+#: actions/ostatusinit.php:138
+msgid "Couldn't look up OStatus account profile."
+msgstr ""
+
+#: actions/ostatusinit.php:153
+msgid "Couldn't confirm remote profile address."
+msgstr ""
+
+#: actions/ostatusinit.php:171
+msgid "OStatus Connect"
+msgstr ""
+
+#: actions/ostatussub.php:68
+msgid "Address or profile URL"
+msgstr ""
+
+#: actions/ostatussub.php:70
+msgid "Enter the profile URL of a PubSubHubbub-enabled feed"
+msgstr ""
+
+#: actions/ostatussub.php:74
msgid "Continue"
msgstr ""
-#: actions/feedsubsettings.php:151
-msgid "Empty feed URL!"
+#: actions/ostatussub.php:112 OStatusPlugin.php:503
+msgid "Join"
+msgstr ""
+
+#: actions/ostatussub.php:113
+msgid "Join this group"
+msgstr ""
+
+#: actions/ostatussub.php:116
+msgid "Subscribe to this user"
+msgstr ""
+
+#: actions/ostatussub.php:137
+msgid "You are already subscribed to this user."
+msgstr ""
+
+#: actions/ostatussub.php:165
+msgid "You are already a member of this group."
msgstr ""
-#: actions/feedsubsettings.php:161
+#: actions/ostatussub.php:286
+msgid "Empty remote profile URL!"
+msgstr ""
+
+#: actions/ostatussub.php:297
+msgid "Invalid address format."
+msgstr ""
+
+#: actions/ostatussub.php:302
msgid "Invalid URL or could not reach server."
msgstr ""
-#: actions/feedsubsettings.php:164
+#: actions/ostatussub.php:304
msgid "Cannot read feed; server returned error."
msgstr ""
-#: actions/feedsubsettings.php:167
+#: actions/ostatussub.php:306
msgid "Cannot read feed; server returned an empty page."
msgstr ""
-#: actions/feedsubsettings.php:170
+#: actions/ostatussub.php:308
msgid "Bad HTML, could not find feed link."
msgstr ""
-#: actions/feedsubsettings.php:173
+#: actions/ostatussub.php:310
msgid "Could not find a feed linked from this URL."
msgstr ""
-#: actions/feedsubsettings.php:176
+#: actions/ostatussub.php:312
msgid "Not a recognized feed type."
msgstr ""
-#: actions/feedsubsettings.php:180
-msgid "Bad feed URL."
+#: actions/ostatussub.php:315
+#, php-format
+msgid "Bad feed URL: %s %s"
+msgstr ""
+
+#. TRANS: OStatus remote group subscription dialog error.
+#: actions/ostatussub.php:336
+msgid "Already a member!"
msgstr ""
-#: actions/feedsubsettings.php:188
-msgid "Feed is not PuSH-enabled; cannot subscribe."
+#. TRANS: OStatus remote group subscription dialog error.
+#: actions/ostatussub.php:346
+msgid "Remote group join failed!"
msgstr ""
-#: actions/feedsubsettings.php:208
-msgid "Feed subscription failed! Bad response from hub."
+#. TRANS: OStatus remote group subscription dialog error.
+#: actions/ostatussub.php:350
+msgid "Remote group join aborted!"
msgstr ""
-#: actions/feedsubsettings.php:218
+#. TRANS: OStatus remote subscription dialog error.
+#: actions/ostatussub.php:356
msgid "Already subscribed!"
msgstr ""
-#: actions/feedsubsettings.php:220
-msgid "Feed subscribed!"
+#. TRANS: OStatus remote subscription dialog error.
+#: actions/ostatussub.php:361
+msgid "Remote subscription failed!"
msgstr ""
-#: actions/feedsubsettings.php:222
-msgid "Feed subscription failed!"
+#. TRANS: Page title for OStatus remote subscription form
+#: actions/ostatussub.php:459
+msgid "Authorize subscription"
+msgstr ""
+
+#: actions/ostatussub.php:470
+msgid ""
+"You can subscribe to users from other supported sites. Paste their address "
+"or profile URI below:"
+msgstr ""
+
+#: classes/Ostatus_profile.php:789
+#, php-format
+msgid "Tried to update avatar for unsaved remote profile %s"
msgstr ""
-#: actions/feedsubsettings.php:231
-msgid "Previewing feed:"
+#: classes/Ostatus_profile.php:797
+#, php-format
+msgid "Unable to fetch avatar from %s"
+msgstr ""
+
+#: lib/salmonaction.php:41
+msgid "This method requires a POST."
+msgstr ""
+
+#: lib/salmonaction.php:45
+msgid "Salmon requires application/magic-envelope+xml"
+msgstr ""
+
+#: lib/salmonaction.php:55
+msgid "Salmon signature verification failed."
+msgstr ""
+
+#: lib/salmonaction.php:67
+msgid "Salmon post must be an Atom entry."
+msgstr ""
+
+#: lib/salmonaction.php:115
+msgid "Unrecognized activity type."
+msgstr ""
+
+#: lib/salmonaction.php:123
+msgid "This target doesn't understand posts."
+msgstr ""
+
+#: lib/salmonaction.php:128
+msgid "This target doesn't understand follows."
+msgstr ""
+
+#: lib/salmonaction.php:133
+msgid "This target doesn't understand unfollows."
+msgstr ""
+
+#: lib/salmonaction.php:138
+msgid "This target doesn't understand favorites."
+msgstr ""
+
+#: lib/salmonaction.php:143
+msgid "This target doesn't understand unfavorites."
+msgstr ""
+
+#: lib/salmonaction.php:148
+msgid "This target doesn't understand share events."
+msgstr ""
+
+#: lib/salmonaction.php:153
+msgid "This target doesn't understand joins."
+msgstr ""
+
+#: lib/salmonaction.php:158
+msgid "This target doesn't understand leave events."
+msgstr ""
+
+#: OStatusPlugin.php:319
+#, php-format
+msgid "Sent from %s via OStatus"
+msgstr ""
+
+#: OStatusPlugin.php:371
+msgid "Could not set up remote subscription."
+msgstr ""
+
+#: OStatusPlugin.php:487
+msgid "Could not set up remote group membership."
+msgstr ""
+
+#: OStatusPlugin.php:504
+#, php-format
+msgid "%s has joined group %s."
+msgstr ""
+
+#: OStatusPlugin.php:512
+msgid "Failed joining remote group."
+msgstr ""
+
+#: OStatusPlugin.php:553
+msgid "Leave"
+msgstr ""
+
+#: OStatusPlugin.php:554
+#, php-format
+msgid "%s has left group %s."
+msgstr ""
+
+#: OStatusPlugin.php:685
+msgid "Subscribe to remote user"
+msgstr ""
+
+#: OStatusPlugin.php:726
+msgid "Profile update"
+msgstr ""
+
+#: OStatusPlugin.php:727
+#, php-format
+msgid "%s has updated their profile page."
+msgstr ""
+
+#: tests/gettext-speedtest.php:57
+msgid "Feeds"
msgstr ""
diff --git a/plugins/OStatus/scripts/updateostatus.php b/plugins/OStatus/scripts/updateostatus.php
new file mode 100644
index 000000000..d553a7d62
--- /dev/null
+++ b/plugins/OStatus/scripts/updateostatus.php
@@ -0,0 +1,127 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, 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/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
+
+$shortoptions = 'i:n:a';
+$longoptions = array('id=', 'nickname=', 'all');
+
+$helptext = <<<END_OF_UPDATEOSTATUS_HELP
+updateostatus.php [options]
+update the OMB subscriptions of a user to use OStatus if possible
+
+ -i --id ID of user to update
+ -n --nickname nickname of the user to update
+ -a --all update all
+
+END_OF_UPDATEOSTATUS_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+try {
+ $user = null;
+
+ if (have_option('i', 'id')) {
+ $id = get_option_value('i', 'id');
+ $user = User::staticGet('id', $id);
+ if (empty($user)) {
+ throw new Exception("Can't find user with id '$id'.");
+ }
+ updateProfileURL($user);
+ } else if (have_option('n', 'nickname')) {
+ $nickname = get_option_value('n', 'nickname');
+ $user = User::staticGet('nickname', $nickname);
+ if (empty($user)) {
+ throw new Exception("Can't find user with nickname '$nickname'");
+ }
+ updateProfileURL($user);
+ } else if (have_option('a', 'all')) {
+ $user = new User();
+ if ($user->find()) {
+ while ($user->fetch()) {
+ updateOStatus($user);
+ }
+ }
+ } else {
+ show_help();
+ exit(1);
+ }
+} catch (Exception $e) {
+ print $e->getMessage()."\n";
+ exit(1);
+}
+
+function updateOStatus($user)
+{
+ if (!have_option('q', 'quiet')) {
+ echo "{$user->nickname}...";
+ }
+
+ $up = $user->getProfile();
+
+ $sp = $user->getSubscriptions();
+
+ $rps = array();
+
+ while ($sp->fetch()) {
+ $remote = Remote_profile::staticGet('id', $sp->id);
+
+ if (!empty($remote)) {
+ $rps[] = clone($sp);
+ }
+ }
+
+ if (!have_option('q', 'quiet')) {
+ echo count($rps) . "\n";
+ }
+
+ foreach ($rps as $rp) {
+ try {
+ if (!have_option('q', 'quiet')) {
+ echo "Checking {$rp->nickname}...";
+ }
+
+ $op = Ostatus_profile::ensureProfile($rp->profileurl);
+
+ if (empty($op)) {
+ echo "can't convert.\n";
+ continue;
+ } else {
+ if (!have_option('q', 'quiet')) {
+ echo "Converting...";
+ }
+ Subscription::cancel($up, $rp);
+ Subscription::start($up, $op->localProfile());
+ if (!have_option('q', 'quiet')) {
+ echo "done.\n";
+ }
+ }
+
+ } catch (Exception $e) {
+ if (!have_option('q', 'quiet')) {
+ echo "fail.\n";
+ }
+ continue;
+ common_log(LOG_WARNING, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname .
+ ") to OStatus: " . $e->getMessage());
+ continue;
+ }
+ }
+}
diff --git a/plugins/OStatus/theme/base/css/ostatus.css b/plugins/OStatus/theme/base/css/ostatus.css
index feeeb47d3..c2d724158 100644
--- a/plugins/OStatus/theme/base/css/ostatus.css
+++ b/plugins/OStatus/theme/base/css/ostatus.css
@@ -38,11 +38,37 @@ display:none;
min-width:96px;
}
-#subscriptions #entity_remote_subscribe {
+#entity_remote_subscribe {
padding:0;
float:right;
+position:relative;
}
-#subscriptions .entity_remote_subscribe {
-float:right;
+.section .entity_actions {
+margin-bottom:0;
+margin-right:7px;
+}
+
+#entity_remote_subscribe .dialogbox {
+width:405px;
+}
+
+.aside #entity_subscriptions .more,
+.aside #entity_groups .more {
+float:left;
+}
+
+.section #entity_remote_subscribe {
+border:0;
+}
+
+.section .entity_remote_subscribe {
+color:#002FA7;
+box-shadow:none;
+-moz-box-shadow:none;
+-webkit-box-shadow:none;
+background-color:transparent;
+background-position:0 -1183px;
+padding:0 0 0 23px;
+border:0;
}