PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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 1.4.62 All 260 releases
propertyhive / includes / avada-widgets / property-image-shortcode.php

property-image-shortcode.php in Property Hive 2.2.4, at includes/avada-widgets/property-image-shortcode.php

120 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_shortcode( 'avada_property_image', function( $atts ) {
4 $atts = shortcode_atts( array(
5 'image_number' => '',
6 'image_size' => '',
7 'output_ratio' => '',
8 ), $atts );
9
10 if ( get_post_type( get_the_ID() ) != 'property' )
11 {
12 return '';
13 }
14
15 fusion_element_rendering_elements( true );
16
17 global $property;
18
19 if ( empty($property) )
20 {
21 $property = new PH_Property(get_the_ID());
22 }
23
24 ob_start();
25
26 $image_number = 1;
27 if ( isset($atts['image_number']) && $atts['image_number'] != '' && is_numeric($atts['image_number']) )
28 {
29 $image_number = (int)$atts['image_number'];
30 }
31
32 $output_ratio = isset($atts['output_ratio']) ? $atts['output_ratio'] : '';
33
34 if ( $output_ratio != '' )
35 {
36 // output div with image as background
37 $url = '';
38 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
39 {
40 $photos = $property->_photo_urls;
41 if ( isset($photos[$image_number-1]) )
42 {
43 $url = $photos[$image_number-1]['url'];
44 }
45 }
46 else
47 {
48 $gallery_attachment_ids = $property->get_gallery_attachment_ids();
49
50 if ( isset($gallery_attachment_ids[$image_number-1]) )
51 {
52 $url = wp_get_attachment_image_src( $gallery_attachment_ids[$image_number-1], $atts['image_size'] );
53 $url = $url[0];
54 }
55 }
56
57 // convert ratio to percentage
58 $numbers = explode(':', $output_ratio);
59 $percent = ( ( (int)$numbers[1] / (int)$numbers[0] ) * 100 ) . '%';
60
61
62 if ( ! empty( $atts['image_link']['url'] ) )
63 {
64 echo '<div style="background:url(' . esc_url($url) . ') no-repeat center center; background-size:cover;">';
65 $this->add_link_attributes( 'image_link', $atts['image_link'] );
66 ?><a <?php $this->print_render_attribute_string( 'image_link' ); ?> style="display:block; <?php echo 'padding-bottom:' . esc_attr($percent); ?>"><?php
67 echo '</a>';
68 echo '</div>';
69 }
70 else
71 {
72 echo '<div style="background:url(' . esc_url($url) . ') no-repeat center center; background-size:cover; padding-bottom:' . esc_attr($percent) . '"></div>';
73 }
74 }
75 else
76 {
77 // output <img>
78 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
79 {
80 $photos = $property->_photo_urls;
81 if ( isset($photos[$image_number-1]) )
82 {
83 if ( ! empty( $atts['image_link']['url'] ) )
84 {
85 $this->add_link_attributes( 'image_link', $atts['image_link'] );
86 ?><a <?php $this->print_render_attribute_string( 'image_link' ); ?>><?php
87 }
88 echo '<img src="' . esc_url($photos[$image_number-1]['url']) . '" alt="">';
89 if ( ! empty( $atts['image_link']['url'] ) ) {
90 echo '</a>';
91 }
92 }
93 }
94 else
95 {
96 $gallery_attachment_ids = $property->get_gallery_attachment_ids();
97
98 if ( isset($gallery_attachment_ids[$image_number-1]) )
99 {
100 if ( ! empty( $atts['image_link']['url'] ) )
101 {
102 $this->add_link_attributes( 'image_link', $atts['image_link'] );
103 ?><a <?php $this->print_render_attribute_string( 'image_link' ); ?>><?php
104 }
105 echo wp_get_attachment_image( $gallery_attachment_ids[$image_number-1], $atts['image_size'] );
106 if ( ! empty( $atts['image_link']['url'] ) ) {
107 echo '</a>';
108 }
109 }
110 }
111 }
112
113 do_action( 'propertyhive_avada_widget_property_image_render_after', $atts, $property );
114
115 $html = ob_get_clean();
116
117 fusion_element_rendering_elements( false );
118
119 return $html;
120 });