forked from DistributedProofreaders/dproofreaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitemap.php
87 lines (71 loc) · 2.27 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
$relPath = "pinc/";
include_once($relPath."base.inc");
// fixed, non-project pages to include in the listing with their
// change frequency
$fixed_pages = [
"default.php" => "monthly",
];
header('Content-type: application/xml; charset=utf-8');
// see https://en.wikipedia.org/wiki/Sitemaps#File_format
echo <<<XML_HEADER
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
XML_HEADER;
// sitemaps are limited to 50k URLs, so we need to keep track of how many
// we output and stop when we get to that number
$MAX_URLS = 50000;
$url_count = 0;
foreach ($fixed_pages as $page => $frequency) {
if ($url_count >= $MAX_URLS) {
break;
}
$url = "$code_url/$page";
$lastmod = date("Y-m-d", filemtime("$code_dir/$page"));
echo <<<URL
<url>
<loc>$url</loc>
<lastmod>$lastmod</lastmod>
<changefreq>$frequency</changefreq>
<priority>1.0</priority>
</url>
URL;
$url_count += 1;
}
// now project pages
// Order the projects in the order they go through the system. This is only
// relevant if there are more than 50k of them, in which case we drop off
// projects on the tail end (deleted projects get dropped first, posted ones
// get dropped second, etc).
$order_by = sql_collator_for_project_state("state");
$sql = "
SELECT projectid, modifieddate
FROM projects
ORDER BY $order_by
";
$result = DPDatabase::query($sql);
while ($row = mysqli_fetch_assoc($result)) {
if ($url_count >= $MAX_URLS) {
break;
}
// skip entries with no modifieddate
$modified_date = (int)$row["modifieddate"];
if ($modified_date == 0) {
continue;
}
$url = "$code_url/project.php?id=" . $row["projectid"];
$lastmod = date("Y-m-d", $modified_date);
echo <<<URL
<url>
<loc>$url</loc>
<lastmod>$lastmod</lastmod>
<priority>0.5</priority>
</url>
URL;
$url_count += 1;
}
echo <<<XML_FOOTER
</urlset>
XML_FOOTER;