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

property-gallery.php in Property Hive 2.2.3, at includes/bricks-builder-widgets/property-gallery.php

318 lines 11.4 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 Gallery Widget.
4 *
5 * @since 1.0.0
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
10 class Bricks_Builder_Property_Gallery_Widget extends \Bricks\Element {
11
12 // Element properties
13 public $category = 'propertyhive'; // Use predefined element category 'general'
14 public $name = 'bricks-builder-property-gallery'; // Make sure to prefix your elements
15 public $icon = 'fas fa-images'; // icon font class
16
17 public function get_label()
18 {
19 return esc_html__( 'Gallery', '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['gallery_layout'] = [
33 'tab' => 'content',
34 //'group' => 'settings',
35 'label' => esc_html__( 'Layout', 'propertyhive' ),
36 'type' => 'select',
37 'options' => [
38 'grid' => __( 'Six Images', 'propertyhive' ),
39 'one_large_four_small' => __( 'One Large Image, Four Small', 'propertyhive' ),
40 ],
41 //'inline' => true,
42 //'clearable' => false,
43 //'pasteStyles' => false,
44 'default' => 'grid',
45 ];
46
47 $this->controls['start_at_image'] = [ // Unique control identifier (lowercase, no spaces)
48 'tab' => 'content', // Control tab: content/style
49 //'group' => 'form', // Show under control group
50 'label' => esc_html__( 'Start at Image #', 'propertyhive' ), // Control label
51 'type' => 'text', // Control type
52 'default' => '1'
53 ];
54 }
55
56 public function render()
57 {
58 global $property;
59
60 $settings = $this->settings;
61
62 if ( !isset($property->id) ) {
63 return;
64 }
65
66 $root_classes[] = $this->name;
67
68 // Add 'class' attribute to element root tag
69 $this->set_attribute( '_root', 'class', $root_classes );
70
71 echo "<div {$this->render_attributes( '_root' )}>";
72
73 $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;
74
75 $images = array();
76 $images_hidden = array();
77 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
78 {
79 $photo_urls = $property->_photo_urls;
80 if ( !is_array($photo_urls) ) { $photo_urls = array(); }
81
82 if ( $start_at_image > 0 )
83 {
84 $photo_urls_hidden = array_slice($photo_urls, 0, $start_at_image);
85
86 foreach ( $photo_urls_hidden as $photo )
87 {
88 $images_hidden[] = array(
89 'title' => isset($photo['title']) ? $photo['title'] : '',
90 'url' => isset($photo['url']) ? $photo['url'] : '',
91 'image' => '<img src="' . ( isset($photo['url']) ? esc_url($photo['url']) : '' ) . '" alt="' . ( isset($photo['title']) ? esc_attr($photo['title']) : '' ) . '">',
92 );
93 }
94 }
95 $photo_urls = array_slice($photo_urls, $start_at_image);
96
97 foreach ( $photo_urls as $photo )
98 {
99 $images[] = array(
100 'title' => isset($photo['title']) ? $photo['title'] : '',
101 'url' => isset($photo['url']) ? $photo['url'] : '',
102 'image' => '<img src="' . ( isset($photo['url']) ? esc_url($photo['url']) : '' ) . '" alt="' . ( isset($photo['title']) ? esc_attr($photo['title']) : '' ) . '">',
103 );
104 }
105 }
106 else
107 {
108 $gallery_attachments = $property->get_gallery_attachment_ids();
109
110 if ( !empty($gallery_attachments) )
111 {
112 if ( $start_at_image > 0 )
113 {
114 $gallery_attachments_hidden = array_slice($gallery_attachments, 0, $start_at_image);
115
116 foreach ($gallery_attachments_hidden as $gallery_attachment)
117 {
118 $images_hidden[] = array(
119 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
120 'url' => wp_get_attachment_url( $gallery_attachment ),
121 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ),
122 'attachment_id' => $gallery_attachment,
123 );
124 }
125 }
126
127 $gallery_attachments = array_slice($gallery_attachments, $start_at_image);
128
129 foreach ($gallery_attachments as $gallery_attachment)
130 {
131 $images[] = array(
132 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
133 'url' => wp_get_attachment_url( $gallery_attachment ),
134 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ),
135 'attachment_id' => $gallery_attachment,
136 );
137 }
138 }
139 }
140
141 if ( isset($images) && is_array($images) && !empty($images) )
142 {
143 $settings['padding'] = 0; // hardcode to 0 for now. Make an option going forward.
144 ?>
145 <style type="text/css">
146
147 /* Clear floats after image containers */
148 .ph-elementor-gallery::after {
149 content: "";
150 clear: both;
151 display: table;
152 }
153
154 <?php $max_images = 6; if ( $settings['gallery_layout'] == 'grid' ) { ?>
155 .gallery-column {
156 position: relative;
157 float: left;
158 width: 33.33%;
159 box-sizing: border-box;
160 padding: <?php echo (int)$settings['padding']; ?>px;
161 }
162 @media (max-width: 1023px) {
163 .gallery-column {
164 width: 50%;
165 }
166 }
167 <?php }elseif ( $settings['gallery_layout'] == 'one_large_four_small' ) { $max_images = 5; ?>
168 .gallery-column {
169 position: relative;
170 float: left;
171 width: 25%;
172 box-sizing: border-box;
173 padding: <?php echo (int)$settings['padding']; ?>px;
174 }
175 .gallery-column:nth-child(1) {
176 width: 50%;
177 }
178 @media (max-width: 1023px) {
179 .gallery-column {
180 width: 50%;
181 }
182 .gallery-column:nth-child(1) {
183 width: 100%;
184 }
185 }
186 <?php } ?>
187
188 .gallery-column > a { display:block; height:100%; padding-top:75%; background:center center no-repeat; background-size:cover; }
189
190 .more-images-container {
191 position: absolute;
192 top:<?php echo (int)$settings['padding']; ?>px;;
193 left:<?php echo (int)$settings['padding']; ?>px;
194 right:<?php echo (int)$settings['padding']; ?>px;
195 bottom:<?php echo (int)$settings['padding']; ?>px;
196 }
197 .more-images-container.mobile {
198 display:none;
199 }
200 .more-images {
201 display: table;
202 background: rgba(0, 0, 0, 0.5); /* Black see-through */
203 height: 100%;
204 width: 100%;
205 opacity:1;
206 font-size: 18px;
207 text-align: center;
208 }
209
210 .more-images a {
211 color: #f1f1f1;
212 display: table-cell;
213 vertical-align: middle;
214 text-align:center;
215 height: 100%;
216 }
217
218 @media (max-width: 767px) {
219 .gallery-column {
220 width: 100%;
221 }
222 .gallery-column:nth-child(3),
223 .gallery-column:nth-child(4),
224 .gallery-column:nth-child(5),
225 .gallery-column:nth-child(6) { display:none }
226
227 .more-images-container.desktop {
228 display:none;
229 }
230 .more-images-container.mobile {
231 display:block;
232 }
233 }
234
235 </style>
236
237 <script>
238 function openGallery()
239 {
240 if ( jQuery(window).width() <= 767 )
241 {
242 jQuery('a#more-images-link-mobile').trigger('click');
243 }
244 else
245 {
246 jQuery('a#more-images-link').trigger('click');
247 }
248 return false;
249 }
250 </script>
251
252 <?php
253
254 foreach ( $images_hidden as $image_hidden )
255 {
256 echo '<a href="' . esc_url($image_hidden['url']) . '" data-fancybox="elementor-gallery"></a>';
257 ++$image_number;
258 }
259 ?>
260
261 <div class="ph-elementor-gallery">
262 <?php
263
264 $image_number = 0;
265
266 for ( $j = 0; $j < $max_images; $j++ )
267 {
268 echo '<div class="gallery-column">';
269
270 if ( isset($images[$image_number]) )
271 {
272 $id_text = $image_number == ($max_images - 1) ? 'id="more-images-link"' : '';
273 $id_text_mobile = $image_number == 1 ? 'id="more-images-link-mobile"' : '';
274
275 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>';
276
277 if ( $image_number == 1 )
278 {
279 echo '<div class="more-images-container mobile"><div class="more-images"><a href="javascript:;" onclick="openGallery();">';
280 printf(
281 /* translators: %d: number of images (1, 2, 3 etc) */
282 __( 'See all %d images', 'propertyhive' ),
283 count($images) + count($images_hidden)
284 );
285 echo '</a></div></div>';
286 }
287 if ( $image_number == ($max_images - 1) )
288 {
289 echo '<div class="more-images-container desktop"><div class="more-images"><a href="javascript:;" onclick="openGallery();">';
290 printf(
291 /* translators: %d: number of images (1, 2, 3 etc) */
292 __( 'See all %d images', 'propertyhive' ),
293 count($images) + count($images_hidden)
294 );
295 echo '</a></div></div>';
296 }
297 }
298
299 echo '</div>';
300
301 ++$image_number;
302 }
303
304 while ( count($images) > ($image_number) )
305 {
306 echo '<a href="' . esc_url($images[$image_number]['url']) . '" data-fancybox="elementor-gallery"></a>';
307 ++$image_number;
308 }
309
310 // Code second layout, for one main photo
311 }
312 ?>
313 </div>
314 <?php
315
316 echo '</div>';
317 }
318 }