Esempio n. 1
0
 /**
  * Gets the user avatar image without any link
  * 
  * @param unknown $system
  * @param unknown $userid
  * @param unknown $alt
  * @param number $height
  * @param string $email
  * @param string $path_only
  * @param unknown $attribs
  * @return void|Ambigous <string, unknown, NULL, string>
  */
 public static function get_user_avatar_image($system, $userid, $alt, $height = 48, $email = null, $path_only = true, $attribs = array())
 {
     $db = JFactory::getDBO();
     $avatar = '';
     $userid = !empty($userid) ? $userid : 0;
     switch ($system) {
         case 'cjforum':
             $api = JPATH_ROOT . '/components/com_cjforum/helpers/api.php';
             if (file_exists($api)) {
                 require_once $api;
                 $avatar = CjForumApi::get_user_avatar_image($userid, $height);
                 if ($path_only == false) {
                     $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($attribs) ? JArrayHelper::toString($attribs) : $attribs) . ' /') . '>';
                 }
             }
             break;
         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_image($userid, $height);
                 if ($path_only == false) {
                     $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($attribs) ? JArrayHelper::toString($attribs) : $attribs) . ' /') . '>';
                 }
             }
             break;
         case 'jomsocial':
             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);
             $avatar = $user->getThumbAvatar();
             if ($path_only == false) {
                 $attribs['height'] = $height . 'px';
                 $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($attribs) ? JArrayHelper::toString($attribs) : $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());
             //TODO: Here
             $img_attribs['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');
                     $avatar = $avatar['avatar'];
                     if ($path_only == false) {
                         $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($attribs) ? JArrayHelper::toString($attribs) : $attribs) . ' /') . '>';
                     }
                 }
             } else {
                 if ($height <= 90) {
                     $avatar = $path_only ? selectTemplate() . 'images/avatar/tnnophoto_n.png' : Jhtml::image(selectTemplate() . 'images/avatar/tnnophoto_n.png', '', $img_attribs);
                 } else {
                     $avatar = $path_only ? selectTemplate() . 'images/avatar/nophoto_n.png' : Jhtml::image(selectTemplate() . 'images/avatar/nophoto_n.png', '', $img_attribs);
                 }
             }
             break;
         case 'touch':
             $avatarLoc = JURI::base(true) . '/index2.php?option=com_community&amp;controller=profile&amp;task=avatar&amp;width=' . $height . '&amp;height=' . $height . '&amp;user_id=' . $userid . '&amp;no_ajax=1';
             $attribs[] = array('style' => 'height: ' . $height . 'px');
             $avatar = $path_only ? $avatarLoc : JHtml::image($avatarLoc, $alt, $attribs);
             break;
         case 'gravatar':
             if (null == $email && $userid > 0) {
                 $strSql = 'SELECT email FROM #__users WHERE id=' . $userid;
                 $db->setQuery($strSql);
                 $email = $db->loadResult();
             }
             $avatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s=' . $height . '&d=mm&r=g';
             if ($path_only == false) {
                 $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($attribs) ? JArrayHelper::toString($attribs) : $attribs) . ' /') . '>';
             }
             break;
         case 'kunena':
             if (CJFunctions::_initialize_kunena()) {
                 $class = 'avatar';
                 $user = KunenaFactory::getUser($userid);
                 $avatar = $user->getAvatarImage($class, $height, $height);
                 if ($path_only) {
                     preg_match_all('/<img .*src=["|\']([^"|\']+)/i', $avatar, $matches);
                     foreach ($matches[1] as $key => $value) {
                         $avatar = $value;
                         break;
                     }
                 }
             }
             break;
         case 'aup':
             $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php';
             if (file_exists($api_AUP)) {
                 require_once $api_AUP;
                 if ($path_only) {
                     $avatar = AlphaUserPointsHelper::getAvatarPath($userid);
                 } else {
                     $avatar = AlphaUserPointsHelper::getAupAvatar($userid, 0, $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();
                 $avatar = $my->getAvatar($height < 64 ? SOCIAL_AVATAR_SMALL : ($height < 128 ? SOCIAL_AVATAR_MEDIUM : SOCIAL_AVATAR_LARGE));
                 $attribs[] = array('style' => 'height: ' . $height . 'px');
                 if ($path_only == false) {
                     $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($attribs) ? JArrayHelper::toString($attribs) : $attribs) . ' /') . '>';
                 }
             }
             break;
     }
     return $avatar;
 }
