2023-04-17 14:45:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Util {
|
|
|
|
function css_link($src) {
|
|
|
|
return '<link rel="stylesheet" href="'.$src.'">';
|
|
|
|
}
|
|
|
|
|
2023-04-30 18:37:16 +00:00
|
|
|
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>';
|
|
|
|
}
|
|
|
|
|
2023-04-17 14:45:44 +00:00
|
|
|
function raumstatus() {
|
|
|
|
$url = 'https://status.ctdo.de/api/simple/v2';
|
|
|
|
$data = json_decode(file_get_contents($url), true);
|
|
|
|
return $data['state'];
|
|
|
|
}
|
2023-04-30 18:37:16 +00:00
|
|
|
|
|
|
|
function str_mass_replace($searchs, $replacers, $string) {
|
|
|
|
foreach ($searchs as $key => $search) {
|
|
|
|
$string = str_replace($search, $replacers[$key], $string);
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2023-05-06 21:51:56 +00:00
|
|
|
//Posts
|
2023-05-06 14:34:12 +00:00
|
|
|
function scan_for_posts() {
|
|
|
|
$s = scandir(__DIR__ . '/../posts/', SCANDIR_SORT_DESCENDING);
|
2023-04-30 18:37:16 +00:00
|
|
|
$output = array();
|
|
|
|
foreach ($s as $f) {
|
2023-05-06 14:34:12 +00:00
|
|
|
if(count(str_split($f)) >= 4)
|
2023-04-30 18:37:16 +00:00
|
|
|
$output[] = $f;
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2023-05-06 14:34:12 +00:00
|
|
|
function generate_post_list($limit = -1) {
|
|
|
|
$events = $this->scan_for_posts();
|
2023-04-30 18:37:16 +00:00
|
|
|
$output = "";
|
2023-05-06 14:34:12 +00:00
|
|
|
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 .= '<div class="eventblock"><h3>'.$signatur.'<br>'.$date.'</h3><a href="?page=blog&id='.str_replace('.md', '', $event).'"><h2>'.$title.'</h2><p>'.$desc.'</p></a></div>';
|
|
|
|
}
|
|
|
|
} 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];
|
2023-05-06 21:51:56 +00:00
|
|
|
$output .= '<div class="eventblock"><h3 class="a">'.$signatur.'</h3><h3 class="b">'.$date.'</h3><a href="?page=blog&id='.str_replace('.md', '', $events[$i]).'"><h2>'.$title.'</h2><p>'.$desc.'</p></a></div>';
|
2023-05-06 14:34:12 +00:00
|
|
|
}
|
2023-04-30 18:37:16 +00:00
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2023-05-06 14:34:12 +00:00
|
|
|
function get_post_content($id) {
|
|
|
|
$lines = file(__DIR__ . '/../posts/' . str_replace('.', '', $id) . '.md');
|
2023-04-30 18:37:16 +00:00
|
|
|
$output = "";
|
2023-05-06 14:34:12 +00:00
|
|
|
for ($i = 5; $i < count($lines); $i++)
|
2023-04-30 18:37:16 +00:00
|
|
|
$output .= $lines[$i] . "\n";
|
|
|
|
return $output;
|
|
|
|
}
|
2023-05-06 21:51:56 +00:00
|
|
|
//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')
|
|
|
|
$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 .= '<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 {
|
|
|
|
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 .= '<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;
|
|
|
|
}
|
|
|
|
//Events end
|
|
|
|
|
2023-04-30 18:37:16 +00:00
|
|
|
function get_next_topic() {
|
|
|
|
$output = new stdClass();
|
|
|
|
$currentDate = new DateTime();
|
|
|
|
|
2023-05-06 14:34:12 +00:00
|
|
|
$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'));
|
2023-04-30 18:37:16 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 14:34:12 +00:00
|
|
|
$output->days = $currentDate->diff($next_topic)->days+1;
|
|
|
|
$output->date = $next_topic->format('Y-m-d');
|
2023-04-30 18:37:16 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
2023-05-06 21:51:56 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
$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 + 1;
|
|
|
|
$output->date = $lastThursday->format('Y-m-d');
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2023-04-17 14:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|