PDA

View Full Version : Show TOP Reputation Poster


hollyboy
10-19-2017, 10:49 PM
Hi,
I would like to show the Top reputation poster on my board.
Preferably on the sidebar.
Is there a way?

MarkFL
10-20-2017, 12:26 AM
Yes, you will need to create a new "Forum Block."

Follow:

AdminCP -> Forums & Moderators -> Forum Blocks Manager

At the bottom of the form, click "Add Block".

From the drop-down menu for "Select Block Type", choose "Custom HTML/PHP" then click "Continue".

You will be presented with a form for defining your new block. Give it a title, such as "Top 5 Reputations" and a description. I recommend caching the block for at least 60 minutes, this way the database need only be queried once an hour. Set the display order so that it shows where you desire in the sidebar.

For "Content Type" select "PHP".

And for the content, add the following code:

global $vbulletin, $db;
$max = 5;
$output = '<div class="restore"><ul>';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid != 8
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$output .= '<li>' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</li>';
$rcount++;
}

$output .= '</ul></div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

Change the line:

$max = 5;

to match the number of users you wish to display.

Note: Users who have elected to hide their reputations will not be displayed. It only makes sense to honor this setting here. Also, banned users are excluded.

If you have any changes to the way the users are displayed, please let me know. The usernames are shown with their username markup, and link to their profiles.

hollyboy
10-20-2017, 02:42 PM
Yes, you will need to create a new "Forum Block."

Follow:

AdminCP -> Forums & Moderators -> Forum Blocks Manager

At the bottom of the form, click "Add Block".

From the drop-down menu for "Select Block Type", choose "Custom HTML/PHP" then click "Continue".

You will be presented with a form for defining your new block. Give it a title, such as "Top 5 Reputations" and a description. I recommend caching the block for at least 60 minutes, this way the database need only be queried once an hour. Set the display order so that it shows where you desire in the sidebar.

For "Content Type" select "PHP".

And for the content, add the following code:

global $vbulletin, $db;
$max = 5;
$output = '<div class="restore"><ul>';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid != 8
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$output .= '<li>' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</li>';
$rcount++;
}

$output .= '</ul></div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

Change the line:

$max = 5;

to match the number of users you wish to display.

Note: Users who have elected to hide their reputations will not be displayed. It only makes sense to honor this setting here. Also, banned users are excluded.

If you have any changes to the way the users are displayed, please let me know. The usernames are shown with their username markup, and link to their profiles.

this is great!
can also avatar be displayed?
Also I want admin to be escluded from the list please

MarkFL
10-20-2017, 03:15 PM
this is great!
can also avatar be displayed?
Also I want admin to be escluded from the list please

Yes, change the content code to:

global $vbulletin, $db;
$max = 5;
$output = '<div class="restore"><ul style="margin-top: 0; margin-bottom: 0;">';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid NOT IN (6,8)
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$avatar_url = fetch_avatar_url($rep_user['userid']);
$avatar = $avatar_url[0];

if (!$avatar)
{
$avatar = $vbulletin->stylevars['imgdir_misc']['imagedir'] . '/unknown.gif';
}

$output .= '<li><div style="display: inline-block; width: 20%; margin: 5px 0;"><img src="' . $avatar . '" style="vertical-align: middle; max-height: 40px;" /></div>' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</li>';
$rcount++;
}

$output .= '</ul></div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

hollyboy
10-20-2017, 03:21 PM
Yes, change the content code to:

global $vbulletin, $db;
$max = 5;
$output = '<div class="restore"><ul style="margin-top: 0; margin-bottom: 0;">';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid NOT IN (6,8)
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$avatar_url = fetch_avatar_url($rep_user['userid']);
$avatar = $avatar_url[0];

if (!$avatar)
{
$avatar = $vbulletin->stylevars['imgdir_misc']['imagedir'] . '/unknown.gif';
}

$output .= '<li><div style="display: inline-block; width: 20%; margin: 5px 0;"><img src="' . $avatar . '" style="vertical-align: middle; max-height: 40px;" /></div>' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</li>';
$rcount++;
}

$output .= '</ul></div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

awesome!
There is an avatar issue (check screenshot below) they should be all square
Also I would disable the bullet points
Thank you!
https://vborg.vbsupport.ru/external/2017/10/4.jpg (http://ibb.co/g4ywmR)

MarkFL
10-20-2017, 03:36 PM
If you force the avatars to be square, then the aspect ratio of the images won't be preserved, and you will wind up with "squished" images. However, give this a try, and you'll see what I mean:

