2. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
My name is Jisse Reitsma
Developer
Owner of Yireo
Joomla! & Magento
Extensies & development
Tutorials & blogs
3. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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
4. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Book release in Autumn 2014
English
About 200-300 pages
Complete reference guide
Available through Amazon
(plus some other channels)
5. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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
6. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Part 1:
Why a plugin?
8. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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.
9. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Plugin-groups (core)
Authentication
Content
System
User
Editors
Editors Xtd
Search
Finder
CAPTCHA
Extension
Quickicon
13. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Part 2:
A bit of programming
14. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
17. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Language files (1/2)
PLG_SYSTEM_EXAMPLE="System Example"
PLG_SYSTEM_EXAMPLE_DESC="An example System Plugin"
18. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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)
25. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
26. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
System Plugin - hacking HTML
<?php
defined('_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);
}
}
27. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
28. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
System Plugin - add headers
<?php
defined('_JEXEC') or die();
jimport( 'joomla.plugin.plugin' );
class plgSystemExample extends JPlugin
{
public function onAfterDispatch()
{
$document = JFactory::getDocument();
$document>setGenerator('drupal');
$document>addScriptDeclaration($script);
}
}
29. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
30. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Content Plugin - remove a field
<?php
defined('_JEXEC') or die();
jimport( 'joomla.plugin.plugin' );
class plgContentExample extends JPlugin
{
public function onContentPrepareForm($form, $data)
{
$form>removeField('name', 'profile');
return true;
}
}
31. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
33. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Reasons for a custom plugin
Modifying HTML-code
Tweaking document-headers
Extending an user-formulier
Extra authentication-type
... and a lot more
35. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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
36. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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.
37. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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
38. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - Twitter @yireo
Calling your own event (2/3)
jimport( 'joomla.plugin.plugin' );
class plgCustomExample extends JPlugin
{
public function doSomething()
{
// @todo: Do something
}
}
39. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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
);
40. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo
Jisse Reitsma (jisse@yireo.com) - 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;