loadLanguage(); require_once(JPATH_SITE.DS.'components'.DS.'com_muscol'.DS.'helpers'.DS.'helpers.php'); } /** * @return array An array of search areas */ function onContentSearchAreas() { static $areas = array( 'albums' => 'Albums', 'artists' => 'Artists', 'songs' => 'Songs' ); return $areas; } function onContentSearch($text, $phrase='', $ordering='', $areas=null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } if(!$areas){ $buscar = true ; $areas = array(); } $rows = array(); $rows2 = array(); $rows3 = array(); $text_orig = $text; //ALBUMS if($text_orig != ""){ if(in_array('albums', $areas) || $buscar){ $keywords = $text_orig; $keyword = explode(" ",$keywords); $cadena = array(); for($i=0;$iQuote( '% '.addslashes( $keyword[$i] ).' %', false ); $cadena[] = " (a.keywords LIKE ".$text.") "; } if($i>0){ $where = implode(" AND ",$cadena); } $query = ' SELECT a.*, ar.artist_name as section, ar.letter, a.name as title, a.added as created, a.review as text '. ' FROM #__muscol_albums AS a '. ' LEFT JOIN #__muscol_artists as ar ON ar.id = a.artist_id '. ' WHERE '. $where . ' ORDER BY a.year,a.month '; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); if ($rows) { foreach($rows as $key => $row) { $rows[$key]->href = MusColHelper::routeAlbum($row->id); } } } } //ARTISTS if($text_orig != ""){ if(in_array('artists', $areas) || $buscar){ $keywords = $text_orig; $keyword = explode(" ",$keywords); $cadena = array(); for($i=0;$iQuote( '% '.addslashes( $keyword[$i] ).' %', false ); $cadena[] = " (a.keywords LIKE ".$text.") "; } if($i>0){ $where = implode(" AND ",$cadena); } $query = ' SELECT a.*, a.artist_name as title, a.added as created, a.review as text '. ' FROM #__muscol_artists AS a '. ' WHERE '. $where . ' ORDER BY a.artist_name '; $db->setQuery( $query ); $albums_data = $db->loadObjectList(); $db->setQuery($query, 0, $limit); $rows2 = $db->loadObjectList(); if ($rows2) { foreach($rows2 as $key => $row) { $rows2[$key]->href = MusColHelper::routeArtist($row->id); } } } } //SONGS if($text_orig != ""){ if(in_array('songs', $areas) || $buscar){ $query = ' SELECT a.*, ar.artist_name as section, a.name as title, a.added as created, a.review as text '. ' FROM #__muscol_songs AS a '. ' LEFT JOIN #__muscol_artists AS ar ON ar.id = a.artist_id ' . ' WHERE a.name LIKE "%'.addslashes($text_orig).'%" '. ' OR ar.artist_name LIKE "%'.addslashes($text_orig).'%" '. ' ORDER BY a.name '; $db->setQuery( $query ); $albums_data = $db->loadObjectList(); $db->setQuery($query, 0, $limit); $rows3 = $db->loadObjectList(); if ($rows3) { foreach($rows3 as $key => $row) { $rows3[$key]->href = MusColHelper::routeSong($row->id); } } } } $return = array_merge($rows, $rows2, $rows3); return $return; } }