| 1 |
<?php |
| 2 |
/** |
| 3 |
* Bricks Builder Property Embedded Virtual Tours Widget. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 9 |
|
| 10 |
class Bricks_Builder_Property_Embedded_Virtual_Tours_Widget extends \Bricks\Element { |
| 11 |
|
| 12 |
// Element properties |
| 13 |
public $category = 'propertyhive'; |
| 14 |
public $name = 'bricks-builder-property-embedded-virtual-tours'; |
| 15 |
public $icon = 'fas fa-video'; |
| 16 |
|
| 17 |
public function get_label() |
| 18 |
{ |
| 19 |
return esc_html__( 'Embedded Virtual Tours', 'propertyhive' ); |
| 20 |
} |
| 21 |
|
| 22 |
public function set_control_groups() |
| 23 |
{ |
| 24 |
/*$this->control_groups['form'] = [ |
| 25 |
'title' => esc_html__( 'Form', 'propertyhive' ), |
| 26 |
'tab' => 'content', // content / style |
| 27 |
];*/ |
| 28 |
} |
| 29 |
|
| 30 |
public function set_controls() |
| 31 |
{ |
| 32 |
$this->controls['oembed'] = [ |
| 33 |
'tab' => 'content', |
| 34 |
//'group' => 'settings', |
| 35 |
'label' => esc_html__( 'Use oEmbed', 'propertyhive' ), |
| 36 |
'type' => 'select', |
| 37 |
'options' => [ |
| 38 |
'no' => __( 'No', 'propertyhive' ), |
| 39 |
'yes' => __( 'Yes', 'propertyhive' ), |
| 40 |
], |
| 41 |
'default' => __( 'no', 'propertyhive' ), |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
public function render() |
| 46 |
{ |
| 47 |
global $property; |
| 48 |
|
| 49 |
if ( !isset($property->id) ) |
| 50 |
{ |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
$virtual_tours = $property->get_virtual_tours(); |
| 55 |
|
| 56 |
if ( empty($virtual_tours) ) |
| 57 |
{ |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
$root_classes[] = $this->name; |
| 62 |
|
| 63 |
// Add 'class' attribute to element root tag |
| 64 |
$this->set_attribute( '_root', 'class', $root_classes ); |
| 65 |
|
| 66 |
echo "<div {$this->render_attributes( '_root' )}>"; |
| 67 |
|
| 68 |
echo '<h4>' . __( 'Virtual Tours', 'propertyhive' ) . '</h4>'; |
| 69 |
|
| 70 |
foreach ( $virtual_tours as $virtual_tour ) |
| 71 |
{ |
| 72 |
if ( isset($this->settings['oembed']) && $this->settings['oembed'] == 'yes' ) |
| 73 |
{ |
| 74 |
$embed_code = wp_oembed_get($virtual_tour['url']); |
| 75 |
echo $embed_code; |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
$virtual_tour['url'] = preg_replace( |
| 80 |
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", |
| 81 |
"//www.youtube.com/embed/$2", |
| 82 |
$virtual_tour['url'] |
| 83 |
); |
| 84 |
|
| 85 |
$virtual_tour['url'] = preg_replace( |
| 86 |
'#https?://(www\.)?youtube\.com/shorts/([^/?]+)#', |
| 87 |
'//www.youtube.com/embed/$2', |
| 88 |
$virtual_tour['url'] |
| 89 |
); |
| 90 |
|
| 91 |
$virtual_tour['url'] = preg_replace( |
| 92 |
'/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*/i', |
| 93 |
"//player.vimeo.com/video/$6", |
| 94 |
$virtual_tour['url'] |
| 95 |
); |
| 96 |
|
| 97 |
echo '<iframe src="' . esc_url($virtual_tour['url']) . '" height="500" width="100%" allowfullscreen frameborder="0" allow="fullscreen"></iframe>'; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
echo '</div>'; |
| 102 |
} |
| 103 |
} |