this is even safer

This commit is contained in:
Nilgün Belma Bugüner
2021-05-19 05:04:17 +03:00
parent e9f815f45a
commit d77b6ea5a0
2 changed files with 33 additions and 33 deletions

View File

@ -238,32 +238,39 @@ function get_stats($idx, $lang, $status) {
return array($result['total'], $result['size']);
}
function showdiff ( $dir, $gitfile, $h2, $c )
function showdiff ()
{
$cwd = getcwd();
chdir( $dir );
$file = `git diff {$h2} -- {$gitfile}`;
chdir( $cwd );
$raw = htmlspecialchars( $file, ENT_XML1, 'UTF-8' );
if ( $c == 'on' ) {
$trans = [ " " => " " ];
$lines = explode ( "\n" , $raw );
foreach ( $lines as $line ) {
$inline = strtr( $line , $trans );
$fc = substr( $inline , 0 , 1 );
if ( $fc == "+" ) {
echo "<div style='color:green;font-family:mono'>";
} elseif ( $fc == "-" ) {
echo "<div style='color:red;font-family:mono'>";
} elseif ( $fc == "@" ) {
echo "<div style='color:blue;font-family:mono'>";
} else
echo "<div style='color:gray;font-family:mono'>";
echo "$inline</div>\n";
}
echo "<p></p>";
} else
echo "<pre style='font-family:mono'>" , $raw , "</pre>";
if (isset($_GET['f'])) {
$gitfile = $_GET['f'];
if (isset($_GET['hbp']))
$h = $_GET['hbp'];
if (isset($_GET['c']))
$c = $_GET['c'];
$cwd = getcwd();
chdir( GIT_DIR . 'en' );
$file = `git diff {$h} -- {$gitfile}`;
chdir( $cwd );
$raw = htmlspecialchars( $file, ENT_XML1, 'UTF-8' );
if ( $c == 'on' ) {
$trans = [ " " => "&nbsp;" ];
$lines = explode ( "\n" , $raw );
foreach ( $lines as $line ) {
$inline = strtr( $line , $trans );
$fc = substr( $inline , 0 , 1 );
if ( $fc == "+" ) {
echo "<div style='color:green;font-family:mono'>";
} elseif ( $fc == "-" ) {
echo "<div style='color:red;font-family:mono'>";
} elseif ( $fc == "@" ) {
echo "<div style='color:blue;font-family:mono'>";
} else
echo "<div style='color:gray;font-family:mono'>";
echo "$inline</div>\n";
}
echo "<p></p>";
} else
echo "<pre style='font-family:mono'>" , $raw , "</pre>";
}
}
function gen_date($file)

View File

@ -382,14 +382,7 @@ END_OF_MULTILINE;
break;
case 'plain':
if (isset($_GET['f'])) {
$gitfile = $_GET['f'];
if (isset($_GET['hbp']))
$h2 = $_GET['hbp'];
if (isset($_GET['c']))
$c = $_GET['c'];
showdiff( GIT_DIR . 'en', $gitfile, $h2, $c );
}
showdiff();
echo gen_date($DBLANG);
break;