Reputation:
Is there a way to modify the code of the Joomla's search component so it can display even the article's image?
I have made a simple code that can search the image or youtube video in the article's text and return the media including the required tags as a string, but where do I put it?
// SEARCH IMAGE OR VIDEO
$hasImage = 0;
$hasVideo = 0;
$articleMedia = '';
$articleText = $text;
// has image?
preg_match_all('/<\s?img[^>]+\>/i', $articleText, $matches);
if(isset($matches['0']['0']))
{
$articleMedia = $matches['0']['0'] ;
$hasImage = 1;
}
// no image? maybe video
if ($hasImage == 0) {
preg_match_all('/(http:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]+))/i', $articleText, $matches);
if(isset($matches['0']['0']))
{
$articleMediaID = $matches['2']['0'] ;
$articleMedia = "//www.youtube.com/embed/" . $articleMediaID;
$hasVideo = 1;
} else {
preg_match_all('/(http:\/\/youtu.be\/([a-zA-Z0-9_-]+))/i', $articleText, $matches1);
if( isset($matches1['0']['0']) ){
$articleMediaID = $matches1['2']['0'] ;
$articleMedia = "//www.youtube.com/embed/" . $articleMediaID;
$hasVideo = 1;
}
}
if ( $hasVideo == 1){
$articleMedia = '<iframe class="youtube" width="100%" src="' . $articleMedia . '" frameborder="0" allowfullscreen></iframe>';
}
}
// END SEARCH IMAGE OR VIDEO
Upvotes: 0
Views: 1168