Issues (234)

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/assets.php (4 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
 * Front End Assets
4
 *
5
 * @package SimpleCalendar;
6
 */
7
namespace SimpleCalendar;
8
9
use SimpleCalendar\Abstracts\Calendar_View;
10
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
/**
16
 * Front end scripts and styles.
17
 *
18
 * Loads scripts and styles based on the requested calendar view.
19
 *
20
 * @since 3.0.0
21
 */
22
class Assets {
23
24
	/**
25
	 * Load minified assets.
26
	 *
27
	 * @access private
28
	 * @var string
29
	 */
30
	private $min = '.min';
31
32
	/**
33
	 * Scripts.
34
	 *
35
	 * @access private
36
	 * @var array
37
	 */
38
	private $scripts = array();
39
40
	/**
41
	 * Styles.
42
	 *
43
	 * @access private
44
	 * @var array
45
	 */
46
	private $styles = array();
47
48
	/**
49
	 * Disable styles.
50
	 *
51
	 * @access public
52
	 * @var bool
53
	 */
54
	public $disable_styles = false;
55
56
	/**
57
	 * Hook in tabs.
58
	 *
59
	 * @since 3.0.0
60
	 */
61
	public function __construct() {
62
63
		$this->min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG == true ) ? '' : '.min';
64
65
		$settings = get_option( 'simple-calendar_settings_advanced' );
66
67
		if ( isset( $settings['assets']['disable_css'] ) ) {
68
			$this->disable_styles = 'yes' == $settings['assets']['disable_css'] ? true : false;
69
		}
70
71
		add_action( 'init', array( $this, 'register' ), 20 );
72
		add_action( 'init', array( $this, 'enqueue' ), 40 );
73
	}
74
75
	/**
76
	 * Register scripts and styles.
77
	 *
78
	 * @since 3.0.0
79
	 */
80
	public function register() {
81
		do_action( 'simcal_register_assets', $this->min );
82
	}
83
84
	/**
85
	 * Enqueue scripts and styles.
86
	 *
87
	 * @since 3.0.0
88
	 */
89
	public function enqueue() {
90
91
		add_action( 'wp_enqueue_scripts', array( $this, 'load' ), 10 );
92
93
		do_action( 'simcal_enqueue_assets', $this->min );
94
95
96
		$min = $this->min;
97
		// Improves compatibility with themes and plugins using Isotope and Masonry.
98
		add_action( 'wp_enqueue_scripts',
99
			function () use ( $min ) {
100
				if ( wp_script_is( 'simcal-qtip', 'enqueued' ) ) {
101
					wp_enqueue_script(
102
						'simplecalendar-imagesloaded',
103
						SIMPLE_CALENDAR_ASSETS . 'js/vendor/imagesloaded.pkgd' . $min . '.js',
104
						array( 'simcal-qtip' ),
105
						SIMPLE_CALENDAR_VERSION,
106
						true
107
					);
108
				}
109
			}, 1000 );
110
	}
111
112
	/**
113
	 * Load scripts and styles.
114
	 *
115
	 * @since 3.0.0
116
	 */
117
	public function load() {
118
119
		$types = simcal_get_calendar_types();
120
121
		foreach ( $types as $calendar => $views ) {
122
			foreach( $views as $key => $view ) {
123
124
				$view = simcal_get_calendar_view( 0, $calendar . '-' . $view );
125
126
				$scripts[] = $view->scripts( $this->min );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$scripts was never initialized. Although not strictly required by PHP, it is generally a good practice to add $scripts = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
127
				$styles[] = $view->styles( $this->min );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$styles was never initialized. Although not strictly required by PHP, it is generally a good practice to add $styles = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
128
			}
129
		}
130
131
		$this->get_widgets_assets();
132
		$this->scripts = apply_filters( 'simcal_front_end_scripts', $scripts, $this->min );
0 ignored issues
show
The variable $scripts does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
133
		// First check if there is a multi-dimensional array of scripts
134
		if ( isset( $this->scripts[0] ) ) {
135
			foreach ( $this->scripts as $script ) {
136
				$this->load_scripts ( $script );
137
			}
138
		} else {
139
			$this->load_scripts( $this->scripts );
140
		}
141
		$this->styles = apply_filters( 'simcal_front_end_styles', $styles, $this->min );
0 ignored issues
show
The variable $styles does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
142
		// First check if there is a multi-dimensional array of styles
143
		if ( isset( $this->styles[0] ) ) {
144
			foreach( $this->styles as $style ) {
145
				$this->load_styles( $style );
146
			}
147
		} else {
148
			$this->load_styles( $this->styles );
149
		}
150
	}
151
152
	/**
153
	 * Get widgets assets.
154
	 *
155
	 * @since 3.0.0
156
	 */
157
	public function get_widgets_assets() {
158
159
		$widgets = get_option( 'widget_gce_widget' );
160
161
		if ( ! empty( $widgets ) && is_array( $widgets ) ) {
162
163
			foreach ( $widgets as $settings ) {
164
165
				if ( ! empty( $settings ) && is_array( $settings ) ) {
166
167
					if ( isset( $settings['calendar_id'] ) ) {
168
169
						$view = simcal_get_calendar_view( absint( $settings['calendar_id'] ) );
170
171
						if ( $view instanceof Calendar_View ) {
172
							add_filter( 'simcal_front_end_scripts', function ( $scripts, $min ) use ( $view ) {
173
								return array_merge( $scripts, $view->scripts( $min ) );
174
							}, 100, 2 );
175
							add_filter( 'simcal_front_end_styles', function ( $styles, $min ) use ( $view ) {
176
								return array_merge( $styles, $view->styles( $min ) );
177
							}, 100, 2 );
178
						}
179
180
					}
181
182
				}
183
			}
184
185
		}
186
	}
187
188
	/**
189
	 * Scripts.
190
	 *
191
	 * @since 3.0.0
192
	 *
193
	 * @param array $scripts
194
	 */
195
	public function load_scripts( $scripts ) {
196
197
		// Only load if not disabled in the settings
198
		if ( ! empty( $scripts ) && is_array( $scripts ) ) {
199
200
			foreach ( $scripts as $script => $v ) {
201
202
				/** Plugin compatibility fixes */
203
204
				// Dequeue moment.js if detected from WP Simple Pay Pro.
205
				if ( ( wp_script_is( 'stripe-checkout-pro-moment', 'enqueued' ) ) && $script == 'simcal-fullcal-moment' ) {
206
					continue;
207
				}
208
209
				if ( ! empty( $v['src'] ) ) {
210
211
					// Enqueued individually so we can dequeue if already enqueued by another plugin.
212
					// TODO Rework dependencies part (or remove completely).
213
214
					$src        = esc_url( $v['src'] );
215
					$in_footer  = isset( $v['in_footer'] )   ? $v['in_footer']  : false;
216
217
					wp_enqueue_script( $script, $src, array(), SIMPLE_CALENDAR_VERSION, $in_footer );
218
219
					if ( ! empty( $v['localize'] ) && is_array( $v['localize'] ) ) {
220
						foreach ( $v['localize'] as $object => $l10n ) {
221
							wp_localize_script( $script, $object, $l10n );
222
						}
223
					}
224
225
				} elseif ( is_string( $v ) && ! empty( $v ) ) {
226
227
					wp_enqueue_script( $v );
228
				}
229
			}
230
231
		}
232
	}
233
234
	/**
235
	 * Styles.
236
	 *
237
	 * @since 3.0.0
238
	 *
239
	 * @param array $styles
240
	 */
241
	public function load_styles( $styles ) {
242
243
		// Only load if not disabled in the settings
244
		if ( ! empty( $styles ) && is_array( $styles ) && false === $this->disable_styles ) {
245
246
			foreach ( $styles as $style => $v ) {
247
248
				if ( ! empty( $v['src'] ) ) {
249
250
					// Enqueued individually so we can dequeue if already enqueued by another plugin.
251
					// TODO Rework dependencies part (or remove completely).
252
253
					$src    = esc_url( $v['src'] );
254
					$media  = isset( $v['media'] )  ? $v['media']   : 'all';
255
256
					wp_enqueue_style( $style, $src, array(), SIMPLE_CALENDAR_VERSION, $media );
257
258
				} elseif ( is_string( $v ) && ! empty( $v ) ) {
259
260
					wp_enqueue_style( $v );
261
				}
262
263
			}
264
265
		}
266
	}
267
}
268