widget/reply: redirect to created comment
[minimedit.git] / widget / reply.php
index 7e0ec1e83aea3c4c0819df20d9315f491db8ab8b..0935567e82ecb51ba2aeb4ff0a6717b50e313abe 100644 (file)
@@ -21,7 +21,7 @@ if ($_POST) {
                        }
                }
                $query = $Db->set('comments', [
-                       'page'    => $Page,
+                       'page'    => $Page->link,
                        'message' => $html,
                        'author'  => $User->login,
                ]);
@@ -60,21 +60,27 @@ if ($_POST) {
                                $Issue = $updated;
                        }
                }
+
+               $target = "/{$Page->link}/$newcomment#$newcomment";
+               abort($target, ($Page->api ? 200 : 303) . ' reply success');
                $_POST['reply'] = NULL;
        }
        catch (Exception $e) {
+               if ($Page->api) {
+                       abort(ucfirst($e->getMessage()), '500 reply error');
+               }
                print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
        }
 }
 
 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
-$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page]);
+$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]);
 
 print '<ul class="replies">';
 
 while ($row = $query->fetch()) {
        $rowuser = new User("profile/{$row->author}");
-       print '<li>';
+       printf('<li id="%d">', $row->id);
        printf('<strong>%s</strong> <small class=date>%s</small>',
                $rowuser->html, showdate(preg_split('/\D/', $row->created))
        );
@@ -90,7 +96,7 @@ while ($row = $query->fetch()) {
                                printf("<em>%s</em> %s",
                                        $journalcol[$change->col], sprintf(
                                                !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
-                                               (!isset($change->value) ? 'verwijderd (<strike>%s</strike>)' :
+                                               (!isset($change->value) ? 'verwijderd (<s>%s</s>)' :
                                                'gewijzigd van <q>%s</q> naar <q>%s</q>'),
                                                $change->old_value, $change->value
                                        )
@@ -103,10 +109,10 @@ while ($row = $query->fetch()) {
        print "</li>\n";
 }
 
-if ($User) {
+if ($User->login) {
        print '<li>';
        print '<form method="post" action="" enctype="multipart/form-data">';
-       if (isset($Issue) and $User->admin("edit $Page")) {
+       if (isset($Issue) and $User->admin("edit {$Page->link}")) {
                print '<p>';
                printf(
                        '<label for="%s">%s:</label> '
@@ -139,7 +145,9 @@ if ($User) {
                ''
        );
        print '<input type="submit" value="Plaatsen" />'."\n";
-       print "</form></li>\n";
+       print "</form>";
+       print '<script src="/upload/progress.js"></script>';
+       print "</li>\n";
 }
 
 print "</ul>\n\n";