make readme rst-compatible
[awstats-helper.git] / functions.php
index 7649f61060ae38250ab436b6f84f805a279b34ac..5ee79a9381ce6a7e8c318ee1e814d2dfd7994183 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 {
@@ -35,6 +54,7 @@ function aws_createHtml($site, $last = false)
        . ' -month=' . $month
        . ' -year=' . $year
        . ' -dir=' . escapeshellarg($dir);
+    echo $cmd . "\n";
     passthru($cmd);
 
     if (!$last) {
@@ -85,8 +105,10 @@ function aws_createGlobalIndex()
     $links = '';
     foreach ($dirs as $dir) {
         $name = basename($dir);
-       $links .= '<li><a href="' . $name . '/">'
-           . $name . '</a></li>';
+       $links .= '<li>'
+        . '<a href="' . $name . '/">' . $name . '</a>'
+        . ' <a href="' . $name . '/current/awstats.' . $name . '.html">[current]</a>'
+        . '</li>';
     }
     $html = <<<XML
 <?xml version="1.0" encoding="utf-8"?>