diff --git a/VKAPI/Handlers/Docs.php b/VKAPI/Handlers/Docs.php index 11938ba7..c7548b2a 100644 --- a/VKAPI/Handlers/Docs.php +++ b/VKAPI/Handlers/Docs.php @@ -50,7 +50,7 @@ final class Docs extends VKAPIRequestHandler return $this->add($owner_id, $doc_id, ""); } - function edit(int $owner_id, int $doc_id, ?string $title, ?string $tags, ?int $folder_id): int + function edit(int $owner_id, int $doc_id, ?string $title = "", ?string $tags = "", ?int $folder_id = 0, int $owner_hidden = -1): int { $this->requireUser(); $this->willExecuteWriteAction(); @@ -69,16 +69,16 @@ final class Docs extends VKAPIRequestHandler $doc->setName($title); if($tags) $doc->setTags($tags); - if($folder_id) { - if(in_array($folder_id, [0, 4])) - $doc->setFolder_id($folder_id); - } + if(in_array($folder_id, [0, 3])) + $doc->setFolder_id($folder_id); + if(in_array($owner_hidden, [0, 1])) + $doc->setOwner_hidden($owner_hidden); try { $doc->setEdited(time()); $doc->save(); } catch(\Throwable $e) { - return 1; + return 0; } return 1; diff --git a/Web/Models/Entities/Document.php b/Web/Models/Entities/Document.php index 71588a59..05e44a58 100644 --- a/Web/Models/Entities/Document.php +++ b/Web/Models/Entities/Document.php @@ -209,10 +209,10 @@ class Document extends Media $parsed = explode(",", $tags); $result = ""; foreach($parsed as $tag) { - $result .= mb_trim($tag) . ($tag != end($parsed) ? "," : ''); + $result .= trim($tag) . ($tag != end($parsed) ? "," : ''); } - $this->stateChanges("tags", $result); + $this->stateChanges("tags", ovk_proc_strtr($result, 500)); return true; } @@ -329,6 +329,7 @@ class Document extends Media $res->url = $this->getURL(); $res->date = $this->getPublicationTime()->timestamp(); $res->type = $this->getVKAPIType(); + $res->is_hidden = (int) $this->isOwnerHidden(); $res->is_licensed = (int) $this->isLicensed(); $res->is_unsafe = (int) $this->isUnsafe(); $res->folder_id = (int) $this->getFolder(); @@ -346,16 +347,25 @@ class Document extends Media return $res; } + function delete(bool $softly = true, bool $all_copies = false): void + { + if($all_copies) { + $ctx = DatabaseConnection::i()->getContext(); + $ctx->table("documents")->where("copy_of", $this->getId())->delete(); + } + parent::delete($softly); + } + static function detectTypeByFormat(string $format) { switch($format) { - case "txt": case "docx": case "doc": case "odt": case "pptx": case "ppt": case "xlsx": case "xls": + case "txt": case "docx": case "doc": case "odt": case "pptx": case "ppt": case "xlsx": case "xls": case "md": return 1; case "zip": case "rar": case "7z": return 2; case "gif": case "apng": return 3; - case "jpg": case "jpeg": case "png": case "psd": case "ps": + case "jpg": case "jpeg": case "png": case "psd": case "ps": case "webp": return 4; case "mp3": return 5; diff --git a/Web/Models/Repositories/Documents.php b/Web/Models/Repositories/Documents.php index 3482924b..1e4fba6c 100644 --- a/Web/Models/Repositories/Documents.php +++ b/Web/Models/Repositories/Documents.php @@ -72,7 +72,7 @@ class Documents function getTypes(int $owner_id): array { - $result = DatabaseConnection::i()->getConnection()->query("SELECT `type`, COUNT(*) AS `count` FROM `documents` WHERE `owner` = $owner_id GROUP BY `type` ORDER BY `type`"); + $result = DatabaseConnection::i()->getConnection()->query("SELECT `type`, COUNT(*) AS `count` FROM `documents` WHERE `owner` = $owner_id AND `deleted` = 0 AND `unlisted` = 0 GROUP BY `type` ORDER BY `type`"); $response = []; foreach($result as $res) { if($res->count < 1 || $res->type == 0) continue; @@ -113,10 +113,11 @@ class Documents foreach($params as $paramName => $paramValue) { switch($paramName) { case "type": + if($paramValue < 1 || $paramValue > 8) continue; $result->where("type", $paramValue); break; case "tags": - $result->where("tags", $paramValue); + $result->where("tags LIKE ?", "%$paramValue%"); break; case "from_me": $result->where("owner", $paramValue); diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index 29eae0ce..f95a3242 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -92,21 +92,25 @@ final class DocumentsPresenter extends OpenVKPresenter $folder = $this->postParam("folder"); $owner_hidden = ($this->postParam("owner_hidden") ?? "off") === "on"; - $document = new Document; - $document->setOwner($owner); - $document->setName($name); - $document->setFolder_id($folder); - $document->setTags(empty($tags) ? NULL : $tags); - $document->setOwner_hidden($owner_hidden); - $document->setFile([ - "tmp_name" => $upload["tmp_name"], - "error" => $upload["error"], - "name" => $upload["name"], - "size" => $upload["size"], - "preview_owner" => $this->user->id, - ]); - - $document->save(); + try { + $document = new Document; + $document->setOwner($owner); + $document->setName(ovk_proc_strtr($name, 255)); + $document->setFolder_id($folder); + $document->setTags(empty($tags) ? NULL : $tags); + $document->setOwner_hidden($owner_hidden); + $document->setFile([ + "tmp_name" => $upload["tmp_name"], + "error" => $upload["error"], + "name" => $upload["name"], + "size" => $upload["size"], + "preview_owner" => $this->user->id, + ]); + + $document->save(); + } catch(\TypeError $e) { + $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); + } if(!$isAjax) { $this->redirect("/docs" . (isset($group) ? $group->getRealId() : "")); diff --git a/Web/Presenters/templates/Documents/List.xml b/Web/Presenters/templates/Documents/List.xml index 6cd41bcb..ea38f865 100644 --- a/Web/Presenters/templates/Documents/List.xml +++ b/Web/Presenters/templates/Documents/List.xml @@ -46,14 +46,18 @@ -