PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / trunk
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel vtrunk
trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / compatibility / class-foobox-compatibility.php
foogallery / includes / compatibility Last commit date
elementor 7 months ago class-autoptimize-compatibility.php 7 months ago class-elasticpress-compatibility.php 7 months ago class-elementor-compatibility.php 7 months ago class-foobox-compatibility.php 7 months ago class-foogallery-compatibility.php 7 months ago class-foovideo-compatibility.php 7 months ago class-jetpack-compatibility.php 7 months ago class-polylang-compatibility.php 7 months ago class-responsive-lightbox-dfactory-compatibility.php 7 months ago class-wpoptimize-compatibility.php 7 months ago class-wprocket-compatibility.php 7 months ago view-foovideo-offer.php 7 months ago
class-foobox-compatibility.php
369 lines
1 <?php
2 /**
3 * Adds in better support for FooBox Free and PRO
4 */
5
6 if ( !class_exists( 'FooGallery_FooBox_Compatibility' ) ) {
7
8 class FooGallery_FooBox_Compatibility {
9
10 function __construct() {
11 //we need to make sure outdated versions of FooBox never run in the future
12 $this->ensure_outdated_foobox_extensions_never_run();
13
14 //add the FooBox lightbox option no matter if using Free or Pro
15 add_filter( 'foogallery_gallery_template_field_lightboxes', array($this, 'add_lightbox'), 11, 2 );
16
17 //alter the default lightbox to be foobox
18 add_filter( 'foogallery_alter_gallery_template_field', array( $this, 'make_foobox_default_lightbox' ), 10, 2 );
19
20 //allow changing of field values
21 add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'check_lightbox_value' ), 10, 4 );
22
23 if ( class_exists( 'fooboxV2' ) ) {
24 //FooBox PRO specific functionality
25
26 //only add FooBox PRO functionality after FooBox version 1.2.29
27 if ( defined( 'FOOBOX_BASE_VERSION' ) && version_compare( FOOBOX_BASE_VERSION, '1.2.29', '>' ) ) {
28 add_filter( 'foogallery_attachment_custom_fields', array($this, 'add_panning_fields' ) );
29 add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'add_panning_attributes' ), 10, 3 );
30 }
31
32 } else {
33 //FooBox Free specific functionality
34 add_filter( 'foogallery_album_stack_link_class_name', array($this, 'album_stack_link_class_name'));
35 }
36
37 //cater for different captions sources
38 add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'add_caption_attributes' ), 20, 3 );
39
40 //add custom captions
41 add_filter( 'foogallery_build_attachment_html_caption_custom', array( &$this, 'customize_captions' ), 90, 3 );
42
43 //add fields for FooBox free captions
44 add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_caption_fields' ), 20, 2 );
45 }
46
47 /**
48 * Customize the captions if needed
49 *
50 * @param $captions
51 * @param $foogallery_attachment FooGalleryAttachment
52 * @param $args array
53 *
54 * @return array
55 */
56 function customize_captions( $captions, $foogallery_attachment, $args) {
57
58 if ( isset( $foogallery_attachment->custom_captions ) && $foogallery_attachment->custom_captions ) {
59 //specifically for foobox, make sure the custom captions are set
60 $foogallery_attachment->caption_title = ' ';
61 $foogallery_attachment->caption_desc = $captions['desc'];
62 }
63
64 return $captions;
65 }
66
67 /**
68 * Handle custom captions for the lightbox
69 * @param $attr
70 * @param $args
71 * @param $foogallery_attachment
72 *
73 * @return mixed
74 */
75 function add_caption_attributes( $attr, $args, $foogallery_attachment ) {
76 global $current_foogallery;
77
78 $force_same = false;
79
80 //check if lightbox set to foobox
81 //Note that the $current_foogallery->lightbox property is only set if FooGallery PRO is running
82 if ( isset( $current_foogallery->lightbox ) && 'foobox' === $current_foogallery->lightbox ) {
83
84 //check lightbox caption source field that is added in FooGallery PRO
85 $lightbox_caption_source = foogallery_gallery_template_setting( 'lightbox_caption_override', false );
86
87 if ( 'override' === $lightbox_caption_source ) {
88 $caption_title_source = foogallery_gallery_template_setting( 'lightbox_caption_override_title', '' );
89 if ( 'none' === $caption_title_source ) {
90 $attr['data-caption-title'] = ' ';
91 } else if ( '' !== $caption_title_source ) {
92 $attr['data-caption-title'] = foogallery_sanitize_full( foogallery_get_caption_by_source( $foogallery_attachment, $caption_title_source, 'title' ) );
93 }
94
95 $caption_desc_source = foogallery_gallery_template_setting( 'lightbox_caption_override_desc', '' );
96 if ( 'none' === $caption_desc_source ) {
97 $attr['data-caption-desc'] = ' ';
98 } else if ( '' !== $caption_desc_source ) {
99 $attr['data-caption-desc'] = foogallery_sanitize_full( foogallery_get_caption_by_source( $foogallery_attachment, $caption_desc_source, 'description' ) );
100 }
101 } else if ( 'custom' === $lightbox_caption_source ) {
102
103 $template = foogallery_gallery_template_setting( 'lightbox_caption_custom_template', '' );
104 if ( ! empty( $template ) ) {
105 $attr['data-caption-title'] = ' ';
106 $attr['data-caption-desc'] = foogallery_sanitize_full( FooGallery_Pro_Advanced_Captions::build_custom_caption( $template, $foogallery_attachment ) );
107 }
108 } else if ( '' === $lightbox_caption_source ) {
109 //same as thumbnail
110 //either way, we need to force the lightbox captions to match the thumb captions
111 $force_same = true;
112 }
113
114 } else {
115 //we will get here if FooGallery FREE is running
116 $lightbox = foogallery_gallery_template_setting_lightbox();
117
118 //we only want to make changes if the lightbox is set to foobox
119 if ( 'foobox' === $lightbox ) {
120 //check foobox caption source field that is only added if FooBox free is installed
121 $foobox_caption_source = foogallery_gallery_template_setting( 'foobox_caption_source', false );
122
123 if ( 'override' === $foobox_caption_source ) {
124 $caption_title_source = foogallery_gallery_template_setting( 'foobox_caption_override_title', '' );
125 if ( 'none' === $caption_title_source ) {
126 $attr['data-caption-title'] = ' ';
127 } else if ( '' !== $caption_title_source ) {
128 $attr['data-caption-title'] = foogallery_sanitize_full( foogallery_get_caption_by_source( $foogallery_attachment, $caption_title_source, 'title' ) );
129 }
130
131 $caption_desc_source = foogallery_gallery_template_setting( 'foobox_caption_override_desc', '' );
132 if ( 'none' === $caption_desc_source ) {
133 $attr['data-caption-desc'] = ' ';
134 } else if ( '' !== $caption_desc_source ) {
135 $attr['data-caption-desc'] = foogallery_sanitize_full( foogallery_get_caption_by_source( $foogallery_attachment, $caption_desc_source, 'description' ) );
136 }
137 } else if ( 'same' === $foobox_caption_source ) {
138 //same as thumbnail, or FooGallery FREE
139 $force_same = true;
140 }
141 }
142 }
143
144 //force the same captions as the thumbnail
145 if ( $force_same ) {
146 if ( isset( $foogallery_attachment->caption_title ) ) {
147 $attr['data-caption-title'] = foogallery_sanitize_full( $foogallery_attachment->caption_title );
148 } else {
149 $attr['data-caption-title'] = ' ';
150 }
151
152 if ( isset( $foogallery_attachment->caption_desc ) ) {
153 $attr['data-caption-desc'] = foogallery_sanitize_full( $foogallery_attachment->caption_desc );
154 } else {
155 $attr['data-caption-desc'] = ' ';
156 }
157 }
158
159 return $attr;
160 }
161
162 /**
163 * Add caption fields for FooBox FREE
164 *
165 * @param $fields
166 * @param $template
167 *
168 * @return mixed
169 */
170 function add_caption_fields( $fields, $template ) {
171 //see if the template has a lightbox field
172 $found_lightbox = false;
173 foreach ( $fields as $key => &$field ) {
174 if ( 'lightbox' === $field['id'] ) {
175 $found_lightbox = true;
176 break;
177 }
178 }
179
180 if ( $found_lightbox && $this->is_foobox_installed() && !foogallery_is_pro() ) {
181
182 $new_fields[] = array(
183 'id' => 'foobox_caption_source',
184 'title' => __( 'Lightbox Caption Source', 'foogallery' ),
185 'desc' => __( 'The lightbox captions can be different to the thumbnail captions.', 'foogallery' ),
186 'section' => __( 'Lightbox', 'foogallery' ),
187 'type' => 'radio',
188 'default' => '',
189 'choices' => array(
190 '' => __('Smart (try to show both caption titles and descriptions if available)', 'foogallery' ),
191 'same' => __( 'Same As Thumbnail', 'foogallery' ),
192 'override' => __( 'Override', 'foogallery' ),
193 ),
194 'row_data'=> array(
195 'data-foogallery-hidden' => true,
196 'data-foogallery-show-when-field' => 'lightbox',
197 'data-foogallery-show-when-field-value' => 'foobox',
198 'data-foogallery-change-selector' => 'input:radio',
199 'data-foogallery-value-selector' => 'input:checked',
200 )
201 );
202
203 $new_fields[] = array(
204 'id' => 'foobox_caption_override_title',
205 'title' => __( 'Override Caption Title', 'foogallery' ),
206 'desc' => __( 'You can override the caption title to be different from the thumbnail caption title.', 'foogallery' ),
207 'section' => __( 'Lightbox', 'foogallery' ),
208 'type' => 'radio',
209 'default' => '',
210 'choices' => array(
211 '' => __( 'Same As Thumbnail', 'foogallery' ),
212 'title' => __( 'Attachment Title', 'foogallery' ),
213 'caption' => __( 'Attachment Caption', 'foogallery' ),
214 'alt' => __( 'Attachment Alt', 'foogallery' ),
215 'desc' => __( 'Attachment Description', 'foogallery' ),
216 'none' => __( 'None', 'foogallery' ),
217 ),
218 'row_data'=> array(
219 'data-foogallery-hidden' => true,
220 'data-foogallery-show-when-field' => 'foobox_caption_source',
221 'data-foogallery-show-when-field-operator' => '===',
222 'data-foogallery-show-when-field-value' => 'override',
223 'data-foogallery-change-selector' => 'input:radio',
224 'data-foogallery-value-selector' => 'input:checked',
225 )
226 );
227
228 $new_fields[] = array(
229 'id' => 'foobox_caption_override_desc',
230 'title' => __( 'Override Caption Desc.', 'foogallery' ),
231 'desc' => __( 'You can override the caption description to be different from the thumbnail caption description.', 'foogallery' ),
232 'section' => __( 'Lightbox', 'foogallery' ),
233 'type' => 'radio',
234 'default' => '',
235 'choices' => array(
236 '' => __( 'Same As Thumbnail', 'foogallery' ),
237 'title' => __( 'Attachment Title', 'foogallery' ),
238 'caption' => __( 'Attachment Caption', 'foogallery' ),
239 'alt' => __( 'Attachment Alt', 'foogallery' ),
240 'desc' => __( 'Attachment Description', 'foogallery' ),
241 'none' => __( 'None', 'foogallery' ),
242 ),
243 'row_data'=> array(
244 'data-foogallery-hidden' => true,
245 'data-foogallery-show-when-field' => 'foobox_caption_source',
246 'data-foogallery-show-when-field-operator' => '===',
247 'data-foogallery-show-when-field-value' => 'override',
248 'data-foogallery-change-selector' => 'input:radio',
249 'data-foogallery-value-selector' => 'input:checked',
250 )
251 );
252
253 //find the index of the first Hover Effect field
254 $index = foogallery_admin_fields_find_index_of_section( $fields, __( 'Hover Effects', 'foogallery' ) );
255
256 array_splice( $fields, $index, 0, $new_fields );
257 }
258
259 return $fields;
260 }
261
262 /***
263 * Check if we have a lightbox value from FooBox free and change it if foobox free is no longer active
264 * @param $value
265 * @param $field
266 * @param $gallery
267 * @param $template
268 *
269 * @return string
270 */
271 function check_lightbox_value($value, $field, $gallery, $template) {
272
273 if ( isset( $field['lightbox'] ) ) {
274 if ( 'foobox-free' === $value ) {
275 if ( !class_exists( 'Foobox_Free' ) ) {
276 return 'foobox';
277 }
278 }
279 }
280
281 return $value;
282 }
283
284 /**
285 * Change the default for lightbox if foobox is activated
286 *
287 * @param $field
288 * @param $gallery_template
289 * @return mixed
290 */
291 function make_foobox_default_lightbox( $field, $gallery_template ) {
292 if ( $this->is_foobox_installed() ) {
293 if (isset($field['lightbox']) && true === $field['lightbox']) {
294 $field['default'] = 'foobox';
295 }
296 }
297
298 return $field;
299 }
300
301 function is_foobox_installed() {
302 return $this->is_foobox_free_installed() || $this->is_foobox_pro_installed();
303 }
304
305 function is_foobox_free_installed() {
306 return class_exists( 'FooBox' );
307 }
308
309 function is_foobox_pro_installed() {
310 return class_exists( 'fooboxV2' );
311 }
312
313 function ensure_outdated_foobox_extensions_never_run() {
314 global $foogallery_extensions;
315
316 //backwards compatibility for older versions of the FooBox Free extension class
317 if ( class_exists( 'FooGallery_FooBox_Free_Extension' ) ) {
318 $foogallery_extensions['foobox-image-lightbox'] = $this;
319 }
320
321 //backwards compatibility for older versions of the FooBox PRO extension class
322 if ( class_exists( 'FooGallery_FooBox_Extension' ) ) {
323 $foogallery_extensions['foobox'] = $this;
324 }
325 }
326
327 function add_lightbox($lightboxes) {
328 $option_text = __( 'FooBox', 'foogallery' );
329 if ( !$this->is_foobox_installed() ) {
330 $option_text .= __( ' (Not installed!)', 'foogallery' );
331 }
332
333 $lightboxes['foobox'] = $option_text;
334 return $lightboxes;
335 }
336
337 function album_stack_link_class_name( $class_name ) {
338 return str_replace( 'foobox-free', 'foobox', $class_name );
339 }
340
341 function add_panning_fields( $fields ) {
342 $fields['foobox_panning'] = array(
343 'label' => __( 'Panning', 'foogallery' ),
344 'input' => 'radio',
345 'helps' => __( 'Enable mouse panning for this image in the lightbox.', 'foogallery' ),
346 'exclusions' => array( 'audio', 'video' ),
347 'options' => array(
348 '' => __( 'Disabled', 'foogallery' ),
349 'enabled' => __( 'Enabled', 'foogallery' )
350 )
351 );
352
353 return $fields;
354 }
355
356 function add_panning_attributes( $attr, $args, $foogallery_attachment ) {
357
358 $foobox_panning = get_post_meta( $foogallery_attachment->ID, '_foobox_panning', true );
359
360 if ( !empty( $foobox_panning ) ) {
361 //add data-overflow="true" + data-proportion="false" attributes to the anchor link
362 $attr['data-overflow'] = 'true';
363 $attr['data-proportion'] = 'false';
364 }
365
366 return $attr;
367 }
368 }
369 }