Plugin Types: Where Can You Insert a Plugin?
Plugins execute when their events are triggered. Plugin events as defined in Joomla are different from events in event-driven programs. In event-driven programming, the program waits for an event, which is frequently a user action such as a mouse click or keyboard entry. Joomla events can be thought of as checkpoints along the various paths of the execution cycle. Every time the execution cycle reaches an event checkpoint, the event is triggered. The events are fixed, although different events get triggered depending on what type of execution cycle we are in. Let’s look briefly at each event type.
Authentication
There is only one event for authentication, called onUserAuthenticate. This event is triggered whenever a user attempts to log in to the front or back end of the site.
Captcha
Captcha is a way to prevent spamming by requiring a user to type some text based on a distorted image of the letters. Joomla version 2.5 added the ability to use captcha to validate user registration. This is implemented by means of three events: onInit, onDisplay, and onCheckAnswer.
Content
Content events are triggered when content is displayed or edited. This includes articles, contacts, and other types of content.
Editors
Editors are implemented in Joomla as plugins. However, they don’t really fit the pattern of plugins as discussed in this chapter. Adding a new editor in Joomla requires in-depth knowledge of JavaScript and is not an easy task. In this book, we do not discuss in detail how to add an editor, but we do show how to use editors in form fields.
Editors-XTD
Editors-XTD plugins are used to create the buttons that show below the editors (for example, Image, Pagebreak, and Read More). There is only one event for these plugins, called onDisplay.
Extension
This plugin type was introduced in Joomla version 1.6. Extension events are triggered when extensions are installed, uninstalled or edited and saved in the Module, Plugin, Template, or Language Manager.
Search
Search plugins implement the search functionality in Joomla. The core plugins are categories, contacts, content, news feeds, and Weblinks. The search events are onContentSearchAreas and onContentSearch. The onContentSearchAreas event is used to create an array of content items to search, and the onContentSearch event is used to actually execute the search for each of the content types. Extension developers can include search plugins to allow the Joomla search to work with their components.
Smart Search (Finder)
The Smart Search plugins are found in the plugins/finder folder. These plugins are used to index the site’s content for use with Smart Search. A plugin is provided for each content type (contacts, content, news feeds, and weblinks) and can be enabled to allow indexing of this type. The events provided are onFinderAfterDelete, onFinderAfterSave, onFinderBeforeSave, onFinderCategoryChangeState, and onFinderChangeState.
System
System plugins provide events that are triggered during each Joomla execution cycle. These include onAfterInitialise, the first event triggered in Joomla, and events tied to the render(), dispatch(), and route() methods. System events should be used for plugins that need to be triggered during every execution cycle, regardless of which task is being performed.
User
User events are triggered during two different tasks. One group of events is tied to editing user information in the User Manager. These include onUserAfterDelete, onUserAfterSave, onUserBeforeDelete, and onUserBeforeSave. A second group of events is related to logging on and off the site. These include onUserLogin and onUserLogout.