You are here

function commons_activity_streams_tokens in Drupal Commons 7.3

Implements hook_tokens().

File

modules/commons/commons_activity_streams/commons_activity_streams.module, line 243

Code

function commons_activity_streams_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'user' && isset($data['user'])) {
    $account = $data['user'];

    // Generate suitable alternative text using the user's username.
    $username = format_username($account);
    $alt = t("@name's picture", array(
      '@name' => $username,
    ));
    foreach ($tokens as $token => $original) {
      if (strpos($token, 'picture:') !== FALSE) {
        list(, $style) = explode(':', $token);

        // Prefer unique account pictures but fall back to the default user
        // picture if necessary.
        $path = $account->picture ? $account->picture->uri : variable_get('user_picture_default', '/profiles/commons/images/avatars/user-avatar.png');
        $image_variables = array(
          'path' => image_style_url($style, $path),
          'alt' => $alt,
          'title' => $alt,
          'class' => array(
            'image-style-none',
          ),
        );
        $image = theme('image', $image_variables);
        $user_path = user_uri($account);
        $link_options = array(
          'attributes' => array(
            'title' => t('View user profile.'),
          ),
          'html' => TRUE,
        );
        $replacements[$original] = "<div class='user-picture'>" . l($image, $user_path['path'], $link_options) . "</div>";
      }
    }
  }
  return $replacements;
}