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)?. SolutionAll you need is to add 7 lines to have the DirectPHP commands processed by Joomla search. For Joomla 1.5.3 and earlier
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;
}
For Joomla 1.5.4 and after
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;
}
That's it! Your DirectPHP commands should now be processed even within Joomla search! |
||
| < Prev | Next > |
|---|




