Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

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

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 297
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 285
Total: 285

Author Topic: Downloads Portal Block  (Read 6287 times)

0 Members and 1 Guest are viewing this topic.

Offline Pegasys

  • Member
  • *
  • Posts: 10
    • View Profile
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:

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!!   ;D

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.


« Last Edit: March 31, 2010, 07:59:38 pm by Pegasys »

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Downloads Portal Block
« Reply #1 on: March 31, 2010, 08:00:52 pm »
Thanks for the code snippet should be helpful for people!
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/

Offline Pegasys

  • Member
  • *
  • Posts: 10
    • View Profile
Re: Downloads Portal Block
« Reply #2 on: April 01, 2010, 07:39:09 am »
Darn... I hate it when this happens.

I just discovered that the downloads language file will not get loaded in when we include the Downloads2.php file. So we need to add one extra line to our code;    loadLanguage('Downloads','english');. That needs to be added as the first line below the globals declaration.


Revised full version:

Code: [Select]
global $sourcedir;

loadLanguage('Downloads','english');
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>';
}



 

Related Topics

  Subject / Started by Replies Last post
1 Replies
5028 Views
Last post June 08, 2010, 03:18:26 pm
by SMFHacks
1 Replies
4357 Views
Last post June 07, 2011, 05:57:48 am
by SMFHacks
10 Replies
7319 Views
Last post January 24, 2012, 06:49:25 pm
by shaka
9 Replies
2138 Views
Last post August 23, 2022, 12:42:22 pm
by SMFHacks
9 Replies
1540 Views
Last post April 05, 2022, 01:29:19 pm
by SMFHacks

+- Recent Topics

No thumbnails on new uploads by SMFHacks
March 27, 2024, 02:10:41 pm

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal