Twitter SMFHacks Facebook SMFHacks SMFHacks.com
** Home Forum Index Hacks Products Login Register Search
Welcome, Guest. Please login or register.
April 16, 2014, 11:09:01 am

Login with username, password and session length
Members
Total Members: 11193
Latest: milissag
Stats
Total Posts: 34797
Total Topics: 5836
Online Today: 89
Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Users: 1
Guests: 59
Total: 60
+ 
|-+ 
| |-+ 
| | |-+ 
| | | |-+ 
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Print
Author Topic: Latest Downloads Block for Tiny Portal  (Read 1735 times)
shaka
Newbie
*
Offline Offline

Posts: 37


View Profile
« on: January 21, 2012, 08:52:18 pm »

Hi guys sorry if this is already done but I have searched and cannot find it

I am looking for a code to add a latest downloads block for tiny portal
Logged
SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 11867


View Profile
« Reply #1 on: January 21, 2012, 08:53:48 pm »

What do you want to show? A listing of latest downloads? And how do you want it to be formatted?
Logged
shaka
Newbie
*
Offline Offline

Posts: 37


View Profile
« Reply #2 on: January 21, 2012, 09:02:30 pm »

Yes much like the layout on the downloads page showing the title and image but would like to put it in a block and display it on my index page  e.g Latest 50 downloads added

hope I am explaining this ok  Huh
Logged
SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 11867


View Profile
« Reply #3 on: January 21, 2012, 11:16:08 pm »

Now is the download image a screenshot or a download link?
Vertical like this?

Title
Download Image

Title
Download Image
Logged
shaka
Newbie
*
Offline Offline

Posts: 37


View Profile
« Reply #4 on: January 22, 2012, 03:59:42 am »

A screenshot would be great with maybe a link either from the image or title to the download page of that download
Logged
SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 11867


View Profile
« Reply #5 on: January 23, 2012, 07:43:32 pm »

One more thing I need what SMF version then will write a quick code.
Logged
shaka
Newbie
*
Offline Offline

Posts: 37


View Profile
« Reply #6 on: January 24, 2012, 02:37:47 am »

Running the latest version 2.0.2  many thanks

before you go ahead and if possible I am only looking for the preview image, title and uploader info to be displayed, just if possible but I will be grateful whatever you can come up with

thanks
Logged
SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 11867


View Profile
« Reply #7 on: January 24, 2012, 06:16:07 pm »

Try this code adapted from ezPortal

Code:

//Example call
DownloadsBlock(1,4,'recent');

