JoomlaComment and JomSocial integration

Many of you have requested the possibility to show jomsocial avatar in comments. Now I finally found the time to install jomSocial and to write the necessary code for this. You will find the option to show jomsocial avatar in the next version of joomlacomment, but for those who are not afraid to make changes to comment.class.php and want to test the code you are welcome to do so.

The first thing you will need to do is to open comment.class.php and go around line 2262 (this is the post_htmlCode function): Find this code:
if ($this->_avatar) {
if(JString::strpos($this->_avatar,"gallery/")===false) {
$path = JURI::base()."/images/comprofiler/tn$this->_avatar";
} else {

$path = JURI::base()."/images/comprofiler/$this->_avatar";
}

$html     = str_replace('{avatar_picture}', $this->profileLink("<img class='avatar' src='$path' alt='avatar' />", $this->_user_id), $html);
} else if ($this->_gravatar) {
$gravatar_email = $this->_item['email'];
$default = JURI::base().'components/com_comment/assets/images/nophoto.jpg';
$size = 60;
// Prepare the gravatar image
$path = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($gravatar_email)).
"&amp;default=".urlencode($default)."&amp;size=".$size;

$html = str_replace('{avatar_picture}', $this->profileLink("<img class='avatar' src='$path' alt='avatar' />", $this->_user_id), $html);
}

and change it to this:

//if ($this->_avatar) {
//            if(JString::strpos($this->_avatar,"gallery/")===false) {
//                $path = JURI::base()."/images/comprofiler/tn$this->_avatar";
//            } else {
//    
//                    $path = JURI::base()."/images/comprofiler/$this->_avatar";
//            }
//    
//            $html     = str_replace('{avatar_picture}', $this->profileLink("<img class='avatar' src='$path' alt='avatar' />", $this->_user_id), $html);
//        } else if ($this->_gravatar) {
//            $gravatar_email = $this->_item['email'];
//            $default = JURI::base().'components/com_comment/assets/images/nophoto.jpg';
//            $size = 60;
//            // Prepare the gravatar image
//            $path = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($gravatar_email)).
//                        "&amp;default=".urlencode($default)."&amp;size=".$size;
//    
//            $html = str_replace('{avatar_picture}', $this->profileLink("<img class='avatar' src='$path' alt='avatar' />", $this->_user_id), $html);
//        }

Now after the above code add this:

$path = JURI::root() . $this->jomSocialAvatar($this->_item['userid']);
$html = str_replace('{avatar_picture}', $this->jomSocialProfileLink("<img class='avatar' src='$path' alt='avatar' />", $this->_item['userid']), $html);

After the closing bracet "{" of the post_htmlCode function add those 2 functions:

function jomSocialProfileLink($s, $id) {
if ($id) {
$link = JRoute::_('index.php?option=com_community&view=profile&userid='.$id);
return "<a href='$link'>".$s."</a>";
} else {
return $s;
}

}
function jomSocialAvatar ($id) {
if($id) {
$database =& JFactory::getDBO();

$query = 'SELECT thumb FROM #__community_users WHERE userid = ' . $id;
$database->setQuery($query);
$result = $database->loadObject();
return $result->thumb;
} else {
return 'components/com_community/assets/default_thumb.jpg';
}
}

This should be everything! Don't forget to enable the use of avatar in the backend. Please report back! I've tested this code on a system with only one account - the administrator one :) I will be happy to hear that it works as well on a community website :)