From 9a247f1c1ef2bc01292f649d29a9f417b1a89d18 Mon Sep 17 00:00:00 2001
From: Joey Schulze
Date: Sun, 15 Jun 2008 09:23:28 +0000
Subject: [PATCH] Move functions into include file
---
src/Termine/index.wml | 85 +++----------------------------------------
src/Termine/years.inc | 78 +++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 80 deletions(-)
diff --git a/src/Termine/index.wml b/src/Termine/index.wml
index fd554e2..305848d 100644
--- a/src/Termine/index.wml
+++ b/src/Termine/index.wml
@@ -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 = ''
- .''
- .' %s | '
- .'Ort | '
- .'Zeit | '
- .'
';
- $layout_row = ''
- .' %d. (%s) | '
- .'%s | '
- .'%s | '
- .'%s | '
- .'
';
- $layout_foot = '
';
+
- $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 = '' . $match[5] . '';
- 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");
?>
@@ -94,9 +20,8 @@ Veranstaltung in Oldenburg statt.
Sollte eine Veranstaltung fehlen, kontaktieren Sie bitte joey@infodrom.org.
- display_dates() ?>
+ display_dates(); ?>
-
diff --git a/src/Termine/years.inc b/src/Termine/years.inc
index 6e1d81e..4fb3dae 100644
--- a/src/Termine/years.inc
+++ b/src/Termine/years.inc
@@ -79,6 +79,84 @@
:>
+
+
+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;
+
+
+ $layout_head = ''
+ .''
+ .' %s | '
+ .'Ort | '
+ .'Zeit | '
+ .'
';
+ $layout_row = ''
+ .' %d. (%s) | '
+ .'%s | '
+ .'%s | '
+ .'%s | '
+ .'
';
+
+ $layout_foot = '
';
+
+ $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 = '' . $match[5] . '';
+ 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;
+}
+?>
+
# Local variables:
# mode: indented-text
--
2.20.1