Topusers function

The top users function built in to Pligg has been something I have neglected since installing Pligg. For the most part because it seemed to just display a list of all members alphabetically.

Today I took a look at the file topusers.php to see what it was using as a query, I wanted to change the output so it showed “top users” as the title suggests.

Sometimes it pays to browse the files of Pligg, the topusers.php files has 6 options for the output:

  • sort users alphabetically
  • sort users by number of submitted links
  • sort users by number of published links
  • sort users by number of comments
  • sort users by number of votes
  • sort users by number of published votes

By default, it is set to the first option, most Pligg installs you visit will have this set for the output. The first option really isn’t something that should be in the topusers.php file, as it only list all of your members.

I would set the option to either #1 or #5, this will show a more accurate picture of your top members.

In your root folder open topusers.php, find this section:

// determine how to sort users
if(isset($_GET['sortby'])){
        $sortby = $_GET['sortby'];}
else{
        $sortby = "0";}
       
// make sure sorting option is between 0 and 5 
if(intval($sortby) < 0 || intval($sortby) > 5)
        $sortby = 0;
else $sortby = intval($sortby);

switch ($sortby) {
        case 0: // sort users alphabetically
                $select = "SELECT user_id";
                $from_where = " FROM " . table_users . " where user_level<>’god’";
                $order_by = " ORDER BY user_login ";
                break;
        case 1: // sort users by number of submitted linkd
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_links . ", " . table_users . " WHERE  link_status != ‘discard’ AND link_author=user_id AND user_level<>’god’ GROUP BY link_author";
                $order_by = " ORDER BY count DESC ";
                break;
        case 2: // sort users by number of published links
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_links . ", " . table_users . " WHERE  link_status = ‘published’ AND link_author=user_id AND user_level<>’god’ GROUP BY link_author";
                $order_by = " ORDER BY count DESC ";
                break;
        case 3: //sort users by number of comments
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_comments . ", " . table_users . " WHERE comment_user_id=user_id AND user_level<>’god’ GROUP BY comment_user_id";
                $order_by = " ORDER BY count DESC ";
                break;
        case 4: //sort users by number of votes
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_votes . ", " . table_users . " WHERE vote_user_id=user_id AND user_level<>’god’ GROUP BY vote_user_id";
                $order_by = " ORDER BY count DESC ";
                break;
        case 5: // sort users by number of published votes
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_votes . ", " . table_users . ", " . table_links . " WHERE vote_user_id=user_id AND link_id=vote_link_id AND link_status=’published’ AND vote_date < link_published_date AND user_level<>’god’ GROUP BY user_id";
                $order_by = " ORDER BY count DESC ";
                break;
}
 

I have changed my to #5, so mine now looks like:

// determine how to sort users
if(isset($_GET['5'])){
        $sortby = $_GET['5'];}
else{
        $sortby = "5";}
       
// make sure sorting option is between 0 and 5 
if(intval($sortby) < 0 || intval($sortby) > 5)
        $sortby = 5;
else $sortby = intval($sortby);

switch ($sortby) {
        case 0: // sort users alphabetically
                $select = "SELECT user_id";
                $from_where = " FROM " . table_users . " where user_level<>’god’";
                $order_by = " ORDER BY user_login ";
                break;
        case 1: // sort users by number of submitted linkd
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_links . ", " . table_users . " WHERE  link_status != ‘discard’ AND

link_author=user_id AND user_level<>’god’ GROUP BY link_author";
                $order_by = " ORDER BY count DESC ";
                break;
        case 2: // sort users by number of published links
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_links . ", " . table_users . " WHERE  link_status = ‘published’ AND

link_author=user_id AND user_level<>’god’ GROUP BY link_author";
                $order_by = " ORDER BY count DESC ";
                break;
        case 3: //sort users by number of comments
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_comments . ", " . table_users . " WHERE comment_user_id=user_id AND

user_level<>’god’ GROUP BY comment_user_id";
                $order_by = " ORDER BY count DESC ";
                break;
        case 4: //sort users by number of votes
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_votes . ", " . table_users . " WHERE vote_user_id=user_id AND user_level<>’god’

GROUP BY vote_user_id";
                $order_by = " ORDER BY count DESC ";
                break;
        case 5: // sort users by number of published votes
                $select = "SELECT user_id, count(*) as count ";
                $from_where = " FROM " . table_votes . ", " . table_users . ", " . table_links . " WHERE vote_user_id=user_id AND

link_id=vote_link_id AND link_status=’published’ AND vote_date < link_published_date AND user_level<>’god’ GROUP BY user_id";
                $order_by = " ORDER BY count DESC ";
                break;
}

Example: News Dots Topusers

Something to play around with until you find the right one for you.

Which one are you using?

If you enjoyed this post, make sure you subscribe to my RSS feed!

  • You wrote:

    if(isset($_GET[‘5′])){
    $sortby = $_GET[‘5′];}
    else{
    $sortby = "5";}

    in my test this broke the ability to sort by other criteria such as 'Published'. Instead I believe the right modification would be this

    if(isset($_GET[‘sortby′])){
    $sortby = $_GET[‘sortby′];}
    else{
    $sortby = "5";}

    This will default to Published votes but allow sorting by other criteria.
blog comments powered by Disqus