Display current events on the main page automatically
[infodrom.org/oldenburg.linux.de] / src / index.wml
index 8ff52e7..ab9d34c 100644 (file)
@@ -1,4 +1,144 @@
 #include <LUGO.style>
+#include <tools.inc>
+
+<?
+$max_news = 2;
+$max_age = 7;
+$newsdir = "News";
+$datedb = "Termine/dates.txt";
+$max_days = 14;
+
+function next_date()
+{
+  global $max_days;
+  global $datedb;
+
+  $head = '<div class="news"><div class="newsbody"><h3 class="newstitle">%s</h3><div class="date">';
+  $head .= '<table class="font" cellpadding=1 cellspacing=2 width=100%%><tr><th>Wann</th><th>Was</th><th>Wo</th></tr>';
+  $foot = '</table></div></div></div>';
+  $row = '<tr%s><td>%s</td><td>%s</td><td>%s</td></tr>';
+  $pivot = time() + 60*60*24*$max_days;
+  $now = mktime(0,0,0, date('m'), date('d'), date('Y'));
+
+  if (($dates = fopen($datedb,'r')) !== false) {
+    $lines = array();
+    while (!feof($dates)) {
+      $line = fgets($dates, 200);
+
+      if (!preg_match("/\|OL\|/", $line))
+       continue;
+
+      if (preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})\|/", $line, $match)) {
+       $when = mktime(0,0,0, $match[2], $match[3], $match[1]);
+       if ($when > $pivot || $when < $now)
+         continue;
+       $lines[] = $line;
+      }
+    }
+
+    if (count($lines)) {
+      sort($lines);
+      echo '<div style="padding-top: 10px"></div>'."\n";
+      printf($head."\n", "Kommende Termine in Oldenburg");
+
+      foreach ($lines as $line) {
+       if (preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})\|([^\|]*)\|OL\|([^\|]*)\|([^\|]*)\|(.*)/", $line, $match)) {
+         $when = mktime(0,0,0, $match[2], $match[3], $match[1]);
+
+         if ($when == $now) {
+           $date = '<strong>heute, ' . $match[4].'</strong>';
+           $color = ' bgcolor="#79c2ef"';
+         } else {
+           $date = strftime("%e.%m.%y", $when) . ', ' . $match[4];
+           $color = '';
+         }
+
+         if (empty($match[7]))
+           $what = $match[5];
+         else
+           $what = '<a href="'.$match[7].'">'.$match[5].'</a>';
+
+         printf($row, $color, $date, $what, $match[6]);
+       }
+      }
+      echo $foot;
+    }
+  }
+}
+function display_news($when, $file)
+{
+  global $newsdir;
+
+  $head = '<div class="news"><div class="newsbody"><h3 class="newstitle">%s</h3><div class="newscontent">';
+  $foot = '</div></div></div>';
+
+  $date = strftime("%e. %B %Y", $when);
+
+  if (($news = fopen($newsdir.'/'.$file,'r')) !== false) {
+    $needp = 0;  // 0 = init, 1 = <p> need, 2 = no <p> needed
+
+    printf($head."\n", $date);
+    while (!feof($news)) {
+      $line = fgets($news, 200);
+
+      $line = str_replace ("\\\n", "", $line);
+
+      if ($needp == 0) {
+       if (substr($_, 0, 3) == "<p>") {
+         $needp = 2;
+       } else {
+         $needp = 1;
+         $line = '<p>'.$line;
+       }
+      }
+
+      echo $line;
+    }
+    if ($needp == 1)
+      echo '</p>';
+    echo $foot;
+  }
+}
+
+function newsbox()
+{
+  global $max_news;
+  global $max_age;
+  global $newsdir;
+
+  setlocale(LC_TIME, "de_DE");
+
+  $pivot = time() - 60*60*24*$max_age;
+  $news = array();
+  if (is_dir($newsdir)) {
+    if ($dir = opendir($newsdir)) {
+      while (($file = readdir($dir)) !== false) {
+       if (!preg_match("/news-([0-9]{4})-([0-9]{2})-([0-9]{2})\.txt/", $file, $matches))
+         continue;
+       $when = mktime(0,0,0, $matches[2], $matches[3], $matches[1]);
+       if ($when < $pivot)
+         continue;
+       $news[$when] = $file;
+      }
+      closedir($dir);
+    }
+  }
+
+  if (count($news)) {
+    echo '<div style="padding-top: 10px"></div>'."\n";
+
+    krsort($news);
+
+    $cnt = 0;
+    foreach ($news as $time => $file) {
+      if ($cnt >= $max_news)
+       continue;
+      display_news($time, $file);
+      $cnt++;
+    }
+  }
+}
+?>
 
 <page>
 
@@ -9,6 +149,8 @@ Oldenburg trifft sich regelm
 href="<root_prefix>Infos/stammtisch.html">Oldenburger Linux-Stammtisch</a>
 und unregelmäßig auf weiteren Treffen.</p>
 
+<?next_date()?>
+
 <p>Außerhalb dieser Treffen wird auf der <a
 href="<root_prefix>Infos/liste.html">Mailing-Liste</a>
 linux-stammtisch (<a href="<url ml-linux-stammtisch>">Archiv</a>) über
@@ -27,18 +169,8 @@ vern
 seine breite Hardwareunterst&uuml;tzung ist es f&uuml;r Privatanwender
 genauso interessant, wie f&uuml;r den gewerblichen Einsatz.  <p>
 
-<center>
-    <p><font face="Helvetica,Arial"><b>Sommer 2004</b></font><p>
-    <a href="http://www.linuxtag.de/">\
-<img src=<root_prefix>images/ltlogo-small.gif width=97 height=64 border=0 alt="[LinuxTag-Logo]"></a>
-</center>
-
 <p>
-<div align=center>
-    <font face="Helvetica,Arial"><b><a
-    href="http://www.i21k.de/radtour/">Hier</a> geht es zu Bildern von der
-    Pinguin Radtour 2003.</b></font>
-</div>
+<?newsbox()?>
 
 </page>