jDownloadsownloads.com



Author Topic: Content Plugin: multiple categories - [Added in 2.5.25]  (Read 2356 times)

0 Members and 1 Guest are viewing this topic.

Offline idfake

  • Newbie
  • *
  • Posts: 7
Hi,

it really would be nice to be able to specify multiple categories to display with the content plugin like "{jd_file catlatest==1,2,3,4}".

The following patch against JD 2.5.24 would implement it.
Code: [Select]
--- plugins/content/jdownloads/jdownloads.php.orig Wed Feb 04 16:25:59 2015
+++ plugins/content/jdownloads/jdownloads.php Thu Feb 05 09:27:30 2015
@@ -1598,26 +1598,27 @@
        if ($sum > 0) $count = 'LIMIT '.$sum;
      
       // Get the data from the model
-      $cat_id = (int) $matches[2];
+  // and convert to array of integer
+      $cat_id = implode(',', array_map( 'intval', array_filter( explode(',', $matches[2]), 'is_numeric' ) ));
      
       $query    = $db->getQuery(true);
       $groups    = implode(',', $user->getAuthorisedViewLevels());
       $asset    = 'com_jdownloads.category.'.$cat_id;
        
       // Check at first whether this user may view the items from this category.
-      $db->setQuery("SELECT count(*) FROM #__jdownloads_categories WHERE published = 1 AND id = '$cat_id' AND access IN ($groups)");
+      $db->setQuery("SELECT count(*) FROM #__jdownloads_categories WHERE published = 1 AND id IN ($cat_id) AND access IN ($groups)");
       $cat = $db->loadResult();
        
        if ($cat){
            if ($type == 'hottest'){
                // we will view only the most downloaded files from a single category
-               $db->setQuery("SELECT * FROM #__jdownloads_files WHERE published = 1 AND cat_id = '$cat_id' AND access IN ($groups) ORDER BY downloads desc ".$count);
+               $db->setQuery("SELECT * FROM #__jdownloads_files WHERE published = 1 AND cat_id IN ($cat_id) AND access IN ($groups) ORDER BY downloads desc ".$count);
            } elseif ($type == 'latest'){
                // we will view only the newest files from a single category
-               $db->setQuery("SELECT * FROM #__jdownloads_files WHERE published = 1 AND cat_id = '$cat_id' AND access IN ($groups) ORDER BY date_added desc ".$count);
+               $db->setQuery("SELECT * FROM #__jdownloads_files WHERE published = 1 AND cat_id IN ($cat_id) AND access IN ($groups) ORDER BY date_added desc ".$count);
            } else {
                // only category placeholder is used - so we use the ordering field
-               $db->setQuery("SELECT * FROM #__jdownloads_files WHERE published = 1 AND cat_id = '$cat_id' AND access IN ($groups) ORDER BY ordering ".$count);
+               $db->setQuery("SELECT * FROM #__jdownloads_files WHERE published = 1 AND cat_id IN ($cat_id) AND access IN ($groups) ORDER BY ordering ".$count);
            }      
            $cat_result = '';
            $files = $db->loadObjectList();
« Last Edit: 05.02.2015 13:01:40 by Arno »

Offline Arno

  • Administrator
  • ***
  • Posts: 12.234
    • jDownloads.com
Re: Content Plugin: multiple categories
« Reply #1 on: 05.02.2015 11:32:59 »
Hi,
you have right - a good idea. ;)
So i will use it. Many thanks.
« Last Edit: 05.02.2015 11:43:09 by Arno »
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!