-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_sitemap.php
557 lines (462 loc) · 17 KB
/
google_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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<?php
/** ACKNOWLEDGMENTS ON BASED CODE AUTHOR AND MODS
* Google Site Map
* @author Karelkin Vladislav
* @copyright 2007/2013 GPL
Version 1.8.6 20160215 (Ruud)
- set Shorturl default to false. (was true by accident)
- xsl style set to relative path
Version 1.8.5 20160210 (Ruud)
- added oneforall support (multiple named modules possible)
- added optional xsl for browser viewing.
Version 1.8.4 20131004 (Ruud)
- few small bugfixes for Topics module
Version 1.8.3 20130814 (Ruud)
- small bugix on using an undeclared static variable
Version 1.8.2 20130814 (Ruud)
- Added support when shorturl is used
- Prevent multiple listings when pages have multiple sections
- Prevent "empty links" to be listed.
Version 1.8.1 20130426 (Christoph Marti)
- Relies on section_id instead of page_id to check module page visibility
Version 1.8.0 (Christoph Marti)
- Reworked some parts of the code
- Only list pages and module pages if they have visiblity active or hidden
- Only list sections if they are in-between publication dates
- Fixed various small bugs
- Added Showcase module
Version 1.7.0 (Ruud)
- List only post on newspages that are public
Version 1.6.0.20100917 (Ruud)
- Added Topics module
Version 1.5.4.20100520 (MurgtalNet on WB Forum)
- Debugs on admin path
Version 1.5.3.20100514 (Olivier Labbe (a.k.a. VotreEspace))
- Debugs on sql commands
Version 1.5.2.20091015 (Olivier Labbe (a.k.a. VotreEspace))
- Debug on menulinks problems
Version 1.5.2.20090918 (Olivier Labbe (a.k.a. VotreEspace))
- Add portfolio module possibilities
Version 1.5.1.20090725 (Olivier Labbe (a.k.a. VotreEspace))
- Will not show outside links from menu link
Version 1.5 (Ruud, thanks to "Mike")
- The homepage is now listed as the WB_URL (without /pages/home.php)
Version 1.4 (Christoph Marti)
- Replaced the hardcoded page directory name /pages by the wb constant PAGES_DIRECTORY
- Added feature to hide urls which contain unwanted words (eg. for web pages which are blocked by robots.txt)
Version 1.3 (Christoph Marti)
- Added module auto detection.
- Removed page title comment (Google ERROR with non utf-8 chars).
Version 1.21 (Ruud Eisinga)
- Added htmlencoding to the url's listed.
- Fixed external url's to be not included in the sitemap.
*/
// -------------------------------------------------------------------------
// CONFIGURATION
// -------------------------------------------------------------------------
// Set configuration values
$sitemap_version = '1.8.6';
// Debug information on / off
$debug = false;
if(isset($_GET['debug'])) $debug = true;
// If shorturl is used, no pages and .php
// For use with shorturl V3: http://www.dev4me.nl/modules-snippets/opensource/shortlinks/
$shorturl = false;
// Ban urls with unwanted words
$exclude = array(); // Array of unwanted words in the url
// eg. array("privat", "do-not-enter", "keep-away")
// Priorities in sitemap should be 0.5 if not set. Google is happy when different priorities are set.
// Normal Pages
$page_priority = "0.5"; // Default priority for normal pages
$page_home_priority = "1.0"; // Homepage priority
$page_root_priority = "0.6"; // Toplevel menu pages priority
$page_frequency = "weekly"; // Update frequency of your pages.
// Allowed: always, hourly, daily, weekly, monthly, yearly, never
// News Module
$news_priority = "0.7"; // News posts of the last 4 weeks
$news_old_priority = "0.5"; // News posts older than 4 weeks
$news_frequency = "weekly"; // News posts update frequency
// Bakery Module
$bakery_priority = "0.5"; //
$bakery_frequency = "weekly"; //
// Catalog Module
$catalogs_priority = "0.5"; //
$catalogs_frequency = "weekly"; //
// Portfolio Module
$portfolio_priority = "0.5"; //
$portfolio_frequency = "weekly"; //
// Topics Module
$topics_mod_name = "topics"; // Name of the module
$topics_priority = "0.5"; //
$topics_frequency = "weekly"; //
// Showcase Module
$showcase_priority = "0.5"; //
$showcase_frequency = "weekly"; //
// OneForAll Module
$oneforall_mod_names = "oneforall"; // Names of the oneforall modules. Seperated by a comma.
//$oneforall_mod_names = "oneforall,projects,portfolio"; // Names of the oneforall modules. Seperated by a comma.
$oneforall_priority = "0.5"; //
$oneforall_frequency = "weekly"; //
// -------------------------------------------------------------------------
// END OF CONFIGURATION
// -------------------------------------------------------------------------
// Include config file
require_once(dirname(__FILE__)."/config.php");
// Check if the config file has been set-up
if(!defined("WB_PATH")) {
die("Website not configured");
}
// Include class frontend
require_once(WB_PATH."/framework/class.frontend.php");
// Create new frontend object
$wb = new frontend();
// Collect general website settings
$wb->get_website_settings();
// Vars
$counter = 0;
$ts = time();
$public = array();
$modules = array();
$debug_info = array();
// Functions
// *********
// Function check_link
function check_link($link, $exclude) {
static $listed = array();
// Check for unwanted words in the url
foreach ($exclude as $value) {
if (strpos($link, $value)) {
$unwanted = ""$link" contains "$value" and will not show up in the google sitemap\n";
return $unwanted;
}
}
// External links should not belong to the google sitemap
if (strpos($link, '://')) {
$unwanted = "$link is an external link and will not show up in the google sitemap\n";
return $unwanted;
}
if (in_array($link , $listed)) {
$unwanted = "$link is already listed\n";
return $unwanted;
}
if (trim($link) === '') {
$unwanted = "Skipped empty link\n";
return $unwanted;
}
$listed[] = $link;
return true;
}
// Function output_xml
function output_xml($link, $lastmod, $freq, $pri) {
global $shorturl;
if($shorturl) {
$linkstart = strlen(WB_URL.PAGES_DIRECTORY);
$linkend = strlen(PAGE_EXTENSION);
$link = WB_URL.substr( $link , $linkstart );
if(substr( $link , 0, -$linkend ) == PAGE_EXTENSION) {
$link = substr( $link , 0, -$linkend ).'/';
} else {
$link = str_replace( PAGE_EXTENSION , '/', $link);
}
}
echo '
<url>
<loc>'.$link.'</loc>
<lastmod>'.$lastmod.'</lastmod>
<changefreq>'.$freq.'</changefreq>
<priority>'.$pri.'</priority>
</url>';
}
// Start with xml header output
// ****************************
if ($debug) {
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<style>
url {
display: block;
}
loc {
font-weight: bold;
line-height: 25px;
}
</style>
</head>
<?php
} else {
@header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
if(file_exists('./google_sitemap.xsl')) echo '<?xml-stylesheet type="text/xsl" href="google_sitemap.xsl"?>'.PHP_EOL;
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
}
// Get public WB pages
// *******************
// Get all pages from db except of the module menu_link
$sql = "SELECT p.`link`, p.`modified_when`, p.`parent`, p.`position`, s.`section_id`, s.`module`
FROM `".TABLE_PREFIX."pages` p
JOIN `".TABLE_PREFIX."sections` s
ON p.`page_id` = s.`page_id`
WHERE (p.`visibility` = 'public')
AND s.`module` != 'menu_link'
AND (s.`publ_start` = '0' OR s.`publ_start` <= $ts)
AND (s.`publ_end` = '0' OR s.`publ_end` >= $ts)
ORDER BY p.`parent`, p.`position` ASC";
$result = $database->query($sql);
// Loop through the pages
if ($result && $result->numRows() > 0) {
while ($page = $result->fetchRow()) {
$checked = check_link($page['link'], $exclude);
if ($checked === true) {
$link = htmlspecialchars($wb->page_link($page['link']));
$lastmod = gmdate("Y-m-d", $page['modified_when']+TIMEZONE);
$freq = $page_frequency;
$pri = $page_priority;
if ($page['parent'] == 0) {
if ($page['position'] == 1) {
$pri = $page_home_priority; // Should be the homepage
$link = WB_URL.'/';
} else {
$pri = $page_root_priority; // Root level pages
}
}
output_xml($link, $lastmod, $freq, $pri);
$counter++;
$public[] = $page['section_id'];
$modules[] = $page['module'];
}
else {
$debug_info[] = $checked;
}
}
}
// All by WB sections currently used modules
$modules = array_unique($modules);
// Count pages excluding module pages
$page_counter = $counter;
// Get module pages of previously set modules
// ******************************************
// News
if (in_array('news', $modules)) {
$sql = "SELECT `section_id`, `link`, `posted_when`, `published_when`
FROM `".TABLE_PREFIX."mod_news_posts`
WHERE `active` = '1'
AND (`published_when` = '0' OR `published_when` <= $ts)
AND (`published_until` = '0' OR `published_until` >= $ts)";
$rs_news = $database->query($sql);
if ($rs_news->numRows() > 0) {
while ($news = $rs_news->fetchRow()) {
if (!in_array($news['section_id'], $public)) continue;
$checked = check_link($news['link'], $exclude);
if ($checked === true) {
$link = htmlspecialchars($wb->page_link($news['link']));
$lastweek = time() - (4 * 7 * 24 * 60 * 60);
if ($news['posted_when'] < $lastweek) {
$news_priority = $news_old_priority;
}
if ((version_compare(WB_VERSION, '2.7.0') <= 0) && $news['published_when'] > 0){
$lastmod = gmdate("Y-m-d", $news['published_when']+TIMEZONE);
} else {
$lastmod = gmdate("Y-m-d", $news['posted_when']+TIMEZONE);
}
output_xml($link, $lastmod, $news_frequency, $news_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
// Bakery
if (in_array('bakery', $modules)) {
$sql = "SELECT `section_id`, `link`, `modified_when`
FROM `".TABLE_PREFIX."mod_bakery_items`
WHERE `active` = '1'";
$rs_bakery = $database->query($sql);
if ($rs_bakery->numRows() > 0) {
while ($bakery = $rs_bakery->fetchRow()) {
if (!in_array($bakery['section_id'], $public)) continue;
$checked = check_link($bakery['link'], $exclude);
if ($checked === true) {
$link = htmlspecialchars($wb->page_link($bakery['link']));
$lastmod = gmdate("Y-m-d", $bakery['modified_when']+TIMEZONE);
output_xml($link, $lastmod, $bakery_frequency, $bakery_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
// Catalog
if (in_array('catalogs', $modules)) {
$sql = "SELECT `section_id`, `link`, `modified_when`
FROM `".TABLE_PREFIX."mod_catalogs_list`
WHERE `active` = '1'";
$rs_catalogs = $database->query($sql);
if ($rs_catalogs->numRows() > 0) {
while ($catalogs = $rs_catalogs->fetchRow()) {
if (!in_array($catalogs['section_id'], $public)) continue;
$checked = check_link($catalogs['link'], $exclude);
if ($checked === true) {
$link = htmlspecialchars($wb->page_link($catalogs['link']));
$lastmod = gmdate("Y-m-d", $catalogs['modified_when']+TIMEZONE);
output_xml($link, $lastmod, $catalogs_frequency, $catalogs_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
// Portfolio
if (in_array('portfolio', $modules)) {
$sql = "SELECT p.`link`, p.`position`, p.`modified_when`, s.`section_id`
FROM `".TABLE_PREFIX."sections` s
JOIN `".TABLE_PREFIX."pages` p
ON s.`page_id` = p.`page_id`
WHERE s.`module` = 'portfolio_detail'
AND p.`position` > '1'
ORDER BY p.`parent`, p.`position` ASC;";
$rs_portfolio = $database->query($sql);
if ($rs_portfolio->numRows() > 0) {
while ($portfolio = $rs_portfolio->fetchRow()) {
$checked = check_link($portfolio['link'], $exclude);
if ($checked === true) {
$length = strrpos($portfolio['link'], '/');
$link = substr($portfolio['link'], 0, $length);
$link = htmlspecialchars($wb->page_link($link)).'?item='.$portfolio['position'];
$lastmod = gmdate("Y-m-d", $portfolio['modified_when']+TIMEZONE);
output_xml($link, $lastmod, $portfolio_frequency, $portfolio_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
// Topics
if (in_array($topics_mod_name, $modules)) {
require(WB_PATH.'/modules/'.$topics_mod_name.'/module_settings.php');
$t = mktime ( (int) gmdate("H"), (int) gmdate("i"), (int) gmdate("s"), (int) gmdate("n"), (int) gmdate("j"), (int) gmdate("Y")) + DEFAULT_TIMEZONE;
$sql = "SELECT `section_id`, `link`, `posted_modified`
FROM `".TABLE_PREFIX."mod_".$topics_mod_name."`
WHERE (`active` > '3' OR `active` = '1')
AND (`published_when` = '0' OR `published_when` < ".$t.")
AND (`published_until` = '0' OR `published_until` > ".$t.")
ORDER BY `position` DESC";
$rs_topics = $database->query($sql);
if($rs_topics->numRows() > 0) {
while($topics = $rs_topics->fetchRow()) {
if (!in_array($topics['section_id'], $public)) continue;
$checked = check_link($topics['link'], $exclude);
if ($checked === true) {
$link = htmlspecialchars(WB_URL.$topics_directory.$topics['link'].PAGE_EXTENSION);
$lastmod = gmdate("Y-m-d", $topics['posted_modified']+TIMEZONE);
output_xml($link, $lastmod, $topics_frequency, $topics_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
// Showcase
if (in_array('showcase', $modules)) {
$sql = "SELECT `section_id`, `link`, `modified_when`
FROM `".TABLE_PREFIX."mod_showcase_items`
WHERE `active` = '1'";
$rs_showcase = $database->query($sql);
if($rs_showcase->numRows() > 0) {
while($showcase = $rs_showcase->fetchRow()) {
if (!in_array($showcase['section_id'], $public)) continue;
$checked = check_link($showcase['link'], $exclude);
if ($checked === true) {
if (!empty($showcase['link'])) {
$path = $database->get_one("SELECT `link` FROM `".TABLE_PREFIX."pages` WHERE `page_id` = (SELECT `page_id` FROM `".TABLE_PREFIX."mod_showcase_items` WHERE `link` = '".$showcase['link']."' LIMIT 1);");
$showcase['link'] = $path.$showcase['link'];
}
$link = htmlspecialchars($wb->page_link($showcase['link']));
$lastmod = gmdate("Y-m-d", $showcase['modified_when']+TIMEZONE);
output_xml($link, $lastmod, $showcase_frequency, $showcase_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
$oneforall_mods = explode(',',$oneforall_mod_names);
foreach ( $oneforall_mods as $oneforall_mod_name) {
$oneforall_mod_name = trim($oneforall_mod_name);
if (in_array($oneforall_mod_name, $modules)) {
$sql = "SELECT `section_id`, `page_id`, `link`, `modified_when`
FROM `".TABLE_PREFIX."mod_".$oneforall_mod_name."_items`
WHERE `active` = '1'";
$rs_oneforall = $database->query($sql);
if($rs_oneforall->numRows() > 0) {
while($oneforall = $rs_oneforall->fetchRow()) {
if (!in_array($oneforall['section_id'], $public)) continue;
$page = $database->get_one("SELECT `link` FROM `".TABLE_PREFIX."pages` WHERE `page_id`='".$oneforall['page_id']."'");
$checked = check_link($page.$oneforall['link'], $exclude);
if ($checked === true) {
$link = htmlspecialchars($wb->page_link($page.$oneforall['link']));
$lastmod = gmdate("Y-m-d", $oneforall['modified_when']+TIMEZONE);
output_xml($link, $lastmod, $oneforall_frequency, $oneforall_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
}
// Add another module here...
// Example code
/*
if (in_array('xxxxxx', $modules)) {
$sql = "SELECT `section_id`, `link`, `modified_when`
FROM `".TABLE_PREFIX."mod_xxxxxx_items`
WHERE `active` = '1'";
$rs_xxxxxx = $database->query($sql);
if($rs_xxxxxx->numRows() > 0) {
while(xxxxxx = $rs_xxxxxx->fetchRow()) {
if (!in_array($xxxxxx['section_id'], $public)) continue;
$checked = check_link(xxxxxx['link'], $exclude);
if ($checked === true) {
$link = htmlspecialchars($wb->page_link($xxxxxx['link']));
$lastmod = gmdate("Y-m-d", $xxxxxx['modified_when']+TIMEZONE);
output_xml($link, $lastmod, $xxxxxx_frequency, $xxxxxx_priority);
$counter++;
}
else {
$debug_info[] = $checked;
}
}
}
}
*/
// Debug
if ($debug) {
echo '<div style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 1em 1em; margin: 1em; line-height: 18px; background-color: #fdd; color: black">';
echo '<h3>DEBUG</h3>';
echo '<h3>Number of Pages</h3>';
echo '<div style="font-family:monospace;font-size:12px">Number of Pages excluding module pages: '.$page_counter.'<br>';
echo 'Number of all Pages including module pages: '.$counter.'</div>';
if (count($debug_info > 0)) {
echo '<h3>Banned Pages</h3><div style="font-family:monospace;font-size:12px">'.implode('', $debug_info).'</div>';
}
echo '</div>';
}
else {
// End xml output
echo "\n".'</urlset>';
}