• 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

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
        );
 

Attachments

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.
 
I don't think you understood my post; I'd move it below staff online, but above members currently online.

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.
 
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.
 
Thanks for taking the time to write this. Nice to see all these familiar faces getting more active here btw :)
 
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.
 
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.

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.
 
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.

Thanks, might do this when more free time presents itself. :)
 
FYI... Manual edits be gone. ZIP attached to first post. Thanks again to Indigo for the XFCP_x suggestion. :)

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?
 
Top Bottom