nieuws: ArchiveArticle class to access news pages
[minimedit.git] / nieuws / index.php
index d6a85e7f36d88c62e0291505fcde2dac18e6d7e8..8a613c2591f57531c594bd28a13ebd2f6d69712e 100644 (file)
@@ -1,11 +1,67 @@
 <?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);
+       $article = new ArchiveArticle("$Page$Args.html");
+       $Place[1] = ' <small class="date">'.$article->date.'</small>';
+       print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', ob_get_clean());
+       if ($article->image) {
+               $Place['image'] = "https://lijtweg.nl/".$article->thumb('600x');
+               printf('<p><img src="/%s" /></p>'."\n", $article->thumb('640x'));
+       }
+
+       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{2,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;
 }
 
@@ -26,9 +82,7 @@ if ($year) {
        }
 
        print "<h2>$title</h2>\n\n";
-       print '<div id="news">'."\n\n";
        shownews(glob($match.'*.html'));
-       print "</div>\n\n";
        return 1;
 }
 
@@ -47,6 +101,20 @@ if ($pages = glob("$Page/19??/*.html")) {
 
 print "</div>\n\n";
 
+if ($replyform) {
+       print "<h3>Melding rapporteren</h3>\n";
+       $_REQUEST['subject'] = 'melding';
+       require 'contact.php';
+?>
+<form method="post">
+<p>
+       <textarea name="body" cols=60 rows=4></textarea>
+       <input type="submit" value="Versturen" />
+</p>
+</form>
+<?php
+}
+
 if (!empty($User['admin'])) {
        print '<script src="/nieuws/edit.js"></script>'."\n";
 }