diff --git a/.gitignore b/.gitignore index b36a8176..a3c85616 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ local.ini db.sqlite db.sqlite-journal +public_html/media/js/jquery.tagit.js +public_html/media/css/jquery.tagit.css diff --git a/config.ini b/config.ini index 5f524247..8c3beb2e 100644 --- a/config.ini +++ b/config.ini @@ -4,6 +4,7 @@ prettyPrint=1 [main] dbPath=./db.sqlite +filesPath=./files/ title=szurubooru [registration] diff --git a/files/.gitignore b/files/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/files/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/init.php b/init.php new file mode 100644 index 00000000..c155b79e --- /dev/null +++ b/init.php @@ -0,0 +1,11 @@ +context->title = $this->config->main->title; $this->context->stylesheets = ['core.css']; + $this->context->scripts = []; $this->context->layoutName = isset($_GET['json']) ? 'layout-json' diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 24167d9d..0a77b1a8 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -1,6 +1,13 @@ context->stylesheets []= 'jquery.tagit.css'; + $this->context->scripts []= 'jquery.tagit.js'; + $callback(); + } + /** * @route /posts * @route /posts/{query} @@ -27,8 +34,78 @@ class PostController */ public function uploadAction() { + $this->context->stylesheets []= 'upload.css'; + $this->context->scripts []= 'upload.js'; $this->context->subTitle = 'upload'; - throw new Exception('Not implemented'); + + PrivilegesHelper::confirmWithException($this->context->user, Privilege::UploadPost); + + if (isset($_FILES['file'])) + { + $suppliedSafety = intval(InputHelper::get('safety')); + if (!in_array($suppliedSafety, PostSafety::getAll())) + throw new SimpleException('Invalid safety type "' . $suppliedSafety . '"'); + + $suppliedTags = InputHelper::get('tags'); + $suppliedTags = preg_split('/[,;\s+]/', $suppliedTags); + $suppliedTags = array_filter($suppliedTags); + $suppliedTags = array_unique($suppliedTags); + foreach ($suppliedTags as $tag) + if (!preg_match('/^\w+$/i', $tag)) + throw new SimpleException('Invalid tag "' . $tag . '"'); + + $suppliedFile = $_FILES['file']; + + switch ($suppliedFile['type']) + { + case 'image/gif': + case 'image/png': + case 'image/jpeg': + $postType = PostType::Image; + break; + case 'application/x-shockwave-flash': + $postType = PostType::Flash; + break; + default: + throw new SimpleException('Invalid file type "' . $suppliedFile['type'] . '"'); + } + + //todo: find out duplicate files + + do + { + $name = md5(mt_rand() . uniqid()); + $path = $this->config->main->filesPath . DIRECTORY_SEPARATOR . $name; + } + while (file_exists($path)); + + $dbTags = []; + foreach ($suppliedTags as $tag) + { + $dbTag = R::findOne('tag', 'name = ?', [$tag]); + if (!$dbTag) + { + $dbTag = R::dispense('tag'); + $dbTag->name = $tag; + R::store($dbTag); + } + $dbTags []= $dbTag; + } + + $dbPost = R::dispense('post'); + $dbPost->type = $postType; + $dbPost->name = $name; + $dbPost->mimeType = $suppliedFile['type']; + $dbPost->safety = $suppliedSafety; + $dbPost->sharedTag = $dbTags; + + move_uploaded_file($suppliedFile['tmp_name'], $path); + R::store($dbPost); + + //todo: generate thumbnail + + $this->context->transport->success = true; + } } /** diff --git a/src/Models/PostSafety.php b/src/Models/PostSafety.php new file mode 100644 index 00000000..8c24a330 --- /dev/null +++ b/src/Models/PostSafety.php @@ -0,0 +1,12 @@ + - + context->subTitle)): ?> <?php printf('%s – %s', $this->context->title, $this->context->subTitle) ?> <?php echo $this->context->title ?> context->stylesheets as $name): ?> - + + + + + + + context->scripts as $name): ?> + - diff --git a/src/Views/post-upload.phtml b/src/Views/post-upload.phtml new file mode 100644 index 00000000..73f40a9f --- /dev/null +++ b/src/Views/post-upload.phtml @@ -0,0 +1,67 @@ +context->transport->success === true): ?> +

Post created!

+context->transport->errorMessage)): ?> +

context->transport->errorMessage ?>

+ + + + +
+
+ +
+
+ Drop files here!
+ Or just click on this box. +
+
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+ +
+ + remove × + + + Thumbnail +
+
+ + filename.jpg +
+ +
+ + + + +
+ +
+ + +
+
+
+
+
+ +