-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcode.php
More file actions
79 lines (65 loc) · 2.5 KB
/
code.php
File metadata and controls
79 lines (65 loc) · 2.5 KB
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
<table width='100%'>
<?php
/**
RIPS - A static source code analyser for vulnerabilities in PHP scripts
by Johannes Dahse (johannesdahse@gmx.de)
Copyright (C) 2010 Johannes Dahse
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
**/
// prepare output to style with CSS
function highlightline($line, $line_nr, $marklines)
{
$tokens = @token_get_all('<? '.$line.' ?>');
$output = "<tr><td class=\"linenrcolumn\"><span class=\"linenr\">$line_nr</span> <A id='".($line_nr+2).'\'></A></td>';
$output .= (in_array($line_nr, $marklines)) ? '<td nowrap class="markline">' : '<td nowrap>';
foreach ($tokens as $token)
{
if (is_string($token))
{
$output .= '<span class="phps-code">';
$output .= htmlentities($token, ENT_QUOTES, 'utf-8');
$output .= '</span>';
}
else if (is_array($token)
&& $token[0] !== T_OPEN_TAG
&& $token[0] !== T_CLOSE_TAG)
{
if ($token[0] !== T_WHITESPACE)
{
$text = '<span ';
if($token[0] === T_VARIABLE)
{
$cssname = str_replace('$', '', $token[1]);
$text.= 'style="cursor:pointer;" name="phps-var-'.$cssname.'" onClick="markVariable(\''.$cssname.'\')"';
}
$text.= 'class="phps-'.str_replace('_', '-', strtolower(token_name($token[0]))).'" ';
$text.= '>'.htmlentities($token[1], ENT_QUOTES, 'utf-8').'</span>';
}
else
{
$text = str_replace(' ', ' ', $token[1]);
$text = str_replace("\t", str_repeat(' ', 8), $text);
}
$output .= $text;
}
}
return $output.'</td></tr>';
}
// print source code and mark lines
$file = $_GET['file'];
$marklines = explode(',', $_GET['lines']);
if(!empty($file))
{
$lines = file($file);
for($i=0, $max=count($lines); $i<$max; $i++)
{
echo highlightline($lines[$i], $i+1, $marklines);
}
} else
{
echo '<tr><td>No file specified.</td></tr>';
}
?>
</table>