|
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
|
|
|
// Ajax call for getting gallery details |
|
27
|
|
|
add_action( 'wp_ajax_foogallery_get_gallery_details', array( $this, 'ajax_get_gallery_details' ) ); |
|
28
|
|
|
|
|
29
|
|
|
// Ajax call for saving gallery details |
|
30
|
|
|
add_action( 'wp_ajax_foogallery_save_gallery_details', array( $this, 'ajax_save_gallery_details' ) ); |
|
31
|
|
|
|
|
32
|
|
|
// Save details for the gallery |
|
33
|
|
|
add_action( 'foogallery_album_gallery_details_save', array( $this, 'gallery_details_save' ), 10, 3 ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function whitelist_metaboxes() { |
|
37
|
|
|
return array( |
|
38
|
|
|
FOOGALLERY_CPT_GALLERY => array( |
|
39
|
|
|
'whitelist' => apply_filters( 'foogallery_metabox_sanity_foogallery-album', |
|
40
|
|
|
array( |
|
41
|
|
|
'submitdiv', |
|
42
|
|
|
'slugdiv', |
|
43
|
|
|
'postimagediv', |
|
44
|
|
|
'foogalleryalbum_galleries', |
|
45
|
|
|
'foogalleryalbum_shortcode' |
|
46
|
|
|
) |
|
47
|
|
|
), |
|
48
|
|
|
'contexts' => array( 'normal', 'advanced', 'side', ), |
|
49
|
|
|
'priorities' => array( 'high', 'core', 'default', 'low', ), |
|
50
|
|
|
) |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function add_meta_boxes() { |
|
55
|
|
|
add_meta_box( |
|
56
|
|
|
'foogalleryalbum_galleries', |
|
57
|
|
|
__( 'Galleries - click a gallery to add it to your album.', 'foogallery' ), |
|
58
|
|
|
array( $this, 'render_gallery_metabox' ), |
|
59
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
60
|
|
|
'normal', |
|
61
|
|
|
'high' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
add_meta_box( |
|
65
|
|
|
'foogalleryalbum_settings', |
|
66
|
|
|
__( 'Settings', 'foogallery' ), |
|
67
|
|
|
array( $this, 'render_settings_metabox' ), |
|
68
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
69
|
|
|
'normal', |
|
70
|
|
|
'high' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
add_meta_box( |
|
74
|
|
|
'foogalleryalbum_customcss', |
|
75
|
|
|
__( 'Custom CSS', 'foogallery' ), |
|
76
|
|
|
array( $this, 'render_customcss_metabox' ), |
|
77
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
78
|
|
|
'normal', |
|
79
|
|
|
'low' |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
add_meta_box( |
|
83
|
|
|
'foogalleryalbum_shortcode', |
|
84
|
|
|
__( 'Album Shortcode', 'foogallery' ), |
|
85
|
|
|
array( $this, 'render_shortcode_metabox' ), |
|
86
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
87
|
|
|
'side', |
|
88
|
|
|
'default' |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
add_meta_box( |
|
92
|
|
|
'foogalleryalbum_sorting', |
|
93
|
|
|
__( 'Album Sorting', 'foogallery' ), |
|
94
|
|
|
array( $this, 'render_sorting_metabox' ), |
|
95
|
|
|
FOOGALLERY_CPT_ALBUM, |
|
96
|
|
|
'side', |
|
97
|
|
|
'default' |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function get_album( $post ) { |
|
102
|
|
|
if ( ! isset( $this->_album ) ) { |
|
103
|
|
|
$this->_album = FooGalleryAlbum::get( $post ); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $this->_album; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function save_album( $post_id ) { |
|
110
|
|
|
// check autosave |
|
111
|
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
112
|
|
|
return $post_id; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
// verify nonce |
|
116
|
|
|
if ( array_key_exists( FOOGALLERY_CPT_ALBUM . '_nonce', $_POST ) && |
|
117
|
|
|
wp_verify_nonce( $_POST[ FOOGALLERY_CPT_ALBUM . '_nonce' ], plugin_basename( FOOGALLERY_FILE ) ) |
|
118
|
|
|
) { |
|
119
|
|
|
//if we get here, we are dealing with the Album custom post type |
|
120
|
|
|
|
|
121
|
|
|
$galleries = apply_filters( 'foogallery_save_album_galleries', explode( ',', $_POST[ FOOGALLERY_ALBUM_META_GALLERIES ] ) ); |
|
122
|
|
|
update_post_meta( $post_id, FOOGALLERY_ALBUM_META_GALLERIES, $galleries ); |
|
123
|
|
|
|
|
124
|
|
|
update_post_meta( $post_id, FOOGALLERY_ALBUM_META_TEMPLATE, $_POST[FOOGALLERY_ALBUM_META_TEMPLATE] ); |
|
125
|
|
|
|
|
126
|
|
|
update_post_meta( $post_id, FOOGALLERY_ALBUM_META_SORT, $_POST[FOOGALLERY_ALBUM_META_SORT] ); |
|
127
|
|
|
|
|
128
|
|
|
$settings = isset($_POST[FOOGALLERY_META_SETTINGS]) ? |
|
129
|
|
|
$_POST[FOOGALLERY_META_SETTINGS] : array(); |
|
130
|
|
|
|
|
131
|
|
|
$settings = apply_filters( 'foogallery_save_album_settings', $settings ); |
|
132
|
|
|
|
|
133
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_SETTINGS, $settings ); |
|
134
|
|
|
|
|
135
|
|
|
$custom_css = isset($_POST[FOOGALLERY_META_CUSTOM_CSS]) ? |
|
136
|
|
|
$_POST[FOOGALLERY_META_CUSTOM_CSS] : ''; |
|
137
|
|
|
|
|
138
|
|
|
if ( empty( $custom_css ) ) { |
|
139
|
|
|
delete_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS ); |
|
140
|
|
|
} else { |
|
141
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS, $custom_css ); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
do_action( 'foogallery_after_save_album', $post_id, $_POST ); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function get_ordered_galleries( $album ) { |
|
149
|
|
|
|
|
150
|
|
|
//get all other galleries |
|
151
|
|
|
$galleries = foogallery_get_all_galleries( $album->gallery_ids ); |
|
152
|
|
|
|
|
153
|
|
|
$album_galleries = $album->galleries(); |
|
154
|
|
|
|
|
155
|
|
|
return array_merge( $album_galleries, $galleries ); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function render_gallery_metabox( $post ) { |
|
159
|
|
|
$album = $this->get_album( $post ); |
|
160
|
|
|
|
|
161
|
|
|
$galleries = $this->get_ordered_galleries( $album ); |
|
162
|
|
|
|
|
163
|
|
|
?> |
|
164
|
|
|
<input type="hidden" name="<?php echo FOOGALLERY_CPT_ALBUM; ?>_nonce" |
|
165
|
|
|
id="<?php echo FOOGALLERY_CPT_ALBUM; ?>_nonce" |
|
166
|
|
|
value="<?php echo wp_create_nonce( plugin_basename( FOOGALLERY_FILE ) ); ?>"/> |
|
167
|
|
|
<input type="hidden" name='foogallery_album_galleries' id="foogallery_album_galleries" |
|
168
|
|
|
value="<?php echo $album->gallery_id_csv(); ?>"/> |
|
169
|
|
|
<div> |
|
170
|
|
|
<?php if ( !$album->has_galleries() ) { ?> |
|
171
|
|
|
<div class="foogallery-album-error"> |
|
172
|
|
|
<?php _e( 'There are no galleries selected for your album yet! Click any gallery to add it to your album.', 'foogallery' ); ?> |
|
173
|
|
|
</div> |
|
174
|
|
|
<?php } ?> |
|
175
|
|
|
|
|
176
|
|
|
<div class="foogallery-album-info-modal media-modal"> |
|
177
|
|
|
<div class="media-modal-content"> |
|
178
|
|
|
<div class="media-frame mode-select"> |
|
179
|
|
|
<div class="media-frame-title"> |
|
180
|
|
|
<h1><?php _e('Edit Gallery Details', 'foogallery'); ?></h1> |
|
181
|
|
|
<span class="spinner is-active"></span> |
|
182
|
|
|
</div> |
|
183
|
|
|
<div class="modal-content"> |
|
184
|
|
|
<?php wp_nonce_field( 'foogallery_album_gallery_details', 'foogallery_album_gallery_details_nonce', false ); ?> |
|
185
|
|
|
<div class="gallery-details" data-loading="<?php _e( 'Loading details for ', 'foogallery' ); ?>"></div> |
|
186
|
|
|
</div> |
|
187
|
|
|
</div> |
|
188
|
|
|
<div class="media-frame-toolbar"> |
|
189
|
|
|
<div class="media-toolbar"> |
|
190
|
|
|
<div class="media-toolbar-secondary"></div> |
|
191
|
|
|
<div class="media-toolbar-primary search-form"> |
|
192
|
|
|
<button type="button" class="button media-button button-primary button-large media-button-select gallery-details-save"><?php _e('Save Gallery Details', 'foogallery'); ?></button> |
|
193
|
|
|
<span class="spinner"></span> |
|
194
|
|
|
</div> |
|
195
|
|
|
</div> |
|
196
|
|
|
</div> |
|
197
|
|
|
</div> |
|
198
|
|
|
<button type="button" class="button-link media-modal-close"> |
|
199
|
|
|
<span class="media-modal-icon"><span class="screen-reader-text"><?php _e('Close media panel', 'foogallery'); ?></span></span> |
|
200
|
|
|
</button> |
|
201
|
|
|
|
|
202
|
|
|
</div> |
|
203
|
|
|
<div class="foogallery-album-info-modal-backdrop media-modal-backdrop"></div> |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
<ul class="foogallery-album-gallery-list"> |
|
207
|
|
|
<?php |
|
208
|
|
|
foreach ( $galleries as $gallery ) { |
|
209
|
|
|
$img_src = $gallery->featured_image_src( array( 150, 150 ) ); |
|
210
|
|
|
$images = $gallery->image_count(); |
|
211
|
|
|
$selected = $album->includes_gallery( $gallery->ID ) ? ' selected' : ''; |
|
212
|
|
|
$title = $gallery->safe_name(); |
|
213
|
|
|
?> |
|
214
|
|
|
<li class="foogallery-pile"> |
|
215
|
|
|
<div class="foogallery-gallery-select attachment-preview landscape<?php echo $selected; ?>" data-foogallery-id="<?php echo $gallery->ID; ?>"> |
|
216
|
|
|
<div class="thumbnail" style="display: table;"> |
|
217
|
|
|
<div style="display: table-cell; vertical-align: middle; text-align: center;"> |
|
218
|
|
|
<img src="<?php echo $img_src; ?>"/> |
|
219
|
|
|
<h3><?php echo $title; ?> |
|
220
|
|
|
<span><?php echo $images; ?></span> |
|
221
|
|
|
</h3> |
|
222
|
|
|
</div> |
|
223
|
|
|
</div> |
|
224
|
|
|
<a class="info foogallery-album-info" href="#" |
|
225
|
|
|
title="<?php _e( 'Edit Album Info', 'foogallery' ); ?>" |
|
226
|
|
|
data-gallery-title="<?php echo $title; ?>" |
|
227
|
|
|
data-gallery-id="<?php echo $gallery->ID; ?>"><span class="dashicons dashicons-info"></span></a> |
|
228
|
|
|
</div> |
|
229
|
|
|
</li> |
|
230
|
|
|
<?php } ?> |
|
231
|
|
|
</ul> |
|
232
|
|
|
<div style="clear: both;"></div> |
|
233
|
|
|
</div> |
|
234
|
|
|
<?php |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function render_shortcode_metabox( $post ) { |
|
238
|
|
|
$album = $this->get_album( $post ); |
|
239
|
|
|
$shortcode = $album->shortcode(); |
|
240
|
|
|
?> |
|
241
|
|
|
<p class="foogallery-shortcode"> |
|
242
|
|
|
<input type="text" id="foogallery-copy-shortcode" size="<?php echo strlen( $shortcode ); ?>" value="<?php echo htmlspecialchars( $shortcode ); ?>" readonly="readonly" /> |
|
243
|
|
|
</p> |
|
244
|
|
|
<p> |
|
245
|
|
|
<?php _e( 'Paste the above shortcode into a post or page to show the album.', 'foogallery' ); ?> |
|
246
|
|
|
</p> |
|
247
|
|
|
<script> |
|
248
|
|
|
jQuery(function($) { |
|
249
|
|
|
var shortcodeInput = document.querySelector('#foogallery-copy-shortcode'); |
|
250
|
|
|
shortcodeInput.addEventListener('click', function () { |
|
251
|
|
|
try { |
|
252
|
|
|
// select the contents |
|
253
|
|
|
shortcodeInput.select(); |
|
254
|
|
|
//copy the selection |
|
255
|
|
|
document.execCommand('copy'); |
|
256
|
|
|
//show the copied message |
|
257
|
|
|
$('.foogallery-shortcode-message').remove(); |
|
258
|
|
|
$(shortcodeInput).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>'); |
|
259
|
|
|
} catch(err) { |
|
260
|
|
|
console.log('Oops, unable to copy!'); |
|
261
|
|
|
} |
|
262
|
|
|
}, false); |
|
263
|
|
|
}); |
|
264
|
|
|
</script> |
|
265
|
|
|
<?php |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
public function render_sorting_metabox( $post ) { |
|
269
|
|
|
$album = $this->get_album( $post ); |
|
270
|
|
|
$sorting_options = foogallery_sorting_options(); ?> |
|
271
|
|
|
<p> |
|
272
|
|
|
<?php _e('Change the way galleries are sorted within your album. By default, they are sorted in the order you see them.', 'foogallery'); ?> |
|
273
|
|
|
</p> |
|
274
|
|
|
<?php |
|
275
|
|
|
foreach ( $sorting_options as $sorting_key => $sorting_label ) { ?> |
|
276
|
|
|
<p> |
|
277
|
|
|
<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; ?>" /> |
|
278
|
|
|
<label for="FooGallerySettings_AlbumSort_<?php echo $sorting_key; ?>"><?php echo $sorting_label; ?></label> |
|
279
|
|
|
</p><?php |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
public function render_settings_metabox( $post ) { |
|
284
|
|
|
$album = $this->get_album( $post ); |
|
285
|
|
|
$available_templates = foogallery_album_templates(); |
|
286
|
|
|
$album_template = foogallery_default_album_template(); |
|
287
|
|
|
if ( ! empty($album->album_template) ) { |
|
288
|
|
|
$album_template = $album->album_template; |
|
289
|
|
|
} |
|
290
|
|
|
if ( false === $album_template ) { |
|
291
|
|
|
$album_template = $available_templates[0]['slug']; |
|
292
|
|
|
} |
|
293
|
|
|
$hide_help = 'on' == foogallery_get_setting( 'hide_gallery_template_help' ); |
|
294
|
|
|
?> |
|
295
|
|
|
<table class="foogallery-album-metabox-settings"> |
|
296
|
|
|
<tbody> |
|
297
|
|
|
<tr class="gallery_template_field gallery_template_field_selector"> |
|
298
|
|
|
<th> |
|
299
|
|
|
<label for="FooGallerySettings_AlbumTemplate"><?php _e( 'Album Template', 'foogallery' ); ?></label> |
|
300
|
|
|
</th> |
|
301
|
|
|
<td> |
|
302
|
|
|
<select id="FooGallerySettings_AlbumTemplate" name="<?php echo FOOGALLERY_ALBUM_META_TEMPLATE; ?>"> |
|
303
|
|
|
<?php |
|
304
|
|
|
foreach ( $available_templates as $template ) { |
|
305
|
|
|
$selected = ($album_template === $template['slug']) ? 'selected' : ''; |
|
306
|
|
|
echo "<option {$selected} value=\"{$template['slug']}\">{$template['name']}</option>"; |
|
307
|
|
|
} |
|
308
|
|
|
?> |
|
309
|
|
|
</select> |
|
310
|
|
|
<br /> |
|
311
|
|
|
<small><?php _e( 'The album template that will be used when the album is output to the frontend.', 'foogallery' ); ?></small> |
|
312
|
|
|
</td> |
|
313
|
|
|
</tr> |
|
314
|
|
|
<?php |
|
315
|
|
|
foreach ( $available_templates as $template ) { |
|
316
|
|
|
$field_visibility = ($album_template !== $template['slug']) ? 'style="display:none"' : ''; |
|
317
|
|
|
$section = ''; |
|
318
|
|
|
$fields = isset( $template['fields'] ) ? $template['fields'] : array(); |
|
319
|
|
|
foreach ( $fields as $field ) { |
|
320
|
|
|
//allow for the field to be altered by extensions. |
|
321
|
|
|
$field = apply_filters( 'foogallery_alter_gallery_template_field', $field, $album ); |
|
322
|
|
|
|
|
323
|
|
|
$class = "gallery_template_field gallery_template_field-{$template['slug']} gallery_template_field-{$template['slug']}-{$field['id']}"; |
|
324
|
|
|
|
|
325
|
|
|
if ( isset($field['section']) && $field['section'] !== $section ) { |
|
326
|
|
|
$section = $field['section']; |
|
327
|
|
|
?> |
|
328
|
|
|
<tr class="<?php echo $class; ?>" <?php echo $field_visibility; ?>> |
|
329
|
|
|
<td colspan="2"><h4><?php echo $section; ?></h4></td> |
|
330
|
|
|
</tr> |
|
331
|
|
|
<?php } |
|
332
|
|
|
if (isset($field['type']) && 'help' == $field['type'] && $hide_help) { |
|
333
|
|
|
continue; //skip help if the 'hide help' setting is turned on |
|
334
|
|
|
} |
|
335
|
|
|
?> |
|
336
|
|
|
<tr class="<?php echo $class; ?>" <?php echo $field_visibility; ?>> |
|
337
|
|
|
<?php if ( isset($field['type']) && 'help' == $field['type'] ) { ?> |
|
338
|
|
|
<td colspan="2"> |
|
339
|
|
|
<div class="foogallery-help"> |
|
340
|
|
|
<?php echo $field['desc']; ?> |
|
341
|
|
|
</div> |
|
342
|
|
|
</td> |
|
343
|
|
|
<?php } else { ?> |
|
344
|
|
|
<th> |
|
345
|
|
|
<label for="FooGallerySettings_<?php echo $template['slug'] . '_' . $field['id']; ?>"><?php echo $field['title']; ?></label> |
|
346
|
|
|
</th> |
|
347
|
|
|
<td> |
|
348
|
|
|
<?php do_action( 'foogallery_render_gallery_template_field', $field, $album, $template ); ?> |
|
349
|
|
|
</td> |
|
350
|
|
|
<?php } ?> |
|
351
|
|
|
</tr> |
|
352
|
|
|
<?php |
|
353
|
|
|
} |
|
354
|
|
|
} |
|
355
|
|
|
?> |
|
356
|
|
|
</tbody> |
|
357
|
|
|
</table> |
|
358
|
|
|
<?php |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
public function render_customcss_metabox( $post ) { |
|
362
|
|
|
$album = $this->get_album( $post ); |
|
363
|
|
|
$custom_css = $album->custom_css; |
|
364
|
|
|
$example = '<code>#foogallery-album-' . $post->ID . ' { }</code>'; |
|
365
|
|
|
?> |
|
366
|
|
|
<p> |
|
367
|
|
|
<?php printf( __( 'Add any custom CSS to target this specific album. For example %s', 'foogallery' ), $example ); ?> |
|
368
|
|
|
</p> |
|
369
|
|
|
<table id="table_styling" class="form-table"> |
|
370
|
|
|
<tbody> |
|
371
|
|
|
<tr> |
|
372
|
|
|
<td> |
|
373
|
|
|
<textarea class="foogallery_metabox_custom_css" name="<?php echo FOOGALLERY_META_CUSTOM_CSS; ?>" type="text"><?php echo $custom_css; ?></textarea> |
|
374
|
|
|
</td> |
|
375
|
|
|
</tr> |
|
376
|
|
|
</tbody> |
|
377
|
|
|
</table> |
|
378
|
|
|
<?php |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
public function include_required_scripts() { |
|
382
|
|
|
if ( FOOGALLERY_CPT_ALBUM === foo_current_screen_post_type() ) { |
|
383
|
|
|
//include album selection script |
|
384
|
|
|
$url = FOOGALLERY_ALBUM_URL . 'js/admin-foogallery-album.js'; |
|
385
|
|
|
wp_enqueue_script( 'admin-foogallery-album', $url, array( 'jquery', 'jquery-ui-core','jquery-ui-sortable' ), FOOGALLERY_VERSION ); |
|
386
|
|
|
|
|
387
|
|
|
//include album selection css |
|
388
|
|
|
$url = FOOGALLERY_ALBUM_URL . 'css/admin-foogallery-album.css'; |
|
389
|
|
|
wp_enqueue_style( 'admin-foogallery-album', $url, array(), FOOGALLERY_VERSION ); |
|
390
|
|
|
|
|
391
|
|
|
//spectrum needed for the colorpicker field |
|
392
|
|
|
$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.js'; |
|
393
|
|
|
wp_enqueue_script( 'foogallery-spectrum', $url, array('jquery'), FOOGALLERY_VERSION ); |
|
394
|
|
|
$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.css'; |
|
395
|
|
|
wp_enqueue_style( 'foogallery-spectrum', $url, array(), FOOGALLERY_VERSION ); |
|
396
|
|
|
} |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
public function ajax_get_gallery_details() { |
|
|
|
|
|
|
400
|
|
|
if ( check_admin_referer( 'foogallery_album_gallery_details' ) ) { |
|
401
|
|
|
$foogallery_id = $_POST['foogallery_id']; |
|
402
|
|
|
$gallery = FooGallery::get_by_id( $foogallery_id ); |
|
403
|
|
|
|
|
404
|
|
|
if ( false !== $gallery ) { |
|
405
|
|
|
$fields = $this->get_gallery_detail_fields( $gallery ); ?> |
|
406
|
|
|
<form name="foogallery_gallery_details"> |
|
407
|
|
|
<input type="hidden" name="foogallery_id" id="foogallery_id" value="<?php echo $foogallery_id; ?>" /> |
|
408
|
|
|
<table class="gallery-detail-fields"> |
|
409
|
|
|
<tbody> |
|
410
|
|
|
<?php foreach ( $fields as $field => $values ) { |
|
411
|
|
|
$value = get_post_meta( $gallery->ID, $field, true ); |
|
412
|
|
|
$input_id = 'foogallery-gallery-detail-fields-' . $field; |
|
413
|
|
|
switch ( $values['input'] ) { |
|
414
|
|
|
case 'text': |
|
415
|
|
|
$values['html'] = '<input type="text" id="' . $input_id . '" name="' . $field . '" value="' . $value . '" />'; |
|
416
|
|
|
break; |
|
417
|
|
|
|
|
418
|
|
|
case 'textarea': |
|
419
|
|
|
$values['html'] = '<textarea id="' . $input_id . '" name="' . $field . '">' . $value . '</textarea>'; |
|
420
|
|
|
break; |
|
421
|
|
|
|
|
422
|
|
|
case 'select': |
|
423
|
|
|
$html = '<select id="' . $input_id . '" name="' . $field . '">'; |
|
424
|
|
|
|
|
425
|
|
|
// If options array is passed |
|
426
|
|
|
if ( isset( $values['options'] ) ) { |
|
427
|
|
|
// Browse and add the options |
|
428
|
|
|
foreach ( $values['options'] as $k => $v ) { |
|
429
|
|
|
// Set the option selected or not |
|
430
|
|
|
if ( $value == $k ) |
|
431
|
|
|
$selected = ' selected="selected"'; |
|
432
|
|
|
else |
|
433
|
|
|
$selected = ''; |
|
434
|
|
|
|
|
435
|
|
|
$html .= '<option' . $selected . ' value="' . $k . '">' . $v . '</option>'; |
|
436
|
|
|
} |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
$html .= '</select>'; |
|
440
|
|
|
|
|
441
|
|
|
// Set the html content |
|
442
|
|
|
$values['html'] = $html; |
|
443
|
|
|
|
|
444
|
|
|
break; |
|
445
|
|
|
|
|
446
|
|
|
case 'checkbox': |
|
|
|
|
|
|
447
|
|
|
|
|
448
|
|
|
// Set the checkbox checked or not |
|
449
|
|
|
if ( $value == 'on' ) |
|
450
|
|
|
$checked = ' checked="checked"'; |
|
451
|
|
|
else |
|
452
|
|
|
$checked = ''; |
|
453
|
|
|
|
|
454
|
|
|
$html = '<input' . $checked . ' type="checkbox" name="' . $field . ']" id="' . $input_id . '" />'; |
|
455
|
|
|
|
|
456
|
|
|
$values['html'] = $html; |
|
457
|
|
|
|
|
458
|
|
|
break; |
|
459
|
|
|
|
|
460
|
|
|
case 'radio': |
|
|
|
|
|
|
461
|
|
|
|
|
462
|
|
|
$html = ''; |
|
463
|
|
|
|
|
464
|
|
|
if ( ! empty( $values['options'] ) ) { |
|
465
|
|
|
$i = 0; |
|
466
|
|
|
|
|
467
|
|
|
foreach ( $values['options'] as $k => $v ) { |
|
468
|
|
|
if ( $value == $k ) |
|
469
|
|
|
$checked = ' checked="checked"'; |
|
470
|
|
|
else |
|
471
|
|
|
$checked = ''; |
|
472
|
|
|
|
|
473
|
|
|
$html .= '<input' . $checked . ' value="' . $k . '" type="radio" name="' . $field . ']" id="' . sanitize_key( $field . '_' . $i ) . '" /> <label for="' . sanitize_key( $field . '_' . $i ) . '">' . $v . '</label><br />'; |
|
474
|
|
|
$i++; |
|
475
|
|
|
} |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
$values['html'] = $html; |
|
479
|
|
|
|
|
480
|
|
|
break; |
|
481
|
|
|
} ?> |
|
482
|
|
|
<tr class="foogallery-gallery-detail-fields-<?php echo $field; ?>"> |
|
483
|
|
|
<th scope="row" class="label"> |
|
484
|
|
|
<label for="foogallery-gallery-detail-fields-<?php echo $field; ?>"><?php echo $values['label']; ?></label> |
|
485
|
|
|
</th> |
|
486
|
|
|
<td> |
|
487
|
|
|
<?php echo $values['html']; ?> |
|
488
|
|
|
<?php if ( !empty( $values['help'] ) ) { ?><p class="help"><?php echo $values['help']; ?></p><?php } ?> |
|
489
|
|
|
</td> |
|
490
|
|
|
</tr> |
|
491
|
|
|
<?php } ?> |
|
492
|
|
|
</tbody> |
|
493
|
|
|
</table> |
|
494
|
|
|
</form><?php |
|
495
|
|
|
} else { |
|
496
|
|
|
echo '<h2>' . __( 'Invalid Gallery!', 'foogallery' ) . '</h2>'; |
|
497
|
|
|
} |
|
498
|
|
|
} |
|
499
|
|
|
die(); |
|
|
|
|
|
|
500
|
|
|
} |
|
501
|
|
|
|
|
502
|
|
|
public function ajax_save_gallery_details() { |
|
|
|
|
|
|
503
|
|
|
if ( check_admin_referer( 'foogallery_album_gallery_details' ) ) { |
|
504
|
|
|
$foogallery_id = $_POST['foogallery_id']; |
|
505
|
|
|
$gallery = FooGallery::get_by_id( $foogallery_id ); |
|
506
|
|
|
if ( false !== $gallery ) { |
|
507
|
|
|
$fields = $this->get_gallery_detail_fields( $gallery ); |
|
508
|
|
|
|
|
509
|
|
|
foreach ( $fields as $field => $values ) { |
|
510
|
|
|
//for every field, save some info |
|
511
|
|
|
do_action( 'foogallery_album_gallery_details_save', $field, $values, $gallery ); |
|
512
|
|
|
} |
|
513
|
|
|
} |
|
514
|
|
|
} |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
public function gallery_details_save($field, $field_args, $gallery) { |
|
|
|
|
|
|
518
|
|
|
if ( 'custom_url' === $field || 'custom_target' === $field ) { |
|
519
|
|
|
$value = $_POST[$field]; |
|
520
|
|
|
update_post_meta( $gallery->ID, $field, $value ); |
|
521
|
|
|
} |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
/** |
|
525
|
|
|
* Get the fields that we want to edit for a gallery from the album management page |
|
526
|
|
|
* @param $gallery FooGallery |
|
527
|
|
|
* |
|
528
|
|
|
* @return mixed|void |
|
529
|
|
|
*/ |
|
530
|
|
|
public function get_gallery_detail_fields($gallery) { |
|
531
|
|
|
|
|
532
|
|
|
$target_options = apply_filters( 'foogallery_gallery_detail_fields_custom_target_options', array( |
|
533
|
|
|
'default' => __( 'Default', 'foogallery' ), |
|
534
|
|
|
'_blank' => __( 'New tab (_blank)', 'foogallery' ), |
|
535
|
|
|
'_self' => __( 'Same tab (_self)', 'foogallery' ) |
|
536
|
|
|
) ); |
|
537
|
|
|
|
|
538
|
|
|
$edit_url = get_edit_post_link( $gallery->ID ); |
|
539
|
|
|
|
|
540
|
|
|
$fields = array( |
|
541
|
|
|
'gallery_title' => array( |
|
542
|
|
|
'label' => __( 'Gallery Title', 'foogallery' ), |
|
543
|
|
|
'input' => 'html', |
|
544
|
|
|
'html' => '<strong>' . $gallery->safe_name() . ' <a href="' . $edit_url . '" target="_blank">' . __( 'Edit Gallery', 'foogallery' ) . '</a></strong>', |
|
545
|
|
|
), |
|
546
|
|
|
|
|
547
|
|
|
'gallery_template' => array( |
|
548
|
|
|
'label' => __( 'Gallery Template', 'foogallery' ), |
|
549
|
|
|
'input' => 'html', |
|
550
|
|
|
'html' => '<strong>' . $gallery->gallery_template_name() . '</strong>', |
|
551
|
|
|
), |
|
552
|
|
|
|
|
553
|
|
|
'gallery_media' => array( |
|
554
|
|
|
'label' => __( 'Media', 'foogallery' ), |
|
555
|
|
|
'input' => 'html', |
|
556
|
|
|
'html' => '<strong>' . $gallery->image_count() . '</strong>' |
|
557
|
|
|
), |
|
558
|
|
|
|
|
559
|
|
|
'custom_url' => array( |
|
560
|
|
|
'label' => __( 'Custom URL', 'foogallery' ), |
|
561
|
|
|
'input' => 'text', |
|
562
|
|
|
'help' => __( 'Point your gallery to a custom URL', 'foogallery' ) |
|
563
|
|
|
), |
|
564
|
|
|
|
|
565
|
|
|
'custom_target' => array( |
|
566
|
|
|
'label' => __( 'Custom Target', 'foogallery' ), |
|
567
|
|
|
'input' => 'select', |
|
568
|
|
|
'help' => __( 'Set a custom target for your gallery', 'foogallery' ), |
|
569
|
|
|
'options' => $target_options |
|
570
|
|
|
) |
|
571
|
|
|
); |
|
572
|
|
|
|
|
573
|
|
|
return apply_filters( 'foogallery_gallery_detail_fields', $fields ); |
|
574
|
|
|
} |
|
575
|
|
|
} |
|
576
|
|
|
} |
|
577
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: