forked from Frug/AJAX-Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Phpbb3 display online chat users
Philip Nicolcev edited this page Jul 8, 2013
·
2 revisions
In includes/functions.php
Add
// AJAX chat user count integration
function getChatInterface() {
static $ajaxChat;
global $phpEx, $phpbb_root_path;
static $ajaxChat;
if (!$ajaxChat) {
// URL to the chat directory:
if (!defined('AJAX_CHAT_URL')) {
define('AJAX_CHAT_URL', $phpbb_root_path . 'chat/');
}
// Path to the chat directory:
if (!defined('AJAX_CHAT_PATH')) {
if (empty($_SERVER['SCRIPT_FILENAME'])) {
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].$_SERVER['SCRIPT_URL'];
}
define('AJAX_CHAT_PATH', realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/chat').'/');
}
// Validate the path to the chat:
if (@is_file(AJAX_CHAT_PATH.'lib/classes.'.$phpEx)) {
// Include Class libraries:
require_once(AJAX_CHAT_PATH.'lib/classes.'.$phpEx);
// Initialize the chat interface:
$ajaxChat = new CustomAJAXChatInterface();
}
}
return $ajaxChat;
}
function getChatOnlineUsers() {
$chatInterface = getChatInterface();
if($chatInterface) {
// Clean out any users who didn't log out properly by calling removeInactive()
// Not necessary but a good idea. You can take out this line if you want.
$chatInterface->removeInactive();
// Now get the online users:
return $chatInterface->getOnlineUsers();
}
else {
return array();
}
}
function getChatOnlineUserIDs() {
return ($chatInterface = getChatInterface()) ? $chatInterface->getOnlineUserIDs() : array();
}
at the end of the file, before
?>
Add
if(in_array($row['user_id'], getChatOnlineUserIDs()))
{
$user_online_link = '<span title="* = '.strip_tags($row['username']).' is logged into the Chat">'.$user_online_link.'*</span>';
}
before
$online_userlist .= ($online_userlist != '') ? ', ' . $user_online_link : $user_online_link;
Add
'CHAT_LINK' => append_sid("{$phpbb_root_path}chat/index.$phpEx"),
'CHAT_LABEL' => 'Chat ['.count(getChatOnlineUserIDs()).']',
'CHAT_TITLE' => 'Online: '.htmlentities(implode(', ', getChatOnlineUsers()), ENT_QUOTES, 'UTF-8'),
after
// The following assigns all _common_ variables that may be used at any point in a template.
$template->assign_vars(array(
In styles/[STYLE_NAME]/template/overall_header.html
Add
<li class="icon-chat"><a href="{CHAT_LINK}" title="{CHAT_TITLE}">{CHAT_LABEL}</a></li>
before
<li class="icon-faq"><a href="{U_FAQ}" title="{L_FAQ_EXPLAIN}">{L_FAQ}</a></li>
Note:
Don't forget to refresh your template cache.