diff --git a/content_plugin/pdfviewer.php b/content_plugin/pdfviewer.php
index ceea75a..60ed85f 100644
--- a/content_plugin/pdfviewer.php
+++ b/content_plugin/pdfviewer.php
@@ -3,8 +3,9 @@
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;
+use Joomla\CMS\Version;
+
/**
* Plug-in to enable loading pdf files into content (e.g. articles)
@@ -141,6 +142,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
@@ -376,10 +378,42 @@ function CreatePdfviewer($filelink,$pagereference,$pagenumber,$pdfjsviewsettings
}
// Popup
IF ($style=='popup') {
-
- JHTML::_('behavior.modal');
- return ''. $linktext .'';
+
+ 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', []);
+
+ return '
'. $linktext .'
+ ';
+ }
+
+
}
// New window
IF ($style=='new') {
@@ -398,40 +432,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 +497,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 +511,35 @@ function Createpdfimage($file_id,$pagenumber,$height,$width,$style,$linktext) {
}
// Popup
IF ($style=='popup') {
+
- JHTML::_('behavior.modal');
+ 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 .'';
+ HTMLHelper::_('bootstrap.modal', '.selector', []);
+
+ return ' '. $linktext .'
+
+
+
+
+
+
+
+
+
+
';
+ }
+
}
// New window
IF ($style=='new') {