-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·123 lines (120 loc) · 4.62 KB
/
Copy pathindex.php
File metadata and controls
executable file
·123 lines (120 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php namespace x\sitemap;
// Insert some HTML `<link>` that maps to the sitemap resource
function content($content) {
\extract(\lot(), \EXTR_SKIP);
if (!$content || empty($page)) {
return $content;
}
return \strtr($content ?? "", ['</head>' => '<link href="' . $page->link . '/sitemap.xml" rel="sitemap" title="' . \i('Sitemap') . ' | ' . \w($state->title) . '" type="application/xml"></head>']);
}
function route($content, $path) {
if (null !== $content) {
return $content;
}
\extract(\lot(), \EXTR_SKIP);
$fire = $_GET['fire'] ?? null;
// Validate function name
if ($fire && !\preg_match('/^[a-z_$][\w$]*(\.[a-z_$][\w$]*)*$/i', $fire)) {
\status(403);
return "";
}
$home = \trim($state->home ?? 'index', '/');
$path = \trim(\dirname($path ?? ""), '/');
$folder = ($folder_page = \LOT . \D . 'page') . \D . \rawurldecode($path ?: $home);
$page = new \Page($exist = $folder . '.{' . \x\page\x() . '}', 1) ?: null);
// `./foo/sitemap.xml`
// `./foo/bar/sitemap.xml`
if ("" !== $path && '.' !== $path) {
$lot = [
0 => 'urlset',
1 => [],
2 => ['xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9']
];
// `./-/sitemap.xml`
if ('-' === $path) {
$exist = true;
foreach (\g($folder_page, 'archive,page') as $k => $v) {
$loc = \Hook::fire('link', ['/' . ($home === ($n = \pathinfo($k, \PATHINFO_FILENAME)) ? "" : $n)]);
$lot[1][$k] = [
0 => 'url',
1 => [
['changefreq', 'monthly', []],
['lastmod', \date('c', \filemtime($k)), []],
['loc', $loc, []],
['priority', 1, []]
],
2 => []
];
}
} else if ($exist) {
foreach (\g($folder, 'archive,page', true) as $k => $v) {
$v = \dirname($k) . \D . \pathinfo($k, \PATHINFO_FILENAME);
$loc = \Hook::fire('link', ['/' . ($r = \strtr(\strtr($v, [$folder_page . \D => ""]), \D, '/'))]);
$priority = \b(1 - (\substr_count($r, '/') * 0.1), [0.5, 1]); // `0.5` to `1.0`
$lot[1][$k] = [
0 => 'url',
1 => [
['changefreq', 'monthly', []],
['lastmod', \date('c', \filemtime($k)), []],
['loc', $loc, []],
['priority', $priority, []]
],
2 => []
];
}
}
// `./sitemap.xml`
} else {
$exist = true;
$lot = [
0 => 'sitemapindex',
1 => [],
2 => ['xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9']
];
$loc = \Hook::fire('link', ['/-/sitemap.xml']);
$lot[1][""] = [
0 => 'sitemap',
1 => [
['lastmod', \date('c', \filemtime($folder_page)), []],
['loc', $loc, []]
],
2 => []
];
foreach (\g($folder_page, 0, true) as $k => $v) {
if (0 === \q(\g($k, 'archive,page'))) {
// Ignore empty folder(s)
continue;
}
if (!$v = \exist($k . '.{' . \x\page\x() . '}', 1)) {
continue;
}
$loc = \Hook::fire('link', ['/' . \strtr(\strtr($k, [$folder_page . \D => ""]), \D, '/') . '/sitemap.xml']);
$lot[1][$v] = [
0 => 'sitemap',
1 => [
['lastmod', \date('c', \filemtime($v)), []],
['loc', $loc, []]
],
2 => []
];
}
}
$age = 60 * 60 * 24; // Cache for a day
$content = '<?xml version="1.0" encoding="utf-8"?>' . (new \XML(\Hook::fire('y.sitemap', [$lot], $page), true));
\status($exist ? 200 : 404, $exist ? [
'cache-control' => 'max-age=' . $age . ', private',
'expires' => \gmdate('D, d M Y H:i:s', $age + $_SERVER['REQUEST_TIME']) . ' GMT',
'pragma' => 'private'
] : [
'cache-control' => 'max-age=0, must-revalidate, no-cache, no-store',
'expires' => '0',
'pragma' => 'no-cache'
]);
\type('application/' . ($fire ? 'javascript' : 'xml'));
return $fire ? $fire . '(' . \To::JSON($content) . ');' : $content;
}
if ('sitemap.xml' !== \basename($link->path ?? "")) {
\Hook::set('content', __NAMESPACE__ . "\\content", -1);
} else {
\Hook::set('route', __NAMESPACE__ . "\\route", 10);
}