Issues (896)

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.

widget-woothemes-sensei-lesson-component.php (7 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
3
4
/**
5
 * Sensei Lesson Component Widget
6
 *
7
 * A WooThemes standardized component widget.
8
 *
9
 * @package Views
10
 * @subpackage Widgets
11
 * @author Automattic
12
 *
13
 * @since 1.0.0
14
 */
15
class WooThemes_Sensei_Lesson_Component_Widget extends WP_Widget {
16
	protected $woo_widget_cssclass;
17
	protected $woo_widget_description;
18
	protected $woo_widget_idbase;
19
	protected $woo_widget_title;
20
21
	/**
22
	 * Constructor function.
23
	 * @since  1.0.0
24
	 * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
25
	 */
26
	public function __construct() {
27
		/* Widget variable settings. */
28
		$this->woo_widget_cssclass = 'widget_sensei_lesson_component';
29
		$this->woo_widget_description = __( 'This widget will output a list of the latest Lessons.', 'woothemes-sensei' );
30
		$this->woo_widget_idbase = 'sensei_lesson_component';
31
		$this->woo_widget_title = __( 'Sensei - Lesson Component', 'woothemes-sensei' );
32
33
		$this->woo_widget_componentslist = array(
34
												'newlessons' => __( 'New Lessons', 'woothemes-sensei' ),
35
												);
36
37
		/* Widget settings. */
38
		$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
39
40
		/* Widget control settings. */
41
		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase );
42
43
		/* Create the widget. */
44
		parent::__construct( $this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops );
45
	} // End __construct()
46
47
	/**
48
	 * Display the widget on the frontend.
49
	 * @since  1.0.0
50
	 * @param  array $args     Widget arguments.
51
	 * @param  array $instance Widget settings for this instance.
52
	 * @return void
53
	 */
54
	public function widget( $args, $instance ) {
55
56
        $before_widget = $args[ 'before_widget' ];
57
        $before_title  = $args[ 'before_title' ];
58
        $after_title   = $args[ 'after_title' ];
59
        $after_widget  = $args[ 'after_widget' ];
60
61
		if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) ) && ( 'activecourses' == $instance['component'] || 'completedcourses' == $instance['component'] ) && !is_user_logged_in() ) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
62
			// No Output
63
		} else {
64
			/* Our variables from the widget settings. */
65
			$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base );
66
67
			/* Before widget (defined by themes). */
68
			echo $before_widget;
69
70
			/* Display the widget title if one was input (before and after defined by themes). */
71
			if ( $title ) { echo $before_title . $title . $after_title; }
72
73
			/* Widget content. */
74
			// Add actions for plugins/themes to hook onto.
75
			do_action( $this->woo_widget_cssclass . '_top' );
76
77
			if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) ) ) {
78
				$this->load_component( $instance );
79
			}
80
81
			// Add actions for plugins/themes to hook onto.
82
			do_action( $this->woo_widget_cssclass . '_bottom' );
83
84
			/* After widget (defined by themes). */
85
			echo $after_widget;
86
		} // End If Statement
87
88
	} // End widget()
89
90
	/**
91
	 * Method to update the settings from the form() method.
92
	 * @since  1.0.0
93
	 * @param  array $new_instance New settings.
94
	 * @param  array $old_instance Previous settings.
95
	 * @return array               Updated settings.
96
	 */
97 View Code Duplication
	public function update ( $new_instance, $old_instance ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
		$instance = $old_instance;
99
100
		/* Strip tags for title and name to remove HTML (important for text inputs). */
101
		$instance['title'] = strip_tags( $new_instance['title'] );
102
103
		/* The select box is returning a text value, so we escape it. */
104
		$instance['component'] = esc_attr( $new_instance['component'] );
105
106
		/* The select box is returning a text value, so we escape it. */
107
		$instance['limit'] = esc_attr( $new_instance['limit'] );
108
109
110
		return $instance;
111
	} // End update()
112
113
	/**
114
	 * The form on the widget control in the widget administration area.
115
	 * Make use of the get_field_id() and get_field_name() function when creating your form elements. This handles the confusing stuff.
116
	 * @since  1.0.0
117
	 * @param  array $instance The settings for this instance.
118
	 * @return void
119
	 */
120 View Code Duplication
    public function form( $instance ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
122
		/* Set up some default widget settings. */
123
		/* Make sure all keys are added here, even with empty string values. */
124
		$defaults = array(
125
						'title' => '',
126
						'component' => '',
127
						'limit' => 3
128
					);
129
130
		$instance = wp_parse_args( (array) $instance, $defaults );
131
?>
132
		<!-- Widget Title: Text Input -->
133
		<p>
134
			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title (optional):', 'woothemes-sensei' ); ?></label>
135
			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"  value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" />
136
		</p>
137
		<!-- Widget Component: Select Input -->
138
		<p>
139
			<label for="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>"><?php _e( 'Component:', 'woothemes-sensei' ); ?></label>
140
			<select name="<?php echo esc_attr( $this->get_field_name( 'component' ) ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>">
141
			<?php foreach ( $this->woo_widget_componentslist as $k => $v ) { ?>
142
				<option value="<?php echo esc_attr( $k ); ?>"<?php selected( $instance['component'], $k ); ?>><?php echo $v; ?></option>
143
			<?php } ?>
144
			</select>
145
		</p>
146
		<!-- Widget Limit: Text Input -->
147
		<p>
148
			<label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Number of Lessons (optional):', 'woothemes-sensei' ); ?></label>
149
			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>"  value="<?php echo esc_attr( $instance['limit'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" />
150
		</p>
151
152
<?php
153
	} // End form()
154
155
	/**
156
	 * Load the desired component, if a method is available for it.
157
	 * @param  string $instance The component to potentially be loaded.
158
	 * @since  5.0.8
159
	 * @return void
160
	 */
161
	protected function load_component ( $instance ) {
162
163
		global  $current_user;
164
165
		/*
166
		newlessons
167
		*/
168
		$posts_array = array();
0 ignored issues
show
$posts_array 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...
169
170
		$post_args = array(	'post_type' 		=> 'lesson',
171
							'posts_per_page' 		=> intval( $instance[ 'limit' ] ),
172
							'orderby'         	=> 'menu_order date',
173
    						'order'           	=> 'DESC',
174
    						'post_status'       => 'publish',
175
							'suppress_filters' 	=> 0
176
							);
177
		$posts_array = get_posts( $post_args );
178
179
		if ( count( $posts_array ) > 0 ) { ?>
180
			<ul>
181
			<?php foreach ($posts_array as $post_item){
182
		    	$post_id = absint( $post_item->ID );
183
		    	$post_title = $post_item->post_title;
184
		    	$user_info = get_userdata( absint( $post_item->post_author ) );
185
		    	$author_link = get_author_posts_url( absint( $post_item->post_author ) );
186
		    	$author_display_name = $user_info->display_name;
187
		    	$author_id = $post_item->post_author;
0 ignored issues
show
$author_id 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...
188
		    	$lesson_course_id = get_post_meta( $post_id, '_lesson_course', true );
189
		    ?>
190
		    	<li class="fix">
191
		    		<?php do_action( 'sensei_lesson_image', $post_id, '100', '100', false, true ); ?>
192
		    		<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a>
193
		    		<br />
194
		    		<?php if ( isset( Sensei()->settings->settings[ 'lesson_author' ] ) && ( Sensei()->settings->settings[ 'lesson_author' ] ) ) { ?>
195
    					<span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo esc_url( $author_link ); ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span>
196
    					<br />
197
    				<?php } // End If Statement ?>
198
    				<?php if ( 0 < $lesson_course_id ) { ?>
199
                        <span class="lesson-course"><?php echo ' ' . sprintf( __( 'Part of: %s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '" title="' . esc_attr( __( 'View course', 'woothemes-sensei' ) ) . '"><em>' . get_the_title( $lesson_course_id ) . '</em></a>' ); ?></span>
200
                    <?php } ?>
201
    				<br />
202
		    	</li>
203
		    <?php } // End For Loop ?>
204
		    <?php echo '<li class="my-account fix"><a class="button" href="'. esc_url( get_post_type_archive_link( 'lesson' ) ) .'">'.__('More Lessons', 'woothemes-sensei').'</a></li>'; ?>
205
		</ul>
206
		<?php } // End If Statement
207
	} // End load_component()
208
} // End Class