Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-type: text/xml");
- header("Cache-Control: private, max-age=10800, pre-check=10800");
- header("Pragma: private");
- header("Expires: " . date(DATE_RFC822, strtotime("2 day")));
- if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
- header('Last-Modified: ' . $_SERVER['HTTP_IF_MODIFIED_SINCE'], true, 304);
- exit;
- }
- $config = array(
- 'startDir' => '.',
- 'includeDir' => true,
- 'include' => array(
- "hourly" => array(''),
- "daily" => array('pdf'),
- "weekly" => array('php'),
- "monthly" => array('')
- ),
- 'exclude' => array(
- '/includes',
- '/xml',
- '/images',
- '/javascript',
- '/css',
- '/sitemap.php'
- )
- );
- //begin
- echo '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
- scanDirectory($config['startDir'], $config);
- echo '</urlset>';
- function scanDirectory($path, $config) {
- if (substr($path, 0, 1) == '.') {
- $path = substr($path, 1);
- }
- if (is_readable('.' . $path)) {
- if (is_dir('.' . $path)) {
- if ($config['includeDir']) {
- $time = date("c", filemtime($path));
- echo '<url><loc>http://' . $_SERVER["SERVER_NAME"] . $path . '</loc><lastmod>' . $time . '</lastmod><changefreq>weekly</changefreq><priority>0.5</priority></url>';
- }
- readFiles('.' . $path, $config);
- }
- }
- }
- function readFiles($dir, $config) {
- $directory_list = opendir($dir);
- while($file = readdir($directory_list)) {
- if ($file != '.' && $file != '..') {
- $path = $dir . "/" . $file;
- if (is_readable($path)) {
- if (substr($path, 0, 1) == '.') {
- $path = substr($path, 1);
- }
- if (!in_array($path, $config['exclude'])) {
- if (is_dir('.' . $path)) {
- scanDirectory('.' . $path, $config);
- }
- else if (is_file('.' . $path)) {
- $extension = end(explode('.', $path));
- foreach($config['include'] as $change => $files) {
- if (in_array($extension, $files)) {
- $time = date("c", filemtime('.' . $path));
- echo '<url><loc>http://' . $_SERVER["SERVER_NAME"] . $path . '</loc><lastmod>' . $time . '</lastmod><changefreq>' . $change . '</changefreq><priority>0.5</priority></url>';
- }
- }
- }
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement