This commit is contained in:
mrilyew 2024-12-30 15:56:06 +03:00
parent 1602313160
commit 4b95283a55
12 changed files with 226 additions and 15 deletions

View file

@ -27,7 +27,7 @@ class Documents
} }
# By "Virtual ID" and "Absolute ID" (to not leak owner's id). # By "Virtual ID" and "Absolute ID" (to not leak owner's id).
function getDocumentById(int $virtual_id, int $real_id, ?string $access_key = NULL): ?Document function getDocumentById(int $virtual_id, int $real_id, string $access_key = NULL): ?Document
{ {
$doc = $this->documents->where(['virtual_id' => $virtual_id, 'id' => $real_id]); $doc = $this->documents->where(['virtual_id' => $virtual_id, 'id' => $real_id]);
/*if($access_key) { /*if($access_key) {
@ -74,7 +74,7 @@ class Documents
function getTypes(int $owner_id): array function getTypes(int $owner_id): array
{ {
$result = DatabaseConnection::i()->getConnection()->query("SELECT `type`, COUNT(*) AS `count` FROM `documents` WHERE `owner` = $owner_id AND `deleted` = 0 AND `unlisted` = 0 GROUP BY `type` ORDER BY `type`"); $result = DatabaseConnection::i()->getConnection()->query("SELECT `type`, COUNT(*) AS `count` FROM `documents` WHERE `owner` = ? AND `deleted` = 0 AND `unlisted` = 0 GROUP BY `type` ORDER BY `type`", $owner_id);
$response = []; $response = [];
foreach($result as $res) { foreach($result as $res) {
if($res->count < 1 || $res->type == 0) continue; if($res->count < 1 || $res->type == 0) continue;

View file

@ -88,7 +88,7 @@ final class CommentPresenter extends OpenVKPresenter
if(!empty($this->postParam("vertical_attachments"))) { if(!empty($this->postParam("vertical_attachments"))) {
$vertical_attachments_array = array_slice(explode(",", $this->postParam("vertical_attachments")), 0, OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["postSizes"]["maxAttachments"]); $vertical_attachments_array = array_slice(explode(",", $this->postParam("vertical_attachments")), 0, OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["postSizes"]["maxAttachments"]);
if(sizeof($vertical_attachments_array) > 0) { if(sizeof($vertical_attachments_array) > 0) {
$vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note']); $vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note', 'doc']);
} }
} }

View file

@ -294,7 +294,7 @@ final class WallPresenter extends OpenVKPresenter
if(!empty($this->postParam("vertical_attachments"))) { if(!empty($this->postParam("vertical_attachments"))) {
$vertical_attachments_array = array_slice(explode(",", $this->postParam("vertical_attachments")), 0, OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["postSizes"]["maxAttachments"]); $vertical_attachments_array = array_slice(explode(",", $this->postParam("vertical_attachments")), 0, OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["postSizes"]["maxAttachments"]);
if(sizeof($vertical_attachments_array) > 0) { if(sizeof($vertical_attachments_array) > 0) {
$vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note']); $vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note', 'doc']);
} }
} }

View file

@ -27,7 +27,7 @@
</form> </form>
<input n:if="$canUpload" id="upload_entry_point" class="button" type="button" value="{_upload_button}" {if isset($group)}data-gid="{$group->getId()}"{/if}> <input n:if="$canUpload" id="upload_entry_point" class="button" type="button" value="{_upload_button}" {if isset($group)}data-gid="{$group->getId()}"{/if}>
</div> </div>
<div class="docs_page_tabs"> <div n:if="sizeof($tabs) > 1" class="docs_page_tabs">
<div class="mb_tabs"> <div class="mb_tabs">
<div class="mb_tab" n:attr="id => $current_tab == 0 ? active"> <div class="mb_tab" n:attr="id => $current_tab == 0 ? active">
<a href="?tab=0">{_document_type_0}</a> <a href="?tab=0">{_document_type_0}</a>

View file

@ -12,7 +12,7 @@
<div class="doc_volume_action" n:if="$copied && !$copyImportance" id="remove_icon"></div> <div class="doc_volume_action" n:if="$copied && !$copyImportance" id="remove_icon"></div>
</div> </div>
<div class="doc_bottom_panel doc_shown_by_hover doc_content"> <div n:class="doc_bottom_panel, doc_shown_by_hover, doc_content, $showInfo ? info_shown">
<span class="doc_bottom_panel_name noOverflow doc_name">{$doc->getName()}</span> <span class="doc_bottom_panel_name noOverflow doc_name">{$doc->getName()}</span>
<span class="doc_bottom_panel_size">{readable_filesize($doc->getFilesize())}</span> <span class="doc_bottom_panel_size">{readable_filesize($doc->getFilesize())}</span>
</div> </div>

View file

@ -66,8 +66,22 @@
{include "../Audio/player.xml", audio => $attachment} {include "../Audio/player.xml", audio => $attachment}
</div> </div>
{elseif $attachment instanceof \openvk\Web\Models\Entities\Document} {elseif $attachment instanceof \openvk\Web\Models\Entities\Document}
<div style="width:100%;" data-att_type='audio' data-att_id="{$attachment->getPrettyId()}"> <div style="width:100%;">
<div style="display:none" data-att_type='doc' data-att_id="{$attachment->getPrettyId()}">
<div class="docMainItem attachment_doc attachment_note" data-id="{$attachment->getPrettiestId()}">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 10"><polygon points="0 0 0 10 8 10 8 4 4 4 4 0 0 0"/><polygon points="5 0 5 3 8 3 5 0"/></svg>
<div class='attachment_note_content'>
<span class="attachment_note_text">{_document}</span>
<span class="attachment_note_name"><a href="/doc{$attachment->getPrettyId()}">{ovk_proc_strtr($attachment->getName(), 50)}</a></span>
</div>
</div>
</div>
{if $attachment->isImage()}
{include "../Documents/components/image.xml", doc => $attachment, copyImportance => true, showInfo => true}
{else}
{include "../Documents/components/doc.xml", doc => $attachment, copyImportance => true, noTags => true} {include "../Documents/components/doc.xml", doc => $attachment, copyImportance => true, noTags => true}
{/if}
</div> </div>
{else} {else}
<span style="color:red;">{_version_incompatibility}</span> <span style="color:red;">{_version_incompatibility}</span>

View file

@ -90,6 +90,10 @@
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-srt.png" /> <img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-srt.png" />
{_note} {_note}
</a> </a>
<a n:if="$docs ?? false" id="__documentAttachment">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-octet-stream.png" />
{_document}
</a>
<a n:if="$graffiti ?? false" onclick="initGraffiti(event);"> <a n:if="$graffiti ?? false" onclick="initGraffiti(event);">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/actions/draw-brush.png" /> <img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/actions/draw-brush.png" />
{_graffiti} {_graffiti}

View file

@ -10,7 +10,7 @@
<div class="insertThere" id="postz"></div> <div class="insertThere" id="postz"></div>
<div id="underHeader"> <div id="underHeader">
<div n:if="$canPost" class="content_subtitle"> <div n:if="$canPost" class="content_subtitle">
{include "../components/textArea.xml", route => "/wall$owner/makePost", graffiti => true, polls => true, notes => true, hasSource => true, geo => true} {include "../components/textArea.xml", route => "/wall$owner/makePost", graffiti => true, polls => true, notes => true, hasSource => true, geo => true, docs => true}
</div> </div>
<div class="content scroll_container"> <div class="content scroll_container">

View file

@ -4017,21 +4017,21 @@ hr {
padding: 10px 10px; padding: 10px 10px;
} }
#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem { .docGalleryItem {
height: 200px; height: 200px;
cursor: pointer; cursor: pointer;
position: relative; position: relative;
/*width: 200px;*/ /*width: 200px;*/
} }
#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem img { .docGalleryItem img {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: block; display: block;
object-fit: cover; object-fit: cover;
} }
#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem .doc_bottom_panel { .docGalleryItem .doc_bottom_panel {
position: absolute; position: absolute;
bottom: 0px; bottom: 0px;
background: rgba(1, 1, 1, 0.7); background: rgba(1, 1, 1, 0.7);
@ -4047,15 +4047,15 @@ hr {
opacity: 0; opacity: 0;
} }
#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem:hover .doc_shown_by_hover { .docGalleryItem:hover .doc_shown_by_hover, .doc_shown_by_hover.info_shown {
opacity: 1; opacity: 1;
} }
#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem .doc_bottom_panel span { .docGalleryItem .doc_bottom_panel span {
color: white; color: white;
} }
#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem .doc_bottom_panel .doc_bottom_panel_size { .docGalleryItem .doc_bottom_panel .doc_bottom_panel_size {
max-width: 49px; max-width: 49px;
width: max-content; width: max-content;
} }
@ -4202,3 +4202,10 @@ hr {
min-height: 30px; min-height: 30px;
border-bottom: unset; border-bottom: unset;
} }
.attachments .docGalleryItem {
display: block;
min-width: 200px;
width: 50%;
margin-bottom: 4px;
}

