joomla! plugin development
DESCRIPTION
Presentation on Joomla! plugin developmentTRANSCRIPT
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Joomla! plugindevelopment
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
My name is Jisse Reitsma
Developer
Owner of Yireo
Joomla! & Magento
Extensies & development
Tutorials & blogs
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Plugins I wrote so far
Language Domains
Auto Login IP
Demo Site
Fancybox
HTTP Authenticatie
New Relic
Piwik
WebP
ScriptMerge
SEF Test
SSL Redirection
Static Content
Trademark
32+ MageBridge plugins
10+ SimpleLists plugins
8+ Dynamic404 plugins
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Book release in Autumn 2014
English
About 200-300 pages
Complete reference guide
Available through Amazon (plus some other channels)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Developing plugins yourself
Part I - Why a plugin?
Part II - A bit of programming
Part III - Hmmm, braindump
Presentation online: http://slideshare.net/yireo
Tweets: @yireo
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Part 1:Why a plugin?
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Joomla! extensions
Component
Modules
Plugins
Libraries
Language files
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Definition of a Joomla! plugin
A Joomla! extension that offers functionality based on a triggered event. The Joomla! core has various core-events by default, but every Joomla! extension can trigger additional events.
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Plugin-groups (core)
Authentication
Content
System
User
Editors
Editors Xtd
Search
Finder
CAPTCHA
Extension
Quickicon
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Plugin-groups (3rd party)
VirtueMart [product, custom]
JomSocial [community]
K2 [fields]
Yireo
Dynamic404 Match Lookups
SimpleLists Content / Link
MageBridge Product Sales / Newsletter Subscriptions
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
User-plugin events
onUserLogin
onUserLogout
onUserAuthenticate
onUserLoginFailure
onUserBeforeSave / onUserAfterSave
onUserBeforeDelete / onUserAfterDelete
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System-plugin events
onAfterInitialise
onAfterRoute
onAfterDispatch
onBeforeRender / onAfterRender
onBeforeCompileHead
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Part 2:A bit of programming
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin files
plugins/system/example/example.php
plugins/system/example/example.xml
plugins/system/example/index.html
administrator/languages/en-GB/en-GB.plg_system_example.ini
administrator/languages/en-GB/en-GB.plg_system_example.sys.ini
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin files
plugins/system/example/example.php
plugins/system/example/example.xml
plugins/system/example/index.html
administrator/languages/en-GB/en-GB.plg_system_example.ini
administrator/languages/en-GB/en-GB.plg_system_example.sys.ini
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Language files (1/2)
PLG_SYSTEM_EXAMPLE="System Example"PLG_SYSTEM_EXAMPLE_DESC="An example System Plugin"
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Language files (2/2)
*.sys.ini = Always loaded
Add plugin title + description, but not much more
*.ini = Only loaded specifically
When editing a plugin in backend
When showing plugin in frontend ($autoLoadLanguage = true)
Add all language strings you need (backend + frontend)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin files
plugins/system/example/example.php
plugins/system/example/example.xml
plugins/system/example/index.html
administrator/languages/en-GB/en-GB.plg_system_example.ini
administrator/languages/en-GB/en-GB.plg_system_example.sys.ini
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
index.html
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin files
plugins/system/example/example.php
plugins/system/example/example.xml
plugins/system/example/index.html
administrator/languages/en-GB/en-GB.plg_system_example.ini
administrator/languages/en-GB/en-GB.plg_system_example.sys.ini
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
XML-manifest
<?xml version="1.0" encoding="utf8"?><extension version="3.0" type="plugin" group="system"> <name>PLG_SYSTEM_EXAMPLE</name> <description>PLG_SYSTEM_EXAMPLE_DESC</description> <version>0.0.1</version> <files> <filename plugin=”example”>example.php</filename> <filename>index.html</filename> </files> <languages> <language tag=”enGB”>enGB.plg_system_example.ini</language> <language tag=”enGB”>enGB.plg_system_example.sys.ini</language> </languages></extension>
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin files
plugins/system/example/example.php
plugins/system/example/example.xml
plugins/system/example/index.html
administrator/languages/en-GB/en-GB.plg_system_example.ini
administrator/languages/en-GB/en-GB.plg_system_example.sys.ini
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin - basic structure
<?phpdefined('_JEXEC') or die();jimport( 'joomla.plugin.plugin' );class plgSystemExample extends JPlugin{}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin - hacking HTML
<?phpdefined('_JEXEC') or die();jimport( 'joomla.plugin.plugin' );class plgSystemExample extends JPlugin{ public function onAfterRender() { $body = JResponse::getBody(); // @todo: Do something with the $body JResponse::setBody($body); }}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System Plugin - add headers
<?phpdefined('_JEXEC') or die();jimport( 'joomla.plugin.plugin' );class plgSystemExample extends JPlugin{ public function onAfterDispatch() { $document = JFactory::getDocument(); $document>setGenerator('drupal'); $document>addScriptDeclaration($script); }}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Content Plugin - remove a field
<?phpdefined('_JEXEC') or die();jimport( 'joomla.plugin.plugin' );class plgContentExample extends JPlugin{ public function onContentPrepareForm($form, $data) { $form>removeField('name', 'profile'); return true; }}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Authenticatie Plugin (1/1)
<?phpdefined('_JEXEC') or die();jimport( 'joomla.plugin.plugin' );class plgAuthenticationExample extends JPlugin{ public function onUserAuthenticate($credentials, $options, &$response ) { if ($credentials['password'] == 'joomla') { $response>status = JAuthentication::STATUS_SUCCESS; $response>error_message = ''; } else { $response>status = JAuthentication::STATUS_FAILURE; $response>error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS') } }}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Part 3:Braindump
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Calling a content-event [1/2]
Scenario: Own component is offering content-object ($item)
Purpose is to modify the $item title through extra plugins
Use of content-event onContentContent
All $item-properties can be modified through this event
Dispatch event in component-view
For example in views/item/view.html.php
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Calling a content-event [2/2]
JPluginHelper::importPlugin( 'content' );
$dispatcher = JDispatcher::getInstance();
$arguments = array(&$item, &$item_params, 0);
$results = $dispatcher>trigger('onPrepareContent', $arguments
);
Note $item is a PHP reference (ampersand &).
Return-variabele $results contains at most an event-status.
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Calling your own event (1/3)
Create a custom component
components/com_example
Create a custom plugin-group
plugins/custom
Create a custom plugin
plugins/custom/example/example.php
plugins/custom/example/example.xml
plugins/custom/example/index.html
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Calling your own event (2/3)
jimport( 'joomla.plugin.plugin' );class plgCustomExample extends JPlugin{ public function doSomething() {
// @todo: Do something }}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Calling your own event (3/3)
Add this to the right place in your MVC-component:
JPluginHelper::importPlugin('custom');$dispatcher = JDispatcher::getInstance();$arguments = null;$results = $dispatcher>trigger(
'doSomething', $arguments);
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Checks (1/2)
Handy variables:$app = JFactory::getApplication();$document = JFactory::getDocument();
Check whether the current application is the frontend:if(!JFactory::getApplication()>isSite()) return false;
Check whether the current output is an HTML document:if (JFactory::getDocument()>getType() != 'html') return false;
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Checks (2/2)
Ignore A JAX-requests:$input = JFactory::getApplication()>input;if ($input>getCmd('tmpl') == 'component') return false;if ($input>getCmd('format') == 'raw') return false;if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') return false;
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Parameters in J1.5 vs J2.5
private function getParams(){ jimport('joomla.version'); $version = new JVersion(); if(version_compare($version>RELEASE, '1.5', 'eq')) { $plugin = JPluginHelper::getPlugin('system','example'); $params = new JParameter($plugin>params); return $params; } else { return $this>params; }}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Loading a language file - Joomla! 2.5
public function __construct(& $subject, $config){ parent::__construct($subject, $config); $this>loadLanguage();}
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Loading a language file - Joomla! 3.x
protected $autoloadLanguage = true;
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
tweet @yireo