summaryrefslogtreecommitdiff
path: root/blog/index.php
blob: 7573d974ff4a9d0cc82686b9638f2c4c17ebc870 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/time.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/post.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/partials.php';

$post_id = null;
$url = parse_url($_SERVER['REQUEST_URI']);
if (strlen($url['path']) > 1) {
    $post_id = explode("/", substr($url['path'], 1), 2);
    $post_id = $post_id[count($post_id) - 1];
}

if ($post_id) {
    $post = read_post(urldecode($post_id));
    if (!$post) {
        http_response_code(404);
        exit("Post not found");
    }
} else {
    $posts = get_posts();
}
?>
<!DOCTYPE html>
<html>

<head>
    <title>blog - ilt.su</title>
    <meta name="description" content="my blog.">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <link rel="stylesheet" href="/static/style.css">
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <meta name="robots" content="noindex, nofollow">
</head>

<body>
    <main>
        <?php html_header(); ?>
        <p><a href="/">ilt.su</a> - <a href="/blog/">blog</a></p>
        <?php if (isset($post)): ?>
            <h1><?= $post['name'] ?? '<i>No title.</i>' ?></h1>
            <div>
                <?= $post['contents'] ?? '<i>No contents.</i>' ?>
            </div>
            <p><i>Posted <?= format_timestamp(time() - $post['time']) ?> ago</i></p>
        <?php endif; ?>

        <?php if (isset($posts)): ?>
            <h1>Blog</h1>
            <ul>
                <?php foreach ($posts as $s): ?>
                    <li><a href="/blog/<?= urlencode($s['name']) ?>"><?= $s['name'] ?></a>
                        <i><?= format_timestamp(time() - $s['time']) ?>
                            ago</i>
                    </li>
                <?php endforeach; ?>
                <?php if (empty($posts)): ?>
                    <i>No posts yet.</i>
                <?php endif; ?>
            </ul>
        <?php endif; ?>
    </main>
</body>

</html>