[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/plugins/ -> _whosonline.plugin.php (source)

   1  <?php
   2  /**

   3   * This file implements the Whosonline plugin.

   4   *

   5   * This file is part of the b2evolution project - {@link http://b2evolution.net/}

   6   *

   7   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   8   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.

   9   *

  10   * {@internal License choice

  11   * - If you have received this file as part of a package, please find the license.txt file in

  12   *   the same folder or the closest folder above for complete license terms.

  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  14   *   then you must choose one of the following licenses before using the file:

  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  17   * }}

  18   *

  19   * {@internal Open Source relicensing agreement:

  20   * Daniel HAHLER grants Francois PLANQUE the right to license

  21   * Daniel HAHLER's contributions to this file and the b2evolution project

  22   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  23   * }}

  24   *

  25   * @package plugins

  26   *

  27   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  28   * @author blueyed: Daniel HAHLER.

  29   * @author fplanque: Francois PLANQUE - {@link http://fplanque.net/}

  30   * @author jeffbearer: Jeff BEARER - {@link http://www.jeffbearer.com/}.

  31   *

  32   * @version $Id: _whosonline.plugin.php,v 1.2 2007/06/20 23:36:06 fplanque Exp $

  33   */
  34  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  35  
  36  
  37  /**

  38   * Calendar Plugin

  39   *

  40   * This plugin displays

  41   */
  42  class whosonline_plugin extends Plugin
  43  {
  44      /**

  45       * Variables below MUST be overriden by plugin implementations,

  46       * either in the subclass declaration or in the subclass constructor.

  47       */
  48  
  49      var $name = 'Who\'s online Widget';
  50      var $code = 'evo_WhosOnline';
  51      var $priority = 96;
  52      var $version = '2.0';
  53      var $author = 'The b2evo Group';
  54      var $group = 'widget';
  55  
  56  
  57      /**

  58       * Init

  59       */
  60  	function PluginInit( & $params )
  61      {
  62          $this->short_desc = T_('This skin tag displays a list of whos is online.');
  63          $this->long_desc = T_('All logged in users and guest users who have requested a page in the last 5 minutes are listed.');
  64      }
  65  
  66  
  67    /**

  68     * Get definitions for widget specific editable params

  69     *

  70       * @see Plugin::GetDefaultSettings()

  71       * @param local params like 'for_editing' => true

  72       */
  73  	function get_widget_param_definitions( $params )
  74      {
  75          $r = array(
  76              'contacticons' => array(
  77                  'label' => T_('Contact icons'),
  78                  'note' => T_('Display contact icons allowing to send private messages to logged in users.'),
  79                  'type' => 'checkbox',
  80                  'defaultvalue' => true,
  81              ),
  82          );
  83          return $r;
  84      }
  85  
  86  
  87      /**

  88       * Event handler: SkinTag (widget)

  89       *

  90       * @param array Associative array of parameters.

  91       * @return boolean did we display?

  92       */
  93  	function SkinTag( $params )
  94      {
  95          global $generating_static, $Plugins;
  96  
  97          if( ! empty($generating_static) || $Plugins->trigger_event_first_true('CacheIsCollectingContent') )
  98          { // We're not generating static pages nor is a caching plugin collecting the content, so we can display this block
  99              return false;
 100          }
 101  
 102          echo $params['block_start'];
 103  
 104          echo $params['block_title_start'];
 105          echo T_('Who\'s Online?');
 106          echo $params['block_title_end'];
 107  
 108          $OnlineSessions = new OnlineSessions();
 109  
 110          $OnlineSessions->display_onliners( $params );
 111  
 112          echo $params['block_end'];
 113  
 114          return true;
 115      }
 116  }
 117  
 118  
 119  /**

 120   * This tracks who is online

 121   *

 122   * @todo dh> I wanted to add a MySQL INDEX on the sess_lastseen field, but this "plugin"

 123   *       is the only real user of this. So, when making this a plugin, this should

 124   *       add the index perhaps.

 125   * @package evocore

 126   */
 127  class OnlineSessions
 128  {
 129      /**

 130       * Number of guests (and users that want to be anonymous)

 131       *

 132       * Gets lazy-filled when needed, through {@link init()}.

 133       *

 134       * @access protected

 135       */
 136      var $_count_guests;
 137  
 138  
 139      /**

 140       * List of registered users.

 141       *

 142       * Gets lazy-filled when needed, through {@link init()}.

 143       *

 144       * @access protected

 145       */
 146      var $_registered_Users;
 147  
 148  
 149      var $_initialized = false;
 150  
 151  
 152      /**

 153       * Get an array of registered users and guests.

 154       *

 155       * @return array containing number of registered users and guests ('registered' and 'guests')

 156       */
 157  	function init()
 158      {
 159          if( $this->_initialized )
 160          {
 161              return true;
 162          }
 163          global $DB, $localtimenow, $timeout_online_user;
 164  
 165          $this->_count_guests = 0;
 166          $this->_registered_Users = array();
 167  
 168          $timeout_YMD = date( 'Y-m-d H:i:s', ($localtimenow - $timeout_online_user) );
 169  
 170          $UserCache = & get_Cache( 'UserCache' );
 171  
 172          // We get all sessions that have been seen in $timeout_YMD and that have a session key.

 173          // NOTE: we do not use DISTINCT here, because guest users are all "NULL".

 174          foreach( $DB->get_results( "
 175              SELECT sess_user_ID
 176                FROM T_sessions
 177               WHERE sess_lastseen > '".$timeout_YMD."'
 178                 AND sess_key IS NOT NULL", OBJECT, 'Sessions: get list of relevant users.' ) as $row )
 179          {
 180              if( !empty( $row->sess_user_ID )
 181                      && ( $User = & $UserCache->get_by_ID( $row->sess_user_ID ) ) )
 182              {
 183                  // assign by ID so that each user is only counted once (he could use multiple user agents at the same time)

 184                  $this->_registered_Users[ $User->ID ] = & $User;
 185  
 186                  if( !$User->showonline )
 187                  {
 188                      $this->_count_guests++;
 189                  }
 190              }
 191              else
 192              {
 193                  $this->_count_guests++;
 194              }
 195          }
 196  
 197          $this->_initialized = true;
 198      }
 199  
 200  
 201      /**

 202       * Get the number of guests.

 203       *

 204       * @param boolean display?

 205       */
 206  	function number_of_guests( $display = true )
 207      {
 208          if( !isset($this->_count_guests) )
 209          {
 210              $this->init();
 211          }
 212  
 213          if( $display )
 214          {
 215              echo $this->_count_guests;
 216          }
 217          return $this->_count_guests;
 218      }
 219  
 220  
 221      /**

 222       * Template function: Display onliners, both registered users and guests.

 223       *

 224       * @todo get class="" out of here (put it into skins)

 225       */
 226  	function display_onliners( $params )
 227      {
 228          $this->display_online_users( $params );
 229          $this->display_online_guests( $params );
 230      }
 231  
 232      /**

 233       * Template function: Display the registered users who are online

 234       *

 235       * @todo get class="" out of here (put it into skins)

 236       *

 237       * @param array

 238       */
 239  	function display_online_users( $params )
 240      {
 241          global $DB, $Blog;
 242          global $generating_static;
 243          if( isset($generating_static) ) { return; }
 244  
 245          if( !isset($this->_registered_Users) )
 246          {
 247              $this->init();
 248          }
 249  
 250          // Note: not all users want to appear online, so we might have an empty list.

 251          $r = '';
 252  
 253          foreach( $this->_registered_Users as $User )
 254          {
 255              if( $User->showonline )
 256              {
 257                  if( empty($r) )
 258                  { // first user
 259                      $r .= $params['list_start'];
 260                  }
 261  
 262                  $r .= $params['item_start'];
 263                  $r .= $User->dget('preferredname');
 264                  if( $params['contacticons'] )
 265                  {    // We want contact icons:
 266                      $r .= $User->get_msgform_link();
 267                  }
 268                  $r .= $params['item_end'];
 269              }
 270          }
 271  
 272          if( !empty($r) )
 273          { // we need to close the list
 274              $r .= $params['list_end'];;
 275          }
 276  
 277          echo $r;
 278      }
 279  
 280  
 281      /**

 282       * Template function: Display number of online guests.

 283       */
 284  	function display_online_guests( $params )
 285      {
 286          global $generating_static;
 287          if( isset($generating_static) ) { return; }
 288  
 289          if( !isset($this->_count_guests) )
 290          {
 291              $this->init();
 292          }
 293  
 294          $r = $params['list_start'];
 295          $r .= $params['item_start'];
 296          $r .= T_('Guest Users:').' ';
 297          $r .= $this->_count_guests;
 298          $r .= $params['item_end'];
 299          $r .= $params['list_end'];;
 300  
 301          echo $r;
 302      }
 303  }
 304  
 305  
 306  /*

 307   * $Log: _whosonline.plugin.php,v $

 308   * Revision 1.2  2007/06/20 23:36:06  fplanque

 309   * cleanup

 310   *

 311   * Revision 1.1  2007/06/20 23:12:51  fplanque

 312   * "Who's online" moved to a plugin

 313   *

 314   * Revision 1.13  2007/06/11 22:01:53  blueyed

 315   * doc fixes

 316   *

 317   * Revision 1.12  2007/04/26 00:11:11  fplanque

 318   * (c) 2007

 319   *

 320   * Revision 1.11  2007/02/05 13:29:09  waltercruz

 321   * Changing double quotes to single quotes

 322   *

 323   * Revision 1.10  2006/12/17 23:44:35  fplanque

 324   * minor cleanup

 325   *

 326   * Revision 1.9  2006/11/24 18:27:24  blueyed

 327   * Fixed link to b2evo CVS browsing interface in file docblocks

 328   */
 329  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics