From 160231316018c59e42c0f98c34ae23f0c4943a24 Mon Sep 17 00:00:00 2001
From: mrilyew <99399973+mrilyew@users.noreply.github.com>
Date: Sun, 29 Dec 2024 23:16:21 +0300
Subject: [PATCH] preparations for picker
---
Web/Models/Entities/Document.php | 18 ++++++++++--
Web/Models/Repositories/Documents.php | 24 ++++++----------
Web/Presenters/GroupPresenter.php | 5 +++-
Web/Presenters/templates/Documents/List.xml | 6 ++--
.../templates/Documents/components/doc.xml | 6 ++--
.../templates/Documents/components/image.xml | 10 +++----
Web/Presenters/templates/Group/View.xml | 18 ++++++++++++
.../templates/components/attachment.xml | 4 +++
Web/static/css/main.css | 26 ++++++++++++++++--
Web/static/img/docs_controls.png | Bin 5482 -> 6094 bytes
Web/static/js/al_docs.js | 10 ++++++-
bootstrap.php | 9 ++++++
locales/ru.strings | 6 ++++
13 files changed, 107 insertions(+), 35 deletions(-)
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 f56b3c85ef752c86e4da9802cb094c242d7ec8c3..22f9d03d42ca0d2f56c775055aaf56c99d819335 100644
GIT binary patch
del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q#Y
z9c9vq#;=?2OY{tDfWVUUe7=Y9xlbj$6mqhb#KfUr1tZNdbDEq>nWp)h66TgLhOI^d
zZt5cGc)>z5>~gMF{O-gNE%p>siqS
zG?k|TH_a?F>y4XQFyuyII{pf&-nWpte=H9b&Q1wGSd->hqcIA=$U8}?G1$i1WDH<~
zgKyO=eVQ?P!44LBg+VVbDc2UZMX_A#_k#g-%>K317>vJHN`4bbPlHf-%;Wp79?~33
zeP9XZKfUW=;pSqgS4FYGfe6c(Nn%Xt2V;hh+;F!g<=TKT5cSD8>y5%@i*y}`f2CX&
z_PTk{p-5sse0Y8qiEkr~FYe~ozkpk=dN$oEz%_vy@-MOd7EuP~bsHsVnxGj2jU
zHuM{7ct5n6REBky8P52e5g?A=I`)td}pvm4Sa{t((T6hL5x+0zKKET
zsyyi3(w!2nhw@Al_^mx9Ff(8~7+;efl0K{|H&mL^ld5-NaHVBh=!=V}f7kI-BN|oN
zE`#(r->`Shc^$?|LV6l!7GIc_Pi2`gurQ&e83Raj%m#YSrHo%Y_t*oPk7aPCR}E?m
zU;{XFT+Epv_F2`&0GB4x;X{jviZbj{nP|EqCI{{wH`UV^UMj=
zjK3L_p={bc!5bVu>p#{8dIe+hKNa+jQgDfs>H1!pAexLq8e {
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 документов";