3 namespace dokuwiki\Sitemap
;
6 * An item of a sitemap.
8 * @author Michael Hamann
20 * @param string $url The url of the item
21 * @param int $lastmod Timestamp of the last modification
22 * @param string $changefreq How frequently the item is likely to change.
23 * Valid values: always, hourly, daily, weekly, monthly, yearly, never.
24 * @param $priority float|string The priority of the item relative to other URLs on your site.
25 * Valid values range from 0.0 to 1.0.
27 public function __construct($url, $lastmod, $changefreq = null, $priority = null)
30 $this->lastmod
= $lastmod;
31 $this->changefreq
= $changefreq;
32 $this->priority
= $priority;
36 * Helper function for creating an item for a wikipage id.
38 * @param string $id A wikipage id.
39 * @param string $changefreq How frequently the item is likely to change.
40 * Valid values: always, hourly, daily, weekly, monthly, yearly, never.
41 * @param float|string $priority The priority of the item relative to other URLs on your site.
42 * Valid values range from 0.0 to 1.0.
43 * @return Item The sitemap item.
45 public static function createFromID($id, $changefreq = null, $priority = null)
48 $date = @filemtime
(wikiFN($id));
49 if (!$date) return null;
50 return new Item(wl($id, '', true), $date, $changefreq, $priority);
54 * Get the XML representation of the sitemap item.
56 * @return string The XML representation.
58 public function toXML()
60 $result = ' <url>' . NL
61 . ' <loc>' . hsc($this->url
) . '</loc>' . NL
62 . ' <lastmod>' . date_iso8601($this->lastmod
) . '</lastmod>' . NL
;
63 if ($this->changefreq
!== null)
64 $result .= ' <changefreq>' . hsc($this->changefreq
) . '</changefreq>' . NL
;
65 if ($this->priority
!== null)
66 $result .= ' <priority>' . hsc($this->priority
) . '</priority>' . NL
;
67 $result .= ' </url>' . NL
;