Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Chat online users

+5 votes
417 views
asked Jul 14, 2014 in Plugins by anonymous
edited Jul 14, 2014
I chat https://github.com/svivian/q2a-chat-room

How to create. How can I see the main page of the website how many online users now in chat? THX

show the number of users to chat on my home page

1 Answer

+2 votes
answered Jul 14, 2014 by q2apro

You use the advanced theme for that. File: qa-theme.php

There you insert:

        function sidepanel() {

    // requires CHAT plugin
    // output Chat-Button only on startpage (main page) + questions list page + liveticker
    if ($this->template=='qa' || $this->template=='questions' || $this->template=='question' || $this->request=='liveticker' ) {
        // get number of online users
        $countActiveUsers = qa_db_read_one_value( qa_db_query_sub( 'SELECT COUNT(*)
                FROM ^users u, ^chat_users c
                WHERE u.userid=c.userid AND c.lastpolled > DATE_SUB(NOW(), INTERVAL 1 MINUTE)' ) );
        
        // logged in see directly who is online
        $onlineUsernames = '';
        if(qa_is_logged_in()) {
            $queryUserNames = qa_db_query_sub( 'SELECT u.userid, u.handle AS username
                    FROM ^users u, ^chat_users c
                    WHERE u.userid=c.userid AND c.lastpolled > DATE_SUB(NOW(), INTERVAL 1 MINUTE)
                    ORDER BY u.handle');
            while ( ($row = qa_db_read_one_assoc($queryUserNames,true)) !== null ) {
                // first
                if($onlineUsernames=='') {
                    $onlineUsernames .= $row['username']; // 'Es unterhalten sich:<br />'
                }
                else {
                    $onlineUsernames .= ', '.$row['username'];
                }
            }
            $onlineUsernames = 'title="Online: '.$onlineUsernames.'"';
        }
        else {
            $onlineUsernames = 'title="Only registered users can join the chat"';
        }
        
        if($countActiveUsers>0) {
            $this->output('<a '.$onlineUsernames.' class="btnyellow oranged" style="margin-top:10px;" href="'.qa_opt('site_url').'chat" target="_blank">Chat ('.$countActiveUsers.')</a>');
        }
        else {
            $this->output('<a class="btnyellow oranged" style="margin-top:10px;" href="'.qa_opt('site_url').'chat" target="_blank">Community-Chat</a>');
        }
    }

qa_html_theme_base::sidepanel();

}

Demo: http://www.gute-mathe-fragen.de/136492/14-tage-biken-fur-mathe-tag-9 (top right)

...