From 6f729beebdb1e9993d3afb0a492680194c39d342 Mon Sep 17 00:00:00 2001 From: Oldperl <44996956+oldperl@users.noreply.github.com> Date: Wed, 16 Nov 2011 16:45:21 +0000 Subject: [PATCH] final version 1.0 --- output.php | 113 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 8 deletions(-) diff --git a/output.php b/output.php index ef85d08..05e6233 100644 --- a/output.php +++ b/output.php @@ -13,9 +13,8 @@ * $Id$ */ - $cfgMod = array( - 'debug' => false + 'debug' => true ); // init db-object @@ -30,15 +29,113 @@ if (!is_object($oTpl)) { $oTpl->reset(); // init debugger -cInclude('classes', 'Debug/DebuggerFactory.class.php'); -/* @var $oDebug Debug_VisibleAdv */ -$oDebug = DebuggerFactory::getDebugger('visible_adv'); +if ($cfgMod['debug']) { + cInclude('classes', 'Debug/DebuggerFactory.class.php'); + /* @var $oDebug Debug_VisibleAdv */ + $oDebug = DebuggerFactory::getDebugger('visible_adv'); +} +$oToday = new DateTime(); +if ($cfgMod['debug']) { + if(isset($_GET['dateoffset'])) { + $oToday->modify($_GET['dateoffset']." days"); + } +} + +$oXmasDate = new DateTime(date("Y")."-12-24 23:59:59"); +$oXmasMondayDate = clone $oXmasDate; +$oXmasMondayDate->modify("+2 days"); + +$oFirstAdventDate = new DateTime(date("Y")."-11-26"); +$oFirstAdventDate->modify("next sunday"); + +$oSecondAdvent = clone $oFirstAdventDate; +$oSecondAdvent->modify("+7 days"); + +$oThirdAdvent = clone $oSecondAdvent; +$oThirdAdvent->modify("+7 days"); + +$oFourthAdvent = clone $oThirdAdvent; +$oFourthAdvent->modify("+7 days"); + +if($oToday <= $oXmasMondayDate && $oToday >= $oFirstAdventDate) { + $sImgPath = $cfgClient[$client]['images']."adventskranz/Extra/"; + + if($oToday >= $oFirstAdventDate && $oToday < $oSecondAdvent) { + $sImgPath .= "advent1.gif"; + } else if($oToday >= $oSecondAdvent && $oToday < $oThirdAdvent) { + $sImgPath .= "advent2.gif"; + } else if ($oToday >= $oThirdAdvent && $oToday < $oFourthAdvent) { + $sImgPath .= "advent3.gif"; + } else { + $sImgPath .= "advent4.gif"; + } + + echo '
'; + echo ''.mi18n('; + echo '

'; + // countdown till xmas + $iDaysTillmas = (int) daysdiff( $oXmasDate->format("Y-m-d"), $oToday->format("Y-m-d")); + if($iDaysTillmas > 1) { + printf(mi18n("Noch %s Tage bis Weihnachten"), $iDaysTillmas); + } else if($iDaysTillmas == 1) { + printf(mi18n("Noch %s Tag bis Weihnachten"), $iDaysTillmas); + } else if($iDaysTillmas === 0) { + echo mi18n("Frohe Weihnacht!
(Heiliger Abend)"); + } else { + echo mi18n("Frohe Weihnacht!"); + } + echo "

"; +} -// your code here // show debug & cleanup -if ($cfgMod['debug']) +if ($cfgMod['debug']) { + $oDebug->add($cfgClient, "cfgClient array"); + $oDebug->add($oToday, "Heute DateTime object"); + $oDebug->add($oXmasDate, "Xmas DateTime object"); + $oDebug->add($oFirstAdventDate, "1. Advent DateTime object"); + $oDebug->add($oSecondAdvent, "2. Advent DateTime object"); + $oDebug->add($oThirdAdvent, "3. Advent DateTime object"); + $oDebug->add($oFourthAdvent, "4. Advent DateTime object"); $oDebug->showAll(); + unset($oDebug); +} unset($cfgMod); -unset($oDebug); + +/** + * compare two datetime objects + * workaround of a php-bug in PHP for windows + * + * @author fbastage at yahoo dot com + * @link https://bugs.php.net/bug.php?id=51184 + * @param DateTime $dt1 + * @param DateTime $dt2 + * @param type $timeZone + * @return type + */ +function daysdiff($dt1, $dt2, $timeZone = 'UTC') { + $tZone = new DateTimeZone($timeZone); + + $dt1 = new DateTime($dt1, $tZone); + $dt2 = new DateTime($dt2, $tZone); + + // use the DateTime datediff function IF we have a non-buggy version + // there is a bug in many Windows implementations that diff() always returns + // 6015 + if( $dt1->diff($dt1)->format("%a") != 6015 ) { + return $dt1->diff($dt2)->format("%a"); + } + + // else let's use our own method + + $y1 = $dt1->format('Y'); + $y2 = $dt2->format('Y'); + $z1 = $dt1->format('z'); + $z2 = $dt2->format('z'); + + $diff = intval($y1 * 365.2425 + $z1) - intval($y2 * 365.2425 + $z2); + + return $diff; + +} ?> \ No newline at end of file