1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* FooGallery Admin Gallery MetaBoxes class |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBoxes' ) ) { |
8
|
|
|
|
9
|
|
|
class FooGallery_Admin_Gallery_MetaBoxes { |
10
|
|
|
|
11
|
|
|
private $_gallery; |
12
|
|
|
|
13
|
|
|
public function __construct() { |
14
|
|
|
//add our foogallery metaboxes |
15
|
|
|
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes_to_gallery' ) ); |
16
|
|
|
|
17
|
|
|
//save extra post data for a gallery |
18
|
|
|
add_action( 'save_post', array( $this, 'save_gallery' ) ); |
19
|
|
|
|
20
|
|
|
//save custom field on a page or post |
21
|
|
|
add_Action( 'save_post', array( $this, 'attach_gallery_to_post' ), 10, 2 ); |
22
|
|
|
|
23
|
|
|
//whitelist metaboxes for our gallery postype |
24
|
|
|
add_filter( 'foogallery_metabox_sanity', array( $this, 'whitelist_metaboxes' ) ); |
25
|
|
|
|
26
|
|
|
//add scripts used by metaboxes |
27
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'include_required_scripts' ) ); |
28
|
|
|
|
29
|
|
|
// Ajax calls for creating a page for the gallery |
30
|
|
|
add_action( 'wp_ajax_foogallery_create_gallery_page', array( $this, 'ajax_create_gallery_page' ) ); |
31
|
|
|
|
32
|
|
|
// Ajax call for clearing thumb cache for the gallery |
33
|
|
|
add_action( 'wp_ajax_foogallery_clear_gallery_thumb_cache', array( $this, 'ajax_clear_gallery_thumb_cache' ) ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function whitelist_metaboxes() { |
37
|
|
|
return array( |
38
|
|
|
FOOGALLERY_CPT_GALLERY => array( |
39
|
|
|
'whitelist' => apply_filters( 'foogallery_metabox_sanity_foogallery', |
40
|
|
|
array( |
41
|
|
|
'submitdiv', |
42
|
|
|
'slugdiv', |
43
|
|
|
'postimagediv', |
44
|
|
|
'foogallery_items', |
45
|
|
|
'foogallery_settings', |
46
|
|
|
'foogallery_preview', |
47
|
|
|
'foogallery_help', |
48
|
|
|
'foogallery_pages', |
49
|
|
|
'foogallery_customcss', |
50
|
|
|
'foogallery_sorting', |
51
|
|
|
'foogallery_thumb_settings', |
52
|
|
|
'foogallery_retina' |
53
|
|
|
) ), |
54
|
|
|
'contexts' => array( 'normal', 'advanced', 'side', ), |
55
|
|
|
'priorities' => array( 'high', 'core', 'default', 'low', ), |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function add_meta_boxes_to_gallery() { |
61
|
|
|
global $post; |
62
|
|
|
|
63
|
|
|
add_meta_box( |
64
|
|
|
'foogallery_items', |
65
|
|
|
__( 'Gallery Items', 'foogallery' ), |
66
|
|
|
array( $this, 'render_gallery_media_metabox' ), |
67
|
|
|
FOOGALLERY_CPT_GALLERY, |
68
|
|
|
'normal', |
69
|
|
|
'high' |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
add_meta_box( |
73
|
|
|
'foogallery_settings', |
74
|
|
|
__( 'Gallery Settings', 'foogallery' ), |
75
|
|
|
array( $this, 'render_gallery_settings_metabox' ), |
76
|
|
|
FOOGALLERY_CPT_GALLERY, |
77
|
|
|
'normal', |
78
|
|
|
'high' |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
add_meta_box( |
82
|
|
|
'foogallery_preview', |
83
|
|
|
__( 'Gallery Preview', 'foogallery' ), |
84
|
|
|
array( $this, 'render_gallery_preview_metabox' ), |
85
|
|
|
FOOGALLERY_CPT_GALLERY, |
86
|
|
|
'normal', |
87
|
|
|
'high' |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
add_meta_box( |
91
|
|
|
'foogallery_help', |
92
|
|
|
__( 'Gallery Shortcode', 'foogallery' ), |
93
|
|
|
array( $this, 'render_gallery_shortcode_metabox' ), |
94
|
|
|
FOOGALLERY_CPT_GALLERY, |
95
|
|
|
'side', |
96
|
|
|
'default' |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
if ( 'publish' == $post->post_status ) { |
100
|
|
|
add_meta_box( 'foogallery_pages', |
101
|
|
|
__( 'Gallery Usage', 'foogallery' ), |
102
|
|
|
array( $this, 'render_gallery_usage_metabox' ), |
103
|
|
|
FOOGALLERY_CPT_GALLERY, |
104
|
|
|
'side', |
105
|
|
|
'default' |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
add_meta_box( |
110
|
|
|
'foogallery_customcss', |
111
|
|
|
__( 'Custom CSS', 'foogallery' ), |
112
|
|
|
array( $this, 'render_customcss_metabox' ), |
113
|
|
|
FOOGALLERY_CPT_GALLERY, |
114
|
|
|
'normal', |
115
|
|
|
'low' |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
add_meta_box( |
119
|
|
|
'foogallery_retina', |
120
|
|
|
__( 'Retina Support', 'foogallery' ), |
121
|
|
|
array( $this, 'render_retina_metabox' ), |
122
|
|
|
FOOGALLERY_CPT_GALLERY, |
123
|
|
|
'side', |
124
|
|
|
'default' |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
add_meta_box( |
128
|
|
|
'foogallery_sorting', |
129
|
|
|
__( 'Gallery Sorting', 'foogallery' ), |
130
|
|
|
array( $this, 'render_sorting_metabox' ), |
131
|
|
|
FOOGALLERY_CPT_GALLERY, |
132
|
|
|
'side', |
133
|
|
|
'default' |
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
add_meta_box( |
137
|
|
|
'foogallery_thumb_settings', |
138
|
|
|
__( 'Thumbnails', 'foogallery' ), |
139
|
|
|
array( $this, 'render_thumb_settings_metabox' ), |
140
|
|
|
FOOGALLERY_CPT_GALLERY, |
141
|
|
|
'side', |
142
|
|
|
'default' |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function get_gallery( $post ) { |
147
|
|
|
if ( ! isset($this->_gallery) ) { |
148
|
|
|
$this->_gallery = FooGallery::get( $post ); |
149
|
|
|
|
150
|
|
|
//attempt to load default gallery settings from another gallery, as per FooGallery settings page |
151
|
|
|
$this->_gallery->load_default_settings_if_new(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $this->_gallery; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function save_gallery( $post_id ) { |
|
|
|
|
158
|
|
|
// check autosave |
159
|
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
160
|
|
|
return $post_id; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
// verify nonce |
164
|
|
|
if ( array_key_exists( FOOGALLERY_CPT_GALLERY . '_nonce', $_POST ) && |
165
|
|
|
wp_verify_nonce( $_POST[FOOGALLERY_CPT_GALLERY . '_nonce'], plugin_basename( FOOGALLERY_FILE ) ) |
166
|
|
|
) { |
167
|
|
|
//if we get here, we are dealing with the Gallery custom post type |
168
|
|
|
do_action( 'foogallery_before_save_gallery', $post_id, $_POST ); |
169
|
|
|
|
170
|
|
|
$attachments = apply_filters( 'foogallery_save_gallery_attachments', explode( ',', $_POST[FOOGALLERY_META_ATTACHMENTS] ) ); |
171
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_ATTACHMENTS, $attachments ); |
172
|
|
|
|
173
|
|
|
$settings = isset($_POST[FOOGALLERY_META_SETTINGS]) ? |
174
|
|
|
$_POST[FOOGALLERY_META_SETTINGS] : array(); |
175
|
|
|
|
176
|
|
|
$settings = apply_filters( 'foogallery_save_gallery_settings', $settings ); |
177
|
|
|
|
178
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_TEMPLATE, $_POST[FOOGALLERY_META_TEMPLATE] ); |
179
|
|
|
|
180
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_SETTINGS, $settings ); |
181
|
|
|
|
182
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_SORT, $_POST[FOOGALLERY_META_SORT] ); |
183
|
|
|
|
184
|
|
|
$custom_css = isset($_POST[FOOGALLERY_META_CUSTOM_CSS]) ? |
185
|
|
|
$_POST[FOOGALLERY_META_CUSTOM_CSS] : ''; |
186
|
|
|
|
187
|
|
|
if ( empty( $custom_css ) ) { |
188
|
|
|
delete_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS ); |
189
|
|
|
} else { |
190
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS, $custom_css ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
if ( isset( $_POST[FOOGALLERY_META_RETINA] ) ) { |
194
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_RETINA, $_POST[FOOGALLERY_META_RETINA] ); |
195
|
|
|
} else { |
196
|
|
|
delete_post_meta( $post_id, FOOGALLERY_META_RETINA ); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
if ( isset( $_POST[FOOGALLERY_META_FORCE_ORIGINAL_THUMBS] ) ) { |
200
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS, $_POST[FOOGALLERY_META_FORCE_ORIGINAL_THUMBS] ); |
201
|
|
|
} else { |
202
|
|
|
delete_post_meta( $post_id, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS ); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
update_post_meta( $post_id, FOOGALLERY_META_SETTINGS_VERSION, FOOGALLERY_SETTINGS_VERSION ); |
206
|
|
|
|
207
|
|
|
do_action( 'foogallery_after_save_gallery', $post_id, $_POST ); |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function attach_gallery_to_post( $post_id, $post ) { |
212
|
|
|
|
213
|
|
|
// check autosave |
214
|
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
215
|
|
|
return $post_id; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
//only do this check for a page or post |
219
|
|
|
if ( 'post' == $post->post_type || |
220
|
|
|
'page' == $post->post_type ) { |
221
|
|
|
|
222
|
|
|
do_action( 'foogallery_start_attach_gallery_to_post', $post_id ); |
223
|
|
|
|
224
|
|
|
//Clear any foogallery usages that the post might have |
225
|
|
|
delete_post_meta( $post_id, FOOGALLERY_META_POST_USAGE ); |
226
|
|
|
|
227
|
|
|
//get all foogallery shortcodes that are on the page/post |
228
|
|
|
$gallery_shortcodes = foogallery_extract_gallery_shortcodes( $post->post_content ); |
229
|
|
|
|
230
|
|
|
if ( is_array( $gallery_shortcodes ) && count( $gallery_shortcodes ) > 0 ) { |
231
|
|
|
|
232
|
|
|
foreach ( $gallery_shortcodes as $id => $shortcode ) { |
233
|
|
|
//if the content contains the foogallery shortcode then add a custom field |
234
|
|
|
add_post_meta( $post_id, FOOGALLERY_META_POST_USAGE, $id, false ); |
235
|
|
|
|
236
|
|
|
do_action( 'foogallery_attach_gallery_to_post', $post_id, $id ); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function render_gallery_media_metabox( $post ) { |
243
|
|
|
$gallery = $this->get_gallery( $post ); |
244
|
|
|
|
245
|
|
|
wp_enqueue_media(); |
246
|
|
|
|
247
|
|
|
?> |
248
|
|
|
<input type="hidden" name="<?php echo FOOGALLERY_CPT_GALLERY; ?>_nonce" |
249
|
|
|
id="<?php echo FOOGALLERY_CPT_GALLERY; ?>_nonce" |
250
|
|
|
value="<?php echo wp_create_nonce( plugin_basename( FOOGALLERY_FILE ) ); ?>"/> |
251
|
|
|
<input type="hidden" name='foogallery_attachments' id="foogallery_attachments" |
252
|
|
|
value="<?php echo $gallery->attachment_id_csv(); ?>"/> |
253
|
|
|
<div> |
254
|
|
|
<ul class="foogallery-attachments-list"> |
255
|
|
|
<?php |
256
|
|
|
if ( $gallery->has_attachments() ) { |
257
|
|
|
foreach ( $gallery->attachments() as $attachment ) { |
258
|
|
|
$this->render_gallery_item( $attachment ); |
259
|
|
|
} |
260
|
|
|
} ?> |
261
|
|
|
<li class="add-attachment"> |
262
|
|
|
<a href="#" data-uploader-title="<?php _e( 'Add Media To Gallery', 'foogallery' ); ?>" |
263
|
|
|
data-uploader-button-text="<?php _e( 'Add Media', 'foogallery' ); ?>" |
264
|
|
|
data-post-id="<?php echo $post->ID; ?>" class="upload_image_button" |
265
|
|
|
title="<?php _e( 'Add Media To Gallery', 'foogallery' ); ?>"> |
266
|
|
|
<div class="dashicons dashicons-format-gallery"></div> |
267
|
|
|
<span><?php _e( 'Add Media', 'foogallery' ); ?></span> |
268
|
|
|
</a> |
269
|
|
|
</li> |
270
|
|
|
</ul> |
271
|
|
|
<div style="clear: both;"></div> |
272
|
|
|
</div> |
273
|
|
|
<textarea style="display: none" id="foogallery-attachment-template"> |
274
|
|
|
<?php $this->render_gallery_item(); ?> |
275
|
|
|
</textarea> |
276
|
|
|
<?php |
277
|
|
|
|
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function render_gallery_item( $attachment_post = false ) { |
281
|
|
|
if ( $attachment_post != false ) { |
282
|
|
|
$attachment_id = $attachment_post->ID; |
283
|
|
|
$attachment = wp_get_attachment_image_src( $attachment_id ); |
284
|
|
|
} else { |
285
|
|
|
$attachment_id = ''; |
286
|
|
|
$attachment = ''; |
287
|
|
|
} |
288
|
|
|
$data_attribute = empty($attachment_id) ? '' : "data-attachment-id=\"{$attachment_id}\""; |
289
|
|
|
$img_tag = empty($attachment) ? '<img width="150" height="150" />' : "<img width=\"150\" height=\"150\" src=\"{$attachment[0]}\" />"; |
290
|
|
|
?> |
291
|
|
|
<li class="attachment details" <?php echo $data_attribute; ?>> |
292
|
|
|
<div class="attachment-preview type-image"> |
293
|
|
|
<div class="thumbnail"> |
294
|
|
|
<div class="centered"> |
295
|
|
|
<?php echo $img_tag; ?> |
296
|
|
|
</div> |
297
|
|
|
</div> |
298
|
|
|
<a class="info" href="#" title="<?php _e( 'Edit Info', 'foogallery' ); ?>"> |
299
|
|
|
<span class="dashicons dashicons-info"></span> |
300
|
|
|
</a> |
301
|
|
|
<a class="remove" href="#" title="<?php _e( 'Remove from gallery', 'foogallery' ); ?>"> |
302
|
|
|
<span class="dashicons dashicons-dismiss"></span> |
303
|
|
|
</a> |
304
|
|
|
</div> |
305
|
|
|
<!-- <input type="text" value="" class="describe" data-setting="caption" placeholder="Caption this image…" />--> |
306
|
|
|
</li> |
307
|
|
|
<?php |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
public function render_gallery_settings_metabox( $post ) { |
311
|
|
|
$gallery = FooGallery::get( $post ); |
312
|
|
|
|
313
|
|
|
$settings = new FooGallery_Admin_Gallery_MetaBox_Settings_Helper( $gallery ); |
314
|
|
|
|
315
|
|
|
$settings->render_hidden_gallery_template_selector(); |
316
|
|
|
|
317
|
|
|
$settings->render_gallery_settings(); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public function render_gallery_preview_metabox( $post ) { |
321
|
|
|
$gallery = $this->get_gallery( $post ); |
322
|
|
|
|
323
|
|
|
foogallery_render_gallery( $gallery->ID ); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
public function render_gallery_shortcode_metabox( $post ) { |
327
|
|
|
$gallery = $this->get_gallery( $post ); |
328
|
|
|
$shortcode = $gallery->shortcode(); |
329
|
|
|
?> |
330
|
|
|
<p class="foogallery-shortcode"> |
331
|
|
|
<input type="text" id="foogallery-copy-shortcode" size="<?php echo strlen( $shortcode ); ?>" value="<?php echo htmlspecialchars( $shortcode ); ?>" readonly="readonly" /> |
332
|
|
|
</p> |
333
|
|
|
<p> |
334
|
|
|
<?php _e( 'Paste the above shortcode into a post or page to show the gallery.', 'foogallery' ); ?> |
335
|
|
|
</p> |
336
|
|
|
<script> |
337
|
|
|
jQuery(function($) { |
338
|
|
|
var shortcodeInput = document.querySelector('#foogallery-copy-shortcode'); |
339
|
|
|
shortcodeInput.addEventListener('click', function () { |
340
|
|
|
try { |
341
|
|
|
// select the contents |
342
|
|
|
shortcodeInput.select(); |
343
|
|
|
//copy the selection |
344
|
|
|
document.execCommand('copy'); |
345
|
|
|
//show the copied message |
346
|
|
|
$('.foogallery-shortcode-message').remove(); |
347
|
|
|
$(shortcodeInput).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>'); |
348
|
|
|
} catch(err) { |
349
|
|
|
console.log('Oops, unable to copy!'); |
350
|
|
|
} |
351
|
|
|
}, false); |
352
|
|
|
}); |
353
|
|
|
</script> |
354
|
|
|
<?php |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
public function render_gallery_usage_metabox( $post ) { |
358
|
|
|
$gallery = $this->get_gallery( $post ); |
359
|
|
|
$posts = $gallery->find_usages(); |
360
|
|
|
if ( $posts && count( $posts ) > 0 ) { ?> |
361
|
|
|
<p> |
362
|
|
|
<?php _e( 'This gallery is used on the following posts or pages:', 'foogallery' ); ?> |
363
|
|
|
</p> |
364
|
|
|
<ul class="ul-disc"> |
365
|
|
|
<?php foreach ( $posts as $post ) { |
366
|
|
|
$url = get_permalink( $post->ID ); |
367
|
|
|
echo '<li>' . $post->post_title . ' '; |
368
|
|
|
edit_post_link( __( 'Edit', 'foogallery' ), '<span class="edit">', ' | </span>', $post->ID ); |
369
|
|
|
echo '<span class="view"><a href="' . esc_url( $url ) . '" target="_blank">' . __( 'View', 'foogallery' ) . '</a></li>'; |
370
|
|
|
} ?> |
371
|
|
|
</ul> |
372
|
|
|
<?php } else { ?> |
373
|
|
|
<p> |
374
|
|
|
<?php _e( 'This gallery is not used on any pages or pages yet. Quickly create a page:', 'foogallery' ); ?> |
375
|
|
|
</p> |
376
|
|
|
<div class="foogallery_metabox_actions"> |
377
|
|
|
<button class="button button-primary button-large" id="foogallery_create_page"><?php _e( 'Create Gallery Page', 'foogallery' ); ?></button> |
378
|
|
|
<span id="foogallery_create_page_spinner" class="spinner"></span> |
379
|
|
|
<?php wp_nonce_field( 'foogallery_create_gallery_page', 'foogallery_create_gallery_page_nonce', false ); ?> |
380
|
|
|
</div> |
381
|
|
|
<p> |
382
|
|
|
<?php _e( 'A draft page will be created which includes the gallery shortcode in the content. The title of the page will be the same title as the gallery.', 'foogallery' ); ?> |
383
|
|
|
</p> |
384
|
|
|
<?php } |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
public function render_sorting_metabox( $post ) { |
388
|
|
|
$gallery = $this->get_gallery( $post ); |
389
|
|
|
$sorting_options = foogallery_sorting_options(); |
390
|
|
|
if ( empty( $gallery->sorting ) ) { |
391
|
|
|
$gallery->sorting = ''; |
392
|
|
|
} |
393
|
|
|
?> |
394
|
|
|
<p> |
395
|
|
|
<?php _e('Change the way images are sorted within your gallery. By default, they are sorted in the order you see them.', 'foogallery'); ?> |
396
|
|
|
</p> |
397
|
|
|
<?php |
398
|
|
|
foreach ( $sorting_options as $sorting_key => $sorting_label ) { ?> |
399
|
|
|
<p> |
400
|
|
|
<input type="radio" value="<?php echo $sorting_key; ?>" <?php checked( $sorting_key === $gallery->sorting ); ?> id="FooGallerySettings_GallerySort_<?php echo $sorting_key; ?>" name="<?php echo FOOGALLERY_META_SORT; ?>" /> |
401
|
|
|
<label for="FooGallerySettings_GallerySort_<?php echo $sorting_key; ?>"><?php echo $sorting_label; ?></label> |
402
|
|
|
</p><?php |
403
|
|
|
} ?> |
404
|
|
|
<p class="foogallery-help"> |
405
|
|
|
<?php _e('PLEASE NOTE : sorting randomly will force HTML Caching for the gallery to be disabled.', 'foogallery'); ?> |
406
|
|
|
</p> |
407
|
|
|
<?php |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
public function render_retina_metabox( $post ) { |
411
|
|
|
$gallery = $this->get_gallery( $post ); |
412
|
|
|
$retina_options = foogallery_retina_options(); |
413
|
|
|
if ( empty( $gallery->retina ) ) { |
414
|
|
|
$gallery->retina = foogallery_get_setting( 'default_retina_support', array() ); |
|
|
|
|
415
|
|
|
} |
416
|
|
|
?> |
417
|
|
|
<p> |
418
|
|
|
<?php _e('Add retina support to this gallery by choosing the different pixel densities you want to enable.', 'foogallery'); ?> |
419
|
|
|
</p> |
420
|
|
|
<?php |
421
|
|
|
foreach ( $retina_options as $retina_key => $retina_label ) { |
422
|
|
|
$checked = array_key_exists( $retina_key, $gallery->retina ) ? ('true' === $gallery->retina[$retina_key]) : false; |
423
|
|
|
?> |
424
|
|
|
<p> |
425
|
|
|
<input type="checkbox" value="true" <?php checked( $checked ); ?> id="FooGallerySettings_Retina_<?php echo $retina_key; ?>" name="<?php echo FOOGALLERY_META_RETINA; ?>[<?php echo $retina_key; ?>]" /> |
426
|
|
|
<label for="FooGallerySettings_Retina_<?php echo $retina_key; ?>"><?php echo $retina_label; ?></label> |
427
|
|
|
</p><?php |
428
|
|
|
} ?> |
429
|
|
|
<p class="foogallery-help"> |
430
|
|
|
<?php _e('PLEASE NOTE : thumbnails will be generated for each of the pixel densities chosen, which will increase your website\'s storage space!', 'foogallery'); ?> |
431
|
|
|
</p> |
432
|
|
|
<?php |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
public function render_thumb_settings_metabox( $post ) { |
436
|
|
|
$gallery = $this->get_gallery( $post ); |
|
|
|
|
437
|
|
|
$force_use_original_thumbs = get_post_meta( $post->ID, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS, true ); |
438
|
|
|
$checked = 'true' === $force_use_original_thumbs; ?> |
439
|
|
|
<p> |
440
|
|
|
<?php _e( 'Clear all the previously cached thumbnails that have been generated for this gallery.', 'foogallery' ); ?> |
441
|
|
|
</p> |
442
|
|
|
<div class="foogallery_metabox_actions"> |
443
|
|
|
<button class="button button-primary button-large" id="foogallery_clear_thumb_cache"><?php _e( 'Clear Thumbnail Cache', 'foogallery' ); ?></button> |
444
|
|
|
<span id="foogallery_clear_thumb_cache_spinner" class="spinner"></span> |
445
|
|
|
<?php wp_nonce_field( 'foogallery_clear_gallery_thumb_cache', 'foogallery_clear_gallery_thumb_cache_nonce', false ); ?> |
446
|
|
|
</div> |
447
|
|
|
<p> |
448
|
|
|
<input type="checkbox" value="true" <?php checked( $checked ); ?> id="FooGallerySettings_ForceOriginalThumbs" name="<?php echo FOOGALLERY_META_FORCE_ORIGINAL_THUMBS; ?>" /> |
449
|
|
|
<label for="FooGallerySettings_ForceOriginalThumbs"><?php _e('Force Original Thumbs', 'foogallery'); ?></label> |
450
|
|
|
</p> |
451
|
|
|
<?php |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
public function include_required_scripts() { |
455
|
|
|
$screen_id = foo_current_screen_id(); |
456
|
|
|
|
457
|
|
|
//only include scripts if we on the foogallery add/edit page |
458
|
|
|
if ( FOOGALLERY_CPT_GALLERY === $screen_id || |
459
|
|
|
'edit-' . FOOGALLERY_CPT_GALLERY === $screen_id ) { |
460
|
|
|
|
461
|
|
|
//spectrum needed for the colorpicker field |
462
|
|
|
$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.js'; |
463
|
|
|
wp_enqueue_script( 'foogallery-spectrum', $url, array('jquery'), FOOGALLERY_VERSION ); |
464
|
|
|
$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.css'; |
465
|
|
|
wp_enqueue_style( 'foogallery-spectrum', $url, array(), FOOGALLERY_VERSION ); |
466
|
|
|
|
467
|
|
|
//include any admin js required for the templates |
468
|
|
|
foreach ( foogallery_gallery_templates() as $template ) { |
469
|
|
|
$admin_js = foo_safe_get( $template, 'admin_js' ); |
470
|
|
|
if ( is_array( $admin_js ) ) { |
471
|
|
|
//dealing with an array of js files to include |
472
|
|
|
foreach( $admin_js as $admin_js_key => $admin_js_src ) { |
473
|
|
|
wp_enqueue_script( 'foogallery-gallery-admin-' . $template['slug'] . '-' . $admin_js_key, $admin_js_src, array('jquery', 'media-upload', 'jquery-ui-sortable'), FOOGALLERY_VERSION ); |
474
|
|
|
} |
475
|
|
|
} else { |
476
|
|
|
//dealing with a single js file to include |
477
|
|
|
wp_enqueue_script( 'foogallery-gallery-admin-' . $template['slug'], $admin_js, array('jquery', 'media-upload', 'jquery-ui-sortable'), FOOGALLERY_VERSION ); |
478
|
|
|
} |
479
|
|
|
} |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
public function render_customcss_metabox( $post ) { |
484
|
|
|
$gallery = $this->get_gallery( $post ); |
485
|
|
|
$custom_css = $gallery->custom_css; |
486
|
|
|
$example = '<code>#foogallery-gallery-' . $post->ID . ' { }</code>'; |
487
|
|
|
?> |
488
|
|
|
<p> |
489
|
|
|
<?php printf( __( 'Add any custom CSS to target this specific gallery. For example %s', 'foogallery' ), $example ); ?> |
490
|
|
|
</p> |
491
|
|
|
<table id="table_styling" class="form-table"> |
492
|
|
|
<tbody> |
493
|
|
|
<tr> |
494
|
|
|
<td> |
495
|
|
|
<textarea class="foogallery_metabox_custom_css" name="<?php echo FOOGALLERY_META_CUSTOM_CSS; ?>" type="text"><?php echo $custom_css; ?></textarea> |
496
|
|
|
</td> |
497
|
|
|
</tr> |
498
|
|
|
</tbody> |
499
|
|
|
</table> |
500
|
|
|
<?php |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
public function ajax_create_gallery_page() { |
|
|
|
|
504
|
|
|
if ( check_admin_referer( 'foogallery_create_gallery_page', 'foogallery_create_gallery_page_nonce' ) ) { |
505
|
|
|
|
506
|
|
|
$foogallery_id = $_POST['foogallery_id']; |
507
|
|
|
|
508
|
|
|
$foogallery = FooGallery::get_by_id( $foogallery_id ); |
509
|
|
|
|
510
|
|
|
$post = array( |
511
|
|
|
'post_content' => $foogallery->shortcode(), |
512
|
|
|
'post_title' => $foogallery->name, |
513
|
|
|
'post_status' => 'draft', |
514
|
|
|
'post_type' => 'page', |
515
|
|
|
); |
516
|
|
|
|
517
|
|
|
wp_insert_post( $post ); |
518
|
|
|
} |
519
|
|
|
die(); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
public function ajax_clear_gallery_thumb_cache() { |
|
|
|
|
523
|
|
|
if ( check_admin_referer( 'foogallery_clear_gallery_thumb_cache', 'foogallery_clear_gallery_thumb_cache_nonce' ) ) { |
524
|
|
|
|
525
|
|
|
$foogallery_id = $_POST['foogallery_id']; |
526
|
|
|
|
527
|
|
|
$foogallery = FooGallery::get_by_id( $foogallery_id ); |
528
|
|
|
|
529
|
|
|
ob_start(); |
530
|
|
|
|
531
|
|
|
//loop through all images, get the full sized file |
532
|
|
|
foreach ( $foogallery->attachments() as $attachment ) { |
533
|
|
|
$meta_data = wp_get_attachment_metadata( $attachment->ID ); |
534
|
|
|
|
535
|
|
|
$file = $meta_data['file']; |
536
|
|
|
|
537
|
|
|
wpthumb_delete_cache_for_file( $file ); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
ob_end_clean(); |
541
|
|
|
|
542
|
|
|
echo __( 'The thumbnail cache has been cleared!', 'foogallery' ); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
die(); |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
} |
549
|
|
|
|
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: