3

I have got a search plugin, which was developed for Joomla 2.5, the code in the search.php is as follows:

    <?php

    //To prevent accessing the document directly, enter this code:
    // no direct access

    defined( '_JEXEC' ) or die( 'Restricted access' );

    $mainframe->registerEvent( 'onSearch', 'plgSearchHotels' );

    JPlugin::loadLanguage( 'plg_search_hotels' );

    function &plgSearchHotelsAreas()
    {
            static $areas = array(
                    'hotels' => 'Hotels'
            );
            return $areas;
    } 

    function plgSearchHotels ( $searchdate, $airport, $resort, $numadults, $numchild, $numinfants, $ordering='' )
    {
            $db    =& JFactory::getDBO();
            $user  =& JFactory::getUser(); 

            $plugin =& JPluginHelper::getPlugin('search', 'hotels');

            $searchdate = trim( $searchdate );
            $numpassengers = $numadults + $numchild;

            if ($searchdate == '') {
                return array();
            }


            switch ( $ordering ) {
    //alphabetic, ascending
                    case 'alpha':
                            $order = 'a.name ASC';
                            break;
    //oldest first
                    case 'oldest':
    //popular first
                    case 'popular':
    //newest first
                    case 'newest':
    //default setting: alphabetic, ascending
                    default:
                            $order = 'a.name ASC';
            }

            $searchHotels = JText::_( 'Hotels' );

            $query = 'SELECT mykey, hotelName, resortName, dep, startDate, sellingPrice FROM Availability WHERE startDate = "'.$searchdate.'" AND available = "Y"';
            if($airport !== "A") $query .= ' AND dep = "'.$airport.'"';
            if($resort !== "A") $query .= ' AND resortCode = "'.$resort.'"';
            $query .= ' AND seats >= '.$numpassengers;
            $query .= ' AND beds >= '.$numpassengers.' ORDER BY sellingPrice ASC';

            $db->setQuery( $query, 0, $limit );
            $rows = $db->loadObjectList();

            return $rows;
    }
    ?>

However, when I try to use this code on Joomla 3.3, it's not working correctly. Any ideas what I'm doing wrong?

1 Answer 1

7

Suggested readings are "Adapting a Joomla 1.5 extension to Joomla 2.5" and the "Creating A Search Plugin" article on Joomla Docs.

Actually, that code look's like a Joomla! 1.5 era search plugin. However, it's not of a standard form… the second method you have plgSearchHotels() follows the naming convention for Joomla 1.5 but the variables passed to it don't match up, e.g. this is the signature of a standard Content search plugin from 1.5:

plgSearchContent( $text, $phrase='', $ordering='', $areas=null )

Obviously the Hotels component is doing something unique.

The give away, re: Joomla 1.5, is the $mainframe which was deprecated in the 1.6/2.5 line, and doesn't exist and isn't required in a new plugin. So first up you need to remove that line.

A Joomla 1.6+ style plugin (of any type) extends the class of JPlugin for example the standard Search plugin for Content in 2.5/3.x+ is defined as:

class plgSearchContent extends JPlugin
{
}

Luckily the class implementation didn't make the work too hard, and while the previous function names changed into method names for the new class and got relabelled they're otherwise pretty similar.

Your function &plgSearchHotelsAreas() will become function onContentSearchAreas(). That was the simple one… normally the second method is as described above and would be renamed to onContentSearch() - without knowing else is happening I can't really advise more on this particular method and how you'll fix it.

So, the next thing is to wrap your renamed functions in the appropriate class, this is usually a portmanteu of the plugin type (Search) and the component's core name (i.e. Hotels), so going on your code I'm guessing it will be:

class plgSearchHotels extends JPlugin
{
}

That should get you started… once you've read the documentation, updated the plugin and hit some bugs I'd suggest opening specific questions about any subsequent issues you hit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.