ctdo.de/app/php/posts.php

50 lines
1.7 KiB
PHP

<?php
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, $page = 0) {
$events = 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 .= '<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 {
$start_index = $page * $limit;
$end_index = $start_index + $limit;
if($end_index > count($events))
$end_index = count($events);
for ($i = $start_index; $i < $end_index; $i++) {
$lines = file(__DIR__ . '/../posts/' . $events[$i]);
$title = $lines[0];
$desc = $lines[1];
$date = $lines[2];
$signatur = $lines[3];
$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>';
}
}
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;
}
?>