-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
155 lines (118 loc) · 4.59 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/* NOTES
* kure is in BETA. Be aware that there may be BUGS and/or SECURITY HOLES
* in the engine, and that you are using it at your own risk. Please be
* cautious.
*
* I graciously accept bug reports and suggestions for kure's engine. Visit
* kure's repo at github.com/glacials/kure. My email is qhiiyr@gmail.com
* if you wish to reach me directly.
*
* If you wish to remove the footer's "powered by kure" text, feel free. I
* always appreciate recognition somewhere, but I'll let you decide what's fair.
* :P
*/
session_start();
// Tell all files to include relative to THIS FILE's directory
set_include_path(dirname($_SERVER['SCRIPT_FILENAME']));
// Avoid warnings about unset timezones by setting it to the server's timezone
if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());
// Autoload any class which is used in this file
function __autoload($class) {
if(file_exists('classes/' . $class . '.php'))
include 'classes/' . $class . '.php';
else
include_once 'classes/Exceptions.php';
}
require_once 'functions.php';
require_once 'classes/markdown.php';
set_exception_handler('exception_handler');
Engine::init_plugins();
try {
$config = Engine::get_config();
$language = Engine::get_language();
} catch(CannotFindFileException $e) {
Engine::quit($language->cant_find_config, $e->getMessage());
} catch(CannotReadFileException $e) {
Engine::quit($language->cant_read_config, $e->getMessage());
}
try {
Template::run('header');
} catch(CannotFindFileException $e) {
Engine::quit($language->cant_find_template, $e->getMessage());
} catch(CannotReadFileException $e) {
Engine::quit($language->cant_read_template, $e->getMessage());
}
/***** Entry Viewer *****/
if(isset($_GET['e'])) { // if a specific entry has been requested
$filename = sanitize($_GET['e']);
try {
$entry_handler = new EntryHandler($filename);
} catch(CannotFindFileException $e) {
Engine::quit($language->cant_find_entry, $e->getMessage());
} catch(CannotReadFileException $e) {
Engine::quit($language->cant_read_entry, $e->getMessage());
}
if(!$entry_handler->has_next())
Engine::quit($language->cant_find);
/***** Entry Listing (Home) *****/
} elseif(empty($_GET) || isset($_GET['page'])) {
if(!isset($_GET['page']))
$_GET['page'] = 0; // default to page 0
// Avoid injection stuff
if(!is_numeric($_GET['page']))
Engine::quit($language->bad_page);
try {
$entry_handler = new EntryHandler($_GET['page'], $config->entries_per_page);
} catch(CannotFindFileException $e) {
Engine::quit($language->cant_find_entry, $e->getMessage());
} catch(CannotReadFileException $e) {
Engine::quit($language->cant_read_entry, $e->getMessage());
}
if(!$entry_handler->has_next())
Engine::quit($language->no_entries);
} else {
Engine::quit('');
}
while($entry_handler->has_next()) {
$entry = $entry_handler->next();
$template_vars = array('{ENTRYTITLE}' => $entry->title,
'{ENTRYADDRESS}' => '?e=' . $entry->filename,
'{ENTRYDAY}' => date('j', $entry->timestamp),
'{ENTRYMONTH}' => date('F', $entry->timestamp),
'{ENTRYYEAR}' => date('Y', $entry->timestamp),
'{ENTRYCONTENT}' => $entry->content
);
try {
Template::run('entry', $template_vars);
} catch(CannotFindFileException $e) {
Engine::quit($language->cant_find_template, $e->getMessage());
} catch(CannotReadFileException $e) {
Engine::quit($language->cant_read_template, $e->getMessage());
}
}
if(!isset($_GET['page']))
$_GET['page'] = 0; // default to page 0
print "\t\t\t" . '<div class="split">' . "\n";
// Display "previous entries" / "more recent entries" links if necessary
if(($_GET['page'] + 1) * $config->entries_per_page < $entry_handler->total_entries) {
$last = '?page=' . ($_GET['page'] + 1);
print "\t\t\t\t" . '<div class="left-split"><a class="navitem" href="' . $last . '">less recent</a></div>' . "\n";
}
if($_GET['page'] != 0) {
if($_GET['page'] == 1)
$next = '?';
else
$next = '?page=' . ($_GET['page'] - 1);
print "\t\t\t\t" . '<div class="right-split"><a class="navitem" href="' . $next . '"> more recent</a></div>' . "\n";
}
print "\t\t\t" . '</div>' . "\n";
try{
Template::run('footer');
} catch(CannotFindFileException $e) {
Engine::quit($language->cant_find_template, $e->getMessage());
} catch(CannotReadFileException $e) {
Engine::quit($language->cant_read_template, $e->getMessage());
}
?>