-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost.php
More file actions
35 lines (29 loc) · 785 Bytes
/
post.php
File metadata and controls
35 lines (29 loc) · 785 Bytes
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
<?php
define('BASEPATH', __DIR__);
require_once 'templating.php';
require_once 'transactions.php';
require_once 'urls.php';
$id = $_GET['id'] ?? '';
if (empty($id)) {
flash('Trying something?');
redirect(getHomeURL());
}
$post = getPost($id);
$hasHiddenParameter = $_GET['hidden'] ?? '' === '1';
if (empty($post) || ($post->isHidden() && !$hasHiddenParameter)) {
flash('Post not found, sorry');
redirect(getHomeURL());
}
$mimeType = $_GET['mimetype'] ?? '';
if (!empty($mimeType)) {
if (!preg_match('#^\w+/[-+\w]+$#', $mimeType)) {
flash('Invalid mime type');
redirect(getHomeURL());
}
header('Content-Type: ' . $mimeType);
die($post->content);
}
renderTemplate('post_view', [
'title' => $post->title,
'post' => $post,
]);