-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
371 lines (250 loc) · 7.08 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?php
// This bit ensures that all output is GZip compressed, saving bandwidth
if( substr_count( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ], 'gzip' ) ) { ob_start( "ob_gzhandler" ); } else { ob_start(); }
session_start();
/** Install the app if necessary, by checking if the install folder exists and if so installing **/
if ( file_exists( "install" ) ) { header( "Location: install/install.php" ); }
require_once( "./User.class.php" );
require_once( "./Token.class.php" );
require_once( "./Article.class.php" );
require_once( "./Comment.class.php" );
require_once( "./markdown.php" );
require_once( "./kses.php" );
$allowed = array('b' => array(),
'i' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
'blockquote' => array(),
'a' => array('href' => 1, 'title' => 1),
'p' => array('align' => 1),
'br' => array());
{ // page building variables
$url = ''; // set to your sites URL, may or may not be usefull
$name = 'Ibrahim';
$proffesion = 'web developer';
$adminEmail = ""; // all "contact site admin" links will point to this
$HTMLEmailheaders = 'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'From: ' . $adminEmail . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$output = '';
$pageTitle = ''; // set the pages title here
$pageHeader = '<!DOCTYPE html>
<html manifest="cache.manifest"
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width" />
<title>' . $pageTitle . '</title>
<link type="text/css"
rel="stylesheet"
href="./styles/blog.css.php" />
</head>
<body>
<div class="wrapper">
<div class="header">
</div>
<div class="body">
<div class="sideColumn">
<p>Hi there, my name's ' . $name . ' and I am a ' . $proffesion . ' from Nairobi, Kenya</p>';
$pageFooter = '
</div>
</div>
<div class="footer"></div>
</div>
</body>
</html>';
$pageBody = '';
}
$section = "articles";
if( isset( $_REQUEST[ "section" ] ) ) {
$section = $_REQUEST[ "section" ];
}
switch( $section ) {
case "home" : {
if( isset( $_REQUEST[ "year" ] ) ) {
$year = $_REQUEST[ "year" ];
if( isset( $_REQUEST[ "month" ] ) ) {
$month = $_REQUEST[ "month" ];
}
}
}
break;
case "articles" : {
$action = "list";
if( isset( $_REQUEST[ "action" ] ) ) {
$action = $_REQUEST[ "action" ];
}
switch( $action ) {
case "list" : {
$articles = getArticles( 0, "published", "any", "any", "all" );
if( count( $articles ) > 0 ) {
$limit = 5;
if( count( $articles ) <= 5 ) {
$limit = count( $articles );
}
for( $i = 0; $i < $limit; $i++ ) {
$article = new Article( $articles[ $i ] );
if( articleExists( 0, $articles[ $i ] ) ) {
$pageBody .= '
<div class="article">
<a href="?section=articles&action=view&target=' . $articles[ $i ] . '">
<h1>' . $article -> getTitle() . '</h1>
</a>
</div>';
}
else {
$pageBody .= '
<p>Sorry, the article referenced no longer exists</p>';
}
}
}
else {
$pageBody .= '
<div class="dialog">
<p> no posts yet :( </p>
</div>';
}
}
break;
case "view" : {
if( isset( $_REQUEST[ "target" ] ) ) {
$article = new Article( $_REQUEST[ "target" ] );
$pageBody .= '
<div class="article">
<h1>' . $article -> getTitle() . '</h1>
' . kses( Markdown( $article -> getBody() ), $allowed ) . '
</div>
<div class="comments">
<h2>comments</h2>';
if( count( $article -> getComments() ) > 0 ) {
foreach( $article -> getComments() as $commentID ) {
$comment = new Comment( $commentID );
$pageBody .= '
<div class="comment">
<p class="meta">on ' . substr( $comment -> getDateCreated(), 0, 10 ) . ' at ' . substr( $comment -> getDateCreated(), 11, 5 ) . ', ' . $comment -> getAuthor() . ' said :</p>
' . kses( Markdown( $comment -> getBody() ), $allowed ) . '
</div>';
}
}
$pageBody .= '
</div>
<div class="commentForm">
<form action="?section=comments&action=new"
method="post">
<fieldset class="info">
<legend>please leave a comment</legend>
<input type="hidden"
name="target"
value="' . $_REQUEST[ "target" ] . '" />
<div class="row">
<textarea name="comment"
placeholder="your comment here"></textarea>
</div>
</fieldset>
<fieldset class="info identity">
<div class="row">
<!-- <label for="name">name</label> -->
<input type="text"
name="name"
placeholder="your name"
required="required" />
</div>
<div class="row">
<!-- <label for="email">email</label> -->
<input type="email"
name="email"
placeholder="your email address [ will not be shared with anyone ]"
required="required" />
</div>
</fieldset>
<fieldset class="buttons">
<button type="submit">comment</button>
</fieldset>
</form>
</div>';
}
else {
$pageBody .= '
<div class="dialog">
<p>you have to specify an article to view</p>
</div>';
}
}
break;
}
}
break;
case "comments" : {
$action = "add";
if( isset( $_REQUEST[ "action" ] ) ) {
$action = $_REQUEST[ "action" ];
}
switch( $action ) {
case "add" :
case "new" :
default : {
if( isset( $_POST[ "comment" ] ) ) {
if( isset( $_POST[ "name" ] ) && isset( $_POST[ "email" ] ) && isset( $_POST[ "target" ] ) && ( filter_var( $_POST[ "email" ], FILTER_VALIDATE_EMAIL ) ) ) {
$comment = new Comment( "00000", $_POST[ "comment" ], $_POST[ "target" ], $_POST[ "name" ], $_POST[ "email" ] );
if( $comment -> saveToDB() ) {
$pageBody .= '
<div class="dialog">
<p>your comment has been saved and is awaiting moderation, thank you for your feedback</p>
</div>';
}
else {
$pageBody .= '
<div class="dialog">
<p>There was a problem saving yourcomment</p>
</div>';
}
}
else {
$pageBody .= '
<div class="dialog">
<p>you must provide a valid email address and a name</p>
</div>';
}
}
else {
$pageBody .= '
<div class="dialog">
<p>you comment cannot be empty</p>
</div>';
}
}
break;
}
}
break;
}
$pageHeader .= '
</div>
<div class="mainColumn">';
$format = 'html';
if( isset( $_REQUEST[ "format" ] ) ) {
$format = $_REQUEST[ "format" ];
}
switch( $format ) {
case "html" : {
header( 'Content-type: application/xml' );
$output = $pageHeader . $pageBody . $pageFooter;
}
break;
case "ajax" : {
$output = $pageBody;
}
break;
case "json" : {
}
break;
case "xml" : {
header( 'Content-type: application/xml' );
}
break;
case "pdf" : {}
break;
}
echo $output;
?>