From b63b5f096c7263e1a4d3d7b34c807f67fcdf91cc Mon Sep 17 00:00:00 2001 From: JLTRY Date: Mon, 6 Jan 2025 09:52:20 +0100 Subject: [PATCH 1/4] Add download link to be able to view attachement ina poprup or download it --- .../site/tmpl/attachments/default.php | 84 +++++++++---------- .../en-GB/en-GB.plg_content_attachments.ini | 1 + .../fr-FR/fr-FR.plg_content_attachments.ini | 1 + 3 files changed, 40 insertions(+), 46 deletions(-) diff --git a/attachments_component/site/tmpl/attachments/default.php b/attachments_component/site/tmpl/attachments/default.php index 38a9f982..3c7bcbf5 100644 --- a/attachments_component/site/tmpl/attachments/default.php +++ b/attachments_component/site/tmpl/attachments/default.php @@ -175,51 +175,37 @@ if ( $this->show_file_links ) { if ( $attachment->uri_type == 'file' ) { // Handle file attachments - if ( $this->secure ) { - $url = Route::_($base_url . "index.php?option=com_attachments&task=download&id=" . (int)$attachment->id); + // We need to urlencode the filename + $offset = strlen(AttachmentsDefines::$ATTACHMENTS_SUBDIR."/{$attachment->parent_entity}/{$attachment->parent_id}/"); + $url_path = mb_strcut($attachment->url, 0, $offset); + $url_filename = rawurlencode(mb_strcut($attachment->url, $offset)); + $url = $base_url . $url_path . $url_filename; + + if (strtoupper(substr(PHP_OS,0,3) == 'WIN')) { + // $url = utf8_encode($url); Deprecated from php 8.2 + $url = iconv('ISO-8859-1', 'UTF-8', $url); } - else { - // We need to urlencode the filename - $offset = strlen(AttachmentsDefines::$ATTACHMENTS_SUBDIR."/{$attachment->parent_entity}/{$attachment->parent_id}/"); - $url_path = mb_strcut($attachment->url, 0, $offset); - $url_filename = rawurlencode(mb_strcut($attachment->url, $offset)); - $url = $base_url . $url_path . $url_filename; - - if (strtoupper(substr(PHP_OS,0,3) == 'WIN')) { - // $url = utf8_encode($url); Deprecated from php 8.2 - $url = iconv('ISO-8859-1', 'UTF-8', $url); - } - } - $tooltip = Text::sprintf('ATTACH_DOWNLOAD_THIS_FILE_S', $actual_filename); + $tooltip = Text::_('ATTACH_VIEW_THIS_ATTACHMENT'); } else { - // Handle URL "attachments" - if ( $this->secure ) { - $url = Route::_($base_url . "index.php?option=com_attachments&task=download&id=" . (int)$attachment->id); - $tooltip = Text::sprintf('ATTACH_ACCESS_THIS_URL_S', $filename); - } - else { // Handle the link url if not logged in but link displayed for guests - $url = ''; - if ( !$logged_in AND ($attachment->access != '1')) { - $guest_levels = $this->params->get('show_guest_access_levels', Array('1')); - if ( in_array($attachment->access, $guest_levels) ) { - /** @var \Joomla\CMS\Application\CMSApplication $app */ - $app = Factory::getApplication(); - $return = $app->getUserState('com_attachments.current_url', ''); - $url = Route::_($base_url . 'index.php?option=com_attachments&task=requestLogin' . $return); - $target = ''; - } - } - if ( $url == '' ) { - $url = $attachment->url; - } - $tooltip = Text::sprintf('ATTACH_ACCESS_THIS_URL_S', $attachment->url); - } - } - - $show_in_modal = (!$app->client->mobile) && ($this->file_link_open_mode == 'in_a_popup') && ($attachment->file_type === "application/pdf" || str_starts_with($attachment->file_type, "image/")); - + $url = ''; + if ( !$logged_in AND ($attachment->access != '1')) { + $guest_levels = $this->params->get('show_guest_access_levels', Array('1')); + if ( in_array($attachment->access, $guest_levels) ) { + /** @var \Joomla\CMS\Application\CMSApplication $app */ + $app = Factory::getApplication(); + $return = $app->getUserState('com_attachments.current_url', ''); + $url = Route::_($base_url . 'index.php?option=com_attachments&task=requestLogin' . $return); + $target = ''; + } + } + if ( $url == '' ) { + $url = $attachment->url; + } + $tooltip = Text::sprintf('ATTACH_ACCESS_THIS_URL_S', $attachment->url); + } + $show_in_modal = (!$app->client->mobile) && ($this->file_link_open_mode == 'in_a_popup') && ($attachment->file_type === "application/pdf" || str_starts_with($attachment->file_type, "image/")); if ( $show_in_modal ) { $a_class = 'modal-button'; AttachmentsJavascript::setupModalJavascript(); @@ -280,7 +266,7 @@ $is_empty = 0; if ( StringHelper::strlen($description) == 0) { $description = ' '; - $is_empty = 1; + $is_empty = 1; } if ( $this->show_column_titles ) @@ -298,7 +284,7 @@ $is_empty = 0; if ( StringHelper::strlen($user_field) == 0 ) { $user_field = ' '; - $is_empty = 1; + $is_empty = 1; } if ( $this->show_column_titles ) @@ -315,7 +301,7 @@ $is_empty = 0; if ( StringHelper::strlen($user_field) == 0 ) { $user_field = ' '; - $is_empty = 1; + $is_empty = 1; } if ( $this->show_column_titles ) @@ -332,7 +318,7 @@ $is_empty = 0; if ( StringHelper::strlen($user_field) == 0 ) { $user_field = ' '; - $is_empty = 1; + $is_empty = 1; } if ( $this->show_column_titles ) @@ -358,7 +344,13 @@ } $html .= '' . $file_size_str . ''; } - + if ( $this->secure ) { + $url = Route::_($base_url . "index.php?option=com_attachments&task=download&id=" . (int)$attachment->id); + $html .= ''; + $tooltip = Text::sprintf('ATTACH_DOWNLOAD_THIS_FILE_S', $actual_filename); + $html .= "" . + HTMLHelper::image("com_attachments/download.gif", "", null, true) . ''; + } // Show number of downloads (maybe) if ( $this->secure && $this->show_downloads ) { $num_downloads = (int)$attachment->download_count; diff --git a/attachments_plugin/language/en-GB/en-GB.plg_content_attachments.ini b/attachments_plugin/language/en-GB/en-GB.plg_content_attachments.ini index 28ae4105..6732b1c3 100644 --- a/attachments_plugin/language/en-GB/en-GB.plg_content_attachments.ini +++ b/attachments_plugin/language/en-GB/en-GB.plg_content_attachments.ini @@ -29,3 +29,4 @@ ATTACH_LAST_MODIFIED="Last modified" ATTACH_REALLY_DELETE_ATTACHMENT="Really delete attachment?" ATTACH_UPDATE_THIS_FILE="Update this file" ATTACH_URL="URL" +ATTACH_VIEW_THIS_ATTACHMENT="View this File" diff --git a/attachments_plugin/language/fr-FR/fr-FR.plg_content_attachments.ini b/attachments_plugin/language/fr-FR/fr-FR.plg_content_attachments.ini index e1edcc9e..1ebac005 100644 --- a/attachments_plugin/language/fr-FR/fr-FR.plg_content_attachments.ini +++ b/attachments_plugin/language/fr-FR/fr-FR.plg_content_attachments.ini @@ -29,3 +29,4 @@ ATTACH_REALLY_DELETE_ATTACHMENT="Voulez-vous vraiment supprimer cette pièce joi ATTACH_S_KB="%s Ko" ATTACH_UPDATE_THIS_FILE="Mettre à jour ce fichier" ATTACH_URL="Adresse URL" +ATTACH_VIEW_THIS_ATTACHMENT="Voir cette pièce jointe" From bad573ed16375e56a56b05b2c17ec7879959b471 Mon Sep 17 00:00:00 2001 From: JLTRY Date: Mon, 6 Jan 2025 21:36:29 +0100 Subject: [PATCH 2/4] rework feature => show icon if option selected and mode is popup --- attachments_component/admin/config.xml | 6 ++ .../language/en-GB/en-GB.com_attachments.ini | 1 + .../language/fr-FR/fr-FR.com_attachments.ini | 1 + .../site/src/Controller/DisplayController.php | 5 +- .../site/src/Helper/AttachmentsHelper.php | 17 +++-- .../site/src/View/Attachments/HtmlView.php | 1 + .../site/tmpl/attachments/default.php | 73 +++++++++++-------- 7 files changed, 67 insertions(+), 37 deletions(-) diff --git a/attachments_component/admin/config.xml b/attachments_component/admin/config.xml index 567ff945..c5784b4e 100644 --- a/attachments_component/admin/config.xml +++ b/attachments_component/admin/config.xml @@ -85,6 +85,12 @@ + + + + diff --git a/attachments_component/admin/language/en-GB/en-GB.com_attachments.ini b/attachments_component/admin/language/en-GB/en-GB.com_attachments.ini index 6192b6bd..7c36c9fb 100644 --- a/attachments_component/admin/language/en-GB/en-GB.com_attachments.ini +++ b/attachments_component/admin/language/en-GB/en-GB.com_attachments.ini @@ -308,6 +308,7 @@ ATTACH_SHOW_MODIFICATION_DATE="Show attachment modification date?" ATTACH_SHOW_MODIFICATION_DATE_DESCRIPTION="Sets whether the modification date for the attachment should be shown." ATTACH_SHOW_NUMBER_OF_DOWNLOADS="Show number of downloads?" ATTACH_SHOW_NUMBER_OF_DOWNLOADS_DESCRIPTION="Show the number of downloads. WARNING: This option only works in secure mode." +ATTACH_SHOW_RAW_DOWNLOAD="Show a download icon" ATTACH_SORT_ATTACHMENT_ID="Attachment ID (order of attachment)" ATTACH_SORT_CREATED_DATE="Creation date (oldest first)" ATTACH_SORT_CREATED_DATE_DESCENDING="Creation date (newest first)" diff --git a/attachments_component/admin/language/fr-FR/fr-FR.com_attachments.ini b/attachments_component/admin/language/fr-FR/fr-FR.com_attachments.ini index cf00c9ac..ab26b313 100644 --- a/attachments_component/admin/language/fr-FR/fr-FR.com_attachments.ini +++ b/attachments_component/admin/language/fr-FR/fr-FR.com_attachments.ini @@ -307,6 +307,7 @@ ATTACH_SHOW_MODIFICATION_DATE="Afficher la date de modification de la pièce joi ATTACH_SHOW_MODIFICATION_DATE_DESCRIPTION="Définit si la date de modification pour la pièce jointe doit être montrée." ATTACH_SHOW_NUMBER_OF_DOWNLOADS="Afficher le nombre de téléchargements ?" ATTACH_SHOW_NUMBER_OF_DOWNLOADS_DESCRIPTION="Affiche le nombre de téléchargements. Attention: cette option fonctionne seulement en mode sécurisé." +ATTACH_SHOW_RAW_DOWNLOAD="Affiche une icône de download" ATTACH_SORT_ATTACHMENT_ID="ID de la pièce jointe" ATTACH_SORT_CREATED_DATE="Date de création (plus ancienne en premier)" ATTACH_SORT_CREATED_DATE_DESCENDING="Date de création (plus récente en premier)" diff --git a/attachments_component/site/src/Controller/DisplayController.php b/attachments_component/site/src/Controller/DisplayController.php index 0b3313b9..aca7839e 100644 --- a/attachments_component/site/src/Controller/DisplayController.php +++ b/attachments_component/site/src/Controller/DisplayController.php @@ -485,9 +485,10 @@ public function download() $errmsg = Text::sprintf('ATTACH_ERROR_INVALID_ATTACHMENT_ID_N', $id) . ' (ERR 12)'; throw new \Exception($errmsg, 500); } - + $raw = $this->input->getInt('raw', 0); + $popup = $this->input->getInt('popup', 0); // NOTE: The helper download_attachment($id) function does the access check - AttachmentsHelper::download_attachment($id); + AttachmentsHelper::download_attachment($id, $raw, $popup); } diff --git a/attachments_component/site/src/Helper/AttachmentsHelper.php b/attachments_component/site/src/Helper/AttachmentsHelper.php index b723ec8a..5d050936 100644 --- a/attachments_component/site/src/Helper/AttachmentsHelper.php +++ b/attachments_component/site/src/Helper/AttachmentsHelper.php @@ -1506,7 +1506,7 @@ public static function add_url(&$attachment, &$parent, $verify, $relative_url=fa * * @param int $id the attachment id */ - public static function download_attachment($id) + public static function download_attachment($id, $raw=0, $popup=0) { $base_url = Uri::base(false); @@ -1614,14 +1614,19 @@ public static function download_attachment($id) } // Force the download - if ($download_mode == 'attachment') { - // attachment - header("Content-Disposition: attachment; filename=\"$mod_filename\""); + $content_disposition = 'attachment'; + // in popup model attachment is inline + if ( $popup == 1 ) { + $content_disposition = 'inline'; } - else { + else if ( $raw == 1 ) { // inline - header("Content-Disposition: inline; filename=\"$mod_filename\""); + $content_disposition = 'attachment'; } + else if ($download_mode != 'attachment' ) { + $content_disposition = 'inline'; + } + header("Content-Disposition: ". $content_disposition ."; filename=\"$mod_filename\""); header('Content-Transfer-Encoding: binary'); header("Content-Type: $content_type"); diff --git a/attachments_component/site/src/View/Attachments/HtmlView.php b/attachments_component/site/src/View/Attachments/HtmlView.php index 2d48267d..84360642 100644 --- a/attachments_component/site/src/View/Attachments/HtmlView.php +++ b/attachments_component/site/src/View/Attachments/HtmlView.php @@ -179,6 +179,7 @@ public function display($tpl = null) $this->show_created_date = $params->get('show_created_date', false); $this->show_modified_date = $params->get('show_modified_date', false); $this->file_link_open_mode = $params->get('file_link_open_mode', 'in_same_window'); + $this->show_raw_download = $params->get('show_raw_download', false); // Set up the file/url titleshow_mod_date if ( $this->show_column_titles ) { diff --git a/attachments_component/site/tmpl/attachments/default.php b/attachments_component/site/tmpl/attachments/default.php index 3c7bcbf5..88d7a81c 100644 --- a/attachments_component/site/tmpl/attachments/default.php +++ b/attachments_component/site/tmpl/attachments/default.php @@ -175,37 +175,51 @@ if ( $this->show_file_links ) { if ( $attachment->uri_type == 'file' ) { // Handle file attachments - // We need to urlencode the filename - $offset = strlen(AttachmentsDefines::$ATTACHMENTS_SUBDIR."/{$attachment->parent_entity}/{$attachment->parent_id}/"); - $url_path = mb_strcut($attachment->url, 0, $offset); - $url_filename = rawurlencode(mb_strcut($attachment->url, $offset)); - $url = $base_url . $url_path . $url_filename; - - if (strtoupper(substr(PHP_OS,0,3) == 'WIN')) { - // $url = utf8_encode($url); Deprecated from php 8.2 - $url = iconv('ISO-8859-1', 'UTF-8', $url); + if ( $this->secure ) { + $url = Route::_($base_url . "index.php?option=com_attachments&task=download&id=" . (int)$attachment->id); } - $tooltip = Text::_('ATTACH_VIEW_THIS_ATTACHMENT'); + else { + // We need to urlencode the filename + $offset = strlen(AttachmentsDefines::$ATTACHMENTS_SUBDIR."/{$attachment->parent_entity}/{$attachment->parent_id}/"); + $url_path = mb_strcut($attachment->url, 0, $offset); + $url_filename = rawurlencode(mb_strcut($attachment->url, $offset)); + $url = $base_url . $url_path . $url_filename; + + if (strtoupper(substr(PHP_OS,0,3) == 'WIN')) { + // $url = utf8_encode($url); Deprecated from php 8.2 + $url = iconv('ISO-8859-1', 'UTF-8', $url); + } + } + $tooltip = Text::sprintf('ATTACH_DOWNLOAD_THIS_FILE_S', $actual_filename); } else { + // Handle URL "attachments" + if ( $this->secure ) { + $url = Route::_($base_url . "index.php?option=com_attachments&task=download&id=" . (int)$attachment->id); + $tooltip = Text::sprintf('ATTACH_ACCESS_THIS_URL_S', $filename); + } + else { // Handle the link url if not logged in but link displayed for guests - $url = ''; - if ( !$logged_in AND ($attachment->access != '1')) { - $guest_levels = $this->params->get('show_guest_access_levels', Array('1')); - if ( in_array($attachment->access, $guest_levels) ) { - /** @var \Joomla\CMS\Application\CMSApplication $app */ - $app = Factory::getApplication(); - $return = $app->getUserState('com_attachments.current_url', ''); - $url = Route::_($base_url . 'index.php?option=com_attachments&task=requestLogin' . $return); - $target = ''; - } - } - if ( $url == '' ) { - $url = $attachment->url; - } - $tooltip = Text::sprintf('ATTACH_ACCESS_THIS_URL_S', $attachment->url); - } - $show_in_modal = (!$app->client->mobile) && ($this->file_link_open_mode == 'in_a_popup') && ($attachment->file_type === "application/pdf" || str_starts_with($attachment->file_type, "image/")); + $url = ''; + if ( !$logged_in AND ($attachment->access != '1')) { + $guest_levels = $this->params->get('show_guest_access_levels', Array('1')); + if ( in_array($attachment->access, $guest_levels) ) { + /** @var \Joomla\CMS\Application\CMSApplication $app */ + $app = Factory::getApplication(); + $return = $app->getUserState('com_attachments.current_url', ''); + $url = Route::_($base_url . 'index.php?option=com_attachments&task=requestLogin' . $return); + $target = ''; + } + } + if ( $url == '' ) { + $url = $attachment->url; + } + $tooltip = Text::sprintf('ATTACH_ACCESS_THIS_URL_S', $attachment->url); + } + } + + $show_in_modal = (!$app->client->mobile) && ($this->file_link_open_mode == 'in_a_popup') && ($attachment->file_type === "application/pdf" || str_starts_with($attachment->file_type, "image/")); + if ( $show_in_modal ) { $a_class = 'modal-button'; AttachmentsJavascript::setupModalJavascript(); @@ -219,6 +233,7 @@ $modalParams['width'] = '80%'; $modalParams['bodyHeight'] = '80'; $modalParams['modalWidth'] = '80'; + $url .= "&popup=1"; $html .= LayoutHelper::render( 'libraries.html.bootstrap.modal.main', [ @@ -344,8 +359,8 @@ } $html .= '' . $file_size_str . ''; } - if ( $this->secure ) { - $url = Route::_($base_url . "index.php?option=com_attachments&task=download&id=" . (int)$attachment->id); + if ( $this->show_raw_download && $show_in_modal ) { + $url = Route::_($base_url . "index.php?option=com_attachments&task=download&id=" . (int)$attachment->id . "&raw=1"); $html .= ''; $tooltip = Text::sprintf('ATTACH_DOWNLOAD_THIS_FILE_S', $actual_filename); $html .= "" . From 6c2b453509875cc7fee877924ff024b9d914076e Mon Sep 17 00:00:00 2001 From: Theofilos Intzoglou Date: Sat, 11 Jan 2025 15:26:12 +0200 Subject: [PATCH 3/4] Move show_raw_download option to Security and show only when applies --- attachments_component/admin/config.xml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/attachments_component/admin/config.xml b/attachments_component/admin/config.xml index c5784b4e..76a66338 100644 --- a/attachments_component/admin/config.xml +++ b/attachments_component/admin/config.xml @@ -85,12 +85,6 @@ - - - - @@ -261,6 +255,13 @@ + + + +
Date: Sat, 11 Jan 2025 15:30:08 +0200 Subject: [PATCH 4/4] Add greek translation --- .../admin/language/el-GR/el-GR.com_attachments.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/attachments_component/admin/language/el-GR/el-GR.com_attachments.ini b/attachments_component/admin/language/el-GR/el-GR.com_attachments.ini index 9a5f6714..58750181 100644 --- a/attachments_component/admin/language/el-GR/el-GR.com_attachments.ini +++ b/attachments_component/admin/language/el-GR/el-GR.com_attachments.ini @@ -308,6 +308,8 @@ ATTACH_SHOW_MODIFICATION_DATE="Εμφάνιση ημερομηνίας τροπ ATTACH_SHOW_MODIFICATION_DATE_DESCRIPTION="Ορίζει αν η ημερομηνία τροποποίησης για το συνημμένο πρέπει να εμφανίζεται." ATTACH_SHOW_NUMBER_OF_DOWNLOADS="Εμφάνιση αριθμού λήψεων;" ATTACH_SHOW_NUMBER_OF_DOWNLOADS_DESCRIPTION="Εμφάνιση του αριθμού των λήψεων. ΠΡΟΕΙΔΟΠΟΙΗΣΗ: Αυτή η επιλογή λειτουργεί μόνο σε ασφαλή λειτουργία." +ATTACH_SHOW_RAW_DOWNLOAD="Εμφάνιση εικονιδίου λήψης για αρχεία που ανοίγουν σε αναδυόμενο παράθυρο" +ATTACH_SHOW_RAW_DOWNLOAD_DESCRIPTION="Αυτή η επιλογή εμφανίζει ένα εικονίδιο δίπλα από το σύνδεσμο του συνημμένου που επιτρέπει τη λήψη του αρχείου αντί για εμφάνιση του αρχείου σε αναδυόμενο παράθυρο." ATTACH_SORT_ATTACHMENT_ID="ID Συνημμένου (σειρά επισύναψης)" ATTACH_SORT_CREATED_DATE="Ημερομηνία δημιουργίας (παλαιότερο πρώτο)" ATTACH_SORT_CREATED_DATE_DESCENDING="Ημερομηνία δημιουργίας (νεότερο πρώτο)"