Source for file categories.php
Documentation is available at categories.php
* @subpackage Search.categories
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
require_once JPATH_SITE .
'/components/com_content/helpers/route.php';
* Categories Search plugin
* @subpackage Search.categories
* Load the language file on instantiation.
* @return array An array of search areas
'categories' =>
'PLG_SEARCH_CATEGORIES_CATEGORIES'
* Categories Search method
* The sql must return the following fields that are
* used in a common display routine: href, title, section, created, text,
* @param string Target search string
* @param string mathcing option, exact|any|all
* @param string ordering option, newest|oldest|popular|alpha|category
* @param mixed An array if restricted to areas, null if search all
public function onContentSearch($text, $phrase =
'', $ordering =
'', $areas =
null)
$groups =
implode(',', $user->getAuthorisedViewLevels());
$sContent =
$this->params->get('search_content', 1);
$sArchived =
$this->params->get('search_archived', 1);
$limit =
$this->params->def('search_limit', 50);
/* TODO: The $where variable does not seem to be used at all
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
$wheres2[] = 'a.title LIKE ' . $text;
$wheres2[] = 'a.description LIKE ' . $text;
$where = '(' . implode(') OR (', $wheres2) . ')';
$words = explode(' ', $text);
foreach ($words as $word)
$word = $db->quote('%' . $db->escape($word, true) . '%', false);
$wheres2[] = 'a.title LIKE ' . $word;
$wheres2[] = 'a.description LIKE ' . $word;
$wheres[] = implode(' OR ', $wheres2);
$where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
$text =
$db->quote('%' .
$db->escape($text, true) .
'%', false);
$query =
$db->getQuery(true);
$case_when =
' CASE WHEN ';
$case_when .=
$query->charLength('a.alias', '!=', '0');
$a_id =
$query->castAsChar('a.id');
$case_when .=
$query->concatenate(array($a_id, 'a.alias'), ':');
$case_when .=
$a_id .
' END as slug';
$query->select('a.title, a.description AS text, \'\' AS created, \'2\' AS browsernav, a.id AS catid, ' .
$case_when)
->from('#__categories AS a')
'(a.title LIKE ' .
$text .
' OR a.description LIKE ' .
$text .
') AND a.published IN (' .
implode(',', $state) .
') AND a.extension = ' .
$db->quote('com_content')
.
'AND a.access IN (' .
$groups .
')'
->group('a.id, a.title, a.description, a.alias')
$query->where('a.language in (' .
$db->quote(JFactory::getLanguage()->getTag()) .
',' .
$db->quote('*') .
')');
$db->setQuery($query, 0, $limit);
$rows =
$db->loadObjectList();
for ($i =
0; $i <
$count; $i++
)
$rows[$i]->section =
JText::_('JCATEGORY');
foreach ($rows as $category)
if (searchHelper::checkNoHTML($category, $searchText, array('name', 'title', 'text')))
Documentation generated on Tue, 19 Nov 2013 14:55:16 +0100 by phpDocumentor 1.4.3