1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Add-on: Most Liked Online Now

Discussion in 'Add-on Releases [Archive]' started by calorie, Oct 12, 2010.

  1. calorie

    calorie Active Member

    Show who is most liked of the members that are online now. Looks like this...

    most_liked_online_now.gif

    There are two ways to apply this add-on. First is to download the attached ZIP and follow the directions in the README file inside the ZIP archive. Alternatively, you can apply the add-on using the following instructions. Do not do both. Pick one way or the other. If you pick the ZIP, then you do not need to make manual edits (no phrase, template, or PHP file edits) but note that a new template called forum_list_most_liked_online_now is used instead of the default forum_list template.


    So if you are a manual edit sort of person, this is what needs to be added/edited...
    • 1 phrase to add
    • 1 template to edit
    • 1 PHP file to edit (two spots)
    Phrase...

    Add title most_liked_online_now with Most Liked Online Now phrase text.

    Template...

    Edit the forum_list template. Find:

    Code:
        <xen:include template="sidebar_online_users" />
    

    After add:

    Code:
        <xen:if is="{$likedvisitors}">
            <xen:require css="member_list.css" />
            <div class="section staffOnline avatarList">
                <div class="secondaryContent">
                    <h3>{xen:phrase most_liked_online_now}</h3>
                    <ul>
                        <xen:foreach loop="$likedvisitors" value="$user">
                            <li>
                                <xen:avatar user="$user" size="s" img="true" />
                                <a href="{xen:link members, $user}" class="username">{xen:helper richUserName, $user}</a>
                                <div class="muted">{xen:phrase likes}: {xen:raw $user.like_count}</div>
                                <div class="muted">{xen:helper userTitle, $user}</div>
                            </li>
                        </xen:foreach>
                    </ul>
                </div>
            </div>
        </xen:if>
    

    PHP file...

    Edit the /library/XenForo/ControllerPublic/Index.php file. Find:

    Code:
            $onlineUsers = $sessionModel->getSessionActivityQuickList(
                $visitor->toArray(),
                array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
                ($visitor['user_id'] ? $visitor->toArray() : null)
            );
    

    After add:

    Code:
            $likedVisitors = array();
    
            if (!empty($onlineUsers))
            {
                $tempArray = array();
                $tempCount = 0;
    
                foreach ($onlineUsers['records'] AS $uniqueKey => $visitorInfo)
                {
                    if ($visitorInfo['visible'] == 1 && $visitorInfo['like_count'] > 0)
                    {
                        $tempArray[$uniqueKey] = $visitorInfo['like_count'];
                    }
                }
    
                arsort($tempArray); // keys in descending order of likes
    
                foreach ($tempArray AS $uniqueKey => $likeCount)
                {
                    if ($tempCount == 5) // how many to show
                    {
                        break;
                    }
    
                    $likedVisitors[$uniqueKey] = $onlineUsers['records'][$uniqueKey];
                    $tempCount ++;
                }
    
                unset($tempArray);
            }
    

    Also find:

    Code:
            $viewParams = array(
                'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay(false, 0),
                'onlineUsers' => $onlineUsers,
                'boardTotals' => $boardTotals
            );
    

    Replace with:

    Code:
            $viewParams = array(
                'likedvisitors' => $likedVisitors,
                'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay(false, 0),
                'onlineUsers' => $onlineUsers,
                'boardTotals' => $boardTotals
            );
    
     

    Attached Files:

    CerbCorp, shenmuee, Steve F and 5 others like this.
  2. glorify

    glorify Well-Known Member

    Pretty sweet calorie. :)
     
  3. ArnyVee

    ArnyVee Well-Known Member

    Nice, I like anything that spiffs up the sidebar ;)

    Thanks for sharing! :D
     
  4. Sir nick

    Sir nick Well-Known Member

    Personally I'd move it below staff; As it seems a bit off because of the members list.
     
  5. ArnyVee

    ArnyVee Well-Known Member

    It is below staff and members online.
     
  6. Sir nick

    Sir nick Well-Known Member

    I don't think you understood my post; I'd move it below staff online, but above members currently online.
     
  7. calorie

    calorie Active Member

    If you want it above members online now, just add the forum_list template edit above the following instead of below:
    Code:
        <xen:include template="sidebar_online_users" />
    
    Note though that you may need to also edit the sidebar_online_users template too to get the look you want.
     
    ArnyVee likes this.
  8. ArnyVee

    ArnyVee Well-Known Member

    Ah, now I see what you mean. Hmm...I can see because of the size of the thumbnails that it kinda throws off the cohesive 'look' of the sidebar a bit.

    It may make sense to put the "most liked" (people that participate the most or have the best things to share on the site) in a prominent spot in the sidebar. Good point.
     
  9. ArnyVee

    ArnyVee Well-Known Member

    How can we exclude certain usergroups (like admins and/or mods) from being on the "liked" list?

    I'd want to reward or give props to those members and supporters of the site more than the staff.
     
  10. dutchbb

    dutchbb Well-Known Member

    Thanks for taking the time to write this. Nice to see all these familiar faces getting more active here btw :)
     
  11. Indigo

    Indigo Active Member

    Nice work. :)

    Suggestion to remove the PHP file edits: Extend the XenForo_ControllerPublic_Index class like so (rename the first part of the class if you'd like):

    PHP:
    class MostLikedOnline_ControllerPublic_Index extends XFCP_MostLikedOnline_ControllerPublic_Index
    {
        public function 
    actionIndex()
        {
            
    $response parent::actionIndex(); // $response is a XenForo_ControllerResponse_View
            
    $onlineUsers $response->params['onlineUsers'];
            
    // your code...

            
    $response->params['likedvisitors'] = $likedVisitors;
            return 
    $response;
        }
    }
    Then use a load_class_controller event listener to make XF use your new class.
     
    dutchbb likes this.
  12. calorie

    calorie Active Member

    In the PHP file edit find:

    Code:
                    if ($visitorInfo['visible'] == 1 && $visitorInfo['like_count'] > 0)
                    {
                        $tempArray[$uniqueKey] = $visitorInfo['like_count'];
                    }
    

    And before add:

    Code:
                    $tempGroups = explode(',', $visitorInfo['secondary_group_ids']);
    
                    if (
                        in_array($visitorInfo['user_group_id'], array(3, 4))
                            ||
                        in_array(3, $tempGroups) || in_array(4, $tempGroups)
                    )
                    {
                        continue;
                    }
    
    Untested but should remove admins and mods from the list.
     
    ArnyVee likes this.
  13. calorie

    calorie Active Member

    Thanks, might do this when more free time presents itself. :)
     
  14. Anthony Parsons

    Anthony Parsons Well-Known Member

    Nice... I will come back to this when it doesn't require a default file edit.
     
  15. calorie

    calorie Active Member

    FYI... Manual edits be gone. ZIP attached to first post. Thanks again to Indigo for the XFCP_x suggestion. :)
     
    ArnyVee likes this.
  16. ArnyVee

    ArnyVee Well-Known Member

    This is great! :)

    By the way, I noticed that you state about having to log into the forum as a regular user to view the sidebar item. Can we not view it as an admin or mod at all?
     
  17. Elizabeth

    Elizabeth Well-Known Member

    What you can do is make a copy of your default, name it something else and make it default and put your edits there. That way you don't edit the core template.
     
    Anthony Parsons likes this.
  18. Perspektif

    Perspektif Active Member

    same...
    How do make
    members of following?
     
  19. Crazyfruitbat

    Crazyfruitbat Well-Known Member

    Yeah probably same here. looks good though
     

Share This Page