-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.whosonlinemodule.php
79 lines (68 loc) · 1.9 KB
/
class.whosonlinemodule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php if (!defined('APPLICATION')) exit();
/**
* Renders a list of users who are taking part in a particular discussion.
*/
class WhosOnlineModule extends Gdn_Module {
protected $_OnlineUsers;
public function __construct(&$Sender = '') {
parent::__construct($Sender);
}
public function GetData($Invisible = FALSE) {
$SQL = Gdn::SQL();
// $this->_OnlineUsers = $SQL
// insert or update entry into table
$Session = Gdn::Session();
$Invisible = ($Invisible ? 1 : 0);
if ($Session->UserID)
$SQL->Replace('Whosonline', array(
'UserID' => $Session->UserID,
'Timestamp' => Gdn_Format::ToDateTime(),
'Invisible' => $Invisible),
array('UserID' => $Session->UserID)
);
$Frequency = C('WhosOnline.Frequency', 4);
$History = time() - $Frequency;
$SQL
->Select('u.UserID, u.Name, w.Timestamp, w.Invisible')
->From('Whosonline w')
->Join('User u', 'w.UserID = u.UserID')
->Where('w.Timestamp >=', date('Y-m-d H:i:s', $History))
->OrderBy('u.Name');
if (!$Session->CheckPermission('Plugins.WhosOnline.ViewHidden'))
$SQL->Where('w.Invisible', 0);
$this->_OnlineUsers = $SQL->Get();
}
public function AssetTarget() {
//return 'Foot';
return 'Panel';
}
public function ToString() {
$String = '';
$Session = Gdn::Session();
ob_start();
?>
<div id="WhosOnline" class="Box">
<h4><?php echo T("Who's Online"); ?> (<?php echo $this->_OnlineUsers->NumRows(); ?>)</h4>
<ul class="PanelInfo">
<?php
if ($this->_OnlineUsers->NumRows() > 0) {
foreach($this->_OnlineUsers->Result() as $User) {
?>
<li>
<strong <?php echo ($User->Invisible == 1 ? 'class="Invisible"' : '')?>>
<?php echo UserAnchor($User); ?>
</strong>
<?php echo Gdn_Format::Date($User->Timestamp); ?>
</li>
<?php
}
}
?>
</ul>
</div>
<?php
$String = ob_get_contents();
@ob_end_clean();
return $String;
}
}