PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
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 1.4.62 All 260 releases
propertyhive / includes / bricks-builder-widgets / property-gallery.php

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

332 lines 11.8 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 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Bricks serializes registered attributes through its documented render_attributes() API.
72 echo "<div {$this->render_attributes( '_root' )}>";
73
74 $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;
75
76 $images = array();
77 $images_hidden = array();
78 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
79 {
80 $photo_urls = $property->_photo_urls;
81 if ( !is_array($photo_urls) ) { $photo_urls = array(); }
82
83 if ( $start_at_image > 0 )
84 {
85 $photo_urls_hidden = array_slice($photo_urls, 0, $start_at_image);
86
87 foreach ( $photo_urls_hidden as $photo )
88 {
89 $images_hidden[] = array(
90 'title' => isset($photo['title']) ? $photo['title'] : '',
91 'url' => isset($photo['url']) ? $photo['url'] : '',
92 'image' => '<img src="' . ( isset($photo['url']) ? esc_url($photo['url']) : '' ) . '" alt="' . ( isset($photo['title']) ? esc_attr($photo['title']) : '' ) . '">',
93 );
94 }
95 }
96 $photo_urls = array_slice($photo_urls, $start_at_image);
97
98 foreach ( $photo_urls as $photo )
99 {
100 $images[] = array(
101 'title' => isset($photo['title']) ? $photo['title'] : '',
102 'url' => isset($photo['url']) ? $photo['url'] : '',
103 'image' => '<img src="' . ( isset($photo['url']) ? esc_url($photo['url']) : '' ) . '" alt="' . ( isset($photo['title']) ? esc_attr($photo['title']) : '' ) . '">',
104 );
105 }
106 }
107 else
108 {
109 $gallery_attachments = $property->get_gallery_attachment_ids();
110
111 if ( !empty($gallery_attachments) )
112 {
113 if ( $start_at_image > 0 )
114 {
115 $gallery_attachments_hidden = array_slice($gallery_attachments, 0, $start_at_image);
116
117 foreach ($gallery_attachments_hidden as $gallery_attachment)
118 {
119 $images_hidden[] = array(
120 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
121 'url' => wp_get_attachment_url( $gallery_attachment ),
122 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ),
123 'attachment_id' => $gallery_attachment,
124 );
125 }
126 }
127
128 $gallery_attachments = array_slice($gallery_attachments, $start_at_image);
129
130 foreach ($gallery_attachments as $gallery_attachment)
131 {
132 $images[] = array(
133 'title' => esc_attr( get_the_title( $gallery_attachment ) ),
134 'url' => wp_get_attachment_url( $gallery_attachment ),
135 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ),
136 'attachment_id' => $gallery_attachment,
137 );
138 }
139 }
140 }
141
142 if ( isset($images) && is_array($images) && !empty($images) )
143 {
144 $settings['padding'] = 0; // hardcode to 0 for now. Make an option going forward.
145 ?>
146 <style type="text/css">
147
148 /* Clear floats after image containers */
149 .ph-elementor-gallery::after {
150 content: "";
151 clear: both;
152 display: table;
153 }
154
155 <?php $max_images = 6; if ( $settings['gallery_layout'] == 'grid' ) { ?>
156 .gallery-column {
157 position: relative;
158 float: left;
159 width: 33.33%;
160 box-sizing: border-box;
161 padding: <?php echo (int)$settings['padding']; ?>px;
162 }
163 @media (max-width: 1023px) {
164 .gallery-column {
165 width: 50%;
166 }
167 }
168 <?php }elseif ( $settings['gallery_layout'] == 'one_large_four_small' ) { $max_images = 5; ?>
169 .gallery-column {
170 position: relative;
171 float: left;
172 width: 25%;
173 box-sizing: border-box;
174 padding: <?php echo (int)$settings['padding']; ?>px;
175 }
176 .gallery-column:nth-child(1) {
177 width: 50%;
178 }
179 @media (max-width: 1023px) {
180 .gallery-column {
181 width: 50%;
182 }
183 .gallery-column:nth-child(1) {
184 width: 100%;
185 }
186 }
187 <?php } ?>
188
189 .gallery-column > a { display:block; height:100%; padding-top:75%; background:center center no-repeat; background-size:cover; }
190
191 .more-images-container {
192 position: absolute;
193 top:<?php echo (int)$settings['padding']; ?>px;;
194 left:<?php echo (int)$settings['padding']; ?>px;
195 right:<?php echo (int)$settings['padding']; ?>px;
196 bottom:<?php echo (int)$settings['padding']; ?>px;
197 }
198 .more-images-container.mobile {
199 display:none;
200 }
201 .more-images {
202 display: table;
203 background: rgba(0, 0, 0, 0.5); /* Black see-through */
204 height: 100%;
205 width: 100%;
206 opacity:1;
207 font-size: 18px;
208 text-align: center;
209 }
210
211 .more-images a {
212 color: #f1f1f1;
213 display: table-cell;
214 vertical-align: middle;
215 text-align:center;
216 height: 100%;
217 }
218
219 @media (max-width: 767px) {
220 .gallery-column {
221 width: 100%;
222 }
223 .gallery-column:nth-child(3),
224 .gallery-column:nth-child(4),
225 .gallery-column:nth-child(5),
226 .gallery-column:nth-child(6) { display:none }
227
228 .more-images-container.desktop {
229 display:none;
230 }
231 .more-images-container.mobile {
232 display:block;
233 }
234 }
235
236 </style>
237
238 <script>
239 function openGallery()
240 {
241 if ( jQuery(window).width() <= 767 )
242 {
243 jQuery('a#more-images-link-mobile').trigger('click');
244 }
245 else
246 {
247 jQuery('a#more-images-link').trigger('click');
248 }
249 return false;
250 }
251 </script>
252
253 <?php
254
255 foreach ( $images_hidden as $image_hidden )
256 {
257 echo '<a href="' . esc_url($image_hidden['url']) . '" data-fancybox="bricks-gallery"></a>';
258 ++$image_number;
259 }
260 ?>
261
262 <div class="ph-elementor-gallery">
263 <?php
264
265 $image_number = 0;
266
267 for ( $j = 0; $j < $max_images; $j++ )
268 {
269 echo '<div class="gallery-column">';
270
271 if ( isset($images[$image_number]) )
272 {
273 $id_text = $image_number == ( $max_images - 1 ) ? 'more-images-link' : '';
274 $id_text_mobile = $image_number == 1 ? 'more-images-link-mobile' : '';
275
276 echo '<a';
277
278 if ( $id_text )
279 {
280 echo ' id="' . esc_attr( $id_text ) . '"';
281 }
282
283 if ( $id_text_mobile )
284 {
285 echo ' id="' . esc_attr( $id_text_mobile ) . '"';
286 }
287
288 echo ' href="' . esc_url( $images[$image_number]['url'] ) . '" data-fancybox="bricks-gallery" style="background-image:url(' . esc_url( $images[$image_number]['url'] ) . ')"></a>';
289
290 if ( $image_number == 1 )
291 {
292 echo '<div class="more-images-container mobile"><div class="more-images"><a href="javascript:;" onclick="openGallery();">';
293 printf(
294 /* translators: %d: number of images (1, 2, 3 etc) */
295 esc_html__( 'See all %d images', 'propertyhive' ),
296 count($images) + count($images_hidden)
297 );
298 echo '</a></div></div>';
299 }
300 if ( $image_number == ($max_images - 1) )
301 {
302 echo '<div class="more-images-container desktop"><div class="more-images"><a href="javascript:;" onclick="openGallery();">';
303 printf(
304 /* translators: %d: number of images (1, 2, 3 etc) */
305 esc_html__( 'See all %d images', 'propertyhive' ),
306 count($images) + count($images_hidden)
307 );
308 echo '</a></div></div>';
309 }
310 }
311
312 echo '</div>';
313
314 ++$image_number;
315 }
316
317 while ( count($images) > ($image_number) )
318 {
319 echo '<a href="' . esc_url($images[$image_number]['url']) . '" data-fancybox="bricks-gallery"></a>';
320 ++$image_number;
321 }
322
323 // Code second layout, for one main photo
324 }
325 ?>
326 </div>
327 <?php
328
329 echo '</div>';
330 }
331 }
332