2008-10-02 16:42:55 +00:00
|
|
|
<?php
|
|
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
|
|
|
if (!ini_get("session.auto_start")) {
|
2009-06-08 19:02:30 +00:00
|
|
|
session_name("adminer_sid");
|
2008-10-02 16:42:55 +00:00
|
|
|
session_set_cookie_params(ini_get("session.cookie_lifetime"), preg_replace('~_coverage\\.php(\\?.*)?$~', '', $_SERVER["REQUEST_URI"]));
|
|
|
|
session_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
function xhtml_open_tags($s) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// returns array of opened tags in $s
|
2008-10-02 16:42:55 +00:00
|
|
|
$return = array();
|
|
|
|
preg_match_all('~<([^>]+)~', $s, $matches);
|
|
|
|
foreach ($matches[1] as $val) {
|
|
|
|
if ($val{0} == "/") {
|
|
|
|
array_pop($return);
|
|
|
|
} elseif (substr($val, -1) != "/") {
|
|
|
|
$return[] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2008-10-02 22:10:34 +00:00
|
|
|
if (!extension_loaded("xdebug")) {
|
|
|
|
echo "<p>Xdebug has to be enabled.</p>\n";
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:42:55 +00:00
|
|
|
if ($_GET["start"]) {
|
2009-06-13 20:55:57 +00:00
|
|
|
unset($_SESSION["coverage"]);
|
2008-10-03 16:32:11 +00:00
|
|
|
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
|
2009-04-15 11:28:58 +00:00
|
|
|
$_SESSION["coverage"] = array();
|
2009-06-13 20:55:19 +00:00
|
|
|
include "./adminer/index.php";
|
2008-10-02 16:42:55 +00:00
|
|
|
header("Location: .");
|
|
|
|
exit;
|
2008-10-02 22:10:34 +00:00
|
|
|
}
|
2009-06-13 20:55:19 +00:00
|
|
|
if (preg_match('~^(include/)?[-_.a-z0-9]+$~i', $_GET["filename"])) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// highlight single file
|
2009-06-13 20:55:19 +00:00
|
|
|
$filename = "adminer/$_GET[filename]";
|
2009-01-29 13:23:59 +00:00
|
|
|
$cov = $_SESSION["coverage"][realpath($filename)];
|
2008-10-02 16:42:55 +00:00
|
|
|
$file = explode("<br />", highlight_file($filename, true));
|
|
|
|
unset($prev_color);
|
|
|
|
$s = "";
|
|
|
|
for ($l=0; $l <= count($file); $l++) {
|
|
|
|
$line = $file[$l];
|
|
|
|
$color = "#C0FFC0"; // tested
|
2009-01-29 13:23:59 +00:00
|
|
|
switch ($cov[$l+1]) {
|
2008-10-02 16:42:55 +00:00
|
|
|
case -1: $color = "#FFC0C0"; break; // untested
|
|
|
|
case -2: $color = "Silver"; break; // dead code
|
|
|
|
case null: $color = ""; break; // not executable
|
|
|
|
}
|
|
|
|
if (!isset($prev_color)) {
|
|
|
|
$prev_color = $color;
|
|
|
|
}
|
|
|
|
if ($prev_color != $color || !isset($line)) {
|
|
|
|
echo "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">" . $s;
|
|
|
|
$open_tags = xhtml_open_tags($s);
|
|
|
|
foreach (array_reverse($open_tags) as $tag) {
|
|
|
|
echo "</" . preg_replace('~ .*~', '', $tag) . ">";
|
|
|
|
}
|
|
|
|
echo "</div>\n";
|
|
|
|
$s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
|
|
|
|
$prev_color = $color;
|
|
|
|
}
|
|
|
|
$s .= "$line<br />\n";
|
|
|
|
}
|
2008-10-02 22:10:34 +00:00
|
|
|
} else {
|
2009-06-21 23:20:32 +00:00
|
|
|
// display list of files
|
2008-10-02 22:10:34 +00:00
|
|
|
echo "<table border='0' cellspacing='0' cellpadding='1'>\n";
|
2009-06-13 20:55:19 +00:00
|
|
|
foreach (array_merge(glob("adminer/*.php"), glob("adminer/include/*.php")) as $filename) {
|
|
|
|
$cov = $_SESSION["coverage"][realpath($filename)];
|
|
|
|
$filename = substr($filename, 8);
|
|
|
|
$ratio = 0;
|
|
|
|
if (isset($cov)) {
|
|
|
|
$values = array_count_values($cov);
|
|
|
|
$ratio = round(100 - 100 * $values[-1] / count($cov));
|
2008-10-02 16:42:55 +00:00
|
|
|
}
|
2009-06-13 20:55:19 +00:00
|
|
|
echo "<tr><td align='right' style='background-color: " . ($ratio < 50 ? "Red" : ($ratio < 75 ? "#FFEA20" : "#A7FC9D")) . ";'>$ratio%</td><td><a href='coverage.php?filename=$filename'>$filename</a></td></tr>\n";
|
2008-10-02 16:42:55 +00:00
|
|
|
}
|
2008-10-02 22:10:34 +00:00
|
|
|
echo "</table>\n";
|
2009-06-13 20:55:19 +00:00
|
|
|
echo "<p><a href='coverage.php?start=1'>Start new coverage</a> (requires <a href='http://www.xdebug.org'>Xdebug</a>)</p>\n";
|
2008-10-02 16:42:55 +00:00
|
|
|
}
|