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