forked from kvirc/kvirc-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitemap.php
64 lines (57 loc) · 2.66 KB
/
sitemap.php
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
<?php
// Create Google sitemap
$date=date("Y-m-d");
$freq="daily";
// array("url" => "url", "date" => "date", "freq" => "frequency", "pri" => "priority")
$urls=array(
array("url" => "http://www.kvirc.net/?id=download", "date" => $date, "freq" => $freq, "pri" => "1.0"),
array("url" => "http://www.kvirc.net/?id=features", "date" => $date, "freq" => $freq, "pri" => "0.2"),
array("url" => "http://www.kvirc.net/?id=screen", "date" => $date, "freq" => $freq, "pri" => "0.7"),
array("url" => "http://www.kvirc.net/?id=tutorials", "date" => $date, "freq" => $freq, "pri" => "0.5"),
array("url" => "http://www.kvirc.net/?id=themes", "date" => $date, "freq" => $freq, "pri" => "0.9"),
array("url" => "http://www.kvirc.net/?id=addons", "date" => $date, "freq" => $freq, "pri" => "0.6"),
array("url" => "http://www.kvirc.net/?id=help", "date" => $date, "freq" => $freq, "pri" => "0.8"),
array("url" => "http://www.kvirc.net/?id=translation", "date" => $date, "freq" => $freq, "pri" => "0.5"),
array("url" => "http://www.kvirc.net/?id=mailinglist", "date" => $date, "freq" => $freq, "pri" => "0.8"),
array("url" => "http://www.kvirc.net/?id=tools", "date" => $date, "freq" => $freq, "pri" => "0.5"),
array("url" => "http://www.kvirc.net/?id=contribute", "date" => $date, "freq" => $freq, "pri" => "0.6")
);
$out = writeGZipFile(outputMap($urls));
header('Cache-Control: ');
header('Pragma: ');
header('Content-Type: application/x-gzip');
header('Content-Length: ' . (string)(strlen($out)));
header('Content-Disposition: attachment; filename=sitemap.xml.gz');
header('Content-Transfer-Encoding: binary\n');
echo($out);
//echo('<h1>OK</h1>Sitemap preparata.');
function outputMap($urls)
{
$out = '';
$out .= ("<?xml version='1.0' encoding='UTF-8'?".">" . "\r\n");
$out .= ('<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"' . "\r\n");
$out .= ('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\r\n");
$out .= ('xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84' . "\r\n");
$out .= ('http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">' . "\r\n");
foreach($urls as $key=>$url)
{
$out .=('<url>' . "\r\n");
$out .=(' <loc>' . htmlentities($url['url']) . '</loc>' . "\r\n");
$out .=(' <lastmod>' . $url['date'] . '</lastmod>' . "\r\n");
$out .=(' <changefreq>' . $url['freq'] . '</changefreq>' . "\r\n");
$out .=(' <priority>' . $url['pri'] . '</priority>' . "\r\n");
$out .=('</url>' . "\r\n");
}
$out .= ('</urlset>' . "\r\n\r\n");
return $out;
}
function writeGZipFile($content, $filePath = '')
{
$gzData = gzencode($content, 9);
if($filePath == '')
return $gzData;
$fp = fopen($filePath, 'w');
fwrite($fp, $gzData);
fclose($fp);
}
?>