<?php
global $User;
+require_once 'database.inc.php';
print '<h3>Reacties</h3>'."\n";
-$pagelink = $Page.$Args;
if ($_POST) {
try {
- @mkdir($pagelink);
- $target = $pagelink.'/'.date('YmdHis').':'.$User->login.'.html';
$html = nl2br(htmlspecialchars($_POST['reply']));
- $html = "<p>$html</p>\n";
- $written = file_put_contents($target, $html);
- if ($written === FALSE) {
+ $html = "<p>$html</p>";
+ $query = $Db->query('INSERT INTO comments (page, message, author) VALUES (?, ?, ?)', [
+ $Page, $html, $User->login
+ ]);
+ if (!$query->rowCount()) {
throw new Exception('Fout bij opslaan');
}
$_POST['reply'] = NULL;
}
}
+$query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$Page]);
+
print '<ul class="replies">';
-foreach (glob("$pagelink/*.html") as $reply) {
- preg_match('</(\d{2,14}) : ([^:]*) [^/]* \.html$>x', $reply, $replymeta);
- if (!$replymeta) continue;
- $replydate = str_split($replymeta[1], 2);
- $replydate[0] = array_shift($replydate) . $replydate[0];
- $replyuser = new User("profile/{$replymeta[2]}");
+while ($row = $query->fetch(PDO::FETCH_OBJ)) {
+ $rowuser = new User("profile/{$row->author}");
print '<li>';
printf('<strong>%s</strong> <small class=date>%s</small>',
- $replyuser->html, showdate($replydate)
+ $rowuser->html, showdate(preg_split('/\D/', $row->created))
);
- printf("<blockquote>%s</blockquote>\n", file_get_contents($reply));
+ printf("<blockquote>%s</blockquote>\n", $row->message);
print "</li>\n";
}