| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
class Divi_Property_Epcs_Widget extends ET_Builder_Module |
| 7 |
{ |
| 8 |
public $slug = 'et_pb_property_epcs_widget'; |
| 9 |
public $vb_support = 'partial'; |
| 10 |
public $icon = ''; |
| 11 |
|
| 12 |
public function init() { |
| 13 |
$this->name = esc_html__( 'Property EPCs', 'propertyhive' ); |
| 14 |
$this->icon = '|'; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_fields() |
| 18 |
{ |
| 19 |
$fields = array(); |
| 20 |
|
| 21 |
return $fields; |
| 22 |
} |
| 23 |
|
| 24 |
public function render( $attrs, $content, $render_slug ) |
| 25 |
{ |
| 26 |
$post_id = get_the_ID(); |
| 27 |
|
| 28 |
$property = new PH_Property($post_id); |
| 29 |
|
| 30 |
if ( !isset($property->id) ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
ob_start(); |
| 35 |
|
| 36 |
if ( get_option('propertyhive_epcs_stored_as', '') == 'urls' ) |
| 37 |
{ |
| 38 |
$epc_urls = $property->_epc_urls; |
| 39 |
if ( is_array($epc_urls) && !empty( $epc_urls ) ) |
| 40 |
{ |
| 41 |
foreach ($epc_urls as $epc) |
| 42 |
{ |
| 43 |
echo '<a href="' . esc_url($epc['url']) . '" data-fancybox="epcs" rel="nofollow"><img src="' . esc_url($epc['url']) . '" alt=""></a>'; |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
else |
| 48 |
{ |
| 49 |
$epc_attachment_ids = $property->get_epc_attachment_ids(); |
| 50 |
|
| 51 |
if ( !empty($epc_attachment_ids) ) |
| 52 |
{ |
| 53 |
echo '<div class="epcs">'; |
| 54 |
|
| 55 |
echo '<h4>' . esc_html(__( 'EPCs', 'propertyhive' )) . '</h4>'; |
| 56 |
|
| 57 |
foreach ( $epc_attachment_ids as $attachment_id ) |
| 58 |
{ |
| 59 |
if ( wp_attachment_is_image($attachment_id) ) |
| 60 |
{ |
| 61 |
echo '<a href="' . esc_url(wp_get_attachment_url($attachment_id)) . '" data-fancybox="epc" rel="nofollow"><img src="' . esc_url(wp_get_attachment_url($attachment_id)) . '" alt=""></a>'; |
| 62 |
} |
| 63 |
else |
| 64 |
{ |
| 65 |
echo '<a href="' . esc_url(wp_get_attachment_url($attachment_id)) . '" target="_blank" rel="nofollow">' . esc_html(__( 'View EPC', 'propertyhive' )) . '</a>'; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
echo '</div>'; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
return $this->_render_module_wrapper( ob_get_clean(), $render_slug ); |
| 74 |
} |
| 75 |
} |