ctdo.de/index.php

146 lines
5.8 KiB
PHP
Raw Normal View History

<?php
2023-02-27 08:11:24 +00:00
2023-04-13 16:44:38 +00:00
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/php/util.php';
2023-04-13 16:44:38 +00:00
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use League\CommonMark\CommonMarkConverter;
$converter = new CommonMarkConverter([
'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
2023-04-13 16:44:38 +00:00
$util = new Util();
2023-04-13 16:44:38 +00:00
$pageloader = new FilesystemLoader(__DIR__ . '/pages');
$templateloader = new FilesystemLoader(__DIR__ . '/templates');
2023-04-13 16:44:38 +00:00
$twig_pages = new Environment($pageloader);
$twig_templates = new Environment($templateloader);
$title = '';
$content = '';
$head = '';
2023-04-13 16:44:38 +00:00
$topictreff = $twig_templates->render('topictreff.html.twig');
$nextevents = $twig_templates->render('nextevents.html.twig');
$raumstatus_b = $util->raumstatus();
$raumstatus = '<b>unbekannt</b>';
$pages = array('index', 'about', 'treff', 'blog', 'events', 'kontakt', 'support', 'verein');
$page_names = array('index', 'über uns', 'zeiten & location', 'blog', 'events', 'kontakt', 'support', 'verein');
$active_page = '';
if(gettype($raumstatus_b) == "boolean") {
if($raumstatus_b)
$raumstatus = $util->html_link('https://status.ctdo.de/', 'green-text', '<b>offen</b>', TRUE);
else
$raumstatus = $util->html_link('https://status.ctdo.de/', 'red-text', '<b>geschlossen</b>', TRUE);
}
2023-04-13 16:44:38 +00:00
$topic = $util->get_next_topic();
switch ($topic->days) {
case 0:
$topic_output = '<p class="topic">Der nächste Topictreff findet heute statt!</p>';
break;
case 1:
$topic_output = '<p class="topic">Der nächste Topictreff findet morgen statt!</p>';
break;
default:
$topic_output = '<p class="topic">Der nächste Topictreff findet in '.$topic->days.' Tagen ['.$topic->date.'] statt.</p>';
break;
}
2023-04-13 16:44:38 +00:00
if(isset($_GET['page'])) {
$page = $_GET['page'];
$active_page = $util->str_mass_replace(array('adresse', 'irc', 'mail'), array('kontakt', 'kontakt', 'kontakt'), $page);
$title = $page_names[array_search($active_page, $pages)];
2023-04-13 16:44:38 +00:00
switch ($page) {
case 'index':
$content = $twig_pages->render('index.html.twig', [ 'topic' => $topic_output, 'posts' => $util->generate_post_list(4) ]);
$head = $util->css_link('css/main.css').$util->css_link('css/home.css').$util->css_link('css/events.css');
break;
case 'about':
$content = $twig_pages->render('about.html.twig');
$head = $util->css_link('css/main.css').$util->css_link('css/about.css');
break;
case 'treff':
$content = $twig_pages->render('treff.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'blog':
if(!isset($_GET['id'])) {
$content = $twig_pages->render('blog.html.twig', [ 'posts' => $util->generate_post_list() ]);
$head = $util->css_link('css/main.css').$util->css_link('css/events.css');
} else {
$content = $converter->convert($util->get_post_content($_GET['id']));
$head = $util->css_link('css/main.css').$util->css_link('css/event.css');
}
break;
case 'events':
if(!isset($_GET['e'])) {
$content = $twig_pages->render('events.html.twig', [ 'topic' => $topic_output, 'events' => $util->generate_post_list() ]);
$head = $util->css_link('css/main.css').$util->css_link('css/events.css');
} else {
$content = $converter->convert($util->get_post_content($_GET['e']));
$head = $util->css_link('css/main.css').$util->css_link('css/event.css');
}
break;
case 'kontakt':
$content = $twig_pages->render('kontakt.html.twig');
$head = $util->css_link('css/main.css').$util->css_link('css/kontakt.css');
break;
case 'adresse':
$content = $twig_pages->render('kontakt/adresse.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'irc':
$content = $twig_pages->render('kontakt/irc.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'mail':
$content = $twig_pages->render('kontakt/mail.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'tel':
$content = $twig_pages->render('kontakt/tel.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'support':
$content = $twig_pages->render('support.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'verein':
$content = $twig_pages->render('verein.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'impressum':
$title = 'impressum';
$content = $twig_pages->render('impressum.html.twig');
$head = $util->css_link('css/main.css');
break;
case 'datenschutz':
$title = 'datenschutz';
$content = $twig_pages->render('datenschutz.html.twig');
$head = $util->css_link('css/main.css');
2023-04-13 16:44:38 +00:00
break;
default:
$content = $twig_pages->render('404.html.twig', ['page' => $_GET['page']]);
break;
}
2023-04-13 16:44:38 +00:00
} else {
$active_page = 'index';
$title = $active_page;
$content = $twig_pages->render('index.html.twig', [ 'topic' => $topic_output, 'posts' => $util->generate_post_list(4) ]);
$head = $util->css_link('css/main.css').$util->css_link('css/home.css').$util->css_link('css/events.css');
2023-04-13 16:44:38 +00:00
}
$nav = $util->generate_nav($active_page, $pages, $page_names);
echo $twig_templates->render('html5struct.html.twig', ['title' => $title, 'head' => $head, 'nav' => $nav, 'raumstatus' => $raumstatus, 'main' => $content]);
2023-04-13 16:44:38 +00:00
?>