Facebook  Twitter 

SMFHacks.com

+- +-

SMFHacks.com

+- User Information

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

+- Forum Stats

Members
Total Members: 12356
Latest: how to logo design
New This Month: 7
New This Week: 0
New Today: 0
Stats
Total Posts: 40076
Total Topics: 7055
Most Online Today: 30
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 25
Total: 25

Author Topic: Downloads Portal Block  (Read 4740 times)

0 Members and 1 Guest are viewing this topic.

Offline Pegasys

  • Newbie
  • *
  • 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: 15040
    • 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

  • Newbie
  • *
  • 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
0 Replies
2340 Views
Last post May 13, 2009, 03:18:58 pm
by propyl
1 Replies
3285 Views
Last post June 08, 2010, 03:18:26 pm
by SMFHacks
1 Replies
2136 Views
Last post June 07, 2011, 05:57:48 am
by SMFHacks
10 Replies
4669 Views
Last post January 24, 2012, 06:49:25 pm
by shaka
0 Replies
1146 Views
Last post October 15, 2015, 07:42:27 pm
by shuban

+- Recent Topics

Cannot install Gallery Pro on SMF 2.1 RC2 by Hatshepsut
March 19, 2020, 12:55:00 am

Newbie questions by SMFHacks
March 08, 2020, 09:28:17 am

Update detect mobile mode PHP5 to PHP7 by Plus
March 05, 2020, 11:19:05 am

Just a hello by Plus
March 05, 2020, 11:05:56 am

Enotify Copyright Problem by SMFHacks
March 04, 2020, 09:21:09 pm

Cannot import by shawnb
March 02, 2020, 12:17:00 pm

Error message with latest SMF 2.1 Github build by Hatshepsut
March 01, 2020, 10:06:10 am

[Mod]Avatars Display Integration by SMFHacks
February 15, 2020, 07:30:47 pm

[Mod]BBC Message Boxes 1.0 by SMFHacks
February 15, 2020, 07:26:46 pm

[Mod]Stack Trace by live627 by SMFHacks
February 15, 2020, 07:21:33 pm

Powered by EzPortal