You can call a plugin method inside a component and pass it data.
$data = array('param1' => $items, 'param1' => $location, ....); // Plugin parammeters
JPluginHelper::importPlugin('myplugins', 'plugin_name'); // Load plugin
$dispatcher = JDispatcher::getInstance();
$result = $dispatcher->trigger('getMyFunction', $data);
$this->items = $result[0];
You can have all your custom plugin in a group and give it a name for example "myplugins". All the component needs to do is invoke the plugin, pass data and handle response.
Read More...
In Joomla 1.6/1.7 parameters enable users to configure settings that later can be used in code of extensions and templates. Following are the ways that can help a developer to access these parameters.
Component Parameters
From inside a Component:
$option = JRequest::getVar('option'); // Get component name
$app = JFactory::getApplication();
$params =& JComponentHelper::getParams($option);
From outside a Component:
Module Parameters
From inside a Module:
From outside a Module:
Plugin Parameters
From inside a Plugin:
$mode = $this->params->def('mode', 1);
From outside a Plugin:
$plugin = JPluginHelper::getPlugin('user', 'userdirect');
$pParams = new JRegistry();
$pParams->loadJSON($plugin->params);
$link = $pParams->get('group_1');
OR
$plugin =& JPluginHelper::getPlugin($plgType, $plgName);
$params_object = new JParameter( $plugin->params );
// to get 1 parameter from a plugin
$param_item = $params_object->get('name_of_param');
Template Parameters
From inside a Template:
From outside a Template:
From out Joomla Framework:
Read More...
In Joomla 1.5 parameters enable users to configure settings that later can be used in code of extensions and templates. Following are the ways that can help a developer to access these parameters.
Component Parameters
From inside a Component:
$componentParams = &JComponentHelper::getParams('com_example');
$param = $componentParams->get('parameter_name', 'default_value');
From outside a Component:
$componentParams = &JComponentHelper::getParams('com_example');
$param = $componentParams->get('parameter_name', 'default_value');
Module Parameters
From inside a Module:
$param = $params->get('parameter_name', 'default_value');
From outside a Module:
$module = &JModuleHelper::getModule('module_example');
$moduleParams = new JParameter($module->params);
$param = $moduleParams->get('parameter_name', 'default_value');
Plugin Parameters
From inside a Plugin:
$param = $this->params->get('parameter_name', 'default_value');
From outside a Plugin:
$plugin = &JPluginHelper::getPlugin('plugin_example');
$pluginParams = new JParameter($plugin->params);
$param = $pluginParams->get('parameter_name', 'default_value');
Template Parameters
From inside a Template:
$param = $this->params->get('parameter_name');
From outside a Template:
jimport('joomla.filesystem.file');
$mainframe = &JFactory::getApplication();
$params = $mainframe->getParams(JFile::read(JURI::root().'/templates/template_name/params.ini'));
$param = $params->get('parameter_name', 'default_value');
From out Joomla Framework:
$paramsFile = dirname(__FILE__) . '/../params.ini'; // Get params.ini
// check if file exists
if(file_exists($paramsFile)) {
$iniString = file_get_contents($paramsFile); // get ini file contents
// Escape double quotes in values and then double-quote all values
$iniQuoted = preg_replace('/=(.*)\\n/', "=\"$1\"\n", addcslashes($iniString, '"'));
$iniParsed = parse_ini_string($iniQuoted);
} else {
$iniParsed = '';
}
$params = (!empty($iniParsed)) ? $iniParsed : array();
$param = $params['paramName'];
Read More...
You can use a plugins functions from another plugin or component using following codes.
These are for Joomla 1.5
$Plugin =& JPluginHelper::getPlugin('system', 'saleslogix');
$dispatcher =& JDispatcher::getInstance();
$plg = array("type"=>"system","name"=>"saleslogix","params"=>$Plugin->params);
$saleslogixPlg = new plgSystemSaleslogix( $dispatcher, $plg );
//$resultHere = $saleslogixPlg->myFunction();
OR
JPluginHelper::importPlugin('system');
$app = &JFactory::getApplication();
$app->triggerEvent('onAfterInitialise');
Read More...
<?php
function CreateNewUser($name, $username, $email, $password, $registerDate = NULL, $usertype = 'Registered', $block = '0', $sendEmail = '1', $gid = '18') {
global $db;
$db = & JFactory::getDBO();
jimport('joomla.user.helper');
//Make the joomla password hash
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($password, $salt);
$joomlapassword = $crypt . ':' . $salt;
//Table #__users
//Informations about the user
$user = new stdClass;
$user->id = NULL;
$user->name = $name;
$user->username = $username;
$user->email = $email;
$user->password = $joomlapassword;
$user->registerDate = registerDate;
$user->usertype = $usertype;
$user->block = $block;
$user->sendEmail = $sendEmail;
$user->gid = $gid;
if (!$db->insertObject('#__users', $user, 'id')) {
echo $db->stderr();
return false;
}
//Table #__core_acl_aro
//Discover what is the last value of value in #__core_acl_aro
$query = "SELECT value FROM #__core_acl_aro ORDER BY id DESC LIMIT 1";
$db->setQuery($query);
$coreaclarolastvalue = $db->loadResult();
$coreaclaro = new stdClass;
$coreaclaro->id = NULL;
$coreaclaro->section_value = 'users';
$coreaclaro->value = $coreaclarolastvalue + 1;
$coreaclaro->order_value = NULL;
$coreaclaro->name = $name;
$coreaclaro->hidden = NULL;
if (!$db->insertObject('#__core_acl_aro', $coreaclaro, 'id')) {
echo $db->stderr();
return false;
}
//Table #__core_acl_groups_aro_map
$coreaclmap = new stdClass;
$coreaclmap->group_id = $gid;
$coreaclmap->section_value = NULL;
$coreaclmap->aro_id = $coreaclaro->id; // maybe just $user->id ?
if (!$db->insertObject('#__core_acl_groups_aro_map', $coreaclmap)) {
echo $db->stderr();
return false;
}
$CreateNewUserInfo = array($user->id, $user->name, $user->username, $user->email);
return $CreateNewUserInfo;
}
Implementation
//This exemple will take data from one post, for example
$username = JRequest::getVar('username');
$name = JRequest::getvar('name');
$email = JRequest::getVar('email');
$password = JRequest::getVar('password');
//This code will call your funcion, then register with your data
$NewUserInfo = CreateNewUser($name, $username, $email, $password, $registerDate);
Read More...
Following is a template that can be used to develop plugins to inert code into Joomla head section.
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="system">
<name>System - Name of Plugin</name>
<author>Name of author</author>
<creationDate>19th April 2010</creationDate>
<authorEmail>
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
</authorEmail>
<authorUrl>http://www.khawaib.co.uk</authorUrl>
<version>1.0</version>
<copyright>Copyright (c) 2010 Khawaib Ahmed. All rights reserved.</copyright>
<license>http://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
<description> Plugin description.</description>
<files>
<filename plugin="phpFileName">phpFileName.php</filename>
</files>
<params>
<param name="code" type="text" default="[DEFAULT VALUE]" label="[LABEL]" description=" [DESCRIPTION]" />
</params>
</install>
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin');
class plgSystemAsynGoogleAnalytics extends JPlugin {
function plgAsynGoogleAnalytics(&$subject, $config) {
parent::__construct($subject, $config);
$this->_plugin = JPluginHelper::getPlugin( 'system', 'AsynGoogleAnalytics' );
$this->_params = new JParameter( $this->_plugin->params );
}
function onAfterRender() {
global $mainframe;
// skip if admin page
if($mainframe->isAdmin()) {
return;
}
// get params
$trackerCode = $this->params->get( 'code', '' );
//getting body code and storing as buffer
$buffer = JResponse::getBody();
//embed Google Analytics code
$javascript = "<script type=\"text/javascript\">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '".$trackerCode."']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>";
// adding the Google Analytics code in the header before the ending </head> tag and then replacing the buffer
$buffer = preg_replace ("/<\/head>/", "\n\n".$javascript."\n\n</head>", $buffer);
//output the buffer
JResponse::setBody($buffer);
return true;
}
}
?>
Read More...
Following are some of the great techniques and scripts to fix IE6 PNG transparency issue.
DD_belatedPNG
Supersleight jQuery Plugin
PNG 8-bit technique (Fireworks)
Clever PNG Optimization Techniques
PNG Optimization Guide: More Clever Techniques
More and more web designers nowadays not fixing the PNG issue for IE6 anymore.
Read More...