| 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 ); |