PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / divi-widgets / property-epcs-link.php

property-epcs-link.php in Property Hive 2.3.1, at includes/divi-widgets/property-epcs-link.php

84 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5
6 class Divi_Property_Epcs_Link_Widget extends ET_Builder_Module
7 {
8 public $slug = 'et_pb_property_epcs_link_widget';
9 public $vb_support = 'partial';
10 public $icon = '';
11
12 public function init() {
13 $this->name = esc_html__( 'Property EPCs Link', '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) ) { $epc_urls = array(); }
40
41 if ( !empty($epc_urls) )
42 {
43 $i = 0;
44 foreach ( $epc_urls as $epc )
45 {
46 $image_extensions = array( 'jpg', 'jpeg', 'png', 'gif', 'bmp' );
47 $image = false;
48 foreach ( $image_extensions as $image_extension )
49 {
50 if ( strpos(strtolower($epc['url']), '.' . $image_extension) )
51 {
52 $image = true;
53 }
54 }
55 if ( $image )
56 {
57 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>';
58 ++$i;
59 }
60 else
61 {
62 echo '<a href="' . esc_url($epc['url']) . '" rel="nofollow" target="_blank">' . esc_html(( count($epc_urls) > 1 ? __( 'EPCs', 'propertyhive' ) : __( 'EPC', 'propertyhive' ) )) . '</a>';
63 }
64 }
65 }
66 }
67 else
68 {
69 $epc_attachment_ids = $property->get_epc_attachment_ids();
70
71 if ( !empty($epc_attachment_ids) )
72 {
73 $i = 0;
74 foreach ( $epc_attachment_ids as $attachment_id )
75 {
76 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>';
77 ++$i;
78 }
79 }
80 }
81
82 return $this->_render_module_wrapper( ob_get_clean(), $render_slug );
83 }
84 }