You are here

function template_preprocess_author_pane in Author Pane 6.2

Same name and namespace in other branches
  1. 5 author_pane.module \template_preprocess_author_pane()
  2. 6 author_pane.module \template_preprocess_author_pane()
  3. 7.2 author_pane.module \template_preprocess_author_pane()

Preprocesses template variables for the author info template.

Available variables (All optional except 'account'): $variables['account']: User account object. $variables['caller']: String identifying who called the theme function. Usually the name of the module but doesn't have to be. $variables['picture_preset']: Imagecache preset to use to format the user picture. $variables['context']: Information about where the Author Pane will be appearing. For nodes, this will be the node object. For comments, the comment object. $variables['disable_css']: TRUE if the preprocess should skip loading the default CSS. This is used by modules such as AF that has its own CSS.

File

./author_pane.module, line 155
Gathers information from user related modules into one template.

Code

function template_preprocess_author_pane(&$variables) {

  // Indicates who called the theme function.
  $caller = !empty($variables['caller']) ? $variables['caller'] : '';

  /* Add CSS */
  if (empty($variables['disable_css'])) {

    // Some modules have their own Author Pane CSS. Because Author Pane is
    // called in a theme function, this CSS would get added after and clobber
    // the CSS in those modules. So we don't load the CSS in that case.
    drupal_add_css(drupal_get_path('module', 'author_pane') . '/author_pane.css');
  }

  /* Account ID & Name */

  // This $account refers to the user whose info is in the pane.
  $variables['account']->uid = empty($variables['account']->uid) ? 0 : $variables['account']->uid;
  $account = $variables['account'];
  $account_id = $account->uid;
  $variables['account_name'] = theme('username', $account);
  $variables['account_id'] = $account_id;

  /* Avatar */
  static $user_pictures;
  if (!empty($user_pictures[$account_id])) {

    // This user's picture is cached so pull it from there.
    $variables['picture'] = $user_pictures[$account_id];
  }
  else {
    $preset = !empty($variables['picture_preset']) ? $variables['picture_preset'] : '';
    $variables['picture'] = theme('author_pane_user_picture', $variables['account'], $caller, $preset);
    $user_pictures[$account_id] = $variables['picture'];
  }

  /* Join date & online status */
  if ($account_id != 0) {

    // Join date (uses short date format) / since
    $just_date = str_replace(array(
      'H:i',
      'g:ia',
      ' - ',
    ), '', variable_get('date_format_short', 'm/d/Y - H:i'));
    $variables['joined'] = format_date($account->created, 'custom', $just_date);
    $variables['joined_ago'] = format_interval(time() - $account->created);

    // Online status - uses the settings for the who's online block.
    $variables['last_active'] = $account->access ? format_interval(time() - $account->access) : t("Never");
    if (time() - $account->access < variable_get('user_block_seconds_online', 900)) {
      $variables['online_status'] = t('Online');
      $variables['online_status_class'] = 'author-online';
    }
    else {
      $variables['online_status'] = t('Offline');
      $variables['online_status_class'] = 'author-offline';
    }
  }
  else {

    // Set the variables to empty to avoid notices when the template is displayed.
    $variables['joined'] = $variables['joined_ago'] = $variables['online_class'] = $variables['online_status'] = '';
  }

  // This variable is no longer used, but previous integrations are expecting
  // it. Pass it the path to the images so they don't break.
  $variables['image_path'] = drupal_get_path('module', 'author_pane') . '/images';

  // Load up all the integration files from other modules.
  author_pane_include('author-pane.inc');
}