Guest User

Whosonline

a guest
Mar 21st, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. <?php if (!defined('APPLICATION')) exit();
  2.  
  3. // Define the plugin:
  4. $PluginInfo['WhosOnline'] = array(
  5. 'Name' => 'WhosOnline',
  6. 'Description' => "Lists the users currently browsing the forum.",
  7. 'Version' => '1.3',
  8. 'Author' => "Gary Mardell",
  9. 'AuthorEmail' => '[email protected]',
  10. 'AuthorUrl' => 'http://vanillaplugins.com',
  11. 'RegisterPermissions' => array('Plugins.WhosOnline.ViewHidden', 'Plugins.WhosOnline.Manage'),
  12. 'SettingsPermission' => array('Plugins.WhosOnline.Manage')
  13. );
  14.  
  15. /**
  16. * TODO:
  17. * Admin option to allow users it hide the module
  18. * User Meta table to store if they are hidden or not
  19. */
  20.  
  21. class WhosOnlinePlugin extends Gdn_Plugin {
  22.  
  23. public function PluginController_WhosOnline_Create(&$Sender) {
  24. $Sender->Permission('Plugins.WhosOnline.Manage');
  25. $Sender->AddSideMenu('plugin/whosonline');
  26. $Sender->Form = new Gdn_Form();
  27. $Validation = new Gdn_Validation();
  28. $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
  29. $ConfigurationModel->SetField(array('WhosOnline.Location.Show', 'WhosOnline.Frequency', 'WhosOnline.Hide'));
  30. $Sender->Form->SetModel($ConfigurationModel);
  31.  
  32. if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
  33. $Sender->Form->SetData($ConfigurationModel->Data);
  34. } else {
  35. $Data = $Sender->Form->FormValues();
  36. $ConfigurationModel->Validation->ApplyRule('WhosOnline.Frequency', array('Required', 'Integer'));
  37. $ConfigurationModel->Validation->ApplyRule('WhosOnline.Location.Show', 'Required');
  38. if ($Sender->Form->Save() !== FALSE)
  39. $Sender->StatusMessage = T("Your settings have been saved.");
  40. }
  41.  
  42. // creates the page for the plugin options such as display options
  43. $Sender->Render($this->GetView('whosonline.php'));
  44. }
  45.  
  46. public function PluginController_ImOnline_Create(&$Sender) {
  47.  
  48. $Session = Gdn::Session();
  49. $UserMetaData = $this->GetUserMeta($Session->UserID, '%');
  50.  
  51. // render new block and replace whole thing opposed to just the data
  52. include_once(PATH_PLUGINS.DS.'WhosOnline'.DS.'class.whosonlinemodule.php');
  53. $WhosOnlineModule = new WhosOnlineModule($Sender);
  54. $WhosOnlineModule->GetData(ArrayValue('Plugin.WhosOnline.Invisible', $UserMetaData));
  55. echo $WhosOnlineModule->ToString();
  56.  
  57. }
  58. public function Base_Render_Before($Sender) {
  59. $Sender->AddCssFile($this->GetResource('design/custom.css', FALSE, FALSE));
  60. }
  61.  
  62.  
  63.  
  64. }
  65. public function Base_Render_Before(&$Sender) {
  66. $ConfigItem = C('WhosOnline.Location.Show', 'every');
  67. $Controller = $Sender->ControllerName;
  68. $Application = $Sender->ApplicationFolder;
  69. $Session = Gdn::Session();
  70.  
  71. // Check if its visible to users
  72. if (C('WhosOnline.Hide', TRUE) && !$Session->IsValid()) {
  73. return;
  74. }
  75.  
  76. $ShowOnController = array();
  77. switch($ConfigItem) {
  78. case 'every':
  79. $ShowOnController = array(
  80. 'discussioncontroller',
  81. 'categoriescontroller',
  82. 'discussionscontroller',
  83. 'profilecontroller',
  84. 'activitycontroller'
  85. );
  86. break;
  87. case 'discussion':
  88. default:
  89. $ShowOnController = array(
  90. 'discussioncontroller',
  91. 'discussionscontroller',
  92. 'categoriescontroller'
  93. );
  94. }
  95.  
  96. if (!InArrayI($Controller, $ShowOnController)) return;
  97.  
  98. $UserMetaData = $this->GetUserMeta($Session->UserID, '%');
  99. include_once(PATH_PLUGINS.DS.'WhosOnline'.DS.'class.whosonlinemodule.php');
  100. $WhosOnlineModule = new WhosOnlineModule($Sender);
  101. $WhosOnlineModule->GetData(ArrayValue('Plugin.WhosOnline.Invisible', $UserMetaData));
  102. $Sender->AddModule($WhosOnlineModule);
  103.  
  104. $Sender->AddJsFile('/plugins/WhosOnline/whosonline.js');
  105. $Frequency = C('WhosOnline.Frequency', 4);
  106. if (!is_numeric($Frequency))
  107. $Frequency = 4;
  108.  
  109. $Sender->AddDefinition('WhosOnlineFrequency', $Frequency);
  110.  
  111. }
  112.  
  113. public function Base_GetAppSettingsMenuItems_Handler(&$Sender) {
  114. $Menu = $Sender->EventArguments['SideMenu'];
  115. $Menu->AddLink('Add-ons', 'Whos Online', 'plugin/whosonline', 'Garden.Themes.Manage');
  116. }
  117.  
  118. // User Settings
  119. public function ProfileController_AfterAddSideMenu_Handler(&$Sender) {
  120. $SideMenu = $Sender->EventArguments['SideMenu'];
  121. $Session = Gdn::Session();
  122. $ViewingUserID = $Session->UserID;
  123.  
  124. if ($Sender->User->UserID == $ViewingUserID) {
  125. $SideMenu->AddLink('Options', T('Who\'s Online Settings'), '/profile/whosonline', FALSE, array('class' => 'Popup'));
  126. }
  127. }
  128.  
  129. public function ProfileController_Whosonline_Create(&$Sender) {
  130.  
  131. $Session = Gdn::Session();
  132. $UserID = $Session->IsValid() ? $Session->UserID : 0;
  133.  
  134. // Get the data
  135. $UserMetaData = $this->GetUserMeta($UserID, '%');
  136. $ConfigArray = array(
  137. 'Plugin.WhosOnline.Invisible' => NULL
  138. );
  139.  
  140. if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
  141. // Convert to using arrays if more options are added.
  142. $ConfigArray = array_merge($ConfigArray, $UserMetaData);
  143. $Sender->Form->SetData($ConfigArray);
  144. }
  145. else {
  146. $Values = $Sender->Form->FormValues();
  147. $FrmValues = array_intersect_key($Values, $ConfigArray);
  148.  
  149. foreach($FrmValues as $MetaKey => $MetaValue) {
  150. $this->SetUserMeta($UserID, $this->TrimMetaKey($MetaKey), $MetaValue);
  151. }
  152.  
  153. $Sender->StatusMessage = T("Your changes have been saved.");
  154. }
  155.  
  156. $Sender->Render($this->GetView('settings.php'));
  157. }
  158.  
  159.  
  160. public function Setup() {
  161. $Structure = Gdn::Structure();
  162. $Structure->Table('Whosonline')
  163. ->Column('UserID', 'int(11)', FALSE, 'primary')
  164. ->Column('Timestamp', 'datetime')
  165. ->Column('Invisible', 'int(1)', 0)
  166. ->Set(FALSE, FALSE);
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment