From: Evan Prodromou Date: Mon, 11 Aug 2008 20:00:58 +0000 (-0400) Subject: correct sitemapindex output X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e90004964fdb60e88e5e77d0ee035679c251ccfd;p=quix0rs-gnu-social.git correct sitemapindex output darcs-hash:20080811200058-84dde-8a45ed98a331d3b53ba8e50494e44f52928c7a04.gz --- diff --git a/sitemap.php b/sitemap.php index ae40d7a89a..ca18196586 100644 --- a/sitemap.php +++ b/sitemap.php @@ -29,7 +29,7 @@ function index_map() { # Just the file name please. $file_name = preg_replace("|$output_dir|", '', $file_name); - $index_urls .= url( + $index_urls .= sitemap( array( 'url' => $output_url . $file_name, 'changefreq' => 'daily' @@ -37,8 +37,7 @@ function index_map() { ); } - write_file($output_paths['index_file'], urlset($index_urls)); - + write_file($output_paths['index_file'], sitemapindex($index_urls)); } # Generate sitemap of standard site elements. @@ -274,6 +273,26 @@ function url($url_args) { return $url_out; } +function sitemap($sitemap_args) { + $url = preg_replace('/&/', '&', $sitemap_args['url']); # escape ampersands for XML + $lastmod = $sitemap_args['lastmod']; + + if (is_null($url)) { + error("url() arguments require 'url' value."); + } + + $sitemap_out = "\t\n"; + $sitemap_out .= "\t\t$url\n"; + + if ($lastmod) { + $sitemap_out .= "\t\t$lastmod\n"; + } + + $sitemap_out .= "\t\n"; + + return $sitemap_out; +} + # Generate a element. function urlset($urlset_text) { $urlset = '' . "\n" . @@ -284,6 +303,16 @@ function urlset($urlset_text) { return $urlset; } +# Generate a element. +function sitemapindex($sitemapindex_text) { + $sitemapindex = '' . "\n" . + '' . "\n" . + $sitemapindex_text . + ''; + + return $sitemapindex; +} + # Generate a sitemap from an array containing elements and write it to a file. function array_to_map($url_list, $filename_prefix) { global $output_paths;