How to create your own plugin for extended searching capabilities
RSSearch! was specifically designed to provide a flexible approach if you want to create your own integration with a third party or standard Joomla! extension. Although this does require scripting knowledge, we will explain generic steps you need to take as well as important bits.
For an easier understanding, an example will be provided for the standard Joomla! Contact (com_contact) which allows RSSearch! to perform searches based on the contact name, email or contact category.
What should the package contain
You can download any RSSearch! available plugin from our free downloads section, unzip the archive and you'll find the following file extensions:
File Extension | Usage |
---|---|
ini | contains language strings |
html | prevents folder access |
php | the actual functionality |
xml | installation data and configuration options |
Package Structure
The plugin folder/file structure is explained below:
- root:
- language folder
- en-GB folder
- en-GB.plg_rssearch_content.ini file
- en-GB.plg_rssearch_content.sys.ini file
- index.html file
- content.php file
- content.xml file
Adjustments and custom scripting
Starting with RSSearch! Content plugin files, these are adjusted one by one in order to create our own RSSearch! Contact plugin.
Language files
It is necessarily that you keep the language constants unique in order not to create conflicts. Open the RSSearch! Content plugin language files and replace language constants. Eventually these should be unique (example):
- PLG_RSSEARCH_CONTENT > was changed into > PLG_RSSEARCH_CONTACT
- All other constants which had RSF_CONT_XML_ prefix > were changed into > RSF_CTAC_XML_
An extra language adjustment is done within the RSSearch! language file, located under this path (\language\en-GB\en-GB.mod_rssearch.ini) from where you'll have to specify your plugin label. In our case this would be added as RSF_MODULE_PLUGIN_CONTACT="Joomla! Contact" (the label will appear when choosing for which components the search is performed via RSSearch! Module configuration).
If you're using another language for your website, replace 'en-GB' with your language prefix (this refers to the folder and the file name prefix as well). If you're using multiple languages in your website, you'll need to create a separate folder for each of your languages where each folder has it's own language files and prefix.
index.html & content.xml files
File index.html does not require any modification, you can use the one from the plugin package you've downloaded.
As for content.xml, similar as the following adjustments are required, such as the name, file paths and language strings (only relevant modifications are listed below):
- plg_rssearch_content → plg_rssearch_contact
- <filename plugin="content">content.php</filename> → <filename plugin="contact">contact.php</filename>
- <language tag="en-GB">language/en-GB/en-GB.plg_rssearch_content.ini</language> → <language tag="en-GB">language/en-GB/en-GB.plg_rssearch_contact.ini</language>
content.php
Any change so far will have to be reflected in the PHP file accordingly. Though we will not list all possible changes, we will talk about essential ones:
- class name:
- class plgRSSearchContent extends JPlugin into
- class plgRSSearchContact extends JPlugin
- loading language file:
- JFactory::getLanguage()->load('plg_rssearch_content',JPATH_ADMINISTRATOR); into
- JFactory::getLanguage()->load('plg_rssearch_contact',JPATH_ADMINISTRATOR);
-
- replacing the helper file:
- require_once JPATH_SITE.'/components/com_content/helpers/route.php'; into
- require_once JPATH_SITE.'/components/com_contact/helpers/route.php';
-
- search results type:
- $field == 'content' into
- $field == 'contact'
Besides these, there are other changes like the database queries, filtering types, usage of component specific helper and output data. For example, the output data is specified as such:
$tmp = new stdClass(); $tmp->title = $item->name; //the contact name $tmp->link = JRoute::_(ContactHelperRoute::getContactRoute($item->id, $item->catid)); //adds the link to the contact details $tmp->text = $item->email_to; //contact email address $tmp->type = JText::_('RSF_CTAC_JCONTACT'); $results[] = $tmp; //array which returns search result(s)
Download our already modified package for the RSSearch! Contact plugin, unzip it and use an editor like Notepad++ to find differences between the RSSearch! Content and RSSearch! Contact plugin files.
Final structure
Before you create a zip archive, review your package structure to be similar with:
- root:
- language folder
- en-GB folder
- en-GB.plg_rssearch_contact.ini file
- en-GB.plg_rssearch_contact.sys.ini file
- index.html file
- contact.php file
- contact.xml file
2 persons found this article helpful.