Warning: The author of this contribution does not provide support for it anymore.

Top Five

If a user is banned - Top Five

If a user is banned

by avixansa » Tue Jan 11, 2011 3:03 pm

Hi ,
If i bann a user who has the top posts in top 5 mod
It still displays the username in top 5 stats of a banned user..
what to modify so that if a user in top 5 is banned does not gets displayed in this stats box ?

Cheers
avixansa
Registered User
Posts: 7
Joined: Fri Aug 13, 2010 1:22 pm
Contact:

Re: If a user is banned

by RMcGirr83 » Tue Jan 11, 2011 4:10 pm

Try

OPEN

includes/top_five.php

FIND

Code: Select all

   // top five posters
   // an array of user types we dont' bother with
   // could add board founder (USER_FOUNDER) if wanted
   $ignore_users = array(USER_IGNORE, USER_INACTIVE);
   
   if (($user_posts = $cache->get('_top_five_posters')) === false)
   {
       $user_posts = array();

      // grab users with most posts
       $sql = 'SELECT user_id, username, user_colour, user_posts
             FROM ' . USERS_TABLE . '
         WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
            AND user_posts <> 0
          ORDER BY user_posts DESC';
      $result = $db->sql_query_limit($sql, 5);


REPLACE WITH

Code: Select all

   // top five posters
   // an array of user types we dont' bother with
   // could add board founder (USER_FOUNDER) if wanted
   $ignore_users = array(USER_IGNORE, USER_INACTIVE);
   
   // we want banned users?
   // make an array and cache it for 5 minutes to reduce sql load
   if (($ban_ary = $cache->get('_banned_users')) === false)
   {
      $ban_ary = array();
      $sql = 'SELECT ban_userid
            FROM ' . BANLIST_TABLE . '
            WHERE ban_userid > 1
            AND (ban_end >= ' . time() . ' OR ban_end = 0)';
      $result = $db->sql_query($sql);
      
      while($row = $db->sql_fetchrow($result))
      {
         $ban_ary[] = $row['ban_userid'];
      }
      $db->sql_freeresult($result);
            
      // cache this data for 5 minutes, this improves performance
      // could change 300 to a higher number if wanted longer cache
      $cache->put('_banned_users', $ban_ary, 300);
   }
   
   $sql_and = sizeof($ban_ary) ? 'AND ' . $db->sql_in_set('user_id', $ban_ary, true) : '';
   
   if (($user_posts = $cache->get('_top_five_posters')) === false)
   {
       $user_posts = array();

      // grab users with most posts
       $sql = 'SELECT user_id, username, user_colour, user_posts
             FROM ' . USERS_TABLE . '
         WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
            AND user_posts <> 0
         ' . $sql_and . '
          ORDER BY user_posts DESC';
      $result = $db->sql_query_limit($sql, 5);


..and please remember the top five posters are cached for 5 minutes so it will not be an immediate effect until the cache is purged or the file made in the cache is older than five minutes.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: If a user is banned

by Theriddler1 » Sat Dec 21, 2013 9:46 pm

i did the fix for 'wrong order' you placed at github and then tried to put back the banned code
but unfortunately it doesn't seem to work anymore.

appreciate your help
Theriddler - Former Moderator @ phpBB.nl | phpBBservice.nl Team-member
Image My Extensions | buy me a beer Image
User avatar
Theriddler1
Registered User
Posts: 451
Joined: Sat Aug 27, 2011 11:00 pm
Location: NL
Name: Theriddler❶
Contact:

Re: If a user is banned

by RMcGirr83 » Sun Dec 22, 2013 11:00 am

There is no reason as to why it wouldn't work...the fix order thingy has nothing to do with banned users.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: If a user is banned

by Theriddler1 » Sun Dec 22, 2013 11:25 am

Thank you for your reply,

first i thought it had something to do with this line:

Code: Select all

$sql_and = sizeof($ban_ary) ? 'AND ' . $db->sql_in_set('user_id', $ban_ary, true) : '';


because the main sql thingy selects u.user_id

Code: Select all

// do the main sql query
                $sql_ary = array(
                 'SELECT' => 'u.user_id, u.username, u.user_colour, u.user_posts',


but after changing it to ('u.user_id', didn't work

maybe there's something wrong within the code:

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id:
* @copyright (c) 2010 Rich McGirr
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
   exit;
}

/**
* Include only once.
*/
if (!defined('INCLUDES_TOP_FIVE_PHP'))
{
   define('INCLUDES_TOP_FIVE_PHP', true);
   
   global $auth, $cache, $user, $db, $phpbb_root_path, $phpEx, $template, $config;

 $user->add_lang('mods/top_five');
        $how_many = 5; //change this number if you want more or less to display
        $forum_ary = array();
        $forum_read_ary = $auth->acl_getf('f_read');
       
        foreach ($forum_read_ary as $forum_id => $allowed)
        {
                if ($allowed['f_read'])
                {
                        $forum_ary[] = (int) $forum_id;
                }
        }
        $forum_ary = array_unique($forum_ary);

        if (sizeof($forum_ary))
        {
                /**
                * Select topic_ids
                */
                $sql = 'SELECT forum_id, topic_id, topic_type
                        FROM ' . TOPICS_TABLE . '
                        WHERE ' . $db->sql_in_set('forum_id', $forum_ary) . '
                        ORDER BY topic_last_post_time DESC';
                       
                $result = $db->sql_query_limit($sql, $how_many);
                $forums = $ga_topic_ids = $topic_ids = array();
                while ($row = $db->sql_fetchrow($result))
                {
                        $topic_ids[] = $row['topic_id'];
                        if ($row['topic_type'] == POST_GLOBAL)
                        {
                                $ga_topic_ids[] = $row['topic_id'];
                        }
                        else
                        {
                                $forums[$row['forum_id']][] = $row['topic_id'];
                        }
                }
                $db->sql_freeresult($result);

                // Get topic tracking
                $topic_ids_ary = $topic_ids;
                $topic_tracking_info = array();
                foreach ($forums as $forum_id => $topic_ids)
                {
                        $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $topic_ids, $ga_topic_ids);
                }
                $topic_ids = $topic_ids_ary;
                unset($topic_ids_ary);
                               
                // grab all posts that meet criteria and auths
                $sql_ary = array(
                        'SELECT'        => 'u.user_id, u.username, u.user_colour, t.topic_title, t.forum_id, t.topic_id, t.topic_last_post_id, t.topic_last_post_time, t.topic_last_poster_name, p.post_text',
                        'FROM'                => array(TOPICS_TABLE => 't'),
                        'LEFT_JOIN'        => array(
                                array(
                                        'FROM'        => array(USERS_TABLE => 'u'),
                                        'ON'        => 't.topic_last_poster_id = u.user_id',
                                ),
                                array(
                                        'FROM'        => array(POSTS_TABLE => 'p'),
                                        'ON'        => 'p.post_id = t.topic_last_post_id',
                                ),                       
                        ),
                        'WHERE'                => $db->sql_in_set('t.topic_id', $topic_ids),
                        'ORDER_BY'        => 't.topic_last_post_time DESC',
                );

   // BEGIN Topic Preview Mod
   if ($config['topic_preview_limit'] && $user->data['user_topic_preview'])
   {
      $sql_ary['LEFT_JOIN'][] = array('FROM' => array(POSTS_TABLE => 'pt'), 'ON' => 'pt.post_id = t.topic_first_post_id');
      $sql_ary['SELECT'] .= ', pt.post_text AS first_post_preview_text';
   }
   // END Topic Preview Mod
   $result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), $how_many);
     while( $row = $db->sql_fetchrow($result) )
     {
   // BEGIN Topic Preview Mod
      if (!empty($row['first_post_preview_text']))
      {
         if(!function_exists('trim_topic_preview'))
         {
            include($phpbb_root_path . 'includes/topic_preview.' . $phpEx);
         }
         $first_post_preview_text = trim_topic_preview($row['first_post_preview_text'], $config['topic_preview_limit']);
      }
      // END Topic Preview Mod
      $topic_id = $row['topic_id'];
                        $forum_id = $row['forum_id'];
                       
                        $post_unread = (isset($topic_tracking_info[$forum_id][$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$topic_id]) ? true : false;
                        $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']);
                        $topic_title = censor_text($row['topic_title']);
                        if (utf8_strlen($topic_title) >= 60)
                        {
                                $topic_title = (utf8_strlen($topic_title) > 60 + 3) ? utf8_substr($topic_title, 0, 60) . '...' : $topic_title;
                        }
                        $is_guest = $row['user_id'] != ANONYMOUS ? false : true;

                        $template->assign_block_vars('top_five_topic',array(
                                'U_TOPIC'         => $view_topic_url,
                                'MINI_POST_IMG'   => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
                        'TOPIC_PREVIEW_TEXT' => (isset($first_post_preview_text)) ? censor_text($first_post_preview_text) : '',
                                'USERNAME_FULL'      => $is_guest ? $user->lang['POST_BY_AUTHOR'] . ' ' . get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour'], $row['topic_last_poster_name']) : $user->lang['POST_BY_AUTHOR'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
                                'LAST_TOPIC_TIME'    => $user->format_date($row['topic_last_post_time']),
                                'TOPIC_TITLE'        => $topic_title,
                        ));
                }

                $db->sql_freeresult($result);
          }
        else
        {
                $template->assign_block_vars('top_five_topic', array(
                        'NO_TOPIC_TITLE'        => $user->lang['NO_TOPIC_EXIST'],
                ));
        }
        // top five posters
        // an array of user types we dont' bother with
        // could add board founder (USER_FOUNDER) if wanted
        $ignore_users = array(USER_IGNORE, USER_INACTIVE);
       
       // we want banned users?
       // make an array and cache it for 5 minutes to reduce sql load
       if (($ban_ary = $cache->get('_banned_users')) === false)
       {
          $ban_ary = array();
          $sql = 'SELECT ban_userid
                FROM ' . BANLIST_TABLE . '
                WHERE ban_userid > 1
                AND (ban_end >= ' . time() . ' OR ban_end = 0)';
          $result = $db->sql_query($sql);
         
          while($row = $db->sql_fetchrow($result))
          {
             $ban_ary[] = $row['ban_userid'];
          }
          $db->sql_freeresult($result);
               
          // cache this data for 5 minutes, this improves performance
          // could change 300 to a higher number if wanted longer cache
          $cache->put('_banned_users', $ban_ary, 300);
       }
       
       $sql_and = sizeof($ban_ary) ? 'AND ' . $db->sql_in_set('user_id', $ban_ary, true) : '';
       
       // top five posters
        if (($user_posts = $cache->get('_top_five_posters')) === false)
        {
                $user_posts = $admin_mod_array = array();
                // quick check for forum moderators and administrators
                // some may not want to show them
                $not_show_admins_mods = true; //change false to true to have moderators and administrators not shown in top five posters

                $sql_and = '';
                if ($not_show_admins_mods)
                {
                        // grab all admins
                        $admin_ary = $auth->acl_get_list(false, 'a_', false);
                        $admin_ary = (!empty($admin_ary[0]['a_'])) ? $admin_ary[0]['a_'] : array();
                       
                        //grab all mods
                        $mod_ary = $auth->acl_get_list(false,'m_', false);
                        $mod_ary = (!empty($mod_ary[0]['m_'])) ? $mod_ary[0]['m_'] : array();
                        $admin_mod_array = array_unique(array_merge($admin_ary,$mod_ary));
                       
                        if(sizeof($admin_mod_array))
                        {
                                $sql_and = ' AND ' . $db->sql_in_set('u.user_id', $admin_mod_array, true);
                        }
                }

                // do the main sql query
                $sql_ary = array(
                 'SELECT' => 'u.user_id, u.username, u.user_colour, u.user_posts',
                 'FROM' => array(USERS_TABLE => 'u'),
                 'WHERE' => $db->sql_in_set('u.user_type', $ignore_users, true) . ' ' . $sql_and . '
                         AND u.user_posts <> 0',
                 'ORDER_BY' => 'u.user_posts DESC',
                );
                $result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), $how_many);
                while ($row = $db->sql_fetchrow($result))
                {
                        $user_posts[$row['user_id']] = array(
                                'user_id' => $row['user_id'],
                                'username' => $row['username'],
                                'user_colour' => $row['user_colour'],
                                'user_posts' => $row['user_posts'],
                        );
                }
                $db->sql_freeresult($result);

                // cache this data for 5 minutes, this improves performance
                $cache->put('_top_five_posters', $user_posts, 300);
      }

        foreach ($user_posts as $row)
        {
                $username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);

                $template->assign_block_vars('top_five_active',array(
                        'S_SEARCH_ACTION'        => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $row['user_id'] . '&amp;sr=posts'),
                        'POSTS'                         => number_format($row['user_posts']),
                        'USERNAME_FULL'                => $username_string,
                ));
    }

    // newest registered users
        if (($newest_users = $cache->get('_top_five_newest_users')) === false)
        {
         $newest_users = array();

         // grab most recent registered users
                $sql = 'SELECT user_id, username, user_colour, user_regdate
                        FROM ' . USERS_TABLE . '
                        WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
                                AND user_inactive_reason = 0
                        ORDER BY user_regdate DESC';
                $result = $db->sql_query_limit($sql, $how_many);

                while ($row = $db->sql_fetchrow($result))
                {
                        $newest_users[$row['user_id']] = array(
                                'user_id'                                => $row['user_id'],
                                'username'                                => $row['username'],
                             'user_colour'                        => $row['user_colour'],
                'user_regdate'                        => $row['user_regdate'],
                        );
                }
         $db->sql_freeresult($result);

                // cache this data for ever, cache is purged when adding or deleting users
                $cache->put('_top_five_newest_users', $newest_users);
        }

   foreach ($newest_users as $row)
        {
                $username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);

                $template->assign_block_vars('top_five_newest',array(
                        'REG_DATE'                        => $user->format_date($row['user_regdate']),
                        'USERNAME_FULL'                => $username_string,
                ));
        }
       // phpBB ajax like Add-on
       $sql_array = array(
          'SELECT'    => 'COUNT(l.poster_id) as user_likes, u.user_id, u.username, u.user_colour',

          'FROM'      => array(
             LIKES_TABLE => 'l',
             USERS_TABLE    => 'u'
          ),

          'WHERE'     =>  'l.poster_id = u.user_id',
             
          'GROUP_BY'  => 'l.poster_id',

          'ORDER_BY'  => 'user_likes DESC',
       );
       $sql = $db->sql_build_query('SELECT', $sql_array);
       $result = $db->sql_query_limit($sql, 5);
          while ($row = $db->sql_fetchrow($result))
       {
          $template->assign_block_vars('toplikes', array(
          'LIKECOUNT'      => $row['user_likes'] > 1 ? sprintf($user->lang['USER_LIKES'], $row['user_likes']) : sprintf($user->lang['USER_LIKE'], $row['user_likes']),
          'USERNAME' => $row['username'],
          'USERCOLOUR' => $row['user_colour'],
          'USERLINK' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id'] . ''),
          ));
       }
       $db->sql_freeresult($result);
          // top five online users
       if (!function_exists('get_time_text'))
       {
          include($phpbb_root_path . 'includes/functions_content.' . $phpEx);
       }
       if (($user_online = $cache->get('_top_five_online')) === false)
       {
           $user_online = array();

          $sql = 'SELECT user_id, username, user_colour, user_online_timeformat, user_online_time
             FROM ' . USERS_TABLE . '       
             ORDER BY user_online_time DESC';
          $result = $db->sql_query_limit($sql, 5);
          while ($row = $db->sql_fetchrow($result))
          {
             $user_online[$row['user_id']] = array(
                'user_id'      => $row['user_id'],
             'username'      => $row['username'],
             'user_colour'   => $row['user_colour'],
                'user_online_timeformat'    => $row['user_online_timeformat'],
             'user_online_time'   => $row['user_online_time'],
             );
          }
          $db->sql_freeresult($result);         

          // cache this data for 5 minutes, this improves performance
          $cache->put('_top_five_online', $user_online, 300);
        }

        foreach ($user_online as $row)
        {
          $username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);

          $template->assign_block_vars('top_five_online',array(
             'USER_ONLINE_TIME'      => get_time_text($row['user_online_time'], $row['user_online_timeformat']),
             'USERNAME_FULL'      => $username_string)
          );
        }
}
?>
Theriddler - Former Moderator @ phpBB.nl | phpBBservice.nl Team-member
Image My Extensions | buy me a beer Image
User avatar
Theriddler1
Registered User
Posts: 451
Joined: Sat Aug 27, 2011 11:00 pm
Location: NL
Name: Theriddler❶
Contact:

