90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
|
|
class Util {
|
|
function css_link($src) {
|
|
return '<link rel="stylesheet" href="'.$src.'">';
|
|
}
|
|
|
|
function generate_nav($active_page, $pages, $page_names) {
|
|
$output = '<nav><ul>';
|
|
foreach ($pages as $key => $page) {
|
|
if ($page == $active_page)
|
|
$output .= '<li>'.$this->html_link('/?page='.$page, 'active', $page_names[$key], FALSE).'</li>';
|
|
else
|
|
$output .= '<li>'.$this->html_link('/?page='.$page, '', $page_names[$key], FALSE).'</li>';
|
|
}
|
|
$output .= '</ul></nav>';
|
|
|
|
return $output;
|
|
}
|
|
|
|
function html_link($href, $class, $innerHTML, $blank) {
|
|
if($blank)
|
|
return '<a href="'.$href.'" class="'.$class.'" target="_blank">'.$innerHTML.'</a>';
|
|
else
|
|
return '<a href="'.$href.'" class="'.$class.'">'.$innerHTML.'</a>';
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
function scan_for_events() {
|
|
$s = scandir('events/');
|
|
$output = array();
|
|
foreach ($s as $f) {
|
|
if(count(str_split($f)) == 13)
|
|
$output[] = $f;
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
function generate_event_list() {
|
|
$events = $this->scan_for_events();
|
|
$output = "";
|
|
foreach ($events as $event) {
|
|
$date = str_replace('.md', '', $event);
|
|
$lines = file(__DIR__ . '/../events/' . $event);
|
|
$title = $lines[0];
|
|
$desc = $lines[1];
|
|
$output .= '<div class="eventblock"><h3>'.$date.'</h3><a href="?page=events&e='.$date.'"><h2>'.$title.'</h2><p>'.$desc.'</p></a></div>';
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
function get_event_content($date) {
|
|
$lines = file(__DIR__ . '/../events/' . $date . '.md');
|
|
$output = "";
|
|
for ($i = 3; $i < count($lines); $i++)
|
|
$output .= $lines[$i] . "\n";
|
|
return $output;
|
|
}
|
|
|
|
function get_next_topic() {
|
|
$output = new stdClass();
|
|
$currentDate = new DateTime();
|
|
|
|
// Find the next fourth Tuesday
|
|
$nextFourthTuesday = clone $currentDate;
|
|
$nextFourthTuesday->modify('next Tuesday')->modify('next Tuesday')->modify('next Tuesday');
|
|
while ($nextFourthTuesday->format('N') !== '2') {
|
|
$nextFourthTuesday->add(new DateInterval('P1D'));
|
|
}
|
|
|
|
$output->days = $currentDate->diff($nextFourthTuesday)->days+1;
|
|
$output->date = $nextFourthTuesday->format('Y-m-d');
|
|
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
?>
|