ctdo.de/app/php/events.php

132 lines
4.0 KiB
PHP
Raw Normal View History

<?php
function scan_for_events() {
$s = scandir(__DIR__ . '/../events/', SCANDIR_SORT_DESCENDING);
$output = array();
foreach ($s as $f) {
if(count(str_split($f)) >= 4 && $f != 'treff.md' && $f != 'topictreff.md' && $f != 'repaircafe.md' && $f != 'brunch.md')
$output[] = $f;
}
return $output;
}
function generate_event_list($limit = -1, $page = 0) {
$events = scan_for_events();
$output = "";
if ($limit == -1) {
foreach ($events as $event) {
$lines = file(__DIR__ . '/../events/' . $event);
$title = $lines[0];
$desc = $lines[1];
$date = $lines[2];
$veranstaltungsort = $lines[4];
$output .= '<div class="eventblock"><a href="?page=events&id='.str_replace('.md', '', $event).'"><h3 class="a">'.$veranstaltungsort.'</h3><h3 class="b">'.$date.'</h3><h2>'.$title.'</h2><p>'.$desc.'</p></a></div>';
}
} else {
$start_index = $page * $limit;
$end_index = $start_index + $limit;
if($end_index > count($events))
$end_index = count($events);
for ($i = $start_index; $i < $end_index; $i++) {
$event = $events[$i];
$lines = file(__DIR__ . '/../events/' . $event);
$title = $lines[0];
$desc = $lines[1];
$date = $lines[2];
$veranstaltungsort = $lines[4];
$output .= '<div class="eventblock"><a href="?page=events&id='.str_replace('.md', '', $event).'"><h3 class="a">'.$veranstaltungsort.'</h3><h3 class="b">'.$date.'</h3><h2>'.$title.'</h2><p>'.$desc.'</p></a></div>';
}
}
return $output;
}
function get_event_content($id) {
$lines = file(__DIR__ . '/../events/' . str_replace('.', '', $id) . '.md');
$output = "";
$output .= '## Datum/Zeit'."\n\n";
$output .= $lines[2]."\n".$lines[3]."\n\n## Veranstaltungsort\n\n".$lines[4]."\n\n";
for ($i = 6; $i < count($lines); $i++)
$output .= $lines[$i] . "\n";
return $output;
}
function get_next_topic() {
$output = new stdClass();
$currentDate = new DateTime();
$next_topic = clone $currentDate;
$next_topic->modify('second Tuesday of this month +1 week');
while ($next_topic->format('N') !== '2') {
$next_topic->add(new DateInterval('P1D'));
}
$output->days = $currentDate->diff($next_topic)->days+1;
$output->date = $next_topic->format('Y-m-d');
return $output;
}
function get_next_treff() {
$output = new stdClass();
// Get current date and time
$now = new DateTime();
// Find the next Friday
$now->modify('next Friday');
// Calculate the number of days until the next Friday
$diff = $now->diff(new DateTime());
$days_until = $diff->format('%a');
$output->days = $days_until+1;
$output->date = $now->format('Y-m-d');
// Return an array with the count and date of the next Friday
return $output;
}
function get_next_repaircafe() {
$output = new stdClass();
$today = new DateTime();
$lastDayOfMonth = clone $today;
$lastDayOfMonth->modify('last day of this month');
$lastThursday = clone $lastDayOfMonth;
while ($lastThursday->format('w') != 4) { // Thursday is represented by 4 (0-6, where 0 is Sunday)
$lastThursday->modify('-1 day');
}
$daysUntilLastThursday = $today->diff($lastThursday)->days;
$output->days = $daysUntilLastThursday;
$output->date = $lastThursday->format('Y-m-d');
return $output;
}
function get_next_brunch() {
$now = new DateTime();
if ($now->format('w') == 0) {
$nextSunday = clone $now;
} else {
$nextSunday = new DateTime('next Sunday');
}
$weekNumber = (int)$nextSunday->format('W');
$isEvenWeek = ($weekNumber % 2) == 0;
if ($isEvenWeek) {
$nextSunday->modify('+1 week');
}
$differenz = $nextSunday->diff($now);
$days = $differenz->days;
$output = new stdClass();
$output->date = $nextSunday->format('Y-m-d');
$output->days = $days+1;
return $output;
}
?>