WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: Argos on November 03, 2010, 06:12:00 PM

Title: Droplet or snippet request for showing downloads of certain group(s)
Post by: Argos on November 03, 2010, 06:12:00 PM
I would like to use the Download Gallery 2 (http://www.websitebakers.com/pages/modules/listings/various/download-gallery-2.php) as a central download repository, and then use a droplet or snippet or some other trick to show the downloads of selected groups on a page.

So if I have 6 different groups of downloads, and I want to show the files of only group 2 and 4 on a certain page, I can use for example a droplet like [[showdownloads?groups=2,4]].

Is this possible? I searched the forum and amasp, but found nothing. This would make a much more flexible solution then using 6 different download sections in the admin. For several reasons I cannot use just 1 download page with all the 6 groups visible.
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: pcwacht on November 03, 2010, 09:35:33 PM
Yes it should be possible

Don't think it exists though, and can't help you here cause I don't have downloadgallery installed.

Where you can look is in the view.php of that module, there is the code used wich you can copy and paste and alter ;)


John
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Argos on November 03, 2010, 11:18:38 PM
Ehm... I can't code, that's why I asked for help...  :cry:
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Ruud on November 03, 2010, 11:30:04 PM
Just a try...

Code: (tested a little bit) [Select]
<?php
global $database;
if (!isset(
$group)) return true//No group=nn parm given..
$returnvalue = &#39;<table>&#39;;
$query_files $database->query ( &#39;SELECT * from &#39;.TABLE_PREFIX.&#39;mod_download_gallery_files where `active`=1 AND `group_id` = &#39;.$group );
if ($query_files) {
while($file $query_files->fetchRow()) {
$url WB_URL . &#39;/modules/download_gallery/dlc.php?file=&#39; .$file[&#39;file_id&#39;];
$returnvalue .= &#39;<tr>&#39;;
$returnvalue .= &#39; <td><a href="&#39;.$url.&#39;" target="_blank">&#39;.$file[&#39;title&#39;].&#39;</a></td>&#39;;
$returnvalue .= &#39; <td>&#39;.gmdate(DATE_FORMAT, $file[&#39;modified_when&#39;]+TIMEZONE).&#39;</td>&#39;;
$returnvalue .= &#39; <td>&#39;.gmdate(TIME_FORMAT, $file[&#39;modified_when&#39;]+TIMEZONE).&#39;</td>&#39;;
$returnvalue .= &#39; <td>&#39;.$file[&#39;dlcount&#39;].&#39;</td>&#39;;
$returnvalue .= &#39;</tr>&#39;;
}
}
$returnvalue .= &#39;</table>&#39;;
return $returnvalue;
?>

Name it "download", call with [[download?group=nn]]

[edit]
Added the `active`=1 in the query to show only active records
[/edit]
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Argos on November 03, 2010, 11:39:03 PM
WONDERFUL! Works like a charm  :-D
Thank you so much, Ruud, very cool stuff. I'm sure others may find the droplet useful too, so maybe you can add it to the official repository.
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Ruud on November 03, 2010, 11:43:40 PM
Works like a charm  :-D

[[droplets?cool=true]]
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: dbs on November 04, 2010, 08:44:20 AM
very nice !!!
i add the description
Code: [Select]

                $returnvalue .= '<tr>';
$returnvalue .= ' <td colspan="4">'.$file['description'].'</td>';
$returnvalue .= '</tr>';
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Argos on November 04, 2010, 11:26:34 AM
Yes, in the same way other info can be added, like filesize (in my opinion the most important extra info) and filetype image. You can also style the output with classes if you want.
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Stefek on November 04, 2010, 01:19:52 PM
Very nice one indeed.

Maybe giving a new parameter to show only a unique Download (by download ID) at wish instead of a whole group?
May be interesting for example in a kind of "Blog-Entry" where you want to put a unique download at the end of the Text (or somewhere else).

Regards,
Stefek

Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Ruud on November 04, 2010, 01:24:41 PM
If you know the file-id, it is just a fixed link you can add with your editor. Seems a bit overkill to use a script for that.
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: pcwacht on November 04, 2010, 04:05:28 PM
Though I am with Ruud on this one this will show everyone how easy droplets are when you know a litle bit of php / mysql.

copy the dropletcode and change :
Code: [Select]
if (!isset($group)) return true; //No group=nn parm given..to
Code: [Select]
if (!isset($file_id)) return true; //No file_id=nn parm given..and
Code: [Select]
$query_files = $database->query ( 'SELECT * from '.TABLE_PREFIX.'mod_download_gallery_files where `active`=1 AND `group_id` = '.$group );to:
Code: [Select]
$query_files = $database->query ( 'SELECT * from '.TABLE_PREFIX.'mod_download_gallery_files where `file_id` = $file_id ' );
and rename the droplet giving it a meaningfull name ;)

Have fun,
John

Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Stefek on November 04, 2010, 09:58:34 PM
Very nice one indeed.

Maybe giving a new parameter to show only a unique Download (by download ID) at wish instead of a whole group?
May be interesting for example in a kind of "Blog-Entry" where you want to put a unique download at the end of the Text (or somewhere else).

