/** * Gets the user avatar of the selected <code>system</code> * * @param string $system Avatar system to be used * @param int $userid user id * @param string $username username or name * @param int $height height of the avatar * * @return string user avatar */ public static function get_user_avatar($system, $userid, $displayname = 'username', $height = 48, $email = null, $attribs = array(), $img_attribs = array()) { $db = JFactory::getDBO(); $avatar = ''; $userid = !empty($userid) ? $userid : 0; switch ($system) { case 'cjblog': $api = JPATH_ROOT . DS . 'components' . DS . 'com_cjblog' . DS . 'api.php'; if (file_exists($api)) { include_once $api; $avatar = CjBlogApi::get_user_avatar($userid, $height, $displayname, $attribs, $img_attribs); } break; case 'jomsocial': if (!$userid) { return CjFunctions::get_user_avatar('gravatar', $userid, $displayname, $height, $email, $attribs, $img_attribs); } include_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'defines.community.php'; require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php'; require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'string.php'; $user = CFactory::getUser($userid); $name = CStringHelper::escape($user->getDisplayName()); $userLink = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid); $img_attribs['height'] = $height . 'px'; $img_attribs['style'] = isset($img_attribs['style']) ? $img_attribs['style'] . '; max-height: ' . $height . 'px' : 'max-height: ' . $height . 'px'; $avatar_image = JHtml::image($user->getThumbAvatar(), $name, $img_attribs); $avatar = $userid > 0 ? JHtml::link($userLink, $avatar_image, $attribs) : JHtml::link('#', $avatar_image, $attribs); break; case 'cb': global $_CB_framework, $_CB_database, $ueConfig, $mainframe; $api = JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php'; if (!is_file($api)) { return; } require_once $api; cbimport('cb.database'); cbimport('cb.tables'); cbimport('cb.field'); cbimport('language.front'); outputCbTemplate($_CB_framework->getUi()); $img_attribs['height'] = $height . 'px'; $img_attribs['style'] = isset($img_attribs['style']) ? $img_attribs['style'] . '; max-height: ' . $height . 'px' : 'max-height: ' . $height . 'px'; if ($userid > 0) { $cbUser = CBuser::getInstance($userid); if ($cbUser !== null) { $avatar = $cbUser->getField('avatar', null, 'php', 'profile', 'list'); $name = $cbUser->getField('name'); $link = cbSef('index.php?option=com_comprofiler&task=userProfile&user='******'avatar'], '', $img_attribs), $attribs); } } else { if ($height <= 90) { $avatar = JHtml::link('#', Jhtml::image(selectTemplate() . 'images/avatar/tnnophoto_n.png', '', $img_attribs), $attribs); } else { $avatar = JHtml::link('#', Jhtml::image(selectTemplate() . 'images/avatar/nophoto_n.png', '', $img_attribs), $attribs); } } break; case 'touch': $avatarLoc = JURI::base(true) . '/index2.php?option=com_community&controller=profile&task=avatar&width=' . $height . '&height=' . $height . '&user_id=' . $userid . '&no_ajax=1'; $avatar = '<img src="' . $avatarLoc . '" style="border: 1px solid #cccccc; height: "' . $height . '"px;" alt=""/>'; $link = JRoute::_("index.php?option=com_community&view=profile&user_id={$userid}&Itemid=" . JRequest::getInt('Itemid')); $avatar = '<a href="' . $link . '">' . $avatar . '</a>'; break; case 'gravatar': if (null == $email && $userid > 0) { $strSql = 'SELECT email FROM #__users WHERE id=' . $userid; $db->setQuery($strSql); $email = $db->loadResult(); } $avatar = '<img src="https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s=' . $height . '&d=mm&r=g"/>'; break; case 'kunena': if (CJFunctions::_initialize_kunena()) { $class = 'avatar'; $user = KunenaFactory::getUser($userid); $avatarHtml = $user->getAvatarImage($class, $height, $height); $avatar = $user->getLink($avatarHtml); } else { if (file_exists(JPATH_ROOT . DS . 'components' . DS . 'com_kunena' . DS . 'class.kunena.php')) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_kunena' . DS . 'class.kunena.php'; require_once JPATH_ROOT . DS . 'components' . DS . 'com_kunena' . DS . 'lib' . DS . 'kunena.link.class.php'; $kunena_user = KunenaFactory::getUser((int) $userid); $displayname = $kunena_user->getName(); // Takes care of realname vs username setting $avatarlink = $kunena_user->getAvatarLink('', $height, $height); $avatar = CKunenaLink::GetProfileLink($userid, $avatarlink, $displayname); } } break; case 'aup': $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; if (file_exists($api_AUP)) { require_once $api_AUP; $avatar = AlphaUserPointsHelper::getAupAvatar($userid, 1, $height, $height); } break; case 'easysocial': $api = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_easysocial' . DS . 'includes' . DS . 'foundry.php'; if (file_exists($api)) { require_once $api; $my = Foundry::user($userid); $img_attribs[] = array('style' => 'max-height: ' . $height . 'px'); $avatar_image = JHtml::image($my->getAvatar(SOCIAL_AVATAR_MEDIUM), $my->getName(), $img_attribs); $profile_url = FRoute::profile(array('id' => $my->getAlias())); $avatar = JHtml::link($profile_url, $avatar_image, $attribs); } break; } return $avatar; }