-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
102 lines (73 loc) · 2.49 KB
/
index.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
require 'bin/h2o/h2o.php';
// load db functions
include('model.php');
// connect to the DB in readonly mode
db_connect();
$guid = mysql_real_escape_string($_GET['id']);
$page = mysql_real_escape_string($_GET['page']);
$post = mysql_real_escape_string($_GET['post']);
$recent = getRecentPostSummaries(5);
# data to hand to the template, no matter which path we take
$data = array(
'blog' => $blog,
'recent' => $recent
);
if ($post != null) {
# single post via SEO-friendly title
$details = getPostBySEOName($post);
if (! $details['post']['guid']) { show404(); }
# init template engine
$h2o = new h2o('tmpl/blog-post.html');
# add post data
$data['post'] = $details['post'];
$data['comments'] = $details['comments'];
$data['tags'] = $details['tags'];
if ($details['older']) { $data['older'] = $details['older']; }
if ($details['newer']) { $data['newer'] = $details['newer']; }
} elseif ($guid != null) {
# single post; more detail, get tags, etc
$details = getPostDetails($guid);
if (! $details['post']['guid']) { show404(); }
# init template engine
$h2o = new h2o('tmpl/blog-post.html');
# add post data
$data['post'] = $details['post'];
$data['comments'] = $details['comments'];
$data['tags'] = $details['tags'];
if ($details['older']) { $data['older'] = $details['older']; }
if ($details['newer']) { $data['newer'] = $details['newer']; }
} elseif ($page != null) {
# single page get details
$details = getPageDetails($page);
if (! $details['name']) { show404(); }
if ( $details['standalone'] == 1 ) {
// no templating necessary
echo $details['body'];
exit;
} else {
$h2o = new h2o('tmpl/blog-page.tmpl');
$data['page'] = $details;
}
} else {
# recent posts; comment summary is okay, and no need for comment details
$num = mysql_real_escape_string($_GET['posts']);
$offset = mysql_real_escape_string($_GET['offset']);
if ($num == '') { $num = 3; }
if ($offset == '') { $offset = 0; }
$posts = getRecentPosts($num, $offset);
# init template engine
$h2o = new h2o('tmpl/blog-index.html');
# data to hand to the template
$data['posts'] = $posts;
$data['older'] = intval($offset) + intval($num);
if ( $offset != 0 ) {
$data['offset'] = $offset;
$data['newer'] = intval($offset) - intval($num);
}
}
# done!
db_close();
# render the page
echo $h2o->render(compact('data'));
?>