152 Zeilen
Kein EOL
4,8 KiB
PHP
152 Zeilen
Kein EOL
4,8 KiB
PHP
<?php
|
|
/**
|
|
* Modul Output: Ewiger Advents Kalender
|
|
*
|
|
* @package Module
|
|
* @subpackage calendars
|
|
* @version $Rev$
|
|
* @author Ortwin Pinke <o.pinke@php-backoffice.de>
|
|
* @copyright 2011 PHP-Backoffice
|
|
* @link www.php-backoffice.de
|
|
* @link http://www.contenido.org
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
$cfgMod = array(
|
|
'debug' => false,
|
|
'eak_imgset' => 'default/',
|
|
'show_countdown' => true
|
|
);
|
|
|
|
// init db-object
|
|
if (!is_object($oDb)) {
|
|
$oDb = new DB_Contenido();
|
|
}
|
|
|
|
// init template
|
|
if (!is_object($oTpl)) {
|
|
$oTpl = new Template();
|
|
}
|
|
$oTpl->reset();
|
|
|
|
// init debugger
|
|
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]['path']['htmlpath'].getEffectiveSetting('adventskranz', 'imghtmlpath', "images/adventskranz/".$cfgMod['eak_imgset']);
|
|
$bShowCountDown = getEffectiveSetting('adventskranz', 'show_countdown', $cfgMod['show_countdown']);
|
|
|
|
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 '<div id="adventskranz" style="position: relative; width: 200px; margin: auto; text-align: center;">'."\n";
|
|
echo '<!-- Der Ewige Adventskranz 1.0 fuer Contenido, (c)2011 PHP-Backoffice <www.php-backoffice.de> -->'."\n";
|
|
echo '<img src="'.$sImgPath.'" alt="'.mi18n("Der ewige Adventskranz").'" />'."\n";
|
|
|
|
if($bShowCountDown) {
|
|
echo '<p class="eak_countdown">'."\n";
|
|
// 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!<br/>(Heiliger Abend)");
|
|
} else {
|
|
echo mi18n("Frohe Weihnacht!");
|
|
}
|
|
echo "</p>"."\n";
|
|
}
|
|
echo '<div style="position: absolute; width:20px; height:20px; top:0; right: 0;">
|
|
<a href="http://sandbox.dceserver.de/deutsch/module/ewiger-adventskranz/index.html" style="color: #aaa; textdecoration: none; cursor: pointer;"
|
|
title="Der Ewige Adventskranz 1.0 fuer Contenido (c)2011 PHP-Backoffice">©</a></div>';
|
|
echo "</div>"."\n";
|
|
}
|
|
|
|
// show debug & cleanup
|
|
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);
|
|
|
|
/**
|
|
* 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(version_compare(phpversion(), "5.3", ">=") && $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;
|
|
|
|
}
|
|
?>
|