Move functions into include file
authorJoey Schulze <joey@infodrom.org>
Sun, 15 Jun 2008 09:23:28 +0000 (09:23 +0000)
committerJoey Schulze <joey@infodrom.org>
Sun, 15 Jun 2008 09:23:28 +0000 (09:23 +0000)
src/Termine/index.wml
src/Termine/years.inc

index fd554e2..305848d 100644 (file)
@@ -2,85 +2,11 @@
 #include "stacheltermine.inc"
 #include "years.inc"
 
-<?
-$datedb = "dates.txt";
-
-$dates = array();
-function readdb()
-{
-  global $datedb;
-  global $dates;
-
-  if (($db = fopen($datedb,'r')) !== false) {
-    $lines = array();
-    while (!feof($db)) {
-      $line = fgets($db, 200);
-
-      if (!preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})\|/", $line))
-       continue;
-
-      $dates[] = $line;
-    }
-  }
-}
-
-function display_dates()
-{
-  global $dates;
-
-  $layout_head = '<div style="padding-top: 10px;"></div>'
-               .'<table class="dates" width="100%%" border="0" cellpadding="0" cellspacing="0">'
-               .'<tr bgcolor="#aeaeae"><th align="left" colspan="2"><strong>&nbsp;%s</strong></th>'
-               .'<td align="left">Ort</td>'
-               .'<td align="center">Zeit</td>'
-               .'</tr>';
-  $layout_row = '<tr bgcolor=#%s>'
-              .'<td align=left width=20%%>&nbsp;%d. (%s)</td>'
-              .'<td align=left width=60%%>%s</td>'
-              .'<td align=left width=15%%>%s</td>'
-              .'<td align=right width=5%%>%s&nbsp;</td>'
-              .'</tr>';
-  $layout_foot = '</table>';
+<php_utils>
 
-  $nowstring = date("Y-m-");
-  $today = mktime(0,0,0, date('m'), date('d'), date('Y'));
-
-  sort($dates);
-  $cmon = false;
-  $color = 'ffffff';
-  foreach ($dates as $line) {
-    if ($line < $nowstring)
-      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 ($match[1] !== $thisyear || $match[2] !== $thismonth) {
-        if ($cmon)
-         echo $layout_foot;
-        $thisyear = $match[1];
-        $thismonth = $match[2];
-       printf($layout_head, strftime("%B %Y", $when));
-       $cmon = true;
-      }
-      if (strlen($match[7]))
-       $title = '<a href="' . $match[7] . '">' . $match[5] . '</a>';
-      else
-       $title = $match[5];
-
-      if ($when == $today)
-        $color = 'ffff00';
-      printf($layout_row, $color, $match[3], strftime("%A", $when), $title, $match[6], $match[4]);
-      $color = $color == 'ffffff'?'d7d7d7':'ffffff';
-    }
-  }
-  if ($cmon)
-    echo $layout_foot;
-}
-
-setlocale(LC_TIME, "de_DE");
-readdb();
+<?
+  setlocale(LC_TIME, "de_DE");
+  $dates = readdb("dates.txt");
 ?>
 
 <page name=Termine>
@@ -94,9 +20,8 @@ Veranstaltung in Oldenburg statt.</p>
 
 <p>Sollte eine Veranstaltung fehlen, kontaktieren Sie bitte joey@infodrom.org.</p>
 
-<? display_dates() ?>
+<? display_dates(); ?>
 
-<build_tables>
 <more_years>
 
 </page>
index 6e1d81e..4fb3dae 100644 (file)
 :>
 </define-tag>
 
+<define-tag php_utils>
+<?
+function readdb($datedb)
+{
+  $dates = array();
+
+  if (($db = fopen($datedb,'r')) !== false) {
+    $lines = array();
+    while (!feof($db)) {
+      $line = fgets($db, 200);
+
+      if (!preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})\|/", $line))
+       continue;
+
+      $dates[] = $line;
+    }
+  }
+  return $dates;
+}
+
+function display_dates()
+{
+  global $dates;
+
+<protect>
+  $layout_head = '<div style="padding-top: 10px;"></div>'
+               .'<table class="dates" width="100%%" border="0" cellpadding="0" cellspacing="0">'
+               .'<tr bgcolor="#aeaeae"><th align="left" colspan="2"><strong>&nbsp;%s</strong></th>'
+               .'<td align="left">Ort</td>'
+               .'<td align="center">Zeit</td>'
+               .'</tr>';
+  $layout_row = '<tr bgcolor=#%s>'
+              .'<td align=left width=20%%>&nbsp;%d. (%s)</td>'
+              .'<td align=left width=60%%>%s</td>'
+              .'<td align=left width=15%%>%s</td>'
+              .'<td align=right width=5%%>%s&nbsp;</td>'
+              .'</tr>';
+</protect>
+  $layout_foot = '</table>';
+
+  $nowstring = date("Y-m-");
+  $today = mktime(0,0,0, date('m'), date('d'), date('Y'));
+
+  sort($dates);
+  $cmon = false;
+  $color = 'ffffff';
+  foreach ($dates as $line) {
+    if ($line < $nowstring)
+      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 ($match[1] !== $thisyear || $match[2] !== $thismonth) {
+        if ($cmon)
+         echo $layout_foot;
+        $thisyear = $match[1];
+        $thismonth = $match[2];
+       printf($layout_head, strftime("%B %Y", $when));
+       $cmon = true;
+      }
+      if (strlen($match[7]))
+       $title = '<a href="' . $match[7] . '">' . $match[5] . '</a>';
+      else
+       $title = $match[5];
+
+      if ($when == $today)
+        $color = 'ffff00';
+      printf($layout_row, $color, $match[3], strftime("%A", $when), $title, $match[6], $match[4]);
+      $color = $color == 'ffffff'?'d7d7d7':'ffffff';
+    }
+  }
+  if ($cmon)
+    echo $layout_foot;
+}
+?>
+</define-tag>
 
 # Local variables:
 # mode: indented-text