diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/config.php | 31 | ||||
-rw-r--r-- | lib/helper.php | 8 | ||||
-rw-r--r-- | lib/program.php | 107 |
3 files changed, 146 insertions, 0 deletions
diff --git a/lib/config.php b/lib/config.php new file mode 100644 index 0000000..2b6b78e --- /dev/null +++ b/lib/config.php @@ -0,0 +1,31 @@ +<?php +date_default_timezone_set('Europe/Berlin'); + +// guessed automatically +// $GLOBALS['CONFIG']['baseurl'] = 'http://foo.com/bar/'; + +$GLOBALS['CONFIG']['SCHEDULE'] = 'http://fahrplan.mrmcd.net/schedule.xml'; +$GLOBALS['CONFIG']['SCHEDULE_CACHE_TTL'] = 5*60; +$GLOBALS['CONFIG']['SCHEDULE_SCALE'] = 0.2; // float, px per second + +$GLOBALS['CONFIG']['ROOMS'] = array( + 'saal1' => 'Saal 1', + 'saal2' => 'Saal 2', + 'saalg' => 'Saal G', + 'saal6' => 'Saal 6', + + 'lounge' => 'Lounge', + 'ambient' => 'Ambient', + + 'sendezentrum' => 'Sendezentrum', +); + +$GLOBALS['CONFIG']['FORMATS'] = array( + 'hd' => 'FullHD', + 'hq' => 'High Quality', + 'lq' => 'Low Quality', + 'audio' => 'Audio', + 'slides' => 'Slide-Images', +); + +?> diff --git a/lib/helper.php b/lib/helper.php index 8951948..4dc6f69 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -1,5 +1,7 @@ <?php +require_once('program.php'); + function link_index() { return ''; @@ -46,3 +48,9 @@ function baseurl() return $base; } + +function strtoduration($str) +{ + $parts = explode(':', $str); + return ((int)$parts[0] * 60 + (int)$parts[1]) * 60; +} diff --git a/lib/program.php b/lib/program.php new file mode 100644 index 0000000..900d1d9 --- /dev/null +++ b/lib/program.php @@ -0,0 +1,107 @@ +<?php + +function program() +{ + $cacheidx = __FILE__.':'.__FUNCTION__.':program'; + if(function_exists('apc_fetch') && $program = apc_fetch($cacheidx)) + return $program; + + echo 'fresh'; + $program = array(); + $schedule = simplexml_load_file($GLOBALS['CONFIG']['SCHEDULE']); + + $dayidx = 0; + foreach($schedule->day as $day) + { + $dayidx++; + $daystart = strtotime((string)$day['start']); + $dayend = strtotime((string)$day['end']); + + $roomidx = 0; + foreach($day->room as $room) + { + $roomidx++; + $name = (string)$room['name']; + $lastend = false; + + foreach ($room->event as $event) + { + $start = strtotime((string)$event->date); + $duration = strtoduration((string)$event->duration); + $end = $start + $duration; + + if($lastend && $lastend < $start) + { + // synthesize pause event + $pauseduration = $start - $lastend; + $program[$name][] = array( + 'special' => 'pause', + 'title' => round($pauseduration / 60).' minutes pause', + + 'fstart' => date('c', $lastend), + 'fend' => date('c', $start), + + 'start' => $lastend, + 'end' => $start, + 'duration' => $pauseduration, + ); + } + else if(!$lastend && $daystart < $start) + { + $program[$name][] = array( + 'special' => 'gap', + + 'fstart' => date('c', $daystart), + 'fend' => date('c', $start), + + 'start' => $daystart, + 'end' => $start, + 'duration' => $start - $daystart, + ); + } + + $program[$name][] = array( + 'title' => (string)$event->title, + + 'fstart' => date('c', $start), + 'fend' => date('c', $end), + + 'start' => $start, + 'end' => $end, + 'duration' => $duration, + ); + + $lastend = $end; + } + + // synthesize daychange event + if(!$lastend) $lastend = $daystart; + if($lastend < $dayend) + { + $program[$name][] = array( + 'special' => 'gap', + + 'fstart' => date('c', $lastend), + 'fend' => date('c', $dayend), + + 'start' => $lastend, + 'end' => $dayend, + 'duration' => $dayend - $lastend, + ); + } + + if($dayidx < count($schedule->day)) + { + $program[$name][] = array( + 'special' => 'daychange', + 'title' => 'Daychange from Day '.$dayidx.' to '.($dayidx+1), + ); + } + } + } + + if(function_exists('apc_store')) + apc_store($cacheidx, $program, $GLOBALS['CONFIG']['SCHEDULE_CACHE_TTL']); + + return $program; +} |