mirror of
https://github.com/openvk/openvk
synced 2025-01-22 07:44:27 +03:00
add tags
This commit is contained in:
parent
cebb4d4eff
commit
3a114fdba9
12 changed files with 109 additions and 33 deletions
|
@ -30,7 +30,7 @@ final class Docs extends VKAPIRequestHandler
|
|||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
$doc = (new Documents)->getDocumentById($owner_id, $doc_id);
|
||||
$doc = (new Documents)->getDocumentByIdUnsafe($owner_id, $doc_id);
|
||||
if(!$doc || $doc->isDeleted())
|
||||
$this->fail(1150, "Invalid document id");
|
||||
|
||||
|
@ -55,7 +55,7 @@ final class Docs extends VKAPIRequestHandler
|
|||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
$doc = (new Documents)->getDocumentById($owner_id, $doc_id);
|
||||
$doc = (new Documents)->getDocumentByIdUnsafe($owner_id, $doc_id);
|
||||
if(!$doc || $doc->isDeleted())
|
||||
$this->fail(1150, "Invalid document id");
|
||||
if(!$doc->canBeModifiedBy($this->getUser()))
|
||||
|
@ -67,8 +67,8 @@ final class Docs extends VKAPIRequestHandler
|
|||
|
||||
if($title)
|
||||
$doc->setName($title);
|
||||
if($tags)
|
||||
$doc->setTags($tags);
|
||||
|
||||
$doc->setTags($tags);
|
||||
if(in_array($folder_id, [0, 3]))
|
||||
$doc->setFolder_id($folder_id);
|
||||
if(in_array($owner_hidden, [0, 1]))
|
||||
|
@ -118,13 +118,10 @@ final class Docs extends VKAPIRequestHandler
|
|||
|
||||
foreach($item_ids as $id) {
|
||||
$splitted_id = explode("_", $id);
|
||||
$doc = (new Documents)->getDocumentById((int)$splitted_id[0], (int)$splitted_id[1]);
|
||||
$doc = (new Documents)->getDocumentById((int)$splitted_id[0], (int)$splitted_id[1], $splitted_id[2]);
|
||||
if(!$doc || $doc->isDeleted())
|
||||
continue;
|
||||
|
||||
if(!$doc->checkAccessKey($splitted_id[2]))
|
||||
continue;
|
||||
|
||||
$response[] = $doc->toVkApiStruct($this->getUser(), $return_tags === 1);
|
||||
}
|
||||
|
||||
|
@ -147,6 +144,19 @@ final class Docs extends VKAPIRequestHandler
|
|||
];
|
||||
}
|
||||
|
||||
function getTags(?int $owner_id, ?int $type = 0)
|
||||
{
|
||||
$this->requireUser();
|
||||
if(!$owner_id)
|
||||
$owner_id = $this->getUser()->getId();
|
||||
|
||||
if($owner_id > 0 && $owner_id != $this->getUser()->getId())
|
||||
$this->fail(15, "Access denied");
|
||||
|
||||
$tags = (new Documents)->getTags($owner_id, $type);
|
||||
return $tags;
|
||||
}
|
||||
|
||||
function search(string $q = "", int $search_own = -1, int $order = -1, int $count = 30, int $offset = 0, int $return_tags = 0, int $type = 0, ?string $tags = NULL): object
|
||||
{
|
||||
$this->requireUser();
|
||||
|
|
|
@ -156,6 +156,11 @@ class Document extends Media
|
|||
return false;
|
||||
}
|
||||
|
||||
function isPrivate(): bool
|
||||
{
|
||||
return $this->getFolder() == Document::VKAPI_FOLDER_PRIVATE;
|
||||
}
|
||||
|
||||
function isImage(): bool
|
||||
{
|
||||
return in_array($this->getVKAPIType(), [3, 4]);
|
||||
|
@ -210,11 +215,17 @@ class Document extends Media
|
|||
|
||||
function setTags(?string $tags): bool
|
||||
{
|
||||
if(!$tags) {
|
||||
return false;
|
||||
if(is_null($tags)) {
|
||||
$this->stateChanges("tags", NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
$parsed = explode(",", $tags);
|
||||
if(sizeof($parsed) < 1 || $parsed[0] == "") {
|
||||
$this->stateChanges("tags", NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
$result = "";
|
||||
foreach($parsed as $tag) {
|
||||
$result .= trim($tag) . ($tag != end($parsed) ? "," : '');
|
||||
|
|
|
@ -45,6 +45,19 @@ class Documents
|
|||
return $n_doc;
|
||||
}
|
||||
|
||||
function getDocumentByIdUnsafe(int $virtual_id, int $real_id): ?Document
|
||||
{
|
||||
$doc = $this->documents->where(['virtual_id' => $virtual_id, 'id' => $real_id]);
|
||||
|
||||
$doc = $doc->fetch();
|
||||
if(is_null($doc))
|
||||
return NULL;
|
||||
|
||||
$n_doc = new Document($doc);
|
||||
|
||||
return $n_doc;
|
||||
}
|
||||
|
||||
function getDocumentsByOwner(int $owner, int $order = 0, int $type = -1): EntityStream
|
||||
{
|
||||
$search = $this->documents->where([
|
||||
|
@ -90,6 +103,27 @@ class Documents
|
|||
return $response;
|
||||
}
|
||||
|
||||
function getTags(int $owner_id, ?int $type = 0): array
|
||||
{
|
||||
$query = "SELECT `tags` FROM `documents` WHERE `owner` = ? AND `deleted` = 0 AND `unlisted` = 0 ";
|
||||
if($type > 0 && $type < 9) {
|
||||
$query .= "AND `type` = $type";
|
||||
}
|
||||
|
||||
$query .= " AND `tags` IS NOT NULL ORDER BY `id`";
|
||||
$result = DatabaseConnection::i()->getConnection()->query($query, $owner_id);
|
||||
$tags = [];
|
||||
foreach($result as $res) {
|
||||
$tags[] = $res->tags;
|
||||
}
|
||||
$imploded_tags = implode(",", $tags);
|
||||
$exploded_tags = array_values(array_unique(explode(",", $imploded_tags)));
|
||||
if($exploded_tags[0] == "")
|
||||
return [];
|
||||
|
||||
return array_slice($exploded_tags, 0, 50);
|
||||
}
|
||||
|
||||
function find(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false]): Util\EntityStream
|
||||
{
|
||||
$result = $this->documents->where("name LIKE ?", "%$query%")->where([
|
||||
|
|
|
@ -36,6 +36,7 @@ final class DocumentsPresenter extends OpenVKPresenter
|
|||
|
||||
$docs = (new Documents)->getDocumentsByOwner($owner_id, (int)$order, (int)$tab);
|
||||
$this->template->tabs = (new Documents)->getTypes($owner_id);
|
||||
$this->template->tags = (new Documents)->getTags($owner_id, (int)$tab);
|
||||
$this->template->current_tab = $tab;
|
||||
$this->template->order = $order;
|
||||
$this->template->count = $docs->size();
|
||||
|
@ -134,7 +135,7 @@ final class DocumentsPresenter extends OpenVKPresenter
|
|||
$this->assertUserLoggedIn();
|
||||
|
||||
$access_key = $this->queryParam("key");
|
||||
$doc = (new Documents)->getDocumentById((int)$virtual_id, (int)$real_id);
|
||||
$doc = (new Documents)->getDocumentById((int)$virtual_id, (int)$real_id, $access_key);
|
||||
if(!$doc || $doc->isDeleted())
|
||||
$this->notFound();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<div n:foreach="$tabs as $tab" class="mb_tab" n:attr="id => $tab['type'] == $current_tab ? active">
|
||||
<a href="?tab={$tab['type']}">
|
||||
{$tab["name"]}
|
||||
<span class="special_counter">{$tab["count"]}</span>
|
||||
<span n:if="$tab['count'] > 1" class="special_counter">{$tab["count"]}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -44,24 +44,35 @@
|
|||
<div class="summaryBar display_flex_row display_flex_space_between">
|
||||
<div class="summary">{tr($locale_string, $count)}.</div>
|
||||
|
||||
<select name="docs_sort">
|
||||
<select n:if="$count > 3" name="docs_sort">
|
||||
<option n:attr="selected => $order == 0" value="0">{_documents_sort_add}</option>
|
||||
<option n:attr="selected => $order == 1" value="1">{_documents_sort_alphabet}</option>
|
||||
<option n:attr="selected => $order == 2" value="2">{_documents_sort_size}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="container_white scroll_container">
|
||||
{if $count > 0}
|
||||
{foreach $docs as $doc}
|
||||
{if $is_gallery}
|
||||
{include "components/image.xml", doc => $doc, scroll_context => true, club => isset($group) ? $group : NULL}
|
||||
{else}
|
||||
{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}
|
||||
<div n:attr="id => !$is_gallery && sizeof($tags) > 0 ? search_page">
|
||||
<div n:class="container_white, scroll_container, !$is_gallery && sizeof($tags) > 0 ? page_wrap_content_main">
|
||||
{if $count > 0}
|
||||
{foreach $docs as $doc}
|
||||
{if $is_gallery}
|
||||
{include "components/image.xml", doc => $doc, scroll_context => true, club => isset($group) ? $group : NULL}
|
||||
{else}
|
||||
{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}
|
||||
</div>
|
||||
|
||||
<div n:if="!$is_gallery && sizeof($tags) > 0" class='page_wrap_content_options verticalGrayTabsWrapper'>
|
||||
<div class="page_wrap_content_options_list verticalGrayTabs with_padding">
|
||||
<a id="used">{_documents_all}</a>
|
||||
{foreach $tags as $tag}
|
||||
<a href="/search?section=docs&tags={urlencode($tag)}">{$tag}</a>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{include "../components/paginator.xml", conf => $paginatorConf}
|
||||
</div>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{var $modifiable = $doc->canBeModifiedBy($thisUser)}
|
||||
|
||||
<div n:class="docMainItem, docListViewItem, $scroll_context ? scroll_node" data-id="{$doc->getPrettiestId()}">
|
||||
<a class="viewerOpener" href="/doc{$doc->getPrettyId()}">
|
||||
<a class="viewerOpener" href="/doc{$doc->getPrettyId()}?key={$doc->getAccessKey()}">
|
||||
{if $preview}
|
||||
<img class="doc_icon" alt="document_preview" src="{$preview->getURLBySizeId('tiny')}">
|
||||
{else}
|
||||
|
@ -14,7 +14,7 @@
|
|||
{/if}
|
||||
</a>
|
||||
<div class="doc_content noOverflow">
|
||||
<a class="viewerOpener" href="/doc{$doc->getPrettyId()}"><b class="noOverflow doc_name">{$doc->getName()}</b></a>
|
||||
<a class="viewerOpener" href="/doc{$doc->getPrettyId()}?key={$doc->getAccessKey()}"><b class="noOverflow doc_name">{$doc->getName()}</b></a>
|
||||
|
||||
<div class="doc_content_info">
|
||||
<span>{$doc->getPublicationTime()}</span>,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{var $copied = !isset($club) ? $doc->isCopiedBy($thisUser) : $doc->isCopiedBy($club)}
|
||||
{var $modifiable = $doc->canBeModifiedBy($thisUser)}
|
||||
|
||||
<a href="/doc{$doc->getPrettyId()}" n:class="docMainItem, viewerOpener, docGalleryItem, $scroll_context ? scroll_node" data-id="{$doc->getPrettiestId()}">
|
||||
<a href="/doc{$doc->getPrettyId()}?key={$doc->getAccessKey()}" n:class="docMainItem, viewerOpener, docGalleryItem, $scroll_context ? scroll_node" data-id="{$doc->getPrettiestId()}">
|
||||
<img loading="lazy" src="{$preview->getURLBySizeId('medium')}" alt="gallery photo">
|
||||
|
||||
<div class="doc_top_panel doc_shown_by_hover">
|
||||
|
|
|
@ -297,7 +297,7 @@
|
|||
</div>
|
||||
<div>
|
||||
<div class="content_subtitle">
|
||||
{tr("documents", $topicsCount)}
|
||||
{tr("documents", $docsCount)}
|
||||
<div style="float: right;">
|
||||
<a href="/docs{$club->getRealId()}">{_all_title}</a>
|
||||
</div>
|
||||
|
|
|
@ -4176,10 +4176,14 @@ hr {
|
|||
background-position-y: -21px;
|
||||
}
|
||||
|
||||
.docListViewItem .doc_volume #report_icon, .docGalleryItem .doc_top_panel #report_icon {
|
||||
.docListViewItem .doc_volume #report_icon {
|
||||
background-position-x: -40px;
|
||||
}
|
||||
|
||||
.docGalleryItem .doc_top_panel #report_icon {
|
||||
background-position-x: -24px;
|
||||
}
|
||||
|
||||
.docListViewItem .doc_volume #edit_icon {
|
||||
background-position-x: -20px;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,9 @@ u(document).on("drop", "#_document_upload_frame", (e) => {
|
|||
|
||||
u(document).on('click', '.docMainItem #edit_icon', async (e) => {
|
||||
e.preventDefault()
|
||||
if(u("#ajloader").hasClass("shown")) {
|
||||
return
|
||||
}
|
||||
|
||||
const target = u(e.target).closest("#edit_icon")
|
||||
const item = target.closest('.docMainItem')
|
||||
|
@ -121,10 +124,10 @@ u(document).on('click', '.docMainItem #edit_icon', async (e) => {
|
|||
title: tr("document_editing_in_general"),
|
||||
body: `
|
||||
<p><b>${tr("info_name")}</b></p>
|
||||
<input type="text" name="doc_name" value="${doc.title}" placeholder="...">
|
||||
<input maxlength="128" type="text" name="doc_name" value="${doc.title}" placeholder="...">
|
||||
|
||||
<label>
|
||||
<input maxlength="255" value="0" type="radio" name="doc_access" ${doc.folder_id != 3 ? "checked" : ''}>
|
||||
<input value="0" type="radio" name="doc_access" ${doc.folder_id != 3 ? "checked" : ''}>
|
||||
${tr("private_document")}
|
||||
</label>
|
||||
<br>
|
||||
|
|
|
@ -2331,6 +2331,7 @@
|
|||
"remove" = "Remove";
|
||||
|
||||
"document" = "Document";
|
||||
"documents_all" = "All documents";
|
||||
"document_type_0" = "All";
|
||||
"document_type_1" = "Text";
|
||||
"document_type_2" = "Archives";
|
||||
|
|
|
@ -2226,6 +2226,7 @@
|
|||
"remove" = "Удалить";
|
||||
|
||||
"document" = "Документ";
|
||||
"documents_all" = "Все документы";
|
||||
"document_type_0" = "Все";
|
||||
"document_type_1" = "Текстовые";
|
||||
"document_type_2" = "Архивы";
|
||||
|
|
Loading…
Reference in a new issue