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
|
<?php
namespace dokuwiki\Sitemap;
/**
* An item of a sitemap.
*
* @author Michael Hamann
*/
class Item
{
public $url;
public $lastmod;
public $changefreq;
public $priority;
/**
* Create a new item.
*
* @param string $url The url of the item
* @param int $lastmod Timestamp of the last modification
* @param string $changefreq How frequently the item is likely to change.
* Valid values: always, hourly, daily, weekly, monthly, yearly, never.
* @param $priority float|string The priority of the item relative to other URLs on your site.
* Valid values range from 0.0 to 1.0.
*/
public function __construct($url, $lastmod, $changefreq = null, $priority = null)
{
$this->url = $url;
$this->lastmod = $lastmod;
$this->changefreq = $changefreq;
$this->priority = $priority;
}
/**
* Helper function for creating an item for a wikipage id.
*
* @param string $id A wikipage id.
* @param string $changefreq How frequently the item is likely to change.
* Valid values: always, hourly, daily, weekly, monthly, yearly, never.
* @param float|string $priority The priority of the item relative to other URLs on your site.
* Valid values range from 0.0 to 1.0.
* @return Item The sitemap item.
*/
public static function createFromID($id, $changefreq = null, $priority = null)
{
$id = trim($id);
$date = @filemtime(wikiFN($id));
if (!$date) return null;
return new Item(wl($id, '', true), $date, $changefreq, $priority);
}
/**
* Get the XML representation of the sitemap item.
*
* @return string The XML representation.
*/
public function toXML()
{
$result = ' <url>' . NL
. ' <loc>' . hsc($this->url) . '</loc>' . NL
. ' <lastmod>' . date_iso8601($this->lastmod) . '</lastmod>' . NL;
if ($this->changefreq !== null)
$result .= ' <changefreq>' . hsc($this->changefreq) . '</changefreq>' . NL;
if ($this->priority !== null)
$result .= ' <priority>' . hsc($this->priority) . '</priority>' . NL;
$result .= ' </url>' . NL;
return $result;
}
}
|