diff --git a/Web/Models/Entities/Document.php b/Web/Models/Entities/Document.php
index 7093e1ed..15b558b1 100644
--- a/Web/Models/Entities/Document.php
+++ b/Web/Models/Entities/Document.php
@@ -161,13 +161,16 @@ class Document extends Media
return in_array($this->getVKAPIType(), [3, 4]);
}
- function isCopiedBy(User $user): bool
+ function isCopiedBy($user = NULL): bool
{
- if($user->getId() === $this->getOwnerID())
+ if(!$user)
+ return false;
+
+ if($user->getRealId() === $this->getOwnerID())
return true;
return DatabaseConnection::i()->getContext()->table("documents")->where([
- "owner" => $user->getId(),
+ "owner" => $user->getRealId(),
"copy_of" => $this->getId(),
"deleted" => 0,
])->count() > 0;
@@ -221,6 +224,15 @@ class Document extends Media
return true;
}
+ function getOwner(bool $real = false): RowModel
+ {
+ $oid = (int) $this->getRecord()->owner;
+ if($oid > 0)
+ return (new Users)->get($oid);
+ else
+ return (new Clubs)->get($oid * -1);
+ }
+
function getFileExtension(): string
{
if($this->tmp_format) {
diff --git a/Web/Models/Repositories/Documents.php b/Web/Models/Repositories/Documents.php
index 1e4fba6c..b102c30f 100644
--- a/Web/Models/Repositories/Documents.php
+++ b/Web/Models/Repositories/Documents.php
@@ -30,17 +30,19 @@ class Documents
function getDocumentById(int $virtual_id, int $real_id, ?string $access_key = NULL): ?Document
{
$doc = $this->documents->where(['virtual_id' => $virtual_id, 'id' => $real_id]);
-
- if($access_key) {
+ /*if($access_key) {
$doc->where("access_key", $access_key);
- }
+ }*/
$doc = $doc->fetch();
- if(!is_null($doc))
- return new Document($doc);
- else
+ if(is_null($doc))
return NULL;
-
+
+ $n_doc = new Document($doc);
+ if(!$n_doc->checkAccessKey($access_key))
+ return NULL;
+
+ return $n_doc;
}
function getDocumentsByOwner(int $owner, int $order = 0, int $type = -1): EntityStream
@@ -85,14 +87,6 @@ class Documents
];
}
- if(sizeof($response) < 1) {
- return [[
- "count" => 0,
- "type" => 0,
- "name" => tr("document_type_0"),
- ]];
- }
-
return $response;
}
diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php
index fd0e9a3d..cde025b5 100644
--- a/Web/Presenters/GroupPresenter.php
+++ b/Web/Presenters/GroupPresenter.php
@@ -3,7 +3,7 @@ namespace openvk\Web\Presenters;
use openvk\Web\Models\Entities\{Club, Photo, Post};
use Nette\InvalidStateException;
use openvk\Web\Models\Entities\Notifications\ClubModeratorNotification;
-use openvk\Web\Models\Repositories\{Clubs, Users, Albums, Managers, Topics, Audios, Posts};
+use openvk\Web\Models\Repositories\{Clubs, Users, Albums, Managers, Topics, Audios, Posts, Documents};
use Chandler\Security\Authenticator;
final class GroupPresenter extends OpenVKPresenter
@@ -27,12 +27,15 @@ final class GroupPresenter extends OpenVKPresenter
if ($club->isBanned()) {
$this->template->_template = "Group/Banned.xml";
} else {
+ $docs = (new Documents)->getDocumentsByOwner($club->getRealId());
$this->template->albums = (new Albums)->getClubAlbums($club, 1, 3);
$this->template->albumsCount = (new Albums)->getClubAlbumsCount($club);
$this->template->topics = (new Topics)->getLastTopics($club, 3);
$this->template->topicsCount = (new Topics)->getClubTopicsCount($club);
$this->template->audios = (new Audios)->getRandomThreeAudiosByEntityId($club->getRealId());
$this->template->audiosCount = (new Audios)->getClubCollectionSize($club);
+ $this->template->docsCount = $docs->size();
+ $this->template->docs = $docs->offsetLimit(0, 2);
}
if(!is_null($this->user->identity) && $club->getWallType() == 2) {
diff --git a/Web/Presenters/templates/Documents/List.xml b/Web/Presenters/templates/Documents/List.xml
index cd662aff..61613c50 100644
--- a/Web/Presenters/templates/Documents/List.xml
+++ b/Web/Presenters/templates/Documents/List.xml
@@ -51,18 +51,16 @@
{if $count > 0}
{foreach $docs as $doc}
{if $is_gallery}
- {include "components/image.xml", doc => $doc, scroll_context => true}
+ {include "components/image.xml", doc => $doc, scroll_context => true, club => isset($group) ? $group : NULL}
{else}
- {include "components/doc.xml", doc => $doc, scroll_context => true}
+ {include "components/doc.xml", doc => $doc, scroll_context => true, club => isset($group) ? $group : NULL}
{/if}
{/foreach}
{else}
{include "../components/error.xml", description => tr("there_is_no_documents_alright")}
{/if}
-
{include "../components/paginator.xml", conf => $paginatorConf}
-
{/block}
diff --git a/Web/Presenters/templates/Documents/components/doc.xml b/Web/Presenters/templates/Documents/components/doc.xml
index 4b81b5a3..c805661f 100644
--- a/Web/Presenters/templates/Documents/components/doc.xml
+++ b/Web/Presenters/templates/Documents/components/doc.xml
@@ -1,6 +1,6 @@
{var $preview = $doc->hasPreview() ? $doc->getPreview() : NULL}
{var $tags = $doc->getTags()}
-{var $copied = $doc->isCopiedBy($thisUser)}
+{var $copied = !isset($club) ? $doc->isCopiedBy($thisUser) : $doc->isCopiedBy($club)}
{var $modifiable = $doc->canBeModifiedBy($thisUser)}
-
+
+
+ {_documents}
+
+
+
+ {tr("documents", $topicsCount)}
+
+
+
+ {foreach $docs as $doc}
+ {include "../Documents/components/doc.xml", doc => $doc, hideButtons => true, noTags => true}
+ {/foreach}
+
+
+
{/block}
diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml
index 59925f27..b60fbc1d 100644
--- a/Web/Presenters/templates/components/attachment.xml
+++ b/Web/Presenters/templates/components/attachment.xml
@@ -65,6 +65,10 @@
{include "../Audio/player.xml", audio => $attachment}
+{elseif $attachment instanceof \openvk\Web\Models\Entities\Document}
+
+ {include "../Documents/components/doc.xml", doc => $attachment, copyImportance => true, noTags => true}
+
{else}
{_version_incompatibility}
{/if}
diff --git a/Web/static/css/main.css b/Web/static/css/main.css
index 492b7ae8..0c6d6af4 100644
--- a/Web/static/css/main.css
+++ b/Web/static/css/main.css
@@ -4074,7 +4074,10 @@ hr {
.docGalleryItem .doc_top_panel > div {
width: 10px;
height: 10px;
- background-color: white;
+ background: url('/assets/packages/static/openvk/img/docs_controls.png?v=8');
+ background-size: 57px;
+ background-position-y: -24px;
+ background-repeat: no-repeat;
}
#docs_page_wrapper select {
@@ -4151,7 +4154,7 @@ hr {
.docListViewItem .doc_volume > div {
width: 20px;
height: 20px;
- background: url('/assets/packages/static/openvk/img/docs_controls.png?v=3');
+ background: url('/assets/packages/static/openvk/img/docs_controls.png?v=8');
}
.docListViewItem:hover .doc_volume {
@@ -4163,7 +4166,7 @@ hr {
background-position-y: -21px;
}
-.docListViewItem .doc_volume #report_icon {
+.docListViewItem .doc_volume #report_icon, .docGalleryItem .doc_top_panel #report_icon {
background-position-x: -40px;
}
@@ -4175,10 +4178,27 @@ hr {
background-position-x: -60px;
}
+.docGalleryItem .doc_top_panel #add_icon {
+ background-position-x: -35px;
+}
+
+.docGalleryItem .doc_top_panel #edit_icon {
+ background-position-x: -12px;
+}
+
.docListViewItem .doc_volume #mark_icon {
background-position-x: -80px;
}
+.docGalleryItem .doc_top_panel #mark_icon {
+ background-position-x: -46px;
+}
+
.doc_viewer_wrapper {
overflow: hidden;
}
+
+.attachments .docListViewItem {
+ min-height: 30px;
+ border-bottom: unset;
+}
diff --git a/Web/static/img/docs_controls.png b/Web/static/img/docs_controls.png
index f56b3c85..22f9d03d 100644
Binary files a/Web/static/img/docs_controls.png and b/Web/static/img/docs_controls.png differ
diff --git a/Web/static/js/al_docs.js b/Web/static/js/al_docs.js
index 9935ea08..2b185b85 100644
--- a/Web/static/js/al_docs.js
+++ b/Web/static/js/al_docs.js
@@ -111,6 +111,11 @@ u(document).on('click', '.docMainItem #edit_icon', async (e) => {
const docs = await window.OVKAPI.call('docs.getById', {docs: id, return_tags: 1})
const doc = docs[0]
+ if(!doc) {
+ fastError("(")
+ CMessageBox.toggleLoader()
+ return
+ }
const cmsg_2 = new CMessageBox({
title: tr("document_editing_in_general"),
@@ -248,6 +253,9 @@ u(document).on('click', '.docMainItem #report_icon', (e) => {
u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", async (e) => {
e.preventDefault()
+ if(e.target.closest('.doc_volume_action')) {
+ return
+ }
const target = u(e.target)
const link = target.closest('a')
@@ -262,7 +270,7 @@ u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", asy
const preview = body.querySelector('.photo-page-wrapper-photo')
const details = body.querySelector('.ovk-photo-details')
- preview.querySelector('img').setAttribute('id', 'ovk-photo-img')
+ u(preview.querySelector('img')).attr('id', 'ovk-photo-img')
const photo_viewer = new CMessageBox({
title: '',
diff --git a/bootstrap.php b/bootstrap.php
index 8a5061d3..75b3140e 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -264,6 +264,7 @@ function parseAttachments($attachments, array $allow_types = ['photo', 'video',
'doc' => [
'repo' => 'openvk\Web\Models\Repositories\Documents',
'method' => 'getDocumentById',
+ 'withKey' => true,
]
];
@@ -281,6 +282,14 @@ function parseAttachments($attachments, array $allow_types = ['photo', 'video',
$repository_class = $repositories[$attachment_type]['repo'];
if(!$repository_class) continue;
$attachment_model = (new $repository_class)->{$repositories[$attachment_type]['method']}($attachment_id);
+ $output_attachments[] = $attachment_model;
+ } elseif($repositories[$attachment_type]['withKey']) {
+ [$attachment_owner, $attachment_id, $access_key] = explode('_', $attachment_ids);
+
+ $repository_class = $repositories[$attachment_type]['repo'];
+ if(!$repository_class) continue;
+ $attachment_model = (new $repository_class)->{$repositories[$attachment_type]['method']}((int)$attachment_owner, (int)$attachment_id, $access_key);
+
$output_attachments[] = $attachment_model;
} else {
[$attachment_owner, $attachment_id] = array_map('intval', explode('_', $attachment_ids));
diff --git a/locales/ru.strings b/locales/ru.strings
index 36bf91fc..dd27c424 100644
--- a/locales/ru.strings
+++ b/locales/ru.strings
@@ -2236,6 +2236,12 @@
"document_type_7" = "Книги";
"document_type_8" = "Остальные";
+"documents_one" = "$1 документ";
+"documents_few" = "$1 документа";
+"documents_many" = "$1 документов";
+"documents_other" = "$1 документов";
+"documents_zero" = "$1 документов";
+
"you_have_x_documents_one" = "У Вас $1 документ";
"you_have_x_documents_few" = "У Вас $1 документа";
"you_have_x_documents_many" = "У Вас $1 документов";