1
Feature Requests / Downloads Portal Block
« on: March 31, 2010, 07:55:00 pm »
* This is not a feature request... but it seemed to be the most appropriate forum to put it in. Staff... please feel free to relocate as required.
If you use any of the portal systems for SMF that have PHP blocks, you can easily duplicate the Recent Downloads section of the Downloads System on your Front Page.
Just add the following code snippet into a portal PHP block:
Options:
If you would rather have the Most Viewed, Most Commented On, Most Downloaded, or Top Rated downloads display, just change the 'recent' string in the function call ( MainPageBlock('Recent Uploads', 'recent'); ) to either 'viewed', 'mostcomments', 'mostdownloaded' or 'toprated'.
* You will also want to change the title string in the function call ( MainPageBlock('Recent Uploads', 'recent'); ) to match what ever function you are calling (eg.. 'Most Viewed Downloads'.. or 'Top Rated Downloads', etc...
If you would like more than one or all of the options to display, just duplicate the function call... and add at least one line break ( eg.. echo '<br />'; ) between them. So you would have the function call like this:
How It Works:
Very little code is required because the block simply uses the code already provided by the Downloads System program. The require_once($sourcedir . '/Downloads2.php') loads in the Downloads System main file so we can use the MainPageBlock function it contains. That function has all the database query code and data output formatting in it... so we don't have to include it. Just once function call... and our work here is done. Miller time!!
The MainPageBlock function, however, does make a function call to the GetStarsByPrecent function which, I know not why, is in the Downloads System template file. Instead of including that rather large file as we did with the Downloads main file, I just copied that fairly small function and pasted it into our block.
NOTES:
* This was designed and tested for the Downloads System (non-pro) version 1.3... running on SMF 2.0 RC3. I would think it would also function properly on older versions as well as the pro version... but don't hold me to that.
* The GetStarsByPrecent function includes a small modification I added where the star images are enclosed in a <span> element with a "white-space: nowrap" property to keep the star images together and prevent them from wrapping if the browser width is reduced too far.
* Because of the width of the display, this code snippet in not suitable for use in a normal left or right pane block.
CREDITS:
* All of the code used in the snippet (well, 99% of it anyway) is code included or copied from the SMF Hacks Downloads System files. All copyrights, I assume... apply. As this code would be useless without that system installed, I believe you can safely use this snippet without violating any copyright or the intent thereof.
If you use any of the portal systems for SMF that have PHP blocks, you can easily duplicate the Recent Downloads section of the Downloads System on your Front Page.
Just add the following code snippet into a portal PHP block:
Code: [Select]
global $sourcedir;
require_once($sourcedir . '/Downloads2.php');
MainPageBlock('Recent Uploads', 'recent');
function GetStarsByPrecent($percent)
{
global $settings, $txt;
$s = '<span style="white-space: nowrap;">';
if ($percent == 0)
return $txt['downloads_text_catnone'];
else if ($percent <= 20)
return $s . str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 1) . '</span>';
else if ($percent <= 40)
return $s . str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 2) . '</span>';
else if ($percent <= 60)
return $s . str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 3) . '</span>';
else if ($percent <= 80)
return $s . str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 4) . '</span>';
else if ($percent <= 100)
return $s . str_repeat('<img src="' . $settings['images_url'] . '/star.gif" alt="*" border="0" />', 5) . '</span>';
}
Options:
If you would rather have the Most Viewed, Most Commented On, Most Downloaded, or Top Rated downloads display, just change the 'recent' string in the function call ( MainPageBlock('Recent Uploads', 'recent'); ) to either 'viewed', 'mostcomments', 'mostdownloaded' or 'toprated'.
* You will also want to change the title string in the function call ( MainPageBlock('Recent Uploads', 'recent'); ) to match what ever function you are calling (eg.. 'Most Viewed Downloads'.. or 'Top Rated Downloads', etc...
If you would like more than one or all of the options to display, just duplicate the function call... and add at least one line break ( eg.. echo '<br />'; ) between them. So you would have the function call like this:
Code: [Select]
//Example Only...
MainPageBlock('Recent Uploads', 'recent');
echo '<br />';
MainPageBlock('Highest Rated Downloads', 'toprated');
echo '<br />';
//.... etc,
How It Works:
Very little code is required because the block simply uses the code already provided by the Downloads System program. The require_once($sourcedir . '/Downloads2.php') loads in the Downloads System main file so we can use the MainPageBlock function it contains. That function has all the database query code and data output formatting in it... so we don't have to include it. Just once function call... and our work here is done. Miller time!!
The MainPageBlock function, however, does make a function call to the GetStarsByPrecent function which, I know not why, is in the Downloads System template file. Instead of including that rather large file as we did with the Downloads main file, I just copied that fairly small function and pasted it into our block.
NOTES:
* This was designed and tested for the Downloads System (non-pro) version 1.3... running on SMF 2.0 RC3. I would think it would also function properly on older versions as well as the pro version... but don't hold me to that.
* The GetStarsByPrecent function includes a small modification I added where the star images are enclosed in a <span> element with a "white-space: nowrap" property to keep the star images together and prevent them from wrapping if the browser width is reduced too far.
* Because of the width of the display, this code snippet in not suitable for use in a normal left or right pane block.
CREDITS:
* All of the code used in the snippet (well, 99% of it anyway) is code included or copied from the SMF Hacks Downloads System files. All copyrights, I assume... apply. As this code would be useless without that system installed, I believe you can safely use this snippet without violating any copyright or the intent thereof.