-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.php
109 lines (98 loc) · 3.95 KB
/
hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
$dir = $_GET[ 'dir' ];
$file = $_GET[ 'file' ];
$line = $_GET[ 'line' ];
if ( empty( $dir ) && empty( $file ) && empty( $line ) )
die();
$results = array();
function get_hooks( $dir ) {
global $results;
$fp = opendir( $dir );
while( $file = readdir( $fp ) ){
if( $file == '.' || $file == '..' || substr( $file,0,1) == '.' )
continue;
$tmp_path = $dir . '/' . $file;
if( is_dir( $tmp_path ) ) {
// get recursivly
get_hooks( $tmp_path );
} else {
$contents = file( $tmp_path );
$results[ $tmp_path ] = preg_grep( '/apply_filters|do_action/', $contents );
}
}
closedir( $fp );
}
if( !empty( $dir ) ) {
get_hooks( $dir );
echo '<ul>';
foreach ( $results as $file => $hits ) {
if( empty( $hits ) )
continue;
printf( '<li>%s</li>', $file );
echo '<ul>';
foreach ( $hits as $line_number => $found ) {
preg_match( '/(apply_filters|do_action)\s*\(\s*(\S*)\s*/',$found , $matches );
$hookname = str_replace( array('\'', '"', ","), array( '', '', '' ), $matches[2] );
printf( '<li><b>%s</b>, <i>Line %d</i> <a href="hooks.php?file=%s&line=%d#line%d" target="_blank">code</a></li>',
$hookname, $line_number+1, urlencode( $file ), $line_number+1, $line_number+1 );
}
echo '</ul>';
}
echo '</ul>';
} else if ( !empty( $file ) && !empty( $line ) ) {
renderFile( $file, $line );
}
function renderFile($filename, $highlight) {
if(file_exists($filename) && is_file($filename)) {
$code = highlight_file($filename, true);
$counter = 1;
$arr = explode('<br />', $code);
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-family: monospace;">' . "\r\n";
foreach($arr as $line) {
echo '<tr>' . "\r\n";
echo '<td width="65px" nowrap style="color: #666;"><a name="line' . $counter. '">' . $counter . '</a>:</td>' . "\r\n";
// fix multi-line comment bug
if((strstr($line, '<span style="color: #FF8000">/*') !== false) && (strstr($line, '*/') !== false)) { // single line comment using /* */
$comments = false;
$startcolor = "orange";
}
elseif(strstr($line, '<span style="color: #FF8000">/*') !== false) { // multi line comment using /* */
$startcolor = "orange";
$comments = true;
}
else { // no comment marks found
$startcolor = "green";
if($comments) { // continuation of multi line comment
if(strstr($line, '*/') !== false) {
$comments = false;
$startcolor = "orange";
}
else {
$comments = true;
}
}
else { // normal line
$comments = false;
$startcolor = "green";
}
}
// end fix multi-line comment bug
if( $counter == $highlight)
$bgcolor = ' background: yellow;';
else
$bgcolor = '';
if($comments)
echo '<td width="100%" nowrap style="color: orange;' .$bgcolor. '">' . $line . '</td>' . "\r\n";
else
echo '<td width="100%" nowrap style="color: ' . $startcolor . ';' .$bgcolor. '">' . $line . '</td>' . "\r\n";
echo '</tr>' . "\r\n";
$counter++;
}
echo '</table>' . "\r\n";
}
else {
echo "<p>The file <i>$filename</i> could not be opened.</p>\r\n";
return;
}
}
?>