aboutsummaryrefslogtreecommitdiff
path: root/src/Handlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Handlers')
-rw-r--r--src/Handlers/AttachmentHandler.php26
-rw-r--r--src/Handlers/NewNote.php4
-rw-r--r--src/Handlers/NoteHandler.php7
3 files changed, 36 insertions, 1 deletions
diff --git a/src/Handlers/AttachmentHandler.php b/src/Handlers/AttachmentHandler.php
new file mode 100644
index 0000000..9b329b0
--- /dev/null
+++ b/src/Handlers/AttachmentHandler.php
@@ -0,0 +1,26 @@
+<?php
+
+
+namespace Micropoly\Handlers;
+
+
+use Micropoly\Env;
+use Micropoly\Handler;
+use Micropoly\Models\Attachment;
+
+class AttachmentHandler implements Handler
+{
+ public function handle(\Micropoly\Env $env, array $variables)
+ {
+ $db = $env->db();
+
+ $attachment = Attachment::byId($db, $variables["id"]);
+ if ($attachment === null) {
+ (new NotFoundHandler())->handle($env, []);
+ return;
+ }
+
+ header("Content-Type: {$attachment->getMime()}");
+ readfile($attachment->getFilePath($env->attachmentsPath()));
+ }
+} \ No newline at end of file
diff --git a/src/Handlers/NewNote.php b/src/Handlers/NewNote.php
index 9c60757..9d4286d 100644
--- a/src/Handlers/NewNote.php
+++ b/src/Handlers/NewNote.php
@@ -7,6 +7,7 @@ namespace Micropoly\Handlers;
use Micropoly\Env;
use Micropoly\Esc;
use Micropoly\Handler;
+use Micropoly\Models\Attachment;
use Micropoly\Models\Note;
class NewNote implements Handler
@@ -29,6 +30,9 @@ class NewNote implements Handler
$note->setTags($_POST["tag"]);
$note->save($env->db());
+ if (isset($_FILES['attachments']))
+ Attachment::createFromUploads($env->db(), $env->attachmentsPath(), $note, $_FILES['attachments']);
+
$url = $env->documentRoot() . "n/" . $note->getId();
http_response_code(303);
header("Location: {$url}");
diff --git a/src/Handlers/NoteHandler.php b/src/Handlers/NoteHandler.php
index afdabb5..aa1cf78 100644
--- a/src/Handlers/NoteHandler.php
+++ b/src/Handlers/NoteHandler.php
@@ -6,7 +6,9 @@ namespace Micropoly\Handlers;
use Micropoly\Env;
use Micropoly\Handler;
+use Micropoly\Models\Attachment;
use Micropoly\Models\Note;
+use Micropoly\TemplateModelWrappers\NoteForTemplate;
class NoteHandler implements Handler
{
@@ -32,8 +34,11 @@ class NoteHandler implements Handler
$note->setContent($_POST["content"]);
$note->setTags($_POST["tag"]);
$note->save($db);
+
+ if (isset($_FILES['attachments']))
+ Attachment::createFromUploads($env->db(), $env->attachmentsPath(), $note, $_FILES['attachments']);
}
- echo $env->twig()->render("/note.twig", ["note" => $note]);
+ echo $env->twig()->render("/note.twig", ["note" => new NoteForTemplate($db, $note)]);
}
} \ No newline at end of file