function diff_result($all, $ent, $newtname, $oldtname, $obj) { $ofile = fopen($oldtname, 'r'); $nfile = fopen($newtname, 'r'); // Get the first real line $line = nextLine($obj); $index = 0; $listing = array(); $curoline = 1; $curnline = 1; while (!endOfFile($obj)) { // Get the first line of this range $oline = 0; sscanf($line, '@@ -%d', $oline); $line = substr($line, strpos($line, '+')); $nline = 0; sscanf($line, '+%d', $nline); while ($curoline < $oline || $curnline < $nline) { if ($all) { $listing[$index]['rev1diffclass'] = 'diff'; $listing[$index]['rev2diffclass'] = 'diff'; } if ($curoline < $oline) { $nl = fgets($ofile); if ($all) { $line = rtrim($nl); if ($ent) { $line = replaceEntities($line); } else { $line = toOutputEncoding($line); } if (strip_tags($line) == '') { $line = ' '; } $listing[$index]['rev1line'] = wrapInCodeTagIfNecessary($line); } $curoline++; } else { if ($all) { $listing[$index]['rev1line'] = ' '; } } if ($curnline < $nline) { $nl = fgets($nfile); if ($all) { $line = rtrim($nl); if ($ent) { $line = replaceEntities($line); } else { $line = toOutputEncoding($line); } if (strip_tags($line) == '') { $line = ' '; } $listing[$index]['rev2line'] = wrapInCodeTagIfNecessary($line); } $curnline++; } else { if ($all) { $listing[$index]['rev2line'] = ' '; } } if ($all) { $listing[$index]['rev1lineno'] = 0; $listing[$index]['rev2lineno'] = 0; $index++; } } if (!$all) { // Output the line numbers $listing[$index]['rev1lineno'] = $oline; $listing[$index]['rev2lineno'] = $nline; $index++; } $fin = false; while (!endOfFile($obj) && !$fin) { $line = nextLine($obj); if ($line === false || $line === '' || strncmp($line, '@@', 2) == 0) { $fin = true; } else { $listing[$index]['rev1lineno'] = 0; $listing[$index]['rev2lineno'] = 0; $mod = $line[0]; $line = rtrim(substr($line, 1)); if ($ent) { $line = replaceEntities($line); } else { $line = toOutputEncoding($line); } if (strip_tags($line) == '') { $line = ' '; } $text = wrapInCodeTagIfNecessary($line); $listing[$index]['rev1line'] = $text; switch ($mod) { case '-': $listing[$index]['rev1diffclass'] = 'diffdeleted'; $listing[$index]['rev2diffclass'] = 'diff'; $listing[$index]['rev1line'] = $text; $listing[$index]['rev2line'] = ' '; fgets($ofile); $curoline++; break; case '+': // Try to mark "changed" line sensibly if (!empty($listing[$index - 1]) && empty($listing[$index - 1]['rev1lineno']) && @$listing[$index - 1]['rev1diffclass'] == 'diffdeleted' && @$listing[$index - 1]['rev2diffclass'] == 'diff') { $i = $index - 1; while (!empty($listing[$i - 1]) && empty($listing[$i - 1]['rev1lineno']) && $listing[$i - 1]['rev1diffclass'] == 'diffdeleted' && $listing[$i - 1]['rev2diffclass'] == 'diff') { $i--; } $listing[$i]['rev1diffclass'] = 'diffchanged'; $listing[$i]['rev2diffclass'] = 'diffchanged'; $listing[$i]['rev2line'] = $text; fgets($nfile); $curnline++; // Don't increment the current index count $index--; } else { $listing[$index]['rev1diffclass'] = 'diff'; $listing[$index]['rev2diffclass'] = 'diffadded'; $listing[$index]['rev1line'] = ' '; $listing[$index]['rev2line'] = $text; fgets($nfile); $curnline++; } break; default: $listing[$index]['rev1diffclass'] = 'diff'; $listing[$index]['rev2diffclass'] = 'diff'; $nl = fgets($ofile); $line = rtrim($nl); if ($ent) { $line = replaceEntities($line); } else { $line = toOutputEncoding($line); } if (strip_tags($line) == '') { $line = ' '; } $listing[$index]['rev1line'] = wrapInCodeTagIfNecessary($line); $curoline++; $nl = fgets($nfile); $line = rtrim($nl); if ($ent) { $line = replaceEntities($line); } else { $line = toOutputEncoding($line); } if (strip_tags($line) == '') { $line = ' '; } $listing[$index]['rev2line'] = wrapInCodeTagIfNecessary($line); $curnline++; break; } } if (!$fin) { $index++; } } } // Output the rest of the files if ($all) { while (!feof($ofile) || !feof($nfile)) { $listing[$index]['rev1diffclass'] = 'diff'; $listing[$index]['rev2diffclass'] = 'diff'; $line = rtrim(fgets($ofile)); if ($ent) { $line = replaceEntities($line); } else { $line = toOutputEncoding($line); } if (strip_tags($line) == '') { $line = ' '; } if (!feof($ofile)) { $listing[$index]['rev1line'] = wrapInCodeTagIfNecessary($line); } else { $listing[$index]['rev1line'] = ' '; } $line = rtrim(fgets($nfile)); if ($ent) { $line = replaceEntities(rtrim(fgets($nfile))); } else { $line = toOutputEncoding($line); } if (strip_tags($line) == '') { $line = ' '; } if (!feof($nfile)) { $listing[$index]['rev2line'] = wrapInCodeTagIfNecessary($line); } else { $listing[$index]['rev2line'] = ' '; } $listing[$index]['rev1lineno'] = 0; $listing[$index]['rev2lineno'] = 0; $index++; } } fclose($ofile); fclose($nfile); return $listing; }
$url = $config->getURL($rep, $parent, 'revision'); $listing[$index]['revision'] = '<a id="l' . $index . '-rev" class="blame-revision" href="' . $url . 'rev=' . $revision . '&peg=' . $rev . '">' . $revision . '</a>'; $seen_rev[$revision] = 1; $row_class = $row_class == 'light' ? 'dark' : 'light'; $listing[$index]['author'] = $author; } else { $listing[$index]['revision'] = ''; $listing[$index]['author'] = ''; } $listing[$index]['row_class'] = $row_class; $last_rev = $revision; $line = rtrim(fgets($file)); if (!$highlighted) { $line = replaceEntities($line); } $listing[$index]['line'] = $empty ? ' ' : wrapInCodeTagIfNecessary($line); $index++; } } fclose($blame); } fclose($file); @unlink($tbname); } @unlink($tfname); // Build the necessary JavaScript as an array of lines, then join them with \n $javascript = array(); $javascript[] = '<script type="text/javascript" src="' . $locwebsvnhttp . '/javascript/blame-popup.js"></script>'; $javascript[] = '<script type="text/javascript">'; $javascript[] = '/* <![CDATA[ */'; $javascript[] = 'var rev = new Array();';