|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Fields' ) ) { |
|
4
|
|
|
|
|
5
|
|
|
class FooGallery_Admin_Gallery_MetaBox_Fields { |
|
6
|
|
|
|
|
7
|
|
|
function __construct() { |
|
8
|
|
|
//handle some default field types that all templates can reuse |
|
9
|
|
|
add_filter( 'foogallery_alter_gallery_template_field', array( $this, 'alter_gallery_template_field' ), 10, 2 ); |
|
10
|
|
|
|
|
11
|
|
|
//render the different types of fields for our gallery settings |
|
12
|
|
|
add_action( 'foogallery_render_gallery_template_field', array( $this, 'render_gallery_template_field' ), 10, 3 ); |
|
13
|
|
|
|
|
14
|
|
|
//allow changing of field values |
|
15
|
|
|
add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'check_lightbox_value' ), 10, 4 ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Renders a gallery template field into the gallery settings metabox for a FooGallery |
|
20
|
|
|
* |
|
21
|
|
|
* @param array $field |
|
22
|
|
|
* @param $gallery FooGallery |
|
23
|
|
|
* @param $template |
|
24
|
|
|
*/ |
|
25
|
|
|
function render_gallery_template_field( $field = array(), $gallery, $template ) { |
|
26
|
|
|
$template_slug = $template['slug']; |
|
27
|
|
|
|
|
28
|
|
|
//only declare up front so no debug warnings are shown |
|
29
|
|
|
$type = $id = $desc = $default = $placeholder = $choices = $class = $spacer = $opactiy = null; |
|
30
|
|
|
|
|
31
|
|
|
extract( $field ); |
|
32
|
|
|
|
|
33
|
|
|
$id = $template_slug . '_' . $id; |
|
34
|
|
|
|
|
35
|
|
|
$field['value'] = apply_filters( 'foogallery_render_gallery_template_field_value', $gallery->get_meta( $id, $default ), $field, $gallery, $template ); |
|
36
|
|
|
|
|
37
|
|
|
$field_class = empty($class) ? '' : ' class="' . $class . '"'; |
|
38
|
|
|
|
|
39
|
|
|
$field['choices'] = apply_filters( 'foogallery_render_gallery_template_field_choices', $choices, $field, $gallery ); |
|
40
|
|
|
|
|
41
|
|
|
//allow for UI customization |
|
42
|
|
|
do_action( 'foogallery_render_gallery_template_field_before', $field, $gallery ); |
|
43
|
|
|
|
|
44
|
|
|
echo '<div class="foogallery_metabox_field-' . $type . '">'; |
|
45
|
|
|
|
|
46
|
|
|
switch ( $type ) { |
|
47
|
|
|
|
|
48
|
|
|
case 'html': |
|
49
|
|
|
echo $desc; |
|
50
|
|
|
$desc = ''; |
|
|
|
|
|
|
51
|
|
|
break; |
|
52
|
|
|
|
|
53
|
|
|
case 'checkbox': |
|
54
|
|
|
if ( isset($gallery->settings[$id]) && $gallery->settings[$id] == 'on' ) { |
|
55
|
|
|
$field['value'] = 'on'; |
|
56
|
|
|
} else if ( ! isset($gallery->settings) && $default == 'on' ) { |
|
57
|
|
|
$field['value'] = 'on'; |
|
58
|
|
|
} else { |
|
59
|
|
|
$field['value'] = ''; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$checked = 'on' === $field['value'] ? ' checked="checked"' : ''; |
|
63
|
|
|
echo '<input' . $field_class . ' type="checkbox" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" value="on"' . $checked . ' />'; |
|
64
|
|
|
break; |
|
65
|
|
|
|
|
66
|
|
|
case 'select': |
|
67
|
|
|
echo '<select' . $field_class . ' id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']">'; |
|
68
|
|
|
foreach ( $choices as $value => $label ) { |
|
|
|
|
|
|
69
|
|
|
$selected = ''; |
|
70
|
|
|
if ( $field['value'] == $value ) { |
|
71
|
|
|
$selected = ' selected="selected"'; |
|
72
|
|
|
} |
|
73
|
|
|
echo '<option ' . $selected . ' value="' . $value . '">' . $label . '</option>'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
echo '</select>'; |
|
77
|
|
|
break; |
|
78
|
|
|
|
|
79
|
|
|
case 'radio': |
|
80
|
|
|
$i = 0; |
|
81
|
|
|
$spacer = isset($spacer) ? $spacer : '<br />'; |
|
82
|
|
|
foreach ( $choices as $value => $label ) { |
|
|
|
|
|
|
83
|
|
|
$selected = ''; |
|
84
|
|
|
if ( $field['value'] == $value ) { |
|
85
|
|
|
$selected = ' checked="checked"'; |
|
86
|
|
|
} |
|
87
|
|
|
echo '<input' . $field_class . $selected . ' type="radio" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" id="FooGallerySettings_' . $id . $i . '" value="' . $value . '"> <label for="FooGallerySettings_' . $id . $i . '">' . $label . '</label>'; |
|
88
|
|
|
if ( $i < count( $choices ) - 1 ) { |
|
89
|
|
|
echo $spacer; |
|
90
|
|
|
} |
|
91
|
|
|
$i++; |
|
92
|
|
|
} |
|
93
|
|
|
break; |
|
94
|
|
|
|
|
95
|
|
|
case 'textarea': |
|
96
|
|
|
echo '<textarea' . $field_class . ' id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" placeholder="' . $placeholder . '">' . esc_attr( $field['value'] ) . '</textarea>'; |
|
97
|
|
|
|
|
98
|
|
|
break; |
|
99
|
|
|
|
|
100
|
|
|
case 'text': |
|
101
|
|
|
echo '<input' . $field_class . ' type="text" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" value="' . esc_attr( $field['value'] ) . '" />'; |
|
102
|
|
|
|
|
103
|
|
|
break; |
|
104
|
|
|
|
|
105
|
|
|
case 'colorpicker': |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
$opacity_attribute = empty($opacity) ? '' : ' data-show-alpha="true"'; |
|
108
|
|
|
|
|
109
|
|
|
echo '<input ' . $opacity_attribute . ' class="colorpicker" type="text" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" value="' . esc_attr( $field['value'] ) . '" />'; |
|
110
|
|
|
|
|
111
|
|
|
break; |
|
112
|
|
|
|
|
113
|
|
|
case 'number': |
|
114
|
|
|
$min = isset($min) ? $min : 0; |
|
115
|
|
|
$step = isset($step) ? $step : 1; |
|
116
|
|
|
echo '<input class="regular-text ' . $class . '" type="number" step="' . $step . '" min="' . $min .'" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" placeholder="' . $placeholder . '" value="' . esc_attr( $field['value'] ) . '" />'; |
|
117
|
|
|
|
|
118
|
|
|
break; |
|
119
|
|
|
|
|
120
|
|
|
case 'checkboxlist': |
|
121
|
|
|
$i = 0; |
|
122
|
|
|
foreach ( $choices as $value => $label ) { |
|
123
|
|
|
|
|
124
|
|
|
$checked = ''; |
|
125
|
|
|
if ( isset($field['value'][$value]) && $field['value'][$value] == 'true' ) { |
|
126
|
|
|
$checked = 'checked="checked"'; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
echo '<input' . $field_class . ' ' . $checked . ' type="checkbox" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '|' . $value . ']" id="FooGallerySettings_' . $id . $i . '" value="on"> <label for="FooGallerySettings_' . $id . $i . '">' . $label . '</label>'; |
|
130
|
|
|
if ( $i < count( $choices ) - 1 ) { |
|
131
|
|
|
echo '<br />'; |
|
132
|
|
|
} |
|
133
|
|
|
$i++; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
break; |
|
137
|
|
|
case 'icon': |
|
138
|
|
|
$i = 0; |
|
139
|
|
|
$input_name = FOOGALLERY_META_SETTINGS . '[' . $id . ']'; |
|
140
|
|
|
$icon_html = ''; |
|
141
|
|
|
foreach ( $choices as $value => $icon ) { |
|
142
|
|
|
$selected = ( $field['value'] == $value ) ? ' checked="checked"' : ''; |
|
143
|
|
|
$icon_html .= '<input style="display:none" name="' . $input_name. '" id="FooGallerySettings_' . $id . $i . '" ' . $selected . ' type="radio" value="' . $value . '" tabindex="' . $i . '"/>'; |
|
144
|
|
|
$title = $icon['label']; |
|
145
|
|
|
$img = $icon['img']; |
|
146
|
|
|
$icon_html .= '<label for="FooGallerySettings_' . $id . $i . '" data-balloon-length="small" data-balloon-pos="down" data-balloon="' . $title . '"><img src="' . $img . '" /></label>'; |
|
147
|
|
|
$i++; |
|
148
|
|
|
} |
|
149
|
|
|
echo $icon_html; |
|
150
|
|
|
break; |
|
151
|
|
|
|
|
152
|
|
|
case 'thumb_size': |
|
153
|
|
|
$width = is_array( $field['value'] ) ? $field['value']['width'] : 150; |
|
154
|
|
|
$height = is_array( $field['value'] ) ? $field['value']['height'] : 150; |
|
155
|
|
|
$crop = is_array( $field['value'] ) && array_key_exists( 'crop', $field['value'] ) ? $field['value']['crop'] : 0; |
|
156
|
|
|
$crop_checked = ( $crop == 1 ) ? ' checked="checked"' : ''; |
|
157
|
|
|
echo '<label for="FooGallerySettings_' . $id . '_width">' . __( 'Width', 'foogallery' ) . '</label>'; |
|
158
|
|
|
echo '<input class="small-text" type="number" step="1" min="0" id="FooGallerySettings_' . $id . '_width" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][width]" value="' . esc_attr( $width ) . '" />'; |
|
159
|
|
|
echo '<label for="FooGallerySettings_' . $id . '_width">' . __( 'Height', 'foogallery' ) . '</label>'; |
|
160
|
|
|
echo '<input class="small-text" type="number" step="1" min="0" id="FooGallerySettings_' . $id . '_height" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][height]" value="' . esc_attr( $height ) . '" />'; |
|
161
|
|
|
echo '<div class="foogallery-thumbsize-crop"><input name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][crop]" type="hidden" id="FooGallerySettings_' . $id . '_nocrop" value="0" />'; |
|
162
|
|
|
echo '<input name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][crop]" type="checkbox" id="FooGallerySettings_' . $id . '_crop" value="1"' . $crop_checked . '>'; |
|
163
|
|
|
echo '<label for="FooGallerySettings_' . $id . '_crop">' . __( 'Crop thumbnail to exact dimensions', 'foogallery' ) . '</label></div>'; |
|
164
|
|
|
break; |
|
165
|
|
|
|
|
166
|
|
|
default: |
|
167
|
|
|
do_action( 'foogallery_render_gallery_template_field_custom', $field, $gallery, $template ); |
|
168
|
|
|
break; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
if (!empty($suffix)) { |
|
172
|
|
|
echo $suffix; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
echo '</div>'; |
|
176
|
|
|
|
|
177
|
|
|
//allow for more customization |
|
178
|
|
|
do_action( 'foogallery_render_gallery_template_field_after', $field, $gallery ); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
function alter_gallery_template_field( $field, $gallery ) { |
|
182
|
|
|
if ( $field ) { |
|
183
|
|
|
switch ( $field['type'] ) { |
|
184
|
|
|
case 'thumb_link': |
|
185
|
|
|
$field['type'] = 'radio'; |
|
186
|
|
|
$field['choices'] = $this->get_thumb_link_field_choices(); |
|
187
|
|
|
break; |
|
188
|
|
|
case 'lightbox': |
|
189
|
|
|
$field['lightbox'] = true; |
|
190
|
|
|
$lightboxes = $this->get_lightbox_field_choices(); |
|
191
|
|
|
if ( 1 === count( $lightboxes ) && array_key_exists( 'none', $lightboxes ) ) { |
|
192
|
|
|
$field['type'] = 'html'; |
|
193
|
|
|
$field['desc'] = '<strong>' . __( 'You have no lightbox extensions activated!', 'foogallery' ) . '</strong><br />'; |
|
194
|
|
|
$api = new FooGallery_Extensions_API(); |
|
195
|
|
|
if ( $api->is_downloaded( false, FOOGALLERY_FOOBOX_PRO_EXTENSION_SLUG ) ) { |
|
|
|
|
|
|
196
|
|
|
//just need to activate it |
|
197
|
|
|
$foobox_install_link = foogallery_build_admin_menu_url( array( |
|
198
|
|
|
'page' => 'foogallery-extensions', |
|
199
|
|
|
'extension' => FOOGALLERY_FOOBOX_PRO_EXTENSION_SLUG, |
|
200
|
|
|
'action' => 'activate', |
|
201
|
|
|
)); |
|
202
|
|
|
$field['desc'] .= '<a target="_blank" href="' . esc_url( $foobox_install_link ). '">' . __( 'Activate FooBox right now!', 'foogallery' ) . '</a>'; |
|
203
|
|
|
} else if ( $api->is_downloaded( false, FOOGALLERY_FOOBOX_FREE_EXTENSION_SLUG ) ) { |
|
|
|
|
|
|
204
|
|
|
//just need to activate it |
|
205
|
|
|
$foobox_install_link = foogallery_build_admin_menu_url( array( |
|
206
|
|
|
'page' => 'foogallery-extensions', |
|
207
|
|
|
'extension' => FOOGALLERY_FOOBOX_FREE_EXTENSION_SLUG, |
|
208
|
|
|
'action' => 'activate', |
|
209
|
|
|
)); |
|
210
|
|
|
$field['desc'] .= '<a target="_blank" href="' . esc_url( $foobox_install_link ). '">' . __( 'Activate FooBox FREE right now!', 'foogallery' ) . '</a>'; |
|
211
|
|
|
} else { |
|
212
|
|
|
//we need to download it |
|
213
|
|
|
$foobox_install_link = foogallery_build_admin_menu_url( array( |
|
214
|
|
|
'page' => 'foogallery-extensions', |
|
215
|
|
|
'extension' => FOOGALLERY_FOOBOX_FREE_EXTENSION_SLUG, |
|
216
|
|
|
'action' => 'download', |
|
217
|
|
|
)); |
|
218
|
|
|
$foobox_install_html = '<a target="_blank" href="' . esc_url( $foobox_install_link ) . '">' . __( 'Download and activate FooBox FREE', 'foogallery' ) . '</a>'; |
|
219
|
|
|
$field['desc'] .= sprintf( __( '%s which works flawlessly with %s.', 'foogallery' ), $foobox_install_html, foogallery_plugin_name() ); |
|
220
|
|
|
} |
|
221
|
|
|
} else { |
|
222
|
|
|
$field['type'] = 'select'; |
|
223
|
|
|
$field['choices'] = $lightboxes; |
|
224
|
|
|
} |
|
225
|
|
|
break; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
if ( isset($field['help']) && $field['help'] ) { |
|
229
|
|
|
$field['type'] = 'help'; |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
return $field; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
function get_thumb_size_choices() { |
|
236
|
|
|
global $_wp_additional_image_sizes; |
|
237
|
|
|
$sizes = array(); |
|
238
|
|
|
foreach( get_intermediate_image_sizes() as $s ){ |
|
239
|
|
|
$sizes[ $s ] = array( 0, 0 ); |
|
240
|
|
|
if ( in_array( $s, array( 'thumbnail', 'medium', 'large', ) ) ){ |
|
241
|
|
|
$sizes[ $s ] = $s . ' (' . get_option( $s . '_size_w' ) . 'x' . get_option( $s . '_size_h' ) . ')'; |
|
242
|
|
|
} else { |
|
243
|
|
|
if ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[ $s ] ) ) |
|
244
|
|
|
$sizes[ $s ] = $s . ' (' . $_wp_additional_image_sizes[ $s ]['width'] . 'x' . $_wp_additional_image_sizes[ $s ]['height'] . ')'; |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
return $sizes; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
function get_thumb_link_field_choices() { |
|
251
|
|
|
return apply_filters( 'foogallery_gallery_template_field_thumb_links', array( |
|
252
|
|
|
'image' => __( 'Full Size Image', 'foogallery' ), |
|
253
|
|
|
'page' => __( 'Image Attachment Page', 'foogallery' ), |
|
254
|
|
|
'custom' => __( 'Custom URL', 'foogallery' ), |
|
255
|
|
|
'none' => __( 'Not linked', 'foogallery' ), |
|
256
|
|
|
) ); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
function get_lightbox_field_choices() { |
|
260
|
|
|
$lightboxes = apply_filters( 'foogallery_gallery_template_field_lightboxes', array() ); |
|
261
|
|
|
$lightboxes['none'] = __( 'None', 'foogallery' ); |
|
262
|
|
|
return $lightboxes; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/*** |
|
266
|
|
|
* Check if we have a lightbox value from FooBox free and change it if foobox free is no longer active |
|
267
|
|
|
* @param $value |
|
268
|
|
|
* @param $field |
|
269
|
|
|
* @param $gallery |
|
270
|
|
|
* @param $template |
|
271
|
|
|
* |
|
272
|
|
|
* @return string |
|
273
|
|
|
*/ |
|
274
|
|
|
function check_lightbox_value($value, $field, $gallery, $template) { |
|
275
|
|
|
|
|
276
|
|
|
if ( isset( $field['lightbox'] ) ) { |
|
277
|
|
|
if ( 'foobox-free' === $value ) { |
|
278
|
|
|
if ( !class_exists( 'Foobox_Free' ) ) { |
|
279
|
|
|
return 'foobox'; |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
return $value; |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.