vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Top 5 posters (https://vborg.vbsupport.ru/showthread.php?t=200783)

Ghost Shadow 01-05-2009 04:42 PM

Top 5 posters
 
Is it possible to list the top 5 posters? Such as using a "$"?

TIA

-Joseph

Bellardia 01-05-2009 05:04 PM

You can't call them by any defined function, but you could make a short plugin that uses a single query to find the top 5, and then style them as you want.

Ghost Shadow 01-05-2009 05:37 PM

Quote:

Originally Posted by Bellardia (Post 1702458)
You can't call them by any defined function, but you could make a short plugin that uses a single query to find the top 5, and then style them as you want.

How difficult is this to do Bellardia?

Bellardia 01-05-2009 06:57 PM

Quote:

Originally Posted by Ghost Shadow (Post 1702493)
How difficult is this to do Bellardia?

Depends how much of the information you want to be displayed and how you want it to be styled, simply listing the top 5 posters in commas in plain text would be very simple; a few lines of code.

Styling them wouldn't be much harder either if using basic styles. However pulling other information with them would take joins (say, color of username, usertitle etc) but nonetheless quite simple in essence.

Depending on what your needs are I could write up a quick script for you.

Ghost Shadow 01-05-2009 07:34 PM

Quote:

Originally Posted by Bellardia (Post 1702557)
Depends how much of the information you want to be displayed and how you want it to be styled, simply listing the top 5 posters in commas in plain text would be very simple; a few lines of code.

Styling them wouldn't be much harder either if using basic styles. However pulling other information with them would take joins (say, color of username, usertitle etc) but nonetheless quite simple in essence.

Depending on what your needs are I could write up a quick script for you.

Bellardia, thank you so much!!!

I created a sidebar and I want it to go within "Top 5 Posters" block, 3rd from the top.
I just want the nick of the poster on the far left, and number of posts on the far right. With the highest poster on top, to the lowest on bottom.

If possible, making the numbers yellow and keeping the names default.

I'll open the forum so you can see the side block I'm referring to.

Thank you so much for your kindness!
-Joseph
http://www.warfaith.com/

Bellardia 01-05-2009 08:15 PM

I have class now, so just give me 3-4 hours ;p

Ghost Shadow 01-05-2009 08:23 PM

Quote:

Originally Posted by Bellardia (Post 1702611)
I have class now, so just give me 3-4 hours ;p

KoOL

I'll close the forum back up...Thank you!!!!!

Bellardia 01-06-2009 01:20 AM

Open a plaintext editor, paste in the code below, and save it as something. Upload it as a product.
Where you want the names to appear, place '$Top5' in the template, and they will be inserted in yellow color. You can specify your own color of yellow by finding and replacing '#ff0' with any hex color of your choice. I just used the default yellow because I don't know what you're after ;)

Please don't repost, submit, or distribute without asking!
Feel free to use as you need.
1 Query, 0 File edits, 0 Uploads
Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="top5posters" active="1">
        <title>Top 5 Posters</title>
        <description>Gets a string of the top five posters, and parses where $Top5 is included in a template</description>
        <version>0.1</version>
        <url />
        <versioncheckurl />
        <dependencies>
        </dependencies>
        <codes>
        </codes>
        <templates>
        </templates>
        <plugins>
                <plugin active="1" executionorder="5">
                        <title>Top5Posters</title>
                        <hookname>forumhome_start</hookname>
                        <phpcode><![CDATA[global $vbulletin;
$GrabString = $vbulletin->db->query_read("select `username`, `posts` from `".TABLE_PREFIX."user` ORDER BY `posts` DESC limit 0, 4;");
while ($GrabTop = $vbulletin->db->fetch_array($GrabString))
{
        $Top5Store[] = '<tr><td width="100%">'.$GrabTop['username'].'</td><td style="white-space:nowrap">'.$GrabTop['posts'].'</td></tr>';       
}
$Top5Store = '<table width="100%" border="0" style="color:#FF0">'.implode('', $Top5Store).'</table>';
htmlspecialchars_uni($Top5Store);
build_datastore('TopPosters', $Top5Store);
unset($GrabTop, $Top5Store, $GrabString);]]></phpcode>
                </plugin>
                <plugin active="1" executionorder="10">
                        <title>Parse Names</title>
                        <hookname>global_start</hookname>
                        <phpcode><![CDATA[$Top5 = $vbulletin->TopPosters;]]></phpcode>
                </plugin>
                <plugin active="1" executionorder="5">
                        <title>DataStore</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[$datastore_fetch[] = "'TopPosters'";
$Top5 = $vbulletin->TopPosters;]]></phpcode>
                </plugin>
        </plugins>
        <phrases>
        </phrases>
        <options>
        </options>
        <helptopics>
        </helptopics>
        <cronentries>
        </cronentries>
        <faqentries>
        </faqentries>
