summaryrefslogtreecommitdiff
path: root/plugins/OStatus/OStatusPlugin.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-03-04 06:07:28 -0800
committerBrion Vibber <brion@pobox.com>2010-03-04 06:07:28 -0800
commitb218aee94e581230e1efa14d4ae1a19756986ddf (patch)
treea832ddf3b4322b520fd20c4d8ea2d31720c3679b /plugins/OStatus/OStatusPlugin.php
parent358556057a87c0cb9291223a2026782e6548ff2e (diff)
parent14d7f4a598d0e24467fe3eafd9a02b0e651edad8 (diff)
Merge commit 'origin/testing' into 0.9.x
Conflicts: lib/action.php lib/adminpanelaction.php
Diffstat (limited to 'plugins/OStatus/OStatusPlugin.php')
-rw-r--r--plugins/OStatus/OStatusPlugin.php165
1 files changed, 111 insertions, 54 deletions
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index b69430ea7..033325c9e 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -44,15 +44,19 @@ class OStatusPlugin extends Plugin
$m->connect('.well-known/host-meta',
array('action' => 'hostmeta'));
$m->connect('main/xrd',
- array('action' => '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'));
@@ -109,13 +113,13 @@ class OStatusPlugin extends Plugin
{
if ($action instanceof ShowstreamAction) {
$acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
- $url = common_local_url('xrd');
+ $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.
@@ -210,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.
*
@@ -233,70 +253,70 @@ class OStatusPlugin extends Plugin
function onEndFindMentions($sender, $text, &$mentions)
{
- preg_match_all('!(?:^|\s+)
- @( # Webfinger:
- (?:\w+\.)*\w+ # user
- @ # @
- (?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+ # domain
- | # Profile:
- (?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+ # domain
- (?:/\w+)+ # /path1(/path2...)
- )!x',
+ $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) {
- $target = $wmatch[0];
- $oprofile = null;
-
- if (strpos($target, '/') === false) {
- $this->log(LOG_INFO, "Checking Webfinger for address '$target'");
+ 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());
}
- } else {
- $schemes = array('https', 'http');
+ }
+ }
+
+ // 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) {
- continue;
+ 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());
}
}
}
+ }
- if (empty($oprofile)) {
- $this->log(LOG_INFO, "No Ostatus_profile found for address '$target'");
- } else {
-
- $this->log(LOG_INFO, "Ostatus_profile found for address '$target'");
-
- if ($oprofile->isGroup()) {
- continue;
- }
- $profile = $oprofile->localProfile();
-
- $pos = $wmatch[1];
- foreach ($mentions as $i => $other) {
- // If we share a common prefix with a local user, override it!
- if ($other['position'] == $pos) {
- unset($mentions[$i]);
- }
- }
- $mentions[] = array('mentioned' => array($profile),
- 'text' => $target,
- 'position' => $pos,
- '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;
}
@@ -567,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();
@@ -711,23 +730,37 @@ class OStatusPlugin extends Plugin
return true;
}
- function onStartShowAllContent($action)
+ function onStartShowUserGroupsContent($action)
+ {
+ $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
+
+ return true;
+ }
+
+ function onEndShowSubscriptionsMiniList($action)
{
$this->showEntityRemoteSubscribe($action);
return true;
}
- function showEntityRemoteSubscribe($action)
+ 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');
}
@@ -779,4 +812,28 @@ class OStatusPlugin extends Plugin
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;
+ }
}