Had a wee bit of spare time today, and came across a great article on making your own search plugins for firefox. As this is something that would be great on the site I'm working on, and goes hand in hand with the Mambo Spread Firefox project, I thought I'd give it a go.
It's a breeze with the Web Developer extension for Firefox, as it shows you exactly what a search form needs to work, and converts POSTs to GETs. Read the article for more info on that, and I'd recommend it for any web dev.
Anyway, I thought I'd share what I found so other Mambers can make search plugins for their own Mambo sites. So here we go:
Firstly, 1.0.9 sites and 4.5.1 sites have different search engines, so I'll show you the basic code for both. Note that I am putting the code in the php code tags here, but it is not php code. Just easier on the eyes
Ok, so first put in your comment:
Then the main search code:
PHP Code:
<search
name="Your Search"
method="GET"
action="http://www.yoursite.com/index.php"
>
The essential line here is the action attribute. Change that to the full URL of your mambo site.
Then come the form fields:
PHP Code:
<input name="option" value="search">
<input name="searchword" user>
<input name="submit" value="search">
These will be the same for all 1.0.9 sites using the standard core search component.
That's it! It's too easy, but it works a charm.
For 4.5.1 sites, the search component is slightly different. So use this for the form fields:
PHP Code:
<input name="searchword" user>
<input name="submit" value="search">
<input name="option" value="com_search">
Save that under the name you want your plugin to have, and make sure it is a .src file.
To go with the .src, create a 16x16 icon to go with it under the same name, save it as a jpg. This is optional, but it looks good
Now the best way to install this lil plugin you have created, is through a javascript on your Mambo site.
Here's the javascript code to put in the head section of your template:
PHP Code:
<script language="javascript">
function addEngine(name,ext,cat)
{
if ((typeof window.sidebar == "object") && (typeof
window.sidebar.addSearchEngine == "function"))
{
window.sidebar.addSearchEngine(
"<?php echo $mosConfig_live_site; ?>/"+name+".src",
"<?php echo $mosConfig_live_site; ?>/"+name+"."+ext,
name,
cat );
}
else
{
alert("Netscape 6 or Mozilla is needed to install a search plugin");
}
}
</script>
You don't need to touch that, I've added the $mosConfig_live_site variable to make things easier.
Now call it from your template with a link like this:
PHP Code:
<a href="javascript:addEngine('yourplugin','jpg','Your Search')">Your Search Plugin!</a>
Make sure the plugin .src and .jpg files are in the root directory of your Mambo site, again the .jpg is not compulsory.
That's all! Phew!
Mambo Spread Firefox will be releasing some premade plugins for the major Mambo community sites in the next few days and we're happy to add any that the community come up with as well. Stay tuned. 8)
Cheers,
Damian