| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
class Divi_Property_Map_Link_Widget extends ET_Builder_Module |
| 7 |
{ |
| 8 |
public $slug = 'et_pb_property_map_link_widget'; |
| 9 |
public $vb_support = 'partial'; |
| 10 |
public $icon = ''; |
| 11 |
|
| 12 |
public function init() { |
| 13 |
$this->name = esc_html__( 'Property Map Link', 'propertyhive' ); |
| 14 |
$this->icon = 'Y'; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_fields() |
| 18 |
{ |
| 19 |
$fields = array( |
| 20 |
'map_link_type' => array( |
| 21 |
'label' => esc_html__( 'Link Type', 'propertyhive' ), |
| 22 |
'type' => 'select', |
| 23 |
'options' => [ |
| 24 |
'_blank' => 'Open map in new window', |
| 25 |
'embedded' => 'Open embedded map in lightbox', |
| 26 |
'iframe' => 'Open iframe map in lightbox', |
| 27 |
], |
| 28 |
'toggle_slug' => 'main_content', |
| 29 |
), |
| 30 |
); |
| 31 |
|
| 32 |
return $fields; |
| 33 |
} |
| 34 |
|
| 35 |
public function render( $attrs, $content, $render_slug ) |
| 36 |
{ |
| 37 |
$post_id = get_the_ID(); |
| 38 |
|
| 39 |
$property = new PH_Property($post_id); |
| 40 |
|
| 41 |
if ( !isset($property->id) ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
if ( $property->latitude == '' || $property->longitude == '' || $property->latitude == '0' || $property->longitude == '0' ) |
| 46 |
{ |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
ob_start(); |
| 51 |
|
| 52 |
$link_type = ( isset($this->props['map_link_type']) && !empty($this->props['map_link_type']) ) ? $this->props['map_link_type'] : '_blank'; |
| 53 |
|
| 54 |
switch ($link_type) |
| 55 |
{ |
| 56 |
case "_blank": |
| 57 |
{ |
| 58 |
echo '<a href="https://www.google.com/maps/?q=' . (float)$property->latitude . ',' . (float)$property->longitude . '&ll=' . (float)$property->latitude . ',' . (float)$property->longitude . '" target="_blank">' . esc_html(__( 'View Map', 'propertyhive' )) . '</a>'; |
| 59 |
break; |
| 60 |
} |
| 61 |
case "embedded": |
| 62 |
{ |
| 63 |
echo '<a href="#map_lightbox" data-fancybox>' . esc_html(__( 'View Map', 'propertyhive' )) . '</a>'; |
| 64 |
|
| 65 |
echo '<div id="map_lightbox" style="display:none; width:90%; max-width:800px;">'; |
| 66 |
echo do_shortcode('[property_map]'); |
| 67 |
echo '</div>'; |
| 68 |
break; |
| 69 |
} |
| 70 |
case "iframe": |
| 71 |
{ |
| 72 |
echo '<a |
| 73 |
href="#" |
| 74 |
data-fancybox |
| 75 |
data-type="iframe" |
| 76 |
data-src="https://maps.google.com/?output=embed&f=q&q=' . (float)$property->latitude . ',' . (float)$property->longitude . '&ll=' . (float)$property->latitude . ',' . (float)$property->longitude . '&layer=t&hq=&t=m&z=15" |
| 77 |
>' . esc_html(__( 'View Map', 'propertyhive' )) . '</a>'; |
| 78 |
break; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
return $this->_render_module_wrapper( ob_get_clean(), $render_slug ); |
| 83 |
} |
| 84 |
} |