Repository navigation
Expand file tree
/
Copy pathsitemap.php
More file actions
114 lines (98 loc) · 4.14 KB
/
Copy pathsitemap.php
File metadata and controls
114 lines (98 loc) · 4.14 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
<?php
/**
* XML Sitemap for OpenParliamentTV.
*
* Lists entity pages only: static pages, persons, organisations, terms,
* legal documents (from the platform DB), plus sessions and electoral periods
* from every configured parliament DB. Media/speeches are deliberately NOT
* included (100k+ items would exceed the 50k-URL per-file limit); they stay
* discoverable via internal links and carry their own VideoObject structured data.
*/
require_once(__DIR__ . '/bootstrap-core.php');
require_once(__DIR__ . '/modules/utilities/safemysql.class.php');
require_once(__DIR__ . '/api/v1/utilities.php'); // getApiDatabaseConnection()
header('Content-Type: application/xml; charset=utf-8');
header('Cache-Control: public, max-age=86400'); // 24h
$baseUrl = rtrim($config["dir"]["root"], '/');
$db = getApiDatabaseConnection('platform');
if (!($db instanceof SafeMySQL)) {
http_response_code(500);
exit;
}
/** Emit a single <url> entry. */
function sitemapUrl($loc, $lastmod = null, $changefreq = 'monthly', $priority = '0.5')
{
echo " <url>\n";
echo " <loc>" . htmlspecialchars($loc) . "</loc>\n";
if ($lastmod) {
echo " <lastmod>" . htmlspecialchars($lastmod) . "</lastmod>\n";
}
echo " <changefreq>" . $changefreq . "</changefreq>\n";
echo " <priority>" . $priority . "</priority>\n";
echo " </url>\n";
}
/** Normalise a DB timestamp/date to YYYY-MM-DD, or null. */
function sitemapDate($value)
{
$date = optvFormatDate($value, 'Y-m-d');
return $date === '' ? null : $date;
}
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
// ===== Static pages =====
sitemapUrl($baseUrl . '/', null, 'daily', '1.0');
sitemapUrl($baseUrl . '/about', null, 'monthly', '0.4');
// ===== Persons (platform DB) =====
$persons = $db->getAll(
"SELECT PersonID, PersonLastChanged FROM ?n ORDER BY PersonID",
$config["platform"]["sql"]["tbl"]["Person"]
);
foreach ($persons ?: [] as $row) {
sitemapUrl($baseUrl . '/person/' . $row["PersonID"], sitemapDate($row["PersonLastChanged"]), 'monthly', '0.7');
}
// ===== Organisations (platform DB) =====
$orgs = $db->getAll(
"SELECT OrganisationID, OrganisationLastChanged FROM ?n ORDER BY OrganisationID",
$config["platform"]["sql"]["tbl"]["Organisation"]
);
foreach ($orgs ?: [] as $row) {
sitemapUrl($baseUrl . '/organisation/' . $row["OrganisationID"], sitemapDate($row["OrganisationLastChanged"]), 'monthly', '0.6');
}
// ===== Terms (platform DB) =====
$terms = $db->getAll(
"SELECT TermID, TermLastChanged FROM ?n ORDER BY TermID",
$config["platform"]["sql"]["tbl"]["Term"]
);
foreach ($terms ?: [] as $row) {
sitemapUrl($baseUrl . '/term/' . $row["TermID"], sitemapDate($row["TermLastChanged"]), 'monthly', '0.5');
}
// ===== Legal documents only (platform DB) =====
$docs = $db->getAll(
"SELECT DocumentID, DocumentLastChanged FROM ?n WHERE DocumentType = 'legalDocument' ORDER BY DocumentID",
$config["platform"]["sql"]["tbl"]["Document"]
);
foreach ($docs ?: [] as $row) {
sitemapUrl($baseUrl . '/document/' . $row["DocumentID"], sitemapDate($row["DocumentLastChanged"]), 'monthly', '0.5');
}
// ===== Sessions + electoral periods (per parliament DB) =====
foreach ($config["parliament"] as $parliamentCode => $parliamentConfig) {
$dbp = getApiDatabaseConnection('parliament', $parliamentCode);
if (!($dbp instanceof SafeMySQL)) {
continue; // invalid/unavailable parliament — skip
}
$electoralPeriods = $dbp->getAll(
"SELECT ElectoralPeriodID FROM ?n ORDER BY ElectoralPeriodNumber",
$parliamentConfig["sql"]["tbl"]["ElectoralPeriod"]
);
foreach ($electoralPeriods ?: [] as $row) {
sitemapUrl($baseUrl . '/electoralPeriod/' . $row["ElectoralPeriodID"], null, 'monthly', '0.5');
}
$sessions = $dbp->getAll(
"SELECT SessionID, SessionDateStart FROM ?n ORDER BY SessionID",
$parliamentConfig["sql"]["tbl"]["Session"]
);
foreach ($sessions ?: [] as $row) {
sitemapUrl($baseUrl . '/session/' . $row["SessionID"], sitemapDate($row["SessionDateStart"]), 'yearly', '0.5');
}
}
echo '</urlset>' . "\n";