'; } function generate_nav($active_page, $pages, $page_names) { $output = array(); foreach ($pages as $key => $page) { if ($page == $active_page) $output[] = ['page' => $page, 'name' => $page_names[$key], 'active' => TRUE]; else $output[] = ['page' => $page, 'name' => $page_names[$key], 'active' => FALSE]; } return $output; } function html_link($href, $class, $innerHTML, $blank) { if($blank) return ''.$innerHTML.''; else return ''.$innerHTML.''; } function raumstatus() { $url = 'https://status.ctdo.de/api/simple/v2'; $data = json_decode(file_get_contents($url), true); return $data['state']; } function str_mass_replace($searchs, $replacers, $string) { foreach ($searchs as $key => $search) { $string = str_replace($search, $replacers[$key], $string); } return $string; } //Posts function scan_for_posts() { $s = scandir(__DIR__ . '/../posts/', SCANDIR_SORT_DESCENDING); $output = array(); foreach ($s as $f) { if(count(str_split($f)) >= 4) $output[] = $f; } return $output; } function generate_post_list($limit = -1) { $events = $this->scan_for_posts(); $output = ""; if ($limit == -1) { foreach ($events as $event) { $lines = file(__DIR__ . '/../posts/' . $event); $title = $lines[0]; $desc = $lines[1]; $date = $lines[2]; $signatur = $lines[3]; $output .= '

'.$signatur.'
'.$date.'

'.$title.'

'.$desc.'

'; } } else { if($limit > count($events)) $limit = count($events); for ($i = 0; $i < $limit; $i++) { $lines = file(__DIR__ . '/../posts/' . $events[$i]); $title = $lines[0]; $desc = $lines[1]; $date = $lines[2]; $signatur = $lines[3]; $output .= '

'.$signatur.'

'.$date.'

'.$title.'

'.$desc.'

'; } } return $output; } function get_post_content($id) { $lines = file(__DIR__ . '/../posts/' . str_replace('.', '', $id) . '.md'); $output = ""; for ($i = 5; $i < count($lines); $i++) $output .= $lines[$i] . "\n"; return $output; } //Posts end //Events 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) { $events = $this->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 .= '

'.$veranstaltungsort.'

'.$date.'

'.$title.'

'.$desc.'

'; } } else { if($limit > count($events)) $limit = count($events); for ($i = 0; $i < $limit; $i++) { $lines = file(__DIR__ . '/../events/' . $event); $title = $lines[0]; $desc = $lines[1]; $date = $lines[2]; $veranstaltungsort = $lines[4]; $output .= '

'.$veranstaltungsort.'

'.$date.'

'.$title.'

'.$desc.'

'; } } 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; } //Events end 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; } } ?>