* @author Wolverine * @copyright (C) JoomlaHacks.com. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @version $Id: mod_joomla-smf_whos_online.php 6 2006-04-17 12:48:51Z joshualross $ * @revision $LastChangedRevision: 6 $ * @date $LastChangedDate: 2006-04-17 08:48:51 -0400 (Mon, 17 Apr 2006) $ * @file $HeadURL: http://scm.joomla.org/svn/repos/joomla-smf_whos_online/mod_joomla-smf_whos_online.php $ * @link http://www.JoomlaHacks.com * @since File available since Release 1.0 * * Visit JoomlaHacks.com for more Joomla Hacks! */ /** ensure this file is being included by a parent file */ defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); //mosConfig_live_site used for images //1.1.1 added mosConfig_live_site to the globals (-Wolverine) global $mosConfig_live_site, $mosConfig_absolute_path, $database; global $profilelink, $displayrealname, $displaygroupcolor, $liststyle, $pmlink, $smf_tprefix; //1.2 Set defaults for all parameters (-Wolverine) $showmode = $params->get( 'showmode', '' ); $moduleclass_sfx = $params->get( 'moduleclass_sfx', '' ); $displayrealname = $params->get( 'displayrealname', 0 ); $displaygroupcolor = $params->get( 'displaygroupcolor', 0 ); $liststyle = $params->get( 'liststyle', 0 ); $showchatters = $params->get( 'showchatters', 0 ); $profilelink = $params->get( 'profilelink', 0 ); $pmlink = $params->get( 'pmlink', 0 ); $flashchaturl = $params->get( 'flashchaturl', '' ); $chatroomempty = $params->get( 'chatroomempty', '' ); //1.3 Add smf_tprefix which is the smf table prefix (-Wolverine) $smf_tprefix = $params->get( 'smf_tprefix', ''); // this is largely the default method used from the Joomla Who's Online module $content = ''; // show online count if ($showmode==0 || $showmode==2) { $query = "SELECT guest, usertype" . "\n FROM #__session" ; $database->setQuery( $query ); $sessions = $database->loadObjectList(); // calculate number of guests and members $user_array = 0; $guest_array = 0; foreach( $sessions as $session ) { // if guest increase guest count by 1 if ( $session->guest == 1 && !$session->usertype ) { $guest_array++; } // if member increase member count by 1 if ( $session->guest == 0 ) { $user_array++; } } // check if any guest or member is on the site if ($guest_array != 0 || $user_array != 0) { $content .= _WE_HAVE; // guest count handling if ($guest_array == 1) { // 1 guest only $content .= sprintf( _GUEST_COUNT, $guest_array ); } else if ($guest_array > 1) { // more than 1 guest $content .= sprintf( _GUESTS_COUNT, $guest_array ); } // if there are guests and members online if ($guest_array != 0 && $user_array != 0) { $content .= _AND; } // member count handling if ($user_array == 1) { // 1 member only $content .= sprintf( _MEMBER_COUNT, $user_array ); } else if ($user_array > 1) { // more than 1 member $content .= sprintf( _MEMBERS_COUNT, $user_array ); } $content .= _ONLINE; } } // show online member names if ($showmode > 0) { $query = "SELECT DISTINCT a.username, a.userid, b.name" . "\n FROM #__session AS a, #__users as b" . "\n WHERE a.guest = 0 " . "\n AND b.id = a.userid " . "\n GROUP by b.id"; $database->setQuery($query); $rows = $database->loadObjectList(); if (count($rows)) { foreach($rows as $row) { $content .= getListStyle(createOnlineLink($row->username, $row->name, $row->userid)); } } } if ($showchatters) { /* check if they put flashchat.php on the end or not */ $content .= "
\"Live
"; $chatters = ''; $query = "SELECT #__users.username, #__users.id, #__users.name " . "\n FROM #__users, #__fc_connections " . "\n WHERE #__fc_connections.userid = #__users.id " . "\n ORDER BY updated desc"; $database->setQuery($query); if ($rows = $database->loadObjectList()) { //$rows = $database->loadObjectList(); foreach($rows as $row) { $chatters .= getListStyle(createOnlineLink($row->username, $row->name, $row->id)); } if (empty($chatters)) { $content .= "\"\"".($chatroomempty != '' ? $chatroomempty : "The chatroom is quite..."); } else { $content .= $chatters; } } } //function ListStyle($item) { /** * Adds optional style to link * @param string $link username or url link * @global boolean $liststyle * @global string $mosConfig_live_site Site URL */ function getListStyle($link) { global $liststyle, $mosConfig_live_site; if ($liststyle) { return '
'.$link; } return ''; } //This function requires that JoomlaSMF Bridge be installed(depracated) //1.2 use $mosurl for links (-Wolverine) //1.3 don't use $mosurl for links to allow use of other bridges(-Wolverine) /** * Creates a link to given user * @param string $username * @param string $name * @param string $userid */ function createOnlineLink($username, $name, $userid) { global $database, $mosConfig_absolute_path, $mosConfig_sef, $mosConfig_live_site; global $profilelink, $displayrealname, $displaygroupcolor, $pmlink, $smf_tprefix; if (!$displayrealname) { $name = $username; } $link = ''; //take the quick way out if ($profilelink == 0 && $pmlink == 0) { return $name; //$link = ($displayrealname ? $name : $username); } //CB profile link if ($profilelink == 2) { $link = ''.$name.''; } //smf profile link or SMF private message link if ($profilelink == 1 || $pmlink == 1) { //1.3 Return if smf table prefix isn't set (-Wolverine) if(empty($smf_tprefix)){ return 'Please configure the SMF table prefix for this module!'; } $query = "SELECT id" . "\n FROM #__menu" . "\n WHERE link = 'index.php?option=com_smf'"; $database->setQuery($query); $smfItemid = $database->loadResult(); if (empty($smfItemid)) { return 't1'.$database->getErrorMsg().''; } $smfurl = "index.php?option=com_smf&Itemid=" . $smfItemid."&"; $query = "SELECT ID_MEMBER, ID_GROUP, ID_POST_GROUP" . "\n FROM {$smf_tprefix}members" . "\n WHERE memberName = '$username'"; $database->setQuery($query); $row = null; if ($database->loadObject($row)) { $memberid = $row->ID_MEMBER; $membergroup = empty($row->ID_GROUP) ? $row->ID_POST_GROUP : $row->ID_GROUP; if (empty($memberid)) { return ''.$database->getErrorMsg().''; } } else { return ''.$database->getErrorMsg().''; } if (isset($membergroup) && !empty($membergroup)) { $query = "SELECT onlineColor" . "\n FROM {$smf_tprefix}membergroups" . "\n WHERE ID_GROUP = '$membergroup'"; $database->setQuery($query); $membercolor = $database->loadResult(); } //smf profile link if ($profilelink == 1) { if ($displaygroupcolor && !empty($membercolor)) { //format a quick style= to add the membercolor(-Wolverine) $link .= ''.$name.''; } else { $link .= ''.$name.''; } } //smf pm link if ($pmlink == 1) { $link .= ''; } //$link = str_replace(";u,",";u=",$link); } //PMS private message link if ($pmlink == 2) { $link .= ''; } return $link; } ?>