b2evolution PHP Cross Reference Blogging Systems

Source: /inc/users/model/_userlist.class.php - 749 lines - 25063 bytes - Summary - Text - Print

Description: This file implements the UserList class. This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**

   3   * This file implements the UserList class.

   4   *

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

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

   7   *

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

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

  10   *

  11   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)

  12   *

  13   * {@internal Open Source relicensing agreement:

  14   * Daniel HAHLER grants Francois PLANQUE the right to license

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

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

  17   * }}

  18   *

  19   * @package evocore

  20   *

  21   * @version $Id: _userlist.class.php 236 2011-11-08 16:08:22Z yura $

  22   */
  23  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  24  
  25  load_class( '_core/model/dataobjects/_dataobjectlist2.class.php', 'DataObjectList2' );
  26  load_class( 'users/model/_userquery.class.php', 'UserQuery' );
  27  
  28  /**

  29   * UserList Class

  30   *

  31   * @package evocore

  32   */
  33  class UserList extends DataObjectList2
  34  {
  35      /**

  36       * SQL object for the Query

  37       */
  38      var $UserQuery;
  39  
  40      /**

  41       * Boolean var, Set TRUE when we should to get new user IDs from DB (when user changes the filter params)

  42       */
  43      var $refresh_query = false;
  44  
  45      /**

  46       * Boolean var, TRUE - to memorize params (regenerate_url)

  47       */
  48      var $memorize = true;
  49      
  50      /**

  51       * @var array Params to build query

  52       */
  53      var $query_params = array();
  54  
  55      /**

  56       * Constructor

  57       *

  58       * @param integer|NULL Limit

  59       * @param string prefix to differentiate page/order params when multiple Results appear one same page

  60       * @param string Name to be used when saving the filterset (leave empty to use default)

  61       * @param array Query params:

  62       *                    'join_group'   => true,

  63       *                    'join_session' => false,

  64       *                    'join_country' => true,

  65       *                    'join_city'    => true,

  66       *                    'keywords_fields'     - Fields of users table to search by keywords

  67       *                    'where_status_closed' - FALSE - to don't display closed users

  68       */
  69  	function UserList(
  70          $filterset_name = '', // Name to be used when saving the filterset (leave empty to use default)
  71          $limit = 20, // Page size
  72          $param_prefix = 'users_',
  73          $query_params = array()
  74          )
  75      {
  76          // Call parent constructor:

  77          parent::DataObjectList2( get_Cache( 'UserCache' ), $limit, $param_prefix, NULL );
  78  
  79          // Init query params, @see $this->query_init()

  80          $this->query_params = $query_params;
  81  
  82          if( !empty( $filterset_name ) )
  83          {    // Set the filterset_name with the filterset_name param
  84              $this->filterset_name = 'UserList_filters_'.$filterset_name;
  85          }
  86          else
  87          {    // Set a generic filterset_name
  88              $this->filterset_name = 'UserList_filters';
  89          }
  90  
  91          $this->order_param = $param_prefix.'order';
  92          $this->page_param = $param_prefix.'paged';
  93  
  94          // Initialize the default filter set:

  95          $this->set_default_filters( array(
  96                  'filter_preset'       => NULL,
  97                  'country'             => NULL,    // integer, Country ID
  98                  'region'              => NULL,    // integer, Region ID
  99                  'subregion'           => NULL,    // integer, Subregion ID
 100                  'city'                => NULL,    // integer, City ID
 101                  'keywords'            => NULL,    // string, Search words
 102                  'gender'              => NULL,    // string: 'M', 'F' or 'MF'
 103                  'status_activated'    => NULL,    // string: 'activated'
 104                  'account_status'      => NULL,    // string: 'new', 'activated', 'autoactivated', 'emailchanged', 'deactivated', 'failedactivation', 'closed'
 105                  'reported'            => NULL,    // integer: 1 to show only reported users
 106                  'custom_sender_email' => NULL,    // integer: 1 to show only users with custom notifcation sender email address
 107                  'custom_sender_name'  => NULL,    // integer: 1 to show only users with custom notifaction sender name
 108                  'group'               => -1,      // string: User group ID, -1 = all groups but list is ungrouped, 0 - all groups with grouped list
 109                  'age_min'             => NULL,    // integer, Age min
 110                  'age_max'             => NULL,    // integer, Age max
 111                  'userfields'          => array(), // Format of item: array( 'type' => type_ID, 'value' => search_words )
 112                  'order'               => '-D',    // Order
 113                  'users'               => array(), // User IDs
 114          ) );
 115      }
 116  
 117  
 118      /**

 119       * Reset the query -- EXPERIMENTAL

 120       *

 121       * Useful to requery with a slighlty moidified filterset

 122       */
 123  	function reset()
 124      {
 125          // The SQL Query object:

 126          $this->UserQuery = new UserQuery( $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname );
 127  
 128          parent::reset();
 129      }
 130  
 131  
 132      /**

 133       * Set/Activate filterset

 134       *

 135       * This will also set back the GLOBALS !!! needed for regenerate_url().

 136       *

 137       * @param array Filters

 138       */
 139  	function set_filters( $filters )
 140      {
 141          if( !empty( $filters ) )
 142          { // Activate the filterset (fallback to default filter when a value is not set):
 143              $this->filters = array_merge( $this->default_filters, $filters );
 144          }
 145  
 146          // Activate preset filters if necessary:

 147          $this->activate_preset_filters();
 148  
 149          // Page

 150          $this->page = param( $this->page_param, 'integer', 1 );
 151  
 152          // asimo> memorize is always false for now, because is not fully implemented

 153          if( $this->memorize )
 154          {    // set back the GLOBALS !!! needed for regenerate_url() :
 155  
 156              /*

 157               * Selected filter preset:

 158               */
 159              memorize_param( 'filter_preset', 'string', $this->default_filters['filter_preset'], $this->filters['filter_preset'] );  // List of authors to restrict to

 160  
 161              /*

 162               * Restrict by keywords

 163               */
 164              memorize_param( 'keywords', 'string', $this->default_filters['keywords'], $this->filters['keywords'] );             // Search string

 165  
 166              /*

 167               * Restrict by gender

 168               */
 169              memorize_param( 'gender_men', 'integer', strpos( $this->default_filters['gender'], 'M' ) !== false, strpos( $this->filters['gender'], 'M' ) !== false );
 170              memorize_param( 'gender_women', 'integer', strpos( $this->default_filters['gender'], 'F' ) !== false, strpos( $this->filters['gender'], 'F' ) !== false );
 171  
 172              /*

 173               * Restrict by status

 174               */
 175              memorize_param( 'status_activated', 'string', $this->default_filters['status_activated'], $this->filters['status_activated'] );
 176              memorize_param( 'account_status', 'string', $this->default_filters['account_status'], $this->filters['account_status'] );
 177  
 178              /*

 179               * Restrict by reported state ( was reported or not )

 180               */
 181              memorize_param( 'reported', 'integer', $this->default_filters['reported'], $this->filters['reported'] );
 182  
 183              /*

 184               * Restrict by custom sender email settings

 185               */
 186              memorize_param( 'custom_sender_email', 'integer', $this->default_filters['custom_sender_email'], $this->filters['custom_sender_email'] );
 187              memorize_param( 'custom_sender_name', 'integer', $this->default_filters['custom_sender_name'], $this->filters['custom_sender_name'] );
 188  
 189              /*

 190               * Restrict by user group

 191               */
 192              memorize_param( 'group', 'string', $this->default_filters['group'], $this->filters['group'] );
 193  
 194              /*

 195               * Restrict by locations

 196               */
 197              memorize_param( 'country', 'integer', $this->default_filters['country'], $this->filters['country'] );       // Search country

 198              memorize_param( 'region', 'integer', $this->default_filters['region'], $this->filters['region'] );          // Search region

 199              memorize_param( 'subregion', 'integer', $this->default_filters['subregion'], $this->filters['subregion'] ); // Search subregion

 200              memorize_param( 'city', 'integer', $this->default_filters['city'], $this->filters['city'] );                // Search city

 201  
 202              /*

 203               * Restrict by age group

 204               */
 205              memorize_param( 'age_min', 'integer', $this->default_filters['age_min'], $this->filters['age_min'] );
 206              memorize_param( 'age_max', 'integer', $this->default_filters['age_max'], $this->filters['age_max'] );
 207  
 208              /*

 209               * Restrict by user fields

 210               */
 211              $filters_uf_types = array();
 212              $filters_uf_values = array();
 213              $userfields = !empty( $this->filters['userfields'] ) ? $this->filters['userfields'] : $this->default_filters['userfields'];
 214              foreach( $userfields as $field )
 215              {
 216                  $filters_uf_types[] = $field['type'];
 217                  $filters_uf_values[] = $field['value'];
 218              }
 219              memorize_param( 'criteria_type', 'array', $filters_uf_types, $filters_uf_types );
 220              memorize_param( 'criteria_value', 'array', $filters_uf_values, $filters_uf_values );
 221  
 222              /*

 223               * order:

 224               */
 225              $order = param( $this->order_param, 'string', '' );
 226              $this->order = $order != '' ? $order : $this->filters['order'];
 227              if( $this->order != $this->filters['order'] )
 228              {    // Save order from request
 229                  $this->filters['order'] = $this->order;
 230                  $this->save_filterset();
 231                  $this->refresh_query = true;
 232              }
 233              memorize_param( $this->order_param, 'string', $this->default_filters['order'], $this->order ); // Order

 234  
 235              // 'paged'

 236              memorize_param( $this->page_param, 'integer', 1, $this->page ); // List page number in paged display

 237          }
 238      }
 239  
 240  
 241      /**

 242       * Init filter params from request params

 243       *

 244       * @param boolean do we want to use saved filters ?

 245       * @return boolean true if we could apply a filterset based on Request params (either explicit or reloaded)

 246       */
 247  	function load_from_Request( $use_filters = true )
 248      {
 249          $this->filters = $this->default_filters;
 250  
 251          if( $use_filters )
 252          {
 253              // Do we want to restore filters or do we want to create a new filterset

 254              $filter = param( 'filter', 'string', '' );
 255              switch( $filter )
 256              {
 257                  case 'new':
 258                      $this->refresh_query = true;
 259                      break;
 260  
 261                  case 'reset':
 262                      // We want to reset the memorized filterset:

 263                      global $Session;
 264                      $Session->delete( $this->filterset_name );
 265  
 266                      // Memorize global variables:

 267                      $this->set_filters( array() );
 268                      $this->refresh_query = true;
 269                      // We have applied no filterset:

 270                      return false;
 271                      /* BREAK */

 272  
 273                  case 'refresh':
 274                      $this->refresh_query = true;
 275                      return $this->restore_filterset();
 276  
 277                  default:
 278                      return $this->restore_filterset();
 279              }
 280  
 281              /**

 282               * Filter preset

 283               */
 284              $this->filters['filter_preset'] = param( 'filter_preset', 'string', $this->default_filters['filter_preset'], true );
 285  
 286              // Activate preset default filters if necessary:

 287              $this->activate_preset_filters();
 288          }
 289  
 290          /*

 291           * Restrict by keywords

 292           */
 293          $this->filters['keywords'] = param( 'keywords', 'string', $this->default_filters['keywords'], true );         // Search string

 294  
 295          /*

 296           * Restrict by gender

 297           */
 298          $gender_men = param( 'gender_men', 'boolean', strpos( $this->default_filters['gender'], 'M' ), true );
 299          $gender_women = param( 'gender_women', 'boolean', strpos( $this->default_filters['gender'], 'F' ), true );
 300          if( ( $gender_men && ! $gender_women ) || ( ! $gender_men && $gender_women ) )
 301          {    // Find men OR women
 302              $this->filters['gender'] = $gender_men ? 'M' : 'F';
 303          }
 304          else if( $gender_men && $gender_women )
 305          {    // Find men AND women
 306              $this->filters['gender'] = 'MF';
 307          }
 308  
 309          /*

 310           * Restrict by status

 311           */
 312          $this->filters['account_status'] = param( 'account_status', 'string', $this->default_filters['account_status'], true );
 313          if( $this->filters['account_status'] === $this->default_filters['account_status'] &&
 314              param( 'status_activated', 'boolean', $this->default_filters['status_activated'], true ) )
 315          {
 316              $this->filters['status_activated'] = 'activated';
 317          }
 318          else
 319          {
 320              $this->filters['status_activated'] = $this->default_filters['status_activated'];
 321          }
 322  
 323          /*

 324           * Restrict by reported state ( was reported or not )

 325           */
 326          $this->filters['reported'] = param( 'reported', 'integer', $this->default_filters['reported'], true );
 327  
 328          /*

 329           * Restrict by custom sender email settings

 330           */
 331          $this->filters['custom_sender_email'] = param( 'custom_sender_email', 'integer', $this->default_filters['custom_sender_email'], true );
 332          $this->filters['custom_sender_name'] = param( 'custom_sender_name', 'integer', $this->default_filters['custom_sender_name'], true );
 333  
 334          /*

 335           * Restrict by user group

 336           */
 337          $this->filters['group'] = param( 'group', 'string', $this->default_filters['group'], true );
 338  
 339          /*

 340           * Restrict by locations

 341           */
 342          $this->filters['country'] = param( 'country', 'integer', $this->default_filters['country'], true );
 343          $this->filters['region'] = param( 'region', 'integer', $this->default_filters['region'], true );
 344          $this->filters['subregion'] = param( 'subregion', 'integer', $this->default_filters['subregion'], true );
 345          $this->filters['city'] = param( 'city', 'integer', $this->default_filters['city'], true );
 346  
 347          /*

 348           * Restrict by age group

 349           */
 350          $this->filters['age_min'] = param( 'age_min', 'integer', $this->default_filters['age_min'], true );
 351          $this->filters['age_max'] = param( 'age_max', 'integer', $this->default_filters['age_max'], true );
 352  
 353          /*

 354           * Restrict by user fields

 355           */
 356          $criteria_types = param( 'criteria_type', 'array/integer', array(), true );
 357          $criteria_values = param( 'criteria_value', 'array/string', array(), true );
 358          $userfields = array();
 359          foreach( $criteria_types as $c => $type )
 360          {
 361              $userfields[] = array(
 362                      'type' => $type,
 363                      'value' => $criteria_values[$c]
 364                  );
 365          }
 366          $this->filters['userfields'] = $userfields;
 367  
 368          // 'paged'

 369          $this->page = param( $this->page_param, 'integer', 1, true );      // List page number in paged display

 370  
 371          // 'order'

 372          global $Session;
 373          $prev_filters = $Session->get( $this->filterset_name );
 374          if( !empty( $prev_filters['order'] ) )
 375          {    // Restore an order from saved session
 376              $this->order = $this->filters['order'] = $prev_filters['order'];
 377          }
 378  
 379          if( $use_filters && $filter == 'new' )
 380          {
 381              $this->save_filterset();
 382          }
 383  
 384          return ! param_errors_detected();
 385      }
 386  
 387  
 388      /**

 389       *

 390       *

 391       * @todo count?

 392       */
 393  	function query_init()
 394      {
 395          if( empty( $this->filters ) )
 396          {    // Filters have not been set before, we'll use the default filterset:
 397              // If there is a preset filter, we need to activate its specific defaults:

 398              $this->filters['filter_preset'] = param( 'filter_preset', 'string', $this->default_filters['filter_preset'], true );
 399              $this->activate_preset_filters();
 400  
 401              // Use the default filters:

 402              $this->set_filters( $this->default_filters );
 403          }
 404  
 405          // GENERATE THE QUERY:

 406  
 407          // The SQL Query object:

 408          // If group == -1 we shouldn't group list by user group

 409          $this->query_params['grouped'] = ( $this->filters['group'] != -1 );
 410          $this->UserQuery = new UserQuery( $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname, $this->query_params );
 411          if( isset( $this->query_params['keywords_fields'] ) )
 412          { // Change keywords_fields from query params
 413              $this->UserQuery->keywords_fields = $this->query_params['keywords_fields'];
 414          }
 415          if( isset( $this->query_params['where_status_closed'] ) )
 416          { // Limit by closed users
 417              $this->UserQuery->where_status( 'closed', $this->query_params['where_status_closed'] );
 418          }
 419  
 420          /*

 421           * filtering stuff:

 422           */
 423          $this->UserQuery->where_keywords( $this->filters['keywords'] );
 424          $this->UserQuery->where_gender( $this->filters['gender'] );
 425          $this->UserQuery->where_status( $this->filters['status_activated'] );
 426          $this->UserQuery->where_status( $this->filters['account_status'], true, true );
 427          $this->UserQuery->where_reported( $this->filters['reported'] );
 428          $this->UserQuery->where_custom_sender( $this->filters['custom_sender_email'], $this->filters['custom_sender_name'] );
 429          $this->UserQuery->where_group( $this->filters['group'] );
 430          $this->UserQuery->where_location( 'ctry', $this->filters['country'] );
 431          $this->UserQuery->where_location( 'rgn', $this->filters['region'] );
 432          $this->UserQuery->where_location( 'subrg', $this->filters['subregion'] );
 433          $this->UserQuery->where_location( 'city', $this->filters['city'] );
 434          $this->UserQuery->where_age_group( $this->filters['age_min'], $this->filters['age_max'] );
 435          $this->UserQuery->where_userfields( $this->filters['userfields'] );
 436  
 437          if( $this->get_order_field_list() != '' )
 438          {
 439              $this->UserQuery->order_by( str_replace( '*', $this->get_order_field_list(), $this->UserQuery->order_by ) );
 440          }
 441          else
 442          {
 443              $this->UserQuery->order_by( $this->get_order_field_list() );
 444          }
 445      }
 446  
 447  
 448      /**

 449       * Run Query: GET DATA ROWS *** HEAVY ***

 450       */
 451  	function query()
 452      {
 453          global $DB, $Session, $localtimenow;
 454  
 455          if( !is_null( $this->rows ) )
 456          { // Query has already executed:
 457              return;
 458          }
 459  
 460          // INIT THE QUERY:

 461          $this->query_init();
 462  
 463  
 464          // We are going to proceed in two steps (we simulate a subquery)

 465          // 1) we get the IDs we need

 466          // 2) we get all the other fields matching these IDs

 467          // This is more efficient than manipulating all fields at once.

 468  
 469          // *** STEP 1 ***

 470          $user_IDs = $this->filters['users'];
 471          if( $this->refresh_query || // Some filters are changed
 472              $localtimenow - $Session->get( $this->filterset_name.'_refresh_time' ) > 7200 ) // Time has passed ( 2 hours )
 473          {    // We should create new list of user IDs
 474              global $Timer;
 475              $Timer->start( 'Users_IDs', false );
 476  
 477              $step1_SQL = new SQL();
 478              $step1_SQL->SELECT( 'T_users.user_ID, IF( user_avatar_file_ID IS NOT NULL, 1, 0 ) as has_picture, COUNT( DISTINCT blog_ID ) AS nb_blogs' );
 479              if( !empty( $this->filters['reported'] ) && $this->filters['reported'] )
 480              {    // Filter is set to 'Reported users'
 481                  $step1_SQL->SELECT_add( ', COUNT( DISTINCT urep_reporter_ID ) AS user_rep' );
 482              }
 483              $step1_SQL->FROM( $this->UserQuery->get_from( '' ) );
 484              $step1_SQL->WHERE( $this->UserQuery->get_where( '' ) );
 485              $step1_SQL->GROUP_BY( $this->UserQuery->get_group_by( '' ) );
 486              $step1_SQL->ORDER_BY( $this->UserQuery->get_order_by( '' ) );
 487              $step1_SQL->LIMIT( 0 );
 488  
 489              // Get list of the IDs we need:

 490              $user_IDs = $DB->get_col( $step1_SQL->get(), 0, 'UserList::Query() Step 1: Get ID list' );
 491              // Update filter with user IDs

 492              $this->filters['users'] = $user_IDs;
 493              $this->save_filterset();
 494  
 495              $Timer->stop( 'Users_IDs' );
 496          }
 497  
 498          // GET TOTAL ROW COUNT:

 499          parent::count_total_rows( count( $user_IDs ) );
 500  
 501          // Pagination, Get user IDs from array for current page

 502          $user_IDs_paged = array_slice( $user_IDs, ( $this->page - 1 ) * $this->limit, $this->limit );
 503  
 504          // *** STEP 2 ***

 505          $step2_SQL = $this->UserQuery;
 506  
 507          if( ! empty( $user_IDs_paged ) )
 508          {    // Init sql query to get users by IDs
 509              $step2_SQL->WHERE( $this->Cache->dbIDname.' IN ('.implode( ',', $user_IDs_paged ).') ' );
 510              $step2_SQL->ORDER_BY( 'FIND_IN_SET( user_ID, "'.implode( ',', $user_IDs_paged ).'" )' );
 511          }
 512          else
 513          {    // No users
 514              $step2_SQL->WHERE( 'user_ID IS NULL' );
 515          }
 516  
 517          $this->sql = $step2_SQL->get();
 518  
 519          // ATTENTION: we skip the parent on purpose here!! fp> refactor

 520          DataObjectList2::query( false, false, false, 'UserList::Query() Step 2' );
 521      }
 522  
 523  
 524      /**

 525       * Check if the Result set is filtered or not

 526       */
 527  	function is_filtered()
 528      {
 529          if( empty( $this->filters ) )
 530          {
 531              return false;
 532          }
 533  
 534          // Exclude user IDs

 535          unset( $this->filters['users'] );
 536          unset( $this->default_filters['users'] );
 537  
 538          return ( $this->filters != $this->default_filters );
 539      }
 540  
 541  
 542      /**

 543       * Link to previous and next link in collection

 544       */
 545  	function prevnext_user_links( $params )
 546      {
 547          $params = array_merge( array(
 548                                      'template'     => '$prev$$back$$next$',
 549                                      'prev_start'   => '',
 550                                      'prev_text'    => '&laquo; $login$',
 551                                      'prev_end'     => '',
 552                                      'prev_no_user' => '',
 553                                      'back_start'   => '',
 554                                      'back_end'     => '',
 555                                      'next_start'   => '',
 556                                      'next_text'    => '$login$ &raquo;',
 557                                      'next_end'     => '',
 558                                      'next_no_user' => '',
 559                                      'user_tab'     => 'profile',
 560                                  ), $params );
 561  
 562          // ID of selected user

 563          $user_ID = get_param( 'user_ID' );
 564  
 565          $users_list = $this->filters['users'];
 566          if( array_search( $user_ID, $users_list ) === false )
 567          {    // Selected user is NOT located in this list
 568              return;
 569          }
 570  
 571          $prev = $this->prevnext_user_link( 'prev', $params['prev_start'], $params['prev_end'], $params['prev_text'], $params['prev_no_user'], $params['user_tab'], false );
 572          $next = $this->prevnext_user_link( 'next', $params['next_start'], $params['next_end'], $params['next_text'], $params['next_no_user'], $params['user_tab'], false );
 573          $back = $this->back_user_link( $params['back_start'], $params['back_end'], false );
 574  
 575          $output = str_replace( '$prev$', $prev, $params['template'] );
 576          $output = str_replace( '$next$', $next, $output );
 577          $output = str_replace( '$back$', $back, $output );
 578  
 579          if( !empty( $output ) )
 580          {    // we have some output, lets wrap it
 581              echo( $params['block_start'] );
 582              echo $output;
 583              echo( $params['block_end'] );
 584          }
 585      }
 586  
 587  
 588      /**

 589       * Get link to previous/next user

 590       *

 591       * @return string Link to previous/next user

 592       */
 593  	function prevnext_user_link( $direction, $before = '', $after = '', $text = '&laquo; $login$', $no_user = '', $user_tab = 'profile', $display = true )
 594      {
 595          /**

 596           * @var User

 597           */
 598          $prev_User = & $this->get_prevnext_User( $direction );
 599  
 600          if( !empty( $prev_User ) )
 601          {    // User exists in DB
 602              $output = $before;
 603              $identity_url = get_user_identity_url( $prev_User->ID, $user_tab );
 604              $login = str_replace( '$login$', $prev_User->get_colored_login(), $text );
 605              if( !empty( $identity_url ) )
 606              {    // User link is available
 607                  // Note: we don't want a bubble tip on navigation links

 608                  $output .= '<a href="'.$identity_url.'">'.$login.'</a>';
 609              }
 610              else
 611              {    // No identity link
 612                  $output .= $login;
 613              }
 614              $output .= $after;
 615          }
 616          else
 617          {    // No user
 618              $output = $no_user;
 619          }
 620          if( $display ) echo $output;
 621          return $output;
 622      }
 623  
 624  
 625      /**

 626       * Get link to back users list

 627       *

 628       * @return string Link to back users list

 629       */
 630  	function back_user_link( $before = '', $after = '', $display = true )
 631      {
 632          // ID of selected user

 633          $user_ID = get_param( 'user_ID' );
 634  
 635          $users_list = $this->filters['users'];
 636  
 637          $user_key = array_search( $user_ID, $users_list );
 638          if( is_int( $user_key ) )
 639          {    // Selected user is located in this list
 640              global $Blog;
 641              ++$user_key;
 642              $page = ceil( $user_key / $this->limit );
 643              $page_param = '';
 644              if( $page > 1 )
 645              {
 646                  $page_param = $this->page_param.'='.$page;
 647              }
 648  
 649              $output = $before;
 650              $output .= '<a href="'.get_dispctrl_url( 'users', $page_param ).'">'.$user_key.'/'.count( $users_list ).'</a>';
 651              $output .= $after;
 652          }
 653          else
 654          {
 655              $output = '';
 656          }
 657          if( $display ) echo $output;
 658          return $output;
 659      }
 660  
 661  
 662      /**

 663       * Skip to previous/next User

 664       *

 665       * @param string prev | next  (relative to the current sort order)

 666       */
 667      function & get_prevnext_User( $direction = 'next' )
 668      {
 669          $users_list = $this->filters['users'];
 670  
 671          if( count( $users_list ) < 2 )
 672          {    // Short users list
 673              $r = NULL;
 674              return $r;
 675          }
 676  
 677          // ID of selected user

 678          $user_ID = get_param( 'user_ID' );
 679  
 680          $user_key = array_search( $user_ID, $users_list );
 681          if( is_int( $user_key ) )
 682          {    // Selected user is located in the list
 683              $prevnext_key = $direction == 'next' ? $user_key + 1 : $user_key - 1;
 684              if( isset( $users_list[$prevnext_key] ) )
 685              {    // Prev/next user is located in the list
 686                  $prevnext_ID = $users_list[$prevnext_key];
 687              }
 688          }
 689  
 690          if( empty( $prevnext_ID ) )
 691          {    // No prev/next user
 692              $r = NULL;
 693              return $r;
 694          }
 695  
 696          $UserCache = & get_UserCache();
 697          $User = & $UserCache->get_by_ID( $prevnext_ID, false, false );
 698  
 699          return $User;
 700      }
 701  
 702  
 703      /**

 704       * Set an order of a list (Use this function after when all $this->cols are already defined)

 705       *

 706       * @param string Field name

 707       * @param string Order direction (A|D)

 708       */
 709  	function set_order( $order_field, $direction = 'D' )
 710      {
 711          global $Session;
 712  
 713          if( empty( $this->cols ) )
 714          { // The columns are not defined yet, Exit here
 715              return;
 716          }
 717  
 718          // Force filter param to reset the previous filters

 719          set_param( 'filter', 'new' );
 720          $this->refresh_query = true;
 721  
 722          foreach( $this->cols as $col_num => $col )
 723          {    // Find a column number
 724              if( $col['order'] == $order_field )
 725              {
 726                  break;
 727              }
 728          }
 729  
 730          // Get the filters from Session

 731          $this->filters = $Session->get( $this->filterset_name );
 732          if( ! is_array( $this->filters ) )
 733          {
 734              $this->filters = array();
 735          }
 736          $this->filters = array_merge( $this->default_filters, $this->filters );
 737  
 738          // Rewrite a previous order to new value

 739          $this->filters['order'] = str_repeat( '-', $col_num ).$direction;
 740          $this->order = $this->filters['order'];
 741  
 742          // Save a new order

 743          $Session->set( $this->filterset_name, $this->filters );
 744          $this->save_filterset();
 745      }
 746  
 747  }
 748  
 749  ?>

title

Description

title

Description

title

Description

title

title

Body