PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 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 2 months ago class-autoptimize-compatibility.php 2 months ago class-elasticpress-compatibility.php 2 months ago class-elementor-compatibility.php 2 months ago class-foobox-compatibility.php 2 months ago class-foogallery-compatibility.php 2 months ago class-foovideo-compatibility.php 2 months ago class-jetpack-compatibility.php 2 months ago class-polylang-compatibility.php 2 months ago class-responsive-lightbox-dfactory-compatibility.php 2 months ago class-wpoptimize-compatibility.php 2 months ago class-wprocket-compatibility.php 2 months ago view-foovideo-offer.php 2 months ago
class-foobox-compatibility.php
375 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 'subsection' => array( 'lightbox-general' => __( 'General', 'foogallery' ) ),
188 'type' => 'radio',
189 'default' => '',
190 'class' => 'foogallery-radios-stacked',
191 'choices' => array(
192 '' => __('Smart (try to show both caption titles and descriptions if available)', 'foogallery' ),
193 'same' => __( 'Same As Thumbnail', 'foogallery' ),
194 'override' => __( 'Override', 'foogallery' ),
195 ),
196 'row_data'=> array(
197 'data-foogallery-hidden' => true,
198 'data-foogallery-show-when-field' => 'lightbox',
199 'data-foogallery-show-when-field-value' => 'foobox',
200 'data-foogallery-change-selector' => 'input:radio',
201 'data-foogallery-value-selector' => 'input:checked',
202 )
203 );
204
205 $new_fields[] = array(
206 'id' => 'foobox_caption_override_title',
207 'title' => __( 'Override Caption Title', 'foogallery' ),
208 'desc' => __( 'You can override the caption title to be different from the thumbnail caption title.', 'foogallery' ),
209 'section' => __( 'Lightbox', 'foogallery' ),
210 'subsection' => array( 'lightbox-general' => __( 'General', 'foogallery' ) ),
211 'type' => 'radio',
212 'default' => '',
213 'class' => 'foogallery-radios-stacked',
214 'choices' => array(
215 '' => __( 'Same As Thumbnail', 'foogallery' ),
216 'title' => __( 'Attachment Title', 'foogallery' ),
217 'caption' => __( 'Attachment Caption', 'foogallery' ),
218 'alt' => __( 'Attachment Alt', 'foogallery' ),
219 'desc' => __( 'Attachment Description', 'foogallery' ),
220 'none' => __( 'None', 'foogallery' ),
221 ),
222 'row_data'=> array(
223 'data-foogallery-hidden' => true,
224 'data-foogallery-show-when-field' => 'foobox_caption_source',
225 'data-foogallery-show-when-field-operator' => '===',
226 'data-foogallery-show-when-field-value' => 'override',
227 'data-foogallery-change-selector' => 'input:radio',
228 'data-foogallery-value-selector' => 'input:checked',
229 )
230 );
231
232 $new_fields[] = array(
233 'id' => 'foobox_caption_override_desc',
234 'title' => __( 'Override Caption Desc.', 'foogallery' ),
235 'desc' => __( 'You can override the caption description to be different from the thumbnail caption description.', 'foogallery' ),
236 'section' => __( 'Lightbox', 'foogallery' ),
237 'subsection' => array( 'lightbox-general' => __( 'General', 'foogallery' ) ),
238 'type' => 'radio',
239 'default' => '',
240 'class' => 'foogallery-radios-stacked',
241 'choices' => array(
242 '' => __( 'Same As Thumbnail', 'foogallery' ),
243 'title' => __( 'Attachment Title', 'foogallery' ),
244 'caption' => __( 'Attachment Caption', 'foogallery' ),
245 'alt' => __( 'Attachment Alt', 'foogallery' ),
246 'desc' => __( 'Attachment Description', 'foogallery' ),
247 'none' => __( 'None', 'foogallery' ),
248 ),
249 'row_data'=> array(
250 'data-foogallery-hidden' => true,
251 'data-foogallery-show-when-field' => 'foobox_caption_source',
252 'data-foogallery-show-when-field-operator' => '===',
253 'data-foogallery-show-when-field-value' => 'override',
254 'data-foogallery-change-selector' => 'input:radio',
255 'data-foogallery-value-selector' => 'input:checked',
256 )
257 );
258
259 //find the index of the first Hover Effect field
260 $index = foogallery_admin_fields_find_index_of_section( $fields, __( 'Hover Effects', 'foogallery' ) );
261
262 array_splice( $fields, $index, 0, $new_fields );
263 }
264
265 return $fields;
266 }
267
268 /***
269 * Check if we have a lightbox value from FooBox free and change it if foobox free is no longer active
270 * @param $value
271 * @param $field
272 * @param $gallery
273 * @param $template
274 *
275 * @return string
276 */
277 function check_lightbox_value($value, $field, $gallery, $template) {
278
279 if ( isset( $field['lightbox'] ) ) {
280 if ( 'foobox-free' === $value ) {
281 if ( !class_exists( 'Foobox_Free' ) ) {
282 return 'foobox';
283 }
284 }
285 }
286
287 return $value;
288 }
289
290 /**
291 * Change the default for lightbox if foobox is activated
292 *
293 * @param $field
294 * @param $gallery_template
295 * @return mixed
296 */
297 function make_foobox_default_lightbox( $field, $gallery_template ) {
298 if ( $this->is_foobox_installed() ) {
299 if (isset($field['lightbox']) && true === $field['lightbox']) {
300 $field['default'] = 'foobox';
301 }
302 }
303
304 return $field;
305 }
306
307 function is_foobox_installed() {
308 return $this->is_foobox_free_installed() || $this->is_foobox_pro_installed();
309 }
310
311 function is_foobox_free_installed() {
312 return class_exists( 'FooBox' );
313 }
314
315 function is_foobox_pro_installed() {
316 return class_exists( 'fooboxV2' );
317 }
318
319 function ensure_outdated_foobox_extensions_never_run() {
320 global $foogallery_extensions;
321
322 //backwards compatibility for older versions of the FooBox Free extension class
323 if ( class_exists( 'FooGallery_FooBox_Free_Extension' ) ) {
324 $foogallery_extensions['foobox-image-lightbox'] = $this;
325 }
326
327 //backwards compatibility for older versions of the FooBox PRO extension class
328 if ( class_exists( 'FooGallery_FooBox_Extension' ) ) {
329 $foogallery_extensions['foobox'] = $this;
330 }
331 }
332
333 function add_lightbox($lightboxes) {
334 $option_text = __( 'FooBox', 'foogallery' );
335 if ( !$this->is_foobox_installed() ) {
336 $option_text .= __( ' (Not installed!)', 'foogallery' );
337 }
338
339 $lightboxes['foobox'] = $option_text;
340 return $lightboxes;
341 }
342
343 function album_stack_link_class_name( $class_name ) {
344 return str_replace( 'foobox-free', 'foobox', $class_name );
345 }
346
347 function add_panning_fields( $fields ) {
348 $fields['foobox_panning'] = array(
349 'label' => __( 'Panning', 'foogallery' ),
350 'input' => 'radio',
351 'helps' => __( 'Enable mouse panning for this image in the lightbox.', 'foogallery' ),
352 'exclusions' => array( 'audio', 'video' ),
353 'options' => array(
354 '' => __( 'Disabled', 'foogallery' ),
355 'enabled' => __( 'Enabled', 'foogallery' )
356 )
357 );
358
359 return $fields;
360 }
361
362 function add_panning_attributes( $attr, $args, $foogallery_attachment ) {
363
364 $foobox_panning = get_post_meta( $foogallery_attachment->ID, '_foobox_panning', true );
365
366 if ( !empty( $foobox_panning ) ) {
367 //add data-overflow="true" + data-proportion="false" attributes to the anchor link
368 $attr['data-overflow'] = 'true';
369 $attr['data-proportion'] = 'false';
370 }
371
372 return $attr;
373 }
374 }
375 }