]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/libomb/plain_xrds_writer.php
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / extlib / libomb / plain_xrds_writer.php
1 <?php
2
3 require_once 'xrds_writer.php';
4
5 /**
6  * Write OMB-specific XRDS using XMLWriter.
7  *
8  * This class writes the XRDS file announcing the OMB server. It uses
9  * OMB_XMLWriter, which is a subclass of XMLWriter. An instance of
10  * OMB_Plain_XRDS_Writer should be passed to OMB_Service_Provider->writeXRDS.
11  *
12  * PHP version 5
13  *
14  * LICENSE: This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Affero General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Affero General Public License for more details.
23  *
24  * You should have received a copy of the GNU Affero General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  *
27  * @package   OMB
28  * @author    Adrian Lang <mail@adrianlang.de>
29  * @copyright 2009 Adrian Lang
30  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
31  **/
32
33 class OMB_Plain_XRDS_Writer implements OMB_XRDS_Writer {
34   public function writeXRDS($user, $mapper) {
35     header('Content-Type: application/xrds+xml');
36     $xw = new XMLWriter();
37     $xw->openURI('php://output');
38     $xw->setIndent(true);
39
40     $xw->startDocument('1.0', 'UTF-8');
41     $this->writeFullElement($xw, 'XRDS',  array('xmlns' => 'xri://$xrds'), array(
42         array('XRD',  array('xmlns' => 'xri://$xrd*($v*2.0)',
43                                           'xml:id' => 'oauth',
44                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
45                                           'version' => '2.0'), array(
46           array('Type', null, 'xri://$xrds*simple'),
47           array('Service', null, array(
48             array('Type', null, OAUTH_ENDPOINT_REQUEST),
49             array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_REQUEST)),
50             array('Type', null, OAUTH_AUTH_HEADER),
51             array('Type', null, OAUTH_POST_BODY),
52             array('Type', null, OAUTH_HMAC_SHA1),
53             array('LocalID', null, $user->getIdentifierURI())
54           )),
55           array('Service', null, array(
56             array('Type', null, OAUTH_ENDPOINT_AUTHORIZE),
57             array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_AUTHORIZE)),
58             array('Type', null, OAUTH_AUTH_HEADER),
59             array('Type', null, OAUTH_POST_BODY),
60             array('Type', null, OAUTH_HMAC_SHA1)
61           )),
62           array('Service', null, array(
63             array('Type', null, OAUTH_ENDPOINT_ACCESS),
64             array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_ACCESS)),
65             array('Type', null, OAUTH_AUTH_HEADER),
66             array('Type', null, OAUTH_POST_BODY),
67             array('Type', null, OAUTH_HMAC_SHA1)
68           )),
69           array('Service', null, array(
70             array('Type', null, OAUTH_ENDPOINT_RESOURCE),
71             array('Type', null, OAUTH_AUTH_HEADER),
72             array('Type', null, OAUTH_POST_BODY),
73             array('Type', null, OAUTH_HMAC_SHA1)
74           ))
75         )),
76         array('XRD',  array('xmlns' => 'xri://$xrd*($v*2.0)',
77                                           'xml:id' => 'omb',
78                                           'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
79                                           'version' => '2.0'), array(
80           array('Type', null, 'xri://$xrds*simple'),
81           array('Service', null, array(
82             array('Type', null, OMB_ENDPOINT_POSTNOTICE),
83             array('URI', null, $mapper->getURL(OMB_ENDPOINT_POSTNOTICE))
84           )),
85           array('Service', null, array(
86             array('Type', null, OMB_ENDPOINT_UPDATEPROFILE),
87             array('URI', null, $mapper->getURL(OMB_ENDPOINT_UPDATEPROFILE))
88           ))
89         )),
90         array('XRD',  array('xmlns' => 'xri://$xrd*($v*2.0)',
91                                           'version' => '2.0'), array(
92           array('Type', null, 'xri://$xrds*simple'),
93           array('Service', null, array(
94             array('Type', null, OAUTH_DISCOVERY),
95             array('URI', null, '#oauth')
96           )),
97           array('Service', null, array(
98             array('Type', null, OMB_VERSION),
99             array('URI', null, '#omb')
100           ))
101         ))
102       ));
103     $xw->endDocument();
104     $xw->flush();
105   }
106
107   public static function writeFullElement($xw, $tag, $attributes, $content) {
108     $xw->startElement($tag);
109     if (!is_null($attributes)) {
110       foreach ($attributes as $name => $value) {
111         $xw->writeAttribute($name, $value);
112       }
113     }
114     if (is_array($content)) {
115       foreach ($content as $values) {
116         OMB_Plain_XRDS_Writer::writeFullElement($xw, $values[0], $values[1], $values[2]);
117       }
118     } else {
119       $xw->text($content);
120     }
121     $xw->fullEndElement();
122   }
123 }
124 ?>