diff --git a/engine/Sitemap.php b/engine/Sitemap.php new file mode 100644 index 0000000..a0ccee1 --- /dev/null +++ b/engine/Sitemap.php @@ -0,0 +1,105 @@ +' . "\n"; + file_put_contents(self::$xml_file_path, $t); + + $t = '' . "\n"; + file_put_contents(self::$xml_file_path, $t, FILE_APPEND); + } + + private static function write_closing() + { + $t = '' . "\n"; + file_put_contents(self::$xml_file_path, $t, FILE_APPEND); + } + + private static function process_cache() + { + if (is_dir(self::$cache_path)) { + if ($dh = opendir(self::$cache_path)) { + while ( ($file = readdir($dh) ) !== false) { + if (substr($file, 0, 4) != "dir-") continue; + $fullpath = self::$cache_path . '/' . $file; + $fileinfo = unserialize(file_get_contents($fullpath)); + foreach ($fileinfo as $key => $value) { + $filename = pathinfo($key, PATHINFO_FILENAME); + $parent = array_pop(split("/", pathinfo($key, PATHINFO_DIRNAME))); + $ts = array_shift(split("-", $value)); + if ($parent == "pages") + { + self::entry($filename, $ts, self::$page_changefreq, self::$page_priority); + } + elseif (pathinfo($key, PATHINFO_EXTENSION) == substr(UPDATER::$post_extension, 1)) + { + $location = substr($filename, 0, 4) . "/" . substr($filename, 4, 2) . "/" . substr($filename, 6, 2) . "/"; + $location .= substr($filename, 12); + self::entry($location, $ts, self::$post_changefreq, self::$post_priority); + } + } + } + } + } + } + + private static function entry($loc, $lastmod_timestamp, $changefreq, $priority) + { + $entry = ""; + $entry .= "" . "\n"; + $entry .= "" . POST::$blog_url . $loc . "" . "\n"; + $entry .= "" . date("Y-m-d", $lastmod_timestamp) . "" . "\n"; + $entry .= "" . $changefreq . "" . "\n"; + $entry .= "" . $priority . "" . "\n"; + $entry .= "" . "\n\n"; + + file_put_contents(self::$xml_file_path, $entry, FILE_APPEND); + } + + private static function generate_robot_file() + { + error_log("writing robots.txt"); + file_put_contents(self::$robots_file_path, "User-agent: *" . "\n"); + file_put_contents(self::$robots_file_path, "Disallow:" . "\n", FILE_APPEND); + file_put_contents(self::$robots_file_path, "" . "\n", FILE_APPEND); + file_put_contents(self::$robots_file_path, "SITEMAP: " . Post::$blog_url . self::$sitemap_name . "\n", FILE_APPEND); + } +} diff --git a/engine/Updater.php b/engine/Updater.php index 3c51c52..d1c1bad 100755 --- a/engine/Updater.php +++ b/engine/Updater.php @@ -2,6 +2,7 @@ require_once(dirname(__FILE__) . '/Post.php'); require_once(dirname(__FILE__) . '/Hook.php'); +require_once(dirname(__FILE__) . '/Sitemap.php'); class Updater { @@ -675,6 +676,10 @@ private static function _update($restart_if_resequenced = true) ); } } + + if ((self::$changes_were_written) || (Sitemap::should_write_sitemap(self::$dest_path))) { + Sitemap::write_sitemap(self::$dest_path, self::$cache_path); + } } }