]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/omb.php
e9108e3e75347722bf7ed8ac80584b760b3ef8ab
[quix0rs-gnu-social.git] / lib / omb.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once('OAuth.php');
23 require_once(INSTALLDIR.'/lib/oauthstore.php');
24
25 require_once(INSTALLDIR.'/classes/Consumer.php');
26 require_once(INSTALLDIR.'/classes/Nonce.php');
27 require_once(INSTALLDIR.'/classes/Token.php');
28
29 define('OAUTH_NAMESPACE', 'http://oauth.net/core/1.0/');
30 define('OMB_NAMESPACE', 'http://openmicroblogging.org/protocol/0.1');
31 define('OMB_VERSION_01', 'http://openmicroblogging.org/protocol/0.1');
32 define('OAUTH_DISCOVERY', 'http://oauth.net/discovery/1.0');
33
34 define('OMB_ENDPOINT_UPDATEPROFILE', OMB_NAMESPACE.'/updateProfile');
35 define('OMB_ENDPOINT_POSTNOTICE', OMB_NAMESPACE.'/postNotice');
36 define('OAUTH_ENDPOINT_REQUEST', OAUTH_NAMESPACE.'endpoint/request');
37 define('OAUTH_ENDPOINT_AUTHORIZE', OAUTH_NAMESPACE.'endpoint/authorize');
38 define('OAUTH_ENDPOINT_ACCESS', OAUTH_NAMESPACE.'endpoint/access');
39 define('OAUTH_ENDPOINT_RESOURCE', OAUTH_NAMESPACE.'endpoint/resource');
40 define('OAUTH_AUTH_HEADER', OAUTH_NAMESPACE.'parameters/auth-header');
41 define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body');
42 define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1');
43            
44 function omb_oauth_consumer() {
45         static $con = null;
46         if (!$con) {
47                 $con = new OAuthConsumer(common_root_url(), '');
48         }
49         return $con;
50 }
51
52 function omb_oauth_server() {
53         static $server = null;
54         if (!$server) {
55                 $server = new OAuthServer(new LaconicaOAuthDataStore());
56         }
57         return $server;
58 }
59
60 function omb_hmac_sha1() {
61         static $hmac_method = NULL;
62         if (!$hmac_method) {
63                 $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
64         }
65         return $hmac_method;
66 }
67
68 function omb_service_filter($type) {
69         return create_function('$s', 
70                                                    'return omb_match_service($s, \''.$type.'\');');
71 }
72         
73 function omb_match_service($service, $type) {
74         if ($service && $service->matchTypes(array($type))) {
75                 return TRUE;
76         } else {
77                 return FALSE;
78         }
79 }
80
81 function omb_service_uri($service) {
82         if (!$service) {
83                 return NULL;
84         }
85         $uris = $service->getURIs();
86         if (!$uris) {
87                 return NULL;
88         }
89         return $uris[0];
90 }
91
92 function omb_local_id($service) {
93         if (!$service) {
94                 return NULL;
95         }
96         $els = $service->getElements('xrd:LocalID');
97         if (!$els) {
98                 return NULL;
99         }
100         $el = $els[0];
101         return $service->parser->content($el);
102 }
103