View file

@ -300,3 +300,113 @@ u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", asy
CMessageBox.toggleLoader() CMessageBox.toggleLoader()
}) })
u(document).on('click', '#__documentAttachment', async (e) => {
const per_page = 10
const form = u(e.target).closest('form')
const msg = new CMessageBox({
title: tr('select_doc'),
body: `
<div class='attachment_selector'>
<div id='attachment_insert' style='height: 325px;'>
<div class="docsInsert"></div>
</div>
</div>
`,
buttons: [tr('close')],
callbacks: [Function.noop]
})
msg.getNode().attr('style', 'width: 340px;')
msg.getNode().find('.ovk-diag-body').attr('style', 'height:335px;padding:0px;')
async function __recieveDocs(page) {
u('#gif_loader').remove()
u('#attachment_insert').append(`<div id='gif_loader'></div>`)
const insert_place = u('#attachment_insert .docsInsert')
let docs = null
try {
docs = await window.OVKAPI.call('docs.get', {'owner_id': window.openvk.current_id, 'count': per_page, 'offset': per_page * page})
} catch(e) {
u("#gif_loader").remove()
insert_place.html("Err")
return
}
u("#gif_loader").remove()
const pages_count = Math.ceil(Number(docs.count) / per_page)
if(docs.count < 1) {
insert_place.append(tr('no_docs'))
}
docs.items.forEach(doc => {
is_attached = (form.find(`.upload-item[data-type='doc'][data-id='${doc.owner_id}_${doc.id}']`)).length > 0
insert_place.append(`
<div class='display_flex_row _content' data-attachmentdata="${doc.owner_id}_${doc.id}_${doc.access_key}" data-name='${escapeHtml(doc.title)}'>
<div class="attachDoc" id='__attach_doc'>
<span>${is_attached ? tr("detach") : tr("attach")}</span>
</div>
</div>
`)
})
if(page < pages_count - 1) {
insert_place.append(`
<div id="show_more" data-pagesCount="${pages_count}" data-page="${page + 1}">
<span>${tr('show_more')}</span>
</div>`)
}
}
// next page
u(".ovk-diag-body .attachment_selector").on("click", "#show_more", async (ev) => {
const target = u(ev.target).closest('#show_more')
target.addClass('lagged')
await __recieveDocs(Number(target.nodes[0].dataset.page))
target.remove()
})
u(".ovk-diag-body .attachment_selector").on("click", "#__attach_doc", async (ev) => {
if(u(form).find(`.upload-item`).length > window.openvk.max_attachments) {
makeError(tr('too_many_attachments'), 'Red', 10000, 1)
return
}
const target = u(ev.target).closest('._content')
const button = target.find('#__attach_doc')
const dataset = target.nodes[0].dataset
const is_attached = (form.find(`.upload-item[data-type='doc'][data-id='${dataset.attachmentdata}']`)).length > 0
if(is_attached) {
(form.find(`.upload-item[data-type='doc'][data-id='${dataset.attachmentdata}']`)).remove()
button.html(tr('attach'))
} else {
if(form.find(`.upload-item`).length + 1 > window.openvk.max_attachments) {
makeError(tr('too_many_attachments'), 'Red', 10000, 1)
return
}
button.html(tr('detach'))
form.find('.post-vertical').append(`
<div class="vertical-attachment upload-item" draggable="true" data-type='doc' data-id="${dataset.attachmentdata}">
<div class='vertical-attachment-content' draggable="false">
<div class="docMainItem attachment_doc attachment_note">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 10"><polygon points="0 0 0 10 8 10 8 4 4 4 4 0 0 0"/><polygon points="5 0 5 3 8 3 5 0"/></svg>
<div class='attachment_note_content'>
<span class="attachment_note_text">${tr("document")}</span>
<span class="attachment_note_name"><a href="/doc${dataset.attachmentdata}">${ovk_proc_strtr(escapeHtml(dataset.name), 66)}</a></span>
</div>
</div>
</div>
<div class='vertical-attachment-remove'>
<div id='small_remove_button'></div>
</div>
</div>
`)
}
})
__recieveDocs(0)
})

