/
threadlist.php
executable file
·148 lines (145 loc) · 4.94 KB
/
threadlist.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Thread List</title>
<link rel=icon href=wakaba.ico>
<link rel="stylesheet" type="text/css" href="css/reimu red.css">
<style>
body {
margin: 0;
padding: 0;
}
table {
margin: 0 auto;
margin-bottom: 20px;
border-collapse: collapse;
border-spacing: 0;
width: 60%;
}
th, td {
padding: 10px;
border: 1px solid black;
text-align: left;
vertical-align: top;
}
th {
background-color: #f2b0a9;
width: 20%;
}
td.comment {
background-color: #edc;
width: 80%;
}
td.thread-number {
background-color: #cec;
width: 20%;
}
.home-link {
text-align: right;
margin-top: 8px;
margin-right: 8px;
font-size: 16px;
}
h1 {
text-align: center;
font-size: 28px;
font-weight: bold;
line-height: 100px;
}
</style>
</head>
<body>
<div class="home-link">
[<a href="/">Home</a>]
[<a href="/faq.html">FAQ</a>]
[<a href="/wakaba">Wakaba</a>]
[<a href="/wakaba/wakaba.pl?task=admin">Manage</a>]
</div>
<h1>Thread List</h1>
<table>
<tbody>
<!-- List all threads from /res/ folder in descending last modified order so the most recently posted in thread appears at the top. -->
<?php
$dir = "res/";
$thumb_dir = "thumb/";
$files = scandir($dir);
usort($files, function($a, $b) use ($dir) {
return filemtime($dir . $b) - filemtime($dir . $a);
});
$page = isset($_GET['page']) ? max(intval($_GET['page']), 1) : 1;
$items_per_page = 10;
$offset = ($page - 1) * $items_per_page;
$total_items = count($files) - 2;
$total_pages = ceil($total_items / $items_per_page);
if ($total_pages > 1) {
echo "<div style=\"text-align: center;\">";
if ($page > 1) {
echo "<a href=\"?page=" . ($page - 1) . "\">Previous</a> ";
}
for ($i = 1; $i <= $total_pages; $i++) {
if ($i == $page) {
echo "$i ";
} else {
echo "<a href=\"?page=$i\">$i</a> ";
}
}
if ($page < $total_pages) {
echo "<a href=\"?page=" . ($page + 1) . "\">Next</a>";
}
echo "</div>";
}
echo "<table>";
echo "<tr>";
echo "<th>Subject</th>";
echo "<th>First Comment</th>";
echo "</tr>";
for ($i = $offset; $i < $offset + $items_per_page && $i < $total_items; $i++) {
$file = $files[$i + 2];
if (preg_match('/^(\d+)\.html$/', $file, $matches)) {
$thread_number = $matches[1];
$thread_title = "";
$comment = "No comment.";
$content = file_get_contents($dir . $file);
if (preg_match('/<span class="filetitle">(.*?)(<a href="(.*?)">.*?<\/a>)?<\/span>/', $content, $matches)) {
if (isset($matches[1])) {
$thread_title = $matches[1];
}
if (isset($matches[2])) {
$thread_link = $matches[2];
} else {
$thread_link = $dir . $file;
}
preg_match('/<img src="(.*?)" class="thumb"/', $content, $matches);
$thumb_path = $thumb_dir . basename($matches[1]);
} else {
$thread_link = $dir . $file;
$thumb_path = "";
}
preg_match('/<p>(.*?)<\/p>/', $content, $matches);
if (isset($matches[1])) {
$comment = $matches[1];
}
echo "<tr>";
echo "<td class=\"thread-number\">";
if (!empty($thumb_path)) {
echo "<img src=\"$thumb_path\" alt=\"\" style=\"vertical-align:middle; margin-right:5px;\">";
}
echo "<a href=\"$thread_link\">";
if (empty(trim($thread_title))) {
echo ">>$thread_number";
} else {
echo $thread_title;
}
echo "</a></td>";
echo "<td class=\"comment\">$comment</td>";
echo "</tr>";
}
}
echo "</table>";
?>
</tbody>
</table>
<p class="footer"> - <a href="https://wakaba.c3.cx/">wakaba 3.0.9</a> + <a href="https://github.com/kimeemaru/wakaba/">teen spirit</a> + <a href="https://ota-ch.com/jp/">all my friends</a> -</p>
</body>
</html>