您的位置:首页 > 其它

Joomla模块学习之后台mod_status模块

2011-02-27 11:42 302 查看
Joomla模块学习之后台mod_status模块

用户状态模块

后台管理模块效果图











原理:

显示用户相关状态,如:消息,当前在线人数





mod_stats模块结构图:







关键代码

$config		=& JFactory::getConfig();
$user		=& JFactory::getUser();
$db			=& JFactory::getDBO();
$lang		=& JFactory::getLanguage();
$session	=& JFactory::getSession();

$sid	= $session->getId();
$output = array();

// Legacy Mode
if (defined('_JLEGACY')) {
	$output[] = '<span class="legacy-mode">'.JText::_('Legacy').': '._JLEGACY.'</span>';
}

// Print the preview button
$output[] = "<span class=/"preview/"><a href="/" mce_href="/""".JURI::root()."/" target=/"_blank/">".JText::_('Preview')."</a></span>";

// Get the number of unread messages in your inbox
// 返回未读消息
$query = 'SELECT COUNT(*)'
. ' FROM #__messages'
. ' WHERE state = 0'
. ' AND user_id_to = '.(int) $user->get('id');
$db->setQuery( $query );
$unread = $db->loadResult();

if (JRequest::getInt('hidemainmenu')) {
	$inboxLink = '<a>';
} else {
	$inboxLink = '<a href="index.php?option=com_messages" mce_href="index.php?option=com_messages">';
}

// Print the inbox message
// 消息链接
if ($unread) {
	$output[] = $inboxLink.'<span class="unread-messages">'.$unread.'</span></a>';
} else {
	$output[] = $inboxLink.'<span class="no-unread-messages">'.$unread.'</span></a>';
}

// Get the number of logged in users
// 返回登录用户数量
$query = 'SELECT COUNT( session_id )'
. ' FROM #__session'
. ' WHERE guest <> 1'
;
$db->setQuery($query);
$online_num = intval( $db->loadResult() );

//Print the logged in users message
$output[] = "<span class=/"loggedin-users/">".$online_num."</span>";

// 如果当前为编辑操作或隐藏菜单,则不能退出
if ($task == 'edit' || $task == 'editA' || JRequest::getInt('hidemainmenu') ) {
	 // Print the logout message
	 $output[] = "<span class=/"logout/">".JText::_('Logout')."</span>";
} else {
	// Print the logout message
	$output[] = "<span class=/"logout/"><a href="/" mce_href="/""index.php?option=com_login&task=logout/">".JText::_('Logout')."</a></span>";
}

// reverse rendering order for rtl display
if ( $lang->isRTL() ) {
	$output = array_reverse( $output );
}

// output the module
foreach ($output as $item){
	echo $item;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: