GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — feature/gallery-template-clien... ( abe0f1...ce7616 )
by Brad
02:33
created

render_customcss_metabox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
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
			// Ajax call for generating a gallery preview
36
			add_action( 'wp_ajax_foogallery_preview', array( $this, 'ajax_gallery_preview' ) );
37
		}
38
39
		public function whitelist_metaboxes() {
40
			return array(
41
				FOOGALLERY_CPT_GALLERY => array(
42
					'whitelist'  => apply_filters( 'foogallery_metabox_sanity_foogallery',
43
						array(
44
							'submitdiv',
45
							'slugdiv',
46
							'postimagediv',
47
							'foogallery_items',
48
							'foogallery_settings',
49
							'foogallery_help',
50
							'foogallery_pages',
51
							'foogallery_customcss',
52
							'foogallery_sorting',
53
							'foogallery_thumb_settings',
54
							'foogallery_retina'
55
						) ),
56
					'contexts'   => array( 'normal', 'advanced', 'side', ),
57
					'priorities' => array( 'high', 'core', 'default', 'low', ),
58
				)
59
			);
60
		}
61
62
		public function add_meta_boxes_to_gallery() {
63
			global $post;
64
65
			add_meta_box(
66
				'foogallery_items',
67
				__( 'Gallery Items', 'foogallery' ),
68
				array( $this, 'render_gallery_media_metabox' ),
69
				FOOGALLERY_CPT_GALLERY,
70
				'normal',
71
				'high'
72
			);
73
74
			add_meta_box(
75
				'foogallery_settings',
76
				__( 'Gallery Settings', 'foogallery' ),
77
				array( $this, 'render_gallery_settings_metabox' ),
78
				FOOGALLERY_CPT_GALLERY,
79
				'normal',
80
				'high'
81
			);
82
83
			add_meta_box(
84
				'foogallery_help',
85
				__( 'Gallery Shortcode', 'foogallery' ),
86
				array( $this, 'render_gallery_shortcode_metabox' ),
87
				FOOGALLERY_CPT_GALLERY,
88
				'side',
89
				'default'
90
			);
91
92
			if ( 'publish' == $post->post_status ) {
93
				add_meta_box( 'foogallery_pages',
94
					__( 'Gallery Usage', 'foogallery' ),
95
					array( $this, 'render_gallery_usage_metabox' ),
96
					FOOGALLERY_CPT_GALLERY,
97
					'side',
98
					'default'
99
				);
100
			}
101
102
			add_meta_box(
103
				'foogallery_customcss',
104
				__( 'Custom CSS', 'foogallery' ),
105
				array( $this, 'render_customcss_metabox' ),
106
				FOOGALLERY_CPT_GALLERY,
107
				'normal',
108
				'low'
109
			);
110
111
			add_meta_box(
112
				'foogallery_retina',
113
				__( 'Retina Support', 'foogallery' ),
114
				array( $this, 'render_retina_metabox' ),
115
				FOOGALLERY_CPT_GALLERY,
116
				'side',
117
				'default'
118
			);
119
120
			add_meta_box(
121
				'foogallery_sorting',
122
				__( 'Gallery Sorting', 'foogallery' ),
123
				array( $this, 'render_sorting_metabox' ),
124
				FOOGALLERY_CPT_GALLERY,
125
				'side',
126
				'default'
127
			);
128
129
			add_meta_box(
130
				'foogallery_thumb_settings',
131
				__( 'Thumbnails', 'foogallery' ),
132
				array( $this, 'render_thumb_settings_metabox' ),
133
				FOOGALLERY_CPT_GALLERY,
134
				'side',
135
				'default'
136
			);
137
		}
138
139
		public function get_gallery( $post ) {
140
			if ( ! isset($this->_gallery) ) {
141
				$this->_gallery = FooGallery::get( $post );
142
143
				//attempt to load default gallery settings from another gallery, as per FooGallery settings page
144
				$this->_gallery->load_default_settings_if_new();
145
			}
146
147
			return $this->_gallery;
148
		}
149
150
		public function save_gallery( $post_id ) {
0 ignored issues
show
Coding Style introduced by
save_gallery uses the super-global variable $_POST which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
151
			// check autosave
152
			if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
153
				return $post_id;
154
			}