global $vbulletin, $db;
$max = 5;
$output = '<div class="restore">';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid NOT IN (6,8)
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$avatar_url = fetch_avatar_url($rep_user['userid']);
$avatar = $avatar_url[0];

if (!$avatar)
{
$avatar = $vbulletin->stylevars['imgdir_misc']['imagedir'] . '/unknown.gif';
}

$output .= '<div style="margin: 5px 0;"><img src="' . $avatar . '" style="vertical-align: middle; width: 40px; height: 40px; margin-right: 0.25em" />' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</div>';
$rcount++;
}

$output .= '</div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

hollyboy
10-20-2017, 03:40 PM
If you force the avatars to be square, then the aspect ratio of the images won't be preserved, and you will wind up with "squished" images. However, give this a try, and you'll see what I mean:

global $vbulletin, $db;
$max = 5;
$output = '<div class="restore">';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid NOT IN (6,8)
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$avatar_url = fetch_avatar_url($rep_user['userid']);
$avatar = $avatar_url[0];

if (!$avatar)
{
$avatar = $vbulletin->stylevars['imgdir_misc']['imagedir'] . '/unknown.gif';
}

$output .= '<div style="margin: 5px 0;"><img src="' . $avatar . '" style="vertical-align: middle; width: 40px; height: 40px; margin-right: 0.25em" />' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</div>';
$rcount++;
}

$output .= '</div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

yes I see what you mean, but better than before. Thank you!
Do you think it can be also made by top poster of the week, month and so?
You should make it as an official mod :)
Thanks dude

MarkFL
10-20-2017, 03:47 PM
yes I see what you mean, but better than before. Thank you!

When I have more time, I will come up with a better solution for the avatars. :)

Do you think it can be also made by top poster of the week, month and so?
You should make it as an official mod :)
Thanks dude

Yes, creating a forum block for the top posters for various time periods could be done...it's just a matter of coming up with the right db queries. Let me know exactly what you want, and I will see what I can do. :)

hollyboy
10-20-2017, 03:51 PM
Let me know exactly what you want, and I will see what I can do. :)

Ok what I have in mind is the box that I have now on my board's sidebar (http://www.interfans.org/forum/forum.php), with 3 different tabs:

- top reputation of the week
- top reputation of the month
- all time top reputation

MarkFL
10-20-2017, 03:56 PM
I get a blank white page following the link you posted to your site. However, if you could create a mockup image of what you want this reputation block to ultimately look like, that would be a huge help in making certain I get what you want without having to make multiple changes.

Also, this would take some time, so it would be a while once I know exactly what you want before I would have the code ready. :)

hollyboy
10-20-2017, 08:44 PM
If you force the avatars to be square, then the aspect ratio of the images won't be preserved, and you will wind up with "squished" images. However, give this a try, and you'll see what I mean:

global $vbulletin, $db;
$max = 5;
$output = '<div class="restore">';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid NOT IN (6,8)
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$avatar_url = fetch_avatar_url($rep_user['userid']);
$avatar = $avatar_url[0];

if (!$avatar)
{
$avatar = $vbulletin->stylevars['imgdir_misc']['imagedir'] . '/unknown.gif';
}

$output .= '<div style="margin: 5px 0;"><img src="' . $avatar . '" style="vertical-align: middle; width: 40px; height: 40px; margin-right: 0.25em" />' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</div>';
$rcount++;
}

$output .= '</div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

Hey Mark,

because of this error:

[20-Oct-2017 23:56:54 Europe/Rome] PHP Fatal error: Call to undefined function fetch_avatar_url() in /home/interfan/public_html/forum/includes/block/html.php(95) : eval()'d code on line 17

the forum crashes and was not available, I had to remove your code

MarkFL
10-20-2017, 09:10 PM
Odd, I've used that function in forum blocks for years on end without any issue on many different sites.

--------------- Added 1508550205 at 1508550205 ---------------

Try this code:

global $vbulletin, $db;
require_once(DIR . '/includes/functions_user.php');
$max = 5;
$output = '<div class="restore">';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid NOT IN (8)
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$avatar_url = fetch_avatar_url($rep_user['userid']);
$avatar = $avatar_url[0];

if (!$avatar)
{
$avatar = $vbulletin->stylevars['imgdir_misc']['imagedir'] . '/unknown.gif';
}

$output .= '<div style="padding: 5px 0; border-bottom: dotted 1px #CCCCCC"><img src="' . $avatar . '" style="vertical-align: middle; width: 40px; height: 40px; margin-right: 0.5em" />' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</div>';
$rcount++;
}

