|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* FooGallery Admin Album MetaBoxes class |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
if ( ! class_exists( 'FooGallery_Admin_Album_MetaBoxes' ) ) { |
|
8
|
|
|
|
|
9
|
|
|
class FooGallery_Admin_Album_MetaBoxes { |
|
10
|
|
|
|
|
11
|
|
|
private $_album; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct() { |
|
14
|
|
|
//add our foogallery metaboxes |
|
15
|
|
|
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
|
16
|
|
|
|
|
17
|
|
|
//save extra post data for a gallery |
|
18
|
|
|
add_action( 'save_post', array( $this, 'save_album' ) ); |
|
19
|
|
|
|
|
20
|
|
|
//whitelist metaboxes for our album posttype |
|
21
|
|
|
add_filter( 'foogallery-album_metabox_sanity', array( $this, 'whitelist_metaboxes' ) ); |
|
22
|
|
|
|
|
23
|
|
|
//add scripts used by metaboxes |
|
24
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'include_required_scripts' ) ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function whitelist_metaboxes() { |
|
28
|
|
|
return array( |
|
29
|
|
|
FOOGALLERY_CPT_GALLERY => array( |
|
30
|
|
|
'whitelist' => apply_filters( 'foogallery_metabox_sanity_foogallery-album', |
|
31
|
|
|
array( |
|
32
|
|
|
'submitdiv', |
|
33
|
|
|
'slugdiv', |
|
34
|
|
|
'postimagediv', |
|
35
|
|
|
'foogalleryalbum_galleries', |
|
36
|
|
|
'foogalleryalbum_shortcode' |
|
37
|
|
|
) |
|
38
|
|
|
), |
|
39
|
|
|
'contexts' => array( 'normal', 'advanced', 'side', ), |
|
40
|
|
|
'priorities' => array( 'high', 'core', 'default', 'low', ), |
|
41
|
|
|
) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function add_meta_boxes() { |
|
46
|
|
|
add_meta_box( |
|
47
|
|
|
'foogalleryalbum_galleries', |
|
48
|
|
|
__( 'Galleries - drag n drop to reorder!', 'foogallery' ), |
|
49
|
|
|
array( $this, 'render_gallery_metabox' ), |
|
50
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
51
|
|
|
'normal', |
|
52
|
|
|
'high' |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
add_meta_box( |
|
56
|
|
|
'foogalleryalbum_settings', |
|
57
|
|
|
__( 'Settings', 'foogallery' ), |
|
58
|
|
|
array( $this, 'render_settings_metabox' ), |
|
59
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
60
|
|
|
'normal', |
|
61
|
|
|
'high' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
add_meta_box( |
|
65
|
|
|
'foogalleryalbum_customcss', |
|
66
|
|
|
__( 'Custom CSS', 'foogallery' ), |
|
67
|
|
|
array( $this, 'render_customcss_metabox' ), |
|
68
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
69
|
|
|
'normal', |
|
70
|
|
|
'low' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
add_meta_box( |
|
74
|
|
|
'foogalleryalbum_shortcode', |
|
75
|
|
|
__( 'Album Shortcode', 'foogallery' ), |
|
76
|
|
|
array( $this, 'render_shortcode_metabox' ), |
|
77
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
78
|
|
|
'side', |
|
79
|
|
|
'default' |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
add_meta_box( |
|
83
|
|
|
'foogalleryalbum_sorting', |
|
84
|
|
|
__( 'Album Sorting', 'foogallery' ), |
|
85
|
|
|
array( $this, 'render_sorting_metabox' ), |
|
86
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
87
|
|
|
'side', |
|
88
|
|
|
'default' |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function get_album( $post ) { |
|
93
|
|
|
if ( ! isset( $this->_album ) ) { |
|
94
|
|
|
$this->_album = FooGalleryAlbum::get( $post ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $this->_album; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function save_album( $post_id ) { |
|
101
|
|
|
// check autosave |
|
102
|
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
103
|
|
|
return $post_id; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// verify nonce |
|
107
|
|
|
if ( array_key_exists( FOOGALLERY_CPT_ALBUM . '_nonce', $_POST ) && |
|
108
|
|
|
wp_verify_nonce( $_POST[ FOOGALLERY_CPT_ALBUM . '_nonce' ], plugin_basename( FOOGALLERY_FILE ) ) |
|
109
|
|
|
) { |
|
110
|
|
|
//if we get here, we are dealing with the Album custom post type |
|
111
|
|
|
|
|
112
|
|
|
$galleries = apply_filters( 'foogallery_save_album_galleries', explode( ',', $_POST[ FOOGALLERY_ALBUM_META_GALLERIES ] ) ); |
|
113
|
|
|
update_post_meta( $post_id, FOOGALLERY_ALBUM_META_GALLERIES, $galleries ); |
|
114
|
|
|
|
|
115
|
|
|
update_post_meta( $post_id, FOOGALLERY_ALBUM_META_TEMPLATE, $_POST[FOOGALLERY_ALBUM_META_TEMPLATE] ); |
|
116
|
|
|
|
|
117
|
|
|
update_post_meta( $post_id, FOOGALLERY_ALBUM_META_SORT, $_POST[FOOGALLERY_ALBUM_META_SORT] ); |
|
118
|
|
|
|
|
119
|
|
|
$settings = isset($_POST[FOOGALLERY_META_SETTINGS]) ? |
|
120
|
|
|
$_POST[FOOGALLERY_META_SETTINGS] : array(); |
|
121
|
|
|
|
|
122
|
|
|
$settings = apply_filters( 'foogallery_save_album_settings', $settings ); |
|
123
|
|
|
|
|
124
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_SETTINGS, $settings ); |
|
125
|
|
|
|
|
126
|
|
|
$custom_css = isset($_POST[FOOGALLERY_META_CUSTOM_CSS]) ? |
|
127
|
|
|
$_POST[FOOGALLERY_META_CUSTOM_CSS] : ''; |
|
128
|
|
|
|
|
129
|
|
|
if ( empty( $custom_css ) ) { |
|
130
|
|
|
delete_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS ); |
|
131
|
|
|
} else { |
|
132
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS, $custom_css ); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
do_action( 'foogallery_after_save_album', $post_id, $_POST ); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function get_ordered_galleries( $album ) { |
|
140
|
|
|
|
|
141
|
|
|
//get all other galleries |
|
142
|
|
|
$galleries = foogallery_get_all_galleries( $album->gallery_ids ); |
|
143
|
|
|
|
|
144
|
|
|
$album_galleries = $album->galleries(); |
|
145
|
|
|
|
|
146
|
|
|
return array_merge( $album_galleries, $galleries ); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function render_gallery_metabox( $post ) { |
|
150
|
|
|
$album = $this->get_album( $post ); |
|
151
|
|
|
|
|
152
|
|
|
$galleries = $this->get_ordered_galleries( $album ); |
|
153
|
|
|
|
|
154
|
|
|
?> |
|
155
|
|
|
<input type="hidden" name="<?php echo FOOGALLERY_CPT_ALBUM; ?>_nonce" |
|
156
|
|
|
id="<?php echo FOOGALLERY_CPT_ALBUM; ?>_nonce" |
|
157
|
|
|
value="<?php echo wp_create_nonce( plugin_basename( FOOGALLERY_FILE ) ); ?>"/> |
|
158
|
|
|
<input type="hidden" name='foogallery_album_galleries' id="foogallery_album_galleries" |
|
159
|
|
|
value="<?php echo $album->gallery_id_csv(); ?>"/> |
|
160
|
|
|
<div> |
|
161
|
|
|
<ul class="foogallery-album-gallery-list"> |
|
162
|
|
|
<?php |
|
163
|
|
|
foreach ( $galleries as $gallery ) { |
|
164
|
|
|
$img_src = $gallery->featured_image_src( array( 150, 150 ) ); |
|
165
|
|
|
$images = $gallery->image_count(); |
|
166
|
|
|
$selected = $album->includes_gallery( $gallery->ID ) ? ' selected' : ''; |
|
167
|
|
|
?> |
|
168
|
|
|
<li class="foogallery-pile"> |
|
169
|
|
|
<div class="foogallery-gallery-select attachment-preview landscape<?php echo $selected; ?>" |
|
170
|
|
|
data-foogallery-id="<?php echo $gallery->ID; ?>"> |
|
171
|
|
|
<div class="thumbnail" style="display: table;"> |
|
172
|
|
|
<div style="display: table-cell; vertical-align: middle; text-align: center;"> |
|
173
|
|
|
<img src="<?php echo $img_src; ?>"/> |
|
174
|
|
|
<?php |
|
175
|
|
|
|
|
176
|
|
|
$title = empty( $gallery->name ) ? |
|
177
|
|
|
sprintf( __( '%s #%s', 'foogallery' ), foogallery_plugin_name(), $gallery->ID ) : |
|
178
|
|
|
$gallery->name; |
|
179
|
|
|
|
|
180
|
|
|
?> |
|
181
|
|
|
<h3><?php echo $title; ?> |
|
182
|
|
|
<span><?php echo $images; ?></span> |
|
183
|
|
|
</h3> |
|
184
|
|
|
</div> |
|
185
|
|
|
</div> |
|
186
|
|
|
</div> |
|
187
|
|
|
</li> |
|
188
|
|
|
<?php } ?> |
|
189
|
|
|
</ul> |
|
190
|
|
|
<div style="clear: both;"></div> |
|
191
|
|
|
</div> |
|
192
|
|
|
<?php |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function render_shortcode_metabox( $post ) { |
|
196
|
|
|
$album = $this->get_album( $post ); |
|
197
|
|
|
$shortcode = $album->shortcode(); |
|
198
|
|
|
?> |
|
199
|
|
|
<p class="foogallery-shortcode"> |
|
200
|
|
|
<input type="text" id="foogallery-copy-shortcode" size="<?php echo strlen( $shortcode ); ?>" value="<?php echo htmlspecialchars( $shortcode ); ?>" readonly="readonly" /> |
|
201
|
|
|
</p> |
|
202
|
|
|
<p> |
|
203
|
|
|
<?php _e( 'Paste the above shortcode into a post or page to show the album.', 'foogallery' ); ?> |
|
204
|
|
|
</p> |
|
205
|
|
|
<script> |
|
206
|
|
|
jQuery(function($) { |
|
207
|
|
|
var shortcodeInput = document.querySelector('#foogallery-copy-shortcode'); |
|
208
|
|
|
shortcodeInput.addEventListener('click', function () { |
|
209
|
|
|
try { |
|
210
|
|
|
// select the contents |
|
211
|
|
|
shortcodeInput.select(); |
|
212
|
|
|
//copy the selection |
|
213
|
|
|
document.execCommand('copy'); |
|
214
|
|
|
//show the copied message |
|
215
|
|
|
$('.foogallery-shortcode-message').remove(); |
|
216
|
|
|
$(shortcodeInput).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>'); |
|
217
|
|
|
} catch(err) { |
|
218
|
|
|
console.log('Oops, unable to copy!'); |
|
219
|
|
|
} |
|
220
|
|
|
}, false); |
|
221
|
|
|
}); |
|
222
|
|
|
</script> |
|
223
|
|
|
<?php |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
public function render_sorting_metabox( $post ) { |
|
227
|
|
|
$album = $this->get_album( $post ); |
|
228
|
|
|
$sorting_options = foogallery_sorting_options(); ?> |
|
229
|
|
|
<p> |
|
230
|
|
|
<?php _e('Change the way galleries are sorted within your album. By default, they are sorted in the order you see them.', 'foogallery'); ?> |
|
231
|
|
|
</p> |
|
232
|
|
|
<?php |
|
233
|
|
|
foreach ( $sorting_options as $sorting_key => $sorting_label ) { ?> |
|
234
|
|
|
<p> |
|
235
|
|
|
<input type="radio" value="<?php echo $sorting_key; ?>" <?php checked( $sorting_key === $album->sorting ); ?> id="FooGallerySettings_AlbumSort_<?php echo $sorting_key; ?>" name="<?php echo FOOGALLERY_ALBUM_META_SORT; ?>" /> |
|
236
|
|
|
<label for="FooGallerySettings_AlbumSort_<?php echo $sorting_key; ?>"><?php echo $sorting_label; ?></label> |
|
237
|
|
|
</p><?php |
|
238
|
|
|
} |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
public function render_settings_metabox( $post ) { |
|
242
|
|
|
$album = $this->get_album( $post ); |
|
243
|
|
|
$available_templates = foogallery_album_templates(); |
|
244
|
|
|
$album_template = foogallery_default_album_template(); |
|
245
|
|
|
if ( ! empty($album->album_template) ) { |
|
246
|
|
|
$album_template = $album->album_template; |
|
247
|
|
|
} |
|
248
|
|
|
if ( false === $album_template ) { |
|
249
|
|
|
$album_template = $available_templates[0]['slug']; |
|
250
|
|
|
} |
|
251
|
|
|
$hide_help = 'on' == foogallery_get_setting( 'hide_gallery_template_help' ); |
|
252
|
|
|
?> |
|
253
|
|
|
<table class="foogallery-album-metabox-settings"> |
|
254
|
|
|
<tbody> |
|
255
|
|
|
<tr class="gallery_template_field gallery_template_field_selector"> |
|
256
|
|
|
<th> |
|
257
|
|
|
<label for="FooGallerySettings_AlbumTemplate"><?php _e( 'Album Template', 'foogallery' ); ?></label> |
|
258
|
|
|
</th> |
|
259
|
|
|
<td> |
|
260
|
|
|
<select id="FooGallerySettings_AlbumTemplate" name="<?php echo FOOGALLERY_ALBUM_META_TEMPLATE; ?>"> |
|
261
|
|
|
<?php |
|
262
|
|
|
foreach ( $available_templates as $template ) { |
|
263
|
|
|
$selected = ($album_template === $template['slug']) ? 'selected' : ''; |
|
264
|
|
|
echo "<option {$selected} value=\"{$template['slug']}\">{$template['name']}</option>"; |
|
265
|
|
|
} |
|
266
|
|
|
?> |
|
267
|
|
|
</select> |
|
268
|
|
|
<br /> |
|
269
|
|
|
<small><?php _e( 'The album template that will be used when the album is output to the frontend.', 'foogallery' ); ?></small> |
|
270
|
|
|
</td> |
|
271
|
|
|
</tr> |
|
272
|
|
|
<?php |
|
273
|
|
|
foreach ( $available_templates as $template ) { |
|
274
|
|
|
$field_visibility = ($album_template !== $template['slug']) ? 'style="display:none"' : ''; |
|
275
|
|
|
$section = ''; |
|
276
|
|
|
$fields = isset( $template['fields'] ) ? $template['fields'] : array(); |
|
277
|
|
|
foreach ( $fields as $field ) { |
|
278
|
|
|
//allow for the field to be altered by extensions. |
|
279
|
|
|
$field = apply_filters( 'foogallery_alter_gallery_template_field', $field, $album ); |
|
280
|
|
|
|
|
281
|
|
|
$class = "gallery_template_field gallery_template_field-{$template['slug']} gallery_template_field-{$template['slug']}-{$field['id']}"; |
|
282
|
|
|
|
|
283
|
|
|
if ( isset($field['section']) && $field['section'] !== $section ) { |
|
284
|
|
|
$section = $field['section']; |
|
285
|
|
|
?> |
|
286
|
|
|
<tr class="<?php echo $class; ?>" <?php echo $field_visibility; ?>> |
|
287
|
|
|
<td colspan="2"><h4><?php echo $section; ?></h4></td> |
|
288
|
|
|
</tr> |
|
289
|
|
|
<?php } |
|
290
|
|
|
if (isset($field['type']) && 'help' == $field['type'] && $hide_help) { |
|
291
|
|
|
continue; //skip help if the 'hide help' setting is turned on |
|
292
|
|
|
} |
|
293
|
|
|
?> |
|
294
|
|
|
<tr class="<?php echo $class; ?>" <?php echo $field_visibility; ?>> |
|
295
|
|
|
<?php if ( isset($field['type']) && 'help' == $field['type'] ) { ?> |
|
296
|
|
|
<td colspan="2"> |
|
297
|
|
|
<div class="foogallery-help"> |
|
298
|
|
|
<?php echo $field['desc']; ?> |
|
299
|
|
|
</div> |
|
300
|
|
|
</td> |
|
301
|
|
|
<?php } else { ?> |
|
302
|
|
|
<th> |
|
303
|
|
|
<label for="FooGallerySettings_<?php echo $template['slug'] . '_' . $field['id']; ?>"><?php echo $field['title']; ?></label> |
|
304
|
|
|
</th> |
|
305
|
|
|
<td> |
|
306
|
|
|
<?php do_action( 'foogallery_render_gallery_template_field', $field, $album, $template ); ?> |
|
307
|
|
|
</td> |
|
308
|
|
|
<?php } ?> |
|
309
|
|
|
</tr> |
|
310
|
|
|
<?php |
|
311
|
|
|
} |
|
312
|
|
|
} |
|
313
|
|
|
?> |
|
314
|
|
|
</tbody> |
|
315
|
|
|
</table> |
|
316
|
|
|
<?php |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
public function render_customcss_metabox( $post ) { |
|
320
|
|
|
$album = $this->get_album( $post ); |
|
321
|
|
|
$custom_css = $album->custom_css; |
|
322
|
|
|
$example = '<code>#foogallery-album-' . $post->ID . ' { }</code>'; |
|
323
|
|
|
?> |
|
324
|
|
|
<p> |
|
325
|
|
|
<?php printf( __( 'Add any custom CSS to target this specific album. For example %s', 'foogallery' ), $example ); ?> |
|
326
|
|
|
</p> |
|
327
|
|
|
<table id="table_styling" class="form-table"> |
|
328
|
|
|
<tbody> |
|
329
|
|
|
<tr> |
|
330
|
|
|
<td> |
|
331
|
|
|
<textarea class="foogallery_metabox_custom_css" name="<?php echo FOOGALLERY_META_CUSTOM_CSS; ?>" type="text"><?php echo $custom_css; ?></textarea> |
|
332
|
|
|
</td> |
|
333
|
|
|
</tr> |
|
334
|
|
|
</tbody> |
|
335
|
|
|
</table> |
|
336
|
|
|
<?php |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
public function include_required_scripts() { |
|
340
|
|
|
if ( FOOGALLERY_CPT_ALBUM === foo_current_screen_post_type() ) { |
|
341
|
|
|
//include album selection script |
|
342
|
|
|
$url = FOOGALLERY_ALBUM_URL . 'js/admin-foogallery-album.js'; |
|
343
|
|
|
wp_enqueue_script( 'admin-foogallery-album', $url, array( 'jquery', 'jquery-ui-core','jquery-ui-sortable' ), FOOGALLERY_VERSION ); |
|
344
|
|
|
|
|
345
|
|
|
//include album selection css |
|
346
|
|
|
$url = FOOGALLERY_ALBUM_URL . 'css/admin-foogallery-album.css'; |
|
347
|
|
|
wp_enqueue_style( 'admin-foogallery-album', $url, array(), FOOGALLERY_VERSION ); |
|
348
|
|
|
|
|
349
|
|
|
//spectrum needed for the colorpicker field |
|
350
|
|
|
$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.js'; |
|
351
|
|
|
wp_enqueue_script( 'foogallery-spectrum', $url, array('jquery'), FOOGALLERY_VERSION ); |
|
352
|
|
|
$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.css'; |
|
353
|
|
|
wp_enqueue_style( 'foogallery-spectrum', $url, array(), FOOGALLERY_VERSION ); |
|
354
|
|
|
} |
|
355
|
|
|
} |
|
356
|
|
|
} |
|
357
|
|
|
} |
|
358
|
|
|
|