From 4c6aafc0a5c236509ab6f271d8a72be3ae878bed Mon Sep 17 00:00:00 2001 From: Tazzios <23451105+Tazzios@users.noreply.github.com> Date: Sun, 23 Apr 2023 14:11:21 +0200 Subject: [PATCH 1/3] J4 fixes Fix for #25 and #26 . But breaks the popup in joomla 3. Find out if there is something universal or that i have to do a version check. --- content_plugin/pdfviewer.php | 100 +++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/content_plugin/pdfviewer.php b/content_plugin/pdfviewer.php index ceea75a..c2f81d4 100644 --- a/content_plugin/pdfviewer.php +++ b/content_plugin/pdfviewer.php @@ -3,8 +3,8 @@ defined('_JEXEC') or die; use Joomla\CMS\Factory; -use Joomla\CMS\Categories\CategoryNode; -use Joomla\CMS\Categories\Categories; // needed for retrieving full file pathfor pdfimage +use Joomla\CMS\HTML\HTMLHelper; + /** * Plug-in to enable loading pdf files into content (e.g. articles) @@ -377,9 +377,32 @@ function CreatePdfviewer($filelink,$pagereference,$pagenumber,$pdfjsviewsettings // Popup IF ($style=='popup') { - JHTML::_('behavior.modal'); + $randomId = rand(0, 1000); // important when there are multiple popup pdfs on one page with different settings + + HTMLHelper::_('bootstrap.modal', '.selector', []); - return ''. $linktext .''; + return '

'. $linktext .'

+ '; + } // New window IF ($style=='new') { @@ -398,40 +421,31 @@ function Createpdfimage($file_id,$pagenumber,$height,$width,$style,$linktext) { $jdownloads_params = JComponentHelper::getParams( 'com_jdownloads' ); $files_uploaddir = $jdownloads_params->get( 'files_uploaddir' ); - // get categorie ID and file name + // get categorie path $db = JFactory::getDbo(); - $query = $db->getQuery(true) - ->select(' cat.id, url_download ') - ->from('#__jdownloads_files as file') - ->join('INNER',' #__jdownloads_categories as cat ON file.catid=cat.id' ) - ->where('file.id = '. $file_id ); - // ->order('ordering ASC'); - $db->setQuery($query); + $db->setQuery("WITH RECURSIVE n AS + ( SELECT id, parent_id, concat('/', title ,'/') AS path + FROM josmf_jdownloads_categories + WHERE parent_id = 0 + union all + SELECT c.id, c.parent_id, concat(n.path, c.title, '/') + FROM n + join josmf_jdownloads_categories c on c.parent_id = n.id + WHERE n.path not like concat('%/', c.id, '/%') -- cycle pruning here! + ) + SELECT REPLACE(path,'/ROOT','') AS path, file.url_download AS filename + FROM n + INNER JOIN josmf_jdownloads_files AS file ON n.id=file.catid WHERE file.id=". $file_id ); $fileDB = $db->loadAssocList(); - $cat_id = ''; - $cat_path = ''; - $filename = '' ; + //Full local file link + $filelink = '' ; foreach ($fileDB as $file) { - $filename = $file['url_download']; - $cat_id = $file['id']; - } - - //Retrieve categories file path with the help of category ID - $cat_parents = ''; - $categories = \Joomla\CMS\Categories\Categories::getInstance('jdownloads'); - $cat = $categories->get($cat_id); - - if ($cat->cat_dir_parent<>''){ - $cat_parents = DS . $cat->cat_dir_parent; + $filelink = $files_uploaddir . $file['path'] . $file['filename']; } - //Full file link - $filelink = $files_uploaddir . $cat_parents . DS . $cat->title. DS . $filename; - - // Imagick starts with page 0 if ($pagenumber <>'') { $pagenumber = (int) $pagenumber-1; @@ -472,13 +486,13 @@ function Createpdfimage($file_id,$pagenumber,$height,$width,$style,$linktext) { //PDF viewer embed settings: IF ($style=='embed') { - $height = ' height='. $height . 'px;' ; + $height = ' height:'. $height . 'px;' ; // If width is numeric then px else assume there is a % if (is_numeric($width)) { - $width = ' width=' . $width . ''; + $width = ' width:' . $width . ''; } else { - $width = ' width=' . $width . '%'; + $width = ' width:' . $width . '%'; } //return 'test'; return ''; @@ -486,10 +500,26 @@ function Createpdfimage($file_id,$pagenumber,$height,$width,$style,$linktext) { } // Popup IF ($style=='popup') { + + $randomId = rand(0, 1000); // important when there are multiple popup pdfs on one page with different settings - JHTML::_('behavior.modal'); + HTMLHelper::_('bootstrap.modal', '.selector', []); - return ''. $linktext .''; + return '

'. $linktext .'

+ '; + } // New window IF ($style=='new') { From 3b503d1d08e4d6b22af2be9295da6025d90e8c53 Mon Sep 17 00:00:00 2001 From: Tazzios <23451105+Tazzios@users.noreply.github.com> Date: Sun, 23 Apr 2023 16:03:07 +0200 Subject: [PATCH 2/3] Url search with phrase phrase true did not work --- content_plugin/pdfviewer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/content_plugin/pdfviewer.php b/content_plugin/pdfviewer.php index c2f81d4..805fbf3 100644 --- a/content_plugin/pdfviewer.php +++ b/content_plugin/pdfviewer.php @@ -141,6 +141,7 @@ public function onContentPrepare($context, &$article, &$params, $page = 0) } //2. get search from url elseif (isset($_GET["search"]) ) { + $search = $_GET["search"]; $pagereference = '#search=' . $_GET["search"]; } //3. get nameddest from url From f26e3964c7b6110966e3f17fa95a056dff724c2a Mon Sep 17 00:00:00 2001 From: Tazzios <23451105+Tazzios@users.noreply.github.com> Date: Fri, 28 Apr 2023 15:59:06 +0200 Subject: [PATCH 3/3] Joomla version check for modal popup --- content_plugin/pdfviewer.php | 49 +++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/content_plugin/pdfviewer.php b/content_plugin/pdfviewer.php index 805fbf3..60ed85f 100644 --- a/content_plugin/pdfviewer.php +++ b/content_plugin/pdfviewer.php @@ -4,6 +4,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Version; /** @@ -377,7 +378,14 @@ function CreatePdfviewer($filelink,$pagereference,$pagenumber,$pdfjsviewsettings } // Popup IF ($style=='popup') { - + + + if (str_starts_with(JVersion::MAJOR_VERSION, 3)) { + + JHTML::_('behavior.modal'); + return ''. $linktext .''; + + } else { $randomId = rand(0, 1000); // important when there are multiple popup pdfs on one page with different settings HTMLHelper::_('bootstrap.modal', '.selector', []); @@ -403,6 +411,8 @@ function CreatePdfviewer($filelink,$pagereference,$pagenumber,$pdfjsviewsettings '; + } + } // New window @@ -502,24 +512,33 @@ function Createpdfimage($file_id,$pagenumber,$height,$width,$style,$linktext) { // Popup IF ($style=='popup') { - $randomId = rand(0, 1000); // important when there are multiple popup pdfs on one page with different settings - HTMLHelper::_('bootstrap.modal', '.selector', []); + if (str_starts_with(JVersion::MAJOR_VERSION, 3)) { + + JHTML::_('behavior.modal'); + return ''. $linktext .''; + + }ELSE { + + $randomId = rand(0, 1000); // important when there are multiple popup pdfs on one page with different settings - return '

'. $linktext .'

-