widget/reply: link non-image uploads instead
[minimedit.git] / widget / reply.php
index 1f6d0e2ff0352f709ff0223fdd455c1d3962eded..a3b8052a6e7c5ad4a6794ffc6ad5b1acf07a2c3a 100644 (file)
@@ -17,7 +17,14 @@ if ($_POST) {
                        }
                        $target .= '/' . $User->login;
                        if ($result = userupload($_FILES['image'], $target)) {
-                               $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
+                               if (preg_match('(^image/)', $_FILES['image']['type'])) {
+                                       $html .= sprintf('<p><img src="/thumb/640x/%s" /></p>', $result);
+                               }
+                               else {
+                                       $html .= sprintf('<p>Bijgevoegd bestand: <a href="/%s" />%s</a></p>',
+                                               $result, basename($result)
+                                       );
+                               }
                        }
                }
                $query = $Db->set('comments', [
@@ -61,9 +68,8 @@ if ($_POST) {
                        }
                }
 
-               if ($Page->api) {
-                       abort("/{$Page->link}", '200 reply success');
-               }
+               $target = "/{$Page->link}/$newcomment#$newcomment";
+               abort($target, ($Page->api ? 200 : 303) . ' reply success');
                $_POST['reply'] = NULL;
        }
        catch (Exception $e) {
@@ -81,7 +87,7 @@ 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))
        );