Facebook 

SMFHacks.com - Celebrating 20 Years!

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4341
Latest: jmac32here
New This Month: 2
New This Week: 0
New Today: 0
Stats
Total Posts: 44306
Total Topics: 7676
Most Online Today: 736
Most Online Ever: 27044
(May 30, 2026, 09:10:16 pm)
Users Online
Members: 0
Guests: 699
Total: 699

Author Topic: Random Downloads Block  (Read 28533 times)

0 Members and 1 Guest are viewing this topic.

Re: Random Downloads Block
« Reply #15 on: »
Code: [Select]
Myabe try just
[code]
global $modSettings, $smcFunc, $boardurl, $txt, $scripturl;

$isPro = true;
        $files = 5;
        $maxrowlevel = 5;


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 />';

That took the loadlanguage call[/code]
« Last Edit: July 03, 2012, 09:50:36 pm by SMFHacks »
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Re: Random Downloads Block
« Reply #16 on: »
now get this error code showing in the block

/Sources/Load.php(2206) : eval()'d code(114) : eval()'d code on line 119

thanks for your time on this but please only when you can it is not urgent

Re: Random Downloads Block
« Reply #17 on: »
Refixed the above retry again.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Re: Random Downloads Block
« Reply #18 on: »
it is now back to showing the full front page in the block again  >:(
« Last Edit: July 04, 2012, 04:13:50 am by shaka »

Re: Random Downloads Block
« Reply #19 on: »
Not sure if this helps or not, but I have just added the following code to a php block in Simpleportal.


Code: [Select]
global $sourcedir;

loadLanguage('Downloads','english');
require_once($sourcedir . '/Downloads2.php');

Downloads_MainPageBlock('Recent Uploads', 'recent');

I get the latest uploaded files only in a block on the portal page.

Re: Random Downloads Block
« Reply #20 on: »
Following on from the last post I made. This is not showing the images now for some reason in a portal block.

See what it does from the info below


Simple Portal 2.3.5 = http://www.******.net/test/thumb_1_07_07_14_12_12_46_0.jpeg - This is the properties of the link to the image.


Downloads = http://www.******.net/test/downloads/thumb_1_07_07_14_12_12_46_0.jpeg - This is the properties of the link to the image.


The code I'm using which has worked until recently is,

Code: [Select]
global $sourcedir;

loadLanguage('Downloads','english');
require_once($sourcedir . '/Downloads2.php');

Downloads_MainPageBlock('Recent Uploads', 'recent');


The error log shows

Code: [Select]
http://www.******.net/test/index.php?action=admin;area=portalblocks;sa=edit

Apply Filter: Only show the errors with the same message

8: Undefined index: down_url

Apply Filter: Only show the errors from this file

File: /home5/******/public_html/test/Sources/Downloads2.php
 Line: 6811

I have just tried this on a new clean 2.0.8 install and the only mods installed are Downloads 3.0.3 and Simple Portal 2.3.5.

The only thing that has happened recently is that the host updated the server files. What I don't understand is why the portal properties seem to leave out the 'Downloads' directory in order to find the image.

So now it's over to you :)
« Last Edit: July 08, 2014, 07:28:38 am by davejo »

Re: Random Downloads Block
« Reply #21 on: »
Hi VB have you any idea on this problem please?

Re: Random Downloads Block
« Reply #22 on: »
Use this code before calling your code just in case
Code: [Select]
global $modSettings;
if (empty($modSettings['down_url']))
$modSettings['down_url'] = $boardurl . '/downloads/';
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Re: Random Downloads Block
« Reply #23 on: »
Use this code before calling your code just in case
Code: [Select]
global $modSettings;
if (empty($modSettings['down_url']))
$modSettings['down_url'] = $boardurl . '/downloads/';

Worked perfectly VB, thanks very much

Re: Random Downloads Block
« Reply #24 on: »
Actually it didn't quite work perfectly but it did nearly.

It threw out an error

Code: [Select]
8: Undefined variable: boardurl

So I changed the code slightly to

Code: [Select]
global $boardurl, $modSettings;
$modSettings['down_url'] = $boardurl . '/downloads/';

global $sourcedir;

loadLanguage('Downloads','english');
require_once($sourcedir . '/Downloads2.php');

Downloads_MainPageBlock('Recent Uploads', 'recent');


and now it works with no errors.

Thanks again VB without the initial code I would never have got it working again.

Is the line
Code: [Select]
if (empty($modSettings['down_url'])) critical to it working as I am using it without and there doesn't seem to be any problems?

Re: Random Downloads Block
« Reply #25 on: »
No it is not critical will work fine.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Re: Random Downloads Block
« Reply #26 on: »
Thanks for the reply

Re: Random Downloads Block
« Reply #27 on: »
Thanks for the reply

The original request was for a block of randomly chosen items to display, I now have this working beautifully in Simple Portal block, it only requires one small edit in addition to a minor change to to the block code, as follows:

In Sources/Downloads2.php add the section circled in green to the snippet of code shown located in the Downloads_MainPageBlock() function:




After that make this minor change to the portal block code, shown in its entirety here:
Code: [Select]
global $boardurl, $modSettings;
$modSettings['down_url'] = $boardurl . '/downloads/';

global $sourcedir;

require_once($sourcedir . '/Downloads2.php');

Downloads_MainPageBlock(null, 'random');

Enjoy... I also have some custom modifications to the SMF Statistics Page that relates to various modules and SMF features, visit my site and have a look at the ones for this module, although my version of Downloads Pro is out of date, everything I've customized works great!!

« Last Edit: February 25, 2017, 06:10:21 am by Web Presence Consulting »
Best Regards,
Bob Perry




"The world is moving so fast these days that the man who says it can't be done is generally interrupted by someone doing it." Elbert Hubbard

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
8208 Views
Last post February 18, 2008, 08:03:27 am
by Ken.
4 Replies
10378 Views
Last post June 18, 2010, 09:18:00 am
by dvera
2 Replies
6815 Views
Last post November 01, 2010, 01:32:28 pm
by clothahump
1 Replies
8518 Views
Last post October 16, 2016, 12:12:51 pm
by exit
5 Replies
8509 Views
Last post July 12, 2017, 03:45:34 pm
by donk

+- Recent Topics

Registration - anti bot pattern matching by SMFHacks
November 01, 2026, 07:20:17 pm

EZPortal 8 by davejo
October 21, 2026, 01:01:54 pm

Downloads Pro 7.0 Released by SMFHacks
October 07, 2026, 07:35:30 pm

[Mod]ActivityPub Federation for SMF 2.1 by SMFHacks
October 01, 2026, 05:03:45 pm

Newsletter Pro 4.0 Released by SMFHacks
September 23, 2026, 08:08:24 pm

Can't remove or restore any item from the recycle bin by SMFHacks
September 22, 2026, 11:01:51 am

MCP Server for SMF 2.1 - let Claude, ChatGPT or Cursor run your admin chores by SMFHacks
September 12, 2026, 02:50:45 pm

Suggestions for improvements to Ultimate Shoutbox & Chatroom by davejo
September 02, 2026, 01:35:09 am

Automatic Sorting of Categories by Kiwi
August 31, 2026, 12:36:09 am

' appears as &#39; in Most Viewed (and Recent Items ?) by SMFHacks
August 22, 2026, 11:01:56 pm

Powered by EzPortal