Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
OlzXmlSitemap | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
getHtml | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
getEntry | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Olz\Components\OlzXmlSitemap; |
4 | |
5 | use Olz\Components\OlzSitemap\OlzSitemap; |
6 | |
7 | class OlzXmlSitemap extends OlzSitemap { |
8 | public function getHtml(mixed $args): string { |
9 | $out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
10 | $out .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; |
11 | |
12 | $entries = $this->getEntries(); |
13 | foreach ($entries as $entry) { |
14 | $out .= self::getEntry($entry); |
15 | } |
16 | |
17 | $out .= "</urlset>\n"; |
18 | return $out; |
19 | } |
20 | |
21 | /** @param array{title: string, description: string, url: string, updates: string, importance: float, level: int} $entry */ |
22 | private static function getEntry(array $entry): string { |
23 | $url = htmlentities($entry['url']); |
24 | $change_frequency = $entry['updates']; |
25 | $priority = $entry['importance']; |
26 | $change_frequency_line = $change_frequency ? "<changefreq>{$change_frequency}</changefreq>" : ''; |
27 | $priority_line = $priority ? "<priority>{$priority}</priority>" : ''; |
28 | return <<<ZZZZZZZZZZ |
29 | <url> |
30 | <loc>{$url}</loc> |
31 | {$change_frequency_line} |
32 | {$priority_line} |
33 | </url>\n |
34 | ZZZZZZZZZZ; |
35 | } |
36 | } |