forked from jdevalk/XML-Sitemap-PHP-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml-sitemap.php
73 lines (55 loc) · 2.06 KB
/
xml-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
<?php
/**
* XML Sitemap PHP Script
* For more info, see: http://yoast.com/xml-sitemap-php-script/
* Copyright (C), 2011 - 2012 - Joost de Valk, [email protected]
*/
require './config.php';
// Get the keys so we can check quickly
$replace_files = array_keys( $replace );
// Sent the correct header so browsers display properly, with or without XSL.
header( 'Content-Type: application/xml' );
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
$ignore = array_merge( $ignore, array( '.', '..', 'config.php', 'xml-sitemap.php' ) );
if ( isset( $xsl ) && !empty( $xsl ) )
echo '<?xml-stylesheet type="text/xsl" href="' . SITEMAP_DIR_URL . $xsl . '"?>' . "\n";
function parse_dir( $dir, $url ) {
global $ignore, $filetypes, $replace, $chfreq, $prio;
$handle = opendir( $dir );
while ( false !== ( $file = readdir( $handle ) ) ) {
// Check if this file needs to be ignored, if so, skip it.
if ( in_array( utf8_encode( $file ), $ignore ) )
continue;
if ( is_dir( $file ) ) {
if ( defined( 'RECURSIVE' ) && RECURSIVE )
parse_dir( $file, $url . $file . '/' );
}
// Check whether the file has on of the extensions allowed for this XML sitemap
$fileinfo = pathinfo( $dir . $file );
if ( in_array( $fileinfo['extension'], $filetypes ) ) {
// Create a W3C valid date for use in the XML sitemap based on the file modification time
if (filemtime( $dir .'/'. $file )==FALSE) {
$mod = date( 'c', filectime( $dir . $file ) );
} else {
$mod = date( 'c', filemtime( $dir . $file ) );
}
// Replace the file with it's replacement from the settings, if needed.
if ( in_array( $file, $replace ) )
$file = $replace[$file];
// Start creating the output
?>
<url>
<loc><?php echo $url . rawurlencode( $file ); ?></loc>
<lastmod><?php echo $mod; ?></lastmod>
<changefreq><?php echo $chfreq; ?></changefreq>
<priority><?php echo $prio; ?></priority>
</url><?php
}
}
closedir( $handle );
}
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><?php
parse_dir( SITEMAP_DIR, SITEMAP_DIR_URL );
?>
</urlset>