View Single Post
10-07-2011, 08:50 AM   #6
wacnstac
Member
 
Join Date: Feb 2011
Posts: 58
Rep Power: 14
wacnstac is getting browny points
I ended up modifying the get_avatar function with the following so I could pass in a user's vb id and get it to work correctly:

PHP Code:
function get_post_avatar($u$size '96'$default ''$alt false )
{
    global 
$vb;
    global 
$firephp;
    
    
/*    if (!is_numeric($u->user_id)) { return; }  */ 
    
if (!is_numeric($u['userid'])) { return; }    

/*    $user = fetch_userinfo($u->user_id);  */ 
    
$user fetch_userinfo($u['userid']);

    if (
$avatar $vb->db->query_first("SELECT dateline, width, height FROM " TABLE_PREFIX "customavatar WHERE userid=" intval($user['userid'])))
    {
        
$safe_alt esc_attr($user['username']);

        
// using a custom avatar
        
if ($vb->options['usefileavatar'])
        {
            
$user['avatarurl'] = $vb->options['avatarurl'] . '/avatar' $user['userid'] . '_' $user['avatarrevision'] . '.gif';
        }

        else
        {
            
$user['avatarurl'] = $vb->options['bburl'] . '/image.php?' $vb->session->vars['sessionurl'] . 'u=' $user['userid'] . "&dateline=$avatar[dateline]";
        }

        
$default $user['avatarurl'];

        
$user['avatarurl'] = "<a class='vbridge_avatar_link' href='" $vb->options['bburl'] . "/member.php?u={$user['userid']}'><img alt='{$safe_alt}' src='{$user[avatarurl]}' class='avatar avatar-{$size} photo avatar-default' width='{$size}' height='{$size}' border='0'/></a>";
    }


    
/*    return apply_filters('get_avatar', $user['geturl'], $u, $size, $default, $user['username']);   */
    
return ($user['avatarurl']);

I found out later that this caused an error in the word press backend when editing comments. I restored the get_avatar function to the old code to fix this, and renamed by new function. Two questions.

1. It sounds like I should be able to use the same function for both if I can figure out how to create a user object. Can you give me a little tutorial on how to do that?

2. How is the get_avatar function called in the WP commenting backend? I don't really see it in the code and avatars are not being associated with the comments in the backend.

3. I lied, one more.... I would also like to display the avatar of each user who comments on a post as in this page:

http://www.michigan-sportsman.com/ms...an-youth-hunt/

But I don't know what to pass from this template function to make that happen. You can see my attempts at trying to get a comment author which have failed.

PHP Code:
class thesis_comment_meta extends thesis_comment {
    function 
build($comment) {
        global 
$thesis_design;
        
$this->meta $thesis_design->comments['comments']['options']['meta'];

        if (
is_array($this->meta)) {
            foreach (
$this->meta as $element_name => $element)
                if (
$element['show']) $output .= call_user_func(array($this$element_name), $comment) . "\n";
        }

        
thesis_hook_before_comment_meta();
        if (
$output) echo $output;
        
thesis_hook_after_comment_meta();
    }

    function 
author($comment) {
        return 
"<span class=\"comment_author\">" get_comment_author_link() . "</span>";
    }

    function 
avatar($comment) {
        global 
$vb;
        global 
$firephp;
        
    

        
$username $comment['comment_author'];
        
        
$firephp->log($comment,'Comment');
        
        
        if (
is_object($vb)) 
        { 
            
$vb_user_record $vb->db->query_first("SELECT * from " TABLE_PREFIX "user where username = '" $vb->db->escape_string($username) . "'");        
        }
        
$vb_userid $vb_user_record["userid"];
        

        
$avatar get_post_avatar($vb_user_record);
        
        
//        $avatar = get_avatar(get_comment_author_email(), $this->meta['avatar']['options']['size'], '');
        
$author_url get_comment_author_url();
        
$avatar_output = (empty($author_url) || $author_url == 'http://') ? $avatar "<a href=\"$author_url\" rel=\"nofollow\">$avatar</a>";
        return 
'<span class="avatar">' apply_filters('thesis_avatar'$avatar_output) . '</span>'#filter
    
}

    function 
date($comment) {
        
$timestamp = ($this->meta['date']['options']['time']) ? sprintf(__('%1$s at %2$s'), get_comment_date(stripslashes($this->meta['date']['options']['date_format'])), get_comment_time()) : get_comment_date(stripslashes($this->meta['date']['options']['date_format']));
        
$text = ($this->meta['number']['show']) ? $timestamp '<a href="#comment-' get_comment_ID() . '" title="Permalink to this comment" rel="nofollow">' $timestamp '</a>';
        return 
'<span class="comment_time">' apply_filters('thesis_comment_date'$text) . '</span>'#filter
    
}

    function 
number($comment) {
        if (!
$GLOBALS['comment_vars']) return; else $c $GLOBALS['comment_vars'];
        
$number = ($c['current'] - 1) * $c['per_page'] + did_action('thesis_hook_before_comment_meta') + 1;
        return 
'<span class="comment_num"><a href="#comment-' get_comment_ID() . "\" title=\"Permalink to this comment\" rel=\"nofollow\">$number</a></span>";
    }

    function 
edit($comment) {
        if (
get_edit_comment_link()) return '<span class="edit_comment">' apply_filters('thesis_edit_comment_link''<a href="' get_edit_comment_link() . '" rel="nofollow">' __('edit''thesis') . '</a>') . '</span>'#filter
    
}

wacnstac is offline   Reply With Quote