You are here

function theme_shoutbox_post in Shoutbox 6.2

Same name and namespace in other branches
  1. 5 shoutbox.module \theme_shoutbox_post()
  2. 6 shoutbox.module \theme_shoutbox_post()
  3. 7.2 shoutbox.theme.inc \theme_shoutbox_post()
  4. 7 shoutbox.theme.inc \theme_shoutbox_post()

Theme function for shoutbox posts.

Parameters

shout: The shout to be themed.

links: Links of possible actions that can be performed on this shout by the current user.

4 theme calls to theme_shoutbox_post()
shoutbox_delete_form in ./shoutbox.pages.inc
Shout delete confirmation form
shoutbox_display_posts in ./shoutbox.module
Output existing shoutbox posts as html.
shoutbox_publish_form in ./shoutbox.pages.inc
Shout publish confirmation form
shoutbox_unpublish_form in ./shoutbox.pages.inc
Shout unpublish confirmation form

File

./shoutbox.theme.inc, line 56
Theme callbacks for the shoutbox module.

Code

function theme_shoutbox_post($shout, $links = array()) {
  global $user;

  // Gather moderation links
  if ($links) {
    foreach ($links as $link) {
      $linkattributes = $link['linkattributes'];
      $link_html = '<img src="' . $link['img'] . '"  width="' . $link['img_width'] . '" height="' . $link['img_height'] . '" alt="' . $link['title'] . '" class="shoutbox-imglink"/>';
      $link_url = 'shout/' . $shout->shout_id . '/' . $link['action'];
      $img_links = l($link_html, $link_url, array(
        'html' => TRUE,
        'query' => array(
          'destination' => drupal_get_path_alias($_GET['q']),
        ),
      )) . $img_links;
    }
  }

  // Generate user name with link
  $user_name = shoutbox_get_user_link($shout);

  // Generate title attribute
  $title = t('Posted !date at !time by !name', array(
    '!date' => format_date($shout->created, 'custom', 'm/d/y'),
    '!time' => format_date($shout->created, 'custom', 'h:ia'),
    '!name' => $shout->nick,
  ));

  // Add to the shout classes
  $shout_classes = array();
  $shout_classes[] = 'shoutbox-msg';

  // Check for moderation
  if ($shout->moderate == 1) {
    $shout_classes[] = 'shoutbox-unpublished';
    $approval_message = '&nbsp;(' . t('This shout is waiting for approval by a moderator.') . ')';
  }

  // Check for specific user class
  $user_classes = array();
  $user_classes[] = 'shoutbox-user-name';
  if ($shout->uid == $user->uid) {
    $user_classes[] = 'shoutbox-current-user-name';
  }
  else {
    if ($shout->uid == 0) {
      $user_classes[] = 'shoutbox-anonymous-user';
    }
  }

  // Build the post
  $post = '';
  $post .= '<div class="' . implode(' ', $shout_classes) . '" title="' . $title . '">';
  $post .= '<div class="shoutbox-admin-links">' . $img_links . '</div>';
  $post .= '<span class="' . implode(' ', $user_classes) . '">' . $user_name . '</span>:&nbsp;';
  $post .= '<span class="shoutbox-shout">' . $shout->shout . $approval_message . '</span>';
  $post .= '<span class="shoutbox-msg-time">';
  $format = variable_get('shoutbox_time_format', 'ago');
  switch ($format) {
    case 'ago':
      $post .= t('!interval ago', array(
        '!interval' => format_interval(time() - $shout->created),
      ));
      break;
    case 'small':
    case 'medium':
    case 'large':
      $post .= format_date($shout->created, $format);
      break;
  }
  $post .= '</span>';
  $post .= '</div>' . "\n";
  return $post;
}