Here is a class I wrote a while back that retrieves the CB avatar among other thihngs:
[code:1]
<?php
/**
* @author gabe@fijiwebdesign.com
* @copyright (c) fijiwebdesign.com
* @license
fijiwebdesign.com/ajaxchat/license/
* @package ajaxchats
* @name ajaxchat
*/
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
/**
* Ajax Chat Comprofiler integration class
* @package ajaxchat
*/
class ajc_comprofilerProfile {
var $_db; // db object
var $query; // sql
var $err; // error
var $img_dir; // image base dir
var $lang; // configured language
/**
* Constructor
*/
function ajc_comprofilerProfile($db) {
$this->_db = $db;
$this->img_dir = $GLOBALS.'/images/comprofiler/';
$this->lang = 'english';
}
/**
* Returns the cb fields
*/
function userFields($sensitive = array('user_id')) {
$this->query = "SELECT * FROM #__comprofiler_fields AS cf"
."\n WHERE cf.table = '#__comprofiler' AND cf.name != 'NA'";
$this->_db->setQuery($this->query);
$all_fields = $this->_db->loadObjectList();
$this->err = $this->_db->stderr();
// avoid sensitive info
$fields = array();
$tbl = 'cb.';
$n = count($all_fields);
for ($i = 0; $i < $n; $i++) {
/*if (in_array($all_fields[$i]->name, $sensitive)) {
continue; // sensitive data, skip
}*/
$fields[$i]->Field = $tbl.$all_fields[$i]->name;
$fields[$i]->Com = 'com_comprofiler';
}
return $fields;
}
/**
* Set a new Image base dir
*/
function setImgDir($dir) {
$this->img_dir = $dir;
}
/**
* Returns the img src for comprofiler user avatar
* @param string avatar url in db
* @param int comprofiler user id
*/
function avatarUrlByEntry($avatar, $userid) { // internal
if ($avatar && $avatar != '') {
if (!stristr($avatar, 'gallery/')) {
$thumb_url = sefRelToAbs($this->img_dir.'tn'.$avatar);
} else {
$thumb_url = sefRelToAbs($this->img_dir.$avatar);
}
} else {
$thumb_url = sefRelToAbs($GLOBALS.'/components/com_comprofiler/images/'.$this->lang.'/tnnophoto.jpg');
}
return $thumb_url;
}
/**
* Returns the img src for comprofiler user avatar given the user id
* @param int comprofiler user id
*/
function avatarUrlById($userid) { // internal
$this->query = "SELECT c.avatar FROM #__comprofiler as c "
."\n WHERE c.user_id = ".intval($userid)." LIMIT 1";
$this->_db->setQuery($this->query);
$avatar = $this->_db->loadResult();
$this->err = $this->_db->stderr();
return $this->avatarUrlByEntry($avatar, $userid); // return avatar url
}
/**
* Returns the comprofiler details for user by userid
* @param int comprofiler user id
*/
function userDetailsById($userid) {
// allow only published fields
require_once( $GLOBALS.'/components/com_ajaxchat/ajaxchat.config.php' );
global $ajaxChat_config;
$fields = $ajaxChat_config;
if (count($fields) > 0) {
$query = implode(',', $fields);
}
print_r($query);
return;
$this->query = "SELECT u.id, u.name, u.username, u.email, u.usertype, u.gid, u.registerDate, u.lastvisitDate, "
."\n s.guest, s.time, "
."\n a.is_ban, a.ban_by, a.ban_reason, a.last_login, a.karma, a.is_mod, "
."\n c.*, ct.*, aa.* "
."\n FROM #__comprofiler AS c "
."\n LEFT JOIN #__users AS u ON (u.id = c.user_id)"
."\n LEFT JOIN #__session AS s ON (s.userid = u.id)"
."\n LEFT JOIN #__ajax_chat_users as a ON (a.userid = u.id)"
."\n LEFT JOIN #__contact_details as ct ON (ct.user_id = u.id)"
."\n LEFT JOIN #__ajax_chat_connections as aa ON (aa.userid = u.id)"
."\n WHERE c.user_id = ".intval($userid)." LIMIT 1";
$this->_db->setQuery($this->query);
$this->_db->loadObject($row);
$this->err = $this->_db->stderr();
return $row;
}
}
?>
[/code:1]
The part of interest is: avatarUrlById() and avatarUrlByEntry():
[code:1] /**
* Returns the img src for comprofiler user avatar
* @param string avatar url in db
* @param int comprofiler user id
*/
function avatarUrlByEntry($avatar, $userid) { // internal
if ($avatar && $avatar != '') {
if (!stristr($avatar, 'gallery/')) {
$thumb_url = sefRelToAbs($this->img_dir.'tn'.$avatar);
} else {
$thumb_url = sefRelToAbs($this->img_dir.$avatar);
}
} else {
$thumb_url = sefRelToAbs($GLOBALS.'/components/com_comprofiler/images/'.$this->lang.'/tnnophoto.jpg');
}
return $thumb_url;
}
/**
* Returns the img src for comprofiler user avatar given the user id
* @param int comprofiler user id
*/
function avatarUrlById($userid) { // internal
$this->query = "SELECT c.avatar FROM #__comprofiler as c "
."\n WHERE c.user_id = ".intval($userid)." LIMIT 1";
$this->_db->setQuery($this->query);
$avatar = $this->_db->loadResult();
$this->err = $this->_db->stderr();
return $this->avatarUrlByEntry($avatar, $userid); // return avatar url
}[/code:1]
documentation inline...