/
* search for some keywords in all comments
*
* @param the search string
* @param int the offset from the start of the list; usually, 0 or 1
* @param int the number of items to display
* @param string the list variant, if any
* @return NULL on error, else an ordered array with $url => ($prefix,
$label, $suffix, $icon)
*
* @see search.php
* @see services/search.php
*/
function &search($pattern, $offset=0, $count=30, $variant='search') {
global $context;
// match
$match = '';
$words = preg_split('/s/', $pattern);
while($word = each($words)) {
if($match)
$match .= ' AND ';
$match .= "MATCH(description)
AGAINST('".SQL::escape($word['value'])."')";
}
// the list of comments
/*$query = "SELECT * FROM ".SQL::table_name('comments')." AS comments "
." WHERE ".$match
." ORDER BY comments.edit_date DESC"
." LIMIT ".$offset.','.$count;
*/
// ****** search from Dobliu **********
$query = "SELECT p1.* FROM (SELECT * FROM
".SQL::table_name('comments')."
AS comments "
." WHERE ".$match ." ORDER BY comments.edit_date DESC) AS
p1,".SQL::table_name('articles')
. " AS articles,".SQL::table_name('sections')
." AS sections WHERE p1.anchor_id = articles.id AND sections.id
=
articles.anchor_id";
// limit the scope of the request
$query .= " AND (sections.active='Y'";
// add restricted items to members, or if teasers are allowed
if(Surfer::is_logged() ||
!isset($context['users_without_teasers'])||($context['users_without_teasers
'] != 'Y'))
$query .= " OR sections.active='R'";
// add associate
if(Surfer::is_empowered('S'))
$query .= " OR sections.active='N'";
// include managed sections
if(count($my_sections = Surfer::assigned_sections()))
$query .= " OR sections.id LIKE ".join(" OR sections.id LIKE ",
$my_sections);
$query .= ") LIMIT ".$offset.','.$count;
// ****** search from Dobliu ************
$output =& Comments::list_selected(SQL::query($query), $variant);
return $output;
}