-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.php
162 lines (132 loc) · 5.63 KB
/
default.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php if (!defined('APPLICATION')) exit();
// Define the plugin:
$PluginInfo['WhosOnline'] = array(
'Name' => 'WhosOnline',
'Description' => "Lists the users currently browsing the forum.",
'Version' => '1.3',
'Author' => "Gary Mardell",
'AuthorEmail' => 'gary@vanillaplugins.com',
'AuthorUrl' => 'http://vanillaplugins.com',
'RegisterPermissions' => array('Plugins.WhosOnline.ViewHidden', 'Plugins.WhosOnline.Manage'),
'SettingsPermission' => array('Plugins.WhosOnline.Manage')
);
/**
* TODO:
* Admin option to allow users it hide the module
* User Meta table to store if they are hidden or not
*/
class WhosOnlinePlugin extends Gdn_Plugin {
public function PluginController_WhosOnline_Create(&$Sender) {
$Sender->Permission('Plugins.WhosOnline.Manage');
$Sender->AddSideMenu('plugin/whosonline');
$Sender->Form = new Gdn_Form();
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array('WhosOnline.Location.Show', 'WhosOnline.Frequency', 'WhosOnline.Hide'));
$Sender->Form->SetModel($ConfigurationModel);
if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
$Sender->Form->SetData($ConfigurationModel->Data);
} else {
$Data = $Sender->Form->FormValues();
$ConfigurationModel->Validation->ApplyRule('WhosOnline.Frequency', array('Required', 'Integer'));
$ConfigurationModel->Validation->ApplyRule('WhosOnline.Location.Show', 'Required');
if ($Sender->Form->Save() !== FALSE)
$Sender->StatusMessage = T("Your settings have been saved.");
}
// creates the page for the plugin options such as display options
$Sender->Render($this->GetView('whosonline.php'));
}
public function PluginController_ImOnline_Create(&$Sender) {
$Session = Gdn::Session();
$UserMetaData = $this->GetUserMeta($Session->UserID, '%');
// render new block and replace whole thing opposed to just the data
include_once(PATH_PLUGINS.DS.'WhosOnline'.DS.'class.whosonlinemodule.php');
$WhosOnlineModule = new WhosOnlineModule($Sender);
$WhosOnlineModule->GetData(ArrayValue('Plugin.WhosOnline.Invisible', $UserMetaData));
echo $WhosOnlineModule->ToString();
}
public function Base_Render_Before(&$Sender) {
$ConfigItem = C('WhosOnline.Location.Show', 'every');
$Controller = $Sender->ControllerName;
$Application = $Sender->ApplicationFolder;
$Session = Gdn::Session();
// Check if its visible to users
if (C('WhosOnline.Hide', TRUE) && !$Session->IsValid()) {
return;
}
$ShowOnController = array();
switch($ConfigItem) {
case 'every':
$ShowOnController = array(
'discussioncontroller',
'categoriescontroller',
'discussionscontroller',
'profilecontroller',
'activitycontroller'
);
break;
case 'discussion':
default:
$ShowOnController = array(
'discussioncontroller',
'discussionscontroller',
'categoriescontroller'
);
}
if (!InArrayI($Controller, $ShowOnController)) return;
$UserMetaData = $this->GetUserMeta($Session->UserID, '%');
include_once(PATH_PLUGINS.DS.'WhosOnline'.DS.'class.whosonlinemodule.php');
$WhosOnlineModule = new WhosOnlineModule($Sender);
$WhosOnlineModule->GetData(ArrayValue('Plugin.WhosOnline.Invisible', $UserMetaData));
$Sender->AddModule($WhosOnlineModule);
$Sender->AddJsFile('/plugins/WhosOnline/whosonline.js');
$Frequency = C('WhosOnline.Frequency', 4);
if (!is_numeric($Frequency))
$Frequency = 4;
$Sender->AddDefinition('WhosOnlineFrequency', $Frequency);
}
public function Base_GetAppSettingsMenuItems_Handler(&$Sender) {
$Menu = $Sender->EventArguments['SideMenu'];
$Menu->AddLink('Add-ons', 'Whos Online', 'plugin/whosonline', 'Garden.Themes.Manage');
}
// User Settings
public function ProfileController_AfterAddSideMenu_Handler(&$Sender) {
$SideMenu = $Sender->EventArguments['SideMenu'];
$Session = Gdn::Session();
$ViewingUserID = $Session->UserID;
if ($Sender->User->UserID == $ViewingUserID) {
$SideMenu->AddLink('Options', T('Who\'s Online Settings'), '/profile/whosonline', FALSE, array('class' => 'Popup'));
}
}
public function ProfileController_Whosonline_Create(&$Sender) {
$Session = Gdn::Session();
$UserID = $Session->IsValid() ? $Session->UserID : 0;
// Get the data
$UserMetaData = $this->GetUserMeta($UserID, '%');
$ConfigArray = array(
'Plugin.WhosOnline.Invisible' => NULL
);
if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
// Convert to using arrays if more options are added.
$ConfigArray = array_merge($ConfigArray, $UserMetaData);
$Sender->Form->SetData($ConfigArray);
}
else {
$Values = $Sender->Form->FormValues();
$FrmValues = array_intersect_key($Values, $ConfigArray);
foreach($FrmValues as $MetaKey => $MetaValue) {
$this->SetUserMeta($UserID, $this->TrimMetaKey($MetaKey), $MetaValue);
}
$Sender->StatusMessage = T("Your changes have been saved.");
}
$Sender->Render($this->GetView('settings.php'));
}
public function Setup() {
$Structure = Gdn::Structure();
$Structure->Table('Whosonline')
->Column('UserID', 'int(11)', FALSE, 'primary')
->Column('Timestamp', 'datetime')
->Column('Invisible', 'int(1)', 0)
->Set(FALSE, FALSE);
}
}