Hello, Guest.

Plugin Tutorials

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

  1. system plugin
  2. profile plugin

Contents

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.

Tutorials

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

Sample of system plugin

example.php

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.
<?php
 
defined('_JEXEC') or die('Restricted access');
require_once( JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'libraries'.DS.'core.php');
 
class plgCommunityExample extends CApplications
{
	var $name	= 'Invite';
	var $_name	= 'invite';
 
	function plgCommunityExampl(& $subject, $config)
	{
		parent::__construct($subject, $config);
	}
}

example.xml

<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="community">
	<name>Walls</name>
	<author>AzrulStudio</author>
	<creationDate>7 October 2008</creationDate>
	<copyright>Copyright (C) 2008. All rights reserved.</copyright>
	<license>http://www.azrul.com</license>
	<authorEmail>support@azrul.com</authorEmail>
	<authorUrl>www.azrul.com</authorUrl>
	<version>1.0</version>
	<isapplication>true</isapplication>
	<description>
		Example for JomSocial © AzrulStudio 2008
	</description>
	<files>
		<file plugin="example">example.php</file>
		<file>example.xml</file>
	</files>
 
	<params>
		<param name="cache" type="list" default="0" label="Enable caching" description="Cache data">
			<option value="0">No</option>
			<option value="1">Yes</option>
		</param>
		<param 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.">
			<option value="0">No</option>
			<option value="1">Yes</option>
		</param>
	</params>
</install>

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 paramaters 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

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

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

$this->loadUserParams();
// 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.

Example

class plgCommunityTwitter extends CApplications
{
	var $name 		= "Me on twitter";
	var $_name		= 'twitter';	
 
	function onProfileDisplay()
	{
		$config	=& CFactory::getConfig();
		$this->loadUserParams();
 
		$uri		= JURI::base();
		$my		=& JFactory::getUser();
		$user		=& CFactory::getActiveProfile();
		$document	=& JFactory::getDocument();
		$css		= $uri	.'plugins/community/groups/style.css';
		$document->addStyleSheet($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, 
			$this->params, 
			$user, $my);
 
		return $content; 
	}
 
	function _getTwitterHTML($username, $password, &$params, &$user, &$my) {
		/* Do the processing here */
		return $content;
	}

Note

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

Docs Navigation

JomSocial Video Testimonial Contest. Top 5 best videos wins iPod Nano 4G.

Slashes & Dots Sdn. Bhd.
MALAYSIA OFFICE
No 1-7, Signature Office,
The Boulevard Mid Valley City,
Lingkaran Syed Putra,
59200 Kuala Lumpur, Malaysia.
U.S. OFFICE
251 West Central Avenue #146,
Springboro, Ohio 45066, U.S.A.

Tel: +60 (3) 2282-1997
Fax: +60 (3) 2283-1997
E-mail:
Copyright © 2007 - 2009 JomSocial.com. All rights reserved.
JomSocial is made for Joomla!
JomSocial Community Count

644 users currently online | 84564 forum posts