Regards,
Stefek
Seems a bit overkill to use a script for that.
je bent een grapje, toch?  :-D

However, I tried the droplet but the download itself doesn't seem to work.
It seems the timestamp is missing on the link (the download_gallery/dlc.php seems to ask for this parameta via $_GET).

Code: (download_gallery/dlc.php (excerpt)) [Select]
<?php 
if(!isset($_GET[&#39;file&#39;]) OR !is_numeric($_GET[&#39;file&#39;])) {
//echo "get file ";
header(&#39;Location: ../index.php&#39;);
} else {
$file = (int) $_GET[&#39;file&#39;];
}
if(!isset(
$_GET[&#39;id&#39;]) OR !is_numeric($_GET[&#39;id&#39;])) {
//echo "get id ";
header(&#39;Location: ../index.php&#39;);
} else {
$prove = (int) $_GET[&#39;id&#39;];
}

I am going to fix this and will implement the second parameter for unique items.

Regards,
Stefek
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: Stefek on November 04, 2010, 11:16:28 PM
If you know the file-id, it is just a fixed link you can add with your editor.
Hello Ruud,
yes, thats right, but if you provide a download, you maybe want to show the download count too?

For that purpose it's better to have a droplet, right?

I advanced the droplet script a little bit (see instructions after the code):
Code: (suggested Droplet-Name-> download) [Select]
<?php
global $database;
$ret_val "";
$download_url WB_URL '/modules/download_gallery/dlc.php?file=';
if (!isset(
$group) && !isset($item))
$ret_val "you must specify a group or a item ID from your download gallery";

elseif(isset(
$item)){
// UNIQUE DOWNLOAD ITEM
$query_unique_file $database->query(sprintf("SELECT * from `%s` WHERE `file_id` = '%d'"
TABLE_PREFIX."mod_download_gallery_files"$item));
if ($query_unique_file) {
while($file $query_unique_file->fetchRow()) {
$ret_val .= '<div class="unique_download">'
.'<a href="'.$download_url.$file['file_id'].'&amp;id='.$file['modified_when'].'" target="_blank">'
.$file['title']
.'</a><small> DL:'.$file['dlcount'].'</small>'
.'<div>'.$file['description'].'</div></div>';
}
}
}
elseif(isset(
$group)){
// GROUP
$query_files $database->query(sprintf("SELECT * from `%s` WHERE `active`=1 AND `group_id` = '%d'"
TABLE_PREFIX."mod_download_gallery_files"$group));
$ret_val '<table border="1">';
if ($query_files) {
while($file $query_files->fetchRow()) {
$ret_val .= '<tr>'
.' <td><a href="'.$download_url.$file['file_id'].'&amp;id='.$file['modified_when'].'" target="_blank">'.$file['title'].'</a></td>'
.' <td>'.gmdate(DATE_FORMAT$file['modified_when']+TIMEZONE).'</td>'
.' <td>'.gmdate(TIME_FORMAT$file['modified_when']+TIMEZONE).'</td>'
.' <td>'.$file['dlcount'].'</td>'
.'</tr>';
}
}
$ret_val .= '</table><br>';
}

return 
$ret_val;

[[download?group=3]] will return the whole groupID 3 (as before)
[[download?item=7]] will return a unique download of fileID 7 only.

Do not mix the parameters. Use only "group" or only "item".
To find out the ID go to the Download Gallery Page/Section of your WB Installation and go over the items with your mouse. You will find it in the browser status bar.

You should handle all the "template" stuff inside the droplet itself.

You may also use additional output from the database:
$file['filename']
$file['extension']
$file['description']
$file['size']

(see database table for more)

Regards,
Stefek
Title: Re: Droplet or snippet request for showing downloads of certain group(s)
Post by: nuke on September 14, 2012, 09:41:12 PM
Stefek and Ruud - this helped me out a lot! Thank you!

Just a try...

Code: (tested a little bit) [Select]
<?php
global $database;
if (!isset(
$group)) return true//No group=nn parm given..
$returnvalue '<table>';
$query_files $database->query 'SELECT * from '.TABLE_PREFIX.'mod_download_gallery_files where `active`=1 AND `group_id` = '.$group );
if (
$query_files) {
while($file $query_files->fetchRow()) {
$url WB_URL '/modules/download_gallery/dlc.php?file=' .$file['file_id'];
$returnvalue .= '<tr>';
$returnvalue .= ' <td><a href="'.$url.'" target="_blank">'.$file['title'].'</a></td>';
$returnvalue .= ' <td>'.gmdate(DATE_FORMAT$file['modified_when']+TIMEZONE).'</td>';
$returnvalue .= ' <td>'.gmdate(TIME_FORMAT$file['modified_when']+TIMEZONE).'</td>';
$returnvalue .= ' <td>'.$file['dlcount'].'</td>';
$returnvalue .= '</tr>';
}
}
$returnvalue .= '</table>';
return 
$returnvalue;
?>

Name it "download", call with [[download?group=nn]]

[edit]
Added the `active`=1 in the query to show only active records
[/edit]