function DownloadsBlock($rows = 4, $files = 4, $type = 'recent')
{
global $txt, $smcFunc, $scripturl,  $modSettings, $scripturl, $boardurl;

$rows = (int) $rows;
$files = (int) $files;



$isPro = true;


// Load the language files
if (loadlanguage('Downloads') == false)
loadLanguage('Downloads','english');


if (empty($modSettings['down_url']))
$modSettings['down_url'] = $boardurl . '/downloads/';

$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
//Check what type it is
$selectPro = '';
$selectProJoin = '';
if ($isPro == true)
{
$selectPro = " f.ID_PICTURE, f.thumbfilename, ";
$selectProJoin =  " LEFT JOIN {db_prefix}down_file_pic AS f ON (f.ID_PICTURE = p.ID_PICTURE) ";
}

$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE  p.approved = 1 ORDER BY p.ID_FILE DESC LIMIT $files";
break;

case 'viewed':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY  p.views DESC LIMIT $files";
break;

case 'mostcomments':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY p.commenttotal DESC LIMIT $files";
break;

case 'toprated':
$query = "SELECT p.ID_FILE,  (p.rating / p.totalratings ) AS ratingaverage, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY ratingaverage DESC LIMIT $files ";
break;

case 'downloads':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY  p.totaldownloads DESC LIMIT $files";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';

echo '<td align="center"><a href="' . $scripturl . '?action=downloads;sa=view;id=' . $row['ID_FILE'] . '">',$row['title'],'</a><br />';

if ($isPro == true && $modSettings['down_set_t_image'] && !empty($row['thumbfilename']))
echo '<a href="' . $scripturl . '?action=downloads;sa=view;id=' . $row['ID_FILE'] . '"><img src="',$modSettings['down_url'],$row['thumbfilename'],'" alt="" /></a><br />';


echo '<span class="smalltext">';
//if (!empty($modSettings['down_set_t_rating']))
//echo $txt['downloads_form_rating'] . EzGetStarsByPrecent(($row['totalratings'] != 0) ? ($row['rating'] / ($row['totalratings']* 5) * 100) : 0) . '<br />';

if (!empty($modSettings['down_set_t_downloads']))
echo $txt['downloads_text_downloads'] . $row['totaldownloads'] . '<br />';
if (!empty($modSettings['down_set_t_views']))
echo $txt['downloads_text_views'] . $row['views'] . '<br />';
if (!empty($modSettings['down_set_t_filesize']))
echo $txt['downloads_text_filesize'] . round($row['filesize'] / 1024, 2) . 'KB<br />';
if (!empty($modSettings['down_set_t_date']))
echo $txt['downloads_text_date'] . timeformat($row['date']) . '<br />';
if (!empty($modSettings['down_set_t_comment']))
echo $txt['downloads_text_comments'] . ' (<a href="' . $scripturl . '?action=downloads;sa=view;id=' . $row['ID_FILE'] . '">' . $row['commenttotal'] . '</a>)<br />';
if (!empty($modSettings['down_set_t_username']))
{
if ($row['real_name'] != '')
echo $txt['downloads_text_by'] . ' <a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">'  . $row['real_name'] . '</a><br />';
else
echo $txt['downloads_text_by'] . ' ' . $txt['downloads_guest'] . '<br />';
}
echo '</span></td>';


if ($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if ($rowlevel !=0)
{
echo '</tr>';
}

echo '
      </table><br />';


}
Logged
shaka
Newbie
*
Offline Offline

Posts: 37


View Profile
« Reply #8 on: January 24, 2012, 06:40:53 pm »

wow almost perfect

is it possible only to show the image, title and members name

can I alter how many it shows i.e. latest 50 downloads

as it is for a center block is it possible to have them horizontal and vertical say 4 across and 12 down

thanks so much for taking the time  Wink
Logged
SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 11867


View Profile
« Reply #9 on: January 24, 2012, 06:46:25 pm »

Retry this code
Code:
//Example call
DownloadsBlock(4,50,'recent');

function DownloadsBlock($rows = 4, $files = 4, $type = 'recent')
{
global $txt, $smcFunc, $scripturl,  $modSettings, $scripturl, $boardurl;

$rows = (int) $rows;
$files = (int) $files;



$isPro = true;


// Load the language files
if (loadlanguage('Downloads') == false)
loadLanguage('Downloads','english');


if (empty($modSettings['down_url']))
$modSettings['down_url'] = $boardurl . '/downloads/';

$maxrowlevel = $rows;
echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
';
//Check what type it is
$selectPro = '';
$selectProJoin = '';
if ($isPro == true)
{
$selectPro = " f.ID_PICTURE, f.thumbfilename, ";
$selectProJoin =  " LEFT JOIN {db_prefix}down_file_pic AS f ON (f.ID_PICTURE = p.ID_PICTURE) ";
}

$query = ' ';
switch($type)
{
case 'recent':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE  p.approved = 1 ORDER BY p.ID_FILE DESC LIMIT $files";
break;

case 'viewed':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY  p.views DESC LIMIT $files";
break;

case 'mostcomments':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY p.commenttotal DESC LIMIT $files";
break;

case 'toprated':
$query = "SELECT p.ID_FILE,  (p.rating / p.totalratings ) AS ratingaverage, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY ratingaverage DESC LIMIT $files ";
break;

case 'downloads':
$query = "SELECT p.ID_FILE, p.commenttotal, $selectPro p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.real_name, p.date, p.description, p.totaldownloads
FROM {db_prefix}down_file as p
LEFT JOIN {db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
$selectProJoin
WHERE p.approved = 1 ORDER BY  p.totaldownloads DESC LIMIT $files";
break;
}
// Execute the SQL query
$dbresult = $smcFunc['db_query']('', $query);
$rowlevel = 0;
while($row = $smcFunc['db_fetch_assoc']($dbresult))
{
if ($rowlevel == 0)
echo '<tr class="windowbg2">';

echo '<td align="center"><a href="' . $scripturl . '?action=downloads;sa=view;id=' . $row['ID_FILE'] . '">',$row['title'],'</a><br />';

if ($isPro == true && $modSettings['down_set_t_image'] && !empty($row['thumbfilename']))
echo '<a href="' . $scripturl . '?action=downloads;sa=view;id=' . $row['ID_FILE'] . '"><img src="',$modSettings['down_url'],$row['thumbfilename'],'" alt="" /></a><br />';


echo '<span class="smalltext">';
//if (!empty($modSettings['down_set_t_rating']))
//echo $txt['downloads_form_rating'] . EzGetStarsByPrecent(($row['totalratings'] != 0) ? ($row['rating'] / ($row['totalratings']* 5) * 100) : 0) . '<br />';



if (!empty($modSettings['down_set_t_username']))
{
if ($row['real_name'] != '')
echo $txt['downloads_text_by'] . ' <a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">'  . $row['real_name'] . '</a><br />';
else
echo $txt['downloads_text_by'] . ' ' . $txt['downloads_guest'] . '<br />';
}
echo '</span></td>';


if ($rowlevel < ($maxrowlevel-1))
$rowlevel++;
else
{
echo '</tr>';
$rowlevel = 0;
}
}
if ($rowlevel !=0)
{
echo '</tr>';
}

echo '
      </table><br />';


}
Logged
shaka
Newbie
*
Offline Offline

Posts: 37


View Profile
« Reply #10 on: January 24, 2012, 06:49:25 pm »

wow that is perfect, thank you so much  Smiley
Logged
Pages: [1] Go Up Print 
« previous next »
Jump to:  

Recent
[April 15, 2014, 12:07:27 pm]

[April 15, 2014, 10:58:02 am]

[April 13, 2014, 11:12:24 am]

[April 11, 2014, 09:39:48 am]

[April 11, 2014, 08:48:03 am]

[April 10, 2014, 08:20:58 am]

[April 09, 2014, 09:16:55 pm]

[April 09, 2014, 12:17:21 pm]

[April 09, 2014, 12:11:46 pm]

[April 08, 2014, 10:39:42 pm]
Random Picture
Donate to SMFHacks.com
Help Support the SMFHacks.com mod making.
Powered by SMF 1.1.19 | SMF © 2013, Simple Machines
TinyPortal v0.9.7 © Bloc
SMF and SimpleMachines are registered trademarks of Simple Machines. SMFHacks.com is not affiliated with nor endorsed by Simple Machines.
Page created in 1.248 seconds with 18 queries.