155
156
			// verify nonce
157
			if ( array_key_exists( FOOGALLERY_CPT_GALLERY . '_nonce', $_POST ) &&
158
				wp_verify_nonce( $_POST[FOOGALLERY_CPT_GALLERY . '_nonce'], plugin_basename( FOOGALLERY_FILE ) )
159
			) {
160
				//if we get here, we are dealing with the Gallery custom post type
161
				do_action( 'foogallery_before_save_gallery', $post_id, $_POST );
162
163
				$attachments = apply_filters( 'foogallery_save_gallery_attachments', explode( ',', $_POST[FOOGALLERY_META_ATTACHMENTS] ), $post_id, $_POST );
164
				update_post_meta( $post_id, FOOGALLERY_META_ATTACHMENTS, $attachments );
165
166
				$gallery_template = $_POST[FOOGALLERY_META_TEMPLATE];
167
				update_post_meta( $post_id, FOOGALLERY_META_TEMPLATE, $gallery_template );
168
169
				$settings = isset($_POST[FOOGALLERY_META_SETTINGS]) ?
170
					$_POST[FOOGALLERY_META_SETTINGS] : array();
171
172
				$settings = apply_filters( 'foogallery_save_gallery_settings', $settings, $post_id, $_POST );
173
				$settings = apply_filters( 'foogallery_save_gallery_settings-'. $gallery_template, $settings, $post_id, $_POST );
174
175
				update_post_meta( $post_id, FOOGALLERY_META_SETTINGS, $settings );
176
177
				update_post_meta( $post_id, FOOGALLERY_META_SORT, $_POST[FOOGALLERY_META_SORT] );
178
179
				$custom_css = isset($_POST[FOOGALLERY_META_CUSTOM_CSS]) ?
180
					$_POST[FOOGALLERY_META_CUSTOM_CSS] : '';
181
182
				if ( empty( $custom_css ) ) {
183
					delete_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS );
184
				} else {
185
					update_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS, $custom_css );
186
				}
187
188
				if ( isset( $_POST[FOOGALLERY_META_RETINA] ) ) {
189
					update_post_meta( $post_id, FOOGALLERY_META_RETINA, $_POST[FOOGALLERY_META_RETINA] );
190
				} else {
191
					delete_post_meta( $post_id, FOOGALLERY_META_RETINA );
192
				}
193
194
				if ( isset( $_POST[FOOGALLERY_META_FORCE_ORIGINAL_THUMBS] ) ) {
195
					update_post_meta( $post_id, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS, $_POST[FOOGALLERY_META_FORCE_ORIGINAL_THUMBS] );
196
				} else {
197
					delete_post_meta( $post_id, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS );
198
				}
199
200
				do_action( 'foogallery_after_save_gallery', $post_id, $_POST );
201
			}
202
		}
203
204
		public function attach_gallery_to_post( $post_id, $post ) {
205
206
			// check autosave
207
			if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
208
				return $post_id;
209
			}
210
211
			//only do this check for a page or post
212
			if ( 'post' == $post->post_type ||
213
				'page' == $post->post_type ) {
214
215
                do_action( 'foogallery_start_attach_gallery_to_post', $post_id );
216
217
				//Clear any foogallery usages that the post might have
218
				delete_post_meta( $post_id, FOOGALLERY_META_POST_USAGE );
219
220
				//get all foogallery shortcodes that are on the page/post
221
				$gallery_shortcodes = foogallery_extract_gallery_shortcodes( $post->post_content );
222
223
                if ( is_array( $gallery_shortcodes ) && count( $gallery_shortcodes ) > 0 ) {
224
225
                    foreach ( $gallery_shortcodes as $id => $shortcode ) {
226
                        //if the content contains the foogallery shortcode then add a custom field
227
                        add_post_meta( $post_id, FOOGALLERY_META_POST_USAGE, $id, false );
228
229
                        do_action( 'foogallery_attach_gallery_to_post', $post_id, $id );
230
                    }
231
                }
232
			}
233
		}
234
235
		public function render_gallery_media_metabox( $post ) {
236
			$gallery = $this->get_gallery( $post );
237
238
			$mode = $gallery->get_meta( 'foogallery_items_view', 'manage' );
239
240
			wp_enqueue_media();
241
242
			?>
243
			<div class="hidden foogallery-items-view-switch-container">
244
				<div class="foogallery-items-view-switch">
245
					<a href="#manage" data-value="manage" data-container=".foogallery-items-view-manage" class="<?php echo $mode==='manage' ? 'current' : ''; ?>"><?php _e('Manage Items', 'foogallery'); ?></a>
246
					<a href="#preview" data-value="preview" data-container=".foogallery-items-view-preview" class="<?php echo $mode==='preview' ? 'current' : ''; ?>"><?php _e('Gallery Preview', 'foogallery'); ?></a>
247
				</div>
248
				<span id="foogallery_preview_spinner" class="spinner"></span>
249
                <input type="hidden" id="foogallery_items_view_input" name="<?php echo FOOGALLERY_META_SETTINGS . '[foogallery_items_view]'; ?>" />
250
			</div>
251
252
			<div class="foogallery-items-view foogallery-items-view-manage <?php echo $mode==='manage' ? '' : 'hidden'; ?>">
253
				<input type="hidden" name="<?php echo FOOGALLERY_CPT_GALLERY; ?>_nonce"
254
					   id="<?php echo FOOGALLERY_CPT_GALLERY; ?>_nonce"
255
					   value="<?php echo wp_create_nonce( plugin_basename( FOOGALLERY_FILE ) ); ?>"/>
256
				<input type="hidden" name='foogallery_attachments' id="foogallery_attachments"
257
					   value="<?php echo $gallery->attachment_id_csv(); ?>"/>
258
				<div>
259
					<ul class="foogallery-attachments-list">
260
					<?php
261
					if ( $gallery->has_attachments() ) {
262
						foreach ( $gallery->attachments() as $attachment ) {
263
							$this->render_gallery_item( $attachment );
264
						}
265
					} ?>
266
						<li class="add-attachment">
267
							<a href="#" data-uploader-title="<?php _e( 'Add Media To Gallery', 'foogallery' ); ?>"
268
							   data-uploader-button-text="<?php _e( 'Add Media', 'foogallery' ); ?>"
269
							   data-post-id="<?php echo $post->ID; ?>" class="upload_image_button"
270
							   title="<?php _e( 'Add Media To Gallery', 'foogallery' ); ?>">
271
								<div class="dashicons dashicons-format-gallery"></div>
272
								<span><?php _e( 'Add Media', 'foogallery' ); ?></span>
273
							</a>
274
						</li>
275
					</ul>
276
					<div style="clear: both;"></div>
277
				</div>
278
				<textarea style="display: none" id="foogallery-attachment-template">
279
					<?php $this->render_gallery_item(); ?>
280
				</textarea>
281
			</div>
282
			<div class="foogallery-items-view foogallery-items-view-preview <?php echo $mode==='preview' ? '' : 'hidden'; ?>">
283
				<div class="foogallery_preview_container">
284
				<?php
285
				if ( $gallery->has_attachments() ) {
286
					foogallery_render_gallery( $gallery->ID );
287
				}
288
				?>
289
				</div>
290
				<?php wp_nonce_field( 'foogallery_preview', 'foogallery_preview', false ); ?>
291
			</div>
292
		<?php
293
294
		}
295
296
		public function render_gallery_item( $attachment_post = false ) {
297
			if ( $attachment_post != false ) {
298
				$attachment_id = $attachment_post->ID;
299
				$attachment = wp_get_attachment_image_src( $attachment_id );
300
			} else {
301
				$attachment_id = '';
302
				$attachment = '';
303
			}
304
			$data_attribute = empty($attachment_id) ? '' : "data-attachment-id=\"{$attachment_id}\"";
305
			$img_tag        = empty($attachment) ? '<img width="150" height="150" />' : "<img width=\"150\" height=\"150\" src=\"{$attachment[0]}\" />";
306
			?>
307
			<li class="attachment details" <?php echo $data_attribute; ?>>
308
				<div class="attachment-preview type-image">
309
					<div class="thumbnail">
310
						<div class="centered">
311
							<?php echo $img_tag; ?>
312
						</div>
313
					</div>
314
					<a class="info" href="#" title="<?php _e( 'Edit Info', 'foogallery' ); ?>">
315
						<span class="dashicons dashicons-info"></span>
316
					</a>
317
					<a class="remove" href="#" title="<?php _e( 'Remove from gallery', 'foogallery' ); ?>">
318
						<span class="dashicons dashicons-dismiss"></span>
319
					</a>
320
				</div>
321
				<!--				<input type="text" value="" class="describe" data-setting="caption" placeholder="Caption this image…" />-->
322
			</li>
323
		<?php
324
		}
325
326
		public function render_gallery_settings_metabox( $post ) {
327
            $gallery = FooGallery::get( $post );
328
329
            $settings = new FooGallery_Admin_Gallery_MetaBox_Settings_Helper( $gallery );
330
331
            $settings->render_hidden_gallery_template_selector();
332
333
            $settings->render_gallery_settings();
334
		}
335
336
		public function render_gallery_shortcode_metabox( $post ) {
337
			$gallery = $this->get_gallery( $post );
338
			$shortcode = $gallery->shortcode();
339
			?>
340
			<p class="foogallery-shortcode">
341
				<input type="text" id="foogallery-copy-shortcode" size="<?php echo strlen( $shortcode ) + 2; ?>" value="<?php echo htmlspecialchars( $shortcode ); ?>" readonly="readonly" />
342
			</p>
343
			<p>
344
				<?php _e( 'Paste the above shortcode into a post or page to show the gallery.', 'foogallery' ); ?>
345
			</p>
346
			<script>
347
				jQuery(function($) {
348
					var shortcodeInput = document.querySelector('#foogallery-copy-shortcode');
349
					shortcodeInput.addEventListener('click', function () {
350
						try {
351
							// select the contents
352
							shortcodeInput.select();
353
							//copy the selection
354
							document.execCommand('copy');
355
							//show the copied message
356
							$('.foogallery-shortcode-message').remove();
357
							$(shortcodeInput).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>');
358
						} catch(err) {
359
							console.log('Oops, unable to copy!');
360
						}
361
					}, false);
362
				});
363
			</script>
364
			<?php
365
		}
366
367
		public function render_gallery_usage_metabox( $post ) {
368
			$gallery = $this->get_gallery( $post );
369
			$posts = $gallery->find_usages();
370
			if ( $posts && count( $posts ) > 0 ) { ?>
371
				<p>
372
					<?php _e( 'This gallery is used on the following posts or pages:', 'foogallery' ); ?>
373
				</p>
374
				<ul class="ul-disc">
375
				<?php foreach ( $posts as $post ) {
376
					$url = get_permalink( $post->ID );
377
					echo '<li>' . $post->post_title . '&nbsp;';
378
					edit_post_link( __( 'Edit', 'foogallery' ), '<span class="edit">', ' | </span>', $post->ID );
379
					echo '<span class="view"><a href="' . esc_url( $url ) . '" target="_blank">' . __( 'View', 'foogallery' ) . '</a></li>';
380
				} ?>
381
				</ul>
382
			<?php } else { ?>
383
				<p>
384
					<?php _e( 'This gallery is not used on any pages or pages yet. Quickly create a page:', 'foogallery' ); ?>
385
				</p>
386
				<div class="foogallery_metabox_actions">
387
					<button class="button button-primary button-large" id="foogallery_create_page"><?php _e( 'Create Gallery Page', 'foogallery' ); ?></button>
388
					<span id="foogallery_create_page_spinner" class="spinner"></span>
389
					<?php wp_nonce_field( 'foogallery_create_gallery_page', 'foogallery_create_gallery_page_nonce', false ); ?>
390
				</div>
391
				<p>
392
					<?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' ); ?>
393
				</p>
394
			<?php }
395
		}
396
397
		public function render_sorting_metabox( $post ) {
398
			$gallery = $this->get_gallery( $post );
399
			$sorting_options = foogallery_sorting_options();
400
			if ( empty( $gallery->sorting ) ) {
401
				$gallery->sorting = '';
402
			}
403
			?>
404
			<p>
405
				<?php _e('Change the way images are sorted within your gallery. By default, they are sorted in the order you see them.', 'foogallery'); ?>
406
			</p>
407
			<?php
408
			foreach ( $sorting_options as $sorting_key => $sorting_label ) { ?>
409
				<p>
410
				<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; ?>" />
411
				<label for="FooGallerySettings_GallerySort_<?php echo $sorting_key; ?>"><?php echo $sorting_label; ?></label>
412
				</p><?php
413
			} ?>
414
			<p class="foogallery-help">
415
				<?php _e('PLEASE NOTE : sorting randomly will force HTML Caching for the gallery to be disabled.', 'foogallery'); ?>
416
			</p>
417
			<?php
418
		}
419
420
		public function render_retina_metabox( $post ) {
421
			$gallery = $this->get_gallery( $post );
422
			$retina_options = foogallery_retina_options();
423
			if ( empty( $gallery->retina ) ) {
424
				$gallery->retina = foogallery_get_setting( 'default_retina_support', array() );
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
425
			}
426
			?>
427
			<p>
428
				<?php _e('Add retina support to this gallery by choosing the different pixel densities you want to enable.', 'foogallery'); ?>
429
			</p>
430
			<?php
431
			foreach ( $retina_options as $retina_key => $retina_label ) {
432
				$checked = array_key_exists( $retina_key, $gallery->retina ) ? ('true' === $gallery->retina[$retina_key]) : false;
433
				?>
434
				<p>
435
				<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; ?>]" />
436
				<label for="FooGallerySettings_Retina_<?php echo $retina_key; ?>"><?php echo $retina_label; ?></label>
437
				</p><?php
438
			} ?>
439
			<p class="foogallery-help">
440
				<?php _e('PLEASE NOTE : thumbnails will be generated for each of the pixel densities chosen, which will increase your website\'s storage space!', 'foogallery'); ?>
441
			</p>
442
			<?php
443
		}
444
445
		public function render_thumb_settings_metabox( $post ) {
446
			$gallery = $this->get_gallery( $post );
0 ignored issues
show
Unused Code introduced by
$gallery is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
447
			$force_use_original_thumbs = get_post_meta( $post->ID, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS, true );
448
			$checked = 'true' === $force_use_original_thumbs; ?>
449
			<p>
450
				<?php _e( 'Clear all the previously cached thumbnails that have been generated for this gallery.', 'foogallery' ); ?>
451
			</p>
452
			<div class="foogallery_metabox_actions">
453
				<button class="button button-primary button-large" id="foogallery_clear_thumb_cache"><?php _e( 'Clear Thumbnail Cache', 'foogallery' ); ?></button>
454
				<span id="foogallery_clear_thumb_cache_spinner" class="spinner"></span>
455
				<?php wp_nonce_field( 'foogallery_clear_gallery_thumb_cache', 'foogallery_clear_gallery_thumb_cache_nonce', false ); ?>
456
			</div>
457
			<p>
458
				<input type="checkbox" value="true" <?php checked( $checked ); ?> id="FooGallerySettings_ForceOriginalThumbs" name="<?php echo FOOGALLERY_META_FORCE_ORIGINAL_THUMBS; ?>" />
459
				<label for="FooGallerySettings_ForceOriginalThumbs"><?php _e('Force Original Thumbs', 'foogallery'); ?></label>
460
			</p>
461
			<?php
462
		}
463
464
		public function include_required_scripts() {
465
			$screen_id = foo_current_screen_id();
466
467
			//only include scripts if we on the foogallery add/edit page
468
			if ( FOOGALLERY_CPT_GALLERY === $screen_id ||
469
			     'edit-' . FOOGALLERY_CPT_GALLERY === $screen_id ) {
470
471
				//enqueue any dependencies from extensions or gallery templates
472
				do_action( 'foogallery_enqueue_preview_dependencies' );
473
				//add core foogallery files for preview
474
				foogallery_enqueue_core_gallery_template_style();
475
				foogallery_enqueue_core_gallery_template_script();
476
477
				//spectrum needed for the colorpicker field
478
				$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.js';
479
				wp_enqueue_script( 'foogallery-spectrum', $url, array('jquery'), FOOGALLERY_VERSION );
480
				$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.css';
481
				wp_enqueue_style( 'foogallery-spectrum', $url, array(), FOOGALLERY_VERSION );
482
483
				//include any admin js required for the templates
484
				foreach ( foogallery_gallery_templates() as $template ) {
485
					$admin_js = foo_safe_get( $template, 'admin_js' );
486
					if ( is_array( $admin_js ) ) {
487
						//dealing with an array of js files to include
488
						foreach( $admin_js as $admin_js_key => $admin_js_src ) {
489
							wp_enqueue_script( 'foogallery-gallery-admin-' . $template['slug'] . '-' . $admin_js_key, $admin_js_src, array('jquery', 'media-upload', 'jquery-ui-sortable'), FOOGALLERY_VERSION );
490
						}
491
					} else {
492
						//dealing with a single js file to include
493
						wp_enqueue_script( 'foogallery-gallery-admin-' . $template['slug'], $admin_js, array('jquery', 'media-upload', 'jquery-ui-sortable'), FOOGALLERY_VERSION );
494
					}
495
				}
496
			}
497
		}
498
499
		public function render_customcss_metabox( $post ) {
500
			$gallery = $this->get_gallery( $post );
501
			$custom_css = $gallery->custom_css;
502
			$example = '<code>#foogallery-gallery-' . $post->ID . ' { }</code>';
503
			?>
504
			<p>
505
				<?php printf( __( 'Add any custom CSS to target this specific gallery. For example %s', 'foogallery' ), $example ); ?>
506
			</p>
507
			<table id="table_styling" class="form-table">
508
				<tbody>
509
				<tr>
510
					<td>
511
						<textarea class="foogallery_metabox_custom_css" name="<?php echo FOOGALLERY_META_CUSTOM_CSS; ?>" type="text"><?php echo $custom_css; ?></textarea>
512
					</td>
513
				</tr>
514
				</tbody>
515
			</table>
516
		<?php
517
		}
518
519
		public function ajax_create_gallery_page() {
0 ignored issues
show
Coding Style introduced by
ajax_create_gallery_page uses the super-global variable $_POST which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
520
			if ( check_admin_referer( 'foogallery_create_gallery_page', 'foogallery_create_gallery_page_nonce' ) ) {
521
522
				$foogallery_id = $_POST['foogallery_id'];
523
524
				$foogallery = FooGallery::get_by_id( $foogallery_id );
525
526
				$post = array(
527
					'post_content' => $foogallery->shortcode(),
528
					'post_title'   => $foogallery->name,
529
					'post_status'  => 'draft',
530
					'post_type'    => 'page',
531
				);
532
533
				wp_insert_post( $post );
534
			}
535
			die();
536
		}
537
538
		public function ajax_clear_gallery_thumb_cache() {
0 ignored issues
show
Coding Style introduced by
ajax_clear_gallery_thumb_cache uses the super-global variable $_POST which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
539
			if ( check_admin_referer( 'foogallery_clear_gallery_thumb_cache', 'foogallery_clear_gallery_thumb_cache_nonce' ) ) {
540
541
				$foogallery_id = $_POST['foogallery_id'];
542
543
				$foogallery = FooGallery::get_by_id( $foogallery_id );
544
545
				ob_start();
546
547
				//loop through all images, get the full sized file
548
				foreach ( $foogallery->attachments() as $attachment ) {
549
					$meta_data = wp_get_attachment_metadata( $attachment->ID );
550
551
					$file = $meta_data['file'];
552
553
					wpthumb_delete_cache_for_file( $file );
554
				}
555
556
				ob_end_clean();
557
558
				echo __( 'The thumbnail cache has been cleared!', 'foogallery' );
559
			}
560
561
			die();
562
		}
563
564
		public function ajax_gallery_preview() {
0 ignored issues
show
Coding Style introduced by
ajax_gallery_preview uses the super-global variable $_POST which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
565
			if ( check_admin_referer( 'foogallery_preview', 'foogallery_preview_nonce' ) ) {
566
567
				$foogallery_id = $_POST['foogallery_id'];
568
569
				$template = $_POST['foogallery_template'];
570
				$args = array(
571
					'template' => $template,
572
					'attachment_ids' => $_POST['foogallery_attachments']
573
				);
574
575
				$args = apply_filters( 'foogallery_preview_arguments-' . $template, $args, $_POST );
576
577
				foogallery_render_gallery( $foogallery_id, $args );
578
			}
579
580
			die();
581
		}
582
	}
583
}
584