Xem mẫu

Chapter 5 Summary The two flavors in which modules come, frontend and backend, essentially define two different types of extension. Backend modules are often overlooked because we tend to be less aware of them. We should try to remember that backend modules are very powerful and can greatly enhance the administrative capabilities of components. Modules are integral to the success of a component. It`s not uncommon for one component to include several modules. The simple nature of modules makes it easy to become sophisticated about them. It`s important to remember that because they are used and rendered so frequently, efficient code is essential to good module design. [ 131 ] Plugin Design Plugins enable us to modify system functionality without the need to alter existing code. For example, plugins can be used to alter content before it is displayed, extend search functionality, or implement a custom authentication mechanism. As an example, this chapter shows how to replace a string in an article with an image. Plugins use the Observer pattern to keep an eye on events. It is by listening to these events that we can modify the system functionality. However, this also means that we are limited to only modifying those parts of the system that raise events. Plugins represent the listener, and they can define either a listener class or a listener function to handle specific events. In this chapter, we will cover the following: • Setting up a Sandbox • Events • Listeners • Plugin Groups • Loading Plugins • Using Plugins as libraries (in lieu of library extensions) • Translating Plugins • Dealing with Plugin Settings (Parameters) • Packaging • File Naming Conflicts Plugin Design Setting Up a Sandbox When we start building a new plugin it is imperative that we have a sandbox: somewhere we can test our code. Ideally, we should have more than one system so we can test our plugins on different server setups. To set up a plugin sandbox we can create a basic installer. The XML displayed below can be used to create a blank plugin called `Foobar - My Extension`. Foobar - My Extension Author`s Name Author`s Email Author`s Website MonthName Year Copyright Notice Plugin License Agreement Plugin Version Plugin Description myextension.php To use this, create a new XML manifest file, using UTF-8 encoding, and save the above code into it. You should update the XML to suit the plugin you intend to build. One of the most important pieces of information in this file is the groupattribute of the install tag. Plugins are organized into logical groups. This list details the core groups: • authentication • content • editors • editors-xtd • search • system • user • xmlrpc [ 134 ] Chapter 6 We can use other groups as well. For example, the group in our XML is foobar. It may seem slightly obscure, but another piece of important information in the XML is the filename tag plugin parameter. This parameter identifies the plugin element. The element is a unique identifier used to determine the root plugin file and used as part of the naming convention. Be careful when you select an element name for your plugin. Only one plugin per group may use any one element name. This table details reserved plugin element names (used by the core): Group authentication content editors editors-xtd search system Reserved element name gmail joomla ldap openid emailcloak geshi loadmodule pagebreak pagenavigation sef vote none tinymce xstandard image pagebreak readmore categories contacts content newsfeeds sections weblinks cache debug legacy [ 135 ] ... - tailieumienphi.vn
nguon tai.lieu . vn