</product>


Ghost Shadow 01-06-2009 02:46 AM

First, thank you for the time you spent on writing this code.

It partially works. Does not show the number of posts. Just shows users in sequence separated by a comma.

Dismounted 01-06-2009 02:52 AM

1) You do not need to evaluate that code...
2) And therefore, do not need addslashes().
3) You should run htmlspecialchars_uni() on the username.
4) This is the sort of data that the datastore should cache. No one cares if the data is 10 minutes off or so...

Bellardia 01-06-2009 04:08 AM

Quote:

Originally Posted by Ghost Shadow (Post 1702923)
First, thank you for the time you spent on writing this code.

It partially works. Does not show the number of posts. Just shows users in sequence separated by a comma.

I thought that was all you wanted, I can add amount of posts for you tomorow.

Quote:

Originally Posted by Dismounted (Post 1702929)
1) You do not need to evaluate that code...
2) And therefore, do not need addslashes().
3) You should run htmlspecialchars_uni() on the username.
4) This is the sort of data that the datastore should cache. No one cares if the data is 10 minutes off or so...

Thanks for the pointers, I was a little rusty since it's been a few months since I wrote any mods. I'll add these changes and repost.

Ghost Shadow 01-06-2009 04:23 AM

I just want the nick of the poster on the far left, and number of posts on the far right. With the highest poster on top, to the lowest on bottom.

Thank you.

Bellardia 01-06-2009 10:29 AM

Quote:

Originally Posted by Ghost Shadow (Post 1702987)
I just want the nick of the poster on the far left, and number of posts on the far right. With the highest poster on top, to the lowest on bottom.

Thank you.

Code was changed above to reflect changes. It's stored in a html table with 100% width, just hold it in a container/div of the required width. Still call using $Top5. It caches the top posters when a user visits forumhome. It could be optimized a bit by using a cron instead but I'll leave that to you, however it shouldn't be a problem.

Ghost Shadow 01-06-2009 02:52 PM

Bellardia,
Works great!!!
One final request please Bellardia; is it possible to have the nick the system color?

It would be nice to only have the number in yellow, and the name in the system color, both are yellow now.

Thank you Bellardia.

Bellardia 01-06-2009 03:38 PM

Quote:

Originally Posted by Ghost Shadow (Post 1703297)
Bellardia,
Works great!!!
One final request please Bellardia; is it possible to have the nick the system color?

It would be nice to only have the number in yellow, and the name in the system color, both are yellow now.

Thank you Bellardia.

Just give me your color codes so I can match it perfectly ;)

Ghost Shadow 01-06-2009 04:56 PM

Quote:

Originally Posted by Bellardia (Post 1703366)
Just give me your color codes so I can match it perfectly ;)

#848484 for the nick
#FFFF00 for the number

Thank you Bellardia!!!!!!!!

Bellardia 01-06-2009 07:15 PM

Glad to help ;) It allows me to practice and learn some of the vb features better anyways.

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="top5posters" active="1">
        <title>Top 5 Posters</title>
        <description>Gets a string of the top five posters, and parses where $Top5 is included in a template</description>
        <version>0.1</version>
        <url />
        <versioncheckurl />
        <dependencies>
        </dependencies>
        <codes>
        </codes>
        <templates>
        </templates>
        <plugins>
                <plugin active="1" executionorder="5">
                        <title>Top5Posters</title>
                        <hookname>forumhome_start</hookname>
                        <phpcode><![CDATA[global $vbulletin;
$GrabString = $vbulletin->db->query_read("select `username`, `posts` from `".TABLE_PREFIX."user` ORDER BY `posts` DESC limit 0, 4;");
while ($GrabTop = $vbulletin->db->fetch_array($GrabString))
{
        $Top5Store[] = '<tr><td width="100%" style="color:#848484;">'.$GrabTop['username'].'</td><td style="white-space:nowrap; color:#FFFF00">'.$GrabTop['posts'].'</td></tr>';       
}
$Top5Store = '<table width="100%" border="0" style="color:#FF0">'.implode('', $Top5Store).'</table>';
htmlspecialchars_uni($Top5Store);
build_datastore('TopPosters', $Top5Store);
unset($GrabTop, $Top5Store, $GrabString);]]></phpcode>
                </plugin>
                <plugin active="1" executionorder="10">
                        <title>Parse Names</title>
                        <hookname>global_start</hookname>
                        <phpcode><![CDATA[$Top5 = $vbulletin->TopPosters;]]></phpcode>
                </plugin>
                <plugin active="1" executionorder="5">
                        <title>DataStore</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[$datastore_fetch[] = "'TopPosters'";
$Top5 = $vbulletin->TopPosters;]]></phpcode>
                </plugin>
        </plugins>
        <phrases>
        </phrases>
        <options>
        </options>
        <helptopics>
        </helptopics>
        <cronentries>
        </cronentries>
        <faqentries>
        </faqentries>