$output .= '</div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

hollyboy
10-21-2017, 02:21 AM
Odd, I've used that function in forum blocks for years on end without any issue on many different sites.

--------------- Added 1508550205 at 1508550205 ---------------

Try this code:

global $vbulletin, $db;
require_once(DIR . '/includes/functions_user.php');
$max = 5;
$output = '<div class="restore">';

$rep_users = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE options & 1024
AND usergroupid NOT IN (8)
ORDER BY reputation DESC
");

$rcount = 0;

while ($rep_user = $db->fetch_array($rep_users) AND $rcount < $max)
{
$avatar_url = fetch_avatar_url($rep_user['userid']);
$avatar = $avatar_url[0];

if (!$avatar)
{
$avatar = $vbulletin->stylevars['imgdir_misc']['imagedir'] . '/unknown.gif';
}

$output .= '<div style="padding: 5px 0; border-bottom: dotted 1px #CCCCCC"><img src="' . $avatar . '" style="vertical-align: middle; width: 40px; height: 40px; margin-right: 0.5em" />' . repuser_link($rep_user) . ': ' . $rep_user['reputation'] . ' Points</div>';
$rcount++;
}

$output .= '</div>';

return $output;

function repuser_link($user)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user['username'];

if ($user['displaygroupid'])
{
$groupid = $user['displaygroupid'];
}
else
{
$groupid = $user['usergroupid'];
}

$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
$title = 'Visit ' . $user['username'] . '\'s Profile';
return '<a title="' . $title . '" href="' . $link . '">' . $open_tag . $user['username'] . $close_tag . '</a>';
}

I like the style you added for each row.
Anyway how to disable admins to appear in the list?

I have made a quick mockup, showing the 3 tabs: week, month, all time.

https://vborg.vbsupport.ru/external/2017/10/6.jpg (https://ibb.co/bND8i6)

MarkFL
10-21-2017, 02:35 AM
I like the style you added for each row.
Anyway how to disable admins to appear in the list?

Oops, I changed that on my local dev site...find the line:

AND usergroupid NOT IN (8)

And change it to:

AND usergroupid NOT IN (6,8)

I have made a quick mockup, showing the 3 tabs: week, month, all time...

The tabs/buttons would have to go below the block title...would that be okay?

hollyboy
10-21-2017, 02:36 AM
The tabs/buttons would have to go below the block title...would that be okay?

yes that's perfect man!

MarkFL
10-25-2017, 02:12 PM
I have created a product that you can now install, and which I have attached. :)

First, delete the previous forum block that you created. Then download and import the attached .XML file. The new forum block will be auto-created. Then visit the product settings to configure the settings to your preferences.

Let me know if there are any issues, or changes you would like. :D

hollyboy
10-25-2017, 02:18 PM
I have created a product that you can now install, and which I have attached. :)

First, delete the previous forum block that you created. Then download and import the attached .XML file. The new forum block will be auto-created. Then visit the product settings to configure the settings to your preferences.

Let me know if there are any issues, or changes you would like. :D

love it: http://www.interfans.org/forum/index.php

- can we set the order in the settings for the tabs: week, month, all time
- the list seems pretty much the same in all 3 tabs

MarkFL
10-25-2017, 02:25 PM
- can we set the order in the settings for the tabs: week, month, all time

At present, the order is hard-coded in the custom template. I chose to go from the greatest period of time to the smallest. :)

- the list seems pretty much the same in all 3 tabs

That depends on what's in your database, that is, on your user's reputation activity. :)

hollyboy
10-25-2017, 02:27 PM
That depends on what's in your database, that is, on your user's reputation activity. :)

the points for the week tab I think are too high in comparison to all time

--------------- Added 1508949583 at 1508949583 ---------------

Oh maybe because I've introduced the REP feature last 2 weeks so there is no much history yet

MarkFL
10-25-2017, 02:41 PM
the points for the week tab I think are too high in comparison to all time

--------------- Added 1508949583 at 1508949583 ---------------

Oh maybe because I've introduced the REP feature last 2 weeks so there is no much history yet

Yes, if your users just recently started giving reps, then the lists would be very similar. Over time that will change.

MarkFL
10-25-2017, 05:41 PM
I've attached a .ZIP file containing instructions and a description. The include .XML file is more robust, and uses phrasing/stylevars to allow you to customize more fully.

Before installing this update, please uninstall the previous product. :)