| 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 |
echo $embed_code; |
| 132 |
} |
| 133 |
else |
| 134 |
{ |
| 135 |
if ( strpos($virtual_tour['url'], 'instagram.com/reel') !== false ) |
| 136 |
{ |
| 137 |
echo ' |
| 138 |
<blockquote class="instagram-media" |
| 139 |
data-instgrm-permalink="' . esc_url($virtual_tour['url']) . '" |
| 140 |
data-instgrm-version="14"></blockquote> |
| 141 |
<script async src="https://www.instagram.com/embed.js"></script> |
| 142 |
'; |
| 143 |
} |
| 144 |
else |
| 145 |
{ |
| 146 |
$virtual_tour['url'] = preg_replace( |
| 147 |
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", |
| 148 |
"//www.youtube.com/embed/$2", |
| 149 |
$virtual_tour['url'] |
| 150 |
); |
| 151 |
|
| 152 |
$virtual_tour['url'] = preg_replace( |
| 153 |
'#https?://(www\.)?youtube\.com/shorts/([^/?]+)#', |
| 154 |
'//www.youtube.com/embed/$2', |
| 155 |
$virtual_tour['url'] |
| 156 |
); |
| 157 |
|
| 158 |
$virtual_tour['url'] = preg_replace( |
| 159 |
'/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*/i', |
| 160 |
"//player.vimeo.com/video/$6", |
| 161 |
$virtual_tour['url'] |
| 162 |
); |
| 163 |
|
| 164 |
echo '<iframe src="' . esc_url($virtual_tour['url']) . '" height="500" width="100%" allowfullscreen frameborder="0" allow="fullscreen"></iframe>'; |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
echo '</div>'; |
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
} |