| 1 |
<?php |
| 2 |
|
| 3 |
add_shortcode( 'avada_property_embedded_virtual_tours', function( $atts ) { |
| 4 |
$atts = shortcode_atts( array( |
| 5 |
'show_title' => '', |
| 6 |
'oembed' => '', |
| 7 |
), $atts ); |
| 8 |
|
| 9 |
if ( get_post_type( get_the_ID() ) != 'property' ) |
| 10 |
{ |
| 11 |
return ''; |
| 12 |
} |
| 13 |
|
| 14 |
fusion_element_rendering_elements( true ); |
| 15 |
|
| 16 |
global $property; |
| 17 |
|
| 18 |
if ( empty($property) ) |
| 19 |
{ |
| 20 |
$property = new PH_Property(get_the_ID()); |
| 21 |
} |
| 22 |
|
| 23 |
ob_start(); |
| 24 |
|
| 25 |
$virtual_tours = $property->get_virtual_tours(); |
| 26 |
|
| 27 |
if ( !empty($virtual_tours) ) |
| 28 |
{ |
| 29 |
echo '<div class="embedded-virtual-tours">'; |
| 30 |
|
| 31 |
if ( $atts['show_title'] == 'yes' ) { echo '<h4>' . esc_html(__( 'Virtual Tours', 'propertyhive' )) . '</h4>'; } |
| 32 |
|
| 33 |
foreach ( $virtual_tours as $virtual_tour ) |
| 34 |
{ |
| 35 |
if ( isset($atts['oembed']) && $atts['oembed'] == 'yes' ) |
| 36 |
{ |
| 37 |
$embed_code = wp_oembed_get($virtual_tour['url']); |
| 38 |
echo $embed_code; |
| 39 |
} |
| 40 |
else |
| 41 |
{ |
| 42 |
$virtual_tour['url'] = preg_replace( |
| 43 |
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", |
| 44 |
"//www.youtube.com/embed/$2", |
| 45 |
$virtual_tour['url'] |
| 46 |
); |
| 47 |
|
| 48 |
$virtual_tour['url'] = preg_replace( |
| 49 |
'#https?://(www\.)?youtube\.com/shorts/([^/?]+)#', |
| 50 |
'//www.youtube.com/embed/$2', |
| 51 |
$virtual_tour['url'] |
| 52 |
); |
| 53 |
|
| 54 |
$virtual_tour['url'] = preg_replace( |
| 55 |
'/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*/i', |
| 56 |
"//player.vimeo.com/video/$6", |
| 57 |
$virtual_tour['url'] |
| 58 |
); |
| 59 |
|
| 60 |
echo '<iframe src="' . esc_url($virtual_tour['url']) . '" height="500" width="100%" allowfullscreen frameborder="0" allow="fullscreen"></iframe>'; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
echo '</div>'; |
| 65 |
} |
| 66 |
|
| 67 |
$html = ob_get_clean(); |
| 68 |
|
| 69 |
fusion_element_rendering_elements( false ); |
| 70 |
|
| 71 |
return $html; |
| 72 |
}); |