auth: create user object regardless of login
[minimedit.git] / widget / reply.php
index fd01a947f81acb6748fb300b2bac7f00788216ef..edffaa75ceb3b6bc9de79f34d79af2b4d94bff72 100644 (file)
@@ -9,9 +9,20 @@ $journalcol = [
 if ($_POST) {
        require_once 'upload.inc.php';
        try {
+               $html = messagehtml($_POST['reply']);
+               if ($_FILES and !empty($_FILES['image'])) {
+                       $target = 'data/upload';
+                       if (!file_exists($target)) {
+                               throw new Exception("er is geen uploadmap aanwezig op $target");
+                       }
+                       $target .= '/' . $User->login;
+                       if ($result = userupload($_FILES['image'], $target)) {
+                               $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
+                       }
+               }
                $query = $Db->set('comments', [
                        'page'    => $Page,
-                       'message' => messagehtml($_POST['reply']),
+                       'message' => $html,
                        'author'  => $User->login,
                ]);
                if (!$query->rowCount()) {
@@ -67,7 +78,7 @@ while ($row = $query->fetch()) {
        printf('<strong>%s</strong> <small class=date>%s</small>',
                $rowuser->html, showdate(preg_split('/\D/', $row->created))
        );
-       printf("<blockquote>%s</blockquote>\n", $row->message);
+       printf("<blockquote>\n%s</blockquote>\n", $row->message);
        if ($changes = json_decode($row->journal)) {
                print '<ul>';
                foreach ($changes as $change) {
@@ -92,9 +103,9 @@ while ($row = $query->fetch()) {
        print "</li>\n";
 }
 
-if ($User) {
+if ($User->login) {
        print '<li>';
-       print '<form method="post" action="">';
+       print '<form method="post" action="" enctype="multipart/form-data">';
        if (isset($Issue) and $User->admin("edit $Page")) {
                print '<p>';
                printf(
@@ -115,6 +126,13 @@ if ($User) {
                );
                print "</p>\n";
        }
+       if (isset($Issue)) {
+               printf(
+                       '<p><label for="%s">%s:</label> '
+                       . '<input id="%1$s" name="%1$s" value=""%s /></p>'."\n",
+                       'image', 'Beeldmateriaal', ' type="file" accept="image/*"'
+               );
+       }
        printf('<textarea id="%s" name="%1$s" cols=60 rows=3 placeholder="%s">%s</textarea>'."\n",
                'reply',
                "Bericht van {$User->login}",