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... ( cd983d...5984e4 )
by Brad
02:39
created

FooGallery_Admin_Gallery_MetaBoxes::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 25
rs 8.8571
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
				update_post_meta( $post_id, FOOGALLERY_META_SETTINGS_VERSION, FOOGALLERY_SETTINGS_VERSION );
201
202
				do_action( 'foogallery_after_save_gallery', $post_id, $_POST );
203
			}
204
		}
205
206
		public function attach_gallery_to_post( $post_id, $post ) {
207
208
			// check autosave
209
			if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
210
				return $post_id;
211
			}
212
213
			//only do this check for a page or post
214
			if ( 'post' == $post->post_type ||
215
				'page' == $post->post_type ) {
216
217
                do_action( 'foogallery_start_attach_gallery_to_post', $post_id );
218
219
				//Clear any foogallery usages that the post might have
220
				delete_post_meta( $post_id, FOOGALLERY_META_POST_USAGE );
221
222
				//get all foogallery shortcodes that are on the page/post
223
				$gallery_shortcodes = foogallery_extract_gallery_shortcodes( $post->post_content );
224
225
                if ( is_array( $gallery_shortcodes ) && count( $gallery_shortcodes ) > 0 ) {
226
227
                    foreach ( $gallery_shortcodes as $id => $shortcode ) {
228
                        //if the content contains the foogallery shortcode then add a custom field
229
                        add_post_meta( $post_id, FOOGALLERY_META_POST_USAGE, $id, false );
230
231
                        do_action( 'foogallery_attach_gallery_to_post', $post_id, $id );
232
                    }
233
                }
234
			}
235
		}
236
237
		public function render_gallery_media_metabox( $post ) {
238
			$gallery = $this->get_gallery( $post );
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-container=".foogallery-items-view-manage" class="current1"><?php _e('Manage Items', 'foogallery'); ?></a>
246
					<a href="#preview" data-container=".foogallery-items-view-preview" class="current"><?php _e('Gallery Preview', 'foogallery'); ?></a>
247
				</div>
248
				<span id="foogallery_preview_spinner" class="spinner"></span>
249
			</div>
250
251
			<div class="foogallery-items-view foogallery-items-view-manage hidden">
252
				<input type="hidden" name="<?php echo FOOGALLERY_CPT_GALLERY; ?>_nonce"
253
					   id="<?php echo FOOGALLERY_CPT_GALLERY; ?>_nonce"
254
					   value="<?php echo wp_create_nonce( plugin_basename( FOOGALLERY_FILE ) ); ?>"/>
255
				<input type="hidden" name='foogallery_attachments' id="foogallery_attachments"
256
					   value="<?php echo $gallery->attachment_id_csv(); ?>"/>
257
				<div>
258
					<ul class="foogallery-attachments-list">
259
					<?php
260
					if ( $gallery->has_attachments() ) {
261
						foreach ( $gallery->attachments() as $attachment ) {
262
							$this->render_gallery_item( $attachment );
263
						}
264
					} ?>
265
						<li class="add-attachment">
266
							<a href="#" data-uploader-title="<?php _e( 'Add Media To Gallery', 'foogallery' ); ?>"
267
							   data-uploader-button-text="<?php _e( 'Add Media', 'foogallery' ); ?>"
268
							   data-post-id="<?php echo $post->ID; ?>" class="upload_image_button"
269
							   title="<?php _e( 'Add Media To Gallery', 'foogallery' ); ?>">
270
								<div class="dashicons dashicons-format-gallery"></div>
271
								<span><?php _e( 'Add Media', 'foogallery' ); ?></span>
272
							</a>
273
						</li>
274
					</ul>
275
					<div style="clear: both;"></div>
276
				</div>
277
				<textarea style="display: none" id="foogallery-attachment-template">
278
					<?php $this->render_gallery_item(); ?>
279
				</textarea>
280
			</div>
281
			<div class="foogallery-items-view foogallery-items-view-preview">
282
				<div class="foogallery_preview_container">
283
				<?php
284
				if ( $gallery->has_attachments() ) {
285
					foogallery_render_gallery( $gallery->ID );
286
				}
287
				?>
288
				</div>
289
				<?php wp_nonce_field( 'foogallery_preview', 'foogallery_preview', false ); ?>
290
			</div>
291
		<?php
292
293
		}
294
295
		public function render_gallery_item( $attachment_post = false ) {
296
			if ( $attachment_post != false ) {
297
				$attachment_id = $attachment_post->ID;
298
				$attachment = wp_get_attachment_image_src( $attachment_id );
299
			} else {
300
				$attachment_id = '';
301
				$attachment = '';
302
			}
303
			$data_attribute = empty($attachment_id) ? '' : "data-attachment-id=\"{$attachment_id}\"";
304
			$img_tag        = empty($attachment) ? '<img width="150" height="150" />' : "<img width=\"150\" height=\"150\" src=\"{$attachment[0]}\" />";
305
			?>
306
			<li class="attachment details" <?php echo $data_attribute; ?>>
307
				<div class="attachment-preview type-image">
308
					<div class="thumbnail">
309
						<div class="centered">
310
							<?php echo $img_tag; ?>
311
						</div>
312
					</div>
313
					<a class="info" href="#" title="<?php _e( 'Edit Info', 'foogallery' ); ?>">
314
						<span class="dashicons dashicons-info"></span>
315
					</a>
316
					<a class="remove" href="#" title="<?php _e( 'Remove from gallery', 'foogallery' ); ?>">
317
						<span class="dashicons dashicons-dismiss"></span>
318
					</a>
319
				</div>
320
				<!--				<input type="text" value="" class="describe" data-setting="caption" placeholder="Caption this image…" />-->
321
			</li>
322
		<?php
323
		}
324
325
		public function render_gallery_settings_metabox( $post ) {
326
            $gallery = FooGallery::get( $post );
327
328
            $settings = new FooGallery_Admin_Gallery_MetaBox_Settings_Helper( $gallery );
329
330
            $settings->render_hidden_gallery_template_selector();
331
332
            $settings->render_gallery_settings();
333
		}
334
335
		public function render_gallery_shortcode_metabox( $post ) {
336
			$gallery = $this->get_gallery( $post );
337
			$shortcode = $gallery->shortcode();
338
			?>
339
			<p class="foogallery-shortcode">
340
				<input type="text" id="foogallery-copy-shortcode" size="<?php echo strlen( $shortcode ) + 2; ?>" value="<?php echo htmlspecialchars( $shortcode ); ?>" readonly="readonly" />
341
			</p>
342
			<p>
343
				<?php _e( 'Paste the above shortcode into a post or page to show the gallery.', 'foogallery' ); ?>
344
			</p>
345
			<script>
346
				jQuery(function($) {
347
					var shortcodeInput = document.querySelector('#foogallery-copy-shortcode');
348
					shortcodeInput.addEventListener('click', function () {
349
						try {
350
							// select the contents
351
							shortcodeInput.select();
352
							//copy the selection
353
							document.execCommand('copy');
354
							//show the copied message
355
							$('.foogallery-shortcode-message').remove();
356
							$(shortcodeInput).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>');
357
						} catch(err) {
358
							console.log('Oops, unable to copy!');
359
						}
360
					}, false);
361
				});
362
			</script>
363
			<?php
364
		}
365
366
		public function render_gallery_usage_metabox( $post ) {
367
			$gallery = $this->get_gallery( $post );
368
			$posts = $gallery->find_usages();
369
			if ( $posts && count( $posts ) > 0 ) { ?>
370
				<p>
371
					<?php _e( 'This gallery is used on the following posts or pages:', 'foogallery' ); ?>
372
				</p>
373
				<ul class="ul-disc">
374
				<?php foreach ( $posts as $post ) {
375
					$url = get_permalink( $post->ID );
376
					echo '<li>' . $post->post_title . '&nbsp;';
377
					edit_post_link( __( 'Edit', 'foogallery' ), '<span class="edit">', ' | </span>', $post->ID );
378
					echo '<span class="view"><a href="' . esc_url( $url ) . '" target="_blank">' . __( 'View', 'foogallery' ) . '</a></li>';
379
				} ?>
380
				</ul>
381
			<?php } else { ?>
382
				<p>
383
					<?php _e( 'This gallery is not used on any pages or pages yet. Quickly create a page:', 'foogallery' ); ?>
384
				</p>
385
				<div class="foogallery_metabox_actions">
386
					<button class="button button-primary button-large" id="foogallery_create_page"><?php _e( 'Create Gallery Page', 'foogallery' ); ?></button>
387
					<span id="foogallery_create_page_spinner" class="spinner"></span>
388
					<?php wp_nonce_field( 'foogallery_create_gallery_page', 'foogallery_create_gallery_page_nonce', false ); ?>
389
				</div>
390
				<p>
391
					<?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' ); ?>
392
				</p>
393
			<?php }
394
		}
395
396
		public function render_sorting_metabox( $post ) {
397
			$gallery = $this->get_gallery( $post );
398
			$sorting_options = foogallery_sorting_options();
399
			if ( empty( $gallery->sorting ) ) {
400
				$gallery->sorting = '';
401
			}
402
			?>
403
			<p>
404
				<?php _e('Change the way images are sorted within your gallery. By default, they are sorted in the order you see them.', 'foogallery'); ?>
405
			</p>
406
			<?php
407
			foreach ( $sorting_options as $sorting_key => $sorting_label ) { ?>
408
				<p>
409
				<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; ?>" />
410
				<label for="FooGallerySettings_GallerySort_<?php echo $sorting_key; ?>"><?php echo $sorting_label; ?></label>
411
				</p><?php
412
			} ?>
413
			<p class="foogallery-help">
414
				<?php _e('PLEASE NOTE : sorting randomly will force HTML Caching for the gallery to be disabled.', 'foogallery'); ?>
415
			</p>
416
			<?php
417
		}
418
419
		public function render_retina_metabox( $post ) {
420
			$gallery = $this->get_gallery( $post );
421
			$retina_options = foogallery_retina_options();
422
			if ( empty( $gallery->retina ) ) {
423
				$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...
424
			}
425
			?>
426
			<p>
427
				<?php _e('Add retina support to this gallery by choosing the different pixel densities you want to enable.', 'foogallery'); ?>
428
			</p>
429
			<?php
430
			foreach ( $retina_options as $retina_key => $retina_label ) {
431
				$checked = array_key_exists( $retina_key, $gallery->retina ) ? ('true' === $gallery->retina[$retina_key]) : false;
432
				?>
433
				<p>
434
				<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; ?>]" />
435
				<label for="FooGallerySettings_Retina_<?php echo $retina_key; ?>"><?php echo $retina_label; ?></label>
436
				</p><?php
437
			} ?>
438
			<p class="foogallery-help">
439
				<?php _e('PLEASE NOTE : thumbnails will be generated for each of the pixel densities chosen, which will increase your website\'s storage space!', 'foogallery'); ?>
440
			</p>
441
			<?php
442
		}
443
444
		public function render_thumb_settings_metabox( $post ) {
445
			$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...
446
			$force_use_original_thumbs = get_post_meta( $post->ID, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS, true );
447
			$checked = 'true' === $force_use_original_thumbs; ?>
448
			<p>
449
				<?php _e( 'Clear all the previously cached thumbnails that have been generated for this gallery.', 'foogallery' ); ?>
450
			</p>
451
			<div class="foogallery_metabox_actions">
452
				<button class="button button-primary button-large" id="foogallery_clear_thumb_cache"><?php _e( 'Clear Thumbnail Cache', 'foogallery' ); ?></button>
453
				<span id="foogallery_clear_thumb_cache_spinner" class="spinner"></span>
454
				<?php wp_nonce_field( 'foogallery_clear_gallery_thumb_cache', 'foogallery_clear_gallery_thumb_cache_nonce', false ); ?>
455
			</div>
456
			<p>
457
				<input type="checkbox" value="true" <?php checked( $checked ); ?> id="FooGallerySettings_ForceOriginalThumbs" name="<?php echo FOOGALLERY_META_FORCE_ORIGINAL_THUMBS; ?>" />
458
				<label for="FooGallerySettings_ForceOriginalThumbs"><?php _e('Force Original Thumbs', 'foogallery'); ?></label>
459
			</p>
460
			<?php
461
		}
462
463
		public function include_required_scripts() {
464
			$screen_id = foo_current_screen_id();
465
466
			//only include scripts if we on the foogallery add/edit page
467
			if ( FOOGALLERY_CPT_GALLERY === $screen_id ||
468
			     'edit-' . FOOGALLERY_CPT_GALLERY === $screen_id ) {
469
470
				//enqueue any dependencies from extensions or gallery templates
471
				do_action( 'foogallery_enqueue_preview_dependencies' );
472
				//add core foogallery files for preview
473
				foogallery_enqueue_core_gallery_template_style();
474
				foogallery_enqueue_core_gallery_template_script();
475
476
				//spectrum needed for the colorpicker field
477
				$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.js';
478
				wp_enqueue_script( 'foogallery-spectrum', $url, array('jquery'), FOOGALLERY_VERSION );
479
				$url = FOOGALLERY_URL . 'lib/spectrum/spectrum.css';
480
				wp_enqueue_style( 'foogallery-spectrum', $url, array(), FOOGALLERY_VERSION );
481
482
				//include any admin js required for the templates
483
				foreach ( foogallery_gallery_templates() as $template ) {
484
					$admin_js = foo_safe_get( $template, 'admin_js' );
485
					if ( is_array( $admin_js ) ) {
486
						//dealing with an array of js files to include
487
						foreach( $admin_js as $admin_js_key => $admin_js_src ) {
488
							wp_enqueue_script( 'foogallery-gallery-admin-' . $template['slug'] . '-' . $admin_js_key, $admin_js_src, array('jquery', 'media-upload', 'jquery-ui-sortable'), FOOGALLERY_VERSION );
489
						}
490
					} else {
491
						//dealing with a single js file to include
492
						wp_enqueue_script( 'foogallery-gallery-admin-' . $template['slug'], $admin_js, array('jquery', 'media-upload', 'jquery-ui-sortable'), FOOGALLERY_VERSION );
493
					}
494
				}
495
			}
496
		}
497
498
		public function render_customcss_metabox( $post ) {
499
			$gallery = $this->get_gallery( $post );
500
			$custom_css = $gallery->custom_css;
501
			$example = '<code>#foogallery-gallery-' . $post->ID . ' { }</code>';
502
			?>
503
			<p>
504
				<?php printf( __( 'Add any custom CSS to target this specific gallery. For example %s', 'foogallery' ), $example ); ?>
505
			</p>
506
			<table id="table_styling" class="form-table">
507
				<tbody>
508
				<tr>
509
					<td>
510
						<textarea class="foogallery_metabox_custom_css" name="<?php echo FOOGALLERY_META_CUSTOM_CSS; ?>" type="text"><?php echo $custom_css; ?></textarea>
511
					</td>
512
				</tr>
513
				</tbody>
514
			</table>
515
		<?php
516
		}
517
518
		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...
519
			if ( check_admin_referer( 'foogallery_create_gallery_page', 'foogallery_create_gallery_page_nonce' ) ) {
520
521
				$foogallery_id = $_POST['foogallery_id'];
522
523
				$foogallery = FooGallery::get_by_id( $foogallery_id );
524
525
				$post = array(
526
					'post_content' => $foogallery->shortcode(),
527
					'post_title'   => $foogallery->name,
528
					'post_status'  => 'draft',
529
					'post_type'    => 'page',
530
				);
531
532
				wp_insert_post( $post );
533
			}
534
			die();
535
		}
536
537
		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...
538
			if ( check_admin_referer( 'foogallery_clear_gallery_thumb_cache', 'foogallery_clear_gallery_thumb_cache_nonce' ) ) {
539
540
				$foogallery_id = $_POST['foogallery_id'];
541
542
				$foogallery = FooGallery::get_by_id( $foogallery_id );
543
544
				ob_start();
545
546
				//loop through all images, get the full sized file
547
				foreach ( $foogallery->attachments() as $attachment ) {
548
					$meta_data = wp_get_attachment_metadata( $attachment->ID );
549
550
					$file = $meta_data['file'];
551
552
					wpthumb_delete_cache_for_file( $file );
553
				}
554
555
				ob_end_clean();
556
557
				echo __( 'The thumbnail cache has been cleared!', 'foogallery' );
558
			}
559
560
			die();
561
		}
562
563
		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...
564
			if ( check_admin_referer( 'foogallery_preview', 'foogallery_preview_nonce' ) ) {
565
566
				$foogallery_id = $_POST['foogallery_id'];
567
568
				$template = $_POST['foogallery_template'];
569
				$args = array(
570
					'template' => $template,
571
					'attachment_ids' => $_POST['foogallery_attachments']
572
				);
573
574
				$args = apply_filters( 'foogallery_preview_arguments-' . $template, $args, $_POST );
575
576
				foogallery_render_gallery( $foogallery_id, $args );
577
			}
578
579
			die();
580
		}
581
	}
582
}
583