nieuws: replies in html files
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 21 Nov 2018 08:45:00 +0000 (09:45 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 21 Nov 2018 08:49:33 +0000 (09:49 +0100)
Same results using comment form, but manually allows for rich contents.

nieuws/replies.php

index b6285b1f7e0723f5dfd54d778a80772353c47631..a6d9740c444950cafe95fbfef56e3cbb44824b85 100644 (file)
@@ -7,8 +7,9 @@ $pagelink = $Page.$Args;
 if ($_POST) {
        try {
                @mkdir($pagelink);
-               $target = $pagelink.'/'.date('YmdHis').':'.$User['name'].'.txt';
-               $written = file_put_contents($target, $_POST['reply']);
+               $target = $pagelink.'/'.date('YmdHis').':'.$User['name'].'.html';
+               $html = nl2br(htmlspecialchars($_POST['reply']));
+               $written = file_put_contents($target, $html);
                if ($written === FALSE) {
                        throw new Exception('Fout bij opslaan');
                }
@@ -21,8 +22,8 @@ if ($_POST) {
 
 print '<ul class="replies">';
 
-foreach (glob("$pagelink/*.txt") as $reply) {
-       preg_match('</(\d{2,14}) : ([^:]*) [^/]* \.txt$>x', $reply, $replymeta);
+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[1] = $replydate[0] . $replydate[1];
@@ -30,8 +31,7 @@ foreach (glob("$pagelink/*.txt") as $reply) {
        printf('<strong>%s</strong> <small class=date>%s</small>',
                $replymeta[2], showdate($replydate)
        );
-       $replydata = file_get_contents($reply);
-       printf('<p>%s</p>', nl2br(htmlspecialchars($replydata)));
+       printf("<p>%s</p>\n", file_get_contents($reply));
        print "</li>\n";
 }