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}
-
+
{tr($locale_string, $count)}.
@@ -49,16 +50,19 @@
{if $count > 0} {foreach $docs as $doc} -
- {include "components/doc.xml", doc => $doc} -
+ {if $is_gallery} + {include "components/image.xml", doc => $doc, scroll_context => true} + {else} + {include "components/doc.xml", doc => $doc, scroll_context => true} + {/if} {/foreach} {else} {include "../components/error.xml", description => tr("there_is_no_documents_alright")} {/if} - - {include "../components/paginator.xml", conf => $paginatorConf}
+ + {include "../components/paginator.xml", conf => $paginatorConf} +
{/block} diff --git a/Web/Presenters/templates/Documents/Page.xml b/Web/Presenters/templates/Documents/Page.xml new file mode 100644 index 00000000..b6640185 --- /dev/null +++ b/Web/Presenters/templates/Documents/Page.xml @@ -0,0 +1,74 @@ +{extends "../@layout.xml"} + +{block title} + {_document} "{ovk_proc_strtr($doc->getName(), 20)}" +{/block} + +{block header} + {$doc->getName()} +{/block} + +{block content} + + +
+
+ {if $is_image} + doc image + {else} + + + + {/if} +
+ +
+
+

+ {foreach $tags as $tag} + + {$tag}{if $tag != $tags[sizeof($tags) - 1]},{/if} + + {/foreach} +

+
+ {_info_upload_date}: {$doc->getPublicationTime()} +
+
+ +
+ +
+
+
+ {if !$doc->isOwnerHidden()} + {var $owner = $doc->getOwner()} + + + +
+ {$owner->getCanonicalName()} +
+
+ {/if} + + {if isset($thisUser)} + {_edit} + {_report} + {_add} + {_remove} + {/if} +
+
+
+
+{/block} diff --git a/Web/Presenters/templates/Documents/Upload.xml b/Web/Presenters/templates/Documents/Upload.xml index 7c91c6b2..28b4ef5f 100644 --- a/Web/Presenters/templates/Documents/Upload.xml +++ b/Web/Presenters/templates/Documents/Upload.xml @@ -12,14 +12,13 @@ » {_documents} {/if} - » - загрузка + Non-AJAX Document upload {/block} {block content} - +
diff --git a/Web/Presenters/templates/Documents/components/doc.xml b/Web/Presenters/templates/Documents/components/doc.xml index bbd2e271..4b81b5a3 100644 --- a/Web/Presenters/templates/Documents/components/doc.xml +++ b/Web/Presenters/templates/Documents/components/doc.xml @@ -3,8 +3,8 @@ {var $copied = $doc->isCopiedBy($thisUser)} {var $modifiable = $doc->canBeModifiedBy($thisUser)} -
- +
+ {if $preview} document_preview {else} @@ -14,7 +14,7 @@ {/if}
- {$doc->getName()} + {$doc->getName()}
{_name}: