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 / elementor-widgets / property-embedded-virtual-tours.php

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

177 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Property Embedded Virtual Tours Widget.
4 *
5 * @since 1.0.0
6 */
7 class Elementor_Property_Embedded_Virtual_Tours_Widget extends \Elementor\Widget_Base {
8
9 public function get_name() {
10 return 'property-embedded-virtual-tours';
11 }
12
13 public function get_title() {
14 return __( 'Embedded Virtual Tours', 'propertyhive' );
15 }
16
17 public function get_icon() {
18 return 'eicon-video-camera';
19 }
20
21 public function get_categories() {
22 return [ 'property-hive' ];
23 }
24
25 public function get_keywords() {
26 return [ 'property hive', 'propertyhive', 'property', 'virtual tour' ];
27 }
28
29 protected function register_controls() {
30
31 $this->start_controls_section(
32 'style_section',
33 [
34 'label' => __( 'Virtual Tours', 'propertyhive' ),
35 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
36 ]
37 );
38
39 $this->add_control(
40 'show_title',
41 [
42 'label' => __( 'Show Title', 'propertyhive' ),
43 'type' => \Elementor\Controls_Manager::SWITCHER,
44 'label_on' => __( 'Show', 'propertyhive' ),
45 'label_off' => __( 'Hide', 'propertyhive' ),
46 'return_value' => 'yes',
47 'default' => 'yes',
48 ]
49 );
50
51 $this->add_group_control(
52 \Elementor\Group_Control_Typography::get_type(),
53 [
54 'name' => 'title_typography',
55 'label' => __( 'Title Typography', 'propertyhive' ),
56 'global' => [
57 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_PRIMARY,
58 ],
59 'selector' => '{{WRAPPER}} .embedded-virtual-tours h4',
60 'condition' => [
61 'show_title' => 'yes'
62 ],
63 ]
64 );
65
66 $this->add_control(
67 'title_color',
68 [
69 'label' => __( 'Title Colour', 'propertyhive' ),
70 'type' => \Elementor\Controls_Manager::COLOR,
71 'global' => [
72 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_PRIMARY,
73 ],
74 'selectors' => [
75 '{{WRAPPER}} .embedded-virtual-tours h4' => 'color: {{VALUE}}',
76 ],
77 'condition' => [
78 'show_title' => 'yes'
79 ],
80 ]
81 );
82
83 $this->add_control(
84 'oembed',
85 [
86 'label' => __( 'Use oEmbed', 'propertyhive' ),
87 'type' => \Elementor\Controls_Manager::SWITCHER,
88 'label_on' => __( 'Yes', 'propertyhive' ),
89 'label_off' => __( 'No', 'propertyhive' ),
90 'return_value' => 'yes',
91 'default' => 'no',
92 ]
93 );
94
95 $this->end_controls_section();
96
97 }
98
99 protected function render() {
100
101 global $property;
102
103 $settings = $this->get_settings_for_display();
104
105 if ( !isset($property->id) ) {
106 return;
107 }
108
109 if ( isset($settings['show_title']) && $settings['show_title'] != 'yes' )
110 {
111 ?>
112 <style type="text/css">
113 .embedded-virtual-tours h4 { display:none; }
114 </style>
115 <?php
116 }
117
118 $virtual_tours = $property->get_virtual_tours();
119
120 if ( !empty($virtual_tours) )
121 {
122 echo '<div class="embedded-virtual-tours">';
123
124 echo '<h4>' . esc_html(__( 'Virtual Tours', 'propertyhive' )) . '</h4>';
125
126 foreach ( $virtual_tours as $virtual_tour )
127 {
128 if ( isset($settings['oembed']) && $settings['oembed'] == 'yes' )
129 {
130 $embed_code = wp_oembed_get($virtual_tour['url']);
131 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_oembed_get() uses WordPress provider trust and sanitization; preserve supported provider scripts and trusted PHP filters.
132 echo $embed_code;
133 }
134 else
135 {
136 if ( strpos($virtual_tour['url'], 'instagram.com/reel') !== false )
137 {
138 // phpcs:ignore PluginCheck.CodeAnalysis.EnqueuedResourceOffloading.OffloadedContent, WordPress.WP.EnqueuedResourceParameters.MissingVersion -- Provider maintains this API endpoint without a plugin version. Required Instagram SDK for the property's configured Reel embed.
139 wp_enqueue_script( 'propertyhive-instagram-embed', 'https://www.instagram.com/embed.js', array(), null, true );
140 echo '
141 <blockquote class="instagram-media"
142 data-instgrm-permalink="' . esc_url($virtual_tour['url']) . '"
143 data-instgrm-version="14"></blockquote>
144 ';
145 }
146 else
147 {
148 $virtual_tour['url'] = preg_replace(
149 "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
150 "//www.youtube.com/embed/$2",
151 $virtual_tour['url']
152 );
153
154 $virtual_tour['url'] = preg_replace(
155 '#https?://(www\.)?youtube\.com/shorts/([^/?]+)#',
156 '//www.youtube.com/embed/$2',
157 $virtual_tour['url']
158 );
159
160 $virtual_tour['url'] = preg_replace(
161 '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*/i',
162 "//player.vimeo.com/video/$6",
163 $virtual_tour['url']
164 );
165
166 echo '<iframe src="' . esc_url($virtual_tour['url']) . '" height="500" width="100%" allowfullscreen frameborder="0" allow="fullscreen"></iframe>';
167 }
168 }
169 }
170
171 echo '</div>';
172 }
173
174 }
175
176 }
177