b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/widgets/_user_avatars.widget.php - 279 lines - 7007 bytes - Summary - Text - Print

Description: This file implements the User Avatars 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 User Avatars 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 fplanque: Francois PLANQUE.

  23   * @author Yabba    - {@link http://www.astonishme.co.uk/}

  24   *

  25   * @version $Id: _user_avatars.widget.php 17 2011-10-25 04:22:09Z sam2kb $

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

  33   * ComponentWidget Class

  34   *

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

  36   *

  37   * @package evocore

  38   */
  39  class user_avatars_Widget extends ComponentWidget
  40  {
  41      /**

  42       * Constructor

  43       */
  44  	function user_avatars_Widget( $db_row = NULL )
  45      {
  46          // Call parent constructor:

  47          parent::ComponentWidget( $db_row, 'core', 'user_avatars' );
  48      }
  49  
  50  
  51      /**

  52       * Get definitions for editable params

  53       *

  54       * @see Plugin::GetDefaultSettings()

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

  56       */
  57  	function get_param_definitions( $params )
  58      {
  59          load_funcs( 'files/model/_image.funcs.php' );
  60  
  61          $r = array_merge( array(
  62              'title' => array(
  63                  'label' => T_('Block title'),
  64                  'note' => T_( 'Title to display in your skin.' ),
  65                  'size' => 40,
  66                  'defaultvalue' => T_('Random Users'),
  67              ),
  68              'thumb_size' => array(
  69                  'label' => T_('Thumbnail size'),
  70                  'note' => T_('Cropping and sizing of thumbnails'),
  71                  'type' => 'select',
  72                  'options' => get_available_thumb_sizes(),
  73                  'defaultvalue' => 'crop-top-80x80',
  74              ),
  75              'thumb_layout' => array(
  76                  'label' => T_('Layout'),
  77                  'note' => T_('How to lay out the thumbnails'),
  78                  'type' => 'select',
  79                  'options' => array( 'grid' => T_( 'Grid' ), 'list' => T_( 'List' ) ),
  80                  'defaultvalue' => 'grid',
  81              ),
  82              'grid_nb_cols' => array(
  83                  'label' => T_( 'Columns' ),
  84                  'note' => T_( 'Number of columns in grid mode.' ),
  85                  'size' => 4,
  86                  'defaultvalue' => 1,
  87              ),
  88              'limit' => array(
  89                  'label' => T_( 'Max pictures' ),
  90                  'note' => T_( 'Maximum number of pictures to display.' ),
  91                  'size' => 4,
  92                  'defaultvalue' => 1,
  93              ),
  94              'bubbletip' => array(
  95                  'label' => T_( 'Bubble tips' ),
  96                  'note' => T_( 'Check to enable bubble tips -- Bubble tips must also be enabled for the current skin.' ),
  97                  'type' => 'checkbox',
  98                  'defaultvalue' => 1,
  99              ),
 100              'order_by' => array(
 101                  'label' => T_('Order by'),
 102                  'note' => T_('How to sort the users'),
 103                  'type' => 'select',
 104                  'options' => array(
 105                          'random'  => T_('Random users'),
 106                          'regdate' => T_('Most recent registrations'),
 107                          'moddate' => T_('Most recent profile updates'),
 108                      ),
 109                  'defaultvalue' => 'random',
 110              ),
 111          ), parent::get_param_definitions( $params )    );
 112  
 113          return $r;
 114      }
 115  
 116  
 117      /**

 118       * Get name of widget

 119       */
 120  	function get_name()
 121      {
 122          return T_('Users pictures');
 123      }
 124  
 125  
 126      /**

 127       * Get a very short desc. Used in the widget list.

 128       */
 129  	function get_short_desc()
 130      {
 131          return format_to_output( $this->disp_params['title'] );
 132      }
 133  
 134  
 135      /**

 136       * Get short description

 137       */
 138  	function get_desc()
 139      {
 140          return T_('Index of users avatars; click goes to user page.');
 141      }
 142  
 143  
 144      /**

 145       * Display the widget!

 146       *

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

 148       */
 149  	function display( $params )
 150      {
 151          $this->init_display( $params );
 152  
 153          $UserCache = & get_UserCache();
 154  
 155          $UserList = new DataObjectList2( $UserCache );
 156  
 157          switch( $this->disp_params[ 'order_by' ] )
 158          {
 159              case 'regdate':
 160                  $sql_order = 'user_created_datetime DESC';
 161                  break;
 162              case 'moddate':
 163                  $sql_order = 'user_profileupdate_date DESC';
 164                  break;
 165              case 'random':
 166              default:
 167                  $sql_order = 'RAND()';
 168                  break;
 169          }
 170  
 171          // Query list of files:

 172          $SQL = new SQL();
 173          $SQL->SELECT( '*' );
 174          $SQL->FROM( 'T_users' );
 175          $SQL->WHERE( 'user_avatar_file_ID IS NOT NULL' );
 176          $SQL->ORDER_BY( $sql_order );
 177          $SQL->LIMIT( $this->disp_params[ 'limit' ] );
 178  
 179          $UserList->sql = $SQL->get();
 180  
 181          $UserList->query( false, false, false, 'User avatars widget' );
 182  
 183          $layout = $this->disp_params[ 'thumb_layout' ];
 184  
 185          $nb_cols = $this->disp_params[ 'grid_nb_cols' ];
 186          $count = 0;
 187          $r = '';
 188          /**

 189           * @var User

 190           */
 191          while( $User = & $UserList->get_next() )
 192          {
 193              if( $layout == 'grid' )
 194              {
 195                  if( $count % $nb_cols == 0 )
 196                  {
 197                      $r .= $this->disp_params[ 'grid_colstart' ];
 198                  }
 199                  $r .= $this->disp_params[ 'grid_cellstart' ];
 200              }
 201              else
 202              {
 203                  $r .= $this->disp_params[ 'item_start' ];
 204              }
 205  
 206              $identity_url = get_user_identity_url( $User->ID );
 207              $avatar_tag = $User->get_avatar_imgtag( $this->disp_params['thumb_size'] );
 208  
 209              if( $this->disp_params[ 'bubbletip' ] == '1' )
 210              {    // Bubbletip is enabled
 211                  $bubbletip_param = ' rel="bubbletip_user_'.$User->ID.'"';
 212                  $avatar_tag = str_replace( '<img ', '<img '.$bubbletip_param.' ', $avatar_tag );
 213              }
 214  
 215              if( ! empty( $identity_url ) )
 216              {
 217                  $r .= '<a href="'.$identity_url.'">'.$avatar_tag.'</a>';
 218              }
 219              else
 220              {
 221                  $r .= $avatar_tag;
 222              }
 223  
 224              ++$count;
 225  
 226              if( $layout == 'grid' )
 227              {
 228                  $r .= $this->disp_params[ 'grid_cellend' ];
 229                  if( $count % $nb_cols == 0 )
 230                  {
 231                      $r .= $this->disp_params[ 'grid_colend' ];
 232                  }
 233              }
 234              else
 235              {
 236                  $r .= $this->disp_params[ 'item_end' ];
 237              }
 238          }
 239  
 240          // Exit if no files found

 241          if( empty($r) ) return;
 242  
 243          echo $this->disp_params[ 'block_start'];
 244  
 245          // Display title if requested

 246          $this->disp_title();
 247          
 248          if( $layout == 'grid' )
 249          {
 250              echo $this->disp_params[ 'grid_start' ];
 251          }
 252          else
 253          {
 254              echo $this->disp_params[ 'list_start' ];
 255          }
 256          
 257          echo $r;
 258  
 259          if( $layout == 'grid' )
 260          {
 261              if( $count && ( $count % $nb_cols != 0 ) )
 262              {
 263                  echo $this->disp_params[ 'grid_colend' ];
 264              }
 265  
 266              echo $this->disp_params[ 'grid_end' ];
 267          }
 268          else
 269          {
 270              echo $this->disp_params[ 'list_end' ];
 271          }
 272  
 273          echo $this->disp_params[ 'block_end' ];
 274  
 275          return true;
 276      }
 277  }
 278  
 279  ?>

title

Description

title

Description

title

Description

title

title

Body