You are here

function shoutbox_get_user_link in Shoutbox 7.2

Same name and namespace in other branches
  1. 6.2 shoutbox.module \shoutbox_get_user_link()
  2. 7 shoutbox.module \shoutbox_get_user_link()

Generate a linked user name for displaying on a shout post.

Parameters

$shout: A shout object

Return value

A user name which links to the user profile

1 call to shoutbox_get_user_link()
theme_shoutbox_post in ./shoutbox.theme.inc
Theme function for shoutbox posts.

File

./shoutbox.module, line 363
Shoutbox module displays a block for users to create short messages for the whole site. Uses AHAH to update the database and display content.

Code

function shoutbox_get_user_link($shout) {
  $link = '';
  if ($shout->uid > 0) {

    // See if we can use a custom profile field for the name.
    if ($field = variable_get('shoutbox_profile_name', '')) {
      $aElements = explode("<split>", $field);
      if (count($aElements) == 2) {
        if ($aElements[0] == "profile") {
          $name = db_query("SELECT v.value FROM {profile_value} v INNER JOIN {profile_field} f ON v.fid = f.fid\n    WHERE f.name = :name AND v.uid = :uid", array(
            ':name' => $aElements[1],
            ':uid' => $shout->uid,
          ))
            ->fetchField();
          $shout->nick = $name ? $name : $shout->nick;
        }
        elseif ($aElements[0] == "custom") {
          $name = db_query("SELECT f.field_" . $aElements[1] . "_value FROM field_data_field_" . $aElements[1] . " as f\n    WHERE f.entity_type='user' AND f.bundle='user'\n    AND f.entity_id=:id", array(
            ':id' => $shout->uid,
          ))
            ->fetchField();
          $shout->nick = $name ? $name : $shout->nick;
        }
      }
    }
  }

  // Build object that theme_username can use.
  $object = new stdClass();
  $object->uid = $shout->uid;
  $object->name = $shout->nick;
  return theme('username', array(
    'account' => $object,
  ));
}