4 * Updates all files within our jurisdiction.
5 * @note This wants to be in a post-commit hook!
10 $xc = XHTMLCompiler
::getInstance();
12 // if in command line mode, allow more options
14 if ($cli = (!ini_get('register_globals') && !empty($argv))) {
16 $type = isset($argv[1]) ?
$argv[1] : 'normal'; // see below
18 header('Content-type: text/plain');
21 // display a help file
22 if ($type == 'help') {
24 'php update.php [type] -- Updates compiled HTML files.
26 . normal : update existing files, remove orphans (default)
27 . all : normal + create files without cached output
28 . force : regenerate all files
29 . clean : remove all cache and dependency files
35 if ($type == 'clean') {
37 $allowed_dirs = $xc->getConf('allowed_dirs');
38 foreach ($allowed_dirs as $dir => $recursive) {
39 $dir = new XHTMLCompiler_Directory($dir);
41 // cleanup HTML cache files
42 $files = $dir->scan('.html', $recursive);
43 foreach ($files as $file) {
44 if (!is_created_by_us($file)) continue;
48 // cleanup dependency files
49 $files = $dir->scan('.xc-deps', $recursive);
50 foreach ($files as $file) unlink($file);
52 // cleanup RSS files (probably should be somewhere else)
53 $files = $dir->scan('.rss', $recursive);
54 foreach ($files as $file) {
55 $contents = file_get_contents($file);
56 if (strpos($contents, '<generator>XHTML Compiler</generator>') !== false) {
63 echo 'Removed all cache and dependency files.';
72 $allowed_dirs = $xc->getConf('allowed_dirs');
74 foreach ($allowed_dirs as $dir => $recursive) {
75 $dir = new XHTMLCompiler_Directory($dir);
76 // search for source files
77 $files = $dir->scan('.xhtml', $recursive);
78 foreach ($files as $file) {
79 $page = new XHTMLCompiler_Page($file);
80 if ($type == 'all' && !$page->isCacheExistent()) {
81 // generate a new page
83 $created[] = $page->getCachePath();
84 } elseif ($type == 'force') {
86 $updated[] = $page->getCachePath();
89 // search for cache files
90 $files = $dir->scan('.html', $recursive);
91 foreach ($files as $file) {
92 $page = new XHTMLCompiler_Page($file, true);
93 // we're only updating files, not creating new ones
94 if ($page->isSourceExistent()) {
96 // don't do it for force, since it's already been done
98 $page->isCacheExistent() &&
102 $updated[] = $page->getCachePath();
104 } elseif (is_created_by_us($page->getCachePath())) {
105 unlink($page); // orphan
106 $orphans[] = $page->getCachePath();
111 // nice error message
112 if (empty($updated)) $updated[] = '(none)';
113 echo wordwrap('Updated pages: ' . implode(', ', $updated)) . PHP_EOL
;
115 if (empty($orphans)) $orphans[] = '(none)';
116 echo wordwrap('Removed orphans: ' . implode(', ', $orphans)) . PHP_EOL
;
118 if ($cli && ($type != 'force')) {
119 if (empty($created)) $created[] = '(none)';
120 echo wordwrap('Created pages: ' . implode(', ', $created)) . PHP_EOL
;