diff options
Diffstat (limited to 'plugins/OStatus/lib')
-rw-r--r-- | plugins/OStatus/lib/discovery.php | 5 | ||||
-rw-r--r-- | plugins/OStatus/lib/discoveryhints.php | 6 | ||||
-rw-r--r-- | plugins/OStatus/lib/feeddiscovery.php | 5 | ||||
-rw-r--r-- | plugins/OStatus/lib/hubconfqueuehandler.php | 1 | ||||
-rw-r--r-- | plugins/OStatus/lib/linkheader.php | 3 | ||||
-rw-r--r-- | plugins/OStatus/lib/magicenvelope.php | 23 | ||||
-rw-r--r-- | plugins/OStatus/lib/ostatusqueuehandler.php | 15 | ||||
-rw-r--r-- | plugins/OStatus/lib/pushinqueuehandler.php | 1 | ||||
-rw-r--r-- | plugins/OStatus/lib/salmon.php | 12 | ||||
-rw-r--r-- | plugins/OStatus/lib/salmonaction.php | 38 | ||||
-rw-r--r-- | plugins/OStatus/lib/salmonqueuehandler.php | 2 | ||||
-rw-r--r-- | plugins/OStatus/lib/xrd.php | 172 | ||||
-rw-r--r-- | plugins/OStatus/lib/xrdaction.php | 6 |
13 files changed, 68 insertions, 221 deletions
diff --git a/plugins/OStatus/lib/discovery.php b/plugins/OStatus/lib/discovery.php index 7187c1f3e..905ece2ca 100644 --- a/plugins/OStatus/lib/discovery.php +++ b/plugins/OStatus/lib/discovery.php @@ -106,7 +106,8 @@ class Discovery } } - throw new Exception('Unable to find services for '. $id); + // TRANS: Exception. + throw new Exception(sprintf(_m('Unable to find services for %s.'),$id)); } public static function getService($links, $service) { @@ -160,7 +161,7 @@ class Discovery_LRDD_Host_Meta implements Discovery_LRDD } else { $domain = parse_url($uri, PHP_URL_HOST); } - + $url = 'http://'. $domain .'/.well-known/host-meta'; $xrd = Discovery::fetchXrd($url); diff --git a/plugins/OStatus/lib/discoveryhints.php b/plugins/OStatus/lib/discoveryhints.php index 34c9be277..a98f4a6d6 100644 --- a/plugins/OStatus/lib/discoveryhints.php +++ b/plugins/OStatus/lib/discoveryhints.php @@ -20,7 +20,6 @@ */ class DiscoveryHints { - static function fromXRD($xrd) { $hints = array(); @@ -114,9 +113,10 @@ class DiscoveryHints { static function _hcard($body, $url) { - // DOMDocument::loadHTML may throw warnings on unrecognized elements. + // DOMDocument::loadHTML may throw warnings on unrecognized elements, + // and notices on unrecognized namespaces. - $old = error_reporting(error_reporting() & ~E_WARNING); + $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE)); $doc = new DOMDocument(); $doc->loadHTML($body); diff --git a/plugins/OStatus/lib/feeddiscovery.php b/plugins/OStatus/lib/feeddiscovery.php index a55399d7c..8a166a0be 100644 --- a/plugins/OStatus/lib/feeddiscovery.php +++ b/plugins/OStatus/lib/feeddiscovery.php @@ -196,8 +196,9 @@ class FeedDiscovery */ function discoverFromHTML($url, $body) { - // DOMDocument::loadHTML may throw warnings on unrecognized elements. - $old = error_reporting(error_reporting() & ~E_WARNING); + // DOMDocument::loadHTML may throw warnings on unrecognized elements, + // and notices on unrecognized namespaces. + $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE)); $dom = new DOMDocument(); $ok = $dom->loadHTML($body); error_reporting($old); diff --git a/plugins/OStatus/lib/hubconfqueuehandler.php b/plugins/OStatus/lib/hubconfqueuehandler.php index c8e0b72fe..8219f8420 100644 --- a/plugins/OStatus/lib/hubconfqueuehandler.php +++ b/plugins/OStatus/lib/hubconfqueuehandler.php @@ -51,4 +51,3 @@ class HubConfQueueHandler extends QueueHandler return true; } } - diff --git a/plugins/OStatus/lib/linkheader.php b/plugins/OStatus/lib/linkheader.php index cd78d31ce..efa3f65ff 100644 --- a/plugins/OStatus/lib/linkheader.php +++ b/plugins/OStatus/lib/linkheader.php @@ -1,4 +1,7 @@ <?php +/** + * @todo Add file header and documentation. + */ class LinkHeader { diff --git a/plugins/OStatus/lib/magicenvelope.php b/plugins/OStatus/lib/magicenvelope.php index 967e5f6d1..03e6f7c66 100644 --- a/plugins/OStatus/lib/magicenvelope.php +++ b/plugins/OStatus/lib/magicenvelope.php @@ -32,7 +32,7 @@ class MagicEnvelope const ENCODING = 'base64url'; const NS = 'http://salmon-protocol.org/ns/magic-env'; - + private function normalizeUser($user_id) { if (substr($user_id, 0, 5) == 'http:' || @@ -70,13 +70,14 @@ class MagicEnvelope $keypair = $parts[1]; } } - + if ($keypair) { return $keypair; } } } - throw new Exception('Unable to locate signer public key'); + // TRANS: Exception. + throw new Exception(_m('Unable to locate signer public key.')); } @@ -92,8 +93,6 @@ class MagicEnvelope 'sig' => $signature_alg->sign($armored_text), 'alg' => $signature_alg->getName() ); - - } public function toXML($env) { @@ -105,13 +104,12 @@ class MagicEnvelope $xs->element('me:alg', null, $env['alg']); $xs->element('me:sig', null, $env['sig']); $xs->elementEnd('me:env'); - + $string = $xs->getString(); common_debug($string); return $string; } - public function unfold($env) { $dom = new DOMDocument(); @@ -137,7 +135,7 @@ class MagicEnvelope return $dom->saveXML(); } - + public function getAuthor($text) { $doc = new DOMDocument(); if (!$doc->loadXML($text)) { @@ -154,12 +152,12 @@ class MagicEnvelope } } } - + public function checkAuthor($text, $signer_uri) { return ($this->getAuthor($text) == $signer_uri); } - + public function verify($env) { if ($env['alg'] != 'RSA-SHA256') { @@ -181,14 +179,14 @@ class MagicEnvelope 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']); } @@ -219,5 +217,4 @@ class MagicEnvelope 'sig' => preg_replace('/\s/', '', $sig_element->nodeValue), ); } - } diff --git a/plugins/OStatus/lib/ostatusqueuehandler.php b/plugins/OStatus/lib/ostatusqueuehandler.php index 8905d2e21..5e0ab46a5 100644 --- a/plugins/OStatus/lib/ostatusqueuehandler.php +++ b/plugins/OStatus/lib/ostatusqueuehandler.php @@ -67,6 +67,17 @@ class OStatusQueueHandler extends QueueHandler } } + if (!empty($this->notice->reply_to)) { + $replyTo = Notice::staticGet('id', $this->notice->reply_to); + if (!empty($replyTo)) { + foreach($replyTo->getReplies() as $profile_id) { + $oprofile = Ostatus_profile::staticGet('profile_id', $profile_id); + if ($oprofile) { + $this->pingReply($oprofile); + } + } + } + } return true; } @@ -161,7 +172,7 @@ class OStatusQueueHandler extends QueueHandler * Queue up direct feed update pushes to subscribers on our internal hub. * If there are a large number of subscriber sites, intermediate bulk * distribution triggers may be queued. - * + * * @param string $atom update feed, containing only new/changed items * @param HubSub $sub open query of subscribers */ @@ -210,6 +221,4 @@ class OStatusQueueHandler extends QueueHandler return $feed; } - } - diff --git a/plugins/OStatus/lib/pushinqueuehandler.php b/plugins/OStatus/lib/pushinqueuehandler.php index 1fd29ae30..965d04266 100644 --- a/plugins/OStatus/lib/pushinqueuehandler.php +++ b/plugins/OStatus/lib/pushinqueuehandler.php @@ -22,7 +22,6 @@ * @package FeedSub * @author Brion Vibber <brion@status.net> */ - class PushInQueueHandler extends QueueHandler { function transport() diff --git a/plugins/OStatus/lib/salmon.php b/plugins/OStatus/lib/salmon.php index ef7719a40..963da6508 100644 --- a/plugins/OStatus/lib/salmon.php +++ b/plugins/OStatus/lib/salmon.php @@ -31,10 +31,10 @@ class Salmon const REL_SALMON = 'salmon'; const REL_MENTIONED = 'mentioned'; - // XXX: these are deprecated + // XXX: these are deprecated 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. * @@ -87,9 +87,10 @@ class Salmon // No keypair yet, let's generate one. $magickey = new Magicsig(); $magickey->generate($user->id); - } + } } else { - throw new Exception("Salmon invalid actor for signing"); + // TRANS: Exception. + throw new Exception(_m('Salmon invalid actor for signing.')); } try { @@ -100,11 +101,10 @@ class Salmon return $magic_env->toXML($env); } - public function verifyMagicEnv($text) { $magic_env = new MagicEnvelope(); - + $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 fa9dc3b1d..41bdb4892 100644 --- a/plugins/OStatus/lib/salmonaction.php +++ b/plugins/OStatus/lib/salmonaction.php @@ -38,36 +38,38 @@ class SalmonAction extends Action parent::prepare($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { + // TRANS: Client error. POST is a HTTP command. It should not be translated. $this->clientError(_m('This method requires a POST.')); } if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/magic-envelope+xml') { - $this->clientError(_m('Salmon requires application/magic-envelope+xml')); + // TRANS: Client error. Do not translate "application/magic-envelope+xml" + $this->clientError(_m('Salmon requires "application/magic-envelope+xml".')); } $xml = file_get_contents('php://input'); - // Check the signature $salmon = new Salmon; if (!$salmon->verifyMagicEnv($xml)) { common_log(LOG_DEBUG, "Salmon signature verification failed."); + // TRANS: Client error. $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"); + // TRANS: Client error. $this->clientError(_m('Salmon post must be an Atom entry.')); } - $this->act = new Activity($dom->documentElement); + $this->activity = new Activity($dom->documentElement); return true; } @@ -79,9 +81,9 @@ class SalmonAction extends Action { StatusNet::setApi(true); // Send smaller error pages - common_log(LOG_DEBUG, "Got a " . $this->act->verb); + common_log(LOG_DEBUG, "Got a " . $this->activity->verb); if (Event::handle('StartHandleSalmon', array($this->activity))) { - switch ($this->act->verb) + switch ($this->activity->verb) { case ActivityVerb::POST: $this->handlePost(); @@ -112,6 +114,7 @@ class SalmonAction extends Action $this->handleUpdateProfile(); break; default: + // TRANS: Client exception. throw new ClientException(_m("Unrecognized activity type.")); } Event::handle('EndHandleSalmon', array($this->activity)); @@ -120,41 +123,49 @@ class SalmonAction extends Action function handlePost() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand posts.")); } function handleFollow() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand follows.")); } function handleUnfollow() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand unfollows.")); } function handleFavorite() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand favorites.")); } function handleUnfavorite() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand unfavorites.")); } function handleShare() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand share events.")); } function handleJoin() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand joins.")); } function handleLeave() { + // TRANS: Client exception. throw new ClientException(_m("This target doesn't understand leave events.")); } @@ -164,12 +175,12 @@ class SalmonAction extends Action */ function handleUpdateProfile() { - $oprofile = Ostatus_profile::getActorProfile($this->act); + $oprofile = Ostatus_profile::getActorProfile($this->activity); if ($oprofile) { common_log(LOG_INFO, "Got a profile-update ping from $oprofile->uri"); - $oprofile->updateFromActivityObject($this->act->actor); + $oprofile->updateFromActivityObject($this->activity->actor); } else { - common_log(LOG_INFO, "Ignoring profile-update ping from unknown " . $this->act->actor->id); + common_log(LOG_INFO, "Ignoring profile-update ping from unknown " . $this->activity->actor->id); } } @@ -178,11 +189,12 @@ class SalmonAction extends Action */ function ensureProfile() { - $actor = $this->act->actor; + $actor = $this->activity->actor; if (empty($actor->id)) { common_log(LOG_ERR, "broken actor: " . var_export($actor, true)); - common_log(LOG_ERR, "activity with no actor: " . var_export($this->act, true)); - throw new Exception("Received a salmon slap from unidentified actor."); + common_log(LOG_ERR, "activity with no actor: " . var_export($this->activity, true)); + // TRANS: Exception. + throw new Exception(_m('Received a salmon slap from unidentified actor.')); } return Ostatus_profile::ensureActivityObjectProfile($actor); @@ -191,6 +203,6 @@ class SalmonAction extends Action function saveNotice() { $oprofile = $this->ensureProfile(); - return $oprofile->processPost($this->act, 'salmon'); + return $oprofile->processPost($this->activity, 'salmon'); } } diff --git a/plugins/OStatus/lib/salmonqueuehandler.php b/plugins/OStatus/lib/salmonqueuehandler.php index 7eeb5f8e9..56d3c9eff 100644 --- a/plugins/OStatus/lib/salmonqueuehandler.php +++ b/plugins/OStatus/lib/salmonqueuehandler.php @@ -36,7 +36,7 @@ class SalmonQueueHandler extends QueueHandler assert(is_string($data['entry'])); $actor = Profile::staticGet($data['actor']); - + $salmon = new Salmon(); $salmon->post($data['salmonuri'], $data['entry'], $actor); diff --git a/plugins/OStatus/lib/xrd.php b/plugins/OStatus/lib/xrd.php deleted file mode 100644 index a10b9f427..000000000 --- a/plugins/OStatus/lib/xrd.php +++ /dev/null @@ -1,172 +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/ - */ - - -class XRD -{ - const XML_NS = 'http://www.w3.org/2000/xmlns/'; - - const XRD_NS = 'http://docs.oasis-open.org/ns/xri/xrd-1.0'; - - const HOST_META_NS = 'http://host-meta.net/xrd/1.0'; - - public $expires; - - public $subject; - - public $host; - - public $alias = array(); - - public $types = array(); - - public $links = array(); - - public static function parse($xml) - { - $xrd = new XRD(); - - $dom = new DOMDocument(); - - // Don't spew XML warnings to output - $old = error_reporting(); - error_reporting($old & ~E_WARNING); - $ok = $dom->loadXML($xml); - error_reporting($old); - - if (!$ok) { - 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); - if ($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; - break; - case 'Subject': - $xrd->subject = $node->nodeValue; - break; - - case 'Alias': - $xrd->alias[] = $node->nodeValue; - break; - - case 'Link': - $xrd->links[] = $xrd->parseLink($node); - break; - - case 'Type': - $xrd->types[] = $xrd->parseType($node); - break; - - } - } - return $xrd; - } - - public function toXML() - { - $xs = new XMLStringer(); - - $xs->startXML(); - $xs->elementStart('XRD', array('xmlns' => XRD::XRD_NS)); - - if ($this->host) { - $xs->element('hm:Host', array('xmlns:hm' => XRD::HOST_META_NS), $this->host); - } - - if ($this->expires) { - $xs->element('Expires', null, $this->expires); - } - - if ($this->subject) { - $xs->element('Subject', null, $this->subject); - } - - foreach ($this->alias as $alias) { - $xs->element('Alias', null, $alias); - } - - foreach ($this->links as $link) { - $titles = array(); - if (isset($link['title'])) { - $titles = $link['title']; - unset($link['title']); - } - $xs->elementStart('Link', $link); - foreach ($titles as $title) { - $xs->element('Title', null, $title); - } - $xs->elementEnd('Link'); - } - - $xs->elementEnd('XRD'); - - return $xs->getString(); - } - - function parseType($element) - { - return array(); - } - - function parseLink($element) - { - $link = array(); - $link['rel'] = $element->getAttribute('rel'); - $link['type'] = $element->getAttribute('type'); - $link['href'] = $element->getAttribute('href'); - $link['template'] = $element->getAttribute('template'); - foreach ($element->childNodes as $node) { - if ($node instanceof DOMElement) { - switch($node->tagName) { - case 'Title': - $link['title'][] = $node->nodeValue; - } - } - } - - return $link; - } -} - diff --git a/plugins/OStatus/lib/xrdaction.php b/plugins/OStatus/lib/xrdaction.php index d8cf648d6..c8b5beff3 100644 --- a/plugins/OStatus/lib/xrdaction.php +++ b/plugins/OStatus/lib/xrdaction.php @@ -26,13 +26,12 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } class XrdAction extends Action { - public $uri; - + public $user; public $xrd; - + function handle() { $nick = $this->user->nickname; @@ -104,5 +103,4 @@ class XrdAction extends Action header('Content-type: application/xrd+xml'); print $xrd->toXML(); } - } |