Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x

This commit is contained in:
Brion Vibber
2010-03-02 13:38:10 -08:00
50 changed files with 1172 additions and 270 deletions

View File

@@ -222,31 +222,62 @@ 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 onEndFindMentions($sender, $text, &$mentions)
{
preg_match_all('/(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)/',
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',
$text,
$wmatches,
PREG_OFFSET_CAPTURE);
foreach ($wmatches[1] as $wmatch) {
$target = $wmatch[0];
$oprofile = null;
$webfinger = $wmatch[0];
$this->log(LOG_INFO, "Checking Webfinger for address '$webfinger'");
$oprofile = Ostatus_profile::ensureWebfinger($webfinger);
if (strpos($target, '/') === false) {
$this->log(LOG_INFO, "Checking Webfinger for address '$target'");
try {
$oprofile = Ostatus_profile::ensureWebfinger($target);
} catch (Exception $e) {
$this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
}
} else {
$schemes = array('https', 'http');
foreach ($schemes as $scheme) {
$url = "$scheme://$target";
$this->log(LOG_INFO, "Checking profile address '$url'");
try {
$oprofile = Ostatus_profile::ensureProfile($url);
if ($oprofile) {
continue;
}
} 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 '$webfinger'");
$this->log(LOG_INFO, "No Ostatus_profile found for address '$target'");
} else {
$this->log(LOG_INFO, "Ostatus_profile found for address '$webfinger'");
$this->log(LOG_INFO, "Ostatus_profile found for address '$target'");
if ($oprofile->isGroup()) {
continue;
@@ -261,7 +292,7 @@ class OStatusPlugin extends Plugin
}
}
$mentions[] = array('mentioned' => array($profile),
'text' => $wmatch[0],
'text' => $target,
'position' => $pos,
'url' => $profile->profileurl);
}
@@ -674,6 +705,20 @@ class OStatusPlugin extends Plugin
}
function onStartShowSubscriptionsContent($action)
{
$this->showEntityRemoteSubscribe($action);
return true;
}
function onStartShowAllContent($action)
{
$this->showEntityRemoteSubscribe($action);
return true;
}
function showEntityRemoteSubscribe($action)
{
$user = common_current_user();
if ($user && ($user->id == $action->profile->id)) {
@@ -686,8 +731,6 @@ class OStatusPlugin extends Plugin
$action->elementEnd('p');
$action->elementEnd('div');
}
return true;
}
/**

View File

@@ -112,7 +112,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');

View File

@@ -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();

View File

@@ -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');
}

View File

@@ -146,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');

View File

@@ -698,7 +698,7 @@ class Ostatus_profile extends Memcached_DataObject
{
// Get the canonical feed URI and check it
$discover = new FeedDiscovery();
if ($hints['feedurl']) {
if (isset($hints['feedurl'])) {
$feeduri = $hints['feedurl'];
$feeduri = $discover->discoverFromFeedURL($feeduri);
} else {
@@ -1145,7 +1145,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($poco)) {
$url = $poco->getPrimaryURL();
if ($url->type == 'homepage') {
if ($url && $url->type == 'homepage') {
$homepage = $url->value;
}
}

View File

@@ -94,7 +94,7 @@ class Discovery
$links = call_user_func(array($class, 'discover'), $uri);
if ($link = Discovery::getService($links, Discovery::LRDD_REL)) {
// Load the LRDD XRD
if ($link['template']) {
if (!empty($link['template'])) {
$xrd_uri = Discovery::applyTemplate($link['template'], $uri);
} else {
$xrd_uri = $link['href'];

View File

@@ -53,17 +53,22 @@ 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);
// 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;
@@ -156,20 +161,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);

View File

@@ -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;
}
}
}

View File

@@ -38,11 +38,11 @@ display:none;
min-width:96px;
}
#subscriptions #entity_remote_subscribe {
#entity_remote_subscribe {
padding:0;
float:right;
}
#subscriptions .entity_remote_subscribe {
float:right;
#all #entity_remote_subscribe {
margin-top:-52px;
}