b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/widgets/_online_users.widget.php - 153 lines - 4146 bytes - Summary - Text - Print

Description: This file implements the Online Users Widget class. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**

   3   * This file implements the Online Users Widget class.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

   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   * @package evocore

  20   *

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

  22   * @author asimo: Evo Factory / Attila Simo

  23   *

  24   * @version $Id: $

  25   */
  26  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  27  
  28  load_class( 'widgets/model/_widget.class.php', 'ComponentWidget' );
  29  
  30  /**

  31   * ComponentWidget Class

  32   *

  33   * A ComponentWidget is a displayable entity that can be placed into a Container on a web page.

  34   *

  35   * @package evocore

  36   */
  37  class online_users_Widget extends ComponentWidget
  38  {
  39      /**

  40       * Constructor

  41       */
  42  	function online_users_Widget( $db_row = NULL )
  43      {
  44          // Call parent constructor:

  45          parent::ComponentWidget( $db_row, 'core', 'online_users' );
  46      }
  47  
  48  
  49      /**

  50       * Get name of widget

  51       */
  52  	function get_name()
  53      {
  54          return T_( 'Online users' );
  55      }
  56  
  57  
  58      /**

  59       * Get short description

  60       */
  61  	function get_desc()
  62      {
  63          return T_('Display currently online users.');
  64      }
  65  
  66  
  67      /**

  68       * Get definitions for editable params

  69       *

  70       * @see Plugin::GetDefaultSettings()

  71       * @param array local params

  72       */
  73  	function get_param_definitions( $params )
  74      {
  75          load_funcs( 'files/model/_image.funcs.php' );
  76  
  77          $r = array_merge( array(
  78              'title' => array(
  79                  'label' => T_( 'Block title' ),
  80                  'note' => T_( 'Title to display in your skin.' ),
  81                  'size' => 40,
  82                  'defaultvalue' => T_( 'Online users' ),
  83              ),
  84              'allow_anonymous' => array(
  85                  'label' => T_( 'Allow for anonymous users' ),
  86                  'note' => T_( 'Uncheck to display this widget only for logged in users' ),
  87                  'type' => 'checkbox',
  88                  'defaultvalue' => 1,
  89              ),
  90          ), parent::get_param_definitions( $params ) );
  91  
  92          return $r;
  93      }
  94  
  95  
  96      /**

  97       * Display the widget!

  98       *

  99       * @param array MUST contain at least the basic display params

 100       */
 101  	function display( $params )
 102      {
 103          global $DB, $Settings, $UserSettings, $localtimenow;
 104  
 105          if( ( !$this->get_param( 'allow_anonymous' ) ) && ( !is_logged_in() ) )
 106          { // display only for logged in users
 107              return;
 108          }
 109  
 110          // load online Users

 111          $UserCache = & get_UserCache();
 112          $online_threshold = $localtimenow - ( 2 * $Settings->get( 'timeout_online' ) );
 113          $UserCache->load_where( 'user_lastseen_ts > '.$DB->quote( date2mysql( $online_threshold ).' AND user_status <> '.$DB->quote( 'closed' ) ) );
 114  
 115          $this->init_display( $params );
 116  
 117          // START DISPLAY:

 118          echo $this->disp_params['block_start'];
 119  
 120          // Display title if requested

 121          $this->disp_title();
 122  
 123          $r = '';
 124  
 125          while( ( $iterator_User = & $UserCache->get_next() ) != NULL )
 126          { // Iterate through UserCache
 127              $user_lastseen_ts = mysql2timestamp( $iterator_User->get( 'lastseen_ts' ) );
 128              if( ( $user_lastseen_ts > $online_threshold )
 129                  && ( $UserSettings->get( 'show_online', $iterator_User->ID ) )
 130                  && ( !$iterator_User->check_status( 'is_closed' ) ) )
 131              {
 132                  if( empty($r) )
 133                  { // first user
 134                      $r .= $params['list_start'];
 135                  }
 136  
 137                  $r .= $params['item_start'];
 138                  $r .= $iterator_User->get_identity_link( array( 'login_mask' => '$login$' ) );
 139                  $r .= $params['item_end'];
 140              }
 141          }
 142  
 143          if( !empty( $r ) )
 144          {
 145              $r .= $params['list_end'];
 146              echo $r;
 147          }
 148  
 149          echo $this->disp_params['block_end'];
 150  
 151          return true;
 152      }
 153  }

title

Description

title

Description

title

Description

title

title

Body