Last active
August 30, 2021 09:05
-
-
Save iamrobert/8dd0339c279bb38066e13086f6f8eaa8 to your computer and use it in GitHub Desktop.
Flexicontent Serve unique image or video content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// No direct access | |
defined( '_JEXEC' )or die( 'Restricted access' ); | |
$detailsField_id = 999; | |
$detailsFieldName = 'field_image'; | |
$detailsImgVid = ''; | |
FlexicontentFields::getFieldDisplay( $item, "$detailsFieldName" ); | |
if ( FlexicontentFields::getFieldDisplay( $item, "$detailsFieldName" ) != "" ) { | |
// GET IMG FIELD VALUES | |
$dvals = $item->fieldvalues[ $detailsField_id ]; | |
$detailsImg = $item->fields[ "$detailsFieldName" ]; | |
$largeDPic = $detailsImg->thumbs_src[ 'large' ]; | |
$originalDPic = $detailsImg->thumbs_src[ 'original' ]; | |
$mediumDPic = $detailsImg->thumbs_src[ 'medium' ]; | |
$smallDPic = $detailsImg->thumbs_src[ 'small' ]; | |
// $thumbPic = $detailsImg->thumbs_src[ 'backend' ]; | |
for ( $i = 0; $i < count( $originalDPic ); $i++ ): | |
$v = JArrayHelper::getValue( $dvals, $i ); | |
if ( @unserialize( $v ) !== false || $v === 'b:0;' )$v = unserialize( $v ); | |
//print_r($v); | |
/* + GET IMAGE (as mediaurl is only for video) | |
===============================================*/ | |
if ( $v[ 'mediaurl' ] == '' ) { | |
$alt = ''; | |
//GET ALT VALUE | |
if ( $v[ 'alt' ] !== '' ) { | |
$alt = $v[ 'alt' ]; | |
} | |
//IMG THUMB WIDTHS/HEIGHTS | |
list( $lsource_w, $lsource_h ) = getimagesize( JURI::base() . $largeDPic[ $i ] ); | |
$imgDims = 'width="' . $lsource_w . '" height="' . $lsource_h . '" '; | |
$detailsImgVid .= ' | |
<picture> | |
<source | |
media="(max-width: 32rem)" | |
srcset="' . $smallDPic[ $i ] . '" /> | |
<source | |
media="(min-width: 32rem) and (max-width: 64rem)" | |
srcset="' . $mediumDPic[ $i ] . '" /> | |
<img | |
src="' . $largeDPic[ $i ] . '" ' . $imgDims . ' class="w100" alt="' . $alt . '" loading="lazy"/> | |
</picture>'; | |
} | |
//VIDEO | |
if ( $v[ 'mediaurl' ] != '' ) { | |
//GET VIDEO URL | |
$datavideo = $v[ 'mediaurl' ]; | |
//GET YOUTUBE ID | |
if ( preg_match( '/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/', $datavideo, $match ) ) { | |
$datavideo = $match[ 1 ]; | |
$provider = "youtube"; | |
} | |
//GET VIMEO ID | |
if ( preg_match( "/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/", $datavideo, $output_array ) ) { | |
$datavideo = $output_array[ 5 ]; | |
$provider = "vimeo"; | |
} | |
//CREATE MEDIA OBJECT | |
$detailsImgVid .= '<div class="plyr__video-embed">'; | |
$detailsImgVid .= '<div data-plyr-provider="' . $provider . '" data-plyr-embed-id="' . $datavideo . '" class="js-player"></div>'; | |
$detailsImgVid .= '</div>'; | |
} | |
endfor; | |
}; | |
?> | |
<?php echo $detailsImgVid; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment