Plugin Tutorials

Revision as of 02:21, 23 January 2013 by Sinisakrisan (Talk | contribs)

A JomSocial plugin allows developer to extends JS and provide new functionality easily. A plugin is essentially a normal Joomla! plugin that can be installed, uninstall and manage just like a normal Joomla! plugin. JomSocial provide a few system hooks, or trigger point which your plugin will override to add new functionality to JomSocial

A plugin can either be

  • system plugin or
  • profile plugin

System plugin

System plugin allows you to perform various system wide task.

Profile plugin

When you create a profile plugin, a site members will be able to select your plugin to be displayed in their profile page. Your plugin will be able to draw on user profile page and will have access to user various parameters.


Creating a JomSocial plugin is easy. At least, you will need 2 files, the plugin php file and its xml file.

Sample of system plugin


In your main php file, you will need to

  • include JomSocial core file
  • declare a class with plgCommunity[Plugin name] format. This class should extends CApplications class.
defined('_JEXEC') or die('Restricted access');
require_once JPATH_ROOT.'/components/com_community/libraries/core.php';
class plgCommunityExample extends CApplications
	var $name	= 'Invite';
	var $_name	= 'invite';
	function plgCommunityExampl(& $subject, $config)
		parent::__construct($subject, $config);


< version="1.0" encoding="utf-8"?>
<install></install> < version="1.5" type="plugin" group="community">
	< Walls>
	<creationdate><</creationdate>7 October 2008>
	<copyright><</copyright>Copyright (C) 2008. All rights reserved.>
	<authoremail><</authoremail>[email protected]>
	<description><</description>Example for JomSocial © AzrulStudio 2008>
	<files> </files>
		<<file></file> plugin="example">example.php>
		  <name="cache" type="list" default="0" label="Enable caching" description="Cache data">
		 <name="coreapp" type="list" default="0" label="Core Application" 
				description="Causes this application to not appearin the users applications 
				list but it will allow this application to appear in the user profile 
				automatically if selected.">

Please take note that there is a few additional element

  • isapplication

If set to true, the application can be selected by user from the front-end

  • Param coreapp

Within the params section, please add a param named 'coreapp'. This allow admin to force this application to appear on all user profile.

Accessing parameter

There are 2 types of plugin parameters, the site plugin params and user params

Default system parameters

System parameters are setting that are specified by the server administrator. It cannot be changed by the user and admin can only modify the setting from Joomla backend. This params is loaded automatically and can be accessed right away.

$db_name = $this->params->get('db_name', '');

User parameters

A user parameter is params data specific to the current user. To define this params, create a file called config.xml inside the plugin folder.

// Sample config.xml
 <version="1.0" encoding="utf-8"?>
<install></install> <version="1.5" type="plugin" group="community">
     <name="path" type="text" default="" label="Feed url"/>
      <name="count" type="text" default="5" label="Count"  />

To use any user specific parameter, you will need to load it before you can use it. Just call

// After loading, userparams object (JParameters) will be available to yoi
$path = $this->userparams->get('path', '');

Caching plugin content

JomSocial, by default does not cache the return values for plugins. If any plugin want to use any caching system, you can deploy standard Joomla caching system.


class plgCommunityTwitter extends CApplications
	var $name 		= "Me on twitter";
	var $_name		= 'twitter';	
	function onProfileDisplay()
		$config	=& CFactory::getConfig();
		$uri		= JURI::base();
		$my		=& JFactory::getUser();
		$user		=& CFactory::getActiveProfile();
		$document	=& JFactory::getDocument();
		$css		= $uri	.'plugins/community/groups/style.css';
		$username = $this->params->get('username');
		$password = $this->params->get('password');
		$cache =& JFactory::getCache('community');
		$callback = array($this, '_getTwitterHTML');
		$content = $cache->call($callback, $username, $password, 
			$user, $my);
		return $content; 
	function _getTwitterHTML($username, $password, &$params, &$user, &$my) {
		/* Do the processing here */
		return $content;

  • Get the cache object with 'community' community.
  • The function that return the final content should not try to get the 'user' and 'my' object. Caller should instead pass these data to the function.
  • Any css/js attachment should be attached outside the cached function.