3 * This file is part of libomb
7 * LICENSE: This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @author Adrian Lang <mail@adrianlang.de>
22 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
23 * @version 0.1a-20090828
24 * @link http://adrianlang.de/libomb
27 require_once 'xrds_writer.php';
30 * Write OMB-specific XRDS using XMLWriter
32 * This class writes the XRDS file announcing the OMB server. It uses XMLWriter.
33 * An instance of OMB_Plain_XRDS_Writer should be passed to
34 * OMB_Service_Provider->writeXRDS.
36 class OMB_Plain_XRDS_Writer implements OMB_XRDS_Writer
39 * Write XRDS using XMLWriter
41 * Outputs a XRDS document specifying an OMB service.
43 * @param OMB_profile $user The target user for the OMB service
44 * @param OMB_XRDS_Mapper $mapper An OMB_XRDS_Mapper providing endpoint URLs
46 public function writeXRDS($user, $mapper)
48 header('Content-Type: application/xrds+xml');
49 $xw = new XMLWriter();
50 $xw->openURI('php://output');
53 $xw->startDocument('1.0', 'UTF-8');
54 $this->_writeFullElement($xw, 'XRDS', array('xmlns' => 'xri://$xrds'), array(
55 array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
57 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
58 'version' => '2.0'), array(
59 array('Type', null, 'xri://$xrds*simple'),
60 array('Service', null, array(
61 array('Type', null, OAUTH_ENDPOINT_REQUEST),
62 array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_REQUEST)),
63 array('Type', null, OAUTH_AUTH_HEADER),
64 array('Type', null, OAUTH_POST_BODY),
65 array('Type', null, OAUTH_HMAC_SHA1),
66 array('LocalID', null, $user->getIdentifierURI())
68 array('Service', null, array(
69 array('Type', null, OAUTH_ENDPOINT_AUTHORIZE),
70 array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_AUTHORIZE)),
71 array('Type', null, OAUTH_AUTH_HEADER),
72 array('Type', null, OAUTH_POST_BODY),
73 array('Type', null, OAUTH_HMAC_SHA1)
75 array('Service', null, array(
76 array('Type', null, OAUTH_ENDPOINT_ACCESS),
77 array('URI', null, $mapper->getURL(OAUTH_ENDPOINT_ACCESS)),
78 array('Type', null, OAUTH_AUTH_HEADER),
79 array('Type', null, OAUTH_POST_BODY),
80 array('Type', null, OAUTH_HMAC_SHA1)
82 array('Service', null, array(
83 array('Type', null, OAUTH_ENDPOINT_RESOURCE),
84 array('Type', null, OAUTH_AUTH_HEADER),
85 array('Type', null, OAUTH_POST_BODY),
86 array('Type', null, OAUTH_HMAC_SHA1)
89 array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
91 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
92 'version' => '2.0'), array(
93 array('Type', null, 'xri://$xrds*simple'),
94 array('Service', null, array(
95 array('Type', null, OMB_ENDPOINT_POSTNOTICE),
96 array('URI', null, $mapper->getURL(OMB_ENDPOINT_POSTNOTICE))
98 array('Service', null, array(
99 array('Type', null, OMB_ENDPOINT_UPDATEPROFILE),
100 array('URI', null, $mapper->getURL(OMB_ENDPOINT_UPDATEPROFILE))
103 array('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
104 'version' => '2.0'), array(
105 array('Type', null, 'xri://$xrds*simple'),
106 array('Service', null, array(
107 array('Type', null, OAUTH_DISCOVERY),
108 array('URI', null, '#oauth')
110 array('Service', null, array(
111 array('Type', null, OMB_VERSION),
112 array('URI', null, '#omb')
120 * Write a complex XML element
122 * Outputs a XML element with attributes and content.
124 * @param XMLWriter $xw The XMLWriter used to output the element
125 * @param string $tag The tag name
126 * @param array|null $attributes A map of XML attributes
127 * @param array|string $content The content of the element; either an
128 * array of child nodes each specified by a
129 * three entry-array ($tag, $attributes,
130 * $content) or a string
132 private function _writeFullElement($xw, $tag, $attributes, $content)
134 $xw->startElement($tag);
135 if (!is_null($attributes)) {
136 foreach ($attributes as $name => $value) {
137 $xw->writeAttribute($name, $value);
140 if (is_array($content)) {
141 foreach ($content as $val) {
142 $this->_writeFullElement($xw, $val[0], $val[1], $val[2]);
147 $xw->fullEndElement();