Stream API V2
Stream API V2
3rd party component can easily integrate JomSocial features into their component. Among other things, 3rd party other component can
{code}$jspath = JPATH_ROOT.DS.'components'.DS.'com_community';
include_once($jspath.DS.'libraries'.DS.'core.php');
include_once($jspath.DS.'libraries'.DS.'messaging.php');
// Add a onclick action to any link to send a message
// Here, we assume $usrid contain the id of the user we want to send message to
$onclick = CMessaging::getPopup($userid);
echo '<a onclick="'.$onclick.'" href="#">Send message</a>';{/code}
To get path to JS avatar, you can simply request a CUser object and call a simple getThumbAvatar function to retrieve the avatar url.
{code}$jspath = JPATH_ROOT.DS.'components'.DS.'com_community';
include_once($jspath.DS.'libraries'.DS.'core.php');
// Get CUser object
$user = CFactory::getUser($userid);
$avatarUrl = $user->getThumbAvatar();
echo '
';{/code}
To retrieve a specific user's friend count, similar like how you would request a CUser object, and call the method getFriendCount.
{code}$jspath = JPATH_ROOT . DS . 'components' . DS . 'com_community';
include_once($jspath. DS . 'libraries' . DS . 'core.php');
// Get CUser object
$user = CFactory::getUser( $userid );
$count = $user->getFriendCount();
echo 'Total friends: ' .$count;{/code}
To retrieve the status that is set by the user, load up the CUser object and call the method getStatus.
{code}$jspath = JPATH_ROOT . DS . 'components' . DS . 'com_community';
include_once($jspath. DS . 'libraries' . DS . 'core.php');
// Get CUser object
$user = CFactory::getUser( $userid );
$status = $user->getStatus();
echo 'User Status: ' . $status;{/code}
Since JomSocial allows displaying name by either username or real name, you should use the getDisplayName method from the CUser object.
{code}$jspath = JPATH_ROOT . DS . 'components' . DS . 'com_community';
include_once($jspath. DS . 'libraries' . DS . 'core.php');
// Get CUser object
$user = CFactory::getUser( $userid );
$name = $user->getDisplayName();
echo 'User name: '.$name ;{/code}
To get the online status of the current user, you should use the isOnline method from the CUser object.
{code}$jspath = JPATH_ROOT . DS . 'components' . DS . 'com_community';
include_once($jspath. DS . 'libraries' . DS . 'core.php');
// Get CUser object
$user = CFactory::getUser( $userid );
$isOnline = $user->isOnline();
if( $isOnline )
{
echo 'User is online now!';
}{/code}
To get a user's view count, you should use the method getViewCount from the CUser object.
{code}$jspath = JPATH_ROOT . DS . 'components' . DS . 'com_community';
include_once($jspath. DS . 'libraries' . DS . 'core.php');
// Get CUser object
$user = CFactory::getUser( $userid );
$count = $user->getViewCount();
echo 'Views: ' .$count. '';{/code}
By using our own library, CRoute, which is a replacement for JRoute, link to any part of JomSocial will have the correct Itemid and will help avoid any duplicate link.
{code}$jspath = JPATH_ROOT.DS.'components'.DS.'com_community';
include_once($jspath.DS.'libraries'.DS.'core.php');
// Get CUser object
$link = CRoute::_('index.php?option=com_community&view=profile&userid='.$userid);
echo 'View user profile';{/code}
Each user within JomSocial is represented by a special object called CUser. CUser inherit all JUser object properties and added a couple new functionality.
{code}// Return user with the given id
$user =& CFactory::getUser($userId);
// Return current logged-in user. If no one is logged-in, it will
// return a visitor object
$user =& CFactory::getUser();{/code}
{code}$user =& CFactory::getUser($userId);
$data = $user->getInfo('FIELD_CODE');{/code}