Difference between revisions of "Integrating Your Component"

Line 27: Line 27:
 
echo '<img src="/.%20$avatarUrl%20.%20" mce_src="http://www.jomsocial.com/. $avatarUrl .">';
 
echo '<img src="/.%20$avatarUrl%20.%20" mce_src="http://www.jomsocial.com/. $avatarUrl .">';
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
<br />
 
===Use and extend JomSocial user object, CUser===
 
===Use and extend JomSocial user object, CUser===
 
JomSocial have its own [[JomSocial User Object|user object]] that can be extended further.
 
JomSocial have its own [[JomSocial User Object|user object]] that can be extended further.
Line 40: Line 40:
 
echo 'Total friends: ' .$count;
 
echo 'Total friends: ' .$count;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
<br />
 
====Getting a User's status====
 
====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.
 
To retrieve the status that is set by the user, load up the CUser object and call the method getStatus.
Line 50: Line 50:
 
echo 'User Status: ' . $status;
 
echo 'User Status: ' . $status;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
<br />
 
====Getting  a User's Display Name====
 
====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.
 
Since JomSocial allows displaying name by either username or real name, you should use the getDisplayName method from the CUser object.
Line 60: Line 60:
 
echo 'User name: '.$name ;
 
echo 'User name: '.$name ;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
<br />
 
====Getting a User's online status====
 
====Getting a User's online status====
 
To get the online status of the current user, you should use the isOnline method from the CUser object.
 
To get the online status of the current user, you should use the isOnline method from the CUser object.
Line 73: Line 73:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
<br />
 
====Getting a User's view count====
 
====Getting a User's view count====
 
To get a user's view count, you should use the method getViewCount from the CUser object.
 
To get a user's view count, you should use the method getViewCount from the CUser object.
Line 83: Line 83:
 
echo 'Views: ' .$count. '';
 
echo 'Views: ' .$count. '';
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
<br />
 
====Link to a User's personal profile Page====
 
====Link to a User's 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.
 
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.
Line 92: Line 92:
 
echo '<a href="/.$link." mce_href="http://www.jomsocial.com/.$link.">View user profile</a>';
 
echo '<a href="/.$link." mce_href="http://www.jomsocial.com/.$link.">View user profile</a>';
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
<br />

Revision as of 15:50, 17 January 2013

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 avatar
Use and extend JomSocial user object, CUser
Include user action to JomSocial activity stream, and reward user with points
Extends JomSocial via new plugin

Support JomSocial build-in personal messaging system

To support private messaging within your component, you can use this snippet.

include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
include_once JPATH_ROOT.'/components/com_community/libraries/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>';


Use 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.

include_once JPATH_ROOT.'/components/com_community/libraries/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 .">';


Use and extend JomSocial user object, CUser

JomSocial have its own user object that can be extended further. Here are few examples how can you use it inside your component

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.

include_once JPATH_ROOT.'/components/com_community/libraries/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.

include_once JPATH_ROOT.'/components/com_community/libraries/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.

include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
// Get CUser object
$user  = CFactory::getUser( $userid );
$name = $user->getDisplayName();
echo 'User name: '.$name ;


Getting a User's online status

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

include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
// Get CUser object
$user  = CFactory::getUser( $userid );
$isOnline = $user->isOnline();
if( $isOnline )
{
	echo 'User is online now!';
}


Getting a User's view count

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

include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
// Get CUser object
$user  = CFactory::getUser( $userid );
$count = $user->getViewCount();
echo 'Views: ' .$count. '';


Link to a User's 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.

include_once JPATH_ROOT.'/components/com_community/libraries/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>';