|
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
|
|
|
add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_foobox_help_field' ), 99, 2 ); |
|
24
|
|
|
|
|
25
|
|
|
if ( class_exists( 'fooboxV2' ) ) { |
|
26
|
|
|
//FooBox PRO specific functionality |
|
27
|
|
|
|
|
28
|
|
|
//only add FooBox PRO functionality after FooBox version 1.2.29 |
|
29
|
|
|
if ( defined( 'FOOBOX_BASE_VERSION' ) && version_compare( FOOBOX_BASE_VERSION, '1.2.29', '>' ) ) { |
|
30
|
|
|
add_filter( 'foogallery_attachment_custom_fields', array($this, 'add_panning_fields' ) ); |
|
31
|
|
|
add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'add_panning_attributes' ), 10, 3 ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
} else { |
|
35
|
|
|
//FooBox Free specific functionality |
|
36
|
|
|
add_filter( 'foogallery_album_stack_link_class_name', array($this, 'album_stack_link_class_name')); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function add_foobox_help_field( $fields, $template ) { |
|
|
|
|
|
|
41
|
|
|
//see if the template has a lightbox field |
|
42
|
|
|
$found_lightbox = false; |
|
43
|
|
|
$position = 0; |
|
44
|
|
|
foreach ($fields as $key => &$field) { |
|
45
|
|
|
if ( 'lightbox' === $field['id'] ) { |
|
46
|
|
|
$found_lightbox = true; |
|
47
|
|
|
break; |
|
48
|
|
|
} |
|
49
|
|
|
$position++; |
|
50
|
|
|
} |
|
51
|
|
|
if ( $found_lightbox && !$this->is_foobox_installed() ) { |
|
52
|
|
|
$action = 'install-plugin'; |
|
53
|
|
|
$slug = 'foobox-image-lightbox'; |
|
54
|
|
|
$install_url = wp_nonce_url( |
|
55
|
|
|
add_query_arg( |
|
56
|
|
|
array( |
|
57
|
|
|
'action' => $action, |
|
58
|
|
|
'plugin' => $slug |
|
59
|
|
|
), |
|
60
|
|
|
admin_url( 'update.php' ) |
|
61
|
|
|
), |
|
62
|
|
|
$action.'_'.$slug |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$foobox_help_field = array( |
|
66
|
|
|
array( |
|
67
|
|
|
'id' => 'lightbox_foobox_help', |
|
68
|
|
|
'title' => __( 'FooBox Help', 'foogallery' ), |
|
69
|
|
|
'desc' => sprintf( __( 'Install our separate FooBox Lightbox plugin so that your gallery images will open in a beautiful responsive lightbox. %s', 'foogallery' ), '<a href="' . $install_url . '" target="_blank">' . __('Install it now!', 'foogallery'). '</a>' ) , |
|
70
|
|
|
'section' => __( 'General', 'foogallery' ), |
|
71
|
|
|
'type' => 'help' |
|
72
|
|
|
) |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
array_splice( $fields, $position, 0, $foobox_help_field ); |
|
76
|
|
|
} |
|
77
|
|
|
return $fields; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/*** |
|
81
|
|
|
* Check if we have a lightbox value from FooBox free and change it if foobox free is no longer active |
|
82
|
|
|
* @param $value |
|
83
|
|
|
* @param $field |
|
84
|
|
|
* @param $gallery |
|
85
|
|
|
* @param $template |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
function check_lightbox_value($value, $field, $gallery, $template) { |
|
90
|
|
|
|
|
91
|
|
|
if ( isset( $field['lightbox'] ) ) { |
|
92
|
|
|
if ( 'foobox-free' === $value ) { |
|
93
|
|
|
if ( !class_exists( 'Foobox_Free' ) ) { |
|
94
|
|
|
return 'foobox'; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return $value; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Change the default for lightbox if foobox is activated |
|
104
|
|
|
* |
|
105
|
|
|
* @param $field |
|
106
|
|
|
* @param $gallery_template |
|
107
|
|
|
* @return mixed |
|
108
|
|
|
*/ |
|
109
|
|
|
function make_foobox_default_lightbox( $field, $gallery_template ) { |
|
|
|
|
|
|
110
|
|
|
if ( $this->is_foobox_installed() ) { |
|
111
|
|
|
if (isset($field['lightbox']) && true === $field['lightbox']) { |
|
112
|
|
|
$field['default'] = 'foobox'; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $field; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
function is_foobox_installed() { |
|
|
|
|
|
|
120
|
|
|
return class_exists( 'FooBox' ) || class_exists( 'fooboxV2' ); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
function ensure_outdated_foobox_extensions_never_run() { |
|
|
|
|
|
|
124
|
|
|
global $foogallery_extensions; |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
//backwards compatibility for older versions of the FooBox Free extension class |
|
127
|
|
|
if ( class_exists( 'FooGallery_FooBox_Free_Extension' ) ) { |
|
128
|
|
|
$foogallery_extensions['foobox-image-lightbox'] = $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
//backwards compatibility for older versions of the FooBox PRO extension class |
|
132
|
|
|
if ( class_exists( 'FooGallery_FooBox_Extension' ) ) { |
|
133
|
|
|
$foogallery_extensions['foobox'] = $this; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
function add_lightbox($lightboxes) { |
|
|
|
|
|
|
138
|
|
|
$option_text = __( 'FooBox', 'foogallery' ); |
|
139
|
|
|
if ( !$this->is_foobox_installed() ) { |
|
140
|
|
|
$option_text .= __( ' (Not installed!)', 'foogallery' ); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$lightboxes['foobox'] = $option_text; |
|
144
|
|
|
return $lightboxes; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
function album_stack_link_class_name( $class_name ) { |
|
|
|
|
|
|
148
|
|
|
return str_replace( 'foobox-free', 'foobox', $class_name ); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
function add_panning_fields( $fields ) { |
|
|
|
|
|
|
152
|
|
|
$fields['foobox_panning'] = array( |
|
153
|
|
|
'label' => __( 'Panning', 'foogallery' ), |
|
154
|
|
|
'input' => 'radio', |
|
155
|
|
|
'helps' => __( 'Enable mouse panning for this image in the lightbox.', 'foogallery' ), |
|
156
|
|
|
'exclusions' => array( 'audio', 'video' ), |
|
157
|
|
|
'options' => array( |
|
158
|
|
|
'' => __( 'Disabled', 'foogallery' ), |
|
159
|
|
|
'enabled' => __( 'Enabled', 'foogallery' ) |
|
160
|
|
|
) |
|
161
|
|
|
); |
|
162
|
|
|
|
|
163
|
|
|
return $fields; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
function add_panning_attributes( $attr, $args, $foogallery_attachment ) { |
|
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
$foobox_panning = get_post_meta( $foogallery_attachment->ID, '_foobox_panning', true ); |
|
169
|
|
|
|
|
170
|
|
|
if ( !empty( $foobox_panning ) ) { |
|
171
|
|
|
//add data-overflow="true" + data-proportion="false" attributes to the anchor link |
|
172
|
|
|
$attr['data-overflow'] = 'true'; |
|
173
|
|
|
$attr['data-proportion'] = 'false'; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return $attr; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
} |
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.