-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·89 lines (84 loc) · 2.5 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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css.css">
<link rel="icon" href="wikipetan.png">
<title>hepatiki</title>
</head>
<?php
date_default_timezone_set('EST');
echo "<div class=term id='header'>
<div id='header'><pre>
__ __ _ __ _
/ / ___ ___ ___ _ / /_ (_)/ /__ (_)
/ _ \/ -_)/ _ \/ _ `// __// // '_// /
/_//_/\__// .__/\_,_/ \__//_//_/\_\/_/
/_/
A small personal blog / wiki
</pre></div>
<div style='position:absolute;right:5px'>
<a href='/'>Index</a>
|
<a href='rss.xml'>RSS</a>
|
<a>Webring</a>
</div>
</div>";
$db = new PDO('sqlite:posts.db');
if (array_key_exists('QUERY_STRING', $_SERVER)) {
$query = explode("=", $_SERVER['QUERY_STRING']);
} else {
$query = array(0 => NULL);
}
$res = select_with_query($query, $db);
foreach ($res as $res) {
$tags = explode(" ", $res['tags']);
$timestamp = $res['date'];
$date = date("d M Y H:i", $timestamp);
$parsed_text = parse_text($res['content']);
echo "<div class=term>
<a style='float:right' href='/?date=$timestamp'>{$timestamp}</a>
<div style='float:left'>tags: ";
foreach ($tags as $tag) {
echo "<a href='/?tags={$tag}'>{$tag}</a> ";
}
echo "</div><br>{$date}<br>{$parsed_text}</div>";
}
function select_with_query($query, $db)
// $query[0] = "date" or "tags"
// $query[1] = the id/tag to be searched for
{
if (strlen($query[0]) > 0){
$name = $query[0];
$search = $query[1];
switch ($name) {
case "date":
$stmt = $db->prepare('SELECT * FROM tbl1 WHERE date LIKE ? ORDER BY date DESC');
break;
case "tags":
$stmt = $db->prepare('SELECT * FROM tbl1 WHERE tags LIKE ? ORDER BY date DESC');
break;
}
$stmt->execute(["%$search%"]);
} else {
$stmt = $db->prepare('SELECT * FROM tbl1 ORDER BY date DESC');
$stmt->execute();
}
return $stmt->fetchAll();
}
function parse_text($content)
{
$textarr = explode("\n", $content);
for ($i = 0; $i < sizeof($textarr); $i++) {
$str = $textarr[$i];
$firstchar = substr($str, 0, 1);
if (strcmp($firstchar, ">") == 0) {
$rest = substr($str, 1);
$textarr[$i] = "<span class='greentext'>>{$rest}</span>";
} else if (strcmp($firstchar, "<") == 0) {
$rest = substr($str, 1);
$textarr[$i] = "<span class='redtext'><{$rest}</span>";
}
}
return join("<br>", $textarr);
}