View file

@ -999,6 +999,10 @@ u(document).on("click", "#editPost", async (e) => {
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/audio-ac3.png" /> <img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/audio-ac3.png" />
${tr('audio')} ${tr('audio')}
</a> </a>
<a id="__documentAttachment">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-octet-stream.png" />
${tr('document')}
</a>
${type == 'post' ? `<a id="__notesAttachment"> ${type == 'post' ? `<a id="__notesAttachment">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-srt.png" /> <img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-srt.png" />
${tr('note')} ${tr('note')}

View file

@ -710,6 +710,7 @@
"search_for_notes" = "Search for notes"; "search_for_notes" = "Search for notes";
"search_for_audios" = "Search for music"; "search_for_audios" = "Search for music";
"search_for_audios_playlists" = "Search for playlists"; "search_for_audios_playlists" = "Search for playlists";
"search_for_docs" = "Search for documents";
"search_button" = "Find"; "search_button" = "Find";
"search_placeholder" = "Start typing any name, title or word"; "search_placeholder" = "Start typing any name, title or word";
"results_zero" = "No results"; "results_zero" = "No results";
@ -1307,6 +1308,7 @@
"going_to_report_user" = "You are about to report this user."; "going_to_report_user" = "You are about to report this user.";
"going_to_report_video" = "You are about to report this video."; "going_to_report_video" = "You are about to report this video.";
"going_to_report_audio" = "You are about to report this audio."; "going_to_report_audio" = "You are about to report this audio.";
"going_to_report_doc" = "You are about to report this document.";
"going_to_report_post" = "You are about to report this post."; "going_to_report_post" = "You are about to report this post.";
"going_to_report_comment" = "You are about to report this comment."; "going_to_report_comment" = "You are about to report this comment.";
@ -2113,6 +2115,7 @@
"s_videos" = "Videos"; "s_videos" = "Videos";
"s_audios" = "Music"; "s_audios" = "Music";
"s_audios_playlists" = "Playlists"; "s_audios_playlists" = "Playlists";
"s_documents" = "Documents";
"s_by_people" = "for users"; "s_by_people" = "for users";
"s_by_groups" = "for groups"; "s_by_groups" = "for groups";
@ -2122,6 +2125,7 @@
"s_by_apps" = "for apps"; "s_by_apps" = "for apps";
"s_by_audios" = "for audios"; "s_by_audios" = "for audios";
"s_by_audios_playlists" = "for playlists"; "s_by_audios_playlists" = "for playlists";
"s_by_documents" = "for documents";
"s_order_by" = "Order by..."; "s_order_by" = "Order by...";
@ -2144,6 +2148,7 @@
"s_date_after" = "After"; "s_date_after" = "After";
"s_main" = "Main"; "s_main" = "Main";
"s_type" = "Type";
"s_now_on_site" = "now on site"; "s_now_on_site" = "now on site";
"s_with_photo" = "with photo"; "s_with_photo" = "with photo";
@ -2308,3 +2313,70 @@
"upd_in_general" = "Avatar update"; "upd_in_general" = "Avatar update";
"on_wall" = "On wall"; "on_wall" = "On wall";
"sign_short" = "Sign"; "sign_short" = "Sign";
/* Documents */
"my_documents" = "Documents";
"my_documents_objectively" = "My Documents";
"documents_of_group" = "Group's documents";
"search_by_documents" = "Search for documents..";
"documents" = "Documents";
"document_uploading_in_general" = "Upload document";
"document_editing_in_general" = "Edit document";
"file" = "File";
"tags" = "Tags";
"owner_is_hidden" = "Hide author";
"accessbility" = "Accessbility";
"download_file" = "Download file";
"remove" = "Remove";
"document" = "Document";
"document_type_0" = "All";
"document_type_1" = "Text";
"document_type_2" = "Archives";
"document_type_3" = "GIF";
"document_type_4" = "Images";
"document_type_5" = "Audio";
"document_type_6" = "Video";
"document_type_7" = "Books";
"document_type_8" = "Another";
"documents_one" = "$1 document";
"documents_few" = "$1 documents";
"documents_many" = "$1 documents";
"documents_other" = "$1 documents";
"documents_zero" = "$1 documents";
"you_have_x_documents_one" = "You have $1 document";
"you_have_x_documents_few" = "You have $1 documents";
"you_have_x_documents_many" = "You have $1 documents";
"you_have_x_documents_other" = "You have $1 documents";
"you_have_x_documents_zero" = "You have $1 documents";
"group_has_x_documents_one" = "This group has $1 document";
"group_has_x_documents_few" = "This group has $1 documents";
"group_has_x_documents_many" = "This group has $1 documents";
"group_has_x_documents_other" = "This group has $1 documents";
"group_has_x_documents_zero" = "This group has $1 documents";
"x_documents_in_tab_one" = "$1 document at this tab";
"x_documents_in_tab_few" = "$1 documents at this tab";
"x_documents_in_tab_many" = "$1 documents at this tab";
"x_documents_in_tab_other" = "$1 documents at this tab";
"x_documents_in_tab_zero" = "$1 documents at this tab";
"there_is_no_documents_alright" = "There is no documents.";
"limitations_file_limit_size" = "File must not exceed $1 MB";
"limitations_file_allowed_formats" = "Allowed formats";
"limitations_file_author_rights" = "File must not violate copyright and site rules";
"select_file_fp" = "Select file";
"error_file_too_big" = "File is too big.";
"error_file_invalid_format" = "File format is not allowed.";
"error_file_adding_copied" = "File is already added.";
"error_file_preview" = "Error when uploading file: weird image.";
"private_document" = "Private (by link)";
"public_document" = "Public";
"documents_sort_add" = "By date";
"documents_sort_alphabet" = "A-Z";
"documents_sort_size" = "By size";