You are here

function theme_privatemsg_user_picture in Privatemsg 5.3

Same name and namespace in other branches
  1. 5 privatemsg.module \theme_privatemsg_user_picture()
2 theme calls to theme_privatemsg_user_picture()
privatemsg_list_form in ./privatemsg.module
theme_privatemsg_view in ./privatemsg.module
Returns content to view a private message.

File

./privatemsg.module, line 2482

Code

function theme_privatemsg_user_picture($account) {
  if (variable_get('user_pictures', 0)) {
    if ($account->picture && file_exists($account->picture)) {
      if (arg(0) == 'user' && is_numeric(arg(1))) {

        // If on user profile page
        $picture = file_create_url($account->picture);
      }
      else {

        // somewhere else on the site - use small pic
        $info = image_get_info($account->picture);
        $newpicture = dirname($account->picture) . '/picture-' . $account->uid . "-avatar." . $info['extension'];
        if (!file_exists($newpicture) || filectime($newpicture) < filectime($account->picture)) {
          image_scale($account->picture, $newpicture, 64, 64);
          if (!file_exists($newpicture)) {
            $newpicture = $account->picture;
          }
        }
        $picture = file_create_url($newpicture);
      }
    }
    else {
      if (variable_get('user_picture_default', '')) {
        $picture = variable_get('user_picture_default', '');
      }
    }
    if (isset($picture)) {
      $alt = t("@user's picture", array(
        '@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous')),
      ));
      $picture = theme('image', $picture, $alt, $alt, '', FALSE);
      if (!empty($account->uid) && user_access('access user profiles')) {
        $picture = l($picture, "user/{$account->uid}", array(
          'title' => t('View user profile.'),
        ), NULL, NULL, FALSE, TRUE);
      }
      if (variable_get('privatemsg_online_status', 1)) {

        // code to show online/offline status
        $time_period = variable_get('user_block_seconds_online', 1200);
        $uid = $account->uid;

        // get the current userid for the avatar.
        $users = db_query("SELECT uid, name, access FROM {users} WHERE access >= %d AND uid = %s", time() - $time_period, $uid);
        $total_users = db_num_rows($users);
        if ($total_users == 1) {
          $output = '<span style="color: #00DD45; font-weight: bold; display:block;">' . t('Online') . '</span>';
        }
        else {
          $output = '<span style="color: #AA4444; display:block;">' . t('Offline') . '</span>';
        }
      }
      return '<div class="picture">' . $output . $picture . '</div>';
    }
  }
}