ctdo.de/app/index.php

151 lines
6.5 KiB
PHP
Raw Permalink 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';
2023-04-13 16:44:38 +00:00
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use League\CommonMark\CommonMarkConverter;
require __DIR__ . '/php/util.php';
require __DIR__ . '/php/events.php';
require __DIR__ . '/php/posts.php';
$converter = new CommonMarkConverter([
'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
2023-04-13 16:44:38 +00:00
$templateloader = new FilesystemLoader(__DIR__ . '/templates');
2023-04-13 16:44:38 +00:00
$twig_templates = new Environment($templateloader);
$title = '';
$content = '';
$raumstatus_b = get_web_json('https://status.ctdo.de/api/simple/v2')["state"];
$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 = html_link('https://status.ctdo.de/', 'green-text', '<b>offen</b>', TRUE);
else
$raumstatus = html_link('https://status.ctdo.de/', 'red-text', '<b>geschlossen</b>', TRUE);
}
2023-04-13 16:44:38 +00:00
$topic = get_next_topic();
$treff = get_next_treff();
$repaircafe = get_next_repaircafe();
$brunch = get_next_brunch();
2023-05-16 11:40:03 +00:00
$css = ['main'];
2023-04-13 16:44:38 +00:00
if(isset($_GET['page'])) {
$page = $_GET['page'];
$active_page = 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':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/index.md'));
$content = $twig_templates->render('index.twig', ['content' => $content, 'topic' => $topic, 'treff' => $treff, 'repaircafe' => $repaircafe, 'brunch' => $brunch, 'events' => generate_event_list(4) ]);
$filetoedit = "pages/index.md";
$css[] = 'home';
$css[] = 'events';
break;
case 'about':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/about.md'));
$filetoedit = "pages/about.md";
$css[] = 'about';
break;
case 'treff':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/treff.md'));
$filetoedit = "pages/treff.md";
break;
case 'blog':
if(!isset($_GET['id'])) {
$content = $twig_templates->render('blog.twig', [ 'posts' => generate_post_list(10) ]);
$filetoedit = "templates/blog.twig";
$css[] = 'events';
} else {
$content = $converter->convert(get_post_content($_GET['id']));
$filetoedit = "posts/".$_GET['id'].".md";
$css[] = 'event';
}
break;
case 'events':
2023-05-06 21:51:56 +00:00
if(!isset($_GET['id'])) {
$content = $twig_templates->render('events.twig', [ 'topic' => $topic, 'treff' => $treff, 'repaircafe' => $repaircafe, 'brunch' => $brunch, 'events' => generate_event_list(10) ]);
$filetoedit = "templates/events.twig";
$css[] = 'events';
} else {
$content = str_mass_replace(array('{{ topicdatum }}', 'Chaostreff Dortmund e.V.', '{{ treffdatum }}', '{{ repaircafedatum }}', '{{ brunchdatum }}'), array(get_next_topic()->date, html_link('/?page=treff', '', 'Chaostreff Dortmund e.V.', FALSE), get_next_treff()->date, get_next_repaircafe()->date, get_next_brunch()->date), $converter->convert(get_event_content($_GET['id'])));
$filetoedit = "events/".$_GET['id'].".md";
$css[] = 'event';
}
break;
case 'kontakt':
2023-10-04 09:54:40 +00:00
$content = $twig_templates->render('kontakt.twig');
$filetoedit = "templates/kontakt.twig";
$css[] = 'kontakt';
break;
case 'adresse':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/kontakt/adresse.md')).'<iframe scrolling="no" marginheight="0" marginwidth="0" src="https://www.openstreetmap.org/export/embed.html?bbox=7.463200986385346%2C51.52693021432671%2C7.4667415022850046%2C51.52841869497588&amp;layer=mapnik&amp;marker=51.52767446073405%2C7.464971244335175" frameborder="0" class="osm"></iframe>';
$filetoedit = "pages/kontakt/adresse.md";
break;
case 'irc':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/kontakt/irc.md'));
$filetoedit = "pages/kontakt/irc.md";
break;
case 'mail':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/kontakt/mail.md'));
$filetoedit = "pages/kontakt/mail.md";
break;
case 'tel':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/kontakt/tel.md'));
$filetoedit = "pages/kontakt/tel.md";
break;
case 'support':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/support.md'));
$filetoedit = "pages/kontakt/support.md";
break;
case 'verein':
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/verein.md'));
$filetoedit = "pages/verein.md";
break;
case 'impressum':
$title = 'impressum';
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/impressum.md'));
$filetoedit = "pages/impressum.md";
break;
case 'datenschutz':
$title = 'datenschutz';
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/datenschutz.md'));
$filetoedit = "pages/datenschutz.md";
2023-04-13 16:44:38 +00:00
break;
default:
$content = $twig_templates->render('404.twig', ['page' => $_GET['page']]);
$filetoedit = "templates/404.twig";
2023-04-13 16:44:38 +00:00
break;
}
2023-04-13 16:44:38 +00:00
} else {
$active_page = 'index';
$title = $active_page;
$filetoedit = "pages/index.md";
2023-10-04 09:54:40 +00:00
$content = $converter->convert(file_get_contents(__DIR__ . '/pages/index.md'));
$content = $twig_templates->render('index.twig', ['content' => $content, 'topic' => $topic, 'treff' => $treff, 'repaircafe' => $repaircafe, 'brunch' => $brunch, 'events' => generate_event_list(4) ]);
$css[] = 'home';
$css[] = 'events';
2023-04-13 16:44:38 +00:00
}
$nav = generate_nav($active_page, $pages, $page_names);
echo $twig_templates->render('default.twig', ['title' => $title, 'css' => $css, 'nav' => $nav, 'raumstatus' => $raumstatus, 'main' => $content, 'file_to_edit' => $filetoedit]);
2023-04-13 16:44:38 +00:00
?>