From 983d943548c136e0d5b12b28f9ac334f22e501f5 Mon Sep 17 00:00:00 2001 From: HWFord <54360213+HWFord@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:51:55 +0200 Subject: [PATCH] issue #2170 update picture tpl to embed pdf reader Add default config pdf_viewer_filesize_threshold Add function to get number of PDF pages Add translations update picture.php to send pdf filesize threshold and nb page to tpl update picture.tpl to add number of pages for PDF picture_content.tpl update for new config name and add translation functions. use embed for pdf if file ext = pdf --- include/config_default.inc.php | 4 ++++ include/functions_picture.inc.php | 14 ++++++++++++++ language/en_UK/common.lang.php | 4 ++++ language/fr_FR/common.lang.php | 3 +++ picture.php | 7 +++++++ themes/default/template/picture.tpl | 8 ++++++++ themes/default/template/picture_content.tpl | 15 ++++++++++++++- themes/default/theme.css | 9 +++++++++ 8 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 96f3dee36..3e1f74e33 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -296,6 +296,10 @@ $conf['linked_album_search_limit'] = 100; // 0 to disable. $conf['fs_quick_check_period'] = 24*60*60; +// This corresponds to the treshold where we no longer display the web browsers +// PDF viewer. In MB (megabytes). +$conf['pdf_viewer_filesize_threshold'] = 5; + // +-----------------------------------------------------------------------+ // | email | // +-----------------------------------------------------------------------+ diff --git a/include/functions_picture.inc.php b/include/functions_picture.inc.php index 20c665862..0b3753217 100644 --- a/include/functions_picture.inc.php +++ b/include/functions_picture.inc.php @@ -135,4 +135,18 @@ UPDATE pwg_query($query); } +/** + * Returns the number of pages of a PDF file + * + * @param string $pdfPath + * @return int + */ +function count_pdf_pages($pdfPath) +{ + $pdftext = file_get_contents($pdfPath); + $num = preg_match_all("/\/Page\W/", $pdftext, $dummy); + + return $num; +} + ?> \ No newline at end of file diff --git a/language/en_UK/common.lang.php b/language/en_UK/common.lang.php index bc3924b83..9bddb0bce 100644 --- a/language/en_UK/common.lang.php +++ b/language/en_UK/common.lang.php @@ -446,4 +446,8 @@ $lang['last 3 months'] = 'Last 3 months'; $lang['last 24 hours'] = 'last 24 hours'; $lang['Album already selected'] = 'Album already selected'; $lang['Only the first %d albums are displayed, out of %d.'] = 'Only the first %d albums are displayed, out of %d.'; +$lang['Pages'] = "Pages"; +$lang['The PDF you requested is too large to display on this page.']= 'The PDF you requested is too large to display on this page.'; +$lang['Click here to display it']= 'Click here to display it'; + ?> diff --git a/language/fr_FR/common.lang.php b/language/fr_FR/common.lang.php index fbf55b16b..93f7c05db 100644 --- a/language/fr_FR/common.lang.php +++ b/language/fr_FR/common.lang.php @@ -451,3 +451,6 @@ $lang['last 3 months'] = '3 derniers mois'; $lang['last 24 hours'] = '24 dernières heures'; $lang['Only the first %d albums are displayed, out of %d.'] = 'Seuls les %d premiers sont affichés, sur %d.'; $lang['Album already selected'] = 'Album déjà sélectionné'; +$lang['Pages'] = "Pages"; +$lang['The PDF you requested is too large to display on this page.']= 'Le PDF que vous avez demandé est trop volumineux pour être affiché sur cette page.'; +$lang['Click here to display it']= 'Cliquez ici pour le voir'; diff --git a/picture.php b/picture.php index eb5250965..38416c0a9 100644 --- a/picture.php +++ b/picture.php @@ -971,6 +971,13 @@ SELECT id, name, permalink } } +$template->assign( + array( + 'PDF_VIEWER_FILESIZE_THRESHOLD' => $conf['pdf_viewer_filesize_threshold']*1024, + 'PDF_NB_PAGES' => count_pdf_pages($picture['current']['path']) + ) +); + // maybe someone wants a special display (call it before page_header so that // they can add stylesheets) $element_content = trigger_change( diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index 29266784f..632f85018 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -234,6 +234,14 @@ y.callService( {/if} + {if isset($PDF_NB_PAGES) and $current.path_ext=="pdf" } +
+
{'Pages'|@translate}
+
{$PDF_NB_PAGES}
+ + + {/if} + {if $display_info.rating_score and isset($rate_summary)}
{'Rating score'|@translate}
diff --git a/themes/default/template/picture_content.tpl b/themes/default/template/picture_content.tpl index cd32c1dbe..32a29189b 100644 --- a/themes/default/template/picture_content.tpl +++ b/themes/default/template/picture_content.tpl @@ -4,7 +4,20 @@ {footer_script}var error_icon = "{$ROOT_URL}{$themeconf.icon_dir}/errors_small.png"{/footer_script} {/if} -is_cached()}src="{$current.selected_derivative->get_url()}"{$current.selected_derivative->get_size_htm()}{else}src="{$ROOT_URL}{$themeconf.img_dir}/ajax_loader.gif" data-src="{$current.selected_derivative->get_url()}"{/if} alt="{$ALT_IMG}" id="theMainImage" usemap="#map{$current.selected_derivative->get_type()}" title="{if isset($COMMENT_IMG)}{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}{else}{$current.TITLE_ESC} - {$ALT_IMG}{/if}"> +{if isset($current.path_ext) and $current.path_ext == 'pdf' and $current.filesize < $PDF_VIEWER_FILESIZE_THRESHOLD} +
+ +
+{else} + is_cached()}src="{$current.selected_derivative->get_url()}"{$current.selected_derivative->get_size_htm()}{else}src="{$ROOT_URL}{$themeconf.img_dir}/ajax_loader.gif" data-src="{$current.selected_derivative->get_url()}"{/if} alt="{$ALT_IMG}" id="theMainImage" usemap="#map{$current.selected_derivative->get_type()}" title="{if isset($COMMENT_IMG)}{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}{else}{$current.TITLE_ESC} - {$ALT_IMG}{/if}"> + + {if isset($current.path_ext) and $current.path_ext == 'pdf' and $current.filesize > $PDF_VIEWER_FILESIZE_THRESHOLD} +
+ {'The PDF you requested is too large to display on this page.'|translate}
+ {'Click here to display it'|translate} +
+ {/if} +{/if} {foreach from=$current.unique_derivatives item=derivative key=derivative_type}{strip} diff --git a/themes/default/theme.css b/themes/default/theme.css index 7fd5b3230..d81fe9b46 100644 --- a/themes/default/theme.css +++ b/themes/default/theme.css @@ -414,6 +414,15 @@ TD.calDayCellFull, TD.calDayCellEmpty { text-align: center; } +.pdf-too-heavy { + margin-top: 20px; + margin-bottom: 20px; +} + +.pdf-too-heavy a { + text-decoration: underline; +} + #imageInfos { position: relative; /*for IE7 positioning of "who can see this photo"*/ min-height: 120px;