From 4b95283a5543ca9d566b49a50b7f95c7bfbc0052 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:56:06 +0300 Subject: [PATCH] things --- Web/Models/Repositories/Documents.php | 4 +- Web/Presenters/CommentPresenter.php | 2 +- Web/Presenters/WallPresenter.php | 2 +- Web/Presenters/templates/Documents/List.xml | 2 +- .../templates/Documents/components/image.xml | 2 +- .../templates/components/attachment.xml | 18 ++- .../templates/components/textArea.xml | 4 + Web/Presenters/templates/components/wall.xml | 2 +- Web/static/css/main.css | 19 ++- Web/static/js/al_docs.js | 110 ++++++++++++++++++ Web/static/js/al_wall.js | 4 + locales/en.strings | 72 ++++++++++++ 12 files changed, 226 insertions(+), 15 deletions(-) diff --git a/Web/Models/Repositories/Documents.php b/Web/Models/Repositories/Documents.php index b102c30f..b6c51bf0 100644 --- a/Web/Models/Repositories/Documents.php +++ b/Web/Models/Repositories/Documents.php @@ -27,7 +27,7 @@ class Documents } # 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]); /*if($access_key) { @@ -74,7 +74,7 @@ class Documents 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 = []; foreach($result as $res) { if($res->count < 1 || $res->type == 0) continue; diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index 7ab74ac0..76279ad6 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -88,7 +88,7 @@ final class CommentPresenter extends OpenVKPresenter 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"]); if(sizeof($vertical_attachments_array) > 0) { - $vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note']); + $vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note', 'doc']); } } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 12067ad0..3a7605bb 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -294,7 +294,7 @@ final class WallPresenter extends OpenVKPresenter 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"]); if(sizeof($vertical_attachments_array) > 0) { - $vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note']); + $vertical_attachments = parseAttachments($vertical_attachments_array, ['audio', 'note', 'doc']); } } diff --git a/Web/Presenters/templates/Documents/List.xml b/Web/Presenters/templates/Documents/List.xml index 61613c50..10f23944 100644 --- a/Web/Presenters/templates/Documents/List.xml +++ b/Web/Presenters/templates/Documents/List.xml @@ -27,7 +27,7 @@ -
+
{_document_type_0} diff --git a/Web/Presenters/templates/Documents/components/image.xml b/Web/Presenters/templates/Documents/components/image.xml index e10dad17..68edcd66 100644 --- a/Web/Presenters/templates/Documents/components/image.xml +++ b/Web/Presenters/templates/Documents/components/image.xml @@ -12,7 +12,7 @@
-
+
{$doc->getName()} {readable_filesize($doc->getFilesize())}
diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml index b60fbc1d..2ceeed27 100644 --- a/Web/Presenters/templates/components/attachment.xml +++ b/Web/Presenters/templates/components/attachment.xml @@ -66,8 +66,22 @@ {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} +
+
+ +
+ {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} + {/if}
{else} {_version_incompatibility} diff --git a/Web/Presenters/templates/components/textArea.xml b/Web/Presenters/templates/components/textArea.xml index bd2291c3..1e714d3e 100644 --- a/Web/Presenters/templates/components/textArea.xml +++ b/Web/Presenters/templates/components/textArea.xml @@ -90,6 +90,10 @@ {_note} + + + {_document} + {_graffiti} diff --git a/Web/Presenters/templates/components/wall.xml b/Web/Presenters/templates/components/wall.xml index 4e4c63f4..d6b68b53 100644 --- a/Web/Presenters/templates/components/wall.xml +++ b/Web/Presenters/templates/components/wall.xml @@ -10,7 +10,7 @@
- {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}
diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 0c6d6af4..f7d34f95 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -4017,21 +4017,21 @@ hr { padding: 10px 10px; } -#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem { +.docGalleryItem { height: 200px; cursor: pointer; position: relative; /*width: 200px;*/ } -#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem img { +.docGalleryItem img { width: 100%; height: 100%; display: block; object-fit: cover; } -#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem .doc_bottom_panel { +.docGalleryItem .doc_bottom_panel { position: absolute; bottom: 0px; background: rgba(1, 1, 1, 0.7); @@ -4047,15 +4047,15 @@ hr { 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; } -#docs_page_wrapper .docs_page_content.docs_page_gallery .scroll_container .docGalleryItem .doc_bottom_panel span { +.docGalleryItem .doc_bottom_panel span { 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; width: max-content; } @@ -4202,3 +4202,10 @@ hr { min-height: 30px; border-bottom: unset; } + +.attachments .docGalleryItem { + display: block; + min-width: 200px; + width: 50%; + margin-bottom: 4px; +} diff --git a/Web/static/js/al_docs.js b/Web/static/js/al_docs.js index 2b185b85..bd459135 100644 --- a/Web/static/js/al_docs.js +++ b/Web/static/js/al_docs.js @@ -300,3 +300,113 @@ u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", asy 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: ` +
+
+
+
+
+ `, + 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(`
`) + 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(` +
+
+ ${is_attached ? tr("detach") : tr("attach")} +
+
+ `) + }) + + if(page < pages_count - 1) { + insert_place.append(` +
+ ${tr('show_more')} +
`) + } + } + + // 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(` +
+ `) + } + }) + + __recieveDocs(0) +}) diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index e6229b28..c04f1932 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -999,6 +999,10 @@ u(document).on("click", "#editPost", async (e) => { ${tr('audio')} + + + ${tr('document')} + ${type == 'post' ? ` ${tr('note')} diff --git a/locales/en.strings b/locales/en.strings index 1aff6d88..f1259a67 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -710,6 +710,7 @@ "search_for_notes" = "Search for notes"; "search_for_audios" = "Search for music"; "search_for_audios_playlists" = "Search for playlists"; +"search_for_docs" = "Search for documents"; "search_button" = "Find"; "search_placeholder" = "Start typing any name, title or word"; "results_zero" = "No results"; @@ -1307,6 +1308,7 @@ "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_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_comment" = "You are about to report this comment."; @@ -2113,6 +2115,7 @@ "s_videos" = "Videos"; "s_audios" = "Music"; "s_audios_playlists" = "Playlists"; +"s_documents" = "Documents"; "s_by_people" = "for users"; "s_by_groups" = "for groups"; @@ -2122,6 +2125,7 @@ "s_by_apps" = "for apps"; "s_by_audios" = "for audios"; "s_by_audios_playlists" = "for playlists"; +"s_by_documents" = "for documents"; "s_order_by" = "Order by..."; @@ -2144,6 +2148,7 @@ "s_date_after" = "After"; "s_main" = "Main"; +"s_type" = "Type"; "s_now_on_site" = "now on site"; "s_with_photo" = "with photo"; @@ -2308,3 +2313,70 @@ "upd_in_general" = "Avatar update"; "on_wall" = "On wall"; "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";