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 |
||
2 | /** |
||
3 | * Generate documentation for hooks in Sensei |
||
4 | * Copied from https://github.com/woothemes/woocommerce |
||
5 | */ |
||
6 | class Sensei_HookFinder { |
||
7 | private static $current_file = ''; |
||
8 | private static $files_to_scan = array(); |
||
9 | private static $pattern_custom_actions = '/do_action(.*?);/i'; |
||
10 | private static $pattern_custom_filters = '/apply_filters(.*?);/i'; |
||
11 | private static $found_files = array(); |
||
12 | private static $custom_hooks_found = ''; |
||
13 | private static $sensei_directory = ''; |
||
14 | private static $docs_output_directory = ''; |
||
15 | private static $put_file = ''; |
||
16 | |||
17 | public static function initialize(){ |
||
18 | |||
19 | self::$sensei_directory = dirname( dirname(__FILE__) ); |
||
20 | self::$docs_output_directory = self::$sensei_directory . '/docs.woothemes.com/images/sensei-apidocs/'; |
||
21 | self::$put_file = self::$docs_output_directory.'/hook-docs.html'; |
||
22 | |||
23 | } |
||
24 | |||
25 | private static function get_files( $pattern, $flags = 0, $path = '' ) { |
||
26 | |||
27 | if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) { |
||
28 | |||
29 | if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement |
||
30 | |||
31 | return self::get_files(basename( $pattern ), $flags, $dir . '/' ); |
||
32 | |||
33 | } // End IF Statement |
||
34 | |||
35 | $paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT ); |
||
36 | $files = glob( $path . $pattern, $flags ); |
||
37 | |||
38 | if ( is_array( $paths ) ) { |
||
39 | foreach ( $paths as $p ) { |
||
40 | $found_files = array(); |
||
41 | $retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' ); |
||
42 | foreach ( $retrieved_files as $file ) { |
||
43 | if ( ! in_array( $file, self::$found_files ) ) |
||
44 | $found_files[] = $file; |
||
45 | } |
||
46 | |||
47 | self::$found_files = array_merge( self::$found_files, $found_files ); |
||
48 | |||
49 | if ( is_array( $files ) && is_array( $found_files ) ) { |
||
50 | $files = array_merge( $files, $found_files ); |
||
51 | } |
||
52 | |||
53 | } // End FOREACH Loop |
||
54 | } |
||
55 | return $files; |
||
56 | } |
||
57 | |||
58 | private static function get_hook_link( $hook, $details = array() ) { |
||
59 | //if ( ! empty( $details['class'] ) ) { |
||
0 ignored issues
–
show
|
|||
60 | // $link = 'http://docs.woothemes.com/sensei-apidocs/source-class-' . $details['class'] . '.html#' . $details['line']; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
48% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
61 | //} elseif ( ! empty( $details['function'] ) ) { |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
62 | // $link = 'http://docs.woothemes.com/sensei-apidocs/source-function-' . $details['function'] . '.html#' . $details['line']; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
48% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
63 | //} else { |
||
64 | $link = 'https://github.com/woothemes/sensei/search?utf8=%E2%9C%93&q=' . $hook; |
||
65 | //} |
||
66 | |||
67 | return '<a href="' . $link . '">' . $hook . '</a>'; |
||
68 | } |
||
69 | |||
70 | public static function process_hooks() { |
||
71 | |||
72 | self::initialize(); |
||
73 | |||
74 | // If we have one, get the PHP files from it. |
||
75 | $template_files = self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/templates/' ); |
||
76 | $template_files[] = self::$sensei_directory . '/includes/template-functions.php'; |
||
77 | |||
78 | $shortcode_files = self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/shortcodes/' ); |
||
79 | $widget_files = self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/widgets/' ); |
||
80 | $admin_files = self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/admin/' ); |
||
81 | $class_files = self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/' ); |
||
82 | $other_files = array( |
||
83 | self::$sensei_directory.'/woothemes-sensei.php' |
||
84 | ); |
||
85 | |||
86 | self::$files_to_scan = array( |
||
87 | 'Template Hooks' => $template_files, |
||
88 | 'Shortcode Hooks' => $shortcode_files, |
||
89 | 'Widget Hooks' => $widget_files, |
||
90 | 'Class Hooks' => $class_files, |
||
91 | 'Admin Hooks' => $admin_files, |
||
92 | 'Other Hooks' => $other_files, |
||
93 | ); |
||
94 | |||
95 | $scanned = array(); |
||
96 | |||
97 | ob_start(); |
||
98 | |||
99 | echo '<div id="content">'; |
||
100 | echo '<h1>Action and Filter Hook Reference</h1>'; |
||
101 | echo '<div class="description"><p>The following is a full list of actions and filters found in Sensei.</p></div>'; |
||
102 | |||
103 | foreach ( self::$files_to_scan as $heading => $files ) { |
||
104 | self::$custom_hooks_found = array(); |
||
105 | |||
106 | foreach ( $files as $f ) { |
||
107 | self::$current_file = basename( $f ); |
||
108 | |||
109 | if ( in_array( self::$current_file, $scanned ) ) { |
||
110 | continue; |
||
111 | } |
||
112 | |||
113 | $scanned[] = self::$current_file; |
||
114 | |||
115 | $tokens = token_get_all( file_get_contents( $f ) ); |
||
116 | $token_type = false; |
||
117 | $current_class = ''; |
||
118 | $current_function = ''; |
||
119 | |||
120 | foreach ( $tokens as $index => $token ) { |
||
121 | if ( is_array( $token ) ) { |
||
122 | if ( $token[0] == T_CLASS ) { |
||
123 | $token_type = 'class'; |
||
124 | } elseif ( $token[0] == T_FUNCTION ) { |
||
125 | $token_type = 'function'; |
||
126 | } elseif ( $token[1] === 'do_action' ) { |
||
127 | $token_type = 'action'; |
||
128 | } elseif ( $token[1] === 'apply_filters' ) { |
||
129 | $token_type = 'filter'; |
||
130 | } elseif ( $token_type && ! empty( trim( $token[1] ) ) ) { |
||
131 | switch ( $token_type ) { |
||
132 | case 'class' : |
||
133 | $current_class = $token[1]; |
||
134 | break; |
||
135 | case 'function' : |
||
136 | $current_function = $token[1]; |
||
137 | break; |
||
138 | case 'filter' : |
||
139 | case 'action' : |
||
140 | $hook = trim( $token[1], "'" ); |
||
141 | if ( isset( self::$custom_hooks_found[ $hook ] ) ) { |
||
142 | self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file; |
||
143 | } else { |
||
144 | self::$custom_hooks_found[ $hook ] = array( |
||
145 | 'line' => $token[2], |
||
146 | 'class' => $current_class, |
||
147 | 'function' => $current_function, |
||
148 | 'file' => array( self::$current_file ), |
||
149 | 'type' => $token_type |
||
150 | ); |
||
151 | } |
||
152 | break; |
||
153 | } |
||
154 | $token_type = false; |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 | foreach ( self::$custom_hooks_found as $hook => $details ) { |
||
161 | if ( ! strstr( $hook, 'sensei' ) ) { |
||
162 | unset( self::$custom_hooks_found[ $hook ] ); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | ksort( self::$custom_hooks_found ); |
||
167 | |||
168 | if ( ! empty( self::$custom_hooks_found ) ) { |
||
169 | echo '<h2>' . $heading . '</h2>'; |
||
170 | |||
171 | echo '<table class="summary"><thead><tr><th>Hook</th><th>Type</th><th>File(s)</th></tr></thead><tbody>'; |
||
172 | |||
173 | foreach ( self::$custom_hooks_found as $hook => $details ) { |
||
174 | echo '<tr> |
||
175 | <td>' . self::get_hook_link( $hook, $details ) . '</td> |
||
176 | <td>' . $details['type'] . '</td> |
||
177 | <td>' . implode( ', ', array_unique( $details['file'] ) ) . '</td> |
||
178 | </tr>' . "\n"; |
||
179 | } |
||
180 | |||
181 | echo '</tbody></table>'; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | echo '</div><div id="footer">'; |
||
186 | |||
187 | |||
188 | |||
189 | // change to the ouput directory before operating on the files |
||
190 | chdir( self::$docs_output_directory ); |
||
191 | |||
192 | $html = file_get_contents( 'index.html' ); |
||
193 | $header = current( explode( '<div id="content">', $html ) ); |
||
194 | $header = str_replace( '<li class="active">', '<li>', $header ); |
||
195 | $header = str_replace( '<li class="hooks">', '<li class="active">', $header ); |
||
196 | $footer = end( explode( '<div id="footer">', $html ) ); |
||
197 | |||
198 | // delete old hook-docs file |
||
199 | if( file_exists( self::$put_file ) ){ |
||
200 | |||
201 | unlink( self::$put_file ); |
||
202 | |||
203 | } |
||
204 | |||
205 | file_put_contents( self::$put_file , $header . ob_get_clean() . $footer ); |
||
206 | |||
207 | echo "Hook docs generated :)\n"; |
||
208 | } |
||
209 | } |
||
210 | |||
211 | Sensei_HookFinder::process_hooks(); |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.