PluginProbe
Property Hive / 2.2.3
Property Hive v2.2.3
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 / salient-widgets / property-image-html.php

property-image-html.php in Property Hive 2.2.3, at includes/salient-widgets/property-image-html.php

74 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 extract(shortcode_atts(array(
6 "image_number" => "",
7 "image_size" => "",
8 "output_ratio" => "",
9 ), $atts));
10
11 global $property;
12
13 if ( !isset($property->id) ) {
14 return;
15 }
16
17 $image_number = 1;
18 if ( isset($atts['image_number']) && $atts['image_number'] != '' && is_numeric($atts['image_number']) )
19 {
20 $image_number = (int)$atts['image_number'];
21 }
22
23 if ( $output_ratio != '' )
24 {
25 // output div with image as background
26 $url = '';
27 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
28 {
29 $photos = $property->_photo_urls;
30 if ( isset($photos[$image_number-1]) )
31 {
32 $url = $photos[$image_number-1]['url'];
33 }
34 }
35 else
36 {
37 $gallery_attachment_ids = $property->get_gallery_attachment_ids();
38
39 if ( isset($gallery_attachment_ids[$image_number-1]) )
40 {
41 $url = wp_get_attachment_image_src( $gallery_attachment_ids[$image_number-1], $atts['image_size'] );
42 $url = $url[0];
43 }
44 }
45
46 // convert ratio to percentage
47 $numbers = explode(':', $output_ratio);
48 $percent = ( ( (int)$numbers[1] / (int)$numbers[0] ) * 100 ) . '%';
49
50 echo '<div style="background:url(' . esc_url($url) . ') no-repeat center center; background-size:cover; padding-bottom:' . esc_attr($percent) . '">';
51 }
52 else
53 {
54 // output <img>
55 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
56 {
57 $photos = $property->_photo_urls;
58 if ( isset($photos[$image_number-1]) )
59 {
60 echo '<img src="' . esc_url($photos[$image_number-1]['url']) . '" alt="">';
61 }
62 }
63 else
64 {
65 $gallery_attachment_ids = $property->get_gallery_attachment_ids();
66
67 if ( isset($gallery_attachment_ids[$image_number-1]) )
68 {
69 echo wp_get_attachment_image( $gallery_attachment_ids[$image_number-1], $atts['image_size'] );
70 }
71 }
72 }
73
74 do_action( 'propertyhive_salient_widget_property_image_render_after', $atts, $property );