You are here

function template_preprocess_author_pane in Author Pane 7.2

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

Process variables for author-pane.tpl.php.

The $variables array contains the following arguments:

  • $variables['account']: User account object.
  • $variables['caller']: (optional) String identifying who called the theme function. Usually the name of the module but doesn't have to be.
  • $variables['picture_preset']: (optional) 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. For users, the user 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.
  • $variables['join_date_type']: The date type the join date should be formated with.

See also

author-pane.tpl.php

File

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

Code

function template_preprocess_author_pane(&$variables) {
  $static =& drupal_static(__FUNCTION__);

  // 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', array(
    'account' => $account,
  ));
  $variables['account_id'] = $account_id;

  /* Avatar */
  $image_style = !empty($variables['picture_preset']) ? $variables['picture_preset'] : '';
  $storage_key = $account_id . ':' . $caller . ':' . $image_style;

  // Use array with a key with account_id:caller:style as storage for the
  // picture, because this function could be called from different callers or
  // with different styles in the same run-time.
  if (!empty($static['user_pictures'][$storage_key])) {
    $variables['picture'] = $static['user_pictures'][$storage_key];
  }
  else {
    $variables['picture'] = theme('author_pane_user_picture', array(
      'account' => $variables['account'],
      'caller' => $caller,
      'picture_preset' => $image_style,
    ));
    $static['user_pictures'][$storage_key] = $variables['picture'];
  }

  /* Join date & online status */
  if ($account_id != 0) {
    $date_type = !empty($variables['join_date_type']) ? $variables['join_date_type'] : 'short';
    $variables['joined'] = format_date($account->created, $date_type);
    $variables['joined_ago'] = format_interval(REQUEST_TIME - $account->created);

    // Online status - uses the settings for the who's online block.
    $variables['last_active'] = $account->access ? format_interval(REQUEST_TIME - $account->access) : t("Never");
    if (_author_pane_is_user_online($account_id)) {
      $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');
}