JomSocial won its third CMSexpo Award. Enjoy 20% Discount Sitewide until 24th May! Learn More
Home Support Documentation Integrating Your Component

Recommend Print

Integrating Your Component

Categories Introduction Favourites Add to favourites (2 users)

JomSocial Library

3rd party component can easily integrate JomSocial features into their component. Among other things, 3rd party other component can

  • Support JomSocial build-in personal messaging system
  • Use JomSocial user object, CUser
  • Use JomSocial avatar
  • Link to user personal profile page
  • Include user action to JomSocial activity stream, and reward user with points
  • Extends JomSocial via new plugin

Support JomSocial Messaging

Example

$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>';

Using JomSocial avatar

To get path to JS avatar, you can simply request a CUser object and call a simple getThumbAvatar function to retrieve the avatar url.

Example

$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 '<img src=".%20$avatarUrl%20.%20" mce_src="http://www.jomsocial.com/. $avatarUrl .">';

Getting a user's friend count

To retrieve a specific user's friend count, similar like how you would request a CUser object, and call the method getFriendCount.

Example

$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;

Getting a user's status

To retrieve the status that is set by the user, load up the CUser object and call the method getStatus.

Example

$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;

Getting a user's display name

Since JomSocial allows displaying name by either username or real name, you should use the getDisplayName method from the CUser object.

Example

$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 ;

Get user's online status

To get the online status of the current user, you should use the isOnline method from the CUser object.

Example

$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!';
}

Get user's view count

To get a user's view count, you should use the method getViewCount from the CUser object.

Example

$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. '';

Link to user personal profile page

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.

Example

$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 '<a href=".$link." mce_href="http://www.jomsocial.com/.$link.">View user profile</a>';

  • Created
    Friday, 21 August 2009
  • Last modified
    Tuesday, 08 November 2011
  • Voting
    (18 votes)
  • Revised by
    Aizzat