Joomla! Plugin Development

4,401 views

Published on

Presentation on Joomla! plugin development

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,401
On SlideShare
0
From Embeds
0
Number of Embeds
679
Actions
Shares
0
Downloads
74
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Joomla! Plugin Development

  1. 1. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Joomla! plugin development
  2. 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. 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. 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. 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. 6. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Part 1: Why a plugin?
  7. 7. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Joomla! extensions Component Modules Plugins Libraries Language files
  8. 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. 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
  10. 10. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - 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
  11. 11. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo User-plugin events onUserLogin onUserLogout onUserAuthenticate onUserLoginFailure onUserBeforeSave / onUserAfterSave onUserBeforeDelete / onUserAfterDelete
  12. 12. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo System-plugin events onAfterInitialise onAfterRoute onAfterDispatch onBeforeRender / onAfterRender onBeforeCompileHead
  13. 13. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Part 2: A bit of programming
  14. 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
  15. 15. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - 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
  16. 16. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - 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
  17. 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. 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)
  19. 19. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - 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
  20. 20. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo index.html
  21. 21. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - 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
  22. 22. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo XML-manifest <?xml version="1.0" encoding="utf­8"?> <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=”en­GB”>en­GB.plg_system_example.ini</language>     <language tag=”en­GB”>en­GB.plg_system_example.sys.ini</language>   </languages> </extension>
  23. 23. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - 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
  24. 24. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo System Plugin - basic structure <?php defined('_JEXEC') or die(); jimport( 'joomla.plugin.plugin' ); class plgSystemExample extends JPlugin { }
  25. 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. 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. 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. 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. 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. 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. 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
  32. 32. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Authenticatie Plugin (1/1) <?php defined('_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')     }   } }
  33. 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
  34. 34. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Part 3: Braindump
  35. 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. 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. 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. 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. 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. 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;
  41. 41. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Checks (2/2) Ignore AJAX-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;
  42. 42. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - 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;   } }
  43. 43. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Loading a language file - Joomla! 2.5 public function __construct(& $subject, $config) {   parent::__construct($subject, $config);   $this­>loadLanguage(); }
  44. 44. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo Loading a language file - Joomla! 3.x protected $autoloadLanguage = true;
  45. 45. Presentation “Joomla! Plugin Development” - http://slideshare.net/yireo Jisse Reitsma (jisse@yireo.com) - Twitter @yireo tweet @yireo

×