nieuws: user reply form on melding page
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 10 Aug 2018 19:40:45 +0000 (21:40 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 11 Aug 2018 06:00:45 +0000 (08:00 +0200)
nieuws.inc.php
nieuws/index.php

index 713347490441bbbb79844e837d6e76aa312005f3..524109d7fb7c2220e7e626e873eb32ad0c0bbbd7 100644 (file)
@@ -10,6 +10,7 @@ function showdate($parts)
        global $monthname;
        return implode(' ', array_filter([
                intval($parts[3]), $parts[2] > 0 ? $monthname[intval($parts[2])] : '', $parts[1],
+               count($parts) > 6 ? "$parts[4]:$parts[5]" : '',
        ]));
 }
 
index cf57dbc0b4882d73c92b4157f33fa113e816d91e..c90034ff2ef138dd41fef0da74cdd410f5292606 100644 (file)
@@ -1,11 +1,61 @@
 <?php
 include 'nieuws.inc.php';
 
+$replyform = $Page == 'melding' && !empty($User);
 @list ($year, $page) = explode('/', trim($Args, '/'));
 
 if ($page and !is_numeric($page)) {
        $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
        print shownewsarticle($Page.$Args, FALSE, $edit);
+
+       if ($replyform) {
+               print '<h3>Reacties</h3>'."\n";
+               $pagelink = $Page.$Args;
+
+               if ($_POST) {
+                       try {
+                               @mkdir($pagelink);
+                               $target = $pagelink.'/'.date('YmdHis').':'.$User['name'].'.txt';
+                               $written = file_put_contents($target, $_POST['reply']);
+                               if ($written === FALSE) {
+                                       throw new Exception('Fout bij opslaan');
+                               }
+                               $_POST['reply'] = NULL;
+                       }
+                       catch (Exception $e) {
+                               print '<p class=warn>Antwoord niet opgeslagen.</p>'."\n\n";
+                       }
+               }
+
+               print '<ul class="replies">';
+
+               foreach (glob("$pagelink/*.txt") as $reply) {
+                       preg_match('</(\d{14}) : ([^:]*) [^/]* \.txt$>x', $reply, $replymeta);
+                       if (!$replymeta) continue;
+                       $replydate = str_split($replymeta[1], 2);
+                       $replydate[1] = $replydate[0] . $replydate[1];
+                       print '<li>';
+                       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)));
+                       print "</li>\n";
+               }
+
+               print '<li>';
+               print '<form method="post" action="">';
+               printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
+                       'reply',
+                       "Bericht van {$User['name']}",
+                       ''
+               );
+               print '<input type="submit" value="Plaatsen" />'."\n";
+               print "</form></li>\n";
+
+               print "</ul>\n\n";
+       }
+
        return 1;
 }