Source for file content.php
Documentation is available at content.php
* @subpackage Search.content
* @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/router.php';
* @subpackage Search.content
* @return array An array of search areas
'content' =>
'JGLOBAL_ARTICLES'
* The sql must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
* @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 the search it to be restricted to areas, null if search all
public function onContentSearch($text, $phrase =
'', $ordering =
'', $areas =
null)
$groups =
implode(',', $user->getAuthorisedViewLevels());
require_once JPATH_SITE .
'/components/com_content/helpers/route.php';
$sContent =
$this->params->get('search_content', 1);
$sArchived =
$this->params->get('search_archived', 1);
$limit =
$this->params->def('search_limit', 50);
$nullDate =
$db->getNullDate();
$text =
$db->quote('%' .
$db->escape($text, true) .
'%', false);
$wheres2[] =
'a.title LIKE ' .
$text;
$wheres2[] =
'a.introtext LIKE ' .
$text;
$wheres2[] =
'a.fulltext LIKE ' .
$text;
$wheres2[] =
'a.metakey LIKE ' .
$text;
$wheres2[] =
'a.metadesc LIKE ' .
$text;
$where =
'(' .
implode(') OR (', $wheres2) .
')';
foreach ($words as $word)
$word =
$db->quote('%' .
$db->escape($word, true) .
'%', false);
$wheres2[] =
'a.title LIKE ' .
$word;
$wheres2[] =
'a.introtext LIKE ' .
$word;
$wheres2[] =
'a.fulltext LIKE ' .
$word;
$wheres2[] =
'a.metakey LIKE ' .
$word;
$wheres2[] =
'a.metadesc LIKE ' .
$word;
$wheres[] =
implode(' OR ', $wheres2);
$where =
'(' .
implode(($phrase ==
'all' ?
') AND (' :
') OR ('), $wheres) .
')';
$order =
'a.created ASC';
$order =
'c.title ASC, a.title ASC';
$order =
'a.created DESC';
$query =
$db->getQuery(true);
if ($sContent &&
$limit >
0)
$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';
$case_when1 =
' CASE WHEN ';
$case_when1 .=
$query->charLength('c.alias', '!=', '0');
$c_id =
$query->castAsChar('c.id');
$case_when1 .=
$query->concatenate(array($c_id, 'c.alias'), ':');
$case_when1 .=
$c_id .
' END as catslug';
$query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created')
->select($query->concatenate(array('a.introtext', 'a.fulltext')) .
' AS text')
->select('c.title AS section, ' .
$case_when .
',' .
$case_when1 .
', ' .
'\'2\' AS browsernav')
->from('#__content AS a')
->join('INNER', '#__categories AS c ON c.id=a.catid')
'(' .
$where .
') AND a.state=1 AND c.published = 1 AND a.access IN (' .
$groups .
') '
.
'AND c.access IN (' .
$groups .
') '
.
'AND (a.publish_up = ' .
$db->quote($nullDate) .
' OR a.publish_up <= ' .
$db->quote($now) .
') '
.
'AND (a.publish_down = ' .
$db->quote($nullDate) .
' OR a.publish_down >= ' .
$db->quote($now) .
')'
->group('a.id, a.title, a.metadesc, a.metakey, a.created, a.introtext, a.fulltext, c.title, a.alias, c.alias, c.id')
$query->where('a.language in (' .
$db->quote($tag) .
',' .
$db->quote('*') .
')')
->where('c.language in (' .
$db->quote($tag) .
',' .
$db->quote('*') .
')');
$db->setQuery($query, 0, $limit);
$list =
$db->loadObjectList();
foreach ($list as $key =>
$item)
// search archived content
if ($sArchived &&
$limit >
0)
$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';
$case_when1 =
' CASE WHEN ';
$case_when1 .=
$query->charLength('c.alias', '!=', '0');
$c_id =
$query->castAsChar('c.id');
$case_when1 .=
$query->concatenate(array($c_id, 'c.alias'), ':');
$case_when1 .=
$c_id .
' END as catslug';
'a.title AS title, a.metadesc, a.metakey, a.created AS created, '
.
$query->concatenate(array("a.introtext", "a.fulltext")) .
' AS text,'
.
$case_when .
',' .
$case_when1 .
', '
.
'c.title AS section, \'2\' AS browsernav'
//.'CONCAT_WS("/", c.title) AS section, \'2\' AS browsernav' );
$query->from('#__content AS a')
->join('INNER', '#__categories AS c ON c.id=a.catid AND c.access IN (' .
$groups .
')')
'(' .
$where .
') AND a.state = 2 AND c.published = 1 AND a.access IN (' .
$groups
.
') AND c.access IN (' .
$groups .
') '
.
'AND (a.publish_up = ' .
$db->quote($nullDate) .
' OR a.publish_up <= ' .
$db->quote($now) .
') '
.
'AND (a.publish_down = ' .
$db->quote($nullDate) .
' OR a.publish_down >= ' .
$db->quote($now) .
')'
$query->where('a.language in (' .
$db->quote($tag) .
',' .
$db->quote('*') .
')')
->where('c.language in (' .
$db->quote($tag) .
',' .
$db->quote('*') .
')');
$db->setQuery($query, 0, $limit);
$list3 =
$db->loadObjectList();
// find an itemid for archived to use if there isn't another one
$item =
$app->getMenu()->getItems('link', 'index.php?option=com_content&view=archive', true);
$itemid = isset
($item->id) ?
'&Itemid=' .
$item->id :
'';
foreach ($list3 as $key =>
$item)
$created_month =
$date->format("n");
$created_year =
$date->format("Y");
$list3[$key]->href =
JRoute::_('index.php?option=com_content&view=archive&year=' .
$created_year .
'&month=' .
$created_month .
$itemid);
foreach ($row as $article)
if (SearchHelper::checkNoHTML($article, $searchText, array('text', 'title', 'metadesc', 'metakey')))
Documentation generated on Tue, 19 Nov 2013 14:56:50 +0100 by phpDocumentor 1.4.3