]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Squashed commit of the following:
authorZach Copley <zach@status.net>
Fri, 15 Jul 2011 19:13:57 +0000 (12:13 -0700)
committerZach Copley <zach@status.net>
Fri, 15 Jul 2011 19:13:57 +0000 (12:13 -0700)
Move OMB to a plugin

commit 75d21f00246bcc56d7f854936be1e28395e079a2
Merge: cea0199 d594d07
Author: Zach Copley <zach@status.net>
Date:   Fri Jul 15 11:16:54 2011 -0700

    Merge branch 'kill-omb2' of gitorious.org:~zcopley/statusnet/zcopleys-clone into kill-omb2

    * 'kill-omb2' of gitorious.org:~zcopley/statusnet/zcopleys-clone:
      Fix paths
      Oops, I left out the ability to authorize a token in ApiStatusNetOAuthDataStore
      Some odds and ends
      Remove omb stuff from queuemanager defaults
      Add check to make sure we're not untagging an OMB profile to OMB plugin
      Move some more subscription stuff and peopletag checks to OMB plugin
      Move some OMB-specific unsubscribe stuff to OMB plugin
      Finish removing libomb from core extlibs
      Fix more conflicts
      Fix queuing/queuehandling
      Move some stuff around; fix references
      Fix conflicts
      Move OMB-specific files to OMB plugin
      Move some stuff around; fix references
      Add OMB plugin README and rm references to OMB in mail StatusNet README
      Update paths
      Fix define
      Basic plugin finished
      Move OMB-specific files to OMB plugin
      Remove OMB stuff from router

commit cea019967f343042ebaea14b7bbb0d54289bcc1a
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 13 14:38:40 2011 -0700

    Fix paths

commit d412aa3c0ea0e21e65a72a16c7b9edd64ff373e1
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 12 18:17:06 2011 -0700

    Oops, I left out the ability to authorize a token in ApiStatusNetOAuthDataStore

commit b459c9f10ac283d6e774ef13f3293fc8a6948143
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 19:02:08 2011 -0700

    Some odds and ends

commit 895cfbfce58ffb3a05beebf48a90c549e00f1cce
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 19:01:23 2011 -0700

    Remove omb stuff from queuemanager defaults

commit b41b9e994f291ff83afb2460d9b37aee8ec1ec2b
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 18:46:44 2011 -0700

    Add check to make sure we're not untagging an OMB profile to OMB plugin

commit 94374d26ddd428dac8e4cd4541fd56db748c248b
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 18:34:20 2011 -0700

    Move some more subscription stuff and peopletag checks to OMB plugin

commit b91043b7820d5cd8b0ba4e9ee2a9d03c99248f11
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 16:37:25 2011 -0700

    Move some OMB-specific unsubscribe stuff to OMB plugin

commit d9430fe52975d9497b4a0d3d54da35b222e207ad
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 15:26:30 2011 -0700

    Finish removing libomb from core extlibs

commit bb6257eb85cc7ba392e91468c01503f51faeb989
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 13 12:47:32 2011 -0700

    Fix more conflicts

commit 3c760d0a4b4a083ae5fca2530d22aad5f4a9fdae
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:49:22 2011 -0700

    Fix queuing/queuehandling

commit ed635fa0c20e150673709c04ecc7f285d12e0ce2
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:29:35 2011 -0700

    Move some stuff around; fix references

commit cbc553a147941cad16e205a6b66ab4b32a5e3d3d
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 13 12:46:05 2011 -0700

    Fix conflicts

commit 5d77c81f75b57f5d5357d6b46d503650a4b3225d
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 19:10:38 2011 -0700

    Move OMB-specific files to OMB plugin

commit 2ed051dbce0ce9b44723b14922026849c39ed603
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:29:35 2011 -0700

    Move some stuff around; fix references

commit 8809b5e35b1aacb67d70ae3e55a43003b6f591b7
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:28:59 2011 -0700

    Add OMB plugin README and rm references to OMB in mail StatusNet README

commit 35ced4067c1915baca0b3e184f9533a91a951d2d
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 23:50:09 2011 -0700

    Update paths

commit 0ee5bafbce95fc9b8db98c1e828d33d26d08bc73
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 23:38:03 2011 -0700

    Fix define

commit e309dd22ffb9087d7fcf9180ede4f531dbd88c3c
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 23:30:43 2011 -0700

    Basic plugin finished

commit 00f1e930f27e080b04d1e82952f7886c84e01d97
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 19:10:38 2011 -0700

    Move OMB-specific files to OMB plugin

commit 39dcd031a79b49da0b4fe25f1594d2e406b5eb65
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 19:10:01 2011 -0700

    Remove OMB stuff from router

commit d594d071be1ec42518dd5465db61e01e7e8ec036
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 13 14:38:40 2011 -0700

    Fix paths

commit 48c1064b4b50e89cf51d2cab388f708f60601247
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 12 18:17:06 2011 -0700

    Oops, I left out the ability to authorize a token in ApiStatusNetOAuthDataStore

commit 1e1168978f38c31dbf0206b3493b2b6dcbe61589
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 19:02:08 2011 -0700

    Some odds and ends

commit ac43af2b497d8b9286c49a9469a1dff950e41650
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 19:01:23 2011 -0700

    Remove omb stuff from queuemanager defaults

commit 2471af2f8800515a3db544b3a186a18f3e8a43af
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 18:46:44 2011 -0700

    Add check to make sure we're not untagging an OMB profile to OMB plugin

commit df974646459ac6d5d97a40d008f1aab66f998226
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 18:34:20 2011 -0700

    Move some more subscription stuff and peopletag checks to OMB plugin

commit 8a1427b759e791c14a7a7a22128ba05f0b4b6d12
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 16:37:25 2011 -0700

    Move some OMB-specific unsubscribe stuff to OMB plugin

commit bd24220dbb5170af22ea0dea8a3062e6d1aeb6a2
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 6 15:26:30 2011 -0700

    Finish removing libomb from core extlibs

commit 4c3c6f1fabb0f2c92635ccc5e8f38db2293f5456
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 13 12:47:32 2011 -0700

    Fix more conflicts

commit db44deefd731a412685c5669c4c6fa69833de922
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:49:22 2011 -0700

    Fix queuing/queuehandling

commit ea2d84d2f3d518950d3aa1956ddc8f3a25ca55f3
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:29:35 2011 -0700

    Move some stuff around; fix references

commit 8ac3e010444b41bd9a78766f5e37e49dff023b45
Author: Zach Copley <zach@status.net>
Date:   Wed Jul 13 12:46:05 2011 -0700

    Fix conflicts

commit 0aad6e10e3637b3189a87b42c24c1d6de1b346bc
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 19:10:38 2011 -0700

    Move OMB-specific files to OMB plugin

commit d982d7076c5cb28c7b8e4b1dde8d07d7e58e278f
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:29:35 2011 -0700

    Move some stuff around; fix references

commit 4b9d39c93562ff4c45c37c940013e8b78197dec1
Author: Zach Copley <zach@status.net>
Date:   Tue Jul 5 15:28:59 2011 -0700

    Add OMB plugin README and rm references to OMB in mail StatusNet README

commit dab0fb6647a85e6835298496d7127a398b6b9293
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 23:50:09 2011 -0700

    Update paths

commit 2cb73dac8ad971f1545dcf6ba57746c777e232ef
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 23:38:03 2011 -0700

    Fix define

commit 6f226b18a059f175b1bdd3abcb8cb95eedc22ee7
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 23:30:43 2011 -0700

    Basic plugin finished

commit 7be304beaa0f39755c3978e0b852fde768950da4
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 19:10:38 2011 -0700

    Move OMB-specific files to OMB plugin

commit 5b30da01cfa2802d6e7a4a4a4f39b8043c54f472
Author: Zach Copley <zach@status.net>
Date:   Thu Jun 30 19:10:01 2011 -0700

    Remove OMB stuff from router

78 files changed:
README
actions/accesstoken.php [deleted file]
actions/addpeopletag.php
actions/apioauthauthorize.php
actions/finishremotesubscribe.php [deleted file]
actions/oauthconnectionssettings.php
actions/postnotice.php [deleted file]
actions/remotesubscribe.php [deleted file]
actions/removepeopletag.php
actions/requesttoken.php [deleted file]
actions/shownotice.php
actions/subscribe.php
actions/updateprofile.php [deleted file]
actions/userauthorization.php [deleted file]
actions/xrds.php [deleted file]
classes/Notice.php
classes/Profile.php
classes/Subscription.php
extlib/libomb/base_url_xrds_mapper.php [deleted file]
extlib/libomb/constants.php [deleted file]
extlib/libomb/datastore.php [deleted file]
extlib/libomb/helper.php [deleted file]
extlib/libomb/invalidparameterexception.php [deleted file]
extlib/libomb/invalidyadisexception.php [deleted file]
extlib/libomb/notice.php [deleted file]
extlib/libomb/omb_yadis_xrds.php [deleted file]
extlib/libomb/plain_xrds_writer.php [deleted file]
extlib/libomb/profile.php [deleted file]
extlib/libomb/remoteserviceexception.php [deleted file]
extlib/libomb/service_consumer.php [deleted file]
extlib/libomb/service_provider.php [deleted file]
extlib/libomb/unsupportedserviceexception.php [deleted file]
extlib/libomb/xrds_mapper.php [deleted file]
extlib/libomb/xrds_writer.php [deleted file]
lib/apioauth.php
lib/apioauthstore.php [deleted file]
lib/microappplugin.php
lib/oauthstore.php [deleted file]
lib/omb.php [deleted file]
lib/ombqueuehandler.php [deleted file]
lib/profilelist.php
lib/profilequeuehandler.php [deleted file]
lib/queuemanager.php
lib/router.php
lib/statusnetoauthstore.php [new file with mode: 0644]
lib/util.php
plugins/Bookmark/BookmarkPlugin.php
plugins/OMB/OMBPlugin.php [new file with mode: 0644]
plugins/OMB/README [new file with mode: 0644]
plugins/OMB/actions/accesstoken.php [new file with mode: 0644]
plugins/OMB/actions/finishremotesubscribe.php [new file with mode: 0644]
plugins/OMB/actions/postnotice.php [new file with mode: 0644]
plugins/OMB/actions/remotesubscribe.php [new file with mode: 0644]
plugins/OMB/actions/requesttoken.php [new file with mode: 0644]
plugins/OMB/actions/updateprofile.php [new file with mode: 0644]
plugins/OMB/actions/userauthorization.php [new file with mode: 0644]
plugins/OMB/actions/xrds.php [new file with mode: 0644]
plugins/OMB/extlib/libomb/base_url_xrds_mapper.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/constants.php [new file with mode: 0644]
plugins/OMB/extlib/libomb/datastore.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/helper.php [new file with mode: 0644]
plugins/OMB/extlib/libomb/invalidparameterexception.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/invalidyadisexception.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/notice.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/omb_yadis_xrds.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/plain_xrds_writer.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/profile.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/remoteserviceexception.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/service_consumer.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/service_provider.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/unsupportedserviceexception.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/xrds_mapper.php [new file with mode: 0755]
plugins/OMB/extlib/libomb/xrds_writer.php [new file with mode: 0755]
plugins/OMB/lib/omb.php [new file with mode: 0644]
plugins/OMB/lib/omboauthstore.php [new file with mode: 0644]
plugins/OMB/lib/ombqueuehandler.php [new file with mode: 0644]
plugins/OMB/lib/profilequeuehandler.php [new file with mode: 0644]
plugins/OStatus/classes/Ostatus_profile.php

diff --git a/README b/README
index f5a0e27cc54873e752448a02f22498342ad41160..6a0633144b8772ad7745f17a5d0add8836dd6646 100644 (file)
--- a/README
+++ b/README
@@ -226,7 +226,6 @@ and the URLs are listed here for your convenience.
 - Facebook library. Used for the Facebook application.
 - PEAR Validate is used for URL and email validation.
 - Console_GetOpt for parsing command-line options.
-- libomb. a library for implementing OpenMicroBlogging 0.1, the
   predecessor to OStatus.
 - HTTP_Request2, a library for making HTTP requests.
 - PEAR Net_URL2 is an HTTP_Request2 dependency.
@@ -484,7 +483,7 @@ On a default installation, your site can broadcast messages using
 XMPP. Users won't be able to post messages using XMPP unless you've
 got the XMPP daemon running.  See 'Queues and daemons' below for how
 to set that up. Also, once you have a sizable number of users, sending
-a lot of SMS, OMB, and XMPP messages whenever someone posts a message
+a lot of SMS, OStatus, and XMPP messages whenever someone posts a message
 can really slow down your site; it may cause posting to timeout.
 
 NOTE: stream_select(), a crucial function for network programming, is
@@ -1111,7 +1110,7 @@ public
 For configuring the public stream.
 
 localonly: If set to true, only messages posted by users of this
-    service (rather than other services, filtered through OMB)
+    service (rather than other services, filtered through OStatus)
     are shown in the public stream. Default true.
 blacklist: An array of IDs of users to hide from the public stream.
     Useful if you have someone making excessive Twitterfeed posts
diff --git a/actions/accesstoken.php b/actions/accesstoken.php
deleted file mode 100644 (file)
index bfb771b..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/**
- * Access token class
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
-require_once INSTALLDIR.'/lib/omb.php';
-
-/**
- * Access token class
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- */
-class AccesstokenAction extends Action
-{
-    /**
-     * Class handler
-     *
-     * @param array $args query arguments
-     *
-     * @return nothing
-     *
-     **/
-    function handle($args)
-    {
-        parent::handle($args);
-        try {
-            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
-                                            omb_oauth_server());
-            $srv->writeAccessToken();
-        } catch (Exception $e) {
-            $this->serverError($e->getMessage());
-        }
-    }
-}
index 1e130e27e858328d52585973adf6d20856a90d58..a661104d5c96b3b763304a22c6c066d1303ddc63 100644 (file)
@@ -111,18 +111,6 @@ class AddpeopletagAction extends Action
             return false;
         }
 
-        // OMB 0.1 doesn't have a mechanism for local-server-
-        // originated tag.
-
-        $omb01 = Remote_profile::staticGet('id', $tagged_id);
-
-        if (!empty($omb01)) {
-            // TRANS: Client error displayed when trying to add an OMB 0.1 remote profile to a list.
-            $this->clientError(_('You cannot list an OMB 0.1 '.
-                                 'remote profile with this action.'));
-            return false;
-        }
-
         return true;
     }
 
index 3a83fd27fc2d8590da217217233902fc3c797692..1755c36be3190fa68e0e87230b2c025cb51d9b13 100644 (file)
@@ -22,7 +22,7 @@
  * @category  API
  * @package   StatusNet
  * @author    Zach Copley <zach@status.net>
- * @copyright 2010 StatusNet, Inc.
+ * @copyright 2010-2011 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -35,7 +35,7 @@ require_once INSTALLDIR . '/lib/apioauth.php';
 require_once INSTALLDIR . '/lib/info.php';
 
 /**
- * Authorize an Oputh request token
+ * Authorize an OAuth request token
  *
  * @category API
  * @package  StatusNet
diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php
deleted file mode 100644 (file)
index 59725af..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-<?php
-/**
- * Handler for remote subscription finish callback
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- **/
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/extlib/libomb/service_consumer.php';
-require_once INSTALLDIR.'/lib/omb.php';
-
-/**
- * Handler for remote subscription finish callback
- *
- * When a remote user subscribes a local user, a redirect to this action is
- * issued after the remote user authorized their service to subscribe.
- *
- * @category Action
- * @package  Laconica
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@controlyourself.ca>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://laconi.ca/
- */
-class FinishremotesubscribeAction extends Action
-{
-    /**
-     * Class handler.
-     *
-     * @param array $args query arguments
-     *
-     * @return nothing
-     *
-     */
-    function handle($args)
-    {
-        parent::handle($args);
-
-        /* Restore session data. RemotesubscribeAction should have stored
-           this entry. */
-        $service  = unserialize($_SESSION['oauth_authorization_request']);
-
-        if (!$service) {
-            // TRANS: Client error displayed when subscribing to a remote profile and an unexpected response is received.
-            $this->clientError(_('Not expecting this response!'));
-            return;
-        }
-
-        common_debug('stored request: '. print_r($service, true), __FILE__);
-
-        /* Create user objects for both users. Do it early for request
-           validation. */
-        $user = User::staticGet('uri', $service->getListeneeURI());
-
-        if (!$user) {
-            // TRANS: Client error displayed when subscribing to a remote profile that does not exist.
-            $this->clientError(_('User being listened to does not exist.'));
-            return;
-        }
-
-        $other = User::staticGet('uri', $service->getListenerURI());
-
-        if ($other) {
-            // TRANS: Client error displayed when subscribing to a remote profile that is a local profile.
-            $this->clientError(_('You can use the local subscription!'));
-            return;
-        }
-
-        $remote = Remote_profile::staticGet('uri', $service->getListenerURI());
-        if ($remote) {
-            // Note remote profile may not have been saved yet.
-            // @fixme not convinced this is correct at all!
-
-            $profile = Profile::staticGet($remote->id);
-
-            if ($user->hasBlocked($profile)) {
-                // TRANS: Client error displayed when subscribing to a remote profile that is blocked form subscribing to.
-                $this->clientError(_('That user has blocked you from subscribing.'));
-                return;
-            }
-        }
-
-        /* Perform the handling itself via libomb. */
-        try {
-            $service->finishAuthorization();
-        } catch (OAuthException $e) {
-            if ($e->getMessage() == 'The authorized token does not equal the ' .
-                                    'submitted token.') {
-                // TRANS: Client error displayed when subscribing to a remote profile without providing an authorised token.
-                $this->clientError(_('You are not authorized.'));
-                return;
-            } else {
-                // TRANS: Client error displayed when subscribing to a remote profile and conversion of the request token to access token fails.
-                $this->clientError(_('Could not convert request token to ' .
-                                     'access token.'));
-                return;
-            }
-        } catch (OMB_RemoteServiceException $e) {
-            // TRANS: Client error displayed when subscribing to a remote profile fails because of an unsupported version of the OMB protocol.
-            $this->clientError(_('Remote service uses unknown version of ' .
-                                 'OMB protocol.'));
-            return;
-        } catch (Exception $e) {
-            common_debug('Got exception ' . print_r($e, true), __FILE__);
-            $this->clientError($e->getMessage());
-            return;
-        }
-
-        /* The service URLs are not accessible from datastore, so setting them
-           after insertion of the profile. */
-        $remote = Remote_profile::staticGet('uri', $service->getListenerURI());
-        $orig_remote = clone($remote);
-
-        $remote->postnoticeurl    =
-                            $service->getServiceURI(OMB_ENDPOINT_POSTNOTICE);
-        $remote->updateprofileurl =
-                            $service->getServiceURI(OMB_ENDPOINT_UPDATEPROFILE);
-
-        if (!$remote->update($orig_remote)) {
-                // TRANS: Server error displayed when subscribing to a remote profile fails because the remote profile could not be updated.
-                $this->serverError(_('Error updating remote profile.'));
-                return;
-        }
-
-        /* Clear the session data. */
-        unset($_SESSION['oauth_authorization_request']);
-
-        /* If we show subscriptions in reverse chronological order, the new one
-           should show up close to the top of the page. */
-        common_redirect(common_local_url('subscribers', array('nickname' =>
-                                                             $user->nickname)),
-                        303);
-    }
-}
index 5c667309317c17e9c6a7a8e836ae6e5093e69ab7..80fac0d50953826ce54253592e825dde1060be4d 100644 (file)
@@ -32,7 +32,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
 }
 
 require_once INSTALLDIR . '/lib/applicationlist.php';
-require_once INSTALLDIR . '/lib/apioauthstore.php';
+require_once INSTALLDIR . '/lib/statusnetoauthstore.php';
 
 /**
  * Show connected OAuth applications
diff --git a/actions/postnotice.php b/actions/postnotice.php
deleted file mode 100644 (file)
index 43c764a..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-/**
- * Handle postnotice action
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/lib/omb.php';
-require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
-
-/**
- * Handler for postnotice action
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- */
-class PostnoticeAction extends Action
-{
-    /**
-     * For initializing members of the class.
-     *
-     * @param array $argarray misc. arguments
-     *
-     * @return boolean true
-     */
-    function prepare($argarray)
-    {
-        StatusNet::setApi(true); // Send smaller error pages
-
-        parent::prepare($argarray);
-
-        try {
-            $this->checkNotice();
-        } catch (Exception $e) {
-            $this->clientError($e->getMessage());
-            return false;
-        }
-        return true;
-    }
-
-    function handle($args)
-    {
-        parent::handle($args);
-        try {
-            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
-                                            omb_oauth_server());
-            $srv->handlePostNotice();
-        } catch (OMB_RemoteServiceException $rse) {
-            $msg = $rse->getMessage();
-            if (preg_match('/Revoked accesstoken/', $msg) ||
-                preg_match('/No subscriber/', $msg)) {
-                $this->clientError($msg, 403);
-            } else {
-                $this->clientError($msg);
-            }
-        } catch (Exception $e) {
-            $this->serverError($e->getMessage());
-            return;
-        }
-    }
-
-    function checkNotice()
-    {
-        $content = common_shorten_links($_POST['omb_notice_content']);
-        if (Notice::contentTooLong($content)) {
-            // TRANS: Client error displayed if the notice posted has too many characters.
-            $this->clientError(_('Invalid notice content.'), 400);
-            return false;
-        }
-        $license      = $_POST['omb_notice_license'];
-        $site_license = common_config('license', 'url');
-        if ($license && !common_compatible_license($license, $site_license)) {
-            // TRANS: Exception thrown if a notice's license is not compatible with the StatusNet site license.
-            // TRANS: %1$s is the notice license, %2$s is the StatusNet site's license.
-            throw new Exception(sprintf(_('Notice license "%1$s" is not ' .
-                                          'compatible with site license "%2$s".'),
-                                        $license, $site_license));
-        }
-    }
-}
diff --git a/actions/remotesubscribe.php b/actions/remotesubscribe.php
deleted file mode 100644 (file)
index 1694512..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-<?php
-/**
- * Handler for remote subscription
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- **/
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/lib/omb.php';
-require_once INSTALLDIR.'/extlib/libomb/service_consumer.php';
-require_once INSTALLDIR.'/extlib/libomb/profile.php';
-
-/**
- * Handler for remote subscription
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- */
-class RemotesubscribeAction extends Action
-{
-    var $nickname;
-    var $profile_url;
-    var $err;
-
-    function prepare($args)
-    {
-        parent::prepare($args);
-
-        if (common_logged_in()) {
-            // TRANS: Client error displayed when using remote subscribe for a local entity.
-            $this->clientError(_('You can use the local subscription!'));
-            return false;
-        }
-
-        $this->nickname    = $this->trimmed('nickname');
-        $this->profile_url = $this->trimmed('profile_url');
-
-        return true;
-    }
-
-    function handle($args)
-    {
-        parent::handle($args);
-
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-            /* Use a session token for CSRF protection. */
-            $token = $this->trimmed('token');
-            if (!$token || $token != common_session_token()) {
-                // TRANS: Client error displayed when the session token does not match or is not given.
-                $this->showForm(_('There was a problem with your session token. '.
-                                  'Try again, please.'));
-                return;
-            }
-            $this->remoteSubscription();
-        } else {
-            $this->showForm();
-        }
-    }
-
-    function showForm($err=null)
-    {
-        $this->err = $err;
-        $this->showPage();
-    }
-
-    function showPageNotice()
-    {
-        if ($this->err) {
-            $this->element('div', 'error', $this->err);
-        } else {
-            // TRANS: Page notice for remote subscribe. This message contains Markdown links.
-            // TRANS: Ensure to keep the correct markup of [link description](link).
-            $inst = _('To subscribe, you can [login](%%action.login%%),' .
-                      ' or [register](%%action.register%%) a new ' .
-                      ' account. If you already have an account ' .
-                      ' on a [compatible microblogging site](%%doc.openmublog%%), ' .
-                      ' enter your profile URL below.');
-            $output = common_markup_to_html($inst);
-            $this->elementStart('div', 'instructions');
-            $this->raw($output);
-            $this->elementEnd('div');
-        }
-    }
-
-    function title()
-    {
-        // TRANS: Page title for Remote subscribe.
-        return _('Remote subscribe');
-    }
-
-    function showContent()
-    {
-        /* The id 'remotesubscribe' conflicts with the
-           button on profile page. */
-        $this->elementStart('form', array('id' => 'form_remote_subscribe',
-                                          'method' => 'post',
-                                          'class' => 'form_settings',
-                                          'action' => common_local_url('remotesubscribe')));
-        $this->elementStart('fieldset');
-        // TRANS: Field legend on page for remote subscribe.
-        $this->element('legend', _('Subscribe to a remote user'));
-        $this->hidden('token', common_session_token());
-
-        $this->elementStart('ul', 'form_data');
-        $this->elementStart('li');
-        // TRANS: Field label on page for remote subscribe.
-        $this->input('nickname', _('User nickname'), $this->nickname,
-                     // TRANS: Field title on page for remote subscribe.
-                     _('Nickname of the user you want to follow.'));
-        $this->elementEnd('li');
-        $this->elementStart('li');
-        // TRANS: Field label on page for remote subscribe.
-        $this->input('profile_url', _('Profile URL'), $this->profile_url,
-                     // TRANS: Field title on page for remote subscribe.
-                     _('URL of your profile on another compatible microblogging service.'));
-        $this->elementEnd('li');
-        $this->elementEnd('ul');
-        // TRANS: Button text on page for remote subscribe.
-        $this->submit('submit', _m('BUTTON','Subscribe'));
-        $this->elementEnd('fieldset');
-        $this->elementEnd('form');
-    }
-
-    function remoteSubscription()
-    {
-        if (!$this->nickname) {
-            // TRANS: Form validation error on page for remote subscribe when no user was provided.
-            $this->showForm(_('No such user.'));
-            return;
-        }
-
-        $user = User::staticGet('nickname', $this->nickname);
-
-        $this->profile_url = $this->trimmed('profile_url');
-
-        if (!$this->profile_url) {
-            // TRANS: Form validation error on page for remote subscribe when no user profile was found.
-            $this->showForm(_('No such user.'));
-            return;
-        }
-
-        if (!common_valid_http_url($this->profile_url)) {
-            // TRANS: Form validation error on page for remote subscribe when an invalid profile URL was provided.
-            $this->showForm(_('Invalid profile URL (bad format).'));
-            return;
-        }
-
-        try {
-            $service = new OMB_Service_Consumer($this->profile_url,
-                                                common_root_url(),
-                                                omb_oauth_datastore());
-        } catch (OMB_InvalidYadisException $e) {
-            // TRANS: Form validation error on page for remote subscribe when no the provided profile URL
-            // TRANS: does not contain expected data.
-            $this->showForm(_('Not a valid profile URL (no YADIS document or ' .
-                              'invalid XRDS defined).'));
-            return;
-        }
-
-        if ($service->getServiceURI(OAUTH_ENDPOINT_REQUEST) ==
-            common_local_url('requesttoken') ||
-            User::staticGet('uri', $service->getRemoteUserURI())) {
-            // TRANS: Form validation error on page for remote subscribe.
-            $this->showForm(_('That is a local profile! Login to subscribe.'));
-            return;
-        }
-
-        try {
-            $service->requestToken();
-        } catch (OMB_RemoteServiceException $e) {
-            // TRANS: Form validation error on page for remote subscribe when the remote service is not providing a request token.
-            $this->showForm(_('Could not get a request token.'));
-            return;
-        }
-
-        /* Create an OMB_Profile from $user. */
-        $profile = $user->getProfile();
-        if (!$profile) {
-            common_log_db_error($user, 'SELECT', __FILE__);
-            // TRANS: Error message displayed when referring to a user without a profile.
-            $this->serverError(_('User has no profile.'));
-            return;
-        }
-
-        $target_url = $service->requestAuthorization(
-                                   profile_to_omb_profile($user->uri, $profile),
-                                   common_local_url('finishremotesubscribe'));
-
-        common_ensure_session();
-
-        $_SESSION['oauth_authorization_request'] = serialize($service);
-
-        /* Redirect to the remote service for authorization. */
-        common_redirect($target_url, 303);
-    }
-}
index 6943f35ed1cbb3eb694737ba69b62ffbe544c6b9..d27175f566ab7f3d17f8ca56edfea14d8583931a 100644 (file)
@@ -112,18 +112,6 @@ class RemovepeopletagAction extends Action
             return false;
         }
 
-        // OMB 0.1 doesn't have a mechanism for local-server-
-        // originated tag.
-
-        $omb01 = Remote_profile::staticGet('id', $tagged_id);
-
-        if (!empty($omb01)) {
-            // TRANS: Client error displayed when trying to (un)list an OMB 0.1 remote profile.
-            $this->clientError(_('You cannot (un)list an OMB 0.1 '.
-                                 'remote profile with this action.'));
-            return false;
-        }
-
         return true;
     }
 
diff --git a/actions/requesttoken.php b/actions/requesttoken.php
deleted file mode 100644 (file)
index 3c8cea0..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-/**
- * Request token action class.
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once INSTALLDIR.'/lib/omb.php';
-require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
-
-/**
- * Request token action class.
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- */
-class RequesttokenAction extends Action
-{
-     /**
-     * Is read only?
-     *
-     * @return boolean false
-     */
-    function isReadOnly()
-    {
-        return false;
-    }
-
-    /**
-     * Class handler.
-     *
-     * @param array $args array of arguments
-     *
-     * @return void
-     */
-    function handle($args)
-    {
-        parent::handle($args);
-        try {
-            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
-                                            omb_oauth_server());
-            $srv->writeRequestToken();
-        } catch (Exception $e) {
-            $this->serverError($e->getMessage());
-        }
-    }
-}
index 5501a0af42b0c6f38f566dda03b84f3cb8e2892e..6055184fcdf2ced037e4cf8bde2dee2be15ebad2 100644 (file)
@@ -214,7 +214,7 @@ class ShownoticeAction extends Action
         if ($this->boolean('ajax')) {
             $this->showAjax();
         } else {
-            if ($this->notice->is_local == Notice::REMOTE_OMB) {
+            if ($this->notice->is_local == Notice::REMOTE) {
                 if (!empty($this->notice->url)) {
                     $target = $this->notice->url;
                 } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
index b8c1cdd8f78bbe3c663dda13f48b706d14155242..ce1d367cf894fe01a009a23dfe62d82423cecb5a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008-2010, StatusNet, Inc.
+ * Copyright (C) 2008-2011, StatusNet, Inc.
  *
  * Subscription action.
  *
@@ -111,18 +111,6 @@ class SubscribeAction extends Action
             return false;
         }
 
-        // OMB 0.1 doesn't have a mechanism for local-server-
-        // originated subscription.
-
-        $omb01 = Remote_profile::staticGet('id', $other_id);
-
-        if (!empty($omb01)) {
-            // TRANS: Client error displayed trying to subscribe to an OMB 0.1 remote profile.
-            $this->clientError(_('You cannot subscribe to an OMB 0.1'.
-                                 ' remote profile with this action.'));
-            return false;
-        }
-
         return true;
     }
 
diff --git a/actions/updateprofile.php b/actions/updateprofile.php
deleted file mode 100644 (file)
index e5c0803..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-/**
- * Handle an updateprofile action
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/lib/omb.php';
-require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
-
-/**
- * Handle an updateprofile action
- *
- * @category Action
- * @package  Laconica
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@controlyourself.ca>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://laconi.ca/
- */
-class UpdateprofileAction extends Action
-{
-    /**
-     * For initializing members of the class.
-     *
-     * @param array $argarray misc. arguments
-     *
-     * @return boolean true
-     */
-    function prepare($argarray)
-    {
-        StatusNet::setApi(true); // Send smaller error pages
-
-        parent::prepare($argarray);
-        $license      = $_POST['omb_listenee_license'];
-        $site_license = common_config('license', 'url');
-        if (!common_compatible_license($license, $site_license)) {
-            // TRANS: Client error displayed when trying to update profile with an incompatible license.
-            // TRANS: %1$s is the license incompatible with site license %2$s.
-            $this->clientError(sprintf(_('Listenee stream license "%1$s" is not '.
-                                         'compatible with site license "%2$s".'),
-                                       $license, $site_license));
-            return false;
-        }
-        return true;
-    }
-
-    function handle($args)
-    {
-        parent::handle($args);
-
-        try {
-            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
-                                            omb_oauth_server());
-            $srv->handleUpdateProfile();
-        } catch (OMB_RemoteServiceException $rse) {
-            $msg = $rse->getMessage();
-            if (preg_match('/Revoked accesstoken/', $msg) ||
-                preg_match('/No subscriber/', $msg)) {
-                $this->clientError($msg, 403);
-            } else {
-                $this->clientError($msg);
-            }
-        } catch (Exception $e) {
-            $this->serverError($e->getMessage());
-            return;
-        }
-    }
-}
diff --git a/actions/userauthorization.php b/actions/userauthorization.php
deleted file mode 100644 (file)
index 0cb5571..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-<?php
-/**
- * Let the user authorize a remote subscription request
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/lib/omb.php';
-require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
-require_once INSTALLDIR.'/extlib/libomb/profile.php';
-define('TIMESTAMP_THRESHOLD', 300);
-
-// @todo FIXME: Missing documentation.
-class UserauthorizationAction extends Action
-{
-    var $error;
-    var $params;
-
-    function handle($args)
-    {
-        parent::handle($args);
-
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-            /* Use a session token for CSRF protection. */
-            $token = $this->trimmed('token');
-            if (!$token || $token != common_session_token()) {
-                $srv = $this->getStoredParams();
-                // TRANS: Client error displayed when the session token does not match or is not given.
-                $this->showForm($srv->getRemoteUser(), _('There was a problem ' .
-                                        'with your session token. Try again, ' .
-                                        'please.'));
-                return;
-            }
-            /* We've shown the form, now post user's choice. */
-            $this->sendAuthorization();
-        } else {
-            if (!common_logged_in()) {
-                /* Go log in, and then come back. */
-                common_set_returnto($_SERVER['REQUEST_URI']);
-
-                common_redirect(common_local_url('login'));
-                return;
-            }
-
-            $user    = common_current_user();
-            $profile = $user->getProfile();
-            if (!$profile) {
-                common_log_db_error($user, 'SELECT', __FILE__);
-                // TRANS: Error message displayed when referring to a user without a profile.
-                $this->serverError(_('User has no profile.'));
-                return;
-            }
-
-            /* TODO: If no token is passed the user should get a prompt to enter
-               it according to OAuth Core 1.0. */
-            try {
-                $this->validateOmb();
-                $srv = new OMB_Service_Provider(
-                        profile_to_omb_profile($user->uri, $profile),
-                        omb_oauth_datastore());
-
-                $remote_user = $srv->handleUserAuth();
-            } catch (Exception $e) {
-                $this->clearParams();
-                $this->clientError($e->getMessage());
-                return;
-            }
-
-            $this->storeParams($srv);
-            $this->showForm($remote_user);
-        }
-    }
-
-    function showForm($params, $error=null)
-    {
-        $this->params = $params;
-        $this->error  = $error;
-        $this->showPage();
-    }
-
-    function title()
-    {
-        // TRANS: Page title.
-        return _('Authorize subscription');
-    }
-
-    function showPageNotice()
-    {
-        // TRANS: Page notice on "Authorize subscription" page.
-        $this->element('p', null, _('Please check these details to make sure '.
-                                    'that you want to subscribe to this ' .
-                                    'user’s notices. If you didn’t just ask ' .
-                                    'to subscribe to someone’s notices, '.
-                                    'click "Reject".'));
-    }
-
-    function showContent()
-    {
-        $params = $this->params;
-
-        $nickname = $params->getNickname();
-        $profile  = $params->getProfileURL();
-        $license  = $params->getLicenseURL();
-        $fullname = $params->getFullname();
-        $homepage = $params->getHomepage();
-        $bio      = $params->getBio();
-        $location = $params->getLocation();
-        $avatar   = $params->getAvatarURL();
-
-        $this->elementStart('div', 'entity_profile vcard');
-
-        if ($avatar) {
-            $this->element('img', array('src' => $avatar,
-                                        'class' => 'photo avatar entity_depiction',
-                                        'width' => AVATAR_PROFILE_SIZE,
-                                        'height' => AVATAR_PROFILE_SIZE,
-                                        'alt' => $nickname));
-        }
-
-        // TRANS: Label for nickname on user authorisation page.
-        $this->element('div', 'entity_nickname', _('Nickname'));
-
-        $hasFN = ($fullname !== '') ? 'nickname' : 'fn nickname';
-
-        // XXX: why are these raw() instead of escaped...?
-
-        $this->elementStart('a', array('href' => $profile,
-                                       'class' => 'url '.$hasFN));
-        $this->raw($nickname);
-        $this->elementEnd('a');
-
-        if (!is_null($fullname)) {
-            $this->elementStart('div', 'fn entity_fn');
-            $this->raw($fullname);
-            $this->elementEnd('div');
-        }
-
-        if (!is_null($location)) {
-            $this->elementStart('div', 'label entity_location');
-            $this->raw($location);
-        }
-
-        if (!is_null($homepage)) {
-            $this->elementStart('a', array('href' => $homepage,
-                                           'class' => 'url entity_url'));
-            $this->raw($homepage);
-            $this->elementEnd('a');
-        }
-
-        if (!is_null($bio)) {
-            $this->elementStart('div', 'note entity_note');
-            $this->raw($bio);
-            $this->elementEnd('dd');
-        }
-
-        if (!is_null($license)) {
-            $this->element('a', array('href' => $license,
-                                      'class' => 'license entity_license'),
-                           $license);
-        }
-
-        $this->elementEnd('div');
-
-        $this->elementStart('div', 'entity_actions');
-        $this->elementStart('ul');
-        $this->elementStart('li', 'entity_subscribe');
-        $this->elementStart('form', array('method' => 'post',
-                                          'id' => 'userauthorization',
-                                          'class' => 'form_user_authorization',
-                                          'name' => 'userauthorization',
-                                          'action' => common_local_url(
-                                                         'userauthorization')));
-        $this->hidden('token', common_session_token());
-
-        $this->submit('accept',
-                      // TRANS: Button text on Authorise Subscription page.
-                      _m('BUTTON','Accept'), 'submit accept', null,
-                      // TRANS: Title for button on Authorise Subscription page.
-                      _('Subscribe to this user.'));
-        $this->submit('reject',
-                      // TRANS: Button text on Authorise Subscription page.
-                      _m('BUTTON','Reject'), 'submit reject', null,
-                      // TRANS: Title for button on Authorise Subscription page.
-                      _('Reject this subscription.'));
-        $this->elementEnd('form');
-        $this->elementEnd('li');
-        $this->elementEnd('ul');
-        $this->elementEnd('div');
-    }
-
-    function sendAuthorization()
-    {
-        $srv = $this->getStoredParams();
-
-        if (is_null($srv)) {
-            // TRANS: Client error displayed for an empty authorisation request.
-            $this->clientError(_('No authorization request!'));
-            return;
-        }
-
-        $accepted = $this->arg('accept');
-        try {
-            list($val, $token) = $srv->continueUserAuth($accepted);
-        } catch (Exception $e) {
-            $this->clientError($e->getMessage());
-            return;
-        }
-        if ($val !== false) {
-            common_redirect($val, 303);
-        } elseif ($accepted) {
-            $this->showAcceptMessage($token);
-        } else {
-            $this->showRejectMessage();
-        }
-    }
-
-    function showAcceptMessage($tok)
-    {
-        // TRANS: Accept message header from Authorise subscription page.
-        common_show_header(_('Subscription authorized'));
-        $this->element('p', null,
-                       // TRANS: Accept message text from Authorise subscription page.
-                       _('The subscription has been authorized, but no '.
-                         'callback URL was passed. Check with the site\'s ' .
-                         'instructions for details on how to authorize the ' .
-                         'subscription. Your subscription token is:'));
-        $this->element('blockquote', 'token', $tok);
-        common_show_footer();
-    }
-
-    function showRejectMessage()
-    {
-        // TRANS: Reject message header from Authorise subscription page.
-        common_show_header(_('Subscription rejected'));
-        $this->element('p', null,
-                       // TRANS: Reject message from Authorise subscription page.
-                       _('The subscription has been rejected, but no '.
-                         'callback URL was passed. Check with the site\'s ' .
-                         'instructions for details on how to fully reject ' .
-                         'the subscription.'));
-        common_show_footer();
-    }
-
-    function storeParams($params)
-    {
-        common_ensure_session();
-        $_SESSION['userauthorizationparams'] = serialize($params);
-    }
-
-    function clearParams()
-    {
-        common_ensure_session();
-        unset($_SESSION['userauthorizationparams']);
-    }
-
-    function getStoredParams()
-    {
-        common_ensure_session();
-        $params = unserialize($_SESSION['userauthorizationparams']);
-        return $params;
-    }
-
-    function validateOmb()
-    {
-        $listener = $_GET['omb_listener'];
-        $listenee = $_GET['omb_listenee'];
-        $nickname = $_GET['omb_listenee_nickname'];
-        $profile  = $_GET['omb_listenee_profile'];
-
-        $user = User::staticGet('uri', $listener);
-        if (!$user) {
-            // TRANS: Exception thrown when no valid user is found for an authorisation request.
-            // TRANS: %s is a listener URI.
-            throw new Exception(sprintf(_('Listener URI "%s" not found here.'),
-                                        $listener));
-        }
-
-        if (strlen($listenee) > 255) {
-            // TRANS: Exception thrown when listenee URI is too long for an authorisation request.
-            // TRANS: %s is a listenee URI.
-            throw new Exception(sprintf(_('Listenee URI "%s" is too long.'),
-                                        $listenee));
-        }
-
-        $other = User::staticGet('uri', $listenee);
-        if ($other) {
-            // TRANS: Exception thrown when listenee URI is a local user for an authorisation request.
-            // TRANS: %s is a listenee URI.
-            throw new Exception(sprintf(_('Listenee URI "%s" is a local user.'),
-                                        $listenee));
-        }
-
-        $remote = Remote_profile::staticGet('uri', $listenee);
-        if ($remote) {
-            $sub             = new Subscription();
-            $sub->subscriber = $user->id;
-            $sub->subscribed = $remote->id;
-            if ($sub->find(true)) {
-                // TRANS: Exception thrown when already subscribed.
-                throw new Exception('You are already subscribed to this user.');
-            }
-        }
-
-        if ($profile == common_profile_url($nickname)) {
-            // TRANS: Exception thrown when profile URL is a local user for an authorisation request.
-            // TRANS: %s is a profile URL.
-            throw new Exception(sprintf(_('Profile URL "%s" is for a local user.'),
-                                        $profile));
-
-        }
-
-        $license      = $_GET['omb_listenee_license'];
-        $site_license = common_config('license', 'url');
-        if (!common_compatible_license($license, $site_license)) {
-            // TRANS: Exception thrown when licenses are not compatible for an authorisation request.
-            // TRANS: %1$s is the license for the listenee, %2$s is the license for "this" StatusNet site.
-            throw new Exception(sprintf(_('Listenee stream license "%1$s" is not ' .
-                                          'compatible with site license "%2$s".'),
-                                        $license, $site_license));
-        }
-
-        $avatar = $_GET['omb_listenee_avatar'];
-        if ($avatar) {
-            if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
-                // TRANS: Exception thrown when avatar URL is invalid for an authorisation request.
-                // TRANS: %s is an avatar URL.
-                throw new Exception(sprintf(_('Avatar URL "%s" is not valid.'),
-                                            $avatar));
-            }
-            $size = @getimagesize($avatar);
-            if (!$size) {
-                // TRANS: Exception thrown when avatar URL could not be read for an authorisation request.
-                // TRANS: %s is an avatar URL.
-                throw new Exception(sprintf(_('Cannot read avatar URL "%s".'),
-                                            $avatar));
-            }
-            if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG,
-                                          IMAGETYPE_PNG))) {
-                // TRANS: Exception thrown when avatar URL return an invalid image type for an authorisation request.
-                // TRANS: %s is an avatar URL.
-                throw new Exception(sprintf(_('Wrong image type for avatar URL '.
-                                              '"%s".'), $avatar));
-            }
-        }
-    }
-}
diff --git a/actions/xrds.php b/actions/xrds.php
deleted file mode 100644 (file)
index 818cd10..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-<?php
-/**
- * XRDS for OpenMicroBlogging
- *
- * PHP version 5
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- *
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once INSTALLDIR.'/lib/omb.php';
-require_once INSTALLDIR.'/extlib/libomb/service_provider.php';
-require_once INSTALLDIR.'/extlib/libomb/xrds_mapper.php';
-require_once INSTALLDIR.'/lib/xrdsoutputter.php';
-
-/**
- * XRDS for OpenMicroBlogging
- *
- * @category Action
- * @package  StatusNet
- * @author   Evan Prodromou <evan@status.net>
- * @author   Robin Millette <millette@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
- * @link     http://status.net/
- */
-class XrdsAction extends Action
-{
-    var $user;
-
-    /**
-     * Is read only?
-     *
-     * @return boolean true
-     */
-    function isReadOnly()
-    {
-        return true;
-    }
-
-    function prepare($args)
-    {
-        parent::prepare($args);
-        $nickname = $this->trimmed('nickname');
-        $this->user     = User::staticGet('nickname', $nickname);
-        if (!$this->user) {
-            // TRANS: Client error displayed providing a non-existing nickname.
-            $this->clientError(_('No such user.'));
-            return;
-        }
-        return true;
-    }
-
-    /**
-     * Class handler.
-     *
-     * @param array $args query arguments
-     *
-     * @return void
-     */
-    function handle($args)
-    {
-        parent::handle($args);
-        $xrdsOutputter = new XRDSOutputter();
-        $xrdsOutputter->startXRDS();
-
-        Event::handle('StartUserXRDS', array($this,&$xrdsOutputter));
-
-        //oauth
-        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
-                                          'xml:id' => 'oauth',
-                                          'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
-                                          'version' => '2.0'));
-        $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
-        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_REQUEST,
-                            common_local_url('requesttoken'),
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1),
-                            null,
-                            $this->user->uri);
-        $xrdsOutputter->showXrdsService( OAUTH_ENDPOINT_AUTHORIZE,
-                            common_local_url('userauthorization'),
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
-        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_ACCESS,
-                            common_local_url('accesstoken'),
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
-        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_RESOURCE,
-                            null,
-                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
-        $xrdsOutputter->elementEnd('XRD');
-
-        //omb
-        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
-                                          'xml:id' => 'omb',
-                                          'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
-                                          'version' => '2.0'));
-        $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
-        $xrdsOutputter->showXrdsService(OMB_ENDPOINT_POSTNOTICE,
-                            common_local_url('postnotice'));
-        $xrdsOutputter->showXrdsService(OMB_ENDPOINT_UPDATEPROFILE,
-                            common_local_url('updateprofile'));
-        $xrdsOutputter->elementEnd('XRD');
-
-        Event::handle('EndUserXRDS', array($this,&$xrdsOutputter));
-
-        //misc
-        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
-                                          'version' => '2.0'));
-        $xrdsOutputter->showXrdsService(OAUTH_DISCOVERY,
-                            '#oauth');
-        $xrdsOutputter->showXrdsService(OMB_VERSION,
-                            '#omb');
-        $xrdsOutputter->elementEnd('XRD');
-
-        $xrdsOutputter->endXRDS();
-    }
-}
index 29824ab700587eef371e1737d834914c2f332dd3..6eb4d9001e4c032f66d78ba8cac8f4f46c1c5a1d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2011 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
@@ -86,7 +86,7 @@ class Notice extends Memcached_DataObject
 
     /* Notice types */
     const LOCAL_PUBLIC    =  1;
-    const REMOTE_OMB      =  0;
+    const REMOTE          =  0;
     const LOCAL_NONPUBLIC = -1;
     const GATEWAY         = -2;
 
@@ -229,11 +229,11 @@ class Notice extends Memcached_DataObject
      *              string 'created' timestamp of notice; defaults to now
      *              int 'is_local' source/gateway ID, one of:
      *                  Notice::LOCAL_PUBLIC    - Local, ok to appear in public timeline
-     *                  Notice::REMOTE_OMB      - Sent from a remote OMB service;
+     *                  Notice::REMOTE          - Sent from a remote service;
      *                                            hide from public timeline but show in
      *                                            local "and friends" timelines
      *                  Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
-     *                  Notice::GATEWAY         - From another non-OMB service;
+     *                  Notice::GATEWAY         - From another non-OStatus service;
      *                                            will not appear in public views
      *              float 'lat' decimal latitude for geolocation
      *              float 'lon' decimal longitude for geolocation
index 2638f745f71227598cc9af97b2369470bafd1b16..23534dfdfd2f14ff8282452d9fcff38035fcf4e8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2011, 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
@@ -1240,13 +1240,8 @@ class Profile extends Memcached_DataObject
 
             if (!empty($user)) {
                 $uri = $user->uri;
-            } else {
-                // return OMB profile if any
-                $remote = Remote_profile::staticGet('id', $this->id);
-                if (!empty($remote)) {
-                    $uri = $remote->uri;
-                }
             }
+
             Event::handle('EndGetProfileUri', array($this, &$uri));
         }
 
@@ -1291,11 +1286,6 @@ class Profile extends Memcached_DataObject
             $user = User::staticGet('uri', $uri);
             if (!empty($user)) {
                 $profile = $user->getProfile();
-            } else {
-                $remote_profile = Remote_profile::staticGet('uri', $uri);
-                if (!empty($remote_profile)) {
-                    $profile = Profile::staticGet('id', $remote_profile->profile_id);
-                }
             }
             Event::handle('EndGetProfileFromURI', array($uri, $profile));
         }
index 8af414b3a7b3ff3048b565548e94260ed3bd3d46..e83621eb86ba3bac099f61504c62bc2905276a9c 100644 (file)
@@ -198,29 +198,6 @@ class Subscription extends Memcached_DataObject
 
             assert(!empty($sub));
 
-            // @todo: move this block to EndSubscribe handler for
-            // OMB plugin when it exists.
-
-            if (!empty($sub->token)) {
-
-                $token = new Token();
-
-                $token->tok    = $sub->token;
-
-                if ($token->find(true)) {
-
-                    $result = $token->delete();
-
-                    if (!$result) {
-                        common_log_db_error($token, 'DELETE', __FILE__);
-                        // TRANS: Exception thrown when the OMB token for a subscription could not deleted on the server.
-                        throw new Exception(_('Could not delete subscription OMB token.'));
-                    }
-                } else {
-                    common_log(LOG_ERR, "Couldn't find credentials with token {$token->tok}");
-                }
-            }
-
             $result = $sub->delete();
 
             if (!$result) {
diff --git a/extlib/libomb/base_url_xrds_mapper.php b/extlib/libomb/base_url_xrds_mapper.php
deleted file mode 100755 (executable)
index d45d6d6..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'xrds_mapper.php';
-require_once 'constants.php';
-
-/**
- * Map XRDS actions to URLs using base URLs
- *
- * This class realizes a simple mapping of action URIs to handler URLs. The
- * target URLs are constructed using a base URL.
- */
-class OMB_Base_URL_XRDS_Mapper implements OMB_XRDS_Mapper
-{
-    protected $urls;
-
-    /**
-     * Constructor
-     *
-     * Initialize the XRDS mapper with base URLs for OAuth and OMB endpoints.
-     *
-     * @param string $oauth_base The base URL for OAuth endpoints
-     * @param string $omb_base   The base URL for OMB endpoints
-     */
-    public function __construct($oauth_base, $omb_base)
-    {
-        $this->urls = array(
-                OAUTH_ENDPOINT_REQUEST => $oauth_base . 'requesttoken',
-                OAUTH_ENDPOINT_AUTHORIZE => $oauth_base . 'userauthorization',
-                OAUTH_ENDPOINT_ACCESS => $oauth_base . 'accesstoken',
-                OMB_ENDPOINT_POSTNOTICE => $omb_base . 'postnotice',
-                OMB_ENDPOINT_UPDATEPROFILE => $omb_base . 'updateprofile');
-    }
-
-    /**
-     * Fetch an URL for a specified action
-     *
-     * Returns the action URL for an action specified by the endpoint URI.
-     *
-     * @param string $action The endpoint URI
-     *
-     * @return string The action URL
-     */
-    public function getURL($action)
-    {
-        return $this->urls[$action];
-    }
-}
-?>
diff --git a/extlib/libomb/constants.php b/extlib/libomb/constants.php
deleted file mode 100644 (file)
index 2f8c0e5..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-/**
- * Constants for libomb
- *
- * This file contains constant definitions for libomb. The defined constants
- * are service and namespace URIs for OAuth and OMB as used in XRDS.
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-/**
- * The OMB constants.
- */
-
-define('OMB_VERSION_01', 'http://openmicroblogging.org/protocol/0.1');
-
-/* The OMB version supported by this libomb version. */
-define('OMB_VERSION', OMB_VERSION_01);
-
-define('OMB_ENDPOINT_UPDATEPROFILE', OMB_VERSION . '/updateProfile');
-define('OMB_ENDPOINT_POSTNOTICE', OMB_VERSION . '/postNotice');
-
-/**
- * The OAuth constants.
- */
-
-define('OAUTH_NAMESPACE', 'http://oauth.net/core/1.0/');
-
-define('OAUTH_ENDPOINT_REQUEST', OAUTH_NAMESPACE.'endpoint/request');
-define('OAUTH_ENDPOINT_AUTHORIZE', OAUTH_NAMESPACE.'endpoint/authorize');
-define('OAUTH_ENDPOINT_ACCESS', OAUTH_NAMESPACE.'endpoint/access');
-define('OAUTH_ENDPOINT_RESOURCE', OAUTH_NAMESPACE.'endpoint/resource');
-
-define('OAUTH_AUTH_HEADER', OAUTH_NAMESPACE.'parameters/auth-header');
-define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body');
-
-define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1');
-
-define('OAUTH_DISCOVERY', 'http://oauth.net/discovery/1.0');
-?>
diff --git a/extlib/libomb/datastore.php b/extlib/libomb/datastore.php
deleted file mode 100755 (executable)
index d67aafc..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'OAuth.php';
-
-/**
- * Data access interface
- *
- * This interface specifies data access methods libomb needs. It should be
- * implemented by libomb users. OMB_Datastore is libomb’s main interface to the
- * application’s data. Objects corresponding to this interface are used in
- * OMB_Service_Provider and OMB_Service_Consumer.
- *
- * Note that it’s implemented as a class since OAuthDataStore is as well a
- * class, though only declaring methods.
- *
- * OMB_Datastore extends OAuthDataStore with two OAuth-related methods for token
- * revoking and authorizing and all OMB-related methods.
- * Refer to OAuth.php for a complete specification of OAuth-related methods.
- *
- * It is the user’s duty to signal and handle errors. libomb does not check
- * return values nor handle exceptions. It is suggested to use exceptions.
- * Note that lookup_token and getProfile return null if the requested object
- * is not available. This is NOT an error and should not raise an exception.
- * Same applies for lookup_nonce which returns a boolean value. These methods
- * may nevertheless throw an exception, for example in case of a storage errors.
- *
- * Most of the parameters passed to these methods are unescaped and unverified
- * user input. Therefore they should be handled with extra care to avoid
- * security problems like SQL injections.
- */
-class OMB_Datastore extends OAuthDataStore
-{
-
-    /*********
-     * OAUTH *
-     *********/
-
-    /**
-     * Revoke specified OAuth token
-     *
-     * Revokes the authorization token specified by $token_key.
-     * Throws exceptions in case of error.
-     *
-     * @param string $token_key The key of the token to be revoked
-     *
-     * @access public
-     */
-    public function revoke_token($token_key)
-    {
-        throw new Exception();
-    }
-
-    /**
-     * Authorize specified OAuth token
-     *
-     * Authorizes the authorization token specified by $token_key.
-     * Throws exceptions in case of error.
-     *
-     * @param string $token_key The key of the token to be authorized
-     *
-     * @access public
-     */
-    public function authorize_token($token_key)
-    {
-        throw new Exception();
-    }
-
-    /*********
-     *  OMB  *
-     *********/
-
-    /**
-     * Get profile by identifying URI
-     *
-     * Returns an OMB_Profile object representing the OMB profile identified by
-     * $identifier_uri.
-     * Returns null if there is no such OMB profile.
-     * Throws exceptions in case of other error.
-     *
-     * @param string $identifier_uri The OMB identifier URI specifying the
-     *                               requested profile
-     *
-     * @access public
-     *
-     * @return OMB_Profile The corresponding profile
-     */
-    public function getProfile($identifier_uri)
-    {
-        throw new Exception();
-    }
-
-    /**
-     * Save passed profile
-     *
-     * Stores the OMB profile $profile. Overwrites an existing entry.
-     * Throws exceptions in case of error.
-     *
-     * @param OMB_Profile $profile The OMB profile which should be saved
-     *
-     * @access public
-     */
-    public function saveProfile($profile)
-    {
-        throw new Exception();
-    }
-
-    /**
-     * Save passed notice
-     *
-     * Stores the OMB notice $notice. The datastore may change the passed
-     * notice. This might by necessary for URIs depending on a database key.
-     * Note that it is the user’s duty to present a mechanism for his
-     * OMB_Datastore to appropriately change his OMB_Notice.
-     * Throws exceptions in case of error.
-     *
-     * @param OMB_Notice &$notice The OMB notice which should be saved
-     *
-     * @access public
-     */
-    public function saveNotice(&$notice)
-    {
-        throw new Exception();
-    }
-
-    /**
-     * Get subscriptions of a given profile
-     *
-     * Returns an array containing subscription informations for the specified
-     * profile. Every array entry should in turn be an array with keys
-     *   'uri´: The identifier URI of the subscriber
-     *   'token´: The subscribe token
-     *   'secret´: The secret token
-     * Throws exceptions in case of error.
-     *
-     * @param string $subscribed_user_uri The OMB identifier URI specifying the
-     *                                    subscribed profile
-     *
-     * @access public
-     *
-     * @return mixed An array containing the subscriptions or 0 if no
-     *               subscription has been found.
-     */
-    public function getSubscriptions($subscribed_user_uri)
-    {
-        throw new Exception();
-    }
-
-    /**
-     * Delete a subscription
-     *
-     * Deletes the subscription from $subscriber_uri to $subscribed_user_uri.
-     * Throws exceptions in case of error.
-     *
-     * @param string $subscriber_uri      The OMB identifier URI specifying the
-     *                                    subscribing profile
-     *
-     * @param string $subscribed_user_uri The OMB identifier URI specifying the
-     *                                    subscribed profile
-     *
-     * @access public
-     */
-    public function deleteSubscription($subscriber_uri, $subscribed_user_uri)
-    {
-        throw new Exception();
-    }
-
-    /**
-     * Save a subscription
-     *
-     * Saves the subscription from $subscriber_uri to $subscribed_user_uri.
-     * Throws exceptions in case of error.
-     *
-     * @param string     $subscriber_uri      The OMB identifier URI specifying
-     *                                            the subscribing profile
-     *
-     * @param string     $subscribed_user_uri The OMB identifier URI specifying
-     *                                            the subscribed profile
-     * @param OAuthToken $token               The access token
-     *
-     * @access public
-     */
-    public function saveSubscription($subscriber_uri, $subscribed_user_uri,
-                                     $token)
-    {
-        throw new Exception();
-    }
-}
-?>
diff --git a/extlib/libomb/helper.php b/extlib/libomb/helper.php
deleted file mode 100644 (file)
index 08e6e7a..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'Validate.php';
-
-/**
- * Helper functions for libomb
- *
- * This class contains helper functions for libomb.
- */
-class OMB_Helper
-{
-
-    /**
-     * Non-scalar constants
-     *
-     * The set of OMB and OAuth Services an OMB Server has to implement.
-     */
-
-    public static $OMB_SERVICES   = array(OMB_ENDPOINT_UPDATEPROFILE,
-                                          OMB_ENDPOINT_POSTNOTICE);
-    public static $OAUTH_SERVICES = array(OAUTH_ENDPOINT_REQUEST,
-                                          OAUTH_ENDPOINT_AUTHORIZE,
-                                          OAUTH_ENDPOINT_ACCESS);
-
-    /**
-     * Validate URL
-     *
-     * Basic URL validation. Currently http, https, ftp and gopher are supported
-     * schemes.
-     *
-     * @param string $url The URL which is to be validated.
-     *
-     * @return bool Whether URL is valid.
-     *
-     * @access public
-     */
-    public static function validateURL($url)
-    {
-        return Validate::uri($url, array('allowed_schemes' => array('http',
-                                                    'https', 'gopher', 'ftp')));
-    }
-
-    /**
-     * Validate Media type
-     *
-     * Basic Media type validation. Checks for valid maintype and correct
-     * format.
-     *
-     * @param string $mediatype The Media type which is to be validated.
-     *
-     * @return bool Whether media type is valid.
-     *
-     * @access public
-     */
-    public static function validateMediaType($mediatype)
-    {
-        return preg_match('/^(\w+)\/([\w\d-+.]+)$/', $mediatype, $subtypes) > 0
-               &&
-               in_array(strtolower($subtypes[1]), array('application', 'audio',
-               'image', 'message', 'model', 'multipart', 'text', 'video'));
-    }
-
-    /**
-     * Remove escaping from request parameters
-     *
-     * Neutralise the evil effects of magic_quotes_gpc in the current request.
-     * This is used before handing a request off to OAuthRequest::from_request.
-     * Many thanks to Ciaran Gultnieks for this fix.
-     *
-     * @access public
-     */
-    public static function removeMagicQuotesFromRequest()
-    {
-        if (get_magic_quotes_gpc() === 1) {
-            $_POST = array_map('stripslashes', $_POST);
-            $_GET  = array_map('stripslashes', $_GET);
-        }
-    }
-}
-?>
diff --git a/extlib/libomb/invalidparameterexception.php b/extlib/libomb/invalidparameterexception.php
deleted file mode 100755 (executable)
index d95c702..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-/**
- * Exception stating that a passed parameter is invalid
- *
- * This exception is raised when a parameter does not obey the OMB standard.
- */
-class OMB_InvalidParameterException extends Exception
-{
-    /**
-     * Constructor
-     *
-     * Creates a new exception based on a parameter name, value, and object
-     * type.
-     *
-     * @param string $value     The wrong value passed
-     * @param string $type      The object type the parameter belongs to;
-     *                          Currently OMB uses profiles and notices
-     * @param string $parameter The name of the parameter the wrong value has
-     *                          been passed for
-     */
-    public function __construct($value, $type, $parameter)
-    {
-        parent::__construct("Invalid value ‘${value}’ for parameter " .
-                            "‘${parameter}’ in $type");
-    }
-}
-?>
diff --git a/extlib/libomb/invalidyadisexception.php b/extlib/libomb/invalidyadisexception.php
deleted file mode 100755 (executable)
index dc61a13..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-/**
- * Exception stating that a requested url does not resolve to a valid yadis
- *
- * This exception is raised when OMB_Service is not able to discover a valid
- * yadis location with XRDS.
- */
-class OMB_InvalidYadisException extends Exception
-{
-
-}
-?>
diff --git a/extlib/libomb/notice.php b/extlib/libomb/notice.php
deleted file mode 100755 (executable)
index 4963597..0000000
+++ /dev/null
@@ -1,294 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'invalidparameterexception.php';
-require_once 'Validate.php';
-require_once 'helper.php';
-
-/**
- * OMB Notice representation
- *
- * This class represents an OMB notice.
- *
- * Do not call the setters with null values. Instead, if you want to delete a
- * field, pass an empty string. The getters will return null for empty fields.
- */
-class OMB_Notice
-{
-    protected $author;
-    protected $uri;
-    protected $content;
-    protected $url;
-    protected $license_url; /* url is an own addition for clarification. */
-    protected $seealso_url; /* url is an own addition for clarification. */
-    protected $seealso_disposition;
-    protected $seealso_mediatype;
-    protected $seealso_license_url; /* url is an addition for clarification. */
-
-    /* The notice as OMB param array. Cached and rebuild on usage.
-       false while outdated. */
-    protected $param_array;
-
-    /**
-     * Constructor for OMB_Notice
-     *
-     * Initializes the OMB_Notice object with author, uri and content.
-     * These parameters are mandatory for postNotice.
-     *
-     * @param object $author  An OMB_Profile object representing the author of
-     *                        the notice.
-     * @param string $uri     The notice URI as defined by the OMB. A unique and
-     *                        never changing identifier for a notice.
-     * @param string $content The content of the notice. 140 chars recommended,
-     *                        but there is no limit.
-     *
-     * @access public
-     */
-    public function __construct($author, $uri, $content)
-    {
-        $this->content = $content;
-        if (is_null($author)) {
-            throw new OMB_InvalidParameterException('', 'notice', 'omb_listenee');
-        }
-        $this->author = $author;
-
-        if (!Validate::uri($uri)) {
-            throw new OMB_InvalidParameterException($uri, 'notice', 'omb_notice');
-        }
-        $this->uri = $uri;
-
-        $this->param_array = false;
-    }
-
-    /**
-     * Return the notice as array
-     *
-     * Returns an array which contains the whole notice as array. The array is
-     * cached and only rebuilt on changes of the notice.
-     * Empty optional values are not passed.
-     *
-     * @access public
-     * @return array The notice as parameter array
-     */
-    public function asParameters()
-    {
-        if ($this->param_array !== false) {
-            return $this->param_array;
-        }
-
-        $this->param_array = array(
-                                 'omb_notice' => $this->uri,
-                                 'omb_notice_content' => $this->content);
-
-        if (!is_null($this->url))
-            $this->param_array['omb_notice_url'] = $this->url;
-
-        if (!is_null($this->license_url))
-            $this->param_array['omb_notice_license'] = $this->license_url;
-
-        if (!is_null($this->seealso_url)) {
-            $this->param_array['omb_seealso'] = $this->seealso_url;
-
-            /* This is actually a free interpretation of the OMB standard. We
-               assume that additional seealso parameters are not of any use if
-               seealso itself is not set. */
-            if (!is_null($this->seealso_disposition))
-                $this->param_array['omb_seealso_disposition'] =
-                                                     $this->seealso_disposition;
-
-            if (!is_null($this->seealso_mediatype))
-                $this->param_array['omb_seealso_mediatype'] =
-                                                       $this->seealso_mediatype;
-
-            if (!is_null($this->seealso_license_url))
-                $this->param_array['omb_seealso_license'] =
-                                                     $this->seealso_license_url;
-        }
-        return $this->param_array;
-    }
-
-    /**
-     * Build an OMB_Notice object from array
-     *
-     * Builds an OMB_Notice object from the passed parameters array. The array
-     * MUST provide a notice URI and content. The array fields HAVE TO be named
-     * according to the OMB standard, i. e. omb_notice_* and omb_seealso_*.
-     * Values are handled as not passed if the corresponding array fields are
-     * not set or the empty string.
-     *
-     * @param object $author     An OMB_Profile object representing the author
-     *                           of the notice.
-     * @param string $parameters An array containing the notice parameters.
-     *
-     * @access public
-     *
-     * @returns OMB_Notice The built OMB_Notice.
-     */
-    public static function fromParameters($author, $parameters)
-    {
-        $notice = new OMB_Notice($author, $parameters['omb_notice'],
-                                             $parameters['omb_notice_content']);
-
-        if (isset($parameters['omb_notice_url'])) {
-            $notice->setURL($parameters['omb_notice_url']);
-        }
-
-        if (isset($parameters['omb_notice_license'])) {
-            $notice->setLicenseURL($parameters['omb_notice_license']);
-        }
-
-        if (isset($parameters['omb_seealso'])) {
-            $notice->setSeealsoURL($parameters['omb_seealso']);
-        }
-
-        if (isset($parameters['omb_seealso_disposition'])) {
-            $notice->setSeealsoDisposition($parameters['omb_seealso_disposition']);
-        }
-
-        if (isset($parameters['omb_seealso_mediatype'])) {
-            $notice->setSeealsoMediatype($parameters['omb_seealso_mediatype']);
-        }
-
-        if (isset($parameters['omb_seealso_license'])) {
-            $notice->setSeealsoLicenseURL($parameters['omb_seealso_license']);
-        }
-        return $notice;
-    }
-
-    public function getAuthor()
-    {
-        return $this->author;
-    }
-
-    public function getIdentifierURI()
-    {
-        return $this->uri;
-    }
-
-    public function getContent()
-    {
-        return $this->content;
-    }
-
-    public function getURL()
-    {
-        return $this->url;
-    }
-
-    public function getLicenseURL()
-    {
-        return $this->license_url;
-    }
-
-    public function getSeealsoURL()
-    {
-        return $this->seealso_url;
-    }
-
-    public function getSeealsoDisposition()
-    {
-        return $this->seealso_disposition;
-    }
-
-    public function getSeealsoMediatype()
-    {
-        return $this->seealso_mediatype;
-    }
-
-    public function getSeealsoLicenseURL()
-    {
-        return $this->seealso_license_url;
-    }
-
-    public function setURL($url)
-    {
-        $this->setVal('notice_url', $url, 'OMB_Helper::validateURL', 'url');
-    }
-
-    public function setLicenseURL($license_url)
-    {
-        $this->setVal('license', $license_url, 'OMB_Helper::validateURL',
-                      'license_url');
-    }
-
-    public function setSeealsoURL($seealso_url)
-    {
-        $this->setVal('seealso', $seealso_url, 'OMB_Helper::validateURL',
-                      'seealso_url');
-    }
-
-    public function setSeealsoDisposition($seealso_disposition)
-    {
-        $this->setVal('seealso_disposition', $seealso_disposition,
-                      'OMB_Notice::validateDisposition');
-    }
-
-    protected static function validateDisposition($str)
-    {
-        return in_array($str, array('link', 'inline'));
-    }
-
-    public function setSeealsoMediatype($seealso_mediatype)
-    {
-        $this->setVal('seealso_mediatype', $seealso_mediatype,
-                      'OMB_Helper::validateMediaType');
-    }
-
-    public function setSeealsoLicenseURL($seealso_license_url)
-    {
-        $this->setVal('seealso_license', $seealso_license_url,
-                      'OMB_Helper::validateURL', 'seealso_license_url');
-    }
-
-    /**
-     * Set a value
-     *
-     * Updates a value specified by a parameter name and the new value.
-     *
-     * @param string   $param     The parameter name according to OMB
-     * @param string   $value     The new value
-     * @param callback $validator A validator function for the parameter
-     * @param string   $field     The name of the field in OMB_Notice
-     * @param bool     $force     Whether null values should be checked as well
-     */
-    protected function setVal($param, $value, $validator, $field = null,
-                              $force = false)
-    {
-        if (is_null($field)) {
-            $field = $param;
-        }
-        if ($value === '' && !$force) {
-            $value = null;
-        } elseif (!call_user_func($validator, $value)) {
-            throw new OMB_InvalidParameterException($value, 'notice', $param);
-        }
-        if ($this->$field !== $value) {
-            $this->$field      = $value;
-            $this->param_array = false;
-        }
-    }
-}
-?>
diff --git a/extlib/libomb/omb_yadis_xrds.php b/extlib/libomb/omb_yadis_xrds.php
deleted file mode 100755 (executable)
index a05477c..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'Auth/Yadis/Yadis.php';
-require_once 'unsupportedserviceexception.php';
-require_once 'invalidyadisexception.php';
-
-/**
- * OMB XRDS representation
- *
- * This class represents a Yadis XRDS file for OMB. It adds some useful methods to
- * Auth_Yadis_XRDS.
- */
-class OMB_Yadis_XRDS extends Auth_Yadis_XRDS
-{
-
-    protected $fetcher;
-
-    /**
-     * Create an instance from URL
-     *
-     * Constructs an OMB_Yadis_XRDS object from a given URL. A full Yadis
-     * discovery is performed on the URL and the XRDS is parsed.
-     * Throws an OMB_InvalidYadisException when no Yadis is discovered or the
-     * detected XRDS file is broken.
-     *
-     * @param string                 $url     The URL on which Yadis discovery
-     *                                        should be performed on
-     * @param Auth_Yadis_HTTPFetcher $fetcher A fetcher used to get HTTP
-     *                                        resources
-     *
-     * @access public
-     *
-     * @return OMB_Yadis_XRDS The initialized object representing the given
-     *                        resource
-     */
-    public static function fromYadisURL($url, $fetcher)
-    {
-        /* Perform a Yadis discovery. */
-        $yadis = Auth_Yadis_Yadis::discover($url, $fetcher);
-        if ($yadis->failed) {
-            throw new OMB_InvalidYadisException($url);
-        }
-
-        /* Parse the XRDS file. */
-        $xrds = OMB_Yadis_XRDS::parseXRDS($yadis->response_text);
-        if ($xrds === null) {
-            throw new OMB_InvalidYadisException($url);
-        }
-        $xrds->fetcher = $fetcher;
-        return $xrds;
-    }
-
-    /**
-     * Get a specific service
-     *
-     * Returns the Auth_Yadis_Service object corresponding to the given service
-     * URI.
-     * Throws an OMB_UnsupportedServiceException if the service is not
-     * available.
-     *
-     * @param string $service URI specifier of the requested service
-     *
-     * @access public
-     *
-     * @return Auth_Yadis_Service The object representing the requested service
-     */
-    public function getService($service)
-    {
-        $match = $this->services(array(create_function('$s',
-                             "return in_array('$service', \$s->getTypes());")));
-        if ($match === array()) {
-            throw new OMB_UnsupportedServiceException($service);
-        }
-        return $match[0];
-    }
-
-    /**
-     * Get a specific XRD
-     *
-     * Returns the OMB_Yadis_XRDS object corresponding to the given URI.
-     * Throws an OMB_UnsupportedServiceException if the XRD is not available.
-     * Note that getXRD tries to resolve external XRD parts as well.
-     *
-     * @param string $uri URI specifier of the requested XRD
-     *
-     * @access public
-     *
-     * @return OMB_Yadis_XRDS The object representing the requested XRD
-     */
-    public function getXRD($uri)
-    {
-        $nexthash = strpos($uri, '#');
-        if ($nexthash === false) {
-            throw new OMB_InvalidYadisException("‘$uri’ does not specify a " .
-                                                'valid XML node.');
-        }
-
-        if ($nexthash > 0) {
-            $cururi  = substr($uri, 0, $nexthash);
-            $nexturi = substr($uri, $nexthash);
-            return OMB_Yadis_XRDS::fromYadisURL($cururi, $this->fetcher)
-                                               ->getXRD($nexturi);
-        }
-
-        $id = substr($uri, 1);
-        foreach ($this->allXrdNodes as $node) {
-            $attrs = $this->parser->attributes($node);
-            if (array_key_exists('xml:id', $attrs) && $attrs['xml:id'] == $id) {
-                /* Trick the constructor into thinking this is the only node. */
-                $bogus_nodes = array($node);
-                return new OMB_Yadis_XRDS($this->parser, $bogus_nodes);
-            }
-        }
-        throw new OMB_UnsupportedServiceException($uri);
-    }
-
-    /**
-     * Parse an XML string containing a XRDS document
-     *
-     * Parses an XML string (XRDS document) and returns either an
-     * Auth_Yadis_XRDS object or null, depending on whether the XRDS XML is
-     * valid.
-     * This method is just copy and paste from the parent class to select the
-     * correct constructor.
-     *
-     * @param string $xml_string   An XRDS XML string
-     * @param array  $extra_ns_map Additional namespace declarations
-     *
-     * @access public
-     *
-     * @return mixed An instance of OMB_Yadis_XRDS or null,
-     *               depending on the validity of $xml_string
-     */
-    public static function parseXRDS($xml_string, $extra_ns_map = null)
-    {
-        $_null = null;
-
-        if (!$xml_string) {
-            return $_null;
-        }
-
-        $parser = Auth_Yadis_getXMLParser();
-
-        $ns_map = Auth_Yadis_getNSMap();
-
-        if ($extra_ns_map && is_array($extra_ns_map)) {
-            $ns_map = array_merge($ns_map, $extra_ns_map);
-        }
-
-        if (!($parser && $parser->init($xml_string, $ns_map))) {
-            return $_null;
-        }
-
-        // Try to get root element.
-        $root = $parser->evalXPath('/xrds:XRDS[1]');
-        if (!$root) {
-            return $_null;
-        }
-
-        if (is_array($root)) {
-            $root = $root[0];
-        }
-
-        $attrs = $parser->attributes($root);
-
-        if (array_key_exists('xmlns:xrd', $attrs) &&
-                    $attrs['xmlns:xrd'] != Auth_Yadis_XMLNS_XRDS) {
-            return $_null;
-        } else if (array_key_exists('xmlns', $attrs) &&
-                                     preg_match('/xri/', $attrs['xmlns']) &&
-                                     $attrs['xmlns'] != Auth_Yadis_XMLNS_XRD_2_0) {
-            return $_null;
-        }
-
-        // Get the last XRD node.
-        $xrd_nodes = $parser->evalXPath('/xrds:XRDS[1]/xrd:XRD');
-
-        if (!$xrd_nodes) {
-            return $_null;
-        }
-
-        $xrds = new OMB_Yadis_XRDS($parser, $xrd_nodes);
-        return $xrds;
-    }
-}
diff --git a/extlib/libomb/plain_xrds_writer.php b/extlib/libomb/plain_xrds_writer.php
deleted file mode 100755 (executable)
index ba1027b..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'xrds_writer.php';
-
-/**
- * Write OMB-specific XRDS using XMLWriter
- *
- * This class writes the XRDS file announcing the OMB server. It uses XMLWriter.
- * An instance of OMB_Plain_XRDS_Writer should be passed to
- * OMB_Service_Provider->writeXRDS.
- */
-class OMB_Plain_XRDS_Writer implements OMB_XRDS_Writer
-{
-    /**
-     * Write XRDS using XMLWriter
-     *
-     * Outputs a XRDS document specifying an OMB service.
-     *
-     * @param OMB_profile     $user   The target user for the OMB service
-     * @param OMB_XRDS_Mapper $mapper An OMB_XRDS_Mapper providing endpoint URLs
-     */
-    public function writeXRDS($user, $mapper)
-    {
-        header('Content-Type: application/xrds+xml');
-        $xw = new XMLWriter();
-        $xw->openURI('php://output');
-        $xw->setIndent(true);
-
-        $xw->startDocument('1.0', 'UTF-8');
-        $this->_writeFullElement($xw, 'XRDS', array('xmlns' => 'xri://$xrds'), array(
-        array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
-                            'xml:id' => 'oauth',
-                            'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
-                            'version' => '2.0'), array(
-          array('Type', null, 'xri://$xrds*simple'),
-          array('Service', null, array(
-            array('Type', null, OAUTH_ENDPOINT_REQUEST),
-            array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_REQUEST)),
-            array('Type', null, OAUTH_AUTH_HEADER),
-            array('Type', null, OAUTH_POST_BODY),
-            array('Type', null, OAUTH_HMAC_SHA1),
-            array('LocalID', null, $user->getIdentifierURI())
-          )),
-          array('Service', null, array(
-            array('Type', null, OAUTH_ENDPOINT_AUTHORIZE),
-            array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_AUTHORIZE)),
-            array('Type', null, OAUTH_AUTH_HEADER),
-            array('Type', null, OAUTH_POST_BODY),
-            array('Type', null, OAUTH_HMAC_SHA1)
-          )),
-          array('Service', null, array(
-            array('Type', null, OAUTH_ENDPOINT_ACCESS),
-            array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_ACCESS)),
-            array('Type', null, OAUTH_AUTH_HEADER),
-            array('Type', null, OAUTH_POST_BODY),
-            array('Type', null, OAUTH_HMAC_SHA1)
-          )),
-          array('Service', null, array(
-            array('Type', null, OAUTH_ENDPOINT_RESOURCE),
-            array('Type', null, OAUTH_AUTH_HEADER),
-            array('Type', null, OAUTH_POST_BODY),
-            array('Type', null, OAUTH_HMAC_SHA1)
-          ))
-        )),
-        array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
-                           'xml:id' => 'omb',
-                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
-                           'version' => '2.0'), array(
-          array('Type', null, 'xri://$xrds*simple'),
-          array('Service', null, array(
-            array('Type', null, OMB_ENDPOINT_POSTNOTICE),
-            array('URI', null, $mapper->getURL(OMB_ENDPOINT_POSTNOTICE))
-          )),
-          array('Service', null, array(
-            array('Type', null, OMB_ENDPOINT_UPDATEPROFILE),
-            array('URI', null, $mapper->getURL(OMB_ENDPOINT_UPDATEPROFILE))
-          ))
-        )),
-        array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
-                           'version' => '2.0'), array(
-          array('Type', null, 'xri://$xrds*simple'),
-          array('Service', null, array(
-            array('Type', null, OAUTH_DISCOVERY),
-            array('URI', null, '#oauth')
-          )),
-          array('Service', null, array(
-            array('Type', null, OMB_VERSION),
-            array('URI', null, '#omb')
-          ))
-        ))));
-        $xw->endDocument();
-        $xw->flush();
-    }
-
-    /**
-     * Write a complex XML element
-     *
-     * Outputs a XML element with attributes and content.
-     *
-     * @param XMLWriter    $xw         The XMLWriter used to output the element
-     * @param string       $tag        The tag name
-     * @param array|null   $attributes A map of XML attributes
-     * @param array|string $content    The content of the element; either an
-     *                                 array of child nodes each specified by a
-     *                                 three entry-array ($tag, $attributes,
-     *                                 $content) or a string
-     */
-    private function _writeFullElement($xw, $tag, $attributes, $content)
-    {
-        $xw->startElement($tag);
-        if (!is_null($attributes)) {
-            foreach ($attributes as $name => $value) {
-                $xw->writeAttribute($name, $value);
-            }
-        }
-        if (is_array($content)) {
-            foreach ($content as $val) {
-                $this->_writeFullElement($xw, $val[0], $val[1], $val[2]);
-            }
-        } else {
-            $xw->text($content);
-        }
-        $xw->fullEndElement();
-    }
-}
-?>
diff --git a/extlib/libomb/profile.php b/extlib/libomb/profile.php
deleted file mode 100755 (executable)
index d732e10..0000000
+++ /dev/null
@@ -1,345 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'invalidparameterexception.php';
-require_once 'Validate.php';
-require_once 'helper.php';
-
-/**
- * OMB profile representation
- *
- * This class represents an OMB profile.
- *
- * Do not call the setters with null values. Instead, if you want to delete a
- * field, pass an empty string. The getters will return null for empty fields.
- */
-class OMB_Profile
-{
-    protected $identifier_uri;
-    protected $profile_url;
-    protected $nickname;
-    protected $license_url;
-    protected $fullname;
-    protected $homepage;
-    protected $bio;
-    protected $location;
-    protected $avatar_url;
-
-    /* The profile as OMB param array. Cached and rebuild on usage.
-       false while outdated. */
-    protected $param_array;
-
-    /**
-     * Constructor for OMB_Profile
-     *
-     * Initializes the OMB_Profile object with an identifier uri.
-     *
-     * @param string $identifier_uri The profile URI as defined by the OMB;
-     *                               A unique and never changing identifier for
-     *                               a profile
-     *
-     * @access public
-     */
-    public function __construct($identifier_uri)
-    {
-        if (!Validate::uri($identifier_uri)) {
-            throw new OMB_InvalidParameterException($identifier_uri, 'profile',
-                                                'omb_listenee or omb_listener');
-        }
-        $this->identifier_uri = $identifier_uri;
-        $this->param_array    = false;
-    }
-
-    /**
-     * Return the profile as array
-     *
-     * Returns an array which contains the whole profile as array.
-     * The array is cached and only rebuilt on changes of the profile.
-     *
-     * @param string $prefix    The common prefix to the key for all parameters
-     * @param bool   $force_all Specifies whether empty fields should be added
-     *                          to the array as well; This is necessary to
-     *                          clear fields via updateProfile
-     *
-     * @access public
-     *
-     * @return array The profile as parameter array
-     */
-    public function asParameters($prefix, $force_all = false)
-    {
-        if ($this->param_array === false) {
-            $this->param_array = array('' => $this->identifier_uri);
-
-            if ($force_all || !is_null($this->profile_url)) {
-                $this->param_array['_profile'] = $this->profile_url;
-            }
-
-            if ($force_all || !is_null($this->homepage)) {
-                $this->param_array['_homepage'] = $this->homepage;
-            }
-
-            if ($force_all || !is_null($this->nickname)) {
-                $this->param_array['_nickname'] = $this->nickname;
-            }
-
-            if ($force_all || !is_null($this->license_url)) {
-                $this->param_array['_license'] = $this->license_url;
-            }
-
-            if ($force_all || !is_null($this->fullname)) {
-                $this->param_array['_fullname'] = $this->fullname;
-            }
-
-            if ($force_all || !is_null($this->bio)) {
-                $this->param_array['_bio'] = $this->bio;
-            }
-
-            if ($force_all || !is_null($this->location)) {
-                $this->param_array['_location'] = $this->location;
-            }
-
-            if ($force_all || !is_null($this->avatar_url)) {
-                $this->param_array['_avatar'] = $this->avatar_url;
-            }
-
-        }
-        $ret = array();
-        foreach ($this->param_array as $k => $v) {
-            $ret[$prefix . $k] = $v;
-        }
-        return $ret;
-    }
-
-    /**
-     * Build an OMB_Profile object from array
-     *
-     * Builds an OMB_Profile object from the passed parameters array. The
-     * array MUST provide a profile URI. The array fields HAVE TO be named
-     * according to the OMB standard. The prefix (omb_listener or omb_listenee)
-     * is passed as a parameter.
-     *
-     * @param string $parameters An array containing the profile parameters
-     * @param string $prefix     The common prefix of the profile parameter keys
-     *
-     * @access public
-     *
-     * @returns OMB_Profile The built OMB_Profile
-     */
-    public static function fromParameters($parameters, $prefix)
-    {
-        if (!isset($parameters[$prefix])) {
-            throw new OMB_InvalidParameterException('', 'profile', $prefix);
-        }
-
-        $profile = new OMB_Profile($parameters[$prefix]);
-        $profile->updateFromParameters($parameters, $prefix);
-        return $profile;
-    }
-
-    /**
-     * Update from array
-     *
-     * Updates from the passed parameters array. The array does not have to
-     * provide a profile URI. The array fields HAVE TO be named according to the
-     * OMB standard. The prefix (omb_listener or omb_listenee) is passed as a
-     * parameter.
-     *
-     * @param string $parameters An array containing the profile parameters
-     * @param string $prefix     The common prefix of the profile parameter keys
-     *
-     * @access public
-     */
-    public function updateFromParameters($parameters, $prefix)
-    {
-        if (isset($parameters[$prefix.'_profile'])) {
-            $this->setProfileURL($parameters[$prefix.'_profile']);
-        }
-
-        if (isset($parameters[$prefix.'_license'])) {
-            $this->setLicenseURL($parameters[$prefix.'_license']);
-        }
-
-        if (isset($parameters[$prefix.'_nickname'])) {
-            $this->setNickname($parameters[$prefix.'_nickname']);
-        }
-
-        if (isset($parameters[$prefix.'_fullname'])) {
-            $this->setFullname($parameters[$prefix.'_fullname']);
-        }
-
-        if (isset($parameters[$prefix.'_homepage'])) {
-            $this->setHomepage($parameters[$prefix.'_homepage']);
-        }
-
-        if (isset($parameters[$prefix.'_bio'])) {
-            $this->setBio($parameters[$prefix.'_bio']);
-        }
-
-        if (isset($parameters[$prefix.'_location'])) {
-            $this->setLocation($parameters[$prefix.'_location']);
-        }
-
-        if (isset($parameters[$prefix.'_avatar'])) {
-            $this->setAvatarURL($parameters[$prefix.'_avatar']);
-        }
-    }
-
-    public function getIdentifierURI()
-    {
-        return $this->identifier_uri;
-    }
-
-    public function getProfileURL()
-    {
-        return $this->profile_url;
-    }
-
-    public function getHomepage()
-    {
-        return $this->homepage;
-    }
-
-    public function getNickname()
-    {
-        return $this->nickname;
-    }
-
-    public function getLicenseURL()
-    {
-        return $this->license_url;
-    }
-
-    public function getFullname()
-    {
-        return $this->fullname;
-    }
-
-    public function getBio()
-    {
-        return $this->bio;
-    }
-
-    public function getLocation()
-    {
-        return $this->location;
-    }
-
-    public function getAvatarURL()
-    {
-        return $this->avatar_url;
-    }
-
-    public function setProfileURL($profile_url)
-    {
-        $this->setVal('profile', $profile_url, 'OMB_Helper::validateURL',
-                      'profile_url');
-    }
-
-    public function setNickname($nickname)
-    {
-        $this->setVal('nickname', $nickname, 'OMB_Profile::validateNickname',
-                      'nickname', true);
-    }
-
-    public function setLicenseURL($license_url)
-    {
-        $this->setVal('license', $license_url, 'OMB_Helper::validateURL',
-                      'license_url');
-    }
-
-    public function setFullname($fullname)
-    {
-        $this->setVal('fullname', $fullname, 'OMB_Profile::validate255');
-    }
-
-    public function setHomepage($homepage)
-    {
-        $this->setVal('homepage', $homepage, 'OMB_Helper::validateURL');
-    }
-
-    public function setBio($bio)
-    {
-        $this->setVal('bio', $bio, 'OMB_Profile::validate140');
-    }
-
-    public function setLocation($location)
-    {
-        $this->setVal('location', $location, 'OMB_Profile::validate255');
-    }
-
-    public function setAvatarURL($avatar_url)
-    {
-        $this->setVal('avatar', $avatar_url, 'OMB_Helper::validateURL',
-                      'avatar_url');
-    }
-
-    protected static function validate255($str)
-    {
-        return Validate::string($str, array('max_length' => 255));
-    }
-
-    protected static function validate140($str)
-    {
-        return Validate::string($str, array('max_length' => 140));
-    }
-
-    protected static function validateNickname($str)
-    {
-        return Validate::string($str,
-                              array('min_length' => 1,
-                                    'max_length' => 64,
-                                    'format' => VALIDATE_NUM . VALIDATE_ALPHA));
-    }
-
-    /**
-     * Set a value
-     *
-     * Updates a value specified by a parameter name and the new value.
-     *
-     * @param string   $param     The parameter name according to OMB
-     * @param string   $value     The new value
-     * @param callback $validator A validator function for the parameter
-     * @param string   $field     The name of the field in OMB_Profile
-     * @param bool     $force     Whether null values should be checked as well
-     */
-    protected function setVal($param, $value, $validator, $field = null,
-                              $force = false)
-    {
-        if (is_null($field)) {
-            $field = $param;
-        }
-        if ($value === '' && !$force) {
-            $value = null;
-        } elseif (!call_user_func($validator, $value)) {
-            throw new OMB_InvalidParameterException($value, 'profile', $param);
-        }
-        if ($this->$field !== $value) {
-            $this->$field      = $value;
-            $this->param_array = false;
-        }
-    }
-}
-?>
diff --git a/extlib/libomb/remoteserviceexception.php b/extlib/libomb/remoteserviceexception.php
deleted file mode 100755 (executable)
index f8341e8..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-/**
- * Exception stating that the remote service had a failure
- *
- * This exception is raised when a remote service failed to return a valid
- * response to a request or send a valid request.
- */
-class OMB_RemoteServiceException extends Exception
-{
-    /**
-     * Create exception from Yadis response
-     *
-     * Creates an exception from a passed yadis result.
-     *
-     * @param string                  $request_uri The target URI for the failed
-     *                                             request
-     * @param Auth_Yadis_HTTPResponse $result      The result of the failed
-     *                                             request
-     *
-     * @return OMB_RemoteServiceException A new exception
-     */
-    public static function fromYadis($request_uri, $result)
-    {
-        if ($result->status == 200) {
-            $err = 'Got wrong response ' . $result->body;
-        } else {
-            $err = 'Got error code ' . $result->status . ' with response ' .
-                   $result->body;
-        }
-        return OMB_RemoteServiceException::forRequest($request_uri, $err);
-    }
-
-    /**
-     * Create exception for a call to a resource
-     *
-     * Creates an exception for a given error message and target URI.
-     *
-     * @param string $action_uri The target URI for the failed request
-     * @param string $failure    An error message
-     *
-     * @return OMB_RemoteServiceException A new exception
-     */
-    public static function forRequest($action_uri, $failure)
-    {
-        return new OMB_RemoteServiceException("Handler for $action_uri: $failure");
-    }
-}
-?>
diff --git a/extlib/libomb/service_consumer.php b/extlib/libomb/service_consumer.php
deleted file mode 100755 (executable)
index 33ebccc..0000000
+++ /dev/null
@@ -1,461 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'Validate.php';
-require_once 'Auth/Yadis/Yadis.php';
-require_once 'OAuth.php';
-require_once 'constants.php';
-require_once 'helper.php';
-require_once 'omb_yadis_xrds.php';
-require_once 'profile.php';
-require_once 'remoteserviceexception.php';
-require_once 'unsupportedserviceexception.php';
-
-/**
- * OMB service representation
- *
- * This class represents a complete remote OMB service. It provides discovery
- * and execution of the service’s methods.
- */
-class OMB_Service_Consumer
-{
-    protected $url; /* The service URL */
-    protected $services; /* An array of strings mapping service URI to
-                            service URL */
-
-    protected $token; /* An OAuthToken */
-
-    protected $listener_uri; /* The URI identifying the listener, i. e. the
-                                remote user. */
-
-    protected $listenee_uri; /* The URI identifying the listenee, i. e. the
-                                local user during an auth request. */
-
-    /**
-     * According to OAuth Core 1.0, an user authorization request is no
-     * full-blown OAuth request. nonce, timestamp, consumer_key and signature
-     * are not needed in this step. See http://laconi.ca/trac/ticket/827 for
-     * more informations.
-     *
-     * Since Laconica up to version 0.7.2 performs a full OAuth request check, a
-     * correct request would fail.
-     */
-    public $performLegacyAuthRequest = true;
-
-    /* Helper stuff we are going to need. */
-    protected $fetcher;
-    protected $oauth_consumer;
-    protected $datastore;
-
-    /**
-     * Constructor for OMB_Service_Consumer
-     *
-     * Initializes an OMB_Service_Consumer object representing the OMB service
-     * specified by $service_url. Performs a complete service discovery using
-     * Yadis.
-     * Throws OMB_UnsupportedServiceException if XRDS file does not specify a
-     * complete OMB service.
-     *
-     * @param string        $service_url  The URL of the service
-     * @param string        $consumer_url An URL representing the consumer
-     * @param OMB_Datastore $datastore    An instance of a class implementing
-     *                                    OMB_Datastore
-     *
-     * @access public
-     */
-    public function __construct ($service_url, $consumer_url, $datastore)
-    {
-        $this->url            = $service_url;
-        $this->fetcher        = Auth_Yadis_Yadis::getHTTPFetcher();
-        $this->datastore      = $datastore;
-        $this->oauth_consumer = new OAuthConsumer($consumer_url, '');
-
-        $xrds = OMB_Yadis_XRDS::fromYadisURL($service_url, $this->fetcher);
-
-        /* Detect our services. This performs a validation as well, since
-            getService und getXRD throw exceptions on failure. */
-        $this->services = array();
-
-        foreach (array(OAUTH_DISCOVERY => OMB_Helper::$OAUTH_SERVICES,
-                       OMB_VERSION     => OMB_Helper::$OMB_SERVICES)
-                 as    $service_root   => $targetservices) {
-            $uris = $xrds->getService($service_root)->getURIs();
-            $xrd  = $xrds->getXRD($uris[0]);
-            foreach ($targetservices as $targetservice) {
-                $yadis_service = $xrd->getService($targetservice);
-                if ($targetservice == OAUTH_ENDPOINT_REQUEST) {
-                        $localid            =
-                                   $yadis_service->getElements('xrd:LocalID');
-                        $this->listener_uri =
-                                   $yadis_service->parser->content($localid[0]);
-                }
-                $uris                           = $yadis_service->getURIs();
-                $this->services[$targetservice] = $uris[0];
-            }
-        }
-    }
-
-    /**
-     * Get the handler URI for a service
-     *
-     * Returns the URI the remote web service has specified for the given
-     * service.
-     *
-     * @param string $service The URI identifying the service
-     *
-     * @access public
-     *
-     * @return string The service handler URI
-     */
-    public function getServiceURI($service)
-    {
-        return $this->services[$service];
-    }
-
-    /**
-     * Get the remote user’s URI
-     *
-     * Returns the URI of the remote user, i. e. the listener.
-     *
-     * @access public
-     *
-     * @return string The remote user’s URI
-     */
-    public function getRemoteUserURI()
-    {
-        return $this->listener_uri;
-    }
-
-    /**
-     * Get the listenee’s URI
-     *
-     * Returns the URI of the user being subscribed to, i. e. the local user.
-     *
-     * @access public
-     *
-     * @return string The local user’s URI
-     */
-    public function getListeneeURI()
-    {
-        return $this->listenee_uri;
-    }
-
-    /**
-     * Request a request token
-     *
-     * Performs a token request on the service. Returns an OAuthToken on success.
-     * Throws an exception if the request fails.
-     *
-     * @access public
-     *
-     * @return OAuthToken An unauthorized request token
-     */
-    public function requestToken()
-    {
-        /* Set the token to null just in case the user called setToken. */
-        $this->token = null;
-
-        $result = $this->performAction(OAUTH_ENDPOINT_REQUEST,
-                                       array('omb_listener' => $this->listener_uri));
-        if ($result->status != 200) {
-            throw OMB_RemoteServiceException::fromYadis(OAUTH_ENDPOINT_REQUEST,
-                                                        $result);
-        }
-        parse_str($result->body, $return);
-        if (!isset($return['oauth_token']) ||
-            !isset($return['oauth_token_secret'])) {
-            throw OMB_RemoteServiceException::fromYadis(OAUTH_ENDPOINT_REQUEST,
-                                                        $result);
-        }
-        $this->setToken($return['oauth_token'], $return['oauth_token_secret']);
-        return $this->token;
-    }
-
-    /**
-     * Request authorization
-     *
-     * Returns an URL which equals to an authorization request. The end user
-     * should be redirected to this location to perform authorization.
-     * The $finish_url should be a local resource which invokes
-     * OMB_Consumer::finishAuthorization on request.
-     *
-     * @param OMB_Profile $profile    An OMB_Profile object representing the
-     *                                soon-to-be subscribed (i. e. local) user
-     * @param string      $finish_url Target location after successful
-     *                                authorization
-     *
-     * @access public
-     *
-     * @return string An URL representing an authorization request
-     */
-    public function requestAuthorization($profile, $finish_url)
-    {
-        if ($this->performLegacyAuthRequest) {
-            $params                   = $profile->asParameters('omb_listenee',
-                                                               false);
-            $params['omb_listener']   = $this->listener_uri;
-            $params['oauth_callback'] = $finish_url;
-
-            $url = $this->prepareAction(OAUTH_ENDPOINT_AUTHORIZE, $params,
-                                        'GET')->to_url();
-        } else {
-            $params = array('oauth_callback' => $finish_url,
-                            'oauth_token'    => $this->token->key,
-                            'omb_version'    => OMB_VERSION,
-                            'omb_listener'   => $this->listener_uri);
-
-            $params = array_merge($profile->asParameters('omb_listenee', false),
-                                  $params);
-
-            /* Build result URL. */
-            $url = $this->services[OAUTH_ENDPOINT_AUTHORIZE] .
-                   (strrpos($url, '?') === false ? '?' : '&');
-            foreach ($params as $k => $v) {
-                $url .= OAuthUtil::urlencode_rfc3986($k) . '=' .
-                        OAuthUtil::urlencode_rfc3986($v) . '&';
-            }
-        }
-
-        $this->listenee_uri = $profile->getIdentifierURI();
-
-        return $url;
-    }
-
-    /**
-     * Finish authorization
-     *
-     * Finish the subscription process by converting the received and authorized
-     * request token into an access token. After that, the subscriber’s profile
-     * and the subscription are stored in the database.
-     * Expects an OAuthRequest in query parameters.
-     * Throws exceptions on failure.
-     *
-     * @access public
-     */
-    public function finishAuthorization()
-    {
-        OMB_Helper::removeMagicQuotesFromRequest();
-        $req = OAuthRequest::from_request();
-        if ($req->get_parameter('oauth_token') != $this->token->key) {
-            /* That’s not the token I wanted to get authorized. */
-            throw new OAuthException('The authorized token does not equal ' .
-                                     'the submitted token.');
-        }
-
-        if ($req->get_parameter('omb_version') != OMB_VERSION) {
-            throw new OMB_RemoteServiceException('The remote service uses an ' .
-                                                 'unsupported OMB version');
-        }
-
-        /* Construct the profile to validate it. */
-
-        /* Fix OMB bug. Listener URI is not passed. */
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-            $params = $_POST;
-        } else {
-            $params = $_GET;
-        }
-        $params['omb_listener'] = $this->listener_uri;
-
-        $listener = OMB_Profile::fromParameters($params, 'omb_listener');
-
-        /* Ask the remote service to convert the authorized request token into
-           an access token. */
-
-        $result = $this->performAction(OAUTH_ENDPOINT_ACCESS, array());
-        if ($result->status != 200) {
-            throw new OAuthException('Could not get access token');
-        }
-
-        parse_str($result->body, $return);
-        if (!isset($return['oauth_token']) ||
-            !isset($return['oauth_token_secret'])) {
-            throw new OAuthException('Could not get access token');
-        }
-        $this->setToken($return['oauth_token'], $return['oauth_token_secret']);
-
-        /* Subscription is finished and valid. Now store the new subscriber and
-           the subscription in the database. */
-
-        $this->datastore->saveProfile($listener);
-        $this->datastore->saveSubscription($this->listener_uri,
-                                           $this->listenee_uri,
-                                           $this->token);
-    }
-
-    /**
-     * Return the URI identifying the listener
-     *
-     * Returns the URI for the OMB user who tries to subscribe or already has
-     * subscribed our user. This method is a workaround for a serious OMB flaw:
-     * The Listener URI is not passed in the finishauthorization call.
-     *
-     * @access public
-     *
-     * @return string the listener’s URI
-     */
-    public function getListenerURI()
-    {
-        return $this->listener_uri;
-    }
-
-    /**
-     * Inform the service about a profile update
-     *
-     * Sends an updated profile to the service.
-     *
-     * @param OMB_Profile $profile The profile that has changed
-     *
-     * @access public
-     */
-    public function updateProfile($profile)
-    {
-        $params = $profile->asParameters('omb_listenee', true);
-        $this->performOMBAction(OMB_ENDPOINT_UPDATEPROFILE, $params,
-                                $profile->getIdentifierURI());
-    }
-
-    /**
-     * Inform the service about a new notice
-     *
-     * Sends a notice to the service.
-     *
-     * @param OMB_Notice $notice The notice
-     *
-     * @access public
-     */
-    public function postNotice($notice)
-    {
-        $params                 = $notice->asParameters();
-        $params['omb_listenee'] = $notice->getAuthor()->getIdentifierURI();
-        $this->performOMBAction(OMB_ENDPOINT_POSTNOTICE, $params,
-                                $params['omb_listenee']);
-    }
-
-    /**
-     * Set the token member variable
-     *
-     * Initializes the token based on given token and secret token.
-     *
-     * @param string $token  The token
-     * @param string $secret The secret token
-     *
-     * @access public
-     */
-    public function setToken($token, $secret)
-    {
-        $this->token = new OAuthToken($token, $secret);
-    }
-
-    /**
-     * Prepare an OAuthRequest object
-     *
-     * Creates an OAuthRequest object mapping the request specified by the
-     * parameters.
-     *
-     * @param string $action_uri The URI specifying the target service
-     * @param array  $params     Additional parameters for the service call
-     * @param string $method     The HTTP method used to call the service
-     *                           ('POST' or 'GET', usually)
-     *
-     * @access protected
-     *
-     * @return OAuthRequest the prepared request
-     */
-    protected function prepareAction($action_uri, $params, $method)
-    {
-        $url = $this->services[$action_uri];
-
-        $url_params = array();
-        parse_str(parse_url($url, PHP_URL_QUERY), $url_params);
-
-        /* Add OMB version. */
-        $url_params['omb_version'] = OMB_VERSION;
-
-        /* Add user-defined parameters. */
-        $url_params = array_merge($url_params, $params);
-
-        $req = OAuthRequest::from_consumer_and_token($this->oauth_consumer,
-                                                     $this->token, $method,
-                                                     $url, $url_params);
-
-        /* Sign the request. */
-        $req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
-                           $this->oauth_consumer, $this->token);
-
-        return $req;
-    }
-
-    /**
-     * Perform a service call
-     *
-     * Creates an OAuthRequest object and execute the mapped call as POST
-     * request.
-     *
-     * @param string $action_uri The URI specifying the target service
-     * @param array  $params     Additional parameters for the service call
-     *
-     * @access protected
-     *
-     * @return Auth_Yadis_HTTPResponse The POST request response
-     */
-    protected function performAction($action_uri, $params)
-    {
-        $req = $this->prepareAction($action_uri, $params, 'POST');
-
-        /* Return result page. */
-        return $this->fetcher->post($req->get_normalized_http_url(),
-                                    $req->to_postdata(), array());
-    }
-
-    /**
-     * Perform an OMB action
-     *
-     * Executes an OMB action – as of OMB 0.1, it’s one of updateProfile and
-     * postNotice.
-     *
-     * @param string $action_uri   The URI specifying the target service
-     * @param array  $params       Additional parameters for the service call
-     * @param string $listenee_uri The URI identifying the local user for whom
-     *                             the action is performed
-     *
-     * @access protected
-     */
-    protected function performOMBAction($action_uri, $params, $listenee_uri)
-    {
-        $result = $this->performAction($action_uri, $params);
-        if ($result->status == 403) {
-            /* The remote user unsubscribed us. */
-            $this->datastore->deleteSubscription($this->listener_uri,
-                                                 $listenee_uri);
-        } else if ($result->status != 200 ||
-                   strpos($result->body, 'omb_version=' . OMB_VERSION) === false) {
-            /* The server signaled an error or sent an incorrect response. */
-            throw OMB_RemoteServiceException::fromYadis($action_uri, $result);
-        }
-    }
-}
-?>
diff --git a/extlib/libomb/service_provider.php b/extlib/libomb/service_provider.php
deleted file mode 100755 (executable)
index 9a1a488..0000000
+++ /dev/null
@@ -1,461 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-require_once 'constants.php';
-require_once 'helper.php';
-require_once 'notice.php';
-require_once 'remoteserviceexception.php';
-
-/**
- * OMB service realization
- *
- * This class realizes a complete, simple OMB service.
- */
-class OMB_Service_Provider
-{
-    protected $user; /* An OMB_Profile representing the user */
-    protected $datastore; /* AN OMB_Datastore */
-
-    protected $remote_user; /* An OMB_Profile representing the remote user
-                               during the authorization process */
-
-    protected $oauth_server; /* An OAuthServer; should only be accessed via
-                                getOAuthServer. */
-
-    /**
-     * Initialize an OMB_Service_Provider object
-     *
-     * Constructs an OMB_Service_Provider instance that provides OMB services
-     * referring to a particular user.
-     *
-     * @param OMB_Profile   $user         An OMB_Profile; mandatory for XRDS
-     *                                    output, user auth handling and OMB
-     *                                    action performing
-     * @param OMB_Datastore $datastore    An OMB_Datastore; mandatory for
-     *                                    everything but XRDS output
-     * @param OAuthServer   $oauth_server An OAuthServer; used for token writing
-     *                                    and OMB action handling; will use
-     *                                    default value if not set
-     *
-     * @access public
-     */
-    public function __construct ($user = null, $datastore = null,
-                                 $oauth_server = null)
-    {
-        $this->user         = $user;
-        $this->datastore    = $datastore;
-        $this->oauth_server = $oauth_server;
-    }
-
-    /**
-     * Return the remote user during user authorization
-     *
-     * Returns an OMB_Profile representing the remote user during the user
-     * authorization request.
-     *
-     * @return OMB_Profile The remote user
-     */
-    public function getRemoteUser()
-    {
-        return $this->remote_user;
-    }
-
-    /**
-     * Write a XRDS document
-     *
-     * Writes a XRDS document specifying the OMB service. Optionally uses a
-     * given object of a class implementing OMB_XRDS_Writer for output. Else
-     * OMB_Plain_XRDS_Writer is used.
-     *
-     * @param OMB_XRDS_Mapper $xrds_mapper An object mapping actions to URLs
-     * @param OMB_XRDS_Writer $xrds_writer Optional; The OMB_XRDS_Writer used to
-     *                                     write the XRDS document
-     *
-     * @access public
-     *
-     * @return mixed Depends on the used OMB_XRDS_Writer; OMB_Plain_XRDS_Writer
-     *               returns nothing.
-     */
-    public function writeXRDS($xrds_mapper, $xrds_writer = null)
-    {
-        if ($xrds_writer == null) {
-                require_once 'plain_xrds_writer.php';
-                $xrds_writer = new OMB_Plain_XRDS_Writer();
-        }
-        return $xrds_writer->writeXRDS($this->user, $xrds_mapper);
-    }
-
-    /**
-     * Echo a request token
-     *
-     * Outputs an unauthorized request token for the query found in $_GET or
-     * $_POST.
-     *
-     * @access public
-     */
-    public function writeRequestToken()
-    {
-        OMB_Helper::removeMagicQuotesFromRequest();
-        echo $this->getOAuthServer()->fetch_request_token(
-                                                  OAuthRequest::from_request());
-    }
-
-    /**
-     * Handle an user authorization request.
-     *
-     * Parses an authorization request. This includes OAuth and OMB
-     * verification.
-     * Throws exceptions on failures. Returns an OMB_Profile object representing
-     * the remote user.
-     *
-     * The OMB_Profile passed to the constructor of OMB_Service_Provider should
-     * not represent the user specified in the authorization request, but the
-     * one currently logged in to the service. This condition being satisfied,
-     * handleUserAuth will check whether the listener specified in the request
-     * is identical to the logged in user.
-     *
-     * @access public
-     *
-     * @return OMB_Profile The profile of the soon-to-be subscribed, i. e.
-     *                     remote user
-     */
-    public function handleUserAuth()
-    {
-        OMB_Helper::removeMagicQuotesFromRequest();
-
-        /* Verify the request token. */
-
-        $this->token = $this->datastore->lookup_token(null, "request",
-                                                      $_GET['oauth_token']);
-        if (is_null($this->token)) {
-            throw new OAuthException('The given request token has not been ' .
-                                     'issued by this service.');
-        }
-
-        /* Verify the OMB part. */
-
-        if ($_GET['omb_version'] !== OMB_VERSION) {
-            throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE,
-                                                         'Wrong OMB version ' .
-                                                         $_GET['omb_version']);
-        }
-
-        if ($_GET['omb_listener'] !== $this->user->getIdentifierURI()) {
-            throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE,
-                                                         'Wrong OMB listener ' .
-                                                         $_GET['omb_listener']);
-        }
-
-        foreach (array('omb_listenee', 'omb_listenee_profile',
-                       'omb_listenee_nickname', 'omb_listenee_license') as $param) {
-            if (!isset($_GET[$param]) || is_null($_GET[$param])) {
-                throw OMB_RemoteServiceException::forRequest(
-                                       OAUTH_ENDPOINT_AUTHORIZE,
-                                       "Required parameter '$param' not found");
-            }
-        }
-
-        /* Store given callback for later use. */
-        if (isset($_GET['oauth_callback']) && $_GET['oauth_callback'] !== '') {
-            $this->callback = $_GET['oauth_callback'];
-            if (!OMB_Helper::validateURL($this->callback)) {
-                throw OMB_RemoteServiceException::forRequest(
-                                        OAUTH_ENDPOINT_AUTHORIZE,
-                                        'Invalid callback URL specified');
-            }
-        }
-        $this->remote_user = OMB_Profile::fromParameters($_GET, 'omb_listenee');
-
-        return $this->remote_user;
-    }
-
-    /**
-     * Continue the OAuth dance after user authorization
-     *
-     * Performs the appropriate actions after user answered the authorization
-     * request.
-     *
-     * @param bool $accepted Whether the user granted authorization
-     *
-     * @access public
-     *
-     * @return array A two-component array with the values:
-     *                 - callback The callback URL or null if none given
-     *                 - token    The authorized request token or null if not
-     *                            authorized.
-     */
-    public function continueUserAuth($accepted)
-    {
-        $callback = $this->callback;
-        if (!$accepted) {
-            $this->datastore->revoke_token($this->token->key);
-            $this->token = null;
-
-        } else {
-            $this->datastore->authorize_token($this->token->key);
-            $this->datastore->saveProfile($this->remote_user);
-            $this->datastore->saveSubscription($this->user->getIdentifierURI(),
-                                         $this->remote_user->getIdentifierURI(),
-                                         $this->token);
-
-            if (!is_null($this->callback)) {
-                /* Callback wants to get some informations as well. */
-                $params = $this->user->asParameters('omb_listener', false);
-
-                $params['oauth_token'] = $this->token->key;
-                $params['omb_version'] = OMB_VERSION;
-
-                $callback .= (parse_url($this->callback, PHP_URL_QUERY) ? '&' : '?');
-                foreach ($params as $k => $v) {
-                    $callback .= OAuthUtil::urlencode_rfc3986($k) . '=' .
-                                 OAuthUtil::urlencode_rfc3986($v) . '&';
-                }
-            }
-        }
-        return array($callback, $this->token);
-    }
-
-    /**
-     * Echo an access token
-     *
-     * Outputs an access token for the query found in $_POST. OMB 0.1 specifies
-     * that the access token request has to be a POST even if OAuth allows GET
-     * as well.
-     *
-     * @access public
-     */
-    public function writeAccessToken()
-    {
-        OMB_Helper::removeMagicQuotesFromRequest();
-        echo $this->getOAuthServer()->fetch_access_token(
-                                            OAuthRequest::from_request('POST'));
-    }
-
-    /**
-     * Handle an updateprofile request
-     *
-     * Handles an updateprofile request posted to this service. Updates the
-     * profile through the OMB_Datastore.
-     *
-     * @access public
-     *
-     * @return OMB_Profile The updated profile
-     */
-    public function handleUpdateProfile()
-    {
-        list($req, $profile) = $this->handleOMBRequest(OMB_ENDPOINT_UPDATEPROFILE);
-        $profile->updateFromParameters($req->get_parameters(), 'omb_listenee');
-        $this->datastore->saveProfile($profile);
-        $this->finishOMBRequest();
-        return $profile;
-    }
-
-    /**
-     * Handle a postnotice request
-     *
-     * Handles a postnotice request posted to this service. Saves the notice
-     * through the OMB_Datastore.
-     *
-     * @access public
-     *
-     * @return OMB_Notice The received notice
-     */
-    public function handlePostNotice()
-    {
-        list($req, $profile) = $this->handleOMBRequest(OMB_ENDPOINT_POSTNOTICE);
-
-        $notice = OMB_Notice::fromParameters($profile, $req->get_parameters());
-        $this->datastore->saveNotice($notice);
-        $this->finishOMBRequest();
-
-        return $notice;
-    }
-
-    /**
-     * Handle an OMB request
-     *
-     * Performs common OMB request handling.
-     *
-     * @param string $uri The URI defining the OMB endpoint being served
-     *
-     * @access protected
-     *
-     * @return array(OAuthRequest, OMB_Profile)
-     */
-    protected function handleOMBRequest($uri)
-    {
-        OMB_Helper::removeMagicQuotesFromRequest();
-        $req      = OAuthRequest::from_request('POST');
-        $listenee = $req->get_parameter('omb_listenee');
-
-        try {
-            list($consumer, $token) = $this->getOAuthServer()->verify_request($req);
-        } catch (OAuthException $e) {
-            header('HTTP/1.1 403 Forbidden');
-            throw OMB_RemoteServiceException::forRequest($uri,
-                                       'Revoked accesstoken for ' . $listenee);
-        }
-
-        $version = $req->get_parameter('omb_version');
-        if ($version !== OMB_VERSION) {
-            header('HTTP/1.1 400 Bad Request');
-            throw OMB_RemoteServiceException::forRequest($uri,
-                                               'Wrong OMB version ' . $version);
-        }
-
-        $profile = $this->datastore->getProfile($listenee);
-        if (is_null($profile)) {
-            header('HTTP/1.1 400 Bad Request');
-            throw OMB_RemoteServiceException::forRequest($uri,
-                                         'Unknown remote profile ' . $listenee);
-        }
-
-        $subscribers = $this->datastore->getSubscriptions($listenee);
-        if (count($subscribers) === 0) {
-            header('HTTP/1.1 403 Forbidden');
-            throw OMB_RemoteServiceException::forRequest($uri,
-                                              'No subscriber for ' . $listenee);
-        }
-
-        return array($req, $profile);
-    }
-
-    /**
-     * Finishes an OMB request handling
-     *
-     * Performs common OMB request handling finishing.
-     *
-     * @access protected
-     */
-    protected function finishOMBRequest()
-    {
-        header('HTTP/1.1 200 OK');
-        header('Content-type: text/plain');
-        /* There should be no clutter but the version. */
-        echo "omb_version=" . OMB_VERSION;
-    }
-
-    /**
-     * Return an OAuthServer
-     *
-     * Checks whether the OAuthServer is null. If so, initializes it with a
-     * default value. Returns the OAuth server.
-     *
-     * @access protected
-     */
-    protected function getOAuthServer()
-    {
-        if (is_null($this->oauth_server)) {
-            $this->oauth_server = new OAuthServer($this->datastore);
-            $this->oauth_server->add_signature_method(
-                                          new OAuthSignatureMethod_HMAC_SHA1());
-        }
-        return $this->oauth_server;
-    }
-
-    /**
-     * Publish a notice
-     *
-     * Posts an OMB notice. This includes storing the notice and posting it to
-     * subscribed users.
-     *
-     * @param OMB_Notice $notice The new notice
-     *
-     * @access public
-     *
-     * @return array An array mapping subscriber URIs to the exception posting
-     *               to them has raised; Empty array if no exception occured
-     */
-    public function postNotice($notice)
-    {
-        $uri = $this->user->getIdentifierURI();
-
-        /* $notice is passed by reference and may change. */
-        $this->datastore->saveNotice($notice);
-        $subscribers = $this->datastore->getSubscriptions($uri);
-
-        /* No one to post to. */
-        if (is_null($subscribers)) {
-            return array();
-        }
-
-        require_once 'service_consumer.php';
-
-        $err = array();
-        foreach ($subscribers as $subscriber) {
-            try {
-                $service = new OMB_Service_Consumer($subscriber['uri'], $uri,
-                                                    $this->datastore);
-                $service->setToken($subscriber['token'], $subscriber['secret']);
-                $service->postNotice($notice);
-            } catch (Exception $e) {
-                $err[$subscriber['uri']] = $e;
-                continue;
-            }
-        }
-        return $err;
-    }
-
-    /**
-     * Publish a profile update
-     *
-     * Posts the current profile as an OMB profile update. This includes
-     * updating the stored profile and posting it to subscribed users.
-     *
-     * @access public
-     *
-     * @return array An array mapping subscriber URIs to the exception posting
-     *               to them has raised; Empty array if no exception occured
-     */
-    public function updateProfile()
-    {
-        $uri = $this->user->getIdentifierURI();
-
-        $this->datastore->saveProfile($this->user);
-        $subscribers = $this->datastore->getSubscriptions($uri);
-
-        /* No one to post to. */
-        if (is_null($subscribers)) {
-                return array();
-        }
-
-        require_once 'service_consumer.php';
-
-        $err = array();
-        foreach ($subscribers as $subscriber) {
-            try {
-                $service = new OMB_Service_Consumer($subscriber['uri'], $uri,
-                                                    $this->datastore);
-                $service->setToken($subscriber['token'], $subscriber['secret']);
-                $service->updateProfile($this->user);
-            } catch (Exception $e) {
-                $err[$subscriber['uri']] = $e;
-                continue;
-            }
-        }
-        return $err;
-    }
-}
diff --git a/extlib/libomb/unsupportedserviceexception.php b/extlib/libomb/unsupportedserviceexception.php
deleted file mode 100755 (executable)
index be30a1f..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-/**
- * Exception stating that a requested service is not available
- *
- * This exception is raised when OMB_Service is asked to call a service the
- * remote server does not provide.
- */
-class OMB_UnsupportedServiceException extends Exception
-{
-}
-?>
diff --git a/extlib/libomb/xrds_mapper.php b/extlib/libomb/xrds_mapper.php
deleted file mode 100755 (executable)
index 8fbe652..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-/**
- * Map XRDS actions to URLs
- *
- * This interface specifies classes which write the XRDS file announcing
- * the OMB server. An instance of an implementing class should be passed to
- * OMB_Service_Provider->writeXRDS.
- */
-interface OMB_XRDS_Mapper
-{
-    /**
-     * Fetch an URL for a specified action
-     *
-     * Returns the action URL for an action specified by the endpoint URI.
-     *
-     * @param string $action The endpoint URI
-     *
-     * @return string The action URL
-     */
-    public function getURL($action);
-}
-?>
diff --git a/extlib/libomb/xrds_writer.php b/extlib/libomb/xrds_writer.php
deleted file mode 100755 (executable)
index c7939d6..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * This file is part of libomb
- *
- * PHP version 5
- *
- * LICENSE: 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 OMB
- * @author  Adrian Lang <mail@adrianlang.de>
- * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
- * @version 0.1a-20090828
- * @link    http://adrianlang.de/libomb
- */
-
-/**
- * Write OMB-specific XRDS
- *
- * This interface specifies classes which write the XRDS file announcing
- * the OMB server. An instance of an implementing class should be passed to
- * OMB_Service_Provider->writeXRDS.
- */
-interface OMB_XRDS_Writer
-{
-    /**
-     * Write XRDS
-     *
-     * Outputs a XRDS document specifying an OMB service.
-     *
-     * @param OMB_profile     $user   The target user for the OMB service
-     * @param OMB_XRDS_Mapper $mapper An OMB_XRDS_Mapper providing endpoint URLs
-     */
-    public function writeXRDS($user, $mapper);
-}
-?>
index 54cecf92a8dca80d27588478f0342309c24946b6..a93811cc0ff63759ec83d30d0d58d9dcebc36a49 100644 (file)
@@ -31,7 +31,7 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 require_once INSTALLDIR . '/lib/apiaction.php';
-require_once INSTALLDIR . '/lib/apioauthstore.php';
+require_once INSTALLDIR . '/lib/statusnetoauthstore.php';
 
 /**
  * Base action for API OAuth enpoints. Clean up the
diff --git a/lib/apioauthstore.php b/lib/apioauthstore.php
deleted file mode 100644 (file)
index ac53ec2..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-<?php
-/*
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR . '/lib/oauthstore.php';
-
-// @todo FIXME: Class documentation missing.
-class ApiStatusNetOAuthDataStore extends StatusNetOAuthDataStore
-{
-    function lookup_consumer($consumerKey)
-    {
-        $con = Consumer::staticGet('consumer_key', $consumerKey);
-
-        if (!$con) {
-
-            // Create an anon consumer and anon application if one
-            // doesn't exist already
-            if ($consumerKey == 'anonymous') {
-
-                common_debug("API OAuth - creating anonymous consumer");
-                $con = new Consumer();
-                $con->consumer_key    = $consumerKey;
-                $con->consumer_secret = $consumerKey;
-                $con->created         = common_sql_now();
-
-                $result = $con->insert();
-                if (!$result) {
-                    // TRANS: Server error displayed when trying to create an anynymous OAuth consumer.
-                    $this->serverError(_('Could not create anonymous consumer.'));
-                }
-
-                $app = Oauth_application::getByConsumerKey('anonymous');
-
-                if (!$app) {
-                    common_debug("API OAuth - creating anonymous application");
-                    $app               = new OAuth_application();
-                    $app->owner        = 1; // XXX: What to do here?
-                    $app->consumer_key = $con->consumer_key;
-                    $app->name         = 'anonymous';
-                    $app->icon         = 'default-avatar-stream.png'; // XXX: Fix this!
-                    $app->description  = "An anonymous application";
-                    // XXX: allow the user to set the access type when
-                    // authorizing? Currently we default to r+w for anonymous
-                    // OAuth client applications
-                    $app->access_type  = 3; // read + write
-                    $app->type         = 2; // desktop
-                    $app->created      = common_sql_now();
-
-                    $id = $app->insert();
-
-                    if (!$id) {
-                        // TRANS: Server error displayed when trying to create an anynymous OAuth application.
-                        $this->serverError(_("Could not create anonymous OAuth application."));
-                    }
-                }
-            } else {
-                return null;
-            }
-        }
-
-        return new OAuthConsumer(
-            $con->consumer_key,
-            $con->consumer_secret
-        );
-    }
-
-    function getAppByRequestToken($token_key)
-    {
-        // Look up the full req token
-        $req_token = $this->lookup_token(
-            null,
-            'request',
-            $token_key
-        );
-
-        if (empty($req_token)) {
-            common_debug("Couldn't get request token from oauth datastore");
-            return null;
-        }
-
-        // Look up the full Token
-        $token = new Token();
-        $token->tok = $req_token->key;
-        $result = $token->find(true);
-
-        if (empty($result)) {
-            common_debug('Couldn\'t find req token in the token table.');
-            return null;
-        }
-
-        // Look up the app
-        $app = new Oauth_application();
-        $app->consumer_key = $token->consumer_key;
-        $result = $app->find(true);
-
-        if (!empty($result)) {
-            return $app;
-        } else {
-            common_debug("Couldn't find the app!");
-            return null;
-        }
-    }
-
-    function new_access_token($token, $consumer, $verifier)
-    {
-        common_debug(
-            sprintf(
-                "New access token from request token %s, consumer %s and verifier %s ",
-                $token,
-                $consumer,
-                $verifier
-            ),
-            __FILE__
-        );
-
-        $rt = new Token();
-
-        $rt->consumer_key = $consumer->key;
-        $rt->tok          = $token->key;
-        $rt->type         = 0; // request
-
-        $app = Oauth_application::getByConsumerKey($consumer->key);
-        assert(!empty($app));
-
-        if ($rt->find(true) && $rt->state == 1 && $rt->verifier == $verifier) { // authorized
-
-            common_debug('Request token found.', __FILE__);
-
-            // find the app and profile associated with this token
-            $tokenAssoc = Oauth_token_association::staticGet('token', $rt->tok);
-
-            if (!$tokenAssoc) {
-                throw new Exception(
-                    // TRANS: Exception thrown when no token association could be found.
-                    _('Could not find a profile and application associated with the request token.')
-                );
-            }
-
-            // Check to see if we have previously issued an access token for
-            // this application and profile; if so we can just return the
-            // existing access token. That seems to be the best practice. It
-            // makes it so users only have to authorize the app once per
-            // machine.
-
-            $appUser = new Oauth_application_user();
-
-            $appUser->application_id = $app->id;
-            $appUser->profile_id     = $tokenAssoc->profile_id;
-
-            $result = $appUser->find(true);
-
-            if (!empty($result)) {
-
-                common_log(LOG_INFO,
-                     sprintf(
-                        "Existing access token found for application %s, profile %s.",
-                        $app->id,
-                        $tokenAssoc->profile_id
-                     )
-                );
-
-                $at = null;
-
-                // Special case: we used to store request tokens in the
-                // Oauth_application_user record, and the access_type would
-                // always be 0 (no access) as a failsafe until an access
-                // token was issued and replaced the request token. There could
-                // be a few old Oauth_application_user records storing request
-                // tokens still around, and we don't want to accidentally
-                // return a useless request token instead of a new access
-                // token. So if we find one, we generate a new access token
-                // and update the existing Oauth_application_user record before
-                // returning the new access token. This should be rare.
-
-                if ($appUser->access_type == 0) {
-
-                    $at = $this->generateNewAccessToken($consumer, $rt, $verifier);
-                    $this->updateAppUser($appUser, $app, $at);
-
-                } else {
-
-                    $at = new Token();
-
-                    // fetch the full access token
-                    $at->consumer_key = $consumer->key;
-                    $at->tok          = $appUser->token;
-
-                    $result = $at->find(true);
-
-                    if (!$result) {
-                        throw new Exception(
-                            // TRANS: Exception thrown when no access token can be issued.
-                            _('Could not issue access token.')
-                        );
-                    }
-                }
-
-                // Yay, we can re-issue the access token
-                return new OAuthToken($at->tok, $at->secret);
-
-            } else {
-
-               common_log(LOG_INFO,
-                    sprintf(
-                        "Creating new access token for application %s, profile %s.",
-                        $app->id,
-                        $tokenAssoc->profile_id
-                     )
-                );
-
-                $at = $this->generateNewAccessToken($consumer, $rt, $verifier);
-                $this->newAppUser($tokenAssoc, $app, $at);
-
-                // Okay, good
-                return new OAuthToken($at->tok, $at->secret);
-            }
-
-        } else {
-
-            // the token was not authorized or not verfied
-            common_log(
-                LOG_INFO,
-                sprintf(
-                    "API OAuth - Attempt to exchange unauthorized or unverified request token %s for an access token.",
-                     $rt->tok
-                )
-            );
-            return null;
-        }
-    }
-
-    /*
-     * Generate a new access token and save it to the database
-     *
-     * @param Consumer $consumer the OAuth consumer
-     * @param Token    $rt       the authorized request token
-     * @param string   $verifier the OAuth 1.0a verifier
-     *
-     * @access private
-     *
-     * @return Token   $at       the new access token
-     */
-    private function generateNewAccessToken($consumer, $rt, $verifier)
-    {
-        $at = new Token();
-
-        $at->consumer_key      = $consumer->key;
-        $at->tok               = common_good_rand(16);
-        $at->secret            = common_good_rand(16);
-        $at->type              = 1; // access
-        $at->verifier          = $verifier;
-        $at->verified_callback = $rt->verified_callback; // 1.0a
-        $at->created           = common_sql_now();
-
-        if (!$at->insert()) {
-            $e = $at->_lastError;
-            common_debug('access token "' . $at->tok . '" not inserted: "' . $e->message . '"', __FILE__);
-            return null;
-        } else {
-            common_debug('access token "' . $at->tok . '" inserted', __FILE__);
-            // burn the old one
-            $orig_rt   = clone($rt);
-            $rt->state = 2; // used
-            if (!$rt->update($orig_rt)) {
-                return null;
-            }
-            common_debug('request token "' . $rt->tok . '" updated', __FILE__);
-        }
-
-        return $at;
-    }
-
-   /*
-    * Add a new app user (Oauth_application_user) record
-    *
-    * @param Oauth_token_association $tokenAssoc token-to-app association
-    * @param Oauth_application       $app        the OAuth client app
-    * @param Token                   $at         the access token
-    *
-    * @access private
-    *
-    * @return void
-    */
-    private function newAppUser($tokenAssoc, $app, $at)
-    {
-        $appUser = new Oauth_application_user();
-
-        $appUser->profile_id     = $tokenAssoc->profile_id;
-        $appUser->application_id = $app->id;
-        $appUser->access_type    = $app->access_type;
-        $appUser->token          = $at->tok;
-        $appUser->created        = common_sql_now();
-
-        $result = $appUser->insert();
-
-        if (!$result) {
-            common_log_db_error($appUser, 'INSERT', __FILE__);
-
-            throw new Exception(
-                // TRANS: Exception thrown when a database error occurs.
-                _('Database error inserting OAuth application user.')
-            );
-        }
-    }
-
-   /*
-    * Update an existing app user (Oauth_application_user) record
-    *
-    * @param Oauth_application_user $appUser existing app user rec
-    * @param Oauth_application      $app     the OAuth client app
-    * @param Token                  $at      the access token
-    *
-    * @access private
-    *
-    * @return void
-    */
-    private function updateAppUser($appUser, $app, $at)
-    {
-        $original = clone($appUser);
-        $appUser->access_type = $app->access_type;
-        $appUser->token       = $at->tok;
-
-        $result = $appUser->update($original);
-
-        if (!$result) {
-            common_log_db_error($appUser, 'UPDATE', __FILE__);
-            throw new Exception(
-                // TRANS: Exception thrown when a database error occurs.
-                _('Database error updating OAuth application user.')
-            );
-        }
-    }
-
-    /**
-     * Revoke specified access token
-     *
-     * Revokes the token specified by $token_key.
-     * Throws exceptions in case of error.
-     *
-     * @param string $token_key the token to be revoked
-     * @param int    $type      type of token (0 = req, 1 = access)
-     *
-     * @access public
-     *
-     * @return void
-     */
-    public function revoke_token($token_key, $type = 0) {
-        $rt        = new Token();
-        $rt->tok   = $token_key;
-        $rt->type  = $type;
-        $rt->state = 0;
-
-        if (!$rt->find(true)) {
-            // TRANS: Exception thrown when an attempt is made to revoke an unknown token.
-            throw new Exception(_('Tried to revoke unknown token.'));
-        }
-
-        if (!$rt->delete()) {
-            // TRANS: Exception thrown when an attempt is made to remove a revoked token.
-            throw new Exception(_('Failed to delete revoked token.'));
-        }
-    }
-
-    /*
-     * Create a new request token. Overrided to support OAuth 1.0a callback
-     *
-     * @param OAuthConsumer $consumer the OAuth Consumer for this token
-     * @param string        $callback the verified OAuth callback URL
-     *
-     * @return OAuthToken   $token a new unauthorized OAuth request token
-     */
-    function new_request_token($consumer, $callback)
-    {
-        $t = new Token();
-        $t->consumer_key = $consumer->key;
-        $t->tok = common_good_rand(16);
-        $t->secret = common_good_rand(16);
-        $t->type = 0; // request
-        $t->state = 0; // unauthorized
-        $t->verified_callback = $callback;
-
-        if ($callback === 'oob') {
-            // six digit pin
-            $t->verifier = mt_rand(0, 9999999);
-        } else {
-            $t->verifier = common_good_rand(8);
-        }
-
-        $t->created = DB_DataObject_Cast::dateTime();
-        if (!$t->insert()) {
-            return null;
-        } else {
-            return new OAuthToken($t->tok, $t->secret);
-        }
-    }
-}
index 1dfb90036e7c451c6f93ea4821ed58ba3daaa57c..0ef2d50141497d845dc8ac053966c8d46f1627b3 100644 (file)
@@ -360,7 +360,7 @@ abstract class MicroAppPlugin extends Plugin
 
             $options = array('uri' => $object->id,
                              'url' => $object->link,
-                             'is_local' => Notice::REMOTE_OMB,
+                             'is_local' => Notice::REMOTE,
                              'source' => 'ostatus');
 
             // $actor is an ostatus_profile
@@ -418,7 +418,7 @@ abstract class MicroAppPlugin extends Plugin
 
             $options = array('uri' => $object->id,
                              'url' => $object->link,
-                             'is_local' => Notice::REMOTE_OMB,
+                             'is_local' => Notice::REMOTE,
                              'source' => 'ostatus');
 
             // $actor is an ostatus_profile
diff --git a/lib/oauthstore.php b/lib/oauthstore.php
deleted file mode 100644 (file)
index 570343b..0000000
+++ /dev/null
@@ -1,520 +0,0 @@
-<?php
-/*
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once 'libomb/datastore.php';
-
-// @todo FIXME: Class documentation missing.
-class StatusNetOAuthDataStore extends OAuthDataStore
-{
-    // We keep a record of who's contacted us
-    function lookup_consumer($consumer_key)
-    {
-        $con = Consumer::staticGet('consumer_key', $consumer_key);
-        if (!$con) {
-            $con = new Consumer();
-            $con->consumer_key = $consumer_key;
-            $con->seed = common_good_rand(16);
-            $con->created = DB_DataObject_Cast::dateTime();
-            if (!$con->insert()) {
-                return null;
-            }
-        }
-        return new OAuthConsumer($con->consumer_key, '');
-    }
-
-    function lookup_token($consumer, $token_type, $token_key)
-    {
-        $t = new Token();
-        if (!is_null($consumer)) {
-            $t->consumer_key = $consumer->key;
-        }
-        $t->tok = $token_key;
-        $t->type = ($token_type == 'access') ? 1 : 0;
-        if ($t->find(true)) {
-            return new OAuthToken($t->tok, $t->secret);
-        } else {
-            return null;
-        }
-    }
-
-    function getTokenByKey($token_key)
-    {
-        $t = new Token();
-        $t->tok = $token_key;
-        if ($t->find(true)) {
-            return $t;
-        } else {
-            return null;
-        }
-    }
-
-    // http://oauth.net/core/1.0/#nonce
-    // "The Consumer SHALL then generate a Nonce value that is unique for
-    // all requests with that timestamp."
-    // XXX: It's not clear why the token is here
-    function lookup_nonce($consumer, $token, $nonce, $timestamp)
-    {
-        $n = new Nonce();
-        $n->consumer_key = $consumer->key;
-        $n->ts = common_sql_date($timestamp);
-        $n->nonce = $nonce;
-        if ($n->find(true)) {
-            return true;
-        } else {
-            $n->created = DB_DataObject_Cast::dateTime();
-            $n->insert();
-            return false;
-        }
-    }
-
-    function new_request_token($consumer)
-    {
-        $t = new Token();
-        $t->consumer_key = $consumer->key;
-        $t->tok = common_good_rand(16);
-        $t->secret = common_good_rand(16);
-        $t->type = 0; // request
-        $t->state = 0; // unauthorized
-        $t->created = DB_DataObject_Cast::dateTime();
-        if (!$t->insert()) {
-            return null;
-        } else {
-            return new OAuthToken($t->tok, $t->secret);
-        }
-    }
-
-    // defined in OAuthDataStore, but not implemented anywhere
-    function fetch_request_token($consumer)
-    {
-        return $this->new_request_token($consumer);
-    }
-
-    function new_access_token($token, $consumer)
-    {
-        common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__);
-        $rt = new Token();
-        $rt->consumer_key = $consumer->key;
-        $rt->tok = $token->key;
-        $rt->type = 0; // request
-        if ($rt->find(true) && $rt->state == 1) { // authorized
-            common_debug('request token found.', __FILE__);
-            $at = new Token();
-            $at->consumer_key = $consumer->key;
-            $at->tok = common_good_rand(16);
-            $at->secret = common_good_rand(16);
-            $at->type = 1; // access
-            $at->created = DB_DataObject_Cast::dateTime();
-            if (!$at->insert()) {
-                $e = $at->_lastError;
-                common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__);
-                return null;
-            } else {
-                common_debug('access token "'.$at->tok.'" inserted', __FILE__);
-                // burn the old one
-                $orig_rt = clone($rt);
-                $rt->state = 2; // used
-                if (!$rt->update($orig_rt)) {
-                    return null;
-                }
-                common_debug('request token "'.$rt->tok.'" updated', __FILE__);
-                // Update subscription
-                // XXX: mixing levels here
-                $sub = Subscription::staticGet('token', $rt->tok);
-                if (!$sub) {
-                    return null;
-                }
-                common_debug('subscription for request token found', __FILE__);
-                $orig_sub = clone($sub);
-                $sub->token = $at->tok;
-                $sub->secret = $at->secret;
-                if (!$sub->update($orig_sub)) {
-                    return null;
-                } else {
-                    common_debug('subscription updated to use access token', __FILE__);
-                    return new OAuthToken($at->tok, $at->secret);
-                }
-            }
-        } else {
-            return null;
-        }
-    }
-
-    // defined in OAuthDataStore, but not implemented anywhere
-    function fetch_access_token($consumer)
-    {
-        return $this->new_access_token($consumer);
-    }
-
-    /**
-     * Revoke specified OAuth token
-     *
-     * Revokes the authorization token specified by $token_key.
-     * Throws exceptions in case of error.
-     *
-     * @param string $token_key The token to be revoked
-     *
-     * @access public
-     **/
-    public function revoke_token($token_key) {
-        $rt = new Token();
-        $rt->tok = $token_key;
-        $rt->type = 0;
-        $rt->state = 0;
-        if (!$rt->find(true)) {
-            throw new Exception('Tried to revoke unknown token');
-        }
-        if (!$rt->delete()) {
-            throw new Exception('Failed to delete revoked token');
-        }
-    }
-
-    /**
-     * Authorize specified OAuth token
-     *
-     * Authorizes the authorization token specified by $token_key.
-     * Throws exceptions in case of error.
-     *
-     * @param string $token_key The token to be authorized
-     *
-     * @access public
-     **/
-    public function authorize_token($token_key) {
-        $rt = new Token();
-        $rt->tok = $token_key;
-        $rt->type = 0;
-        $rt->state = 0;
-        if (!$rt->find(true)) {
-            throw new Exception('Tried to authorize unknown token');
-        }
-        $orig_rt = clone($rt);
-        $rt->state = 1; # Authorized but not used
-        if (!$rt->update($orig_rt)) {
-            throw new Exception('Failed to authorize token');
-        }
-    }
-
-    /**
-     * Get profile by identifying URI
-     *
-     * Returns an OMB_Profile object representing the OMB profile identified by
-     * $identifier_uri.
-     * Returns null if there is no such OMB profile.
-     * Throws exceptions in case of other error.
-     *
-     * @param string $identifier_uri The OMB identifier URI specifying the
-     *                               requested profile
-     *
-     * @access public
-     *
-     * @return OMB_Profile The corresponding profile
-     **/
-    public function getProfile($identifier_uri) {
-        /* getProfile is only used for remote profiles by libomb.
-           @TODO: Make it work with local ones anyway. */
-        $remote = Remote_profile::staticGet('uri', $identifier_uri);
-        if (!$remote) throw new Exception('No such remote profile');
-        $profile = Profile::staticGet('id', $remote->id);
-        if (!$profile) throw new Exception('No profile for remote user');
-
-        require_once INSTALLDIR.'/lib/omb.php';
-        return profile_to_omb_profile($identifier_uri, $profile);
-    }
-
-    /**
-     * Save passed profile
-     *
-     * Stores the OMB profile $profile. Overwrites an existing entry.
-     * Throws exceptions in case of error.
-     *
-     * @param OMB_Profile $profile   The OMB profile which should be saved
-     *
-     * @access public
-     **/
-    public function saveProfile($omb_profile) {
-        if (common_profile_url($omb_profile->getNickname()) ==
-                                                $omb_profile->getProfileURL()) {
-            throw new Exception('Not implemented');
-        } else {
-            $remote = Remote_profile::staticGet('uri', $omb_profile->getIdentifierURI());
-
-            if ($remote) {
-                $exists = true;
-                $profile = Profile::staticGet($remote->id);
-                $orig_remote = clone($remote);
-                $orig_profile = clone($profile);
-                // XXX: compare current postNotice and updateProfile URLs to the ones
-                // stored in the DB to avoid (possibly...) above attack
-            } else {
-                $exists = false;
-                $remote = new Remote_profile();
-                $remote->uri = $omb_profile->getIdentifierURI();
-                $profile = new Profile();
-            }
-
-            $profile->nickname = $omb_profile->getNickname();
-            $profile->profileurl = $omb_profile->getProfileURL();
-
-            $fullname = $omb_profile->getFullname();
-            $profile->fullname = is_null($fullname) ? '' : $fullname;
-            $homepage = $omb_profile->getHomepage();
-            $profile->homepage = is_null($homepage) ? '' : $homepage;
-            $bio = $omb_profile->getBio();
-            $profile->bio = is_null($bio) ? '' : $bio;
-            $location = $omb_profile->getLocation();
-            $profile->location = is_null($location) ? '' : $location;
-
-            if ($exists) {
-                $profile->update($orig_profile);
-            } else {
-                $profile->created = DB_DataObject_Cast::dateTime(); # current time
-                $id = $profile->insert();
-                if (!$id) {
-                    // TRANS: Exception thrown when creating a new profile fails in OAuth store.
-                    throw new Exception(_('Error inserting new profile.'));
-                }
-                $remote->id = $id;
-            }
-
-            $avatar_url = $omb_profile->getAvatarURL();
-            if ($avatar_url) {
-                if (!$this->add_avatar($profile, $avatar_url)) {
-                    // TRANS: Exception thrown when creating a new avatar fails in OAuth store.
-                    throw new Exception(_('Error inserting avatar.'));
-                }
-            } else {
-                $avatar = $profile->getOriginalAvatar();
-                if($avatar) $avatar->delete();
-                $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
-                if($avatar) $avatar->delete();
-                $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
-                if($avatar) $avatar->delete();
-                $avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
-                if($avatar) $avatar->delete();
-            }
-
-            if ($exists) {
-                if (!$remote->update($orig_remote)) {
-                    // TRANS: Exception thrown when updating a remote profile fails in OAuth store.
-                    throw new Exception(_('Error updating remote profile.'));
-                }
-            } else {
-                $remote->created = DB_DataObject_Cast::dateTime(); # current time
-                if (!$remote->insert()) {
-                    // TRANS: Exception thrown when creating a remote profile fails in OAuth store.
-                    throw new Exception(_('Error inserting remote profile.'));
-                }
-            }
-        }
-    }
-
-    function add_avatar($profile, $url)
-    {
-        $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
-        try {
-            copy($url, $temp_filename);
-            $imagefile = new ImageFile($profile->id, $temp_filename);
-            $filename = Avatar::filename($profile->id,
-                                         image_type_to_extension($imagefile->type),
-                                         null,
-                                         common_timestamp());
-            rename($temp_filename, Avatar::path($filename));
-        } catch (Exception $e) {
-            unlink($temp_filename);
-            throw $e;
-        }
-        return $profile->setOriginal($filename);
-    }
-
-    /**
-     * Save passed notice
-     *
-     * Stores the OMB notice $notice. The datastore may change the passed notice.
-     * This might by neccessary for URIs depending on a database key. Note that
-     * it is the user’s duty to present a mechanism for his OMB_Datastore to
-     * appropriately change his OMB_Notice.
-     * Throws exceptions in case of error.
-     *
-     * @param OMB_Notice $notice The OMB notice which should be saved
-     *
-     * @access public
-     **/
-    public function saveNotice(&$omb_notice) {
-        if (Notice::staticGet('uri', $omb_notice->getIdentifierURI())) {
-            // TRANS: Exception thrown when a notice is denied because it has been sent before.
-            throw new Exception(_('Duplicate notice.'));
-        }
-        $author_uri = $omb_notice->getAuthor()->getIdentifierURI();
-        common_log(LOG_DEBUG, $author_uri, __FILE__);
-        $author = Remote_profile::staticGet('uri', $author_uri);
-        if (!$author) {
-            $author = User::staticGet('uri', $author_uri);
-        }
-        if (!$author) {
-            throw new Exception('No such user.');
-        }
-
-        common_log(LOG_DEBUG, print_r($author, true), __FILE__);
-
-        $notice = Notice::saveNew($author->id,
-                                  $omb_notice->getContent(),
-                                  'omb',
-                                  array('is_local' => Notice::REMOTE_OMB,
-                                        'uri' => $omb_notice->getIdentifierURI()));
-
-    }
-
-    /**
-     * Get subscriptions of a given profile
-     *
-     * Returns an array containing subscription informations for the specified
-     * profile. Every array entry should in turn be an array with keys
-     *   'uri´: The identifier URI of the subscriber
-     *   'token´: The subscribe token
-     *   'secret´: The secret token
-     * Throws exceptions in case of error.
-     *
-     * @param string $subscribed_user_uri The OMB identifier URI specifying the
-     *                                    subscribed profile
-     *
-     * @access public
-     *
-     * @return mixed An array containing the subscriptions or 0 if no
-     *               subscription has been found.
-     **/
-    public function getSubscriptions($subscribed_user_uri) {
-        $sub = new Subscription();
-
-        $user = $this->_getAnyProfile($subscribed_user_uri);
-
-        $sub->subscribed = $user->id;
-
-        if (!$sub->find(true)) {
-            return array();
-        }
-
-        /* Since we do not use OMB_Service_Provider’s action methods, there
-           is no need to actually return the subscriptions. */
-        return 1;
-    }
-
-    private function _getAnyProfile($uri)
-    {
-        $user = Remote_profile::staticGet('uri', $uri);
-        if (!$user) {
-            $user = User::staticGet('uri', $uri);
-        }
-        if (!$user) {
-            throw new Exception('No such user.');
-        }
-        return $user;
-    }
-
-    /**
-     * Delete a subscription
-     *
-     * Deletes the subscription from $subscriber_uri to $subscribed_user_uri.
-     * Throws exceptions in case of error.
-     *
-     * @param string $subscriber_uri      The OMB identifier URI specifying the
-     *                                    subscribing profile
-     *
-     * @param string $subscribed_user_uri The OMB identifier URI specifying the
-     *                                    subscribed profile
-     *
-     * @access public
-     **/
-    public function deleteSubscription($subscriber_uri, $subscribed_user_uri)
-    {
-        $sub = new Subscription();
-
-        $subscribed = $this->_getAnyProfile($subscribed_user_uri);
-        $subscriber = $this->_getAnyProfile($subscriber_uri);
-
-        $sub->subscribed = $subscribed->id;
-        $sub->subscriber = $subscriber->id;
-
-        $sub->delete();
-    }
-
-    /**
-     * Save a subscription
-     *
-     * Saves the subscription from $subscriber_uri to $subscribed_user_uri.
-     * Throws exceptions in case of error.
-     *
-     * @param string     $subscriber_uri      The OMB identifier URI specifying
-     *                                        the subscribing profile
-     *
-     * @param string     $subscribed_user_uri The OMB identifier URI specifying
-     *                                        the subscribed profile
-     * @param OAuthToken $token               The access token
-     *
-     * @access public
-     **/
-    public function saveSubscription($subscriber_uri, $subscribed_user_uri,
-                                                                       $token)
-    {
-        $sub = new Subscription();
-
-        $subscribed = $this->_getAnyProfile($subscribed_user_uri);
-        $subscriber = $this->_getAnyProfile($subscriber_uri);
-
-        if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
-            common_log(LOG_INFO, __METHOD__ . ": remote subscriber banned ($subscriber_uri subbing to $subscribed_user_uri)");
-            // TRANS: Error message displayed to a banned user when they try to subscribe.
-            return _('You have been banned from subscribing.');
-        }
-
-        $sub->subscribed = $subscribed->id;
-        $sub->subscriber = $subscriber->id;
-
-        $sub_exists = $sub->find(true);
-
-        if ($sub_exists) {
-            $orig_sub = clone($sub);
-        } else {
-            $sub->created = DB_DataObject_Cast::dateTime();
-        }
-
-        $sub->token  = $token->key;
-        $sub->secret = $token->secret;
-
-        if ($sub_exists) {
-            $result = $sub->update($orig_sub);
-        } else {
-            $result = $sub->insert();
-        }
-
-        if (!$result) {
-            common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__);
-            // TRANS: Exception thrown when creating a new subscription fails in OAuth store.
-            throw new Exception(_('Could not insert new subscription.'));
-            return;
-        }
-
-        /* Notify user, if necessary. */
-
-        if ($subscribed instanceof User) {
-            mail_subscribe_notify_profile($subscribed,
-                                          Profile::staticGet($subscriber->id));
-        }
-    }
-}
diff --git a/lib/omb.php b/lib/omb.php
deleted file mode 100644 (file)
index db60fa0..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-<?php
-/*
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-require_once INSTALLDIR.'/lib/oauthstore.php';
-require_once 'OAuth.php';
-require_once 'libomb/constants.php';
-require_once 'libomb/service_consumer.php';
-require_once 'libomb/notice.php';
-require_once 'libomb/profile.php';
-require_once 'Auth/Yadis/Yadis.php';
-
-function omb_oauth_consumer()
-{
-    // Don't try to make this static. Leads to issues in
-    // multi-site setups - Z
-    return new OAuthConsumer(common_root_url(), '');
-}
-
-function omb_oauth_server()
-{
-    static $server = null;
-    if (is_null($server)) {
-        $server = new OAuthServer(omb_oauth_datastore());
-        $server->add_signature_method(omb_hmac_sha1());
-    }
-    return $server;
-}
-
-function omb_oauth_datastore()
-{
-    static $store = null;
-    if (is_null($store)) {
-        $store = new StatusNetOAuthDataStore();
-    }
-    return $store;
-}
-
-function omb_hmac_sha1()
-{
-    static $hmac_method = null;
-    if (is_null($hmac_method)) {
-        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
-    }
-    return $hmac_method;
-}
-
-function omb_broadcast_notice($notice)
-{
-
-    try {
-        $omb_notice = notice_to_omb_notice($notice);
-    } catch (Exception $e) {
-        // @fixme we should clean up or highlight the problem item
-        common_log(LOG_ERR, 'Invalid OMB outgoing notice for notice ' . $notice->id);
-        common_log(LOG_ERR, 'Error status '.$e);
-        return true;
-    }
-
-    /* Get remote users subscribed to this profile. */
-    $rp = new Remote_profile();
-
-    $rp->query('SELECT remote_profile.*, secret, token ' .
-               'FROM subscription JOIN remote_profile ' .
-               'ON subscription.subscriber = remote_profile.id ' .
-               'WHERE subscription.subscribed = ' . $notice->profile_id . ' ');
-
-    $posted = array();
-
-    while ($rp->fetch()) {
-        if (isset($posted[$rp->postnoticeurl])) {
-            /* We already posted to this url. */
-            continue;
-        }
-        common_debug('Posting to ' . $rp->postnoticeurl, __FILE__);
-
-        /* Post notice. */
-        $service = new StatusNet_OMB_Service_Consumer(
-                     array(OMB_ENDPOINT_POSTNOTICE => $rp->postnoticeurl),
-                                                      $rp->uri);
-        try {
-            $service->setToken($rp->token, $rp->secret);
-            $service->postNotice($omb_notice);
-        } catch (Exception $e) {
-            common_log(LOG_ERR, 'Failed posting to ' . $rp->postnoticeurl);
-            common_log(LOG_ERR, 'Error status '.$e);
-            continue;
-        }
-        $posted[$rp->postnoticeurl] = true;
-
-        common_debug('Finished to ' . $rp->postnoticeurl, __FILE__);
-    }
-
-    return true;
-}
-
-function omb_broadcast_profile($profile)
-{
-    $user = User::staticGet('id', $profile->id);
-
-    if (!$user) {
-        return false;
-    }
-
-    $profile = $user->getProfile();
-
-    $omb_profile = profile_to_omb_profile($user->uri, $profile, true);
-
-    /* Get remote users subscribed to this profile. */
-    $rp = new Remote_profile();
-
-    $rp->query('SELECT remote_profile.*, secret, token ' .
-               'FROM subscription JOIN remote_profile ' .
-               'ON subscription.subscriber = remote_profile.id ' .
-               'WHERE subscription.subscribed = ' . $profile->id . ' ');
-
-    $posted = array();
-
-    while ($rp->fetch()) {
-        if (isset($posted[$rp->updateprofileurl])) {
-            /* We already posted to this url. */
-            continue;
-        }
-        common_debug('Posting to ' . $rp->updateprofileurl, __FILE__);
-
-        /* Update profile. */
-        $service = new StatusNet_OMB_Service_Consumer(
-                     array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl),
-                                                      $rp->uri);
-        try {
-            $service->setToken($rp->token, $rp->secret);
-            $service->updateProfile($omb_profile);
-        } catch (Exception $e) {
-            common_log(LOG_ERR, 'Failed posting to ' . $rp->updateprofileurl);
-            common_log(LOG_ERR, 'Error status '.$e);
-            continue;
-        }
-        $posted[$rp->updateprofileurl] = true;
-
-        common_debug('Finished to ' . $rp->updateprofileurl, __FILE__);
-    }
-
-    return;
-}
-
-class StatusNet_OMB_Service_Consumer extends OMB_Service_Consumer {
-    public function __construct($urls, $listener_uri=null)
-    {
-        $this->services       = $urls;
-        $this->datastore      = omb_oauth_datastore();
-        $this->oauth_consumer = omb_oauth_consumer();
-        $this->fetcher        = Auth_Yadis_Yadis::getHTTPFetcher();
-        $this->fetcher->timeout = intval(common_config('omb', 'timeout'));
-        $this->listener_uri   = $listener_uri;
-    }
-
-}
-
-function profile_to_omb_profile($uri, $profile, $force = false)
-{
-    $omb_profile = new OMB_Profile($uri);
-    $omb_profile->setNickname($profile->nickname);
-    $omb_profile->setLicenseURL(common_config('license', 'url'));
-    if (!is_null($profile->fullname)) {
-        $omb_profile->setFullname($profile->fullname);
-    } elseif ($force) {
-        $omb_profile->setFullname('');
-    }
-    if (!is_null($profile->homepage)) {
-        $omb_profile->setHomepage($profile->homepage);
-    } elseif ($force) {
-        $omb_profile->setHomepage('');
-    }
-    if (!is_null($profile->bio)) {
-        $omb_profile->setBio($profile->bio);
-    } elseif ($force) {
-        $omb_profile->setBio('');
-    }
-    if (!is_null($profile->location)) {
-        $omb_profile->setLocation($profile->location);
-    } elseif ($force) {
-        $omb_profile->setLocation('');
-    }
-    if (!is_null($profile->profileurl)) {
-        $omb_profile->setProfileURL($profile->profileurl);
-    } elseif ($force) {
-        $omb_profile->setProfileURL('');
-    }
-
-    $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
-    if ($avatar) {
-        $omb_profile->setAvatarURL($avatar->url);
-    } elseif ($force) {
-        $omb_profile->setAvatarURL('');
-    }
-    return $omb_profile;
-}
-
-function notice_to_omb_notice($notice)
-{
-    /* Create an OMB_Notice for $notice. */
-    $user = User::staticGet('id', $notice->profile_id);
-
-    if (!$user) {
-        return null;
-    }
-
-    $profile = $user->getProfile();
-
-    $omb_notice = new OMB_Notice(profile_to_omb_profile($user->uri, $profile),
-                                 $notice->uri,
-                                 $notice->content);
-    $omb_notice->setURL(common_local_url('shownotice', array('notice' =>
-                                                                 $notice->id)));
-    $omb_notice->setLicenseURL(common_config('license', 'url'));
-
-    return $omb_notice;
-}
-?>
diff --git a/lib/ombqueuehandler.php b/lib/ombqueuehandler.php
deleted file mode 100644 (file)
index 1921c2b..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-/*
- * StatusNet - the 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/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-/**
- * Queue handler for pushing new notices to OpenMicroBlogging subscribers.
- */
-class OmbQueueHandler extends QueueHandler
-{
-
-    function transport()
-    {
-        return 'omb';
-    }
-
-    /**
-     * @fixme doesn't currently report failure back to the queue manager
-     * because omb_broadcast_notice() doesn't report it to us
-     */
-    function handle($notice)
-    {
-        if ($this->is_remote($notice)) {
-            common_log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id);
-            return true;
-        } else {
-            require_once(INSTALLDIR.'/lib/omb.php');
-            omb_broadcast_notice($notice);
-            return true;
-        }
-    }
-
-    function is_remote($notice)
-    {
-        $user = User::staticGet($notice->profile_id);
-        return is_null($user);
-    }
-}
index 397ea19848043521ba95d2068ad83c7fe3343bb7..90e1c743a5e063da7cfea5fa3d633f0852967fa2 100644 (file)
@@ -289,11 +289,10 @@ class ProfileListItem extends Widget
                 $usf = new UnsubscribeForm($this->out, $this->profile);
                 $usf->show();
             } else {
-                // We can't initiate sub for a remote OMB profile.
-                $remote = Remote_profile::staticGet('id', $this->profile->id);
-                if (empty($remote)) {
+                if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
                     $sf = new SubscribeForm($this->out, $this->profile);
                     $sf->show();
+                    Event::handle('EndShowProfileListSubscribeButton', array($this));
                 }
             }
             $this->out->elementEnd('li');
diff --git a/lib/profilequeuehandler.php b/lib/profilequeuehandler.php
deleted file mode 100644 (file)
index 6ce9322..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?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 QueueHandler
- * @maintainer Brion Vibber <brion@status.net>
- */
-
-class ProfileQueueHandler extends QueueHandler
-{
-
-    function transport()
-    {
-        return 'profile';
-    }
-
-    function handle($profile)
-    {
-        if (!($profile instanceof Profile)) {
-            common_log(LOG_ERR, "Got a bogus profile, not broadcasting");
-            return true;
-        }
-
-        if (Event::handle('StartBroadcastProfile', array($profile))) {
-            require_once(INSTALLDIR.'/lib/omb.php');
-            try {
-                omb_broadcast_profile($profile);
-            } catch (Exception $e) {
-                common_log(LOG_ERR, "Failed sending OMB profiles: " . $e->getMessage());
-            }
-        }
-        Event::handle('EndBroadcastProfile', array($profile));
-        return true;
-    }
-
-}
index 1fa3417829a30edbd73aefff9b6b885c9e364e36..72eff6e463182d55404620250cdf79464cd50d46 100644 (file)
@@ -233,7 +233,6 @@ abstract class QueueManager extends IoManager
 
         if (Event::handle('StartInitializeQueueManager', array($this))) {
             $this->connect('distrib', 'DistribQueueHandler');
-            $this->connect('omb', 'OmbQueueHandler');
             $this->connect('ping', 'PingQueueHandler');
             if (common_config('sms', 'enabled')) {
                 $this->connect('sms', 'SmsQueueHandler');
@@ -246,9 +245,6 @@ abstract class QueueManager extends IoManager
             $this->connect('acctmove', 'AccountMover');
             $this->connect('actmove', 'ActivityMover');
 
-            // Broadcasting profile updates to OMB remote subscribers
-            $this->connect('profile', 'ProfileQueueHandler');
-
             // For compat with old plugins not registering their own handlers.
             $this->connect('plugin', 'PluginQueueHandler');
         }
index dbf3aaeb9732cfe7c66ee55de63aee0362a8f3da..536797dce17ec6d224b2fb56ffaf9a99668040ea 100644 (file)
@@ -113,8 +113,6 @@ class Router
 {
     var $m = null;
     static $inst = null;
-    static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
-                         'postnotice', 'updateprofile', 'finishremotesubscribe');
 
     const REGEX_TAG = '[^\/]+'; // [\pL\pN_\-\.]{1,64} better if we can do unicode regexes
 
@@ -257,15 +255,6 @@ class Router
                 $m->connect('main/'.$c.'/:code', array('action' => $c));
             }
 
-            // exceptional
-
-            $m->connect('main/remote', array('action' => 'remotesubscribe'));
-            $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
-
-            foreach (Router::$bare as $action) {
-                $m->connect('index.php?action=' . $action, array('action' => $action));
-            }
-
             // settings
 
             foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
@@ -896,8 +885,8 @@ class Router
                 $nickname = User::singleUserNickname();
 
                 foreach (array('subscriptions', 'subscribers',
-                               'all', 'foaf', 'xrds',
-                               'replies', 'microsummary', 'hcard') as $a) {
+                               'all', 'foaf', 'replies',
+                               'microsummary', 'hcard') as $a) {
                     $m->connect($a,
                                 array('action' => $a,
                                       'nickname' => $nickname));
@@ -964,8 +953,8 @@ class Router
                 $m->connect('rsd.xml', array('action' => 'rsd'));
 
                 foreach (array('subscriptions', 'subscribers',
-                               'nudge', 'all', 'foaf', 'xrds',
-                               'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
+                               'nudge', 'all', 'foaf', 'replies',
+                               'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
                     $m->connect(':nickname/'.$a,
                                 array('action' => $a),
                                 array('nickname' => Nickname::DISPLAY_FMT));
diff --git a/lib/statusnetoauthstore.php b/lib/statusnetoauthstore.php
new file mode 100644 (file)
index 0000000..341e32d
--- /dev/null
@@ -0,0 +1,506 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+require_once 'OAuth.php';
+
+/**
+ * @fixme class doc
+ */
+class ApiStatusNetOAuthDataStore extends OAuthDataStore
+{
+    function lookup_consumer($consumerKey)
+    {
+        $con = Consumer::staticGet('consumer_key', $consumerKey);
+
+        if (!$con) {
+
+            // Create an anon consumer and anon application if one
+            // doesn't exist already
+            if ($consumerKey == 'anonymous') {
+
+                common_debug("API OAuth - creating anonymous consumer");
+                $con = new Consumer();
+                $con->consumer_key    = $consumerKey;
+                $con->consumer_secret = $consumerKey;
+                $con->created         = common_sql_now();
+
+                $result = $con->insert();
+                if (!$result) {
+                    // TRANS: Server error displayed when trying to create an anynymous OAuth consumer.
+                    $this->serverError(_('Could not create anonymous consumer.'));
+                }
+
+                $app = Oauth_application::getByConsumerKey('anonymous');
+
+                if (!$app) {
+                    common_debug("API OAuth - creating anonymous application");
+                    $app               = new OAuth_application();
+                    $app->owner        = 1; // XXX: What to do here?
+                    $app->consumer_key = $con->consumer_key;
+                    $app->name         = 'anonymous';
+                    $app->icon         = 'default-avatar-stream.png'; // XXX: Fix this!
+                    $app->description  = "An anonymous application";
+                    // XXX: allow the user to set the access type when
+                    // authorizing? Currently we default to r+w for anonymous
+                    // OAuth client applications
+                    $app->access_type  = 3; // read + write
+                    $app->type         = 2; // desktop
+                    $app->created      = common_sql_now();
+
+                    $id = $app->insert();
+
+                    if (!$id) {
+                        // TRANS: Server error displayed when trying to create an anynymous OAuth application.
+                        $this->serverError(_("Could not create anonymous OAuth application."));
+                    }
+                }
+            } else {
+                return null;
+            }
+        }
+
+        return new OAuthConsumer(
+            $con->consumer_key,
+            $con->consumer_secret
+        );
+    }
+
+    function getAppByRequestToken($token_key)
+    {
+        // Look up the full req token
+        $req_token = $this->lookup_token(
+            null,
+            'request',
+            $token_key
+        );
+
+        if (empty($req_token)) {
+            common_debug("Couldn't get request token from oauth datastore");
+            return null;
+        }
+
+        // Look up the full Token
+        $token = new Token();
+        $token->tok = $req_token->key;
+        $result = $token->find(true);
+
+        if (empty($result)) {
+            common_debug('Couldn\'t find req token in the token table.');
+            return null;
+        }
+
+        // Look up the app
+        $app = new Oauth_application();
+        $app->consumer_key = $token->consumer_key;
+        $result = $app->find(true);
+
+        if (!empty($result)) {
+            return $app;
+        } else {
+            common_debug("Couldn't find the app!");
+            return null;
+        }
+    }
+
+    function new_access_token($token, $consumer, $verifier)
+    {
+        common_debug(
+            sprintf(
+                "New access token from request token %s, consumer %s and verifier %s ",
+                $token,
+                $consumer,
+                $verifier
+            ),
+            __FILE__
+        );
+
+        $rt = new Token();
+
+        $rt->consumer_key = $consumer->key;
+        $rt->tok          = $token->key;
+        $rt->type         = 0; // request
+
+        $app = Oauth_application::getByConsumerKey($consumer->key);
+        assert(!empty($app));
+
+        if ($rt->find(true) && $rt->state == 1 && $rt->verifier == $verifier) { // authorized
+
+            common_debug('Request token found.', __FILE__);
+
+            // find the app and profile associated with this token
+            $tokenAssoc = Oauth_token_association::staticGet('token', $rt->tok);
+
+            if (!$tokenAssoc) {
+                throw new Exception(
+                    // TRANS: Exception thrown when no token association could be found.
+                    _('Could not find a profile and application associated with the request token.')
+                );
+            }
+
+            // Check to see if we have previously issued an access token for
+            // this application and profile; if so we can just return the
+            // existing access token. That seems to be the best practice. It
+            // makes it so users only have to authorize the app once per
+            // machine.
+
+            $appUser = new Oauth_application_user();
+
+            $appUser->application_id = $app->id;
+            $appUser->profile_id     = $tokenAssoc->profile_id;
+
+            $result = $appUser->find(true);
+
+            if (!empty($result)) {
+
+                common_log(LOG_INFO,
+                     sprintf(
+                        "Existing access token found for application %s, profile %s.",
+                        $app->id,
+                        $tokenAssoc->profile_id
+                     )
+                );
+
+                $at = null;
+
+                // Special case: we used to store request tokens in the
+                // Oauth_application_user record, and the access_type would
+                // always be 0 (no access) as a failsafe until an access
+                // token was issued and replaced the request token. There could
+                // be a few old Oauth_application_user records storing request
+                // tokens still around, and we don't want to accidentally
+                // return a useless request token instead of a new access
+                // token. So if we find one, we generate a new access token
+                // and update the existing Oauth_application_user record before
+                // returning the new access token. This should be rare.
+
+                if ($appUser->access_type == 0) {
+
+                    $at = $this->generateNewAccessToken($consumer, $rt, $verifier);
+                    $this->updateAppUser($appUser, $app, $at);
+
+                } else {
+
+                    $at = new Token();
+
+                    // fetch the full access token
+                    $at->consumer_key = $consumer->key;
+                    $at->tok          = $appUser->token;
+
+                    $result = $at->find(true);
+
+                    if (!$result) {
+                        throw new Exception(
+                            // TRANS: Exception thrown when no access token can be issued.
+                            _('Could not issue access token.')
+                        );
+                    }
+                }
+
+                // Yay, we can re-issue the access token
+                return new OAuthToken($at->tok, $at->secret);
+
+            } else {
+
+               common_log(LOG_INFO,
+                    sprintf(
+                        "Creating new access token for application %s, profile %s.",
+                        $app->id,
+                        $tokenAssoc->profile_id
+                     )
+                );
+
+                $at = $this->generateNewAccessToken($consumer, $rt, $verifier);
+                $this->newAppUser($tokenAssoc, $app, $at);
+
+                // Okay, good
+                return new OAuthToken($at->tok, $at->secret);
+            }
+
+        } else {
+
+            // the token was not authorized or not verfied
+            common_log(
+                LOG_INFO,
+                sprintf(
+                    "API OAuth - Attempt to exchange unauthorized or unverified request token %s for an access token.",
+                     $rt->tok
+                )
+            );
+            return null;
+        }
+    }
+
+    /*
+     * Generate a new access token and save it to the database
+     *
+     * @param Consumer $consumer the OAuth consumer
+     * @param Token    $rt       the authorized request token
+     * @param string   $verifier the OAuth 1.0a verifier
+     *
+     * @access private
+     *
+     * @return Token   $at       the new access token
+     */
+    private function generateNewAccessToken($consumer, $rt, $verifier)
+    {
+        $at = new Token();
+
+        $at->consumer_key      = $consumer->key;
+        $at->tok               = common_good_rand(16);
+        $at->secret            = common_good_rand(16);
+        $at->type              = 1; // access
+        $at->verifier          = $verifier;
+        $at->verified_callback = $rt->verified_callback; // 1.0a
+        $at->created           = common_sql_now();
+
+        if (!$at->insert()) {
+            $e = $at->_lastError;
+            common_debug('access token "' . $at->tok . '" not inserted: "' . $e->message . '"', __FILE__);
+            return null;
+        } else {
+            common_debug('access token "' . $at->tok . '" inserted', __FILE__);
+            // burn the old one
+            $orig_rt   = clone($rt);
+            $rt->state = 2; // used
+            if (!$rt->update($orig_rt)) {
+                return null;
+            }
+            common_debug('request token "' . $rt->tok . '" updated', __FILE__);
+        }
+
+        return $at;
+    }
+
+   /*
+    * Add a new app user (Oauth_application_user) record
+    *
+    * @param Oauth_token_association $tokenAssoc token-to-app association
+    * @param Oauth_application       $app        the OAuth client app
+    * @param Token                   $at         the access token
+    *
+    * @access private
+    *
+    * @return void
+    */
+    private function newAppUser($tokenAssoc, $app, $at)
+    {
+        $appUser = new Oauth_application_user();
+
+        $appUser->profile_id     = $tokenAssoc->profile_id;
+        $appUser->application_id = $app->id;
+        $appUser->access_type    = $app->access_type;
+        $appUser->token          = $at->tok;
+        $appUser->created        = common_sql_now();
+
+        $result = $appUser->insert();
+
+        if (!$result) {
+            common_log_db_error($appUser, 'INSERT', __FILE__);
+
+            throw new Exception(
+                // TRANS: Exception thrown when a database error occurs.
+                _('Database error inserting OAuth application user.')
+            );
+        }
+    }
+
+   /*
+    * Update an existing app user (Oauth_application_user) record
+    *
+    * @param Oauth_application_user $appUser existing app user rec
+    * @param Oauth_application      $app     the OAuth client app
+    * @param Token                  $at      the access token
+    *
+    * @access private
+    *
+    * @return void
+    */
+    private function updateAppUser($appUser, $app, $at)
+    {
+        $original = clone($appUser);
+        $appUser->access_type = $app->access_type;
+        $appUser->token       = $at->tok;
+
+        $result = $appUser->update($original);
+
+        if (!$result) {
+            common_log_db_error($appUser, 'UPDATE', __FILE__);
+            throw new Exception(
+                // TRANS: Exception thrown when a database error occurs.
+                _('Database error updating OAuth application user.')
+            );
+        }
+    }
+
+    /**
+     * Revoke specified access token
+     *
+     * Revokes the token specified by $token_key.
+     * Throws exceptions in case of error.
+     *
+     * @param string $token_key the token to be revoked
+     * @param int    $type      type of token (0 = req, 1 = access)
+     *
+     * @access public
+     *
+     * @return void
+     */
+    public function revoke_token($token_key, $type = 0) {
+        $rt        = new Token();
+        $rt->tok   = $token_key;
+        $rt->type  = $type;
+        $rt->state = 0;
+
+        if (!$rt->find(true)) {
+            // TRANS: Exception thrown when an attempt is made to revoke an unknown token.
+            throw new Exception(_('Tried to revoke unknown token.'));
+        }
+
+        if (!$rt->delete()) {
+            // TRANS: Exception thrown when an attempt is made to remove a revoked token.
+            throw new Exception(_('Failed to delete revoked token.'));
+        }
+    }
+
+    /*
+     * Create a new request token. Overrided to support OAuth 1.0a callback
+     *
+     * @param OAuthConsumer $consumer the OAuth Consumer for this token
+     * @param string        $callback the verified OAuth callback URL
+     *
+     * @return OAuthToken   $token a new unauthorized OAuth request token
+     */
+    function new_request_token($consumer, $callback)
+    {
+        $t = new Token();
+        $t->consumer_key = $consumer->key;
+        $t->tok = common_good_rand(16);
+        $t->secret = common_good_rand(16);
+        $t->type = 0; // request
+        $t->state = 0; // unauthorized
+        $t->verified_callback = $callback;
+
+        if ($callback === 'oob') {
+            // six digit pin
+            $t->verifier = mt_rand(0, 9999999);
+        } else {
+            $t->verifier = common_good_rand(8);
+        }
+
+        $t->created = DB_DataObject_Cast::dateTime();
+        if (!$t->insert()) {
+            return null;
+        } else {
+            return new OAuthToken($t->tok, $t->secret);
+        }
+    }
+
+    /**
+     * Authorize specified OAuth token
+     *
+     * Authorizes the authorization token specified by $token_key.
+     * Throws exceptions in case of error.
+     *
+     * @param string $token_key The token to be authorized
+     *
+     * @access public
+     **/
+    public function authorize_token($token_key) {
+        $rt = new Token();
+        $rt->tok = $token_key;
+        $rt->type = 0;
+        $rt->state = 0;
+        if (!$rt->find(true)) {
+            throw new Exception('Tried to authorize unknown token');
+        }
+        $orig_rt = clone($rt);
+        $rt->state = 1; # Authorized but not used
+        if (!$rt->update($orig_rt)) {
+            throw new Exception('Failed to authorize token');
+        }
+    }
+
+    /**
+     *
+     * http://oauth.net/core/1.0/#nonce
+     * "The Consumer SHALL then generate a Nonce value that is unique for
+     * all requests with that timestamp."
+     * XXX: It's not clear why the token is here
+     *
+     * @param type $consumer
+     * @param type $token
+     * @param type $nonce
+     * @param type $timestamp
+     * @return type
+     */
+    function lookup_nonce($consumer, $token, $nonce, $timestamp)
+    {
+        $n = new Nonce();
+        $n->consumer_key = $consumer->key;
+        $n->ts = common_sql_date($timestamp);
+        $n->nonce = $nonce;
+        if ($n->find(true)) {
+            return true;
+        } else {
+            $n->created = DB_DataObject_Cast::dateTime();
+            $n->insert();
+            return false;
+        }
+    }
+
+    /**
+     *
+     * @param type $consumer
+     * @param type $token_type
+     * @param type $token_key
+     * @return OAuthToken
+     */
+    function lookup_token($consumer, $token_type, $token_key)
+    {
+        $t = new Token();
+        if (!is_null($consumer)) {
+            $t->consumer_key = $consumer->key;
+        }
+        $t->tok = $token_key;
+        $t->type = ($token_type == 'access') ? 1 : 0;
+        if ($t->find(true)) {
+            return new OAuthToken($t->tok, $t->secret);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     *
+     * @param type $token_key
+     * @return Token 
+     */
+    function getTokenByKey($token_key)
+    {
+        $t = new Token();
+        $t->tok = $token_key;
+        if ($t->find(true)) {
+            return $t;
+        } else {
+            return null;
+        }
+    }
+}
index 3535cfb08a8a4ca1914db1d8065255cb5259011b..d35833851900758a2354849063050cdfe745e865 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2011, 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
@@ -1501,7 +1501,7 @@ function common_enqueue_notice($notice)
 }
 
 /**
- * Broadcast profile updates to OMB and other remote subscribers.
+ * Broadcast profile updates to remote subscribers.
  *
  * Since this may be slow with a lot of subscribers or bad remote sites,
  * this is run through the background queues if possible.
@@ -2008,20 +2008,20 @@ function common_user_property($property)
 
 function common_profile_uri($profile)
 {
-    if (!$profile) {
-        return null;
-    }
-    $user = User::staticGet($profile->id);
-    if ($user) {
-        return $user->uri;
-    }
+    $uri = null;
 
-    $remote = Remote_profile::staticGet($profile->id);
-    if ($remote) {
-        return $remote->uri;
+    if (!empty($profile)) {
+        if (Event::handle('StartCommonProfileURI', array($profile, &$uri))) {
+            $user = User::staticGet($profile->id);
+            if (!empty($user)) {
+                $uri = $user->uri;
+            }
+            Event::handle('EndCommonProfileURI', array($profile, &$uri));
+        }
     }
+
     // XXX: this is a very bad profile!
-    return null;
+    return $uri;
 }
 
 function common_canonical_sms($sms)
index f8db77e2b701d9ca0274704e0b9ba5b5726c046d..e383f805608ec85cefd9be36a62529d3dbf7e07a 100644 (file)
@@ -322,7 +322,7 @@ class BookmarkPlugin extends MicroAppPlugin
 
         $options = array('uri' => $bookmark->id,
                          'url' => $bookmark->link,
-                         'is_local' => Notice::REMOTE_OMB,
+                         'is_local' => Notice::REMOTE,
                          'source' => 'ostatus');
 
         return self::_postBookmark($author->localProfile(), $activity, $options);
diff --git a/plugins/OMB/OMBPlugin.php b/plugins/OMB/OMBPlugin.php
new file mode 100644 (file)
index 0000000..f5fed60
--- /dev/null
@@ -0,0 +1,393 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * OpenMicroBlogging plugin - add OpenMicroBloggin 0.1 support to
+ * StatusNet.
+ *
+ * Note: the OpenMicroBlogging protocol has been deprecated in favor of OStatus.
+ * This plugin is provided for backwards compatibility and experimentation.
+ *
+ * Please see the README and the OStatus plugin.
+ *
+ * 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/>.
+ *
+ * @category  Sample
+ * @package   StatusNet
+ * @author    Zach Copley
+ * @copyright 2011 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/');
+
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * OMB plugin main class
+ *
+ * @category  Integration
+ * @package   StatusNet
+ * @author    Zach Copley <zach@status.net>
+ * @copyright 2011 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+class OMBPlugin extends Plugin
+{
+    /**
+     * Load related modules when needed
+     *
+     * @param string $cls Name of the class to be loaded
+     *
+     * @return boolean hook value; true means continue processing, false means stop.
+     */
+    function onAutoload($cls)
+    {
+        $dir = dirname(__FILE__);
+
+        switch ($cls)
+        {
+        case 'Requesttokenaction':
+        case 'Accesstokenaction':
+        case 'Userauthorizationaction':
+        case 'Postnoticeaction':
+        case 'Updateprofileaction':
+        case 'Finishremotesubscribeaction':
+        case 'Remotesubscribeaction':
+        case 'XrdsAction':
+            include_once $dir . '/action/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
+            return false;
+            break;
+        case 'OmbQueueHandler':
+        case 'ProfileQueueHandler':
+            include_once $dir . '/lib/' . strtolower($cls) . '.php';
+            return false;
+        case 'OMBOAuthDataStore':
+            include_once $dir . '/lib/omboauthstore.php';
+        default:
+            return true;
+        }
+    }
+
+    /**
+     * Map URLs to actions
+     *
+     * @param Net_URL_Mapper $m path-to-action mapper
+     *
+     * @return boolean hook value; true means continue processing, false means stop.
+     */
+    function onRouterInitialized($m)
+    {
+        $bare = array(
+            'requesttoken',
+            'accesstoken',
+            'userauthorization',
+            'postnotice',
+            'updateprofile',
+            'finishremotesubscribe'
+        );
+
+        foreach ($bare as $action) {
+            $m->connect(
+                'index.php?action=' . $action, array('action' => $action)
+            );
+        }
+
+        // exceptional
+
+        $m->connect('main/remote', array('action' => 'remotesubscribe'));
+        $m->connect(
+            'main/remote?nickname=:nickname',
+            array('action' => 'remotesubscribe'),
+            array('nickname' => '[A-Za-z0-9_-]+')
+        );
+
+        $m->connect(
+            'xrds',
+            array('action' => 'xrds', 'nickname' => $nickname)
+        );
+
+        return true;
+    }
+
+    /**
+     * Put saved notices into the queue for OMB distribution
+     *
+     * @param Notice $notice     the notice to broadcast
+     * @param array  $transports queuehandler's list of transports
+     * @return boolean true if queing was successful
+     */
+    function onStartEnqueueNotice($notice, &$transports)
+    {
+        if ($notice->isLocal()) {
+            if ($notice->inScope(null)) {
+                array_unshift($transports, 'omb');
+                common_log(
+                    LOG_INFO, "Notice {$notice->id} queued for OMB processing"
+                );
+            } else {
+                // Note: We don't do privacy-controlled OMB updates.
+                common_log(
+                    LOG_NOTICE,
+                    "Not queueing notice {$notice->id} for OMB because of "
+                    . "privacy; scope = {$notice->scope}",
+                    __FILE__
+                );
+            }
+        } else {
+            common_log(
+                LOG_NOTICE,
+                "Not queueing notice {$notice->id} for OMB because it's not "
+                . "local.",
+                __FILE__
+            );
+        }
+
+        return true;
+    }
+
+    /**
+     * Set up queue handlers for outgoing OMB pushes
+     *
+     * @param QueueManager $qm
+     * @return boolean hook return
+     */
+    function onEndInitializeQueueManager(QueueManager $qm)
+    {
+        // Prepare outgoing distributions after notice save.
+        $qm->connect('omb', 'OmbQueueHandler');
+        $qm->connect('profile', 'ProfileQueueHandler');
+
+        return true;
+    }
+
+    /**
+     * Return OMB remote profile, if any
+     *
+     * @param Profile $profile
+     * @param string  $uri
+     * @return boolen false if there's a remote profile
+     */
+    function onStartGetProfileUri($profile, &$uri)
+    {
+        $remote = Remote_profile::staticGet('id', $this->id);
+        if (!empty($remote)) {
+            $uri = $remote->uri;
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * We can't initiate subscriptions for a remote OMB profile; don't show
+     * subscribe button
+     *
+     * @param type $action
+     */
+    function onStartShowProfileListSubscribeButton($action)
+    {
+        $remote = Remote_profile::staticGet('id', $action->profile->id);
+        if (empty($remote)) {
+            false;
+        }
+        return true;
+    }
+
+    /**
+     * Check for illegal subscription attempts
+     *
+     * @param User    $user     subscriber
+     * @param Profile $other    subscribee
+     * @return hook return value
+     */
+    function onStartSubscribe($profile, $other)
+    {
+        // OMB 0.1 doesn't have a mechanism for local-server-
+        // originated subscription.
+
+        $omb01 = Remote_profile::staticGet('id', $other_id);
+
+        if (!empty($omb01)) {
+            // TRANS: Client error displayed trying to subscribe to an OMB 0.1 remote profile.
+            throw new ClientException(
+                _m(
+                    'You cannot subscribe to an OMB 0.1 '
+                    . 'remote profile with this action.'
+                )
+            );
+            return false;
+        }
+
+    }
+
+    /**
+     * Throw an error if someone tries to tag a remote profile
+     *
+     * @param Profile $tagger_profile   profile of the tagger
+     * @param Profile $tagged_profile   profile of the taggee
+     * @param string $tag
+     *
+     * @return true
+     */
+    function onStartTagProfile($tagger_profile, $tagged_profile, $tag)
+    {
+        // OMB 0.1 doesn't have a mechanism for local-server-
+        // originated tag.
+
+        $omb01 = Remote_profile::staticGet('id', $tagged_profile->id);
+
+        if (!empty($omb01)) {
+            // TRANS: Client error displayed when trying to add an OMB 0.1 remote profile to a list.
+            $this->clientError(
+                _m(
+                    'You cannot list an OMB 0.1 '
+                   .'remote profile with this action.')
+            );
+        }
+        return false;
+    }
+
+    /**
+     * Check to make sure we're not tryng to untag an OMB profile
+     *
+     * // XXX: Should this ever happen?
+     *
+     * @param Profile_tag $ptag the profile tag
+     */
+    function onUntagProfile($ptag)
+    {
+        // OMB 0.1 doesn't have a mechanism for local-server-
+        // originated tag.
+
+        $omb01 = Remote_profile::staticGet('id', $ptag->tagged);
+
+        if (!empty($omb01)) {
+            // TRANS: Client error displayed when trying to (un)list an OMB 0.1 remote profile.
+            $this->clientError(
+                _m(
+                    'You cannot (un)list an OMB 0.1 '
+                    . 'remote profile with this action.')
+            );
+            return false;
+        }
+    }
+
+    /**
+     * Remove old OMB subscription tokens
+     *
+     * @param User    $user     subscriber
+     * @param Profile $other    subscribee
+     * @return hook return value
+     */
+    function onEndUnsubscribe($profile, $other)
+    {
+        $sub = Subscription::pkeyGet(
+            array('subscriber' => $subscriber->id, 'subscribed' => $other->id)
+        );
+
+        if (!empty($sub->token)) {
+
+            $token = new Token();
+
+            $token->tok    = $sub->token;
+
+            if ($token->find(true)) {
+
+                $result = $token->delete();
+
+                if (!$result) {
+                    common_log_db_error($token, 'DELETE', __FILE__);
+                    // TRANS: Exception thrown when the OMB token for a subscription could not deleted on the server.
+                    throw new Exception(
+                        _m('Could not delete subscription OMB token.')
+                    );
+                }
+            } else {
+                common_log(
+                    LOG_ERR,
+                    "Couldn't find credentials with token {$token->tok}",
+                    __FILE__
+                );
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Search for an OMB remote profile by URI
+     *
+     * @param string  $uri      remote profile URI
+     * @param Profile $profile  the profile to set
+     * @return boolean hook value
+     */
+    function onStartGetProfileFromURI($uri, &$profile)
+    {
+        $remote_profile = Remote_profile::staticGet('uri', $uri);
+        if (!empty($remote_profile)) {
+            $profile = Profile::staticGet('id', $remote_profile->profile_id);
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * Return OMB remote profiles as well as regular profiles
+     * in helper
+     *
+     * @param type $profile
+     * @param type $uri
+     */
+    function onStartCommonProfileURI($profile, &$uri)
+    {
+        $remote = Remote_profile::staticGet($profile->id);
+        if ($remote) {
+            $uri = $remote->uri;
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Plugin version info
+     *
+     * @param array $versions
+     * @return boolean hook value
+     */
+    function onPluginVersion(&$versions)
+    {
+        $versions[] = array(
+            'name'           => 'OpenMicroBlogging',
+            'version'        => STATUSNET_VERSION,
+            'author'         => 'Zach Copley',
+            'homepage'       => 'http://status.net/wiki/Plugin:Sample',
+            'rawdescription' =>
+            // TRANS: Plugin description.
+            _m('A sample plugin to show basics of development for new hackers.')
+        );
+
+        return true;
+    }
+}
+
diff --git a/plugins/OMB/README b/plugins/OMB/README
new file mode 100644 (file)
index 0000000..839eb4e
--- /dev/null
@@ -0,0 +1,31 @@
+OMB (OpenMicroBlogging) plugin
+==============================
+
+This plugin encapsulates OpenMicroBlogging 0.1 functionality. OMB was the
+original federation protocol for StatusNet, but has been deprecated
+in favor of OStatus (see the OStatus plugin). This plugin is provided for
+backward-compatibility with older sites, and for posterity.
+
+External libraries
+------------------
+
+This is provided with the plugin, but you may wish to use a newer version of
+the library, if and when it becomes available.
+
+- libomb. a library for implementing OpenMicroBlogging 0.1
+  http://gitorious.org/libomb
+
+
+Installation
+------------
+
+[TODO]
+
+Offline Processing
+------------------
+
+Note: once you have a sizable number of users, sending OMB messages whenever
+someone posts a message can really slow down your site; it may cause posting
+to timeout. You may wish to enable queuing and handle OMB communication
+offline. See the "queues and daemons" section of the main StatusNet README.
+
diff --git a/plugins/OMB/actions/accesstoken.php b/plugins/OMB/actions/accesstoken.php
new file mode 100644 (file)
index 0000000..cd7a2f4
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Access token class
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+require_once dirname(__FILE__) . '/../extlib/libomb/service_provider.php';
+require_once dirname(__FILE__) . '/../lib/omb.php';
+
+/**
+ * Access token class
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ */
+class AccesstokenAction extends Action
+{
+    /**
+     * Class handler
+     *
+     * @param array $args query arguments
+     *
+     * @return nothing
+     *
+     **/
+    function handle($args)
+    {
+        parent::handle($args);
+        try {
+            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
+                                            omb_oauth_server());
+            $srv->writeAccessToken();
+        } catch (Exception $e) {
+            $this->serverError($e->getMessage());
+        }
+    }
+}
diff --git a/plugins/OMB/actions/finishremotesubscribe.php b/plugins/OMB/actions/finishremotesubscribe.php
new file mode 100644 (file)
index 0000000..fb98dbd
--- /dev/null
@@ -0,0 +1,158 @@
+<?php
+/**
+ * Handler for remote subscription finish callback
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ **/
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+require_once dirname(__FILE__) . '/../extlib/libomb/service_consumer.php';
+require_once dirname(__FILE__) . '/../lib/omb.php';
+
+/**
+ * Handler for remote subscription finish callback
+ *
+ * When a remote user subscribes a local user, a redirect to this action is
+ * issued after the remote user authorized their service to subscribe.
+ *
+ * @category Action
+ * @package  Laconica
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@controlyourself.ca>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://laconi.ca/
+ */
+class FinishremotesubscribeAction extends Action
+{
+    /**
+     * Class handler.
+     *
+     * @param array $args query arguments
+     *
+     * @return nothing
+     *
+     */
+    function handle($args)
+    {
+        parent::handle($args);
+
+        /* Restore session data. RemotesubscribeAction should have stored
+           this entry. */
+        $service  = unserialize($_SESSION['oauth_authorization_request']);
+
+        if (!$service) {
+            // TRANS: Client error displayed when subscribing to a remote profile and an unexpected response is received.
+            $this->clientError(_('Not expecting this response!'));
+            return;
+        }
+
+        common_debug('stored request: '. print_r($service, true), __FILE__);
+
+        /* Create user objects for both users. Do it early for request
+           validation. */
+        $user = User::staticGet('uri', $service->getListeneeURI());
+
+        if (!$user) {
+            // TRANS: Client error displayed when subscribing to a remote profile that does not exist.
+            $this->clientError(_('User being listened to does not exist.'));
+            return;
+        }
+
+        $other = User::staticGet('uri', $service->getListenerURI());
+
+        if ($other) {
+            // TRANS: Client error displayed when subscribing to a remote profile that is a local profile.
+            $this->clientError(_('You can use the local subscription!'));
+            return;
+        }
+
+        $remote = Remote_profile::staticGet('uri', $service->getListenerURI());
+        if ($remote) {
+            // Note remote profile may not have been saved yet.
+            // @fixme not convinced this is correct at all!
+
+            $profile = Profile::staticGet($remote->id);
+
+            if ($user->hasBlocked($profile)) {
+                // TRANS: Client error displayed when subscribing to a remote profile that is blocked form subscribing to.
+                $this->clientError(_('That user has blocked you from subscribing.'));
+                return;
+            }
+        }
+
+        /* Perform the handling itself via libomb. */
+        try {
+            $service->finishAuthorization();
+        } catch (OAuthException $e) {
+            if ($e->getMessage() == 'The authorized token does not equal the ' .
+                                    'submitted token.') {
+                // TRANS: Client error displayed when subscribing to a remote profile without providing an authorised token.
+                $this->clientError(_('You are not authorized.'));
+                return;
+            } else {
+                // TRANS: Client error displayed when subscribing to a remote profile and conversion of the request token to access token fails.
+                $this->clientError(_('Could not convert request token to ' .
+                                     'access token.'));
+                return;
+            }
+        } catch (OMB_RemoteServiceException $e) {
+            // TRANS: Client error displayed when subscribing to a remote profile fails because of an unsupported version of the OMB protocol.
+            $this->clientError(_('Remote service uses unknown version of ' .
+                                 'OMB protocol.'));
+            return;
+        } catch (Exception $e) {
+            common_debug('Got exception ' . print_r($e, true), __FILE__);
+            $this->clientError($e->getMessage());
+            return;
+        }
+
+        /* The service URLs are not accessible from datastore, so setting them
+           after insertion of the profile. */
+        $remote = Remote_profile::staticGet('uri', $service->getListenerURI());
+        $orig_remote = clone($remote);
+
+        $remote->postnoticeurl    =
+                            $service->getServiceURI(OMB_ENDPOINT_POSTNOTICE);
+        $remote->updateprofileurl =
+                            $service->getServiceURI(OMB_ENDPOINT_UPDATEPROFILE);
+
+        if (!$remote->update($orig_remote)) {
+                // TRANS: Server error displayed when subscribing to a remote profile fails because the remote profile could not be updated.
+                $this->serverError(_('Error updating remote profile.'));
+                return;
+        }
+
+        /* Clear the session data. */
+        unset($_SESSION['oauth_authorization_request']);
+
+        /* If we show subscriptions in reverse chronological order, the new one
+           should show up close to the top of the page. */
+        common_redirect(common_local_url('subscribers', array('nickname' =>
+                                                             $user->nickname)),
+                        303);
+    }
+}
diff --git a/plugins/OMB/actions/postnotice.php b/plugins/OMB/actions/postnotice.php
new file mode 100644 (file)
index 0000000..c2128f7
--- /dev/null
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Handle postnotice action
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+require_once dirname(__FILE__) . '/../lib/omb.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/service_provider.php';
+
+/**
+ * Handler for postnotice action
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ */
+class PostnoticeAction extends Action
+{
+    /**
+     * For initializing members of the class.
+     *
+     * @param array $argarray misc. arguments
+     *
+     * @return boolean true
+     */
+    function prepare($argarray)
+    {
+        StatusNet::setApi(true); // Send smaller error pages
+
+        parent::prepare($argarray);
+
+        try {
+            $this->checkNotice();
+        } catch (Exception $e) {
+            $this->clientError($e->getMessage());
+            return false;
+        }
+        return true;
+    }
+
+    function handle($args)
+    {
+        parent::handle($args);
+        try {
+            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
+                                            omb_oauth_server());
+            $srv->handlePostNotice();
+        } catch (OMB_RemoteServiceException $rse) {
+            $msg = $rse->getMessage();
+            if (preg_match('/Revoked accesstoken/', $msg) ||
+                preg_match('/No subscriber/', $msg)) {
+                $this->clientError($msg, 403);
+            } else {
+                $this->clientError($msg);
+            }
+        } catch (Exception $e) {
+            $this->serverError($e->getMessage());
+            return;
+        }
+    }
+
+    function checkNotice()
+    {
+        $content = common_shorten_links($_POST['omb_notice_content']);
+        if (Notice::contentTooLong($content)) {
+            // TRANS: Client error displayed if the notice posted has too many characters.
+            $this->clientError(_('Invalid notice content.'), 400);
+            return false;
+        }
+        $license      = $_POST['omb_notice_license'];
+        $site_license = common_config('license', 'url');
+        if ($license && !common_compatible_license($license, $site_license)) {
+            // TRANS: Exception thrown if a notice's license is not compatible with the StatusNet site license.
+            // TRANS: %1$s is the notice license, %2$s is the StatusNet site's license.
+            throw new Exception(sprintf(_('Notice license "%1$s" is not ' .
+                                          'compatible with site license "%2$s".'),
+                                        $license, $site_license));
+        }
+    }
+}
diff --git a/plugins/OMB/actions/remotesubscribe.php b/plugins/OMB/actions/remotesubscribe.php
new file mode 100644 (file)
index 0000000..aafbaf5
--- /dev/null
@@ -0,0 +1,224 @@
+<?php
+/**
+ * Handler for remote subscription
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011 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/>.
+ **/
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+require_once dirname(__FILE__) . '/../lib/omb.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/service_consumer.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/profile.php';
+
+/**
+ * Handler for remote subscription
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ */
+class RemotesubscribeAction extends Action
+{
+    var $nickname;
+    var $profile_url;
+    var $err;
+
+    function prepare($args)
+    {
+        parent::prepare($args);
+
+        if (common_logged_in()) {
+            // TRANS: Client error displayed when using remote subscribe for a local entity.
+            $this->clientError(_('You can use the local subscription!'));
+            return false;
+        }
+
+        $this->nickname    = $this->trimmed('nickname');
+        $this->profile_url = $this->trimmed('profile_url');
+
+        return true;
+    }
+
+    function handle($args)
+    {
+        parent::handle($args);
+
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+            /* Use a session token for CSRF protection. */
+            $token = $this->trimmed('token');
+            if (!$token || $token != common_session_token()) {
+                // TRANS: Client error displayed when the session token does not match or is not given.
+                $this->showForm(_('There was a problem with your session token. '.
+                                  'Try again, please.'));
+                return;
+            }
+            $this->remoteSubscription();
+        } else {
+            $this->showForm();
+        }
+    }
+
+    function showForm($err=null)
+    {
+        $this->err = $err;
+        $this->showPage();
+    }
+
+    function showPageNotice()
+    {
+        if ($this->err) {
+            $this->element('div', 'error', $this->err);
+        } else {
+            // TRANS: Page notice for remote subscribe. This message contains Markdown links.
+            // TRANS: Ensure to keep the correct markup of [link description](link).
+            $inst = _('To subscribe, you can [login](%%action.login%%),' .
+                      ' or [register](%%action.register%%) a new ' .
+                      ' account. If you already have an account ' .
+                      ' on a [compatible microblogging site](%%doc.openmublog%%), ' .
+                      ' enter your profile URL below.');
+            $output = common_markup_to_html($inst);
+            $this->elementStart('div', 'instructions');
+            $this->raw($output);
+            $this->elementEnd('div');
+        }
+    }
+
+    function title()
+    {
+        // TRANS: Page title for Remote subscribe.
+        return _('Remote subscribe');
+    }
+
+    function showContent()
+    {
+        /* The id 'remotesubscribe' conflicts with the
+           button on profile page. */
+        $this->elementStart('form', array('id' => 'form_remote_subscribe',
+                                          'method' => 'post',
+                                          'class' => 'form_settings',
+                                          'action' => common_local_url('remotesubscribe')));
+        $this->elementStart('fieldset');
+        // TRANS: Field legend on page for remote subscribe.
+        $this->element('legend', _('Subscribe to a remote user'));
+        $this->hidden('token', common_session_token());
+
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
+        // TRANS: Field label on page for remote subscribe.
+        $this->input('nickname', _('User nickname'), $this->nickname,
+                     // TRANS: Field title on page for remote subscribe.
+                     _('Nickname of the user you want to follow.'));
+        $this->elementEnd('li');
+        $this->elementStart('li');
+        // TRANS: Field label on page for remote subscribe.
+        $this->input('profile_url', _('Profile URL'), $this->profile_url,
+                     // TRANS: Field title on page for remote subscribe.
+                     _('URL of your profile on another compatible microblogging service.'));
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+        // TRANS: Button text on page for remote subscribe.
+        $this->submit('submit', _m('BUTTON','Subscribe'));
+        $this->elementEnd('fieldset');
+        $this->elementEnd('form');
+    }
+
+    function remoteSubscription()
+    {
+        if (!$this->nickname) {
+            // TRANS: Form validation error on page for remote subscribe when no user was provided.
+            $this->showForm(_('No such user.'));
+            return;
+        }
+
+        $user = User::staticGet('nickname', $this->nickname);
+
+        $this->profile_url = $this->trimmed('profile_url');
+
+        if (!$this->profile_url) {
+            // TRANS: Form validation error on page for remote subscribe when no user profile was found.
+            $this->showForm(_('No such user.'));
+            return;
+        }
+
+        if (!common_valid_http_url($this->profile_url)) {
+            // TRANS: Form validation error on page for remote subscribe when an invalid profile URL was provided.
+            $this->showForm(_('Invalid profile URL (bad format).'));
+            return;
+        }
+
+        try {
+            $service = new OMB_Service_Consumer($this->profile_url,
+                                                common_root_url(),
+                                                omb_oauth_datastore());
+        } catch (OMB_InvalidYadisException $e) {
+            // TRANS: Form validation error on page for remote subscribe when no the provided profile URL
+            // TRANS: does not contain expected data.
+            $this->showForm(_('Not a valid profile URL (no YADIS document or ' .
+                              'invalid XRDS defined).'));
+            return;
+        }
+
+        if ($service->getServiceURI(OAUTH_ENDPOINT_REQUEST) ==
+            common_local_url('requesttoken') ||
+            User::staticGet('uri', $service->getRemoteUserURI())) {
+            // TRANS: Form validation error on page for remote subscribe.
+            $this->showForm(_('That is a local profile! Login to subscribe.'));
+            return;
+        }
+
+        try {
+            $service->requestToken();
+        } catch (OMB_RemoteServiceException $e) {
+            // TRANS: Form validation error on page for remote subscribe when the remote service is not providing a request token.
+            $this->showForm(_('Could not get a request token.'));
+            return;
+        }
+
+        /* Create an OMB_Profile from $user. */
+        $profile = $user->getProfile();
+        if (!$profile) {
+            common_log_db_error($user, 'SELECT', __FILE__);
+            // TRANS: Error message displayed when referring to a user without a profile.
+            $this->serverError(_('User has no profile.'));
+            return;
+        }
+
+        $target_url = $service->requestAuthorization(
+                                   profile_to_omb_profile($user->uri, $profile),
+                                   common_local_url('finishremotesubscribe'));
+
+        common_ensure_session();
+
+        $_SESSION['oauth_authorization_request'] = serialize($service);
+
+        /* Redirect to the remote service for authorization. */
+        common_redirect($target_url, 303);
+    }
+}
diff --git a/plugins/OMB/actions/requesttoken.php b/plugins/OMB/actions/requesttoken.php
new file mode 100644 (file)
index 0000000..57e8118
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Request token action class.
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+require_once dirname(__FILE__) . '/../lib/omb.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/service_provider.php';
+
+/**
+ * Request token action class.
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ */
+class RequesttokenAction extends Action
+{
+     /**
+     * Is read only?
+     *
+     * @return boolean false
+     */
+    function isReadOnly()
+    {
+        return false;
+    }
+
+    /**
+     * Class handler.
+     *
+     * @param array $args array of arguments
+     *
+     * @return void
+     */
+    function handle($args)
+    {
+        parent::handle($args);
+        try {
+            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
+                                            omb_oauth_server());
+            $srv->writeRequestToken();
+        } catch (Exception $e) {
+            $this->serverError($e->getMessage());
+        }
+    }
+}
diff --git a/plugins/OMB/actions/updateprofile.php b/plugins/OMB/actions/updateprofile.php
new file mode 100644 (file)
index 0000000..29d334b
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * Handle an updateprofile action
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+require_once dirname(__FILE__) . '/../lib/omb.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/service_provider.php';
+
+/**
+ * Handle an updateprofile action
+ *
+ * @category Action
+ * @package  Laconica
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@controlyourself.ca>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://laconi.ca/
+ */
+class UpdateprofileAction extends Action
+{
+    /**
+     * For initializing members of the class.
+     *
+     * @param array $argarray misc. arguments
+     *
+     * @return boolean true
+     */
+    function prepare($argarray)
+    {
+        StatusNet::setApi(true); // Send smaller error pages
+
+        parent::prepare($argarray);
+        $license      = $_POST['omb_listenee_license'];
+        $site_license = common_config('license', 'url');
+        if (!common_compatible_license($license, $site_license)) {
+            // TRANS: Client error displayed when trying to update profile with an incompatible license.
+            // TRANS: %1$s is the license incompatible with site license %2$s.
+            $this->clientError(sprintf(_('Listenee stream license "%1$s" is not '.
+                                         'compatible with site license "%2$s".'),
+                                       $license, $site_license));
+            return false;
+        }
+        return true;
+    }
+
+    function handle($args)
+    {
+        parent::handle($args);
+
+        try {
+            $srv = new OMB_Service_Provider(null, omb_oauth_datastore(),
+                                            omb_oauth_server());
+            $srv->handleUpdateProfile();
+        } catch (OMB_RemoteServiceException $rse) {
+            $msg = $rse->getMessage();
+            if (preg_match('/Revoked accesstoken/', $msg) ||
+                preg_match('/No subscriber/', $msg)) {
+                $this->clientError($msg, 403);
+            } else {
+                $this->clientError($msg);
+            }
+        } catch (Exception $e) {
+            $this->serverError($e->getMessage());
+            return;
+        }
+    }
+}
diff --git a/plugins/OMB/actions/userauthorization.php b/plugins/OMB/actions/userauthorization.php
new file mode 100644 (file)
index 0000000..642a8dc
--- /dev/null
@@ -0,0 +1,371 @@
+<?php
+/**
+ * Let the user authorize a remote subscription request
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+require_once dirname(__FILE__) . '/../lib/omb.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/service_provider.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/profile.php';
+define('TIMESTAMP_THRESHOLD', 300);
+
+// @todo FIXME: Missing documentation.
+class UserauthorizationAction extends Action
+{
+    var $error;
+    var $params;
+
+    function handle($args)
+    {
+        parent::handle($args);
+
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+            /* Use a session token for CSRF protection. */
+            $token = $this->trimmed('token');
+            if (!$token || $token != common_session_token()) {
+                $srv = $this->getStoredParams();
+                // TRANS: Client error displayed when the session token does not match or is not given.
+                $this->showForm($srv->getRemoteUser(), _('There was a problem ' .
+                                        'with your session token. Try again, ' .
+                                        'please.'));
+                return;
+            }
+            /* We've shown the form, now post user's choice. */
+            $this->sendAuthorization();
+        } else {
+            if (!common_logged_in()) {
+                /* Go log in, and then come back. */
+                common_set_returnto($_SERVER['REQUEST_URI']);
+
+                common_redirect(common_local_url('login'));
+                return;
+            }
+
+            $user    = common_current_user();
+            $profile = $user->getProfile();
+            if (!$profile) {
+                common_log_db_error($user, 'SELECT', __FILE__);
+                // TRANS: Error message displayed when referring to a user without a profile.
+                $this->serverError(_('User has no profile.'));
+                return;
+            }
+
+            /* TODO: If no token is passed the user should get a prompt to enter
+               it according to OAuth Core 1.0. */
+            try {
+                $this->validateOmb();
+                $srv = new OMB_Service_Provider(
+                        profile_to_omb_profile($user->uri, $profile),
+                        omb_oauth_datastore());
+
+                $remote_user = $srv->handleUserAuth();
+            } catch (Exception $e) {
+                $this->clearParams();
+                $this->clientError($e->getMessage());
+                return;
+            }
+
+            $this->storeParams($srv);
+            $this->showForm($remote_user);
+        }
+    }
+
+    function showForm($params, $error=null)
+    {
+        $this->params = $params;
+        $this->error  = $error;
+        $this->showPage();
+    }
+
+    function title()
+    {
+        // TRANS: Page title.
+        return _('Authorize subscription');
+    }
+
+    function showPageNotice()
+    {
+        // TRANS: Page notice on "Authorize subscription" page.
+        $this->element('p', null, _('Please check these details to make sure '.
+                                    'that you want to subscribe to this ' .
+                                    'user’s notices. If you didn’t just ask ' .
+                                    'to subscribe to someone’s notices, '.
+                                    'click "Reject".'));
+    }
+
+    function showContent()
+    {
+        $params = $this->params;
+
+        $nickname = $params->getNickname();
+        $profile  = $params->getProfileURL();
+        $license  = $params->getLicenseURL();
+        $fullname = $params->getFullname();
+        $homepage = $params->getHomepage();
+        $bio      = $params->getBio();
+        $location = $params->getLocation();
+        $avatar   = $params->getAvatarURL();
+
+        $this->elementStart('div', 'entity_profile vcard');
+
+        if ($avatar) {
+            $this->element('img', array('src' => $avatar,
+                                        'class' => 'photo avatar entity_depiction',
+                                        'width' => AVATAR_PROFILE_SIZE,
+                                        'height' => AVATAR_PROFILE_SIZE,
+                                        'alt' => $nickname));
+        }
+
+        // TRANS: Label for nickname on user authorisation page.
+        $this->element('div', 'entity_nickname', _('Nickname'));
+
+        $hasFN = ($fullname !== '') ? 'nickname' : 'fn nickname';
+
+        // XXX: why are these raw() instead of escaped...?
+
+        $this->elementStart('a', array('href' => $profile,
+                                       'class' => 'url '.$hasFN));
+        $this->raw($nickname);
+        $this->elementEnd('a');
+
+        if (!is_null($fullname)) {
+            $this->elementStart('div', 'fn entity_fn');
+            $this->raw($fullname);
+            $this->elementEnd('div');
+        }
+
+        if (!is_null($location)) {
+            $this->elementStart('div', 'label entity_location');
+            $this->raw($location);
+        }
+
+        if (!is_null($homepage)) {
+            $this->elementStart('a', array('href' => $homepage,
+                                           'class' => 'url entity_url'));
+            $this->raw($homepage);
+            $this->elementEnd('a');
+        }
+
+        if (!is_null($bio)) {
+            $this->elementStart('div', 'note entity_note');
+            $this->raw($bio);
+            $this->elementEnd('dd');
+        }
+
+        if (!is_null($license)) {
+            $this->element('a', array('href' => $license,
+                                      'class' => 'license entity_license'),
+                           $license);
+        }
+
+        $this->elementEnd('div');
+
+        $this->elementStart('div', 'entity_actions');
+        $this->elementStart('ul');
+        $this->elementStart('li', 'entity_subscribe');
+        $this->elementStart('form', array('method' => 'post',
+                                          'id' => 'userauthorization',
+                                          'class' => 'form_user_authorization',
+                                          'name' => 'userauthorization',
+                                          'action' => common_local_url(
+                                                         'userauthorization')));
+        $this->hidden('token', common_session_token());
+
+        $this->submit('accept',
+                      // TRANS: Button text on Authorise Subscription page.
+                      _m('BUTTON','Accept'), 'submit accept', null,
+                      // TRANS: Title for button on Authorise Subscription page.
+                      _('Subscribe to this user.'));
+        $this->submit('reject',
+                      // TRANS: Button text on Authorise Subscription page.
+                      _m('BUTTON','Reject'), 'submit reject', null,
+                      // TRANS: Title for button on Authorise Subscription page.
+                      _('Reject this subscription.'));
+        $this->elementEnd('form');
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+        $this->elementEnd('div');
+    }
+
+    function sendAuthorization()
+    {
+        $srv = $this->getStoredParams();
+
+        if (is_null($srv)) {
+            // TRANS: Client error displayed for an empty authorisation request.
+            $this->clientError(_('No authorization request!'));
+            return;
+        }
+
+        $accepted = $this->arg('accept');
+        try {
+            list($val, $token) = $srv->continueUserAuth($accepted);
+        } catch (Exception $e) {
+            $this->clientError($e->getMessage());
+            return;
+        }
+        if ($val !== false) {
+            common_redirect($val, 303);
+        } elseif ($accepted) {
+            $this->showAcceptMessage($token);
+        } else {
+            $this->showRejectMessage();
+        }
+    }
+
+    function showAcceptMessage($tok)
+    {
+        // TRANS: Accept message header from Authorise subscription page.
+        common_show_header(_('Subscription authorized'));
+        $this->element('p', null,
+                       // TRANS: Accept message text from Authorise subscription page.
+                       _('The subscription has been authorized, but no '.
+                         'callback URL was passed. Check with the site\'s ' .
+                         'instructions for details on how to authorize the ' .
+                         'subscription. Your subscription token is:'));
+        $this->element('blockquote', 'token', $tok);
+        common_show_footer();
+    }
+
+    function showRejectMessage()
+    {
+        // TRANS: Reject message header from Authorise subscription page.
+        common_show_header(_('Subscription rejected'));
+        $this->element('p', null,
+                       // TRANS: Reject message from Authorise subscription page.
+                       _('The subscription has been rejected, but no '.
+                         'callback URL was passed. Check with the site\'s ' .
+                         'instructions for details on how to fully reject ' .
+                         'the subscription.'));
+        common_show_footer();
+    }
+
+    function storeParams($params)
+    {
+        common_ensure_session();
+        $_SESSION['userauthorizationparams'] = serialize($params);
+    }
+
+    function clearParams()
+    {
+        common_ensure_session();
+        unset($_SESSION['userauthorizationparams']);
+    }
+
+    function getStoredParams()
+    {
+        common_ensure_session();
+        $params = unserialize($_SESSION['userauthorizationparams']);
+        return $params;
+    }
+
+    function validateOmb()
+    {
+        $listener = $_GET['omb_listener'];
+        $listenee = $_GET['omb_listenee'];
+        $nickname = $_GET['omb_listenee_nickname'];
+        $profile  = $_GET['omb_listenee_profile'];
+
+        $user = User::staticGet('uri', $listener);
+        if (!$user) {
+            // TRANS: Exception thrown when no valid user is found for an authorisation request.
+            // TRANS: %s is a listener URI.
+            throw new Exception(sprintf(_('Listener URI "%s" not found here.'),
+                                        $listener));
+        }
+
+        if (strlen($listenee) > 255) {
+            // TRANS: Exception thrown when listenee URI is too long for an authorisation request.
+            // TRANS: %s is a listenee URI.
+            throw new Exception(sprintf(_('Listenee URI "%s" is too long.'),
+                                        $listenee));
+        }
+
+        $other = User::staticGet('uri', $listenee);
+        if ($other) {
+            // TRANS: Exception thrown when listenee URI is a local user for an authorisation request.
+            // TRANS: %s is a listenee URI.
+            throw new Exception(sprintf(_('Listenee URI "%s" is a local user.'),
+                                        $listenee));
+        }
+
+        $remote = Remote_profile::staticGet('uri', $listenee);
+        if ($remote) {
+            $sub             = new Subscription();
+            $sub->subscriber = $user->id;
+            $sub->subscribed = $remote->id;
+            if ($sub->find(true)) {
+                // TRANS: Exception thrown when already subscribed.
+                throw new Exception('You are already subscribed to this user.');
+            }
+        }
+
+        if ($profile == common_profile_url($nickname)) {
+            // TRANS: Exception thrown when profile URL is a local user for an authorisation request.
+            // TRANS: %s is a profile URL.
+            throw new Exception(sprintf(_('Profile URL "%s" is for a local user.'),
+                                        $profile));
+
+        }
+
+        $license      = $_GET['omb_listenee_license'];
+        $site_license = common_config('license', 'url');
+        if (!common_compatible_license($license, $site_license)) {
+            // TRANS: Exception thrown when licenses are not compatible for an authorisation request.
+            // TRANS: %1$s is the license for the listenee, %2$s is the license for "this" StatusNet site.
+            throw new Exception(sprintf(_('Listenee stream license "%1$s" is not ' .
+                                          'compatible with site license "%2$s".'),
+                                        $license, $site_license));
+        }
+
+        $avatar = $_GET['omb_listenee_avatar'];
+        if ($avatar) {
+            if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
+                // TRANS: Exception thrown when avatar URL is invalid for an authorisation request.
+                // TRANS: %s is an avatar URL.
+                throw new Exception(sprintf(_('Avatar URL "%s" is not valid.'),
+                                            $avatar));
+            }
+            $size = @getimagesize($avatar);
+            if (!$size) {
+                // TRANS: Exception thrown when avatar URL could not be read for an authorisation request.
+                // TRANS: %s is an avatar URL.
+                throw new Exception(sprintf(_('Cannot read avatar URL "%s".'),
+                                            $avatar));
+            }
+            if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG,
+                                          IMAGETYPE_PNG))) {
+                // TRANS: Exception thrown when avatar URL return an invalid image type for an authorisation request.
+                // TRANS: %s is an avatar URL.
+                throw new Exception(sprintf(_('Wrong image type for avatar URL '.
+                                              '"%s".'), $avatar));
+            }
+        }
+    }
+}
diff --git a/plugins/OMB/actions/xrds.php b/plugins/OMB/actions/xrds.php
new file mode 100644 (file)
index 0000000..5e6758e
--- /dev/null
@@ -0,0 +1,139 @@
+<?php
+/**
+ * XRDS for OpenMicroBlogging
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+require_once dirname(__FILE__) . '/../lib/omb.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/service_provider.php';
+require_once dirname(__FILE__) . '/../extlib/libomb/xrds_mapper.php';
+require_once dirname(__FILE__) . '/../lib/xrdsoutputter.php';
+
+/**
+ * XRDS for OpenMicroBlogging
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Robin Millette <millette@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ */
+class XrdsAction extends Action
+{
+    var $user;
+
+    /**
+     * Is read only?
+     *
+     * @return boolean true
+     */
+    function isReadOnly()
+    {
+        return true;
+    }
+
+    function prepare($args)
+    {
+        parent::prepare($args);
+        $nickname = $this->trimmed('nickname');
+        $this->user     = User::staticGet('nickname', $nickname);
+        if (!$this->user) {
+            // TRANS: Client error displayed providing a non-existing nickname.
+            $this->clientError(_('No such user.'));
+            return;
+        }
+        return true;
+    }
+
+    /**
+     * Class handler.
+     *
+     * @param array $args query arguments
+     *
+     * @return void
+     */
+    function handle($args)
+    {
+        parent::handle($args);
+        $xrdsOutputter = new XRDSOutputter();
+        $xrdsOutputter->startXRDS();
+
+        Event::handle('StartUserXRDS', array($this,&$xrdsOutputter));
+
+        //oauth
+        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+                                          'xml:id' => 'oauth',
+                                          'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
+                                          'version' => '2.0'));
+        $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
+        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_REQUEST,
+                            common_local_url('requesttoken'),
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1),
+                            null,
+                            $this->user->uri);
+        $xrdsOutputter->showXrdsService( OAUTH_ENDPOINT_AUTHORIZE,
+                            common_local_url('userauthorization'),
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
+        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_ACCESS,
+                            common_local_url('accesstoken'),
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
+        $xrdsOutputter->showXrdsService(OAUTH_ENDPOINT_RESOURCE,
+                            null,
+                            array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY, OAUTH_HMAC_SHA1));
+        $xrdsOutputter->elementEnd('XRD');
+
+        //omb
+        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+                                          'xml:id' => 'omb',
+                                          'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
+                                          'version' => '2.0'));
+        $xrdsOutputter->element('Type', null, 'xri://$xrds*simple');
+        $xrdsOutputter->showXrdsService(OMB_ENDPOINT_POSTNOTICE,
+                            common_local_url('postnotice'));
+        $xrdsOutputter->showXrdsService(OMB_ENDPOINT_UPDATEPROFILE,
+                            common_local_url('updateprofile'));
+        $xrdsOutputter->elementEnd('XRD');
+
+        Event::handle('EndUserXRDS', array($this,&$xrdsOutputter));
+
+        //misc
+        $xrdsOutputter->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+                                          'version' => '2.0'));
+        $xrdsOutputter->showXrdsService(OAUTH_DISCOVERY,
+                            '#oauth');
+        $xrdsOutputter->showXrdsService(OMB_VERSION,
+                            '#omb');
+        $xrdsOutputter->elementEnd('XRD');
+
+        $xrdsOutputter->endXRDS();
+    }
+}
diff --git a/plugins/OMB/extlib/libomb/base_url_xrds_mapper.php b/plugins/OMB/extlib/libomb/base_url_xrds_mapper.php
new file mode 100755 (executable)
index 0000000..d45d6d6
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'xrds_mapper.php';
+require_once 'constants.php';
+
+/**
+ * Map XRDS actions to URLs using base URLs
+ *
+ * This class realizes a simple mapping of action URIs to handler URLs. The
+ * target URLs are constructed using a base URL.
+ */
+class OMB_Base_URL_XRDS_Mapper implements OMB_XRDS_Mapper
+{
+    protected $urls;
+
+    /**
+     * Constructor
+     *
+     * Initialize the XRDS mapper with base URLs for OAuth and OMB endpoints.
+     *
+     * @param string $oauth_base The base URL for OAuth endpoints
+     * @param string $omb_base   The base URL for OMB endpoints
+     */
+    public function __construct($oauth_base, $omb_base)
+    {
+        $this->urls = array(
+                OAUTH_ENDPOINT_REQUEST => $oauth_base . 'requesttoken',
+                OAUTH_ENDPOINT_AUTHORIZE => $oauth_base . 'userauthorization',
+                OAUTH_ENDPOINT_ACCESS => $oauth_base . 'accesstoken',
+                OMB_ENDPOINT_POSTNOTICE => $omb_base . 'postnotice',
+                OMB_ENDPOINT_UPDATEPROFILE => $omb_base . 'updateprofile');
+    }
+
+    /**
+     * Fetch an URL for a specified action
+     *
+     * Returns the action URL for an action specified by the endpoint URI.
+     *
+     * @param string $action The endpoint URI
+     *
+     * @return string The action URL
+     */
+    public function getURL($action)
+    {
+        return $this->urls[$action];
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/constants.php b/plugins/OMB/extlib/libomb/constants.php
new file mode 100644 (file)
index 0000000..2f8c0e5
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Constants for libomb
+ *
+ * This file contains constant definitions for libomb. The defined constants
+ * are service and namespace URIs for OAuth and OMB as used in XRDS.
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+/**
+ * The OMB constants.
+ */
+
+define('OMB_VERSION_01', 'http://openmicroblogging.org/protocol/0.1');
+
+/* The OMB version supported by this libomb version. */
+define('OMB_VERSION', OMB_VERSION_01);
+
+define('OMB_ENDPOINT_UPDATEPROFILE', OMB_VERSION . '/updateProfile');
+define('OMB_ENDPOINT_POSTNOTICE', OMB_VERSION . '/postNotice');
+
+/**
+ * The OAuth constants.
+ */
+
+define('OAUTH_NAMESPACE', 'http://oauth.net/core/1.0/');
+
+define('OAUTH_ENDPOINT_REQUEST', OAUTH_NAMESPACE.'endpoint/request');
+define('OAUTH_ENDPOINT_AUTHORIZE', OAUTH_NAMESPACE.'endpoint/authorize');
+define('OAUTH_ENDPOINT_ACCESS', OAUTH_NAMESPACE.'endpoint/access');
+define('OAUTH_ENDPOINT_RESOURCE', OAUTH_NAMESPACE.'endpoint/resource');
+
+define('OAUTH_AUTH_HEADER', OAUTH_NAMESPACE.'parameters/auth-header');
+define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body');
+
+define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1');
+
+define('OAUTH_DISCOVERY', 'http://oauth.net/discovery/1.0');
+?>
diff --git a/plugins/OMB/extlib/libomb/datastore.php b/plugins/OMB/extlib/libomb/datastore.php
new file mode 100755 (executable)
index 0000000..d67aafc
--- /dev/null
@@ -0,0 +1,212 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'OAuth.php';
+
+/**
+ * Data access interface
+ *
+ * This interface specifies data access methods libomb needs. It should be
+ * implemented by libomb users. OMB_Datastore is libomb’s main interface to the
+ * application’s data. Objects corresponding to this interface are used in
+ * OMB_Service_Provider and OMB_Service_Consumer.
+ *
+ * Note that it’s implemented as a class since OAuthDataStore is as well a
+ * class, though only declaring methods.
+ *
+ * OMB_Datastore extends OAuthDataStore with two OAuth-related methods for token
+ * revoking and authorizing and all OMB-related methods.
+ * Refer to OAuth.php for a complete specification of OAuth-related methods.
+ *
+ * It is the user’s duty to signal and handle errors. libomb does not check
+ * return values nor handle exceptions. It is suggested to use exceptions.
+ * Note that lookup_token and getProfile return null if the requested object
+ * is not available. This is NOT an error and should not raise an exception.
+ * Same applies for lookup_nonce which returns a boolean value. These methods
+ * may nevertheless throw an exception, for example in case of a storage errors.
+ *
+ * Most of the parameters passed to these methods are unescaped and unverified
+ * user input. Therefore they should be handled with extra care to avoid
+ * security problems like SQL injections.
+ */
+class OMB_Datastore extends OAuthDataStore
+{
+
+    /*********
+     * OAUTH *
+     *********/
+
+    /**
+     * Revoke specified OAuth token
+     *
+     * Revokes the authorization token specified by $token_key.
+     * Throws exceptions in case of error.
+     *
+     * @param string $token_key The key of the token to be revoked
+     *
+     * @access public
+     */
+    public function revoke_token($token_key)
+    {
+        throw new Exception();
+    }
+
+    /**
+     * Authorize specified OAuth token
+     *
+     * Authorizes the authorization token specified by $token_key.
+     * Throws exceptions in case of error.
+     *
+     * @param string $token_key The key of the token to be authorized
+     *
+     * @access public
+     */
+    public function authorize_token($token_key)
+    {
+        throw new Exception();
+    }
+
+    /*********
+     *  OMB  *
+     *********/
+
+    /**
+     * Get profile by identifying URI
+     *
+     * Returns an OMB_Profile object representing the OMB profile identified by
+     * $identifier_uri.
+     * Returns null if there is no such OMB profile.
+     * Throws exceptions in case of other error.
+     *
+     * @param string $identifier_uri The OMB identifier URI specifying the
+     *                               requested profile
+     *
+     * @access public
+     *
+     * @return OMB_Profile The corresponding profile
+     */
+    public function getProfile($identifier_uri)
+    {
+        throw new Exception();
+    }
+
+    /**
+     * Save passed profile
+     *
+     * Stores the OMB profile $profile. Overwrites an existing entry.
+     * Throws exceptions in case of error.
+     *
+     * @param OMB_Profile $profile The OMB profile which should be saved
+     *
+     * @access public
+     */
+    public function saveProfile($profile)
+    {
+        throw new Exception();
+    }
+
+    /**
+     * Save passed notice
+     *
+     * Stores the OMB notice $notice. The datastore may change the passed
+     * notice. This might by necessary for URIs depending on a database key.
+     * Note that it is the user’s duty to present a mechanism for his
+     * OMB_Datastore to appropriately change his OMB_Notice.
+     * Throws exceptions in case of error.
+     *
+     * @param OMB_Notice &$notice The OMB notice which should be saved
+     *
+     * @access public
+     */
+    public function saveNotice(&$notice)
+    {
+        throw new Exception();
+    }
+
+    /**
+     * Get subscriptions of a given profile
+     *
+     * Returns an array containing subscription informations for the specified
+     * profile. Every array entry should in turn be an array with keys
+     *   'uri´: The identifier URI of the subscriber
+     *   'token´: The subscribe token
+     *   'secret´: The secret token
+     * Throws exceptions in case of error.
+     *
+     * @param string $subscribed_user_uri The OMB identifier URI specifying the
+     *                                    subscribed profile
+     *
+     * @access public
+     *
+     * @return mixed An array containing the subscriptions or 0 if no
+     *               subscription has been found.
+     */
+    public function getSubscriptions($subscribed_user_uri)
+    {
+        throw new Exception();
+    }
+
+    /**
+     * Delete a subscription
+     *
+     * Deletes the subscription from $subscriber_uri to $subscribed_user_uri.
+     * Throws exceptions in case of error.
+     *
+     * @param string $subscriber_uri      The OMB identifier URI specifying the
+     *                                    subscribing profile
+     *
+     * @param string $subscribed_user_uri The OMB identifier URI specifying the
+     *                                    subscribed profile
+     *
+     * @access public
+     */
+    public function deleteSubscription($subscriber_uri, $subscribed_user_uri)
+    {
+        throw new Exception();
+    }
+
+    /**
+     * Save a subscription
+     *
+     * Saves the subscription from $subscriber_uri to $subscribed_user_uri.
+     * Throws exceptions in case of error.
+     *
+     * @param string     $subscriber_uri      The OMB identifier URI specifying
+     *                                            the subscribing profile
+     *
+     * @param string     $subscribed_user_uri The OMB identifier URI specifying
+     *                                            the subscribed profile
+     * @param OAuthToken $token               The access token
+     *
+     * @access public
+     */
+    public function saveSubscription($subscriber_uri, $subscribed_user_uri,
+                                     $token)
+    {
+        throw new Exception();
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/helper.php b/plugins/OMB/extlib/libomb/helper.php
new file mode 100644 (file)
index 0000000..08e6e7a
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'Validate.php';
+
+/**
+ * Helper functions for libomb
+ *
+ * This class contains helper functions for libomb.
+ */
+class OMB_Helper
+{
+
+    /**
+     * Non-scalar constants
+     *
+     * The set of OMB and OAuth Services an OMB Server has to implement.
+     */
+
+    public static $OMB_SERVICES   = array(OMB_ENDPOINT_UPDATEPROFILE,
+                                          OMB_ENDPOINT_POSTNOTICE);
+    public static $OAUTH_SERVICES = array(OAUTH_ENDPOINT_REQUEST,
+                                          OAUTH_ENDPOINT_AUTHORIZE,
+                                          OAUTH_ENDPOINT_ACCESS);
+
+    /**
+     * Validate URL
+     *
+     * Basic URL validation. Currently http, https, ftp and gopher are supported
+     * schemes.
+     *
+     * @param string $url The URL which is to be validated.
+     *
+     * @return bool Whether URL is valid.
+     *
+     * @access public
+     */
+    public static function validateURL($url)
+    {
+        return Validate::uri($url, array('allowed_schemes' => array('http',
+                                                    'https', 'gopher', 'ftp')));
+    }
+
+    /**
+     * Validate Media type
+     *
+     * Basic Media type validation. Checks for valid maintype and correct
+     * format.
+     *
+     * @param string $mediatype The Media type which is to be validated.
+     *
+     * @return bool Whether media type is valid.
+     *
+     * @access public
+     */
+    public static function validateMediaType($mediatype)
+    {
+        return preg_match('/^(\w+)\/([\w\d-+.]+)$/', $mediatype, $subtypes) > 0
+               &&
+               in_array(strtolower($subtypes[1]), array('application', 'audio',
+               'image', 'message', 'model', 'multipart', 'text', 'video'));
+    }
+
+    /**
+     * Remove escaping from request parameters
+     *
+     * Neutralise the evil effects of magic_quotes_gpc in the current request.
+     * This is used before handing a request off to OAuthRequest::from_request.
+     * Many thanks to Ciaran Gultnieks for this fix.
+     *
+     * @access public
+     */
+    public static function removeMagicQuotesFromRequest()
+    {
+        if (get_magic_quotes_gpc() === 1) {
+            $_POST = array_map('stripslashes', $_POST);
+            $_GET  = array_map('stripslashes', $_GET);
+        }
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/invalidparameterexception.php b/plugins/OMB/extlib/libomb/invalidparameterexception.php
new file mode 100755 (executable)
index 0000000..d95c702
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+/**
+ * Exception stating that a passed parameter is invalid
+ *
+ * This exception is raised when a parameter does not obey the OMB standard.
+ */
+class OMB_InvalidParameterException extends Exception
+{
+    /**
+     * Constructor
+     *
+     * Creates a new exception based on a parameter name, value, and object
+     * type.
+     *
+     * @param string $value     The wrong value passed
+     * @param string $type      The object type the parameter belongs to;
+     *                          Currently OMB uses profiles and notices
+     * @param string $parameter The name of the parameter the wrong value has
+     *                          been passed for
+     */
+    public function __construct($value, $type, $parameter)
+    {
+        parent::__construct("Invalid value ‘${value}’ for parameter " .
+                            "‘${parameter}’ in $type");
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/invalidyadisexception.php b/plugins/OMB/extlib/libomb/invalidyadisexception.php
new file mode 100755 (executable)
index 0000000..dc61a13
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+/**
+ * Exception stating that a requested url does not resolve to a valid yadis
+ *
+ * This exception is raised when OMB_Service is not able to discover a valid
+ * yadis location with XRDS.
+ */
+class OMB_InvalidYadisException extends Exception
+{
+
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/notice.php b/plugins/OMB/extlib/libomb/notice.php
new file mode 100755 (executable)
index 0000000..4963597
--- /dev/null
@@ -0,0 +1,294 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'invalidparameterexception.php';
+require_once 'Validate.php';
+require_once 'helper.php';
+
+/**
+ * OMB Notice representation
+ *
+ * This class represents an OMB notice.
+ *
+ * Do not call the setters with null values. Instead, if you want to delete a
+ * field, pass an empty string. The getters will return null for empty fields.
+ */
+class OMB_Notice
+{
+    protected $author;
+    protected $uri;
+    protected $content;
+    protected $url;
+    protected $license_url; /* url is an own addition for clarification. */
+    protected $seealso_url; /* url is an own addition for clarification. */
+    protected $seealso_disposition;
+    protected $seealso_mediatype;
+    protected $seealso_license_url; /* url is an addition for clarification. */
+
+    /* The notice as OMB param array. Cached and rebuild on usage.
+       false while outdated. */
+    protected $param_array;
+
+    /**
+     * Constructor for OMB_Notice
+     *
+     * Initializes the OMB_Notice object with author, uri and content.
+     * These parameters are mandatory for postNotice.
+     *
+     * @param object $author  An OMB_Profile object representing the author of
+     *                        the notice.
+     * @param string $uri     The notice URI as defined by the OMB. A unique and
+     *                        never changing identifier for a notice.
+     * @param string $content The content of the notice. 140 chars recommended,
+     *                        but there is no limit.
+     *
+     * @access public
+     */
+    public function __construct($author, $uri, $content)
+    {
+        $this->content = $content;
+        if (is_null($author)) {
+            throw new OMB_InvalidParameterException('', 'notice', 'omb_listenee');
+        }
+        $this->author = $author;
+
+        if (!Validate::uri($uri)) {
+            throw new OMB_InvalidParameterException($uri, 'notice', 'omb_notice');
+        }
+        $this->uri = $uri;
+
+        $this->param_array = false;
+    }
+
+    /**
+     * Return the notice as array
+     *
+     * Returns an array which contains the whole notice as array. The array is
+     * cached and only rebuilt on changes of the notice.
+     * Empty optional values are not passed.
+     *
+     * @access public
+     * @return array The notice as parameter array
+     */
+    public function asParameters()
+    {
+        if ($this->param_array !== false) {
+            return $this->param_array;
+        }
+
+        $this->param_array = array(
+                                 'omb_notice' => $this->uri,
+                                 'omb_notice_content' => $this->content);
+
+        if (!is_null($this->url))
+            $this->param_array['omb_notice_url'] = $this->url;
+
+        if (!is_null($this->license_url))
+            $this->param_array['omb_notice_license'] = $this->license_url;
+
+        if (!is_null($this->seealso_url)) {
+            $this->param_array['omb_seealso'] = $this->seealso_url;
+
+            /* This is actually a free interpretation of the OMB standard. We
+               assume that additional seealso parameters are not of any use if
+               seealso itself is not set. */
+            if (!is_null($this->seealso_disposition))
+                $this->param_array['omb_seealso_disposition'] =
+                                                     $this->seealso_disposition;
+
+            if (!is_null($this->seealso_mediatype))
+                $this->param_array['omb_seealso_mediatype'] =
+                                                       $this->seealso_mediatype;
+
+            if (!is_null($this->seealso_license_url))
+                $this->param_array['omb_seealso_license'] =
+                                                     $this->seealso_license_url;
+        }
+        return $this->param_array;
+    }
+
+    /**
+     * Build an OMB_Notice object from array
+     *
+     * Builds an OMB_Notice object from the passed parameters array. The array
+     * MUST provide a notice URI and content. The array fields HAVE TO be named
+     * according to the OMB standard, i. e. omb_notice_* and omb_seealso_*.
+     * Values are handled as not passed if the corresponding array fields are
+     * not set or the empty string.
+     *
+     * @param object $author     An OMB_Profile object representing the author
+     *                           of the notice.
+     * @param string $parameters An array containing the notice parameters.
+     *
+     * @access public
+     *
+     * @returns OMB_Notice The built OMB_Notice.
+     */
+    public static function fromParameters($author, $parameters)
+    {
+        $notice = new OMB_Notice($author, $parameters['omb_notice'],
+                                             $parameters['omb_notice_content']);
+
+        if (isset($parameters['omb_notice_url'])) {
+            $notice->setURL($parameters['omb_notice_url']);
+        }
+
+        if (isset($parameters['omb_notice_license'])) {
+            $notice->setLicenseURL($parameters['omb_notice_license']);
+        }
+
+        if (isset($parameters['omb_seealso'])) {
+            $notice->setSeealsoURL($parameters['omb_seealso']);
+        }
+
+        if (isset($parameters['omb_seealso_disposition'])) {
+            $notice->setSeealsoDisposition($parameters['omb_seealso_disposition']);
+        }
+
+        if (isset($parameters['omb_seealso_mediatype'])) {
+            $notice->setSeealsoMediatype($parameters['omb_seealso_mediatype']);
+        }
+
+        if (isset($parameters['omb_seealso_license'])) {
+            $notice->setSeealsoLicenseURL($parameters['omb_seealso_license']);
+        }
+        return $notice;
+    }
+
+    public function getAuthor()
+    {
+        return $this->author;
+    }
+
+    public function getIdentifierURI()
+    {
+        return $this->uri;
+    }
+
+    public function getContent()
+    {
+        return $this->content;
+    }
+
+    public function getURL()
+    {
+        return $this->url;
+    }
+
+    public function getLicenseURL()
+    {
+        return $this->license_url;
+    }
+
+    public function getSeealsoURL()
+    {
+        return $this->seealso_url;
+    }
+
+    public function getSeealsoDisposition()
+    {
+        return $this->seealso_disposition;
+    }
+
+    public function getSeealsoMediatype()
+    {
+        return $this->seealso_mediatype;
+    }
+
+    public function getSeealsoLicenseURL()
+    {
+        return $this->seealso_license_url;
+    }
+
+    public function setURL($url)
+    {
+        $this->setVal('notice_url', $url, 'OMB_Helper::validateURL', 'url');
+    }
+
+    public function setLicenseURL($license_url)
+    {
+        $this->setVal('license', $license_url, 'OMB_Helper::validateURL',
+                      'license_url');
+    }
+
+    public function setSeealsoURL($seealso_url)
+    {
+        $this->setVal('seealso', $seealso_url, 'OMB_Helper::validateURL',
+                      'seealso_url');
+    }
+
+    public function setSeealsoDisposition($seealso_disposition)
+    {
+        $this->setVal('seealso_disposition', $seealso_disposition,
+                      'OMB_Notice::validateDisposition');
+    }
+
+    protected static function validateDisposition($str)
+    {
+        return in_array($str, array('link', 'inline'));
+    }
+
+    public function setSeealsoMediatype($seealso_mediatype)
+    {
+        $this->setVal('seealso_mediatype', $seealso_mediatype,
+                      'OMB_Helper::validateMediaType');
+    }
+
+    public function setSeealsoLicenseURL($seealso_license_url)
+    {
+        $this->setVal('seealso_license', $seealso_license_url,
+                      'OMB_Helper::validateURL', 'seealso_license_url');
+    }
+
+    /**
+     * Set a value
+     *
+     * Updates a value specified by a parameter name and the new value.
+     *
+     * @param string   $param     The parameter name according to OMB
+     * @param string   $value     The new value
+     * @param callback $validator A validator function for the parameter
+     * @param string   $field     The name of the field in OMB_Notice
+     * @param bool     $force     Whether null values should be checked as well
+     */
+    protected function setVal($param, $value, $validator, $field = null,
+                              $force = false)
+    {
+        if (is_null($field)) {
+            $field = $param;
+        }
+        if ($value === '' && !$force) {
+            $value = null;
+        } elseif (!call_user_func($validator, $value)) {
+            throw new OMB_InvalidParameterException($value, 'notice', $param);
+        }
+        if ($this->$field !== $value) {
+            $this->$field      = $value;
+            $this->param_array = false;
+        }
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/omb_yadis_xrds.php b/plugins/OMB/extlib/libomb/omb_yadis_xrds.php
new file mode 100755 (executable)
index 0000000..a05477c
--- /dev/null
@@ -0,0 +1,209 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'Auth/Yadis/Yadis.php';
+require_once 'unsupportedserviceexception.php';
+require_once 'invalidyadisexception.php';
+
+/**
+ * OMB XRDS representation
+ *
+ * This class represents a Yadis XRDS file for OMB. It adds some useful methods to
+ * Auth_Yadis_XRDS.
+ */
+class OMB_Yadis_XRDS extends Auth_Yadis_XRDS
+{
+
+    protected $fetcher;
+
+    /**
+     * Create an instance from URL
+     *
+     * Constructs an OMB_Yadis_XRDS object from a given URL. A full Yadis
+     * discovery is performed on the URL and the XRDS is parsed.
+     * Throws an OMB_InvalidYadisException when no Yadis is discovered or the
+     * detected XRDS file is broken.
+     *
+     * @param string                 $url     The URL on which Yadis discovery
+     *                                        should be performed on
+     * @param Auth_Yadis_HTTPFetcher $fetcher A fetcher used to get HTTP
+     *                                        resources
+     *
+     * @access public
+     *
+     * @return OMB_Yadis_XRDS The initialized object representing the given
+     *                        resource
+     */
+    public static function fromYadisURL($url, $fetcher)
+    {
+        /* Perform a Yadis discovery. */
+        $yadis = Auth_Yadis_Yadis::discover($url, $fetcher);
+        if ($yadis->failed) {
+            throw new OMB_InvalidYadisException($url);
+        }
+
+        /* Parse the XRDS file. */
+        $xrds = OMB_Yadis_XRDS::parseXRDS($yadis->response_text);
+        if ($xrds === null) {
+            throw new OMB_InvalidYadisException($url);
+        }
+        $xrds->fetcher = $fetcher;
+        return $xrds;
+    }
+
+    /**
+     * Get a specific service
+     *
+     * Returns the Auth_Yadis_Service object corresponding to the given service
+     * URI.
+     * Throws an OMB_UnsupportedServiceException if the service is not
+     * available.
+     *
+     * @param string $service URI specifier of the requested service
+     *
+     * @access public
+     *
+     * @return Auth_Yadis_Service The object representing the requested service
+     */
+    public function getService($service)
+    {
+        $match = $this->services(array(create_function('$s',
+                             "return in_array('$service', \$s->getTypes());")));
+        if ($match === array()) {
+            throw new OMB_UnsupportedServiceException($service);
+        }
+        return $match[0];
+    }
+
+    /**
+     * Get a specific XRD
+     *
+     * Returns the OMB_Yadis_XRDS object corresponding to the given URI.
+     * Throws an OMB_UnsupportedServiceException if the XRD is not available.
+     * Note that getXRD tries to resolve external XRD parts as well.
+     *
+     * @param string $uri URI specifier of the requested XRD
+     *
+     * @access public
+     *
+     * @return OMB_Yadis_XRDS The object representing the requested XRD
+     */
+    public function getXRD($uri)
+    {
+        $nexthash = strpos($uri, '#');
+        if ($nexthash === false) {
+            throw new OMB_InvalidYadisException("‘$uri’ does not specify a " .
+                                                'valid XML node.');
+        }
+
+        if ($nexthash > 0) {
+            $cururi  = substr($uri, 0, $nexthash);
+            $nexturi = substr($uri, $nexthash);
+            return OMB_Yadis_XRDS::fromYadisURL($cururi, $this->fetcher)
+                                               ->getXRD($nexturi);
+        }
+
+        $id = substr($uri, 1);
+        foreach ($this->allXrdNodes as $node) {
+            $attrs = $this->parser->attributes($node);
+            if (array_key_exists('xml:id', $attrs) && $attrs['xml:id'] == $id) {
+                /* Trick the constructor into thinking this is the only node. */
+                $bogus_nodes = array($node);
+                return new OMB_Yadis_XRDS($this->parser, $bogus_nodes);
+            }
+        }
+        throw new OMB_UnsupportedServiceException($uri);
+    }
+
+    /**
+     * Parse an XML string containing a XRDS document
+     *
+     * Parses an XML string (XRDS document) and returns either an
+     * Auth_Yadis_XRDS object or null, depending on whether the XRDS XML is
+     * valid.
+     * This method is just copy and paste from the parent class to select the
+     * correct constructor.
+     *
+     * @param string $xml_string   An XRDS XML string
+     * @param array  $extra_ns_map Additional namespace declarations
+     *
+     * @access public
+     *
+     * @return mixed An instance of OMB_Yadis_XRDS or null,
+     *               depending on the validity of $xml_string
+     */
+    public static function parseXRDS($xml_string, $extra_ns_map = null)
+    {
+        $_null = null;
+
+        if (!$xml_string) {
+            return $_null;
+        }
+
+        $parser = Auth_Yadis_getXMLParser();
+
+        $ns_map = Auth_Yadis_getNSMap();
+
+        if ($extra_ns_map && is_array($extra_ns_map)) {
+            $ns_map = array_merge($ns_map, $extra_ns_map);
+        }
+
+        if (!($parser && $parser->init($xml_string, $ns_map))) {
+            return $_null;
+        }
+
+        // Try to get root element.
+        $root = $parser->evalXPath('/xrds:XRDS[1]');
+        if (!$root) {
+            return $_null;
+        }
+
+        if (is_array($root)) {
+            $root = $root[0];
+        }
+
+        $attrs = $parser->attributes($root);
+
+        if (array_key_exists('xmlns:xrd', $attrs) &&
+                    $attrs['xmlns:xrd'] != Auth_Yadis_XMLNS_XRDS) {
+            return $_null;
+        } else if (array_key_exists('xmlns', $attrs) &&
+                                     preg_match('/xri/', $attrs['xmlns']) &&
+                                     $attrs['xmlns'] != Auth_Yadis_XMLNS_XRD_2_0) {
+            return $_null;
+        }
+
+        // Get the last XRD node.
+        $xrd_nodes = $parser->evalXPath('/xrds:XRDS[1]/xrd:XRD');
+
+        if (!$xrd_nodes) {
+            return $_null;
+        }
+
+        $xrds = new OMB_Yadis_XRDS($parser, $xrd_nodes);
+        return $xrds;
+    }
+}
diff --git a/plugins/OMB/extlib/libomb/plain_xrds_writer.php b/plugins/OMB/extlib/libomb/plain_xrds_writer.php
new file mode 100755 (executable)
index 0000000..ba1027b
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'xrds_writer.php';
+
+/**
+ * Write OMB-specific XRDS using XMLWriter
+ *
+ * This class writes the XRDS file announcing the OMB server. It uses XMLWriter.
+ * An instance of OMB_Plain_XRDS_Writer should be passed to
+ * OMB_Service_Provider->writeXRDS.
+ */
+class OMB_Plain_XRDS_Writer implements OMB_XRDS_Writer
+{
+    /**
+     * Write XRDS using XMLWriter
+     *
+     * Outputs a XRDS document specifying an OMB service.
+     *
+     * @param OMB_profile     $user   The target user for the OMB service
+     * @param OMB_XRDS_Mapper $mapper An OMB_XRDS_Mapper providing endpoint URLs
+     */
+    public function writeXRDS($user, $mapper)
+    {
+        header('Content-Type: application/xrds+xml');
+        $xw = new XMLWriter();
+        $xw->openURI('php://output');
+        $xw->setIndent(true);
+
+        $xw->startDocument('1.0', 'UTF-8');
+        $this->_writeFullElement($xw, 'XRDS', array('xmlns' => 'xri://$xrds'), array(
+        array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+                            'xml:id' => 'oauth',
+                            'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
+                            'version' => '2.0'), array(
+          array('Type', null, 'xri://$xrds*simple'),
+          array('Service', null, array(
+            array('Type', null, OAUTH_ENDPOINT_REQUEST),
+            array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_REQUEST)),
+            array('Type', null, OAUTH_AUTH_HEADER),
+            array('Type', null, OAUTH_POST_BODY),
+            array('Type', null, OAUTH_HMAC_SHA1),
+            array('LocalID', null, $user->getIdentifierURI())
+          )),
+          array('Service', null, array(
+            array('Type', null, OAUTH_ENDPOINT_AUTHORIZE),
+            array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_AUTHORIZE)),
+            array('Type', null, OAUTH_AUTH_HEADER),
+            array('Type', null, OAUTH_POST_BODY),
+            array('Type', null, OAUTH_HMAC_SHA1)
+          )),
+          array('Service', null, array(
+            array('Type', null, OAUTH_ENDPOINT_ACCESS),
+            array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_ACCESS)),
+            array('Type', null, OAUTH_AUTH_HEADER),
+            array('Type', null, OAUTH_POST_BODY),
+            array('Type', null, OAUTH_HMAC_SHA1)
+          )),
+          array('Service', null, array(
+            array('Type', null, OAUTH_ENDPOINT_RESOURCE),
+            array('Type', null, OAUTH_AUTH_HEADER),
+            array('Type', null, OAUTH_POST_BODY),
+            array('Type', null, OAUTH_HMAC_SHA1)
+          ))
+        )),
+        array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+                           'xml:id' => 'omb',
+                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
+                           'version' => '2.0'), array(
+          array('Type', null, 'xri://$xrds*simple'),
+          array('Service', null, array(
+            array('Type', null, OMB_ENDPOINT_POSTNOTICE),
+            array('URI', null, $mapper->getURL(OMB_ENDPOINT_POSTNOTICE))
+          )),
+          array('Service', null, array(
+            array('Type', null, OMB_ENDPOINT_UPDATEPROFILE),
+            array('URI', null, $mapper->getURL(OMB_ENDPOINT_UPDATEPROFILE))
+          ))
+        )),
+        array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+                           'version' => '2.0'), array(
+          array('Type', null, 'xri://$xrds*simple'),
+          array('Service', null, array(
+            array('Type', null, OAUTH_DISCOVERY),
+            array('URI', null, '#oauth')
+          )),
+          array('Service', null, array(
+            array('Type', null, OMB_VERSION),
+            array('URI', null, '#omb')
+          ))
+        ))));
+        $xw->endDocument();
+        $xw->flush();
+    }
+
+    /**
+     * Write a complex XML element
+     *
+     * Outputs a XML element with attributes and content.
+     *
+     * @param XMLWriter    $xw         The XMLWriter used to output the element
+     * @param string       $tag        The tag name
+     * @param array|null   $attributes A map of XML attributes
+     * @param array|string $content    The content of the element; either an
+     *                                 array of child nodes each specified by a
+     *                                 three entry-array ($tag, $attributes,
+     *                                 $content) or a string
+     */
+    private function _writeFullElement($xw, $tag, $attributes, $content)
+    {
+        $xw->startElement($tag);
+        if (!is_null($attributes)) {
+            foreach ($attributes as $name => $value) {
+                $xw->writeAttribute($name, $value);
+            }
+        }
+        if (is_array($content)) {
+            foreach ($content as $val) {
+                $this->_writeFullElement($xw, $val[0], $val[1], $val[2]);
+            }
+        } else {
+            $xw->text($content);
+        }
+        $xw->fullEndElement();
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/profile.php b/plugins/OMB/extlib/libomb/profile.php
new file mode 100755 (executable)
index 0000000..d732e10
--- /dev/null
@@ -0,0 +1,345 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'invalidparameterexception.php';
+require_once 'Validate.php';
+require_once 'helper.php';
+
+/**
+ * OMB profile representation
+ *
+ * This class represents an OMB profile.
+ *
+ * Do not call the setters with null values. Instead, if you want to delete a
+ * field, pass an empty string. The getters will return null for empty fields.
+ */
+class OMB_Profile
+{
+    protected $identifier_uri;
+    protected $profile_url;
+    protected $nickname;
+    protected $license_url;
+    protected $fullname;
+    protected $homepage;
+    protected $bio;
+    protected $location;
+    protected $avatar_url;
+
+    /* The profile as OMB param array. Cached and rebuild on usage.
+       false while outdated. */
+    protected $param_array;
+
+    /**
+     * Constructor for OMB_Profile
+     *
+     * Initializes the OMB_Profile object with an identifier uri.
+     *
+     * @param string $identifier_uri The profile URI as defined by the OMB;
+     *                               A unique and never changing identifier for
+     *                               a profile
+     *
+     * @access public
+     */
+    public function __construct($identifier_uri)
+    {
+        if (!Validate::uri($identifier_uri)) {
+            throw new OMB_InvalidParameterException($identifier_uri, 'profile',
+                                                'omb_listenee or omb_listener');
+        }
+        $this->identifier_uri = $identifier_uri;
+        $this->param_array    = false;
+    }
+
+    /**
+     * Return the profile as array
+     *
+     * Returns an array which contains the whole profile as array.
+     * The array is cached and only rebuilt on changes of the profile.
+     *
+     * @param string $prefix    The common prefix to the key for all parameters
+     * @param bool   $force_all Specifies whether empty fields should be added
+     *                          to the array as well; This is necessary to
+     *                          clear fields via updateProfile
+     *
+     * @access public
+     *
+     * @return array The profile as parameter array
+     */
+    public function asParameters($prefix, $force_all = false)
+    {
+        if ($this->param_array === false) {
+            $this->param_array = array('' => $this->identifier_uri);
+
+            if ($force_all || !is_null($this->profile_url)) {
+                $this->param_array['_profile'] = $this->profile_url;
+            }
+
+            if ($force_all || !is_null($this->homepage)) {
+                $this->param_array['_homepage'] = $this->homepage;
+            }
+
+            if ($force_all || !is_null($this->nickname)) {
+                $this->param_array['_nickname'] = $this->nickname;
+            }
+
+            if ($force_all || !is_null($this->license_url)) {
+                $this->param_array['_license'] = $this->license_url;
+            }
+
+            if ($force_all || !is_null($this->fullname)) {
+                $this->param_array['_fullname'] = $this->fullname;
+            }
+
+            if ($force_all || !is_null($this->bio)) {
+                $this->param_array['_bio'] = $this->bio;
+            }
+
+            if ($force_all || !is_null($this->location)) {
+                $this->param_array['_location'] = $this->location;
+            }
+
+            if ($force_all || !is_null($this->avatar_url)) {
+                $this->param_array['_avatar'] = $this->avatar_url;
+            }
+
+        }
+        $ret = array();
+        foreach ($this->param_array as $k => $v) {
+            $ret[$prefix . $k] = $v;
+        }
+        return $ret;
+    }
+
+    /**
+     * Build an OMB_Profile object from array
+     *
+     * Builds an OMB_Profile object from the passed parameters array. The
+     * array MUST provide a profile URI. The array fields HAVE TO be named
+     * according to the OMB standard. The prefix (omb_listener or omb_listenee)
+     * is passed as a parameter.
+     *
+     * @param string $parameters An array containing the profile parameters
+     * @param string $prefix     The common prefix of the profile parameter keys
+     *
+     * @access public
+     *
+     * @returns OMB_Profile The built OMB_Profile
+     */
+    public static function fromParameters($parameters, $prefix)
+    {
+        if (!isset($parameters[$prefix])) {
+            throw new OMB_InvalidParameterException('', 'profile', $prefix);
+        }
+
+        $profile = new OMB_Profile($parameters[$prefix]);
+        $profile->updateFromParameters($parameters, $prefix);
+        return $profile;
+    }
+
+    /**
+     * Update from array
+     *
+     * Updates from the passed parameters array. The array does not have to
+     * provide a profile URI. The array fields HAVE TO be named according to the
+     * OMB standard. The prefix (omb_listener or omb_listenee) is passed as a
+     * parameter.
+     *
+     * @param string $parameters An array containing the profile parameters
+     * @param string $prefix     The common prefix of the profile parameter keys
+     *
+     * @access public
+     */
+    public function updateFromParameters($parameters, $prefix)
+    {
+        if (isset($parameters[$prefix.'_profile'])) {
+            $this->setProfileURL($parameters[$prefix.'_profile']);
+        }
+
+        if (isset($parameters[$prefix.'_license'])) {
+            $this->setLicenseURL($parameters[$prefix.'_license']);
+        }
+
+        if (isset($parameters[$prefix.'_nickname'])) {
+            $this->setNickname($parameters[$prefix.'_nickname']);
+        }
+
+        if (isset($parameters[$prefix.'_fullname'])) {
+            $this->setFullname($parameters[$prefix.'_fullname']);
+        }
+
+        if (isset($parameters[$prefix.'_homepage'])) {
+            $this->setHomepage($parameters[$prefix.'_homepage']);
+        }
+
+        if (isset($parameters[$prefix.'_bio'])) {
+            $this->setBio($parameters[$prefix.'_bio']);
+        }
+
+        if (isset($parameters[$prefix.'_location'])) {
+            $this->setLocation($parameters[$prefix.'_location']);
+        }
+
+        if (isset($parameters[$prefix.'_avatar'])) {
+            $this->setAvatarURL($parameters[$prefix.'_avatar']);
+        }
+    }
+
+    public function getIdentifierURI()
+    {
+        return $this->identifier_uri;
+    }
+
+    public function getProfileURL()
+    {
+        return $this->profile_url;
+    }
+
+    public function getHomepage()
+    {
+        return $this->homepage;
+    }
+
+    public function getNickname()
+    {
+        return $this->nickname;
+    }
+
+    public function getLicenseURL()
+    {
+        return $this->license_url;
+    }
+
+    public function getFullname()
+    {
+        return $this->fullname;
+    }
+
+    public function getBio()
+    {
+        return $this->bio;
+    }
+
+    public function getLocation()
+    {
+        return $this->location;
+    }
+
+    public function getAvatarURL()
+    {
+        return $this->avatar_url;
+    }
+
+    public function setProfileURL($profile_url)
+    {
+        $this->setVal('profile', $profile_url, 'OMB_Helper::validateURL',
+                      'profile_url');
+    }
+
+    public function setNickname($nickname)
+    {
+        $this->setVal('nickname', $nickname, 'OMB_Profile::validateNickname',
+                      'nickname', true);
+    }
+
+    public function setLicenseURL($license_url)
+    {
+        $this->setVal('license', $license_url, 'OMB_Helper::validateURL',
+                      'license_url');
+    }
+
+    public function setFullname($fullname)
+    {
+        $this->setVal('fullname', $fullname, 'OMB_Profile::validate255');
+    }
+
+    public function setHomepage($homepage)
+    {
+        $this->setVal('homepage', $homepage, 'OMB_Helper::validateURL');
+    }
+
+    public function setBio($bio)
+    {
+        $this->setVal('bio', $bio, 'OMB_Profile::validate140');
+    }
+
+    public function setLocation($location)
+    {
+        $this->setVal('location', $location, 'OMB_Profile::validate255');
+    }
+
+    public function setAvatarURL($avatar_url)
+    {
+        $this->setVal('avatar', $avatar_url, 'OMB_Helper::validateURL',
+                      'avatar_url');
+    }
+
+    protected static function validate255($str)
+    {
+        return Validate::string($str, array('max_length' => 255));
+    }
+
+    protected static function validate140($str)
+    {
+        return Validate::string($str, array('max_length' => 140));
+    }
+
+    protected static function validateNickname($str)
+    {
+        return Validate::string($str,
+                              array('min_length' => 1,
+                                    'max_length' => 64,
+                                    'format' => VALIDATE_NUM . VALIDATE_ALPHA));
+    }
+
+    /**
+     * Set a value
+     *
+     * Updates a value specified by a parameter name and the new value.
+     *
+     * @param string   $param     The parameter name according to OMB
+     * @param string   $value     The new value
+     * @param callback $validator A validator function for the parameter
+     * @param string   $field     The name of the field in OMB_Profile
+     * @param bool     $force     Whether null values should be checked as well
+     */
+    protected function setVal($param, $value, $validator, $field = null,
+                              $force = false)
+    {
+        if (is_null($field)) {
+            $field = $param;
+        }
+        if ($value === '' && !$force) {
+            $value = null;
+        } elseif (!call_user_func($validator, $value)) {
+            throw new OMB_InvalidParameterException($value, 'profile', $param);
+        }
+        if ($this->$field !== $value) {
+            $this->$field      = $value;
+            $this->param_array = false;
+        }
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/remoteserviceexception.php b/plugins/OMB/extlib/libomb/remoteserviceexception.php
new file mode 100755 (executable)
index 0000000..f8341e8
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+/**
+ * Exception stating that the remote service had a failure
+ *
+ * This exception is raised when a remote service failed to return a valid
+ * response to a request or send a valid request.
+ */
+class OMB_RemoteServiceException extends Exception
+{
+    /**
+     * Create exception from Yadis response
+     *
+     * Creates an exception from a passed yadis result.
+     *
+     * @param string                  $request_uri The target URI for the failed
+     *                                             request
+     * @param Auth_Yadis_HTTPResponse $result      The result of the failed
+     *                                             request
+     *
+     * @return OMB_RemoteServiceException A new exception
+     */
+    public static function fromYadis($request_uri, $result)
+    {
+        if ($result->status == 200) {
+            $err = 'Got wrong response ' . $result->body;
+        } else {
+            $err = 'Got error code ' . $result->status . ' with response ' .
+                   $result->body;
+        }
+        return OMB_RemoteServiceException::forRequest($request_uri, $err);
+    }
+
+    /**
+     * Create exception for a call to a resource
+     *
+     * Creates an exception for a given error message and target URI.
+     *
+     * @param string $action_uri The target URI for the failed request
+     * @param string $failure    An error message
+     *
+     * @return OMB_RemoteServiceException A new exception
+     */
+    public static function forRequest($action_uri, $failure)
+    {
+        return new OMB_RemoteServiceException("Handler for $action_uri: $failure");
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/service_consumer.php b/plugins/OMB/extlib/libomb/service_consumer.php
new file mode 100755 (executable)
index 0000000..33ebccc
--- /dev/null
@@ -0,0 +1,461 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'Validate.php';
+require_once 'Auth/Yadis/Yadis.php';
+require_once 'OAuth.php';
+require_once 'constants.php';
+require_once 'helper.php';
+require_once 'omb_yadis_xrds.php';
+require_once 'profile.php';
+require_once 'remoteserviceexception.php';
+require_once 'unsupportedserviceexception.php';
+
+/**
+ * OMB service representation
+ *
+ * This class represents a complete remote OMB service. It provides discovery
+ * and execution of the service’s methods.
+ */
+class OMB_Service_Consumer
+{
+    protected $url; /* The service URL */
+    protected $services; /* An array of strings mapping service URI to
+                            service URL */
+
+    protected $token; /* An OAuthToken */
+
+    protected $listener_uri; /* The URI identifying the listener, i. e. the
+                                remote user. */
+
+    protected $listenee_uri; /* The URI identifying the listenee, i. e. the
+                                local user during an auth request. */
+
+    /**
+     * According to OAuth Core 1.0, an user authorization request is no
+     * full-blown OAuth request. nonce, timestamp, consumer_key and signature
+     * are not needed in this step. See http://laconi.ca/trac/ticket/827 for
+     * more informations.
+     *
+     * Since Laconica up to version 0.7.2 performs a full OAuth request check, a
+     * correct request would fail.
+     */
+    public $performLegacyAuthRequest = true;
+
+    /* Helper stuff we are going to need. */
+    protected $fetcher;
+    protected $oauth_consumer;
+    protected $datastore;
+
+    /**
+     * Constructor for OMB_Service_Consumer
+     *
+     * Initializes an OMB_Service_Consumer object representing the OMB service
+     * specified by $service_url. Performs a complete service discovery using
+     * Yadis.
+     * Throws OMB_UnsupportedServiceException if XRDS file does not specify a
+     * complete OMB service.
+     *
+     * @param string        $service_url  The URL of the service
+     * @param string        $consumer_url An URL representing the consumer
+     * @param OMB_Datastore $datastore    An instance of a class implementing
+     *                                    OMB_Datastore
+     *
+     * @access public
+     */
+    public function __construct ($service_url, $consumer_url, $datastore)
+    {
+        $this->url            = $service_url;
+        $this->fetcher        = Auth_Yadis_Yadis::getHTTPFetcher();
+        $this->datastore      = $datastore;
+        $this->oauth_consumer = new OAuthConsumer($consumer_url, '');
+
+        $xrds = OMB_Yadis_XRDS::fromYadisURL($service_url, $this->fetcher);
+
+        /* Detect our services. This performs a validation as well, since
+            getService und getXRD throw exceptions on failure. */
+        $this->services = array();
+
+        foreach (array(OAUTH_DISCOVERY => OMB_Helper::$OAUTH_SERVICES,
+                       OMB_VERSION     => OMB_Helper::$OMB_SERVICES)
+                 as    $service_root   => $targetservices) {
+            $uris = $xrds->getService($service_root)->getURIs();
+            $xrd  = $xrds->getXRD($uris[0]);
+            foreach ($targetservices as $targetservice) {
+                $yadis_service = $xrd->getService($targetservice);
+                if ($targetservice == OAUTH_ENDPOINT_REQUEST) {
+                        $localid            =
+                                   $yadis_service->getElements('xrd:LocalID');
+                        $this->listener_uri =
+                                   $yadis_service->parser->content($localid[0]);
+                }
+                $uris                           = $yadis_service->getURIs();
+                $this->services[$targetservice] = $uris[0];
+            }
+        }
+    }
+
+    /**
+     * Get the handler URI for a service
+     *
+     * Returns the URI the remote web service has specified for the given
+     * service.
+     *
+     * @param string $service The URI identifying the service
+     *
+     * @access public
+     *
+     * @return string The service handler URI
+     */
+    public function getServiceURI($service)
+    {
+        return $this->services[$service];
+    }
+
+    /**
+     * Get the remote user’s URI
+     *
+     * Returns the URI of the remote user, i. e. the listener.
+     *
+     * @access public
+     *
+     * @return string The remote user’s URI
+     */
+    public function getRemoteUserURI()
+    {
+        return $this->listener_uri;
+    }
+
+    /**
+     * Get the listenee’s URI
+     *
+     * Returns the URI of the user being subscribed to, i. e. the local user.
+     *
+     * @access public
+     *
+     * @return string The local user’s URI
+     */
+    public function getListeneeURI()
+    {
+        return $this->listenee_uri;
+    }
+
+    /**
+     * Request a request token
+     *
+     * Performs a token request on the service. Returns an OAuthToken on success.
+     * Throws an exception if the request fails.
+     *
+     * @access public
+     *
+     * @return OAuthToken An unauthorized request token
+     */
+    public function requestToken()
+    {
+        /* Set the token to null just in case the user called setToken. */
+        $this->token = null;
+
+        $result = $this->performAction(OAUTH_ENDPOINT_REQUEST,
+                                       array('omb_listener' => $this->listener_uri));
+        if ($result->status != 200) {
+            throw OMB_RemoteServiceException::fromYadis(OAUTH_ENDPOINT_REQUEST,
+                                                        $result);
+        }
+        parse_str($result->body, $return);
+        if (!isset($return['oauth_token']) ||
+            !isset($return['oauth_token_secret'])) {
+            throw OMB_RemoteServiceException::fromYadis(OAUTH_ENDPOINT_REQUEST,
+                                                        $result);
+        }
+        $this->setToken($return['oauth_token'], $return['oauth_token_secret']);
+        return $this->token;
+    }
+
+    /**
+     * Request authorization
+     *
+     * Returns an URL which equals to an authorization request. The end user
+     * should be redirected to this location to perform authorization.
+     * The $finish_url should be a local resource which invokes
+     * OMB_Consumer::finishAuthorization on request.
+     *
+     * @param OMB_Profile $profile    An OMB_Profile object representing the
+     *                                soon-to-be subscribed (i. e. local) user
+     * @param string      $finish_url Target location after successful
+     *                                authorization
+     *
+     * @access public
+     *
+     * @return string An URL representing an authorization request
+     */
+    public function requestAuthorization($profile, $finish_url)
+    {
+        if ($this->performLegacyAuthRequest) {
+            $params                   = $profile->asParameters('omb_listenee',
+                                                               false);
+            $params['omb_listener']   = $this->listener_uri;
+            $params['oauth_callback'] = $finish_url;
+
+            $url = $this->prepareAction(OAUTH_ENDPOINT_AUTHORIZE, $params,
+                                        'GET')->to_url();
+        } else {
+            $params = array('oauth_callback' => $finish_url,
+                            'oauth_token'    => $this->token->key,
+                            'omb_version'    => OMB_VERSION,
+                            'omb_listener'   => $this->listener_uri);
+
+            $params = array_merge($profile->asParameters('omb_listenee', false),
+                                  $params);
+
+            /* Build result URL. */
+            $url = $this->services[OAUTH_ENDPOINT_AUTHORIZE] .
+                   (strrpos($url, '?') === false ? '?' : '&');
+            foreach ($params as $k => $v) {
+                $url .= OAuthUtil::urlencode_rfc3986($k) . '=' .
+                        OAuthUtil::urlencode_rfc3986($v) . '&';
+            }
+        }
+
+        $this->listenee_uri = $profile->getIdentifierURI();
+
+        return $url;
+    }
+
+    /**
+     * Finish authorization
+     *
+     * Finish the subscription process by converting the received and authorized
+     * request token into an access token. After that, the subscriber’s profile
+     * and the subscription are stored in the database.
+     * Expects an OAuthRequest in query parameters.
+     * Throws exceptions on failure.
+     *
+     * @access public
+     */
+    public function finishAuthorization()
+    {
+        OMB_Helper::removeMagicQuotesFromRequest();
+        $req = OAuthRequest::from_request();
+        if ($req->get_parameter('oauth_token') != $this->token->key) {
+            /* That’s not the token I wanted to get authorized. */
+            throw new OAuthException('The authorized token does not equal ' .
+                                     'the submitted token.');
+        }
+
+        if ($req->get_parameter('omb_version') != OMB_VERSION) {
+            throw new OMB_RemoteServiceException('The remote service uses an ' .
+                                                 'unsupported OMB version');
+        }
+
+        /* Construct the profile to validate it. */
+
+        /* Fix OMB bug. Listener URI is not passed. */
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+            $params = $_POST;
+        } else {
+            $params = $_GET;
+        }
+        $params['omb_listener'] = $this->listener_uri;
+
+        $listener = OMB_Profile::fromParameters($params, 'omb_listener');
+
+        /* Ask the remote service to convert the authorized request token into
+           an access token. */
+
+        $result = $this->performAction(OAUTH_ENDPOINT_ACCESS, array());
+        if ($result->status != 200) {
+            throw new OAuthException('Could not get access token');
+        }
+
+        parse_str($result->body, $return);
+        if (!isset($return['oauth_token']) ||
+            !isset($return['oauth_token_secret'])) {
+            throw new OAuthException('Could not get access token');
+        }
+        $this->setToken($return['oauth_token'], $return['oauth_token_secret']);
+
+        /* Subscription is finished and valid. Now store the new subscriber and
+           the subscription in the database. */
+
+        $this->datastore->saveProfile($listener);
+        $this->datastore->saveSubscription($this->listener_uri,
+                                           $this->listenee_uri,
+                                           $this->token);
+    }
+
+    /**
+     * Return the URI identifying the listener
+     *
+     * Returns the URI for the OMB user who tries to subscribe or already has
+     * subscribed our user. This method is a workaround for a serious OMB flaw:
+     * The Listener URI is not passed in the finishauthorization call.
+     *
+     * @access public
+     *
+     * @return string the listener’s URI
+     */
+    public function getListenerURI()
+    {
+        return $this->listener_uri;
+    }
+
+    /**
+     * Inform the service about a profile update
+     *
+     * Sends an updated profile to the service.
+     *
+     * @param OMB_Profile $profile The profile that has changed
+     *
+     * @access public
+     */
+    public function updateProfile($profile)
+    {
+        $params = $profile->asParameters('omb_listenee', true);
+        $this->performOMBAction(OMB_ENDPOINT_UPDATEPROFILE, $params,
+                                $profile->getIdentifierURI());
+    }
+
+    /**
+     * Inform the service about a new notice
+     *
+     * Sends a notice to the service.
+     *
+     * @param OMB_Notice $notice The notice
+     *
+     * @access public
+     */
+    public function postNotice($notice)
+    {
+        $params                 = $notice->asParameters();
+        $params['omb_listenee'] = $notice->getAuthor()->getIdentifierURI();
+        $this->performOMBAction(OMB_ENDPOINT_POSTNOTICE, $params,
+                                $params['omb_listenee']);
+    }
+
+    /**
+     * Set the token member variable
+     *
+     * Initializes the token based on given token and secret token.
+     *
+     * @param string $token  The token
+     * @param string $secret The secret token
+     *
+     * @access public
+     */
+    public function setToken($token, $secret)
+    {
+        $this->token = new OAuthToken($token, $secret);
+    }
+
+    /**
+     * Prepare an OAuthRequest object
+     *
+     * Creates an OAuthRequest object mapping the request specified by the
+     * parameters.
+     *
+     * @param string $action_uri The URI specifying the target service
+     * @param array  $params     Additional parameters for the service call
+     * @param string $method     The HTTP method used to call the service
+     *                           ('POST' or 'GET', usually)
+     *
+     * @access protected
+     *
+     * @return OAuthRequest the prepared request
+     */
+    protected function prepareAction($action_uri, $params, $method)
+    {
+        $url = $this->services[$action_uri];
+
+        $url_params = array();
+        parse_str(parse_url($url, PHP_URL_QUERY), $url_params);
+
+        /* Add OMB version. */
+        $url_params['omb_version'] = OMB_VERSION;
+
+        /* Add user-defined parameters. */
+        $url_params = array_merge($url_params, $params);
+
+        $req = OAuthRequest::from_consumer_and_token($this->oauth_consumer,
+                                                     $this->token, $method,
+                                                     $url, $url_params);
+
+        /* Sign the request. */
+        $req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
+                           $this->oauth_consumer, $this->token);
+
+        return $req;
+    }
+
+    /**
+     * Perform a service call
+     *
+     * Creates an OAuthRequest object and execute the mapped call as POST
+     * request.
+     *
+     * @param string $action_uri The URI specifying the target service
+     * @param array  $params     Additional parameters for the service call
+     *
+     * @access protected
+     *
+     * @return Auth_Yadis_HTTPResponse The POST request response
+     */
+    protected function performAction($action_uri, $params)
+    {
+        $req = $this->prepareAction($action_uri, $params, 'POST');
+
+        /* Return result page. */
+        return $this->fetcher->post($req->get_normalized_http_url(),
+                                    $req->to_postdata(), array());
+    }
+
+    /**
+     * Perform an OMB action
+     *
+     * Executes an OMB action – as of OMB 0.1, it’s one of updateProfile and
+     * postNotice.
+     *
+     * @param string $action_uri   The URI specifying the target service
+     * @param array  $params       Additional parameters for the service call
+     * @param string $listenee_uri The URI identifying the local user for whom
+     *                             the action is performed
+     *
+     * @access protected
+     */
+    protected function performOMBAction($action_uri, $params, $listenee_uri)
+    {
+        $result = $this->performAction($action_uri, $params);
+        if ($result->status == 403) {
+            /* The remote user unsubscribed us. */
+            $this->datastore->deleteSubscription($this->listener_uri,
+                                                 $listenee_uri);
+        } else if ($result->status != 200 ||
+                   strpos($result->body, 'omb_version=' . OMB_VERSION) === false) {
+            /* The server signaled an error or sent an incorrect response. */
+            throw OMB_RemoteServiceException::fromYadis($action_uri, $result);
+        }
+    }
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/service_provider.php b/plugins/OMB/extlib/libomb/service_provider.php
new file mode 100755 (executable)
index 0000000..9a1a488
--- /dev/null
@@ -0,0 +1,461 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+require_once 'constants.php';
+require_once 'helper.php';
+require_once 'notice.php';
+require_once 'remoteserviceexception.php';
+
+/**
+ * OMB service realization
+ *
+ * This class realizes a complete, simple OMB service.
+ */
+class OMB_Service_Provider
+{
+    protected $user; /* An OMB_Profile representing the user */
+    protected $datastore; /* AN OMB_Datastore */
+
+    protected $remote_user; /* An OMB_Profile representing the remote user
+                               during the authorization process */
+
+    protected $oauth_server; /* An OAuthServer; should only be accessed via
+                                getOAuthServer. */
+
+    /**
+     * Initialize an OMB_Service_Provider object
+     *
+     * Constructs an OMB_Service_Provider instance that provides OMB services
+     * referring to a particular user.
+     *
+     * @param OMB_Profile   $user         An OMB_Profile; mandatory for XRDS
+     *                                    output, user auth handling and OMB
+     *                                    action performing
+     * @param OMB_Datastore $datastore    An OMB_Datastore; mandatory for
+     *                                    everything but XRDS output
+     * @param OAuthServer   $oauth_server An OAuthServer; used for token writing
+     *                                    and OMB action handling; will use
+     *                                    default value if not set
+     *
+     * @access public
+     */
+    public function __construct ($user = null, $datastore = null,
+                                 $oauth_server = null)
+    {
+        $this->user         = $user;
+        $this->datastore    = $datastore;
+        $this->oauth_server = $oauth_server;
+    }
+
+    /**
+     * Return the remote user during user authorization
+     *
+     * Returns an OMB_Profile representing the remote user during the user
+     * authorization request.
+     *
+     * @return OMB_Profile The remote user
+     */
+    public function getRemoteUser()
+    {
+        return $this->remote_user;
+    }
+
+    /**
+     * Write a XRDS document
+     *
+     * Writes a XRDS document specifying the OMB service. Optionally uses a
+     * given object of a class implementing OMB_XRDS_Writer for output. Else
+     * OMB_Plain_XRDS_Writer is used.
+     *
+     * @param OMB_XRDS_Mapper $xrds_mapper An object mapping actions to URLs
+     * @param OMB_XRDS_Writer $xrds_writer Optional; The OMB_XRDS_Writer used to
+     *                                     write the XRDS document
+     *
+     * @access public
+     *
+     * @return mixed Depends on the used OMB_XRDS_Writer; OMB_Plain_XRDS_Writer
+     *               returns nothing.
+     */
+    public function writeXRDS($xrds_mapper, $xrds_writer = null)
+    {
+        if ($xrds_writer == null) {
+                require_once 'plain_xrds_writer.php';
+                $xrds_writer = new OMB_Plain_XRDS_Writer();
+        }
+        return $xrds_writer->writeXRDS($this->user, $xrds_mapper);
+    }
+
+    /**
+     * Echo a request token
+     *
+     * Outputs an unauthorized request token for the query found in $_GET or
+     * $_POST.
+     *
+     * @access public
+     */
+    public function writeRequestToken()
+    {
+        OMB_Helper::removeMagicQuotesFromRequest();
+        echo $this->getOAuthServer()->fetch_request_token(
+                                                  OAuthRequest::from_request());
+    }
+
+    /**
+     * Handle an user authorization request.
+     *
+     * Parses an authorization request. This includes OAuth and OMB
+     * verification.
+     * Throws exceptions on failures. Returns an OMB_Profile object representing
+     * the remote user.
+     *
+     * The OMB_Profile passed to the constructor of OMB_Service_Provider should
+     * not represent the user specified in the authorization request, but the
+     * one currently logged in to the service. This condition being satisfied,
+     * handleUserAuth will check whether the listener specified in the request
+     * is identical to the logged in user.
+     *
+     * @access public
+     *
+     * @return OMB_Profile The profile of the soon-to-be subscribed, i. e.
+     *                     remote user
+     */
+    public function handleUserAuth()
+    {
+        OMB_Helper::removeMagicQuotesFromRequest();
+
+        /* Verify the request token. */
+
+        $this->token = $this->datastore->lookup_token(null, "request",
+                                                      $_GET['oauth_token']);
+        if (is_null($this->token)) {
+            throw new OAuthException('The given request token has not been ' .
+                                     'issued by this service.');
+        }
+
+        /* Verify the OMB part. */
+
+        if ($_GET['omb_version'] !== OMB_VERSION) {
+            throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE,
+                                                         'Wrong OMB version ' .
+                                                         $_GET['omb_version']);
+        }
+
+        if ($_GET['omb_listener'] !== $this->user->getIdentifierURI()) {
+            throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE,
+                                                         'Wrong OMB listener ' .
+                                                         $_GET['omb_listener']);
+        }
+
+        foreach (array('omb_listenee', 'omb_listenee_profile',
+                       'omb_listenee_nickname', 'omb_listenee_license') as $param) {
+            if (!isset($_GET[$param]) || is_null($_GET[$param])) {
+                throw OMB_RemoteServiceException::forRequest(
+                                       OAUTH_ENDPOINT_AUTHORIZE,
+                                       "Required parameter '$param' not found");
+            }
+        }
+
+        /* Store given callback for later use. */
+        if (isset($_GET['oauth_callback']) && $_GET['oauth_callback'] !== '') {
+            $this->callback = $_GET['oauth_callback'];
+            if (!OMB_Helper::validateURL($this->callback)) {
+                throw OMB_RemoteServiceException::forRequest(
+                                        OAUTH_ENDPOINT_AUTHORIZE,
+                                        'Invalid callback URL specified');
+            }
+        }
+        $this->remote_user = OMB_Profile::fromParameters($_GET, 'omb_listenee');
+
+        return $this->remote_user;
+    }
+
+    /**
+     * Continue the OAuth dance after user authorization
+     *
+     * Performs the appropriate actions after user answered the authorization
+     * request.
+     *
+     * @param bool $accepted Whether the user granted authorization
+     *
+     * @access public
+     *
+     * @return array A two-component array with the values:
+     *                 - callback The callback URL or null if none given
+     *                 - token    The authorized request token or null if not
+     *                            authorized.
+     */
+    public function continueUserAuth($accepted)
+    {
+        $callback = $this->callback;
+        if (!$accepted) {
+            $this->datastore->revoke_token($this->token->key);
+            $this->token = null;
+
+        } else {
+            $this->datastore->authorize_token($this->token->key);
+            $this->datastore->saveProfile($this->remote_user);
+            $this->datastore->saveSubscription($this->user->getIdentifierURI(),
+                                         $this->remote_user->getIdentifierURI(),
+                                         $this->token);
+
+            if (!is_null($this->callback)) {
+                /* Callback wants to get some informations as well. */
+                $params = $this->user->asParameters('omb_listener', false);
+
+                $params['oauth_token'] = $this->token->key;
+                $params['omb_version'] = OMB_VERSION;
+
+                $callback .= (parse_url($this->callback, PHP_URL_QUERY) ? '&' : '?');
+                foreach ($params as $k => $v) {
+                    $callback .= OAuthUtil::urlencode_rfc3986($k) . '=' .
+                                 OAuthUtil::urlencode_rfc3986($v) . '&';
+                }
+            }
+        }
+        return array($callback, $this->token);
+    }
+
+    /**
+     * Echo an access token
+     *
+     * Outputs an access token for the query found in $_POST. OMB 0.1 specifies
+     * that the access token request has to be a POST even if OAuth allows GET
+     * as well.
+     *
+     * @access public
+     */
+    public function writeAccessToken()
+    {
+        OMB_Helper::removeMagicQuotesFromRequest();
+        echo $this->getOAuthServer()->fetch_access_token(
+                                            OAuthRequest::from_request('POST'));
+    }
+
+    /**
+     * Handle an updateprofile request
+     *
+     * Handles an updateprofile request posted to this service. Updates the
+     * profile through the OMB_Datastore.
+     *
+     * @access public
+     *
+     * @return OMB_Profile The updated profile
+     */
+    public function handleUpdateProfile()
+    {
+        list($req, $profile) = $this->handleOMBRequest(OMB_ENDPOINT_UPDATEPROFILE);
+        $profile->updateFromParameters($req->get_parameters(), 'omb_listenee');
+        $this->datastore->saveProfile($profile);
+        $this->finishOMBRequest();
+        return $profile;
+    }
+
+    /**
+     * Handle a postnotice request
+     *
+     * Handles a postnotice request posted to this service. Saves the notice
+     * through the OMB_Datastore.
+     *
+     * @access public
+     *
+     * @return OMB_Notice The received notice
+     */
+    public function handlePostNotice()
+    {
+        list($req, $profile) = $this->handleOMBRequest(OMB_ENDPOINT_POSTNOTICE);
+
+        $notice = OMB_Notice::fromParameters($profile, $req->get_parameters());
+        $this->datastore->saveNotice($notice);
+        $this->finishOMBRequest();
+
+        return $notice;
+    }
+
+    /**
+     * Handle an OMB request
+     *
+     * Performs common OMB request handling.
+     *
+     * @param string $uri The URI defining the OMB endpoint being served
+     *
+     * @access protected
+     *
+     * @return array(OAuthRequest, OMB_Profile)
+     */
+    protected function handleOMBRequest($uri)
+    {
+        OMB_Helper::removeMagicQuotesFromRequest();
+        $req      = OAuthRequest::from_request('POST');
+        $listenee = $req->get_parameter('omb_listenee');
+
+        try {
+            list($consumer, $token) = $this->getOAuthServer()->verify_request($req);
+        } catch (OAuthException $e) {
+            header('HTTP/1.1 403 Forbidden');
+            throw OMB_RemoteServiceException::forRequest($uri,
+                                       'Revoked accesstoken for ' . $listenee);
+        }
+
+        $version = $req->get_parameter('omb_version');
+        if ($version !== OMB_VERSION) {
+            header('HTTP/1.1 400 Bad Request');
+            throw OMB_RemoteServiceException::forRequest($uri,
+                                               'Wrong OMB version ' . $version);
+        }
+
+        $profile = $this->datastore->getProfile($listenee);
+        if (is_null($profile)) {
+            header('HTTP/1.1 400 Bad Request');
+            throw OMB_RemoteServiceException::forRequest($uri,
+                                         'Unknown remote profile ' . $listenee);
+        }
+
+        $subscribers = $this->datastore->getSubscriptions($listenee);
+        if (count($subscribers) === 0) {
+            header('HTTP/1.1 403 Forbidden');
+            throw OMB_RemoteServiceException::forRequest($uri,
+                                              'No subscriber for ' . $listenee);
+        }
+
+        return array($req, $profile);
+    }
+
+    /**
+     * Finishes an OMB request handling
+     *
+     * Performs common OMB request handling finishing.
+     *
+     * @access protected
+     */
+    protected function finishOMBRequest()
+    {
+        header('HTTP/1.1 200 OK');
+        header('Content-type: text/plain');
+        /* There should be no clutter but the version. */
+        echo "omb_version=" . OMB_VERSION;
+    }
+
+    /**
+     * Return an OAuthServer
+     *
+     * Checks whether the OAuthServer is null. If so, initializes it with a
+     * default value. Returns the OAuth server.
+     *
+     * @access protected
+     */
+    protected function getOAuthServer()
+    {
+        if (is_null($this->oauth_server)) {
+            $this->oauth_server = new OAuthServer($this->datastore);
+            $this->oauth_server->add_signature_method(
+                                          new OAuthSignatureMethod_HMAC_SHA1());
+        }
+        return $this->oauth_server;
+    }
+
+    /**
+     * Publish a notice
+     *
+     * Posts an OMB notice. This includes storing the notice and posting it to
+     * subscribed users.
+     *
+     * @param OMB_Notice $notice The new notice
+     *
+     * @access public
+     *
+     * @return array An array mapping subscriber URIs to the exception posting
+     *               to them has raised; Empty array if no exception occured
+     */
+    public function postNotice($notice)
+    {
+        $uri = $this->user->getIdentifierURI();
+
+        /* $notice is passed by reference and may change. */
+        $this->datastore->saveNotice($notice);
+        $subscribers = $this->datastore->getSubscriptions($uri);
+
+        /* No one to post to. */
+        if (is_null($subscribers)) {
+            return array();
+        }
+
+        require_once 'service_consumer.php';
+
+        $err = array();
+        foreach ($subscribers as $subscriber) {
+            try {
+                $service = new OMB_Service_Consumer($subscriber['uri'], $uri,
+                                                    $this->datastore);
+                $service->setToken($subscriber['token'], $subscriber['secret']);
+                $service->postNotice($notice);
+            } catch (Exception $e) {
+                $err[$subscriber['uri']] = $e;
+                continue;
+            }
+        }
+        return $err;
+    }
+
+    /**
+     * Publish a profile update
+     *
+     * Posts the current profile as an OMB profile update. This includes
+     * updating the stored profile and posting it to subscribed users.
+     *
+     * @access public
+     *
+     * @return array An array mapping subscriber URIs to the exception posting
+     *               to them has raised; Empty array if no exception occured
+     */
+    public function updateProfile()
+    {
+        $uri = $this->user->getIdentifierURI();
+
+        $this->datastore->saveProfile($this->user);
+        $subscribers = $this->datastore->getSubscriptions($uri);
+
+        /* No one to post to. */
+        if (is_null($subscribers)) {
+                return array();
+        }
+
+        require_once 'service_consumer.php';
+
+        $err = array();
+        foreach ($subscribers as $subscriber) {
+            try {
+                $service = new OMB_Service_Consumer($subscriber['uri'], $uri,
+                                                    $this->datastore);
+                $service->setToken($subscriber['token'], $subscriber['secret']);
+                $service->updateProfile($this->user);
+            } catch (Exception $e) {
+                $err[$subscriber['uri']] = $e;
+                continue;
+            }
+        }
+        return $err;
+    }
+}
diff --git a/plugins/OMB/extlib/libomb/unsupportedserviceexception.php b/plugins/OMB/extlib/libomb/unsupportedserviceexception.php
new file mode 100755 (executable)
index 0000000..be30a1f
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+/**
+ * Exception stating that a requested service is not available
+ *
+ * This exception is raised when OMB_Service is asked to call a service the
+ * remote server does not provide.
+ */
+class OMB_UnsupportedServiceException extends Exception
+{
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/xrds_mapper.php b/plugins/OMB/extlib/libomb/xrds_mapper.php
new file mode 100755 (executable)
index 0000000..8fbe652
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+/**
+ * Map XRDS actions to URLs
+ *
+ * This interface specifies classes which write the XRDS file announcing
+ * the OMB server. An instance of an implementing class should be passed to
+ * OMB_Service_Provider->writeXRDS.
+ */
+interface OMB_XRDS_Mapper
+{
+    /**
+     * Fetch an URL for a specified action
+     *
+     * Returns the action URL for an action specified by the endpoint URI.
+     *
+     * @param string $action The endpoint URI
+     *
+     * @return string The action URL
+     */
+    public function getURL($action);
+}
+?>
diff --git a/plugins/OMB/extlib/libomb/xrds_writer.php b/plugins/OMB/extlib/libomb/xrds_writer.php
new file mode 100755 (executable)
index 0000000..c7939d6
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * This file is part of libomb
+ *
+ * PHP version 5
+ *
+ * LICENSE: 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 OMB
+ * @author  Adrian Lang <mail@adrianlang.de>
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
+ * @version 0.1a-20090828
+ * @link    http://adrianlang.de/libomb
+ */
+
+/**
+ * Write OMB-specific XRDS
+ *
+ * This interface specifies classes which write the XRDS file announcing
+ * the OMB server. An instance of an implementing class should be passed to
+ * OMB_Service_Provider->writeXRDS.
+ */
+interface OMB_XRDS_Writer
+{
+    /**
+     * Write XRDS
+     *
+     * Outputs a XRDS document specifying an OMB service.
+     *
+     * @param OMB_profile     $user   The target user for the OMB service
+     * @param OMB_XRDS_Mapper $mapper An OMB_XRDS_Mapper providing endpoint URLs
+     */
+    public function writeXRDS($user, $mapper);
+}
+?>
diff --git a/plugins/OMB/lib/omb.php b/plugins/OMB/lib/omb.php
new file mode 100644 (file)
index 0000000..0804b65
--- /dev/null
@@ -0,0 +1,236 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+$dir = dirname(__FILE__);
+
+require_once $dir . '/omboauthstore.php';
+require_once $dir . '/../extlib/libomb/constants.php';
+require_once $dir . '/../extlib/libomb/service_consumer.php';
+require_once $dir . '/../extlib/libomb/notice.php';
+require_once $dir . '/../extlib/libomb/profile.php';
+require_once INSTALLDIR . '/extlib/Auth/Yadis/Yadis.php';
+
+function omb_oauth_consumer()
+{
+    // Don't try to make this static. Leads to issues in
+    // multi-site setups - Z
+    return new OAuthConsumer(common_root_url(), '');
+}
+
+function omb_oauth_server()
+{
+    static $server = null;
+    if (is_null($server)) {
+        $server = new OAuthServer(omb_oauth_datastore());
+        $server->add_signature_method(omb_hmac_sha1());
+    }
+    return $server;
+}
+
+function omb_oauth_datastore()
+{
+    static $store = null;
+    if (is_null($store)) {
+        $store = new OMBOAuthDataStore();
+    }
+    return $store;
+}
+
+function omb_hmac_sha1()
+{
+    static $hmac_method = null;
+    if (is_null($hmac_method)) {
+        $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
+    }
+    return $hmac_method;
+}
+
+function omb_broadcast_notice($notice)
+{
+    try {
+        $omb_notice = notice_to_omb_notice($notice);
+    } catch (Exception $e) {
+        // @fixme we should clean up or highlight the problem item
+        common_log(LOG_ERR, 'Invalid OMB outgoing notice for notice ' . $notice->id);
+        common_log(LOG_ERR, 'Error status '.$e);
+        return true;
+    }
+
+    /* Get remote users subscribed to this profile. */
+    $rp = new Remote_profile();
+
+    $rp->query('SELECT remote_profile.*, secret, token ' .
+               'FROM subscription JOIN remote_profile ' .
+               'ON subscription.subscriber = remote_profile.id ' .
+               'WHERE subscription.subscribed = ' . $notice->profile_id . ' ');
+
+    $posted = array();
+
+    while ($rp->fetch()) {
+        if (isset($posted[$rp->postnoticeurl])) {
+            /* We already posted to this url. */
+            continue;
+        }
+        common_debug('Posting to ' . $rp->postnoticeurl, __FILE__);
+
+        /* Post notice. */
+        $service = new StatusNet_OMB_Service_Consumer(
+                     array(OMB_ENDPOINT_POSTNOTICE => $rp->postnoticeurl),
+                                                      $rp->uri);
+        try {
+            $service->setToken($rp->token, $rp->secret);
+            $service->postNotice($omb_notice);
+        } catch (Exception $e) {
+            common_log(LOG_ERR, 'Failed posting to ' . $rp->postnoticeurl);
+            common_log(LOG_ERR, 'Error status '.$e);
+            continue;
+        }
+        $posted[$rp->postnoticeurl] = true;
+
+        common_debug('Finished to ' . $rp->postnoticeurl, __FILE__);
+    }
+
+    return true;
+}
+
+function omb_broadcast_profile($profile)
+{
+    $user = User::staticGet('id', $profile->id);
+
+    if (!$user) {
+        return false;
+    }
+
+    $profile = $user->getProfile();
+
+    $omb_profile = profile_to_omb_profile($user->uri, $profile, true);
+
+    /* Get remote users subscribed to this profile. */
+    $rp = new Remote_profile();
+
+    $rp->query('SELECT remote_profile.*, secret, token ' .
+               'FROM subscription JOIN remote_profile ' .
+               'ON subscription.subscriber = remote_profile.id ' .
+               'WHERE subscription.subscribed = ' . $profile->id . ' ');
+
+    $posted = array();
+
+    while ($rp->fetch()) {
+        if (isset($posted[$rp->updateprofileurl])) {
+            /* We already posted to this url. */
+            continue;
+        }
+        common_debug('Posting to ' . $rp->updateprofileurl, __FILE__);
+
+        /* Update profile. */
+        $service = new StatusNet_OMB_Service_Consumer(
+                     array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl),
+                                                      $rp->uri);
+        try {
+            $service->setToken($rp->token, $rp->secret);
+            $service->updateProfile($omb_profile);
+        } catch (Exception $e) {
+            common_log(LOG_ERR, 'Failed posting to ' . $rp->updateprofileurl);
+            common_log(LOG_ERR, 'Error status '.$e);
+            continue;
+        }
+        $posted[$rp->updateprofileurl] = true;
+
+        common_debug('Finished to ' . $rp->updateprofileurl, __FILE__);
+    }
+
+    return;
+}
+
+class StatusNet_OMB_Service_Consumer extends OMB_Service_Consumer {
+    public function __construct($urls, $listener_uri=null)
+    {
+        $this->services       = $urls;
+        $this->datastore      = omb_oauth_datastore();
+        $this->oauth_consumer = omb_oauth_consumer();
+        $this->fetcher        = Auth_Yadis_Yadis::getHTTPFetcher();
+        $this->fetcher->timeout = intval(common_config('omb', 'timeout'));
+        $this->listener_uri   = $listener_uri;
+    }
+
+}
+
+function profile_to_omb_profile($uri, $profile, $force = false)
+{
+    $omb_profile = new OMB_Profile($uri);
+    $omb_profile->setNickname($profile->nickname);
+    $omb_profile->setLicenseURL(common_config('license', 'url'));
+    if (!is_null($profile->fullname)) {
+        $omb_profile->setFullname($profile->fullname);
+    } elseif ($force) {
+        $omb_profile->setFullname('');
+    }
+    if (!is_null($profile->homepage)) {
+        $omb_profile->setHomepage($profile->homepage);
+    } elseif ($force) {
+        $omb_profile->setHomepage('');
+    }
+    if (!is_null($profile->bio)) {
+        $omb_profile->setBio($profile->bio);
+    } elseif ($force) {
+        $omb_profile->setBio('');
+    }
+    if (!is_null($profile->location)) {
+        $omb_profile->setLocation($profile->location);
+    } elseif ($force) {
+        $omb_profile->setLocation('');
+    }
+    if (!is_null($profile->profileurl)) {
+        $omb_profile->setProfileURL($profile->profileurl);
+    } elseif ($force) {
+        $omb_profile->setProfileURL('');
+    }
+
+    $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+    if ($avatar) {
+        $omb_profile->setAvatarURL($avatar->url);
+    } elseif ($force) {
+        $omb_profile->setAvatarURL('');
+    }
+    return $omb_profile;
+}
+
+function notice_to_omb_notice($notice)
+{
+    /* Create an OMB_Notice for $notice. */
+    $user = User::staticGet('id', $notice->profile_id);
+
+    if (!$user) {
+        return null;
+    }
+
+    $profile = $user->getProfile();
+
+    $omb_notice = new OMB_Notice(profile_to_omb_profile($user->uri, $profile),
+                                 $notice->uri,
+                                 $notice->content);
+    $omb_notice->setURL(common_local_url('shownotice', array('notice' =>
+                                                                 $notice->id)));
+    $omb_notice->setLicenseURL(common_config('license', 'url'));
+
+    return $omb_notice;
+}
+
diff --git a/plugins/OMB/lib/omboauthstore.php b/plugins/OMB/lib/omboauthstore.php
new file mode 100644 (file)
index 0000000..c29eeb7
--- /dev/null
@@ -0,0 +1,509 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
+require_once dirname(__FILE__) . '/../extlib/libomb/datastore.php';
+
+// @todo FIXME: Class documentation missing.
+class OMBOAuthDataStore extends OAuthDataStore
+{
+    // We keep a record of who's contacted us
+    function lookup_consumer($consumer_key)
+    {
+        $con = Consumer::staticGet('consumer_key', $consumer_key);
+        if (!$con) {
+            $con = new Consumer();
+            $con->consumer_key = $consumer_key;
+            $con->seed = common_good_rand(16);
+            $con->created = DB_DataObject_Cast::dateTime();
+            if (!$con->insert()) {
+                return null;
+            }
+        }
+        return new OAuthConsumer($con->consumer_key, '');
+    }
+
+    function lookup_token($consumer, $token_type, $token_key)
+    {
+        $t = new Token();
+        if (!is_null($consumer)) {
+            $t->consumer_key = $consumer->key;
+        }
+        $t->tok = $token_key;
+        $t->type = ($token_type == 'access') ? 1 : 0;
+        if ($t->find(true)) {
+            return new OAuthToken($t->tok, $t->secret);
+        } else {
+            return null;
+        }
+    }
+
+    // http://oauth.net/core/1.0/#nonce
+    // "The Consumer SHALL then generate a Nonce value that is unique for
+    // all requests with that timestamp."
+    // XXX: It's not clear why the token is here
+    function lookup_nonce($consumer, $token, $nonce, $timestamp)
+    {
+        $n = new Nonce();
+        $n->consumer_key = $consumer->key;
+        $n->ts = common_sql_date($timestamp);
+        $n->nonce = $nonce;
+        if ($n->find(true)) {
+            return true;
+        } else {
+            $n->created = DB_DataObject_Cast::dateTime();
+            $n->insert();
+            return false;
+        }
+    }
+
+    function new_request_token($consumer)
+    {
+        $t = new Token();
+        $t->consumer_key = $consumer->key;
+        $t->tok = common_good_rand(16);
+        $t->secret = common_good_rand(16);
+        $t->type = 0; // request
+        $t->state = 0; // unauthorized
+        $t->created = DB_DataObject_Cast::dateTime();
+        if (!$t->insert()) {
+            return null;
+        } else {
+            return new OAuthToken($t->tok, $t->secret);
+        }
+    }
+
+    // defined in OAuthDataStore, but not implemented anywhere
+    function fetch_request_token($consumer)
+    {
+        return $this->new_request_token($consumer);
+    }
+
+    function new_access_token($token, $consumer)
+    {
+        common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__);
+        $rt = new Token();
+        $rt->consumer_key = $consumer->key;
+        $rt->tok = $token->key;
+        $rt->type = 0; // request
+        if ($rt->find(true) && $rt->state == 1) { // authorized
+            common_debug('request token found.', __FILE__);
+            $at = new Token();
+            $at->consumer_key = $consumer->key;
+            $at->tok = common_good_rand(16);
+            $at->secret = common_good_rand(16);
+            $at->type = 1; // access
+            $at->created = DB_DataObject_Cast::dateTime();
+            if (!$at->insert()) {
+                $e = $at->_lastError;
+                common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__);
+                return null;
+            } else {
+                common_debug('access token "'.$at->tok.'" inserted', __FILE__);
+                // burn the old one
+                $orig_rt = clone($rt);
+                $rt->state = 2; // used
+                if (!$rt->update($orig_rt)) {
+                    return null;
+                }
+                common_debug('request token "'.$rt->tok.'" updated', __FILE__);
+                // Update subscription
+                // XXX: mixing levels here
+                $sub = Subscription::staticGet('token', $rt->tok);
+                if (!$sub) {
+                    return null;
+                }
+                common_debug('subscription for request token found', __FILE__);
+                $orig_sub = clone($sub);
+                $sub->token = $at->tok;
+                $sub->secret = $at->secret;
+                if (!$sub->update($orig_sub)) {
+                    return null;
+                } else {
+                    common_debug('subscription updated to use access token', __FILE__);
+                    return new OAuthToken($at->tok, $at->secret);
+                }
+            }
+        } else {
+            return null;
+        }
+    }
+
+    // defined in OAuthDataStore, but not implemented anywhere
+    function fetch_access_token($consumer)
+    {
+        return $this->new_access_token($consumer);
+    }
+
+    /**
+     * Revoke specified OAuth token
+     *
+     * Revokes the authorization token specified by $token_key.
+     * Throws exceptions in case of error.
+     *
+     * @param string $token_key The token to be revoked
+     *
+     * @access public
+     **/
+    public function revoke_token($token_key) {
+        $rt = new Token();
+        $rt->tok = $token_key;
+        $rt->type = 0;
+        $rt->state = 0;
+        if (!$rt->find(true)) {
+            throw new Exception('Tried to revoke unknown token');
+        }
+        if (!$rt->delete()) {
+            throw new Exception('Failed to delete revoked token');
+        }
+    }
+
+    /**
+     * Authorize specified OAuth token
+     *
+     * Authorizes the authorization token specified by $token_key.
+     * Throws exceptions in case of error.
+     *
+     * @param string $token_key The token to be authorized
+     *
+     * @access public
+     **/
+    public function authorize_token($token_key) {
+        $rt = new Token();
+        $rt->tok = $token_key;
+        $rt->type = 0;
+        $rt->state = 0;
+        if (!$rt->find(true)) {
+            throw new Exception('Tried to authorize unknown token');
+        }
+        $orig_rt = clone($rt);
+        $rt->state = 1; # Authorized but not used
+        if (!$rt->update($orig_rt)) {
+            throw new Exception('Failed to authorize token');
+        }
+    }
+
+    /**
+     * Get profile by identifying URI
+     *
+     * Returns an OMB_Profile object representing the OMB profile identified by
+     * $identifier_uri.
+     * Returns null if there is no such OMB profile.
+     * Throws exceptions in case of other error.
+     *
+     * @param string $identifier_uri The OMB identifier URI specifying the
+     *                               requested profile
+     *
+     * @access public
+     *
+     * @return OMB_Profile The corresponding profile
+     **/
+    public function getProfile($identifier_uri) {
+        /* getProfile is only used for remote profiles by libomb.
+           @TODO: Make it work with local ones anyway. */
+        $remote = Remote_profile::staticGet('uri', $identifier_uri);
+        if (!$remote) throw new Exception('No such remote profile');
+        $profile = Profile::staticGet('id', $remote->id);
+        if (!$profile) throw new Exception('No profile for remote user');
+
+        require_once dirname(__FILE__) . '/omb.php';
+        return profile_to_omb_profile($identifier_uri, $profile);
+    }
+
+    /**
+     * Save passed profile
+     *
+     * Stores the OMB profile $profile. Overwrites an existing entry.
+     * Throws exceptions in case of error.
+     *
+     * @param OMB_Profile $profile   The OMB profile which should be saved
+     *
+     * @access public
+     **/
+    public function saveProfile($omb_profile) {
+        if (common_profile_url($omb_profile->getNickname()) ==
+                                                $omb_profile->getProfileURL()) {
+            throw new Exception('Not implemented');
+        } else {
+            $remote = Remote_profile::staticGet('uri', $omb_profile->getIdentifierURI());
+
+            if ($remote) {
+                $exists = true;
+                $profile = Profile::staticGet($remote->id);
+                $orig_remote = clone($remote);
+                $orig_profile = clone($profile);
+                // XXX: compare current postNotice and updateProfile URLs to the ones
+                // stored in the DB to avoid (possibly...) above attack
+            } else {
+                $exists = false;
+                $remote = new Remote_profile();
+                $remote->uri = $omb_profile->getIdentifierURI();
+                $profile = new Profile();
+            }
+
+            $profile->nickname = $omb_profile->getNickname();
+            $profile->profileurl = $omb_profile->getProfileURL();
+
+            $fullname = $omb_profile->getFullname();
+            $profile->fullname = is_null($fullname) ? '' : $fullname;
+            $homepage = $omb_profile->getHomepage();
+            $profile->homepage = is_null($homepage) ? '' : $homepage;
+            $bio = $omb_profile->getBio();
+            $profile->bio = is_null($bio) ? '' : $bio;
+            $location = $omb_profile->getLocation();
+            $profile->location = is_null($location) ? '' : $location;
+
+            if ($exists) {
+                $profile->update($orig_profile);
+            } else {
+                $profile->created = DB_DataObject_Cast::dateTime(); # current time
+                $id = $profile->insert();
+                if (!$id) {
+                    // TRANS: Exception thrown when creating a new profile fails in OAuth store.
+                    throw new Exception(_('Error inserting new profile.'));
+                }
+                $remote->id = $id;
+            }
+
+            $avatar_url = $omb_profile->getAvatarURL();
+            if ($avatar_url) {
+                if (!$this->add_avatar($profile, $avatar_url)) {
+                    // TRANS: Exception thrown when creating a new avatar fails in OAuth store.
+                    throw new Exception(_('Error inserting avatar.'));
+                }
+            } else {
+                $avatar = $profile->getOriginalAvatar();
+                if($avatar) $avatar->delete();
+                $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+                if($avatar) $avatar->delete();
+                $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+                if($avatar) $avatar->delete();
+                $avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
+                if($avatar) $avatar->delete();
+            }
+
+            if ($exists) {
+                if (!$remote->update($orig_remote)) {
+                    // TRANS: Exception thrown when updating a remote profile fails in OAuth store.
+                    throw new Exception(_('Error updating remote profile.'));
+                }
+            } else {
+                $remote->created = DB_DataObject_Cast::dateTime(); # current time
+                if (!$remote->insert()) {
+                    // TRANS: Exception thrown when creating a remote profile fails in OAuth store.
+                    throw new Exception(_('Error inserting remote profile.'));
+                }
+            }
+        }
+    }
+
+    function add_avatar($profile, $url)
+    {
+        $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
+        try {
+            copy($url, $temp_filename);
+            $imagefile = new ImageFile($profile->id, $temp_filename);
+            $filename = Avatar::filename($profile->id,
+                                         image_type_to_extension($imagefile->type),
+                                         null,
+                                         common_timestamp());
+            rename($temp_filename, Avatar::path($filename));
+        } catch (Exception $e) {
+            unlink($temp_filename);
+            throw $e;
+        }
+        return $profile->setOriginal($filename);
+    }
+
+    /**
+     * Save passed notice
+     *
+     * Stores the OMB notice $notice. The datastore may change the passed notice.
+     * This might by neccessary for URIs depending on a database key. Note that
+     * it is the user’s duty to present a mechanism for his OMB_Datastore to
+     * appropriately change his OMB_Notice.
+     * Throws exceptions in case of error.
+     *
+     * @param OMB_Notice $notice The OMB notice which should be saved
+     *
+     * @access public
+     **/
+    public function saveNotice(&$omb_notice) {
+        if (Notice::staticGet('uri', $omb_notice->getIdentifierURI())) {
+            // TRANS: Exception thrown when a notice is denied because it has been sent before.
+            throw new Exception(_('Duplicate notice.'));
+        }
+        $author_uri = $omb_notice->getAuthor()->getIdentifierURI();
+        common_log(LOG_DEBUG, $author_uri, __FILE__);
+        $author = Remote_profile::staticGet('uri', $author_uri);
+        if (!$author) {
+            $author = User::staticGet('uri', $author_uri);
+        }
+        if (!$author) {
+            throw new Exception('No such user.');
+        }
+
+        common_log(LOG_DEBUG, print_r($author, true), __FILE__);
+
+        $notice = Notice::saveNew($author->id,
+                                  $omb_notice->getContent(),
+                                  'omb',
+                                  array('is_local' => Notice::REMOTE,
+                                        'uri' => $omb_notice->getIdentifierURI()));
+
+    }
+
+    /**
+     * Get subscriptions of a given profile
+     *
+     * Returns an array containing subscription informations for the specified
+     * profile. Every array entry should in turn be an array with keys
+     *   'uri´: The identifier URI of the subscriber
+     *   'token´: The subscribe token
+     *   'secret´: The secret token
+     * Throws exceptions in case of error.
+     *
+     * @param string $subscribed_user_uri The OMB identifier URI specifying the
+     *                                    subscribed profile
+     *
+     * @access public
+     *
+     * @return mixed An array containing the subscriptions or 0 if no
+     *               subscription has been found.
+     **/
+    public function getSubscriptions($subscribed_user_uri) {
+        $sub = new Subscription();
+
+        $user = $this->_getAnyProfile($subscribed_user_uri);
+
+        $sub->subscribed = $user->id;
+
+        if (!$sub->find(true)) {
+            return array();
+        }
+
+        /* Since we do not use OMB_Service_Provider’s action methods, there
+           is no need to actually return the subscriptions. */
+        return 1;
+    }
+
+    private function _getAnyProfile($uri)
+    {
+        $user = Remote_profile::staticGet('uri', $uri);
+        if (!$user) {
+            $user = User::staticGet('uri', $uri);
+        }
+        if (!$user) {
+            throw new Exception('No such user.');
+        }
+        return $user;
+    }
+
+    /**
+     * Delete a subscription
+     *
+     * Deletes the subscription from $subscriber_uri to $subscribed_user_uri.
+     * Throws exceptions in case of error.
+     *
+     * @param string $subscriber_uri      The OMB identifier URI specifying the
+     *                                    subscribing profile
+     *
+     * @param string $subscribed_user_uri The OMB identifier URI specifying the
+     *                                    subscribed profile
+     *
+     * @access public
+     **/
+    public function deleteSubscription($subscriber_uri, $subscribed_user_uri)
+    {
+        $sub = new Subscription();
+
+        $subscribed = $this->_getAnyProfile($subscribed_user_uri);
+        $subscriber = $this->_getAnyProfile($subscriber_uri);
+
+        $sub->subscribed = $subscribed->id;
+        $sub->subscriber = $subscriber->id;
+
+        $sub->delete();
+    }
+
+    /**
+     * Save a subscription
+     *
+     * Saves the subscription from $subscriber_uri to $subscribed_user_uri.
+     * Throws exceptions in case of error.
+     *
+     * @param string     $subscriber_uri      The OMB identifier URI specifying
+     *                                        the subscribing profile
+     *
+     * @param string     $subscribed_user_uri The OMB identifier URI specifying
+     *                                        the subscribed profile
+     * @param OAuthToken $token               The access token
+     *
+     * @access public
+     **/
+    public function saveSubscription($subscriber_uri, $subscribed_user_uri,
+                                                                       $token)
+    {
+        $sub = new Subscription();
+
+        $subscribed = $this->_getAnyProfile($subscribed_user_uri);
+        $subscriber = $this->_getAnyProfile($subscriber_uri);
+
+        if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
+            common_log(LOG_INFO, __METHOD__ . ": remote subscriber banned ($subscriber_uri subbing to $subscribed_user_uri)");
+            // TRANS: Error message displayed to a banned user when they try to subscribe.
+            return _('You have been banned from subscribing.');
+        }
+
+        $sub->subscribed = $subscribed->id;
+        $sub->subscriber = $subscriber->id;
+
+        $sub_exists = $sub->find(true);
+
+        if ($sub_exists) {
+            $orig_sub = clone($sub);
+        } else {
+            $sub->created = DB_DataObject_Cast::dateTime();
+        }
+
+        $sub->token  = $token->key;
+        $sub->secret = $token->secret;
+
+        if ($sub_exists) {
+            $result = $sub->update($orig_sub);
+        } else {
+            $result = $sub->insert();
+        }
+
+        if (!$result) {
+            common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__);
+            // TRANS: Exception thrown when creating a new subscription fails in OAuth store.
+            throw new Exception(_('Could not insert new subscription.'));
+            return;
+        }
+
+        /* Notify user, if necessary. */
+
+        if ($subscribed instanceof User) {
+            mail_subscribe_notify_profile($subscribed,
+                                          Profile::staticGet($subscriber->id));
+        }
+    }
+}
diff --git a/plugins/OMB/lib/ombqueuehandler.php b/plugins/OMB/lib/ombqueuehandler.php
new file mode 100644 (file)
index 0000000..bc70edb
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008-2011, 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/>.
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+/**
+ * Queue handler for pushing new notices to OpenMicroBlogging subscribers.
+ */
+class OmbQueueHandler extends QueueHandler
+{
+
+    function transport()
+    {
+        return 'omb';
+    }
+
+    /**
+     * @fixme doesn't currently report failure back to the queue manager
+     * because omb_broadcast_notice() doesn't report it to us
+     */
+    function handle($notice)
+    {
+        if ($this->is_remote($notice)) {
+            common_log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id);
+            return true;
+        } else {
+            require_once(dirname(__FILE__) . '/omb.php');
+            omb_broadcast_notice($notice);
+            return true;
+        }
+    }
+
+    function is_remote($notice)
+    {
+        $user = User::staticGet($notice->profile_id);
+        return is_null($user);
+    }
+}
diff --git a/plugins/OMB/lib/profilequeuehandler.php b/plugins/OMB/lib/profilequeuehandler.php
new file mode 100644 (file)
index 0000000..5c67b0b
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010-2011, 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 QueueHandler
+ * @maintainer Brion Vibber <brion@status.net>
+ */
+
+class ProfileQueueHandler extends QueueHandler
+{
+
+    function transport()
+    {
+        return 'profile';
+    }
+
+    function handle($profile)
+    {
+        if (!($profile instanceof Profile)) {
+            common_log(LOG_ERR, "Got a bogus profile, not broadcasting");
+            return true;
+        }
+
+        if (Event::handle('StartBroadcastProfile', array($profile))) {
+            require_once(dirname(__FILE__) . '/omb.php');
+            try {
+                omb_broadcast_profile($profile);
+            } catch (Exception $e) {
+                common_log(LOG_ERR, "Failed sending OMB profiles: " . $e->getMessage());
+            }
+        }
+        Event::handle('EndBroadcastProfile', array($profile));
+        return true;
+    }
+
+}
index 8f27d86c8b4f83fd8bc7937ba370f9e1031801e1..479a590b3f1a09ba4612f622c34d7335879c13e8 100644 (file)
@@ -591,7 +591,7 @@ class Ostatus_profile extends Managed_DataObject
             }
         }
 
-        $options = array('is_local' => Notice::REMOTE_OMB,
+        $options = array('is_local' => Notice::REMOTE,
                         'url' => $sourceUrl,
                         'uri' => $sourceUri,
                         'rendered' => $rendered,