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 / bricks-builder-widgets / property-image.php

property-image.php in Property Hive 2.3.1, at includes/bricks-builder-widgets/property-image.php

161 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bricks Builder Property Image Widget.
4 *
5 * @since 1.0.0
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
10 class Bricks_Builder_Property_Image_Widget extends \Bricks\Element {
11
12 // Element properties
13 public $category = 'propertyhive';
14 public $name = 'bricks-builder-property-image';
15 public $icon = 'fas fa-image';
16
17 public function get_label()
18 {
19 return esc_html__( 'Image', '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['image_number'] = [ // Unique control identifier (lowercase, no spaces)
33 'tab' => 'content', // Control tab: content/style
34 //'group' => 'form', // Show under control group
35 'label' => esc_html__( 'Image #', 'propertyhive' ), // Control label
36 'type' => 'text', // Control type
37 'default' => 1
38 ];
39
40 $this->controls['image_size'] = [
41 'tab' => 'content',
42 //'group' => 'settings',
43 'label' => esc_html__( 'Type', 'propertyhive' ),
44 'type' => 'select',
45 'options' => [
46 'thumbnail' => __( 'Thumbnail', 'propertyhive' ),
47 'medium' => __( 'Medium', 'propertyhive' ),
48 'large' => __( 'Large', 'propertyhive' ),
49 'full' => __( 'Full', 'propertyhive' ),
50 ],
51 //'inline' => true,
52 //'clearable' => false,
53 //'pasteStyles' => false,
54 'default' => 'large',
55 ];
56
57 $this->controls['output_ratio'] = [
58 'tab' => 'content',
59 //'group' => 'settings',
60 'label' => esc_html__( 'Image Ratio', 'propertyhive' ),
61 'type' => 'select',
62 'options' => [
63 '' => __( 'Uploaded Ratio', 'propertyhive' ),
64 '3:2' => __( '3:2', 'propertyhive' ),
65 '4:3' => __( '4:3', 'propertyhive' ),
66 '16:9' => __( '16:9', 'propertyhive' ),
67 '1:1' => __( 'Square', 'propertyhive' ),
68 ],
69 //'inline' => true,
70 //'clearable' => false,
71 //'pasteStyles' => false,
72 'default' => 'large',
73 ];
74
75 do_action( 'propertyhive_bricks_builder_widget_property_image_controls', $this );
76 }
77
78 public function render()
79 {
80 global $property;
81
82 if ( !isset($property->id) )
83 {
84 return;
85 }
86
87 $root_classes[] = $this->name;
88
89 $settings = $this->settings;
90
91 // Add 'class' attribute to element root tag
92 $this->set_attribute( '_root', 'class', $root_classes );
93
94 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Bricks serializes registered attributes through its documented render_attributes() API.
95 echo "<div {$this->render_attributes( '_root' )}>";
96
97 $image_number = 1;
98 if ( isset($settings['image_number']) && $settings['image_number'] != '' && is_numeric($settings['image_number']) )
99 {
100 $image_number = (int)$settings['image_number'];
101 }
102
103 $output_ratio = isset($settings['output_ratio']) ? $settings['output_ratio'] : '';
104
105 if ( $output_ratio != '' )
106 {
107 // output div with image as background
108 $url = '';
109 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
110 {
111 $photos = $property->_photo_urls;
112 if ( isset($photos[$image_number-1]) )
113 {
114 $url = $photos[$image_number-1]['url'];
115 }
116 }
117 else
118 {
119 $gallery_attachment_ids = $property->get_gallery_attachment_ids();
120
121 if ( isset($gallery_attachment_ids[$image_number-1]) )
122 {
123 $url = wp_get_attachment_image_src( $gallery_attachment_ids[$image_number-1], $settings['image_size'] );
124 $url = $url[0];
125 }
126 }
127
128 // convert ratio to percentage
129 $numbers = explode(':', $output_ratio);
130 $percent = ( ( (int)$numbers[1] / (int)$numbers[0] ) * 100 ) . '%';
131
132 echo '<div style="background:url(' . esc_url($url) . ') no-repeat center center; background-size:cover; padding-bottom:' . esc_attr($percent) . '">';
133 }
134 else
135 {
136 // output <img>
137 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
138 {
139 $photos = $property->_photo_urls;
140 if ( isset($photos[$image_number-1]) )
141 {
142 echo '<img src="' . esc_url($photos[$image_number-1]['url']) . '" alt="">';
143 }
144 }
145 else
146 {
147 $gallery_attachment_ids = $property->get_gallery_attachment_ids();
148
149 if ( isset($gallery_attachment_ids[$image_number-1]) )
150 {
151 echo wp_get_attachment_image( $gallery_attachment_ids[$image_number-1], $settings['image_size'] );
152 }
153 }
154 }
155
156 do_action( 'propertyhive_bricks_builder_widget_property_image_render_after', $settings, $property );
157
158 echo '</div>';
159 }
160 }
161