-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResyncDiscover.php
71 lines (57 loc) · 1.77 KB
/
ResyncDiscover.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
include_once('util/http.php');
include_once('util/file.php');
class ResyncDiscover {
// The base URL of the site
public $url;
// The discovery raw XML
private $xml;
// List of discovered feeds
private $capabilities;
// Whether or not to display debug information
private $debug = false;
// Whether the debugging messages are for display in HTML or not
private $htmldebug = false;
// Try to download discovery information
function __construct($url) {
$this->capabilities = array();
// Check the URL finishes with a slash
if (!(substr($url, - count($url)) === '/')) {
$url .= '/';
}
$this->url = $url . '.well-known/resourcesync';
$response = get_headers($this->url);
if ($response[0] == 'HTTP/1.1 200 OK') {
$xmllist = http_get($this->url);
$this->xml = simplexml_load_string($xmllist);
foreach ($this->xml->sitemap as $sitemap) {
array_push($this->capabilities, (String)$sitemap->loc);
}
} else {
$this->xml = '';
}
if ($this->debug) print_r($this->capabilities);
}
// Return the list of sitemaps
function getCapabilities() {
return $this->capabilities;
}
// Return the fully formatted URL
function getURL() {
return $this->url;
}
// Whether to display debug messages or not
function enableDebug($debug = true, $html = false) {
$this->debug = $debug;
$this->htmldebug = $html;
}
// Display a debug message
private function debug($message) {
if ($this->debug) echo $message . "\n";
if ($this->htmldebug) {
echo "<br />\n";
ob_flush();
}
}
}
?>