| 1 |
<?php |
| 2 |
/** |
| 3 |
* Bricks Builder Property EPCs Link Widget. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 9 |
|
| 10 |
class Bricks_Builder_Property_Epcs_Link_Widget extends \Bricks\Element { |
| 11 |
|
| 12 |
// Element properties |
| 13 |
public $category = 'propertyhive'; |
| 14 |
public $name = 'bricks-builder-property-epcs-link'; |
| 15 |
public $icon = 'fas fa-chart-bar'; |
| 16 |
|
| 17 |
public function get_label() |
| 18 |
{ |
| 19 |
return esc_html__( 'EPCs Link', '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['height'] = [ |
| 33 |
'tab' => 'content', |
| 34 |
//'group' => 'settings', |
| 35 |
'label' => esc_html__( 'Height', 'propertyhive' ), |
| 36 |
'type' => 'number', |
| 37 |
'default' => 400 |
| 38 |
];*/ |
| 39 |
} |
| 40 |
|
| 41 |
public function render() |
| 42 |
{ |
| 43 |
global $property; |
| 44 |
|
| 45 |
if ( !isset($property->id) ) |
| 46 |
{ |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
$root_classes[] = $this->name; |
| 51 |
|
| 52 |
// Add 'class' attribute to element root tag |
| 53 |
$this->set_attribute( '_root', 'class', $root_classes ); |
| 54 |
|
| 55 |
echo "<div {$this->render_attributes( '_root' )}>"; |
| 56 |
|
| 57 |
if ( get_option('propertyhive_epcs_stored_as', '') == 'urls' ) |
| 58 |
{ |
| 59 |
$epc_urls = $property->epc_urls; |
| 60 |
if ( !is_array($epc_urls) ) { $epc_urls = array(); } |
| 61 |
|
| 62 |
if ( !empty($epc_urls) ) |
| 63 |
{ |
| 64 |
$i = 0; |
| 65 |
foreach ( $epc_urls as $epc ) |
| 66 |
{ |
| 67 |
$image_extensions = array( 'jpg', 'jpeg', 'png', 'gif', 'bmp' ); |
| 68 |
$image = false; |
| 69 |
foreach ( $image_extensions as $image_extension ) |
| 70 |
{ |
| 71 |
if ( strpos(strtolower($epc['url']), '.' . $image_extension) ) |
| 72 |
{ |
| 73 |
$image = true; |
| 74 |
} |
| 75 |
} |
| 76 |
if ( $image ) |
| 77 |
{ |
| 78 |
echo '<a' . ( $i > 0 ? ' style="display:none"' : '' ) . ' href="' . esc_url($epc['url']) . '" data-fancybox="epcs" rel="nofollow">' . esc_html( ( count($epc_urls) > 1 ? __( 'EPCs', 'propertyhive' ) : __( 'EPC', 'propertyhive' ) ) ) . '</a>'; |
| 79 |
++$i; |
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
echo '<a href="' . esc_url($epc['url']) . '" rel="nofollow" target="_blank">' . esc_html( ( count($epc_urls) > 1 ? __( 'EPCs', 'propertyhive' ) : __( 'EPC', 'propertyhive' ) ) ) . '</a>'; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
else |
| 89 |
{ |
| 90 |
$epc_attachment_ids = $property->get_epc_attachment_ids(); |
| 91 |
|
| 92 |
if ( !empty($epc_attachment_ids) ) |
| 93 |
{ |
| 94 |
$i = 0; |
| 95 |
foreach ( $epc_attachment_ids as $attachment_id ) |
| 96 |
{ |
| 97 |
echo '<a' . ( $i > 0 ? ' style="display:none"' : '' ) . ' href="' . esc_url(wp_get_attachment_url($attachment_id)) . '" data-fancybox="epc" rel="nofollow">' . esc_html( ( count($epc_attachment_ids) > 1 ? __( 'EPCs', 'propertyhive' ) : __( 'EPC', 'propertyhive' ) ) ) . '</a>'; |
| 98 |
++$i; |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
echo '</div>'; |
| 104 |
} |
| 105 |
} |