Re: If a user is banned

by RMcGirr83 » Sun Dec 22, 2013 11:39 am

Code: Select all

       $sql_and = sizeof($ban_ary) ? 'AND ' . $db->sql_in_set('user_id', $ban_ary, true) : '';
       
       // top five posters
        if (($user_posts = $cache->get('_top_five_posters')) === false)
        {
                $user_posts = $admin_mod_array = array();
                // quick check for forum moderators and administrators
                // some may not want to show them
                $not_show_admins_mods = true; //change false to true to have moderators and administrators not shown in top five posters

                $sql_and = '';
                if ($not_show_admins_mods)
                {
                        // grab all admins
                        $admin_ary = $auth->acl_get_list(false, 'a_', false);
                        $admin_ary = (!empty($admin_ary[0]['a_'])) ? $admin_ary[0]['a_'] : array();
                       
                        //grab all mods
                        $mod_ary = $auth->acl_get_list(false,'m_', false);
                        $mod_ary = (!empty($mod_ary[0]['m_'])) ? $mod_ary[0]['m_'] : array();
                        $admin_mod_array = array_unique(array_merge($admin_ary,$mod_ary));
                       
                        if(sizeof($admin_mod_array))
                        {
                                $sql_and = ' AND ' . $db->sql_in_set('u.user_id', $admin_mod_array, true);
                        }
                }


you are overwriting the banned users array as you don't want admins and mods to display.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: If a user is banned

by Theriddler1 » Sun Dec 22, 2013 12:09 pm

tried it to switch to false to show admins and mods but still the banned member showed up

when changed the code to this it seems to work but only if i set it to not show admin and mods.

maybe there's a better way to do this

Code: Select all

// we want banned users?
       // make an array and cache it for 5 minutes to reduce sql load
       if (($ban_ary = $cache->get('_banned_users')) === false)
       {
          $ban_ary = array();
          $sql = 'SELECT ban_userid
                FROM ' . BANLIST_TABLE . '
                WHERE ban_userid <> 0
                AND (ban_end >= ' . time() . ' OR ban_end = 0)';
          $result = $db->sql_query($sql);
         
          while($row = $db->sql_fetchrow($result))
          {
             $ban_ary[] = $row['ban_userid'];
          }
          $db->sql_freeresult($result);
               
          // cache this data for 5 minutes, this improves performance
          // could change 300 to a higher number if wanted longer cache
          $cache->put('_banned_users', $ban_ary, 300);
       }
       
       // top five posters
        if (($user_posts = $cache->get('_top_five_posters')) === false)
        {
                $user_posts = $admin_mod_array = array();
                // quick check for forum moderators and administrators
                // some may not want to show them
                $not_show_admins_mods = true; //change false to true to have moderators and administrators not shown in top five posters

                $sql_and = '';
                if ($not_show_admins_mods)
                {
                        // grab all admins
                        $admin_ary = $auth->acl_get_list(false, 'a_', false);
                        $admin_ary = (!empty($admin_ary[0]['a_'])) ? $admin_ary[0]['a_'] : array();
                       
                        //grab all mods
                        $mod_ary = $auth->acl_get_list(false,'m_', false);
                        $mod_ary = (!empty($mod_ary[0]['m_'])) ? $mod_ary[0]['m_'] : array();
                        $admin_mod_array = array_unique(array_merge($admin_ary,$mod_ary,$ban_ary));
                       
                        if(sizeof($admin_mod_array))
                        {
                                $sql_and = ' AND ' . $db->sql_in_set('u.user_id', $admin_mod_array, $ban_ary, true);
                        }
                }
Theriddler - Former Moderator @ phpBB.nl | phpBBservice.nl Team-member
Image My Extensions | buy me a beer Image
User avatar
Theriddler1
Registered User
Posts: 451
Joined: Sat Aug 27, 2011 11:00 pm
Location: NL
Name: Theriddler❶
Contact:

Re: If a user is banned

by RMcGirr83 » Sun Dec 22, 2013 12:26 pm

Try the attached

top_five.zip
(2.87 KiB) Downloaded 185 times


and if you like the support
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: If a user is banned

by Theriddler1 » Sun Dec 22, 2013 12:58 pm

thank you so much, this works great

as for the support i currently don't have money to do so :oops: but i do added a backlink to your site on our footer.

thank you for your help, much appreciated

Edit:

when both options set on true

Code: Select all

$not_show_admins_mods = true; //change false to true to have moderators and administrators not shown in top five posters
            $not_show_banned_users = true; //change false to true to not have banned users display


then banned users were back in the list i think because it overwrites the sql_and

when added a second sql_and2 it works

Code: Select all

$sql_and = '';
            $sql_and2 = '';


Code: Select all

$sql_and2 = ' AND ' . $db->sql_in_set('u.user_id', $banned_users, true);


Code: Select all

'WHERE' => $db->sql_in_set('u.user_type', $ignore_users, true) . ' ' . $sql_and . $sql_and2 . '
Theriddler - Former Moderator @ phpBB.nl | phpBBservice.nl Team-member
Image My Extensions | buy me a beer Image
User avatar
Theriddler1
Registered User
Posts: 451
Joined: Sat Aug 27, 2011 11:00 pm
Location: NL
Name: Theriddler❶
Contact: