1432adb37SAndreas Gohr<?php 2432adb37SAndreas Gohr 3432adb37SAndreas Gohrnamespace dokuwiki\Sitemap; 4432adb37SAndreas Gohr 5432adb37SAndreas Gohr/** 6432adb37SAndreas Gohr * An item of a sitemap. 7432adb37SAndreas Gohr * 8432adb37SAndreas Gohr * @author Michael Hamann 9432adb37SAndreas Gohr */ 108c7c53b0SAndreas Gohrclass Item 118c7c53b0SAndreas Gohr{ 12432adb37SAndreas Gohr public $url; 13432adb37SAndreas Gohr public $lastmod; 14432adb37SAndreas Gohr public $changefreq; 15432adb37SAndreas Gohr public $priority; 16432adb37SAndreas Gohr 17432adb37SAndreas Gohr /** 18432adb37SAndreas Gohr * Create a new item. 19432adb37SAndreas Gohr * 20432adb37SAndreas Gohr * @param string $url The url of the item 21432adb37SAndreas Gohr * @param int $lastmod Timestamp of the last modification 22432adb37SAndreas Gohr * @param string $changefreq How frequently the item is likely to change. 23432adb37SAndreas Gohr * Valid values: always, hourly, daily, weekly, monthly, yearly, never. 24432adb37SAndreas Gohr * @param $priority float|string The priority of the item relative to other URLs on your site. 25432adb37SAndreas Gohr * Valid values range from 0.0 to 1.0. 26432adb37SAndreas Gohr */ 27*d868eb89SAndreas Gohr public function __construct($url, $lastmod, $changefreq = null, $priority = null) 28*d868eb89SAndreas Gohr { 29432adb37SAndreas Gohr $this->url = $url; 30432adb37SAndreas Gohr $this->lastmod = $lastmod; 31432adb37SAndreas Gohr $this->changefreq = $changefreq; 32432adb37SAndreas Gohr $this->priority = $priority; 33432adb37SAndreas Gohr } 34432adb37SAndreas Gohr 35432adb37SAndreas Gohr /** 36432adb37SAndreas Gohr * Helper function for creating an item for a wikipage id. 37432adb37SAndreas Gohr * 38432adb37SAndreas Gohr * @param string $id A wikipage id. 39432adb37SAndreas Gohr * @param string $changefreq How frequently the item is likely to change. 40432adb37SAndreas Gohr * Valid values: always, hourly, daily, weekly, monthly, yearly, never. 41432adb37SAndreas Gohr * @param float|string $priority The priority of the item relative to other URLs on your site. 42432adb37SAndreas Gohr * Valid values range from 0.0 to 1.0. 43432adb37SAndreas Gohr * @return Item The sitemap item. 44432adb37SAndreas Gohr */ 45*d868eb89SAndreas Gohr public static function createFromID($id, $changefreq = null, $priority = null) 46*d868eb89SAndreas Gohr { 47432adb37SAndreas Gohr $id = trim($id); 48432adb37SAndreas Gohr $date = @filemtime(wikiFN($id)); 49432adb37SAndreas Gohr if (!$date) return null; 50432adb37SAndreas Gohr return new Item(wl($id, '', true), $date, $changefreq, $priority); 51432adb37SAndreas Gohr } 52432adb37SAndreas Gohr 53432adb37SAndreas Gohr /** 54432adb37SAndreas Gohr * Get the XML representation of the sitemap item. 55432adb37SAndreas Gohr * 56432adb37SAndreas Gohr * @return string The XML representation. 57432adb37SAndreas Gohr */ 58*d868eb89SAndreas Gohr public function toXML() 59*d868eb89SAndreas Gohr { 60432adb37SAndreas Gohr $result = ' <url>' . NL 61432adb37SAndreas Gohr . ' <loc>' . hsc($this->url) . '</loc>' . NL 62432adb37SAndreas Gohr . ' <lastmod>' . date_iso8601($this->lastmod) . '</lastmod>' . NL; 63432adb37SAndreas Gohr if ($this->changefreq !== null) 64432adb37SAndreas Gohr $result .= ' <changefreq>' . hsc($this->changefreq) . '</changefreq>' . NL; 65432adb37SAndreas Gohr if ($this->priority !== null) 66432adb37SAndreas Gohr $result .= ' <priority>' . hsc($this->priority) . '</priority>' . NL; 67432adb37SAndreas Gohr $result .= ' </url>' . NL; 68432adb37SAndreas Gohr return $result; 69432adb37SAndreas Gohr } 70432adb37SAndreas Gohr} 71