Merge pull request #4230 from dokuwiki-translate/lang_update_830_1709550808
[dokuwiki.git] / inc / Sitemap / Item.php
blobc8e602fbe9cf5ef0f376bcc34860f66ca4882313
1 <?php
3 namespace dokuwiki\Sitemap;
5 /**
6 * An item of a sitemap.
8 * @author Michael Hamann
9 */
10 class Item
12 public $url;
13 public $lastmod;
14 public $changefreq;
15 public $priority;
17 /**
18 * Create a new item.
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)
29 $this->url = $url;
30 $this->lastmod = $lastmod;
31 $this->changefreq = $changefreq;
32 $this->priority = $priority;
35 /**
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)
47 $id = trim($id);
48 $date = @filemtime(wikiFN($id));
49 if (!$date) return null;
50 return new Item(wl($id, '', true), $date, $changefreq, $priority);
53 /**
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;
68 return $result;