This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
2 | |||
3 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
||
4 | |||
5 | /** |
||
6 | * Global Sensei functions |
||
7 | */ |
||
8 | |||
9 | function is_sensei() { |
||
10 | global $post; |
||
11 | |||
12 | $is_sensei = false; |
||
13 | |||
14 | $post_types = array( 'lesson', 'course', 'quiz', 'question' ); |
||
15 | $taxonomies = array( 'course-category', 'quiz-type', 'question-type', 'lesson-tag' ); |
||
16 | |||
17 | if( is_post_type_archive( $post_types ) || is_singular( $post_types ) || is_tax( $taxonomies ) ) { |
||
18 | |||
19 | $is_sensei = true; |
||
20 | |||
21 | } |
||
22 | |||
23 | if( is_object( $post ) && ! is_wp_error( $post ) ) { |
||
24 | |||
25 | $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
||
26 | $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
||
27 | |||
28 | if( in_array( $post->ID, array( $course_page_id, $my_courses_page_id ) ) ) { |
||
29 | |||
30 | $is_sensei = true; |
||
31 | |||
32 | } |
||
33 | |||
34 | } |
||
35 | |||
36 | return apply_filters( 'is_sensei', $is_sensei, $post ); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Determine if the current user is and admin that |
||
41 | * can acess all of Sensei without restrictions |
||
42 | * |
||
43 | * @since 1.4.0 |
||
44 | * @return boolean |
||
45 | */ |
||
46 | function sensei_all_access() { |
||
47 | |||
48 | $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); |
||
49 | |||
50 | /** |
||
51 | * Filter sensei_all_access function result |
||
52 | * which determinse if the current user |
||
53 | * can access all of Sensei without restrictions |
||
54 | * |
||
55 | * @since 1.4.0 |
||
56 | * @param bool $access |
||
57 | */ |
||
58 | return apply_filters( 'sensei_all_access', $access ); |
||
59 | |||
60 | } // End sensei_all_access() |
||
61 | |||
62 | if ( ! function_exists( 'sensei_light_or_dark' ) ) { |
||
63 | |||
64 | /** |
||
65 | * Detect if we should use a light or dark colour on a background colour |
||
66 | * |
||
67 | * @access public |
||
68 | * @param mixed $color |
||
69 | * @param string $dark (default: '#000000') |
||
70 | * @param string $light (default: '#FFFFFF') |
||
71 | * @return string |
||
72 | */ |
||
73 | function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
||
74 | |||
75 | $hex = str_replace( '#', '', $color ); |
||
76 | |||
77 | $c_r = hexdec( substr( $hex, 0, 2 ) ); |
||
78 | $c_g = hexdec( substr( $hex, 2, 2 ) ); |
||
79 | $c_b = hexdec( substr( $hex, 4, 2 ) ); |
||
80 | $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
||
81 | |||
82 | return $brightness > 155 ? $dark : $light; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | if ( ! function_exists( 'sensei_rgb_from_hex' ) ) { |
||
87 | |||
88 | /** |
||
89 | * Hex darker/lighter/contrast functions for colours |
||
90 | * |
||
91 | * @access public |
||
92 | * @param mixed $color |
||
93 | * @return string |
||
94 | */ |
||
95 | function sensei_rgb_from_hex( $color ) { |
||
96 | $color = str_replace( '#', '', $color ); |
||
97 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
||
98 | $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
||
99 | |||
100 | $rgb['R'] = hexdec( $color{0}.$color{1} ); |
||
101 | $rgb['G'] = hexdec( $color{2}.$color{3} ); |
||
102 | $rgb['B'] = hexdec( $color{4}.$color{5} ); |
||
103 | return $rgb; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | View Code Duplication | if ( ! function_exists( 'sensei_hex_darker' ) ) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
108 | |||
109 | /** |
||
110 | * Hex darker/lighter/contrast functions for colours |
||
111 | * |
||
112 | * @access public |
||
113 | * @param mixed $color |
||
114 | * @param int $factor (default: 30) |
||
115 | * @return string |
||
116 | */ |
||
117 | function sensei_hex_darker( $color, $factor = 30 ) { |
||
118 | $base = sensei_rgb_from_hex( $color ); |
||
119 | $color = '#'; |
||
120 | |||
121 | foreach ($base as $k => $v) : |
||
122 | $amount = $v / 100; |
||
123 | $amount = round($amount * $factor); |
||
124 | $new_decimal = $v - $amount; |
||
125 | |||
126 | $new_hex_component = dechex($new_decimal); |
||
127 | if(strlen($new_hex_component) < 2) : |
||
128 | $new_hex_component = "0".$new_hex_component; |
||
129 | endif; |
||
130 | $color .= $new_hex_component; |
||
131 | endforeach; |
||
132 | |||
133 | return $color; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | View Code Duplication | if ( ! function_exists( 'sensei_hex_lighter' ) ) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
138 | |||
139 | /** |
||
140 | * Hex darker/lighter/contrast functions for colours |
||
141 | * |
||
142 | * @access public |
||
143 | * @param mixed $color |
||
144 | * @param int $factor (default: 30) |
||
145 | * @return string |
||
146 | */ |
||
147 | function sensei_hex_lighter( $color, $factor = 30 ) { |
||
148 | $base = sensei_rgb_from_hex( $color ); |
||
149 | $color = '#'; |
||
150 | |||
151 | foreach ($base as $k => $v) : |
||
152 | $amount = 255 - $v; |
||
153 | $amount = $amount / 100; |
||
154 | $amount = round($amount * $factor); |
||
155 | $new_decimal = $v + $amount; |
||
156 | |||
157 | $new_hex_component = dechex($new_decimal); |
||
158 | if(strlen($new_hex_component) < 2) : |
||
159 | $new_hex_component = "0".$new_hex_component; |
||
160 | endif; |
||
161 | $color .= $new_hex_component; |
||
162 | endforeach; |
||
163 | |||
164 | return $color; |
||
165 | } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * WC Detection for backwards compatibility |
||
170 | * |
||
171 | * @since 1.9.0 |
||
172 | * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active() |
||
173 | */ |
||
174 | if ( ! function_exists( 'is_woocommerce_active' ) ) { |
||
175 | function is_woocommerce_active() { |
||
176 | // calling is present instead of is active here |
||
177 | // as this function can override other is_woocommerce_active |
||
178 | // function in other woo plugins and Sensei_WC::is_woocommerce_active |
||
179 | // also check the sensei settings for enable WooCommerce support, which |
||
180 | // other plugins should not check against. |
||
181 | return Sensei_WC::is_woocommerce_present(); |
||
182 | } |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Provides an interface to allow us to deprecate hooks while still allowing them |
||
187 | * to work, but giving the developer an error message. |
||
188 | * |
||
189 | * @since 1.9.0 |
||
190 | * |
||
191 | * @param $hook_tag |
||
192 | * @param $version |
||
193 | * @param $alternative |
||
194 | * @param array $args |
||
195 | */ |
||
196 | function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array() ){ |
||
197 | |||
198 | if( has_action( $hook_tag ) ){ |
||
199 | |||
200 | $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); |
||
201 | |||
202 | if( !empty( $alternative ) ){ |
||
203 | |||
204 | $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; |
||
205 | |||
206 | } |
||
207 | |||
208 | trigger_error( $error_message ); |
||
209 | do_action( $hook_tag , $args ); |
||
210 | |||
211 | } |
||
212 | |||
213 | }// end sensei_do_deprecated_action |
||
214 | |||
215 | /** |
||
216 | * Check the given post or post type id is a of the |
||
217 | * the course post type. |
||
218 | * |
||
219 | * @since 1.9.0 |
||
220 | * |
||
221 | * @param $post_id |
||
222 | * @return bool |
||
223 | */ |
||
224 | function sensei_is_a_course( $post ){ |
||
225 | |||
226 | return "course" == get_post_type( $post ); |
||
227 | |||
228 | } |
||
229 | |||
230 | /** |
||
231 | * Determine the login link |
||
232 | * on the frontend. |
||
233 | * |
||
234 | * This function will return the my-courses page link |
||
235 | * or the wp-login link. |
||
236 | * |
||
237 | * @since 1.9.0 |
||
238 | */ |
||
239 | function sensei_user_login_url(){ |
||
240 | |||
241 | $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); |
||
242 | $page = get_post( $my_courses_page_id ); |
||
243 | |||
244 | if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID ) ){ |
||
245 | |||
246 | return get_permalink( $page->ID ); |
||
247 | |||
248 | } else { |
||
249 | |||
250 | return wp_login_url(); |
||
251 | |||
252 | } |
||
253 | |||
254 | }// end sensei_user_login_link |
||
255 | |||
256 | /** |
||
257 | * Checks the settings to see |
||
258 | * if a user must be logged in to view content |
||
259 | * |
||
260 | * duplicate of Sensei()->access_settings(). |
||
261 | * |
||
262 | * @since 1.9.0 |
||
263 | * @return bool |
||
264 | */ |
||
265 | function sensei_is_login_required(){ |
||
266 | |||
267 | $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); |
||
268 | |||
269 | return $login_required; |
||
270 | |||
271 | } |
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.