|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Sitemap |
|
5
|
|
|
* |
|
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
|
7
|
|
|
* @link http://inji.ru/ |
|
8
|
|
|
* @copyright 2016 Alexey Krupskiy |
|
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
|
10
|
|
|
*/ |
|
11
|
|
|
class Sitemap extends Module |
|
12
|
|
|
{ |
|
13
|
|
|
function scanModules() |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
$modules = Module::getInstalled(App::$primary); |
|
16
|
|
|
$map = []; |
|
17
|
|
|
foreach ($modules as $module) { |
|
18
|
|
|
$map[$module] = App::$cur->$module->sitemap(); |
|
19
|
|
|
if (!$map[$module]) { |
|
20
|
|
|
unset($map[$module]); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
return $map; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
function generate($map) |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
header("Content-Type: text/xml"); |
|
29
|
|
|
header("Expires: Thu, 19 Feb 1998 13:24:18 GMT"); |
|
30
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
31
|
|
|
header("Cache-Control: no-cache, must-revalidate"); |
|
32
|
|
|
header("Cache-Control: post-check=0,pre-check=0"); |
|
33
|
|
|
header("Cache-Control: max-age=0"); |
|
34
|
|
|
header("Pragma: no-cache"); |
|
35
|
|
|
|
|
36
|
|
|
$xml = new \DOMDocument('1.0', 'utf-8'); |
|
37
|
|
|
$xml->formatOutput = true; |
|
38
|
|
|
$root = $xml->createElement('urlset'); |
|
39
|
|
|
$root->setAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"); |
|
40
|
|
|
$root = $xml->appendChild($root); |
|
41
|
|
|
|
|
42
|
|
|
$addToXml = function ($xml, $parent, $nodeName, $text) { |
|
43
|
|
|
$node = $parent->appendChild($xml->createElement($nodeName)); |
|
44
|
|
|
$node->appendChild($xml->createTextNode($text)); |
|
45
|
|
|
return $node; |
|
46
|
|
|
}; |
|
47
|
|
|
|
|
48
|
|
|
foreach ($map as $module => $items) { |
|
49
|
|
|
foreach ($items as $item) { |
|
50
|
|
|
$url = $xml->createElement('url'); |
|
51
|
|
|
foreach ($item['url'] as $key => $item) { |
|
52
|
|
|
$addToXml($xml, $url, $key, $item); |
|
53
|
|
|
} |
|
54
|
|
|
$root->appendChild($url); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
echo $xml->saveXML(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.