joomla! plugin development
DESCRIPTION
Presentation on Joomla! plugin developmentTRANSCRIPT
![Page 1: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/1.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Joomla! plugindevelopment
![Page 2: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/2.jpg)
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
![Page 3: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/3.jpg)
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
![Page 4: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/4.jpg)
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)
![Page 5: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/5.jpg)
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
![Page 6: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/6.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Part 1:Why a plugin?
![Page 7: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/7.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Joomla! extensions
Component
Modules
Plugins
Libraries
Language files
![Page 8: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/8.jpg)
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.
![Page 9: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/9.jpg)
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
![Page 10: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/10.jpg)
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
![Page 11: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/11.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
User-plugin events
onUserLogin
onUserLogout
onUserAuthenticate
onUserLoginFailure
onUserBeforeSave / onUserAfterSave
onUserBeforeDelete / onUserAfterDelete
![Page 12: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/12.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
System-plugin events
onAfterInitialise
onAfterRoute
onAfterDispatch
onBeforeRender / onAfterRender
onBeforeCompileHead
![Page 13: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/13.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Part 2:A bit of programming
![Page 14: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/14.jpg)
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
![Page 15: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/15.jpg)
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
![Page 16: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/16.jpg)
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
![Page 17: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/17.jpg)
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"
![Page 18: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/18.jpg)
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)
![Page 19: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/19.jpg)
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
![Page 20: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/20.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
index.html
![Page 21: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/21.jpg)
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
![Page 22: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/22.jpg)
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>
![Page 23: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/23.jpg)
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
![Page 24: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/24.jpg)
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{}
![Page 25: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/25.jpg)
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
![Page 26: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/26.jpg)
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); }}
![Page 27: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/27.jpg)
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
![Page 28: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/28.jpg)
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); }}
![Page 29: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/29.jpg)
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
![Page 30: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/30.jpg)
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; }}
![Page 31: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/31.jpg)
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
![Page 32: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/32.jpg)
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') } }}
![Page 33: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/33.jpg)
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
![Page 34: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/34.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Part 3:Braindump
![Page 35: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/35.jpg)
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
![Page 36: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/36.jpg)
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.
![Page 37: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/37.jpg)
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
![Page 38: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/38.jpg)
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 }}
![Page 39: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/39.jpg)
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);
![Page 40: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/40.jpg)
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;
![Page 41: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/41.jpg)
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;
![Page 42: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/42.jpg)
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; }}
![Page 43: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/43.jpg)
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();}
![Page 44: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/44.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
Loading a language file - Joomla! 3.x
protected $autoloadLanguage = true;
![Page 45: Joomla! Plugin Development](https://reader034.vdocuments.mx/reader034/viewer/2022050720/554f5fe4b4c9058a148b46c0/html5/thumbnails/45.jpg)
Presentation “Joomla! Plugin Development” - http://slideshare.net/yireoJisse Reitsma ([email protected]) - Twitter @yireo
tweet @yireo