Creating the installation XML file
The first file we need to create is the installation XML file (also known as the XML Manifest) which tells Joomla! all about this plugin when you install it through an extension manager. This XML file describes all the files and folders used by this plugin, and what parameters the plugin has. The naming standard of the installation XML file is extensionname.xml
, in our case it will be clicktocall.xml
as we drop the plg_content_
prefix.
Create a folder called plg_content_clicktocall
.
In this folder, create a file called clicktocall.xml
and insert the following code:
<?xml version="1.0" encoding="UTF-8"?> <extension version="3.0" type="plugin" group="content" method="upgrade"> <name>Content - Click To Call</name> <author>Tim Plummer</author> <creationDate>April 2013</creationDate> <copyright>Copyright (C) 2013 Packt Publishing. All rights reserved.</copyright> <license> http://www.gnu.org/licenses/gpl-3.0.html</license> <authorEmail>example@packtpub.com</authorEmail> <authorUrl>http://packtpub.com</authorUrl> <version>1.0.0</version> <description>This plugin will replace phone numbers with click to call links. Requires Joomla! 3.0 or greater. Don't forget to publish this plugin! </description> <files> <filename plugin="clicktocall">clicktocall.php</filename> <filename>index.html</filename> </files> </extension>
Now let's examine what we have just made. The first thing to notice is the extension tag, that tells Joomla! what kind of extension this is; in our case, a plugin.
<extension
version="3.0"
type="plugin"
group="content"
method="upgrade">
The version indicates the minimum version of Joomla! that this extension can be installed on. If you wanted to also support Joomla! 2.5, you could to change this to version="2.5"
.
<extension
version="2.5"
type="plugin"
group="content"
method="upgrade">
The group attribute is required for plugins because there are several types of plugins, but you wouldn't see this in a module or a component. In our case, we are creating a content plugin.
<extension
version="3.0"
type="plugin"
group="content"
method="upgrade">
The method="upgrade"
is important to note. If you do not include this, then every time you install an upgrade version of the extension, the uninstall script will run and it will delete your existing data. That's not really a problem for this plugin as it doesn't have an associated database table, but it's a good idea to include it anyway in all your extensions.
<extension
version="3.0"
type="plugin"
group="content"
method="upgrade">
In the name
tag, you will see Content - Click To Call
. The standard for plugins is to say the plugin type dash plugin name.
<name>Content - Click To Call</name>
The author
, creationDate
, copyright
, license
, authorEmail
, and authorUrl
tags are pretty self-explanatory, just put in your own details as follows:
<author>Tim Plummer</author> <creationDate>April 2013</creationDate> <copyright>Copyright (C) 2013 Packt Publishing. All rights reserved.</copyright> <license> http://www.gnu.org/licenses/gpl-3.0.html</license> <authorEmail>example@packtpub.com</authorEmail> <authorUrl>http://packtpub.com</authorUrl>
The version
tag is important, each time you release a new version of your extension you should adjust this version number. You should use a three digit version number separated by full stops.
<version>1.0.0</version>
The description
tag is the text that the user will see when they initially install the plugin. Most plugin developers add the words "Don't forget to publish this plugin!" as plugins are disabled by default when they are installed and will not work until they have been enabled.
<description>This plugin will replace phone numbers with Click to Call links. Requires Joomla! 3.0 or greater. Don't forget to publish this plugin! </description>
The files
tag tells Joomla! all the files that this extension uses, in this case, we only have two files in addition to our installation XML file, the index.html
file and the clicktocall.php
file which is going to contain the code for our plugin.
<files> <filename plugin="clicktocall">clicktocall.php</filename> <filename>index.html</filename> </files>
Note
In the older Joomla! versions, you had to individually list every file in the extension, however, now you can use the folder
tag to include all the files and subfolders within a folder. For example, if we had a folder called views
, you could write <folder>views</folder>
.
Then at the end of our XML file, we have a closing extension tag that tells Joomla! that it's the end of this file.
</extension>
Now in your plg_content_clicktocall
folder, create an index.html
file with the following code:
<html><body bgcolor="#FFFFFF"></body></html>
The index.html
file should be included in every folder within your extension and will just show the user a blank page if they try to browse the folder directly. In the past, it was considered a security risk not to include these index.html
files, as without them you could potentially be exposing information about your website to malicious users. The JED previously rejected any extension that did not include these index.html
files. As of April 1, 2013, the JED has dropped the requirement to include index.html
files in all folders. Nicholas K. Dionysopoulos from Akeeba has written a detailed explanation as to why the index.html
files are not an effective security feature. This explanation can be found at http://www.dionysopoulos.me/blog/86-the-files-of-wrath.html.
Ideally your web host should have the directory traversal disabled, or you should utilize the .htaccess
or web.config
file to prevent directory traversal. However, there are still a lot of Joomla! sites that will not configure these alternatives, so I would be inclined to still include an index.html
file in every folder. The following screenshot shows a blank page displayed when the user tries to browse a folder directly:
If we were to forget to put in the index.html
file and the directory traversal was not disabled, someone could potentially browse directly to the folder containing our plugin and they would see all the files in that directory as well as other information such as web server and PHP versions. This is shown in the following screenshot: