3 require_once 'xrds_writer.php';
6 * Write OMB-specific XRDS using XMLWriter.
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.
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.
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.
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/>.
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
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');
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)',
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())
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)
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)
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)
76 array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
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))
85 array('Service', null, array(
86 array('Type', null, OMB_ENDPOINT_UPDATEPROFILE),
87 array('URI', null, $mapper->getURL(OMB_ENDPOINT_UPDATEPROFILE))
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')
97 array('Service', null, array(
98 array('Type', null, OMB_VERSION),
99 array('URI', null, '#omb')
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);
114 if (is_array($content)) {
115 foreach ($content as $values) {
116 OMB_Plain_XRDS_Writer::writeFullElement($xw, $values[0], $values[1], $values[2]);
121 $xw->fullEndElement();