PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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 / elementor-widgets / property-gallery.php

property-gallery.php in Property Hive 2.2.4, at includes/elementor-widgets/property-gallery.php

359 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Property Gallery Widget.
4 *
5 * @since 1.0.0
6 */
7 class Elementor_Property_Gallery_Widget extends \Elementor\Widget_Base {
8
9 public function get_name() {
10 return 'property-gallery';
11 }
12
13 public function get_title() {
14 return __( 'Gallery', 'propertyhive' );
15 }
16
17 public function get_icon() {
18 return 'eicon-gallery-grid';
19 }
20
21 public function get_categories() {
22 return [ 'property-hive' ];
23 }
24
25 public function get_keywords() {
26 return [ 'property hive', 'propertyhive', 'property', 'images', 'photos', 'gallery', 'slideshow' ];
27 }
28
29 protected function register_controls() {
30
31 $this->start_controls_section(
32 'content_section',
33 [
34 'label' => __( 'Gallery', 'propertyhive' ),
35 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
36 ]
37 );
38
39 /*$this->add_control(
40 'padding',
41 [
42 'label' => __( 'Image Padding (px)', 'propertyhive' ),
43 'type' => \Elementor\Controls_Manager::TEXT,
44 'input_type' => 'number',
45 'default' => 0,
46 ]
47 );*/
48
49 $this->add_control(
50 'gallery_layout',
51 [
52 'label' => __( 'Layout', 'propertyhive' ),
53 'type' => \Elementor\Controls_Manager::SELECT,
54 'options' => [
55 'grid' => __( 'Six Images', 'propertyhive' ),
56 'one_large_four_small' => __( 'One Large Image, Four Small', 'propertyhive' ),
57 ],
58 'default' => 'grid',
59 ]
60 );
61
62 $this->add_control(
63 'start_at_image',
64 [
65 'label' => __( 'Start at Image #', 'propertyhive' ),
66 'type' => \Elementor\Controls_Manager::NUMBER,
67 'default' => 1,
68 'min' => 1,
69 ]
70 );
71
72 $this->add_control(
73 'output_ratio',
74 [
75 'label' => __( 'Image Ratio', 'propertyhive' ),
76 'type' => \Elementor\Controls_Manager::SELECT,
77 'options' => [
78 '3:2' => __( '3:2', 'propertyhive' ),
79 '4:3' => __( '4:3', 'propertyhive' ),
80 '16:9' => __( '16:9', 'propertyhive' ),
81 '1:1' => __( 'Square', 'propertyhive' ),
82 ],
83 'default' => '4:3'
84 ]
85 );
86
87 $this->end_controls_section();
88 }
89
90 protected function render() {
91
92 global $property;
93
94 $settings = $this->get_settings_for_display();
95
96 if ( !isset($property->id) ) {
97 return;
98 }
99
100 $start_at_image = ( isset($settings['start_at_image']) && !empty($settings['start_at_image']) && is_numeric($settings['start_at_image']) ) ? ($settings['start_at_image'] - 1) : 0;
101
102 $images = array();
103 $images_hidden = array();
104 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
105 {
106 $photo_urls = $property->_photo_urls;
107 if ( !is_array($photo_urls) ) { $photo_urls = array(); }
108
109 if ( $start_at_image > 0 )
110 {
111 $photo_urls_hidden = array_slice($photo_urls, 0, $start_at_image);
112
113 foreach ( $photo_urls_hidden as $photo )
114 {
115 $images_hidden[] = array(
116 'title' => isset($photo['title']) ? $photo['title'] : '',
117 'url' => isset($photo['url']) ? $photo['url'] : '',
118 'image' => '<img src="' . ( isset($photo['url']) ? $photo['url'] : '' ) . '" alt="' . ( isset($photo['title']) ? $photo['title'] : '' ) . '">',
119 );
120 }
121 }
122 $photo_urls = array_slice($photo_urls, $start_at_image);
123
124 foreach ( $photo_urls as $photo )
125 {
126 $images[] = array(
127 'title' => isset($photo['title']) ? $photo['title'] : '',
128 'url' => isset($photo['url']) ? $photo['url'] : '',
129 'image' => '<img src="' . ( isset($photo['url']) ? $photo['url'] : '' ) . '" alt="' . ( isset($photo['title']) ? $photo['title'] : '' ) . '">',
130 );
131 }
132 }
133 else
134 {
135 $gallery_attachments = $property->get_gallery_attachment_ids();
136
137 if ( !empty($gallery_attachments) )
138 {
139 if ( $start_at_image > 0 )
140 {
141 $gallery_attachments_hidden = array_slice($gallery_attachments, 0, $start_at_image);
142
143 foreach ($gallery_attachments_hidden as $gallery_attachment)
144 {
145 $images_hidden[] = array(
146 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
147 'url' => wp_get_attachment_url( $gallery_attachment ),
148 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ),
149 'attachment_id' => $gallery_attachment,
150 );
151 }
152 }
153
154 $gallery_attachments = array_slice($gallery_attachments, $start_at_image);
155
156 foreach ($gallery_attachments as $gallery_attachment)
157 {
158 $images[] = array(
159 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
160 'url' => wp_get_attachment_url( $gallery_attachment ),
161 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ),
162 'attachment_id' => $gallery_attachment,
163 );
164 }
165 }
166 }
167
168 if ( isset($images) && is_array($images) && !empty($images) )
169 {
170 $settings['padding'] = 0; // hardcode to 0 for now. Make an option going forward.
171 ?>
172 <style type="text/css">
173
174 /* Clear floats after image containers */
175 .ph-elementor-gallery::after {
176 content: "";
177 clear: both;
178 display: table;
179 }
180
181 <?php $max_images = 6; if ( $settings['gallery_layout'] == 'grid' ) { ?>
182 .gallery-column {
183 position: relative;
184 float: left;
185 width: 33.33%;
186 box-sizing: border-box;
187 padding: <?php echo (int)$settings['padding']; ?>px;
188 }
189 @media (max-width: 1023px) {
190 .gallery-column {
191 width: 50%;
192 }
193 }
194 <?php }elseif ( $settings['gallery_layout'] == 'one_large_four_small' ) { $max_images = 5; ?>
195 .gallery-column {
196 position: relative;
197 float: left;
198 width: 25%;
199 box-sizing: border-box;
200 padding: <?php echo (int)$settings['padding']; ?>px;
201 }
202 .gallery-column:nth-child(1) {
203 width: 50%;
204 }
205 @media (max-width: 1023px) {
206 .gallery-column {
207 width: 50%;
208 }
209 .gallery-column:nth-child(1) {
210 width: 100%;
211 }
212 }
213 <?php } ?>
214
215 <?php
216 $output_ratio = ( isset($settings['output_ratio']) && !empty($settings['output_ratio'])) ? $settings['output_ratio'] : '4:3';
217 $padding_top = '75%';
218 switch ($output_ratio)
219 {
220 case "3:2": { $padding_top = '66.67%'; break; }
221 case "16:9": { $padding_top = '56.25%'; break; }
222 case "1:1": { $padding_top = '100%'; break; }
223 }
224 ?>
225 .gallery-column > a {
226 display:block;
227 height:100%;
228 padding-top:<?php echo $padding_top; ?>;
229 background:center center no-repeat;
230 background-size:cover;
231 }
232
233 .more-images-container {
234 position: absolute;
235 top:<?php echo (int)$settings['padding']; ?>px;;
236 left:<?php echo (int)$settings['padding']; ?>px;
237 right:<?php echo (int)$settings['padding']; ?>px;
238 bottom:<?php echo (int)$settings['padding']; ?>px;
239 }
240 .more-images-container.mobile {
241 display:none;
242 }
243 .more-images {
244 display: table;
245 background: rgba(0, 0, 0, 0.5); /* Black see-through */
246 height: 100%;
247 width: 100%;
248 opacity:1;
249 font-size: 18px;
250 text-align: center;
251 }
252
253 .more-images a {
254 color: #f1f1f1;
255 display: table-cell;
256 vertical-align: middle;
257 text-align:center;
258 height: 100%;
259 }
260
261 @media (max-width: 767px) {
262 .gallery-column {
263 width: 100%;
264 }
265 .gallery-column:nth-child(3),
266 .gallery-column:nth-child(4),
267 .gallery-column:nth-child(5),
268 .gallery-column:nth-child(6) { display:none }
269
270 .more-images-container.desktop {
271 display:none;
272 }
273 .more-images-container.mobile {
274 display:block;
275 }
276 }
277
278 </style>
279
280 <script>
281 function openGallery()
282 {
283 if ( jQuery(window).width() <= 767 )
284 {
285 jQuery('a#more-images-link-mobile').trigger('click');
286 }
287 else
288 {
289 jQuery('a#more-images-link').trigger('click');
290 }
291 return false;
292 }
293 </script>
294
295 <?php
296
297 foreach ( $images_hidden as $image_hidden )
298 {
299 echo '<a href="' . esc_url($image_hidden['url']) . '" data-fancybox="elementor-gallery"></a>';
300 ++$image_number;
301 }
302 ?>
303
304 <div class="ph-elementor-gallery">
305 <?php
306
307 $image_number = 0;
308
309 for ( $j = 0; $j < $max_images; $j++ )
310 {
311 echo '<div class="gallery-column">';
312
313 if ( isset($images[$image_number]) )
314 {
315 $id_text = $image_number == ($max_images - 1) ? 'id="more-images-link"' : '';
316 $id_text_mobile = $image_number == 1 ? 'id="more-images-link-mobile"' : '';
317
318 echo '<a ' . $id_text . ' ' . $id_text_mobile . ' href="' . esc_url($images[$image_number]['url']) . '" data-fancybox="elementor-gallery" style="background-image:url(' . esc_url($images[$image_number]['url']) . ')"></a>';
319
320 if ( $image_number == 1 )
321 {
322 echo '<div class="more-images-container mobile"><div class="more-images"><a href="javascript:;" onclick="openGallery();">';
323 printf(
324 /* translators: %d: number of images (1, 2, 3 etc) */
325 __( 'See all %d images', 'propertyhive' ),
326 count($images) + count($images_hidden)
327 );
328 echo '</a></div></div>';
329 }
330 if ( $image_number == ($max_images - 1) )
331 {
332 echo '<div class="more-images-container desktop"><div class="more-images"><a href="javascript:;" onclick="openGallery();">';
333 printf(
334 /* translators: %d: number of images (1, 2, 3 etc) */
335 __( 'See all %d images', 'propertyhive' ),
336 count($images) + count($images_hidden)
337 );
338 echo '</a></div></div>';
339 }
340 }
341
342 echo '</div>';
343
344 ++$image_number;
345 }
346
347 while ( count($images) > ($image_number) )
348 {
349 echo '<a href="' . esc_url($images[$image_number]['url']) . '" data-fancybox="elementor-gallery"></a>';
350 ++$image_number;
351 }
352
353 // Code second layout, for one main photo
354 }
355 ?>
356 </div>
357 <?php
358 }
359 }