script to create old historic static pages
authorChristian Weiske <cweiske@cweiske.de>
Sat, 14 Nov 2009 17:52:25 +0000 (18:52 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Sat, 14 Nov 2009 17:52:25 +0000 (18:52 +0100)
create-historic.php [new file with mode: 0644]
functions.php

diff --git a/create-historic.php b/create-historic.php
new file mode 100644 (file)
index 0000000..2977931
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Renders historic data for multiple sites
+ * Does not render static pages if they exist
+ * already.
+ */
+require_once 'functions.php';
+
+foreach (aws_sites() as $site) {
+    $dates = aws_historic($site);
+    foreach ($dates as $date) {
+        list($year, $month) = $date;
+       $dir = $GLOBALS['htmldir'] . '/' . $site . '/' . $year . '-' . $month . '/';
+       if (!is_dir($dir)) {
+           aws_createHtml($site, true, $year, $month);
+       }
+    }
+    aws_createIndex($site);
+}
+
+?>
\ No newline at end of file
index 7649f61060ae38250ab436b6f84f805a279b34ac..803d684a24fe4efa9968ff074872b442e6e925b8 100644 (file)
@@ -10,13 +10,32 @@ function aws_sites()
     return $sites;
 }
 
-function aws_createHtml($site, $last = false)
+function aws_historic($site)
+{
+    $dates = array();
+    foreach (glob($GLOBALS['awdata'] . '/awstats*.' . $site . '.txt') as $file) {
+        $date = explode(
+           '-',
+           preg_replace(
+                '/^.*\/awstats([0-9]{2})([0-9]{4})\\.' . $site . '.txt$/',
+               '\\2-\\1',
+               $file
+            )
+        );
+       count($date) == 2 && $dates[] = $date;
+    }
+    return $dates;
+}
+
+function aws_createHtml($site, $last = false, $year = null, $month = null)
 {
     if (!is_dir($GLOBALS['htmldir'])) {
         die("HTML directory " . $GLOBALS['htmldir'] . " does not exist\n");
     }
 
-    if ($last) {
+    if ($year !== null && $month !== null) {
+        //already set
+    } else if ($last) {
         $month = date('m', strtotime('last month'));
         $year  = date('Y', strtotime('last month'));
     } else {