diff --git a/Web/Models/Entities/Document.php b/Web/Models/Entities/Document.php index 05e44a58..7093e1ed 100644 --- a/Web/Models/Entities/Document.php +++ b/Web/Models/Entities/Document.php @@ -156,6 +156,11 @@ class Document extends Media return false; } + function isImage(): bool + { + return in_array($this->getVKAPIType(), [3, 4]); + } + function isCopiedBy(User $user): bool { if($user->getId() === $this->getOwnerID()) diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index f95a3242..6fd827d7 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -2,6 +2,7 @@ namespace openvk\Web\Presenters; use openvk\Web\Models\Repositories\{Documents, Clubs}; use openvk\Web\Models\Entities\Document; +use Nette\InvalidStateException as ISE; final class DocumentsPresenter extends OpenVKPresenter { @@ -10,6 +11,8 @@ final class DocumentsPresenter extends OpenVKPresenter function renderList(?int $owner_id = NULL): void { + $this->assertUserLoggedIn(); + $this->template->_template = "Documents/List.xml"; if($owner_id > 0) $this->notFound(); @@ -110,6 +113,10 @@ final class DocumentsPresenter extends OpenVKPresenter $document->save(); } catch(\TypeError $e) { $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); + } catch(ISE $e) { + $this->flashFail("err", tr("forbidden"), tr("error_file_preview"), null, $isAjax); + } catch(\ValueError $e) { + $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); } if(!$isAjax) { @@ -121,4 +128,25 @@ final class DocumentsPresenter extends OpenVKPresenter ]); } } + + function renderPage(int $virtual_id, int $real_id): void + { + $this->assertUserLoggedIn(); + + $access_key = $this->queryParam("key"); + $doc = (new Documents)->getDocumentById((int)$virtual_id, (int)$real_id); + if(!$doc || $doc->isDeleted()) + $this->notFound(); + + if(!$doc->checkAccessKey($access_key)) + $this->notFound(); + + $this->template->doc = $doc; + $this->template->type = $doc->getVKAPIType(); + $this->template->is_image = $doc->isImage(); + $this->template->tags = $doc->getTags(); + $this->template->copied = $doc->isCopiedBy($this->user->identity); + $this->template->copyImportance = true; + $this->template->modifiable = $doc->canBeModifiedBy($this->user->identity); + } } diff --git a/Web/Presenters/templates/Documents/List.xml b/Web/Presenters/templates/Documents/List.xml index ea38f865..cd662aff 100644 --- a/Web/Presenters/templates/Documents/List.xml +++ b/Web/Presenters/templates/Documents/List.xml @@ -18,6 +18,7 @@ {/block} {block content} + {var $is_gallery = $current_tab == 3 || $current_tab == 4}
+ {foreach $tags as $tag} + + {$tag}{if $tag != $tags[sizeof($tags) - 1]},{/if} + + {/foreach} +
+