PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / avada-widgets / property-embedded-virtual-tours-shortcode.php

property-embedded-virtual-tours-shortcode.php in Property Hive 2.3.1, at includes/avada-widgets/property-embedded-virtual-tours-shortcode.php

80 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7
8 add_shortcode( 'avada_property_embedded_virtual_tours', function( $atts ) {
9 $atts = shortcode_atts( array(
10 'show_title' => '',
11 'oembed' => '',
12 ), $atts );
13
14 if ( get_post_type( get_the_ID() ) != 'property' )
15 {
16 return '';
17 }
18
19 fusion_element_rendering_elements( true );
20
21 global $property;
22
23 if ( empty($property) )
24 {
25 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared frontend property global used by the Avada shortcode contract; changing $property would break the existing property context passed to these widgets.
26 $property = new PH_Property(get_the_ID());
27 }
28
29 ob_start();
30
31 $virtual_tours = $property->get_virtual_tours();
32
33 if ( !empty($virtual_tours) )
34 {
35 echo '<div class="embedded-virtual-tours">';
36
37 if ( $atts['show_title'] == 'yes' ) { echo '<h4>' . esc_html(__( 'Virtual Tours', 'propertyhive' )) . '</h4>'; }
38
39 foreach ( $virtual_tours as $virtual_tour )
40 {
41 if ( isset($atts['oembed']) && $atts['oembed'] == 'yes' )
42 {
43 $embed_code = wp_oembed_get($virtual_tour['url']);
44 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_oembed_get() uses WordPress provider trust and sanitization; preserve supported provider scripts and trusted PHP filters.
45 echo $embed_code;
46 }
47 else
48 {
49 $virtual_tour['url'] = preg_replace(
50 "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
51 "//www.youtube.com/embed/$2",
52 $virtual_tour['url']
53 );
54
55 $virtual_tour['url'] = preg_replace(
56 '#https?://(www\.)?youtube\.com/shorts/([^/?]+)#',
57 '//www.youtube.com/embed/$2',
58 $virtual_tour['url']
59 );
60
61 $virtual_tour['url'] = preg_replace(
62 '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*/i',
63 "//player.vimeo.com/video/$6",
64 $virtual_tour['url']
65 );
66
67 echo '<iframe src="' . esc_url($virtual_tour['url']) . '" height="500" width="100%" allowfullscreen frameborder="0" allow="fullscreen"></iframe>';
68 }
69 }
70
71 echo '</div>';
72 }
73
74 $html = ob_get_clean();
75
76 fusion_element_rendering_elements( false );
77
78 return $html;
79 });
80