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/class-foogallery.php (6 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
 * Class FooGallery
5
 *
6
 * An easy to use wrapper class for a FooGallery gallery post
7
 */
8
class FooGallery extends stdClass {
9
10
	/**
11
	 * private constructor
12
	 *
13
	 * @param null $post
14
	 */
15
	private function __construct( $post = null ) {
16
		$this->set_defaults();
17
18
		if ( $post !== null ) {
19
			$this->load( $post );
20
		}
21
	}
22
23
	/**
24
	 *  Sets the default when a new gallery is instantiated
25
	 */
26
	private function set_defaults() {
27
		$this->_post = null;
28
		$this->ID = 0;
29
		$this->attachment_ids = array();
30
		$this->_attachments = false;
31
		$this->datasource_name = foogallery_default_datasource();
32
		$this->_datasource = false;
33
		$this->settings = array();
34
		$this->sorting = '';
35
		$this->force_use_original_thumbs = false;
36
		$this->retina = array();
37
	}
38
39
	/**
40
	 * private gallery load function
41
	 * @param $post
42
	 */
43
	private function load( $post ) {
44
		$this->_post = $post;
45
		$this->ID = $post->ID;
46
		$this->slug = $post->post_name;
47
		$this->name = $post->post_title;
48
		$this->author = $post->post_author;
49
		$this->post_status = $post->post_status;
50
51
		$attachment_meta = get_post_meta( $post->ID, FOOGALLERY_META_ATTACHMENTS, true );
52
		$this->attachment_ids = is_array( $attachment_meta ) ? array_filter( $attachment_meta ) : array();
53
54
		$this->load_meta( $post->ID );
55
56
		do_action( 'foogallery_instance_after_load', $this, $post );
57
	}
58
59
	/**
60
	 * private meta data load function
61
	 * @param $post_id int
62
	 */
63
	private function load_meta( $post_id ) {
64
		$this->gallery_template = get_post_meta( $post_id, FOOGALLERY_META_TEMPLATE, true );
65
		$this->settings = $this->load_settings( $post_id );
66
		$this->custom_css = get_post_meta( $post_id, FOOGALLERY_META_CUSTOM_CSS, true );
67
		$this->sorting = get_post_meta( $post_id, FOOGALLERY_META_SORT, true );
68
		$this->datasource_name = get_post_meta( $post_id, FOOGALLERY_META_DATASOURCE, true );
69
		if ( empty( $this->datasource_name ) ) {
70
			$this->datasource_name = foogallery_default_datasource();
71
		}
72
        $this->retina = get_post_meta( $post_id, FOOGALLERY_META_RETINA, true );
73
		$this->force_use_original_thumbs = 'true' === get_post_meta( $post_id, FOOGALLERY_META_FORCE_ORIGINAL_THUMBS, true );
74
	}
75
76
	private function load_settings( $post_id ) {
77
		$settings = get_post_meta( $post_id, FOOGALLERY_META_SETTINGS, true );
78
79
		//the gallery is considered new if the template has not been set
80
		$is_new = empty( $this->gallery_template );
81
82
		//if we have no settings, and the gallery is not new, then allow for an upgrade
83
		if ( empty( $settings ) && !$is_new ) {
84
			$settings = apply_filters( 'foogallery_settings_upgrade', $settings, $this );
85
		}
86
87
		//if we still have no settings, then get default settings for the gallery template
88
        if ( empty( $settings ) && !$is_new ) {
89
		    $settings = foogallery_build_default_settings_for_gallery_template( $this->gallery_template );
90
91
            $settings = apply_filters('foogallery_default_settings-' . $this->gallery_template, $settings, $this);
92
        }
93
94
		return $settings;
95
	}
96
97
	/**
98
	 * private function to load a gallery by an id
99
	 * @param $post_id
100
	 */
101
	private function load_by_id( $post_id ) {
102
		$post = get_post( $post_id );
103
		if ( $post ) {
104
			$this->load( $post );
105
		}
106
	}
107
108
	/**
109
	 * private function to load a gallery by the slug.
110
	 * Will be used when loading gallery shortcodes
111
	 * @param $slug
112
	 */
113
	private function load_by_slug( $slug ) {
114
		if ( ! empty( $slug ) ) {
115
			$args = array(
116
				'name'        => $slug,
117
				'numberposts' => 1,
118
				'post_type'   => FOOGALLERY_CPT_GALLERY,
119
			);
120
121
			$galleries = get_posts( $args );
122
123
			if ( $galleries ) {
124
				$this->load( $galleries[0] );
125
			}
126
		}
127
	}
128
129
	/**
130
	 * Static function to build a dynamic gallery that does not exist in the database
131
	 * @param $template
132
	 * @param $attachment_ids
133
	 *
134
	 * @return FooGallery
135
	 */
136
	public static function dynamic( $template, $attachment_ids ) {
137
		$gallery = new self( null );
138
139
		$gallery->gallery_template = $template;
140
		$gallery->attachment_ids = $attachment_ids;
141
142
		//loads all meta data from the default gallery
143
		$default_gallery_id = foogallery_get_setting( 'default_gallery_settings' );
144
		if ( $default_gallery_id > 0 ) {
145
			$gallery->load_meta( $default_gallery_id );
146
		}
147
148
		return $gallery;
149
	}
150
151
	/**
152
	 * Static function to load a Gallery instance by passing in a post object
153
	 * @static
154
	 *
155
	 * @param $post
156
	 *
157
	 * @return FooGallery
158
	 */
159
	public static function get( $post ) {
160
		return new self( $post );
161
	}
162
163
	/**
164
	 * Static function to load a Gallery instance by post id
165
	 *
166
	 * @param $post_id
167
	 *
168
	 * @return FooGallery | boolean
169
	 */
170
	public static function get_by_id( $post_id ) {
171
		$gallery = new self();
172
		$gallery->load_by_id( $post_id );
173
		if ( ! $gallery->does_exist() ) {
174
			return false;
175
		}
176
		return $gallery;
177
	}
178
179
	/**
180
	 * Static function to load a gallery instance by passing in a gallery slug
181
	 *
182
	 * @param string $slug
183
	 *
184
	 * @return FooGallery | boolean
185
	 */
186
	public static function get_by_slug( $slug ) {
187
		$gallery = new self();
188
		$gallery->load_by_slug( $slug );
189
		if ( ! $gallery->does_exist() ) {
190
			return false;
191
		}
192
		return $gallery;
193
	}
194
195
	/**
196
	 * Get a setting using the current template and meta key
197
	 * @param $key
198
	 * @param $default
199
	 *
200
	 * @return mixed|null
201
	 */
202
	function get_setting( $key, $default ) {
203
		return $this->get_meta( "{$this->gallery_template}_$key", $default );
204
	}
205
206
	/**
207
	 * Get a meta value using a full key
208
	 * @param $key
209
	 * @param $default
210
	 *
211
	 * @return mixed|null
212
	 */
213
	function get_meta( $key, $default ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
214
		if ( ! is_array( $this->settings ) ) {
215
			return $default;
216
		}
217
218
		$value = array_key_exists( $key, $this->settings ) ? $this->settings[ $key ] : null;
219
220
		if ( $value === null ) {
221
			return $default;
222
		}
223
224
		return $value;
225
	}
226
227
	function is_checked( $key, $default = false ) {
228
		if ( ! is_array( $this->settings ) ) {
229
			return $default;
230
		}
231
232
		return array_key_exists( $key, $this->settings );
233
	}
234
235
	/**
236
	 * Returns the number of attachments in the current gallery
237
	 * @return int
238
	 */
239
	public function attachment_count() {
240
		return $this->datasource()->getCount();
241
	}
242
243
	/**
244
	 * Checks if the gallery has attachments
245
	 * @return bool
246
	 */
247
	public function has_attachments() {
248
		return $this->attachment_count() > 0;
249
	}
250
251
	/**
252
	 * Checks if the gallery exists
253
	 * @return bool
254
	 */
255
	public function does_exist() {
256
		return $this->ID > 0;
257
	}
258
259
	/**
260
	 * Returns true if the gallery is published
261
	 * @return bool
262
	 */
263
	public function is_published() {
264
		return $this->post_status === 'publish';
265
	}
266
267
	/**
268
	 * Returns true if the gallery is newly created and not yet saved
269
	 */
270
	public function is_new() {
271
		$template = get_post_meta( $this->ID, FOOGALLERY_META_TEMPLATE, true );
272
		return empty( $template );
273
	}
274
275
	/**
276
	 * Get a comma separated list of attachment ids
277
	 * @return string
278
	 */
279
	public function attachment_id_csv() {
280
		return $this->datasource()->getSerializedData();
281
	}
282
283
	/**
284
	 * Lazy load the attachments for the gallery
285
	 *
286
	 * @return array
287
	 */
288
	public function attachments() {
289
		//lazy load the attachments for performance
290
		if ( $this->_attachments === false ) {
291
			$this->_attachments = $this->datasource()->getAttachments();
292
		}
293
294
		return $this->_attachments;
295
	}
296
297
	/**
298
	 * @deprecated 1.3.0 This is now moved into the datasource implementation
299
	 *
300
	 * This forces the attachments to be fetched using the correct ordering.
301
	 * Some plugins / themes override this globally for some reason, so this is a preventative measure to ensure sorting is correct
302
	 * @param $query WP_Query
303
	 */
304
	public function force_gallery_ordering( $query ) {
0 ignored issues
show
The parameter $query 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...
305
		_deprecated_function( __FUNCTION__, '1.3.0' );
306
	}
307
308
	/**
309
	 * Output the shortcode for the gallery
310
	 *
311
	 * @return string
312
	 */
313
	public function shortcode() {
314
		return foogallery_build_gallery_shortcode( $this->ID );
315
	}
316
317
	/**
318
	 * @deprecated 1.3.0 This is now moved into the datasource implementation
319
	 *
320
	 * @return int|mixed|string
321
	 */
322
	public function find_featured_attachment_id() {
323
		_deprecated_function( __FUNCTION__, '1.3.0' );
324
325
		return 0;
326
	}
327
328
	/**
329
	 * Gets the featured image FooGalleryAttachment object. If no featured image is set, then get back the first image in the gallery
330
	 *
331
	 * @return bool|FooGalleryAttachment
332
	 */
333
	public function featured_attachment() {
334
		return $this->datasource()->getFeaturedAttachment();
335
	}
336
337
	/**
338
	 * @deprecated 1.3.0 This is now moved into the datasource implementation
339
	 *
340
	 * @param string $size
341
	 * @param bool   $icon
342
	 *
343
	 * @return bool
344
	 */
345
	public function featured_image_src( $size = 'thumbnail', $icon = false ) {
0 ignored issues
show
The parameter $size 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...
The parameter $icon 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...
346
		_deprecated_function( __FUNCTION__, '1.3.0' );
347
348
		return false;
349
	}
350
351
	/**
352
	 * @deprecated 1.3.0 This is now moved into the datasource implementation
353
	 *
354
	 * Get an HTML img element representing the featured image for the gallery
355
	 *
356
	 * @param string $size Optional, default is 'thumbnail'.
357
	 * @param bool $icon Optional, default is false. Whether it is an icon.
358
	 *
359
	 * @return string HTML img element or empty string on failure.
360
	 */
361
	public function featured_image_html( $size = 'thumbnail', $icon = false ) {
0 ignored issues
show
The parameter $size 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...
The parameter $icon 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...
362
		_deprecated_function( __FUNCTION__, '1.3.0' );
363
364
		return '';
365
	}
366
367
	public function image_count() {
368
		$no_images_text = foogallery_get_setting( 'language_images_count_none_text',   __( 'No images', 'foogallery' ) );
369
		$singular_text  = foogallery_get_setting( 'language_images_count_single_text', __( '1 image', 'foogallery' ) );
370
		$plural_text    = foogallery_get_setting( 'language_images_count_plural_text', __( '%s images', 'foogallery' ) );
371
372
		$count = $this->attachment_count();
373
374
		switch ( $count ) {
375
			case 0:
376
				$count_text = $no_images_text === false ? __( 'No images', 'foogallery' ) : $no_images_text;
377
				break;
378
			case 1:
379
				$count_text = $singular_text === false ? __( '1 image', 'foogallery' ) : $singular_text;
380
				break;
381
			default:
382
				$count_text = sprintf( $plural_text === false ?  __( '%s images', 'foogallery' ) : $plural_text, $count );
383
		}
384
385
		return esc_html( apply_filters( 'foogallery_image_count', $count_text, $this ) );
386
	}
387
388
	/**
389
	 * Returns a safe name for the gallery, in case there has been no title set
390
	 *
391
	 * @return string
392
	 */
393
	public function safe_name() {
394
		return empty( $this->name ) ?
395
				sprintf( __( '%s #%s', 'foogallery' ), foogallery_plugin_name(), $this->ID ) :
396
				$this->name;
397
	}
398
399
	public function find_usages() {
400
		return get_posts( array(
401
			'post_type'      => array( 'post', 'page', ),
402
			'post_status'    => array( 'draft', 'publish', ),
403
			'posts_per_page' => -1,
404
			'orderby'        => 'post_type',
405
			'meta_query'     => array(
406
				array(
407
					'key'     => FOOGALLERY_META_POST_USAGE,
408
					'value'   => $this->ID,
409
					'compare' => 'IN',
410
				),
411
			),
412
		) );
413
	}
414
415
	public function gallery_template_details() {
416
		if ( ! empty( $this->gallery_template ) ) {
417
418
			foreach ( foogallery_gallery_templates() as $template ) {
419
				if ( $this->gallery_template == $template['slug'] ) {
420
					return $template;
421
				}
422
			}
423
		}
424
425
		return false;
426
	}
427
428
	/**
429
	 * Returns the name of the gallery template
430
	 * @return string|void
431
	 */
432
	public function gallery_template_name() {
433
		$template = $this->gallery_template_details();
434
		if ( false !== $template ) {
435
			return $template['name'];
436
		}
437
		return __( 'Unknown', 'foogallery' );
438
	}
439
440
	public function gallery_template_has_field_of_type( $field_type ) {
441
		$gallery_template_details = $this->gallery_template_details();
442
443
		if ( false != $gallery_template_details ) {
444
			if ( array_key_exists( 'fields', $gallery_template_details ) ) {
445
				foreach ( $gallery_template_details['fields'] as $field ) {
446
					if ( $field_type == $field['type'] ) {
447
						return true;
448
					}
449
				}
450
			}
451
		}
452
		return false;
453
	}
454
455
	/**
456
	 * Loads default settings from another gallery if it is set on the settings page
457
	 */
458
	public function load_default_settings_if_new() {
459
		if ( $this->is_new() ) {
460
			$default_gallery_id = foogallery_get_setting( 'default_gallery_settings' );
461
			//loads all meta data from the default gallery
462
			$this->load_meta( $default_gallery_id );
463
		}
464
	}
465
466
	/**
467
	 * Returns the current gallery datasource object
468
	 *
469
	 * @returns IFooGalleryDatasource
470
	 */
471
	public function datasource() {
472
		//lazy load the datasource only when needed
473
		if ( $this->_datasource === false ) {
474
			$this->_datasource = foogallery_instantiate_datasource( $this->datasource_name );
475
			$this->_datasource->setGallery( $this );
476
		}
477
478
		return $this->_datasource;
479
	}
480
}
481