Esempio n. 2
0
 public function getUserAvatarImage($app, $userId, $email = null, $height = 48, $urlOnly = true, $alt = '', $imgAttribs = array())
 {
     $avatar = '';
     $userId = !empty($userId) ? $userId : 0;
     $imgAttribs['class'] = isset($imgAttribs['class']) ? $imgAttribs['class'] : 'img-avatar';
     switch ($app) {
         case 'cjforum':
             $api = JPATH_ROOT . '/components/com_cjforum/lib/api.php';
             if (file_exists($api)) {
                 require_once $api;
                 $profileApi = CjForumApi::getProfileApi();
                 $avatar = $profileApi->getUserAvatarImage($userId, $height);
                 if ($urlOnly == false) {
                     $imgAttribs['height'] = $height . 'px';
                     $imgAttribs['style'] = 'max-height: ' . $height . 'px; max-width: ' . $height . 'px;';
                     $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($imgAttribs) ? JArrayHelper::toString($imgAttribs) : $imgAttribs) . ' /') . '>';
                 }
             }
             break;
         case 'cjblog':
             $api = JPATH_ROOT . '/components/com_cjblog/api.php';
             if (file_exists($api)) {
                 include_once $api;
                 $avatar = CjBlogApi::get_user_avatar_image($userId, $height);
                 if ($urlOnly == false) {
                     $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($imgAttribs) ? JArrayHelper::toString($imgAttribs) : $imgAttribs) . ' /') . '>';
                 }
             }
             break;
         case 'easyprofile':
             $api = JPATH_ROOT . '/components/com_jsn/helpers/helper.php';
             if (file_exists($api)) {
                 $user = new JsnUser($userId);
                 $avatar = $user->getValue('avatar');
                 if ($urlOnly == false) {
                     $imgAttribs['height'] = $height . 'px';
                     $imgAttribs['style'] = 'max-height: ' . $height . 'px; display: block; margin: 0 auto';
                     $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($imgAttribs) ? JArrayHelper::toString($imgAttribs) : $imgAttribs) . ' /') . '>';
                 }
             }
             break;
         case 'jomsocial':
             require_once JPATH_ROOT . '/components/com_community/defines.community.php';
             require_once JPATH_ROOT . '/components/com_community/libraries/core.php';
             require_once JPATH_ROOT . '/components/com_community/helpers/string.php';
             $user = CFactory::getUser($userId);
             $avatar = $user->getThumbAvatar();
             if ($urlOnly == false) {
                 $imgAttribs['height'] = $height . 'px';
                 $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($imgAttribs) ? JArrayHelper::toString($imgAttribs) : $imgAttribs) . ' /') . '>';
             }
             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());
             //TODO: Here
             $imgAttribs['height'] = $height . 'px';
             if ($userId > 0) {
                 $cbUser = CBuser::getInstance($userId);
                 if ($cbUser !== null) {
                     $avatar = $cbUser->getField('avatar', null, 'php', 'profile', 'list');
                     $alt = $cbUser->getField('name');
                     $avatar = $avatar['avatar'];
                 }
             } else {
                 if ($height <= 90) {
                     $avatar = selectTemplate() . 'images/avatar/tnnophoto_n.png';
                 } else {
                     $avatar = selectTemplate() . 'images/avatar/nophoto_n.png';
                 }
             }
             if ($urlOnly == false) {
                 $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($imgAttribs) ? JArrayHelper::toString($imgAttribs) : $imgAttribs) . ' /') . '>';
             }
             break;
         case 'gravatar':
             if (null == $email && $userId > 0) {
                 try {
                     $db = JFactory::getDbo();
                     $query = $db->getQuery(true)->select('email')->from('#__users')->where('id = ' . $userId);
                     $db->setQuery($query);
                     $email = $db->loadResult();
                 } catch (Exception $e) {
                 }
             }
             $avatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s=' . $height . '&d=mm&r=g';
             if ($urlOnly == false) {
                 $avatar = JHtml::image($avatar, $alt, $imgAttribs);
             }
             break;
         case 'kunena':
             if ($this->_initialize_kunena()) {
                 $class = 'avatar';
                 $user = KunenaFactory::getUser($userId);
                 $avatar = $user->getAvatarImage($class, $height, $height);
                 if ($urlOnly) {
                     preg_match_all('/<img .*src=["|\']([^"|\']+)/i', $avatar, $matches);
                     foreach ($matches[1] as $key => $value) {
                         $avatar = $value;
                         break;
                     }
                 }
             }
             break;
         case 'aup':
             $api_AUP = JPATH_SITE . '/components/com_alphauserpoints/helper.php';
             if (file_exists($api_AUP)) {
                 require_once $api_AUP;
                 if ($urlOnly) {
                     $avatar = AlphaUserPointsHelper::getAvatarPath($userId);
                 } else {
                     $avatar = AlphaUserPointsHelper::getAupAvatar($userId, 0, $height, $height);
                 }
             }
             break;
         case 'easysocial':
             $api = JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/foundry.php';
             if (file_exists($api)) {
                 require_once $api;
                 $my = Foundry::user($userId);
                 $avatar = $my->getAvatar($height < 64 ? SOCIAL_AVATAR_SMALL : ($height < 128 ? SOCIAL_AVATAR_MEDIUM : SOCIAL_AVATAR_LARGE));
                 $imgAttribs[] = array('style' => 'height: ' . $height . 'px');
                 if ($urlOnly == false) {
                     $avatar = '<img src="' . $avatar . '" alt="' . $alt . '" ' . trim((is_array($imgAttribs) ? JArrayHelper::toString($imgAttribs) : $imgAttribs) . ' /') . '>';
                 }
             }
             break;
     }
     return $avatar;
 }