How to have DirectPHP commands processed in Joomla search (for Joomla 1.5.x)?
Written by kksou   
Monday, 04 August 2008

Suppose you have installed the DirectPHP plguin, which allows you to embed PHP commands right inside your Joomla content item..

In standard Joomla 1.5.x search, the DirectPHP commands will be visible in the search result. This is both undesirable and confusing to the users.

This article shows you how to have the DirectPHP commands processed in Joomla search.

Note: the steps below works for Joomla 1.5.x only. For Joomla 1.0.x, please refer to How to have DirectPHP commands processed in Joomla search (for Joomla 1.0.x)?.


Solution

All you need is to add 7 lines to have the DirectPHP commands processed by Joomla search.

For Joomla 1.5.3 and earlier

  1. Go to the folder <Joomla root folder>/components/com_search/models, you will see a file called search.php.
  2. Open this file search.php in your favorite editor.
  3. Go to around Line 128. In the function getData(), add the seven lines highlighted in yellow as shown follow:
  4. function getData()
    {
    	// Lets load the content if it doesn't already exist
    	if (empty($this->_data))
    	{
    		$areas = $this->getAreas();
    
    		JPluginHelper::importPlugin( 'search');
    		$dispatcher =& JDispatcher::getInstance();
    		$results = $dispatcher->trigger( 'onSearch', array(
    			$this->getState('keyword'),
    			$this->getState('match'),
    			$this->getState('ordering'),
    			$areas['active']) );
    
    		$rows = array();
    		for ($i = 0, $n = count( $results); $i < $n; $i++) {
    			$rows = array_merge( (array)$rows, (array)$results[$i] );
    		}
    
    		$dispatcher	=& JDispatcher::getInstance();
    		JPluginHelper::importPlugin('content');
    		global $mainframe;
    		$params2 =& $mainframe->getParams('com_content');
    		for ($i=0; $i<count($rows); ++$i) {
    			$results = $dispatcher->trigger('onPrepareContent',
    				array (&$rows[$i], &$params2, 0));
    		}
    
    		$this->_total	= count($rows);
    		if($this->getState('limit') > 0) {
    			$this->_data    = array_splice($rows, 
    			    $this->getState('limitstart'), $this->getState('limit'));
    		} else {
    			$this->_data = $rows;
    		}
    	}
    
    	return $this->_data;
    }
    
  5. Save and close this file.

For Joomla 1.5.4 and after

  1. Go to the folder <Joomla root folder>/components/com_search/models, you will see a file called search.php.
  2. Open this file search.php in your favorite editor.
  3. Go to around Line 128. In the function getData(), add the seven lines highlighted in yellow as shown follow:
  4. function getData()
    {
    	// Lets load the content if it doesn't already exist
    	if (empty($this->_data))
    	{
    		$areas = $this->getAreas();
    
    		JPluginHelper::importPlugin( 'search');
    		$dispatcher =& JDispatcher::getInstance();
    		$results = $dispatcher->trigger( 'onSearch', array(
    			$this->getState('keyword'),
    			$this->getState('match'),
    			$this->getState('ordering'),
    			$areas['active']) );
    
    		$rows = array();
    		for ($i = 0, $n = count( $results); $i < $n; $i++) {
    			// Lets remove HTML and check again
    			foreach ($results[$i] as $_result) {
    			    if ( strpos(strtolower(strip_tags($_result->text)),
    			        strtolower($this->getState('keyword'))) === false) {
    			    } else {
    				$rows[] = $_result;
    			    }
    			}
    		}
    
    		$dispatcher	=& JDispatcher::getInstance();
    		JPluginHelper::importPlugin('content');
    		global $mainframe;
    		$params2 =& $mainframe->getParams('com_content');
    		for ($i=0; $i<count($rows); ++$i) {
    			$results = $dispatcher->trigger('onPrepareContent',
    				array (&$rows[$i], &$params2, 0));
    		}
    
    		$this->_total	= count($rows);
    		if($this->getState('limit') > 0) {
    			$this->_data    = array_splice($rows,
    			    $this->getState('limitstart'), $this->getState('limit'));
    		} else {
    			$this->_data = $rows;
    		}
    	}
    
    	return $this->_data;
    }
    
  5. Save and close this file.

That's it! Your DirectPHP commands should now be processed even within Joomla search!


 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved