|
@@ -104,12 +104,63 @@ class Discoverer {
|
104
|
104
|
}
|
105
|
105
|
|
106
|
106
|
private function discover($uri) {
|
107
|
|
- // TODO: Yaris discovery
|
108
|
|
-
|
109
|
107
|
$this->delegate = $uri;
|
110
|
108
|
$this->server = null;
|
111
|
109
|
|
112
|
|
- $this->htmlDiscover($uri);
|
|
110
|
+ if (!$this->yadisDiscover($uri)) {
|
|
111
|
+ $this->htmlDiscover($uri);
|
|
112
|
+ }
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ private function yadisDiscover($uri, $allowLocation = true) {
|
|
116
|
+ $ctx = stream_context_create(array(
|
|
117
|
+ 'http' => array(
|
|
118
|
+ 'header' => array("Accept: application/xrds+xml\r\n"),
|
|
119
|
+ )
|
|
120
|
+ ));
|
|
121
|
+
|
|
122
|
+ $fh = @fopen($uri, 'r', false, $ctx);
|
|
123
|
+
|
|
124
|
+ if (!$fh) {
|
|
125
|
+ return false;
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ $details = stream_get_meta_data($fh);
|
|
129
|
+
|
|
130
|
+ $data = '';
|
|
131
|
+ while (!feof($fh) && strpos($data, '</head>') === false) {
|
|
132
|
+ $data .= fgets($fh);
|
|
133
|
+ }
|
|
134
|
+
|
|
135
|
+ fclose($fh);
|
|
136
|
+
|
|
137
|
+ foreach ($details['wrapper_data'] as $line) {
|
|
138
|
+ if ($allowLocation && preg_match('/^X-XRDS-Location:\s*(.*?)$/i', $line, $m)) {
|
|
139
|
+ // TODO: Allow relative URLs?
|
|
140
|
+ return $this->yadisDiscover($m[1], false);
|
|
141
|
+ } else if (preg_match('#^Content-type:\s*application/xrds\+xml(;.*?)?$#i', $line)) {
|
|
142
|
+ return $this->parseYadis($data);
|
|
143
|
+ }
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ return $this->parseYadisHTML($data);
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ private function parseYadis($data) {
|
|
150
|
+ $sxml = @new SimpleXMLElement($data);
|
|
151
|
+
|
|
152
|
+ if (!$sxml) {
|
|
153
|
+ // TODO: Die somehow?
|
|
154
|
+ return false;
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ foreach ($sxml->xrd->service as $service) {
|
|
158
|
+ // TODO: Meh
|
|
159
|
+ }
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ private function parseYadisHTML($data) {
|
|
163
|
+ // TODO: Implement me
|
113
|
164
|
}
|
114
|
165
|
|
115
|
166
|
private function htmlDiscover($uri) {
|