date_default_timezone_set('Europe/Vienna');
$archiveSelector = 'archiv';
$selectedYear = $_GET['jahr'];
$selectedArchiveYear = $_GET['archivjahr'];
$currentYear = date('Y');
$startingYear = $currentYear;
$allowedYearsInAdvance = 1;
// If no year is set or an invalid value, take the current year.
if (null === $selectedYear or (!is_numeric($selectedYear) and $selectedYear !== $archiveSelector) or $selectedYear < $startingYear or $selectedYear > ($currentYear + $allowedYearsInAdvance)) {
$selectedYear = $currentYear;
}
// Detect the year of the first event of all.
$firstYear = null;
$firstEventArray = EM_Events::get(array('scope' => 'past', 'limit' => 1,'orderby' => 'event_start_date', 'order' => 'ASC'));
if (sizeof($firstEventArray) > 0) {
$firstEvent = $firstEventArray[0];
$firstYear = date('Y', strtotime($firstEvent->event_start_date));
}
if (null === $selectedArchiveYear or !is_numeric($selectedArchiveYear) or $selectedArchiveYear < $startingYear or $selectedYear > ($currentYear - 1)) {
$selectedArchiveYear = $currentYear - 1;
}
Woody Snippet
// List all years.
echo '<div class="sub-page-selector-wrapper"><ul class="sub-page-selector">';
echo '<li'.(($selectedYear === $archiveSelector) ? ' class="selected"' : '').'><a href="/termine/?jahr='.$archiveSelector.'">Archiv</span></a></li>';
for ($i = $startingYear; $i <= ($currentYear + $allowedYearsInAdvance); $i++) {
echo '<li'.(($i == $selectedYear) ? ' class="selected"' : '').'><a href="/termine/?jahr='.$i.'"><span>'.$i.'</span></a></li>';
}
echo '</ul></div>';
// Submenu for archive years
if ($selectedYear == $archiveSelector) {
echo '<div class="sub-page-selector-wrapper archive"><ul class="sub-page-selector">';
for ($i = $firstYear; $i < $currentYear; $i++) {
echo '<li'.(($i == $selectedArchiveYear) ? ' class="selected"' : '').'><a href="/termine/?jahr=archiv&archivjahr='.$i.'"><span>'.$i.'</span></a></li>';
}
echo '</ul></div>';
}
// Events this year and future.
if ($selectedYear !== $archiveSelector) {
if ($selectedYear >= $currentYear) {
echo '<h2>Aktuelle Termine '.htmlentities($selectedYear).'</h2>';
echo '<div class="current-events">';
$scope = $selectedYear.'-01-01,'.$selectedYear.'-12-31';
if ($selectedYear == $currentYear) {
$scope = $selectedYear.date('-m-d').','.$selectedYear.'-12-31';
}
// Include the events list of the selected year.
echo EM_Events::output(array('scope' => $scope, 'orderby' => 'event_start_date', 'order' => 'asc'));
echo '</div>';
}
if ($selectedYear === $currentYear) {
echo '<h2>Vergangene Termine '.htmlentities($selectedYear).'</h2>';
echo '<div class="past-events">';
$scope = $selectedYear.'-01-01,'.$selectedYear.'-12-31';
if ($selectedYear == $currentYear) {
$scope = $selectedYear.'-01-01'.','.$selectedYear.date('-m-d');
}
// Include the events list of the selected year.
echo EM_Events::output(array('scope' => $scope, 'orderby' => 'event_start_date', 'order' => 'asc'));
echo '</div>';
}
} else {
// Past events.
echo '<h2>Archiv: Termine '.htmlentities($selectedArchiveYear).'</h2>';
echo '<div class="past-events">';
$scope = $selectedArchiveYear.'-01-01'.','.$selectedArchiveYear.date('-12-31');
// Include the events list of the selected year.
echo EM_Events::output(array('scope' => $scope, 'orderby' => 'event_start_date', 'order' => 'asc'));
echo '</div>';
}
CONTENTS