Is there a way to show Comment Poster Pictures with views?

CommentFileSizeAuthor
#11 Schermata 2010-11-27 a 20.03.53.png40.21 KBGolDRoger

Comments

icecreamyou’s picture

Category: feature » support
Status: Active » Fixed

Comments are rendered using a theme function which you will need to override. Look in your theme; if there is a file called "template.php" then open it, if the file doesn't exist then create it and put this in it:

/**
 * Formats a comment.
 *
 * @param $comment
 *   The comment object.
 * @param $classes
 *   An array of extra classes to include in the comment status wrapper div.
 * @param $destination
 *   The destination query string for edit and delete links. Usually the current
 *   page unless this function is called from a JavaScript callback page.
 * @return
 *   The fully themed status comment or FALSE if the current user does not have
 *   permission to view the comment.
 */
function theme_fbssc_item($comment, $classes = array(), $destination = '') {
  if (!fbssc_can_view($comment)) {
      return FALSE;
  }
  $author = user_load(array('uid' => $comment->uid));
  array_unshift($classes, 'fbssc_comment');
  $classes = implode(' ', $classes);
  $output = '<div class="'. $classes .'">';
  $output .= '<div class="fbssc_author_picture">'. theme('user_picture', $author) .'</div>'; //This is line where the picture is added
  $output .= '<div class="fbssc_author">'. theme('username', $author) .'</div>';
  $comment_text = _facebook_status_run_filter($comment->comment);
  $comment_text = nl2br($comment_text);
  $output .= '<div class="fbssc_text">'. $comment_text .'</div>';
  $output .= '<div class="fbssc_closure">';
  $output .= '<span class="fbssc_time">'. theme('facebook_status_time', $comment->comment_time) .'</span>';
  $q = $_GET['q'];
  if ($destination) {
    $q = $destination;
  }
  elseif (strpos($q, 'fbssc/js') !== FALSE) {
    $q = '<front>';
  }
  if (fbssc_can_edit($comment)) {
    $output .= '<span class="fbssc_edit_delete">'.
      l(t('Edit'), 'statuses/comment/'. $comment->cid .'/edit', array('query' => array('destination' => $q)))
      .'</span>';
  }
  if (fbssc_can_delete($comment)) {
    $output .= '<span class="fbssc_edit_delete">'.
      l(t('Delete'), 'statuses/comment/'. $comment->cid .'/delete', array('query' => array('destination' => $q)))
      .'</span>';
  }
  $output .= '</div></div>';
  //Invokes hook_fbssc_render_alter(&$output, $comment).
  drupal_alter('fbssc_render', $output, $comment);
  return $output;
}

If you're creating the file, don't include the closing ?> tag. If you're adding this to a file that already exists, don't include the opening or closing <?php ?> tags. You will also probably want to use CSS to make the picture display inline, e.g.:

.fbssc_author_picture {
  display: inline;
}

For more info about overriding theme functions, see http://drupal.org/node/173880#function-override and http://drupal.org/node/457740

I think I will probably make this theme function into a template eventually, which will make it slightly easier to override. However, that won't happen for awhile.

baff’s picture

Thanks a lot

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

johnhesston’s picture

Hi IceCreamyou, how would I make user_picture use a preset imagecache picture?

I'm using this code in template.php, but it doesn't work. What am I doing wrong? Please help if you have the time.

function waffles_fbssc($author, $timestamp = NULL, $referer = NULL) {
$output = '

'."\n";
$output .= theme('imagecache', 'thumbnail', $author->picture, $alt, $title, $attributes);
$output .= '
'. theme('username', $author) .'

'."\n";
if ($timestamp) {
$output .= $timestamp ? '

'. t('!time ago', array('!time' => format_interval(time() - $timestamp))) .'

'."\n" : '';
$output .= $referer ? '

'. t('Referer !link', array('!link' => l($referer, $referer))) .'

'."\n" : '';
}
$output .= '

'."\n";
return $output;
}

icecreamyou’s picture

johnhesston, your question is different than the topic of this issue. Feel free to open a new one. In the future, unless you are absolutely sure that the old issue is identical to your new one and the old issue was not resolved, please open a new issue instead of reopening a closed one and give links to similar older issues you found when searching.

glitz’s picture

After following these instructions exactly, I am getting the following when going to my site...

Fatal error: Cannot redeclare theme_fbssc_item() (previously declared in /home2/pulsepos/public_html/sites/all/modules/fbssc/fbssc.module:140) in /home2/pulsepos/public_html/sites/all/themes/zeropoint/template.php on line 741

i made sure the php tags were not included in this already created file

Is this just releated to the theme I using, Or is there something in the code I need to change. I would really like to get users avatars to appear in fbssc

glitz’s picture

Status: Closed (fixed) » Active
icecreamyou’s picture

Status: Active » Closed (fixed)

theme_fbssc_item() is the function you have to override. In your template.php it should be declared as either MYTHEMENAME_fbssc_item() (recommended) or MYTHEMEENGINE_fbssc_item().

glitz’s picture

any luck with this? I have comments to appear but need a smaller version I have stored in image cache

GolDRoger’s picture

Hi Ice, can I ask you a question please?

I've used your script and declaring correctly the funcion in

function framework_fbssc_item($comment, $classes = array(), $destination = '') {

(framework is my currently theme in use)

but nothing happens adding this in template.php, post are appearing without the thumbnail of the post commenter (for the images i use the default drupal system, not cck or other).

Maybe i have to do something other to make it working?
That's strange because when i add in the view poster picture, the image appear.

thx

GolDRoger’s picture

StatusFileSize
new40.21 KB

Sorry i forgot to attach the image

GolDRoger’s picture

Problem solved, I've discovered why it wasn't appearing. Just runned update.php and pics was showed near posts.

Michsk’s picture

Ice: dont get mad at me, i know you wanted a new issue but i really think we can keep this in here.

Here's howto use imagecache.

theme('imagecache','IMAGECACHE_PROFILE_TO_USE', $author->picture, $alt, $title, $attributes)