PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
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 / divi-widgets / property-gallery.php

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

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