scanner/modules/output_html.php
Correl Roush 2386113895 Text output is now tab delimited, one fault per line. Added an html output module. Mantis: 2691
git-svn-id: file:///srv/svn/scanner/trunk@5 a0501263-5b7a-4423-a8ba-1edf086583e7
2008-02-15 19:05:09 +00:00

109 lines
2.8 KiB
PHP

<?php
class HTMLOutput extends OutputModule {
function write( $filename ) {
global $faults, $files;
$output = fopen( $filename, 'w' );
if( $output === false ) {
err( "Cannot write to $filename\n" );
return false;
}
fwrite( $output,
'<html>
<head>
<title>Code Scanner Output</title>
<style type="text/css">
.fault {
padding: 5px;
margin-bottom: 5px;
border-style: solid;
border-width: 1px;
}
.fault.level_0 {
color: #3f1c00;
background-color: #cf5c00;
border-color: #8f4000;
}
.fault.level_1 {
color: #3f0000;
background-color: #cf0000;
border-color: #8f0000;
}
.fault.level_2 {
color: #eee;
background-color: #333;
border-color: #999;
}
.fault dt {
cursor: pointer;
}
.fault code {
color: #000;
display: block;
margin-left: 10px;
border: 1px dashed #999;
background-color: #eee;
padding: 5px;
}
</style>
<script type="text/javascript">
function toggleDisplay( id ) {
var e = document.getElementById( "info_" + id );
if( e.style.display == "none" ) {
e.style.display = "block";
} else {
e.style.display = "none";
}
}
</script>
</head>
<body>
<h1>Code Scanner Output</h1>
<h2>Summary</h2>
<p>Found ' . count( $faults ) . ' faults in ' . count( $files ) . ' files</p>
<h2>Faults by file</h2>
<dl>'
);
$current_file = '';
foreach( $faults as $id => $fault ) {
$svn = serialize( $fault['svn'] );
if( $current_file != $fault['object']['file'] ) {
if( $current_file != '' ) {
fwrite( $output, '</ul></dd>' );
}
$current_file = $fault['object']['file'];
fwrite( $output, "<dt>$current_file</dt><dd><ul>" );
}
fprintf( $output,
'<li>
<dl class="fault level_%s">
<dt onclick="toggleDisplay( ' . $id . ')"><strong>%s:</strong> <span class="reason">%s</span></dt>
<dd id="info_' . $id . '" style="display: none;">
<strong>Line:</strong> <span class="line">%d</span><br />
<strong>Author:</strong> <span class="author">%s</span><br />
<strong>Revision:</strong> <span class="revision">%s</span><br />
<strong>Code:</strong>
<code>%s</code>
</dd>
</dl>
</li>',
$fault['level'],
$fault['module'],
$fault['reason'],
$fault['object']['line'],
isset( $fault['svn']['author'] ) ? $fault['svn']['author'] : 'Unknown',
isset( $fault['svn']['revision'] ) ? $fault['svn']['revision'] : 'Unknown',
$fault['object']['context']
);
}
fwrite( $output,
' </dl>
</body>
</html>' . "\n"
);
fclose( $output );
}
}
addModule( new HTMLOutput() );
?>