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') ); |
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
|
|
|
|
38
|
|
|
/*** |
39
|
|
|
* Check if we have a lightbox value from FooBox free and change it if foobox free is no longer active |
40
|
|
|
* @param $value |
41
|
|
|
* @param $field |
42
|
|
|
* @param $gallery |
43
|
|
|
* @param $template |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
function check_lightbox_value($value, $field, $gallery, $template) { |
48
|
|
|
|
49
|
|
|
if ( isset( $field['lightbox'] ) ) { |
50
|
|
|
if ( 'foobox-free' === $value ) { |
51
|
|
|
if ( !class_exists( 'Foobox_Free' ) ) { |
52
|
|
|
return 'foobox'; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $value; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Change the default for lightbox if foobox is activated |
62
|
|
|
* |
63
|
|
|
* @param $field |
64
|
|
|
* @param $gallery_template |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
function make_foobox_default_lightbox( $field, $gallery_template ) { |
|
|
|
|
68
|
|
|
if ( $this->is_foobox_installed() ) { |
69
|
|
|
if (isset($field['lightbox']) && true === $field['lightbox']) { |
70
|
|
|
$field['default'] = 'foobox'; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $field; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function is_foobox_installed() { |
|
|
|
|
78
|
|
|
return class_exists( 'FooBox' ) || class_exists( 'fooboxV2' ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
function ensure_outdated_foobox_extensions_never_run() { |
|
|
|
|
82
|
|
|
global $foogallery_extensions; |
|
|
|
|
83
|
|
|
|
84
|
|
|
//backwards compatibility for older versions of the FooBox Free extension class |
85
|
|
|
if ( class_exists( 'FooGallery_FooBox_Free_Extension' ) ) { |
86
|
|
|
$foogallery_extensions['foobox-image-lightbox'] = $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
//backwards compatibility for older versions of the FooBox PRO extension class |
90
|
|
|
if ( class_exists( 'FooGallery_FooBox_Extension' ) ) { |
91
|
|
|
$foogallery_extensions['foobox'] = $this; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
function add_lightbox($lightboxes) { |
|
|
|
|
96
|
|
|
$option_text = __( 'FooBox', 'foogallery' ); |
97
|
|
|
if ( !$this->is_foobox_installed() ) { |
98
|
|
|
$option_text .= __( ' (Not installed!)', 'foogallery' ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$lightboxes['foobox'] = $option_text; |
102
|
|
|
return $lightboxes; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
function album_stack_link_class_name( $class_name ) { |
|
|
|
|
106
|
|
|
return str_replace( 'foobox-free', 'foobox', $class_name ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
function add_panning_fields( $fields ) { |
|
|
|
|
110
|
|
|
$fields['foobox_panning'] = array( |
111
|
|
|
'label' => __( 'Panning', 'foogallery' ), |
112
|
|
|
'input' => 'radio', |
113
|
|
|
'helps' => __( 'Enable mouse panning for this image in the lightbox.', 'foogallery' ), |
114
|
|
|
'exclusions' => array( 'audio', 'video' ), |
115
|
|
|
'options' => array( |
116
|
|
|
'' => __( 'Disabled', 'foogallery' ), |
117
|
|
|
'enabled' => __( 'Enabled', 'foogallery' ) |
118
|
|
|
) |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
return $fields; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function add_panning_attributes( $attr, $args, $foogallery_attachment ) { |
|
|
|
|
125
|
|
|
|
126
|
|
|
$foobox_panning = get_post_meta( $foogallery_attachment->ID, '_foobox_panning', true ); |
127
|
|
|
|
128
|
|
|
if ( !empty( $foobox_panning ) ) { |
129
|
|
|
//add data-overflow="true" + data-proportion="false" attributes to the anchor link |
130
|
|
|
$attr['data-overflow'] = 'true'; |
131
|
|
|
$attr['data-proportion'] = 'false'; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $attr; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.