Learning Joomla! 3 Extension Development(Third Edition)
上QQ阅读APP看书,第一时间看更新

Plugin types

Before we create our first plugin, let's talk about the different types of plugins that you can create for Joomla!. Plugin code is executed when certain events are triggered. You can skip the next couple of pages if you just want to get stuck in with the hands-on example and just go straight to the Where do I start? section, but you may want to refer back to this introduction later when you are creating your own plugins. The different types of plugins are explained as follows:

  • Authentication: When you log in to your website, an authentication plugin runs to check your credentials and decide if you should have access to the site. Authentication plugins are used when you want to use other login methods too, such as Facebook, Gmail, or LDAP. You can use more than one authentication plugin on the same site so that you can give your users a choice and not force them to have to remember another password by allowing them to reuse one of their existing accounts in another system. The following screenshot shows the authentication plugins you can enable on your Joomla! site:
    Tip

    Downloading the example code

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

  • Captcha: You have probably seen a CAPTCHA on a form that you've filled out. It's that box where you need to type in characters to prove that you are a person and not an automated spambot. Joomla! has a plugin in the core for reCAPTCHA, but potentially other CAPTCHAs could be added if you wrote an appropriate plugin. The following screenshot shows a Captcha where you need to type in the given Captcha characters to prove you are not an automated spambot:
  • Content: This mostly refers to article contents but some extensions load content plugins too. Content plugins allow you to change the content before it is displayed on the website. The Click To Call plugin we are creating in this chapter is a content plugin. We can see the Click to Call plugin enabled in the following screenshot:
  • Editors: Joomla! has TinyMCE and CodeMirror editors in the core, but many people want a bit more functionality from their editors and install another third-party editor such as JCE. You could potentially integrate a different editor in the core by creating an editor plugin. Editor plugins are probably the most complex, so it's not something a beginner would attempt to create.
  • Editors-XTD: This type of plugin is to extend the functionality of editor plugins by adding new buttons which trigger new functionality. For example, if you wanted to create a button in the editor that inserts a copyright symbol, you could write an editors-XTD plugin with this functionality.
  • Extension: Extension events are triggered when extensions are installed, uninstalled, updated, or edited through Plug-in Manager, Module Manager, Template Manager, or Language Manager. I haven't seen this plugin type used much in third-party extensions.
  • Quick Icons: In the admin control panel page in the backend of Joomla! versions prior to Joomla! 3, there was a Quick Icons panel that provided shortcuts to many of the frequently accessed sections. The Joomla! 3 core still has full support for Quick Icons, however the default administrator template is lacking this feature. Quick Icons plugins are used to display the Joomla! update icons, which actually change to give a visual indication that there is an update available.

    This Quick Icons panel is not shown in the new default template in Joomla! 3 called Isis.

    However at the time of writing this book, the alternate admin template in Joomla! (called Hathor) does still include these icons.

  • Search: This is the older type of search that has been in Joomla! for a while now. The search plugin type is commonly used by extension developers to get data from their component showing up in the core Joomla! search. Due to the introduction of smart search, eventually this older style search will be removed from the core, but for now, some people still choose to use it.
  • Smart Search (Finder): Smart Search is the new search functionality that was added to the Joomla! core in Joomla! 2.5. It does some fancy stuff such as suggesting alternative keywords that might help the user find what they are looking for. For example, if you search for "color" (American spelling) it will suggest "colour" (UK spelling), or if you made a typo, it would suggest similar words. Because this new search was such a dramatic change, it was decided that it would be gradually introduced by having it as an optional feature that you can turn on if you want to. Many extension developers have written smart search plugins for their components so they can take advantage of this new searching ability. These plugins are used to index the content so it can be used by Smart Search.

The following screenshot demonstrates how smart search can suggest similar words to the term you are searching:

The following screenshot shows an example of a search using Smart Search where a relevant article is found.

  • User: User plugins allow you to do some extra things during user-specific events. The user profile plugin is a good example that was added in Joomla! 2.5 which extends the fields on the user registration form and allows you to capture additional details such as address, terms of service, date of birth, and website. If you wanted to keep a log of when people log in and log out of your website, you could write a user plugin to do this.
  • System: System plugins run in the background and are triggered during every execution cycle regardless of which task is being performed. Akeeba Backup uses system plugins to trigger the update e-mail notifications. System plugins are loaded very early in the Joomla! execution cycle, before most Joomla! core classes, so we can use system plugins to override the core classes and change how Joomla! works. This is because when Joomla! loads a class into the memory, it first checks to see if this class is already loaded into the working memory, and if so, it won't load it again. So if our system plugin gets in first, its code will be used instead of the core class. Overriding core Joomla! classes is an advanced topic, and is outside the scope for this book. The following screenshot shows the System plugins which you can enable/disable as needed: