Projet

Général

Profil

Révision 6c9579f7

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/author_pane/author_pane.module
41 41
 * Implements hook_block_info().
42 42
 */
43 43
function author_pane_block_info() {
44
  // TODO Rename block deltas (e.g. delta-0) to readable strings.
44
  // TODO Rename block deltas (e.g., delta-0) to readable strings.
45 45
  $blocks['delta-0']['info'] = t('Author Pane');
46 46

  
47 47
  // We don't want the block to cache since what is displayed depends on
......
225 225
    // Online status - uses the settings for the who's online block.
226 226
    $variables['last_active'] = ($account->access) ? format_interval(REQUEST_TIME - $account->access) : t("Never");
227 227

  
228
    if ((REQUEST_TIME -$account->access) < variable_get('user_block_seconds_online', 900)) {
228
    if (_author_pane_is_user_online($account_id)) {
229 229
      $variables['online_status'] = t('Online');
230 230
      $variables['online_status_class'] = 'author-online';
231 231
    }
......
385 385
  }
386 386

  
387 387
  return TRUE;
388
}
388
}
389

  
390
/**
391
 * Help function for Author Pane to check if a user is online.
392
 *
393
 * @param int $uid
394
 *  A user id of the user to check if is online.
395
 * @return
396
 *  TRUE if the user is onlie, else FALSE.
397
 */
398
function _author_pane_is_user_online($uid) {
399
  global $user;
400
  // Use a static to save database calls,
401
  // if this function is called for the same user more then once.
402
  $static = &drupal_static(__FUNCTION__);
403

  
404
  if (isset($static[$uid])) {
405
    return $static[$uid];
406
  }
407

  
408
  // If current users is not anonymous and is watching its own author pane then the user is online.
409
  if ($user->uid != 0 && $user->uid == $uid) {
410
    return $static[$uid] = TRUE;
411
  }
412

  
413
  // How long back to check if the user has been active.
414
  $time = REQUEST_TIME - variable_get('user_block_seconds_online', 900);
415

  
416
  // Check if the user has a session active and that it has been used for the last $time ago.
417
  if (db_query("SELECT 1 FROM {sessions} WHERE uid = :uid and timestamp > :time", array(':uid' => $uid, ':time' => $time))->fetchField()) {
418
    return $static[$uid] = TRUE;
419
  }
420

  
421
  return $static[$uid] = FALSE;
422
}

Formats disponibles : Unified diff