</product>


Ghost Shadow 01-06-2009 11:12 PM

Bellardia.....PERFECT!!
Thanks so much, looks GREAT.
Thanks so much for being patient and so helpful!!! :):D:eek::up:;):p

Dismounted 01-07-2009 05:37 AM

Quote:

Originally Posted by Bellardia (Post 1703548)
Glad to help ;) It allows me to practice and learn some of the vb features better anyways.

What's the point of putting the data into the datastore when you're going to update it every time? You need to add a "time to live" on the variable (e.g. TIMENOW + 10 mins), then check if this time is up, if it is not, don't update the cache, but use the data already in the cache.

Ghost Shadow 01-07-2009 05:22 PM

Quote:

Originally Posted by Dismounted (Post 1703916)
What's the point of putting the data into the datastore when you're going to update it every time? You need to add a "time to live" on the variable (e.g. TIMENOW + 10 mins), then check if this time is up, if it is not, don't update the cache, but use the data already in the cache.

Do I need to change something?
One other thing, not a big deal, but it would be nice if it could be changed. :)
The first digit is showing up on the left, instead of the right. Please see graphic; zero under one. It would be nice just to have numbers begin on the far right.

https://vborg.vbsupport.ru/external/2009/01/4.bmp

Thank you!!

Bellardia 01-07-2009 11:09 PM

Hopefully this will be my final revision :x

Fixed alignment, and updates every 20minutes.
Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="top5posters" active="1">
        <title>Top 5 Posters</title>
        <description>Gets a string of the top five posters, and parses where $Top5 is included in a template</description>
        <version>0.1</version>
        <url />
        <versioncheckurl />
        <dependencies>
        </dependencies>
        <codes>
        </codes>
        <templates>
        </templates>
        <plugins>
                <plugin active="1" executionorder="10">
                        <title>Parse Names</title>
                        <hookname>global_start</hookname>
                        <phpcode><![CDATA[global $vbulletin;
        $Top5Data = unserialize($vbulletin->TopPosters);
        if (count($Top5Data) != 2) $Top5Data[0] = 0;
        $Top5 = $Top5Data[1];
        if (($Top5Data[0] + 1200) < TIMENOW)
        {
                $GrabString = $vbulletin->db->query_read("select `username`, `posts` from `".TABLE_PREFIX."user` ORDER BY `posts` DESC limit 0, 4;");
                while ($GrabTop = $vbulletin->db->fetch_array($GrabString))
                {
                        $Top5Store[] = '<tr><td width="100%" style="color:#848484;">'.$GrabTop['username'].'</td><td style="white-space:nowrap; color:#FFFF00" align="right">'.$GrabTop['posts'].'</td></tr>';       
                }
                $Top5Store = '<table width="100%" border="0" style="color:#FF0">'.implode('', $Top5Store).'</table>';
                htmlspecialchars_uni($Top5Store);
                $Top5Storage = array(TIMENOW, $Top5Store);
                build_datastore('TopPosters', serialize($Top5Storage));
                $Top5 = $Top5Store;
        }]]></phpcode>
                </plugin>
                <plugin active="1" executionorder="5">
                        <title>DataStore</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[$datastore_fetch[] = "'TopPosters'";
$Top5 = $vbulletin->TopPosters;]]></phpcode>
                </plugin>
        </plugins>
        <phrases>
        </phrases>
        <options>
        </options>
        <helptopics>
        </helptopics>
        <cronentries>
        </cronentries>
        <faqentries>
        </faqentries>
</product>


Ghost Shadow 01-07-2009 11:19 PM

Bellardia, you are a "Coding Saint". Now it is PERFECT!!
Today is my birthday; thank you for all the time you spent helping me, fantastic present.
Peace my friend.


:p:D:):rolleyes::eek::cool:;):up:

Dismounted 01-08-2009 03:14 AM

Quote:

Originally Posted by Bellardia (Post 1704609)
Hopefully this will be my final revision :x

Maybe not. ;)

First line of the plugin at init_startup, you have too many sets of quotes. Second line is not needed at all. When using build_datastore(), you can set a third parameter, which can automatically unserialize the data for you. Also, you want to run htmlspecialchars_uni on the username, not the whole thing. Finally, you might want to look at the vBulletin Coding Standards document.

F0xy 02-06-2009 07:57 PM

it would be amazing if this could be edited to show the top 10 latest posts for the sidebar.

When I added the latest it only displayed the top 4 posters?

slinky 04-27-2009 03:28 PM

I'm using an old hack and need to work on this one. If I had the time I'd probably take a better look. I'm shocked that nobody has done a good one for this very popular function.


All times are GMT. The time now is 12:48 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01254 seconds
  • Memory Usage 1,824KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (12)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (25)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete