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.

Issues (1881)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

includes/admin/class-gallery-metaboxes.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
609
610
					$foogallery_gallery_preview = true;
611
612
					$args = array(
613
						'template'       => $template,
614
						'attachment_ids' => $_POST['foogallery_attachments'],
615
                        'preview'        => true
616
					);
617
618
					$args = apply_filters( 'foogallery_preview_arguments', $args, $_POST, $template );
619
					$args = apply_filters( 'foogallery_preview_arguments-' . $template, $args, $_POST );
620
621
					foogallery_render_gallery( $foogallery_id, $args );
622
623
					$foogallery_gallery_preview = false;
624
625
				} else {
626
					echo '<div style="padding:20px 50px 50px 50px; text-align: center">';
627
					echo '<h3>' . __( 'Preview not available!', 'foogallery' ) . '</h3>';
628
					echo __('Sorry, but this gallery template does not support live previews. Please update the gallery in order to see what the gallery will look like.', 'foogallery' );
629
					echo '</div>';
630
				}
631
			}
632
633
			die();
634
		}
635
636
		/**
637
		 * Handle gallery previews where there are no attachments
638
		 *
639
		 * @param $foogallery FooGallery
640
		 */
641
		public function preview_no_attachments( $foogallery ) {
0 ignored issues
show
The parameter $foogallery is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
642
			global $foogallery_gallery_preview;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
643
644
			if ( isset( $foogallery_gallery_preview ) && true === $foogallery_gallery_preview ) {
645
				$this->render_empty_gallery_preview();
646
			}
647
		}
648
	}
649
}
650