function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->_final();
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         $this->changedLine($line, $aline);
         $this->originalLineNum++;
         $this->finalLineNum++;
     }
     $this->_added($add);
     // If any leftovers
 }
示例#2
0
 function _changed($orig, $final)
 {
     $diff = new WordLevelDiff($orig, $final);
     $this->_lines($diff->orig(), 'original', '-');
     $this->_lines($diff->_final(), 'final', '+');
 }
示例#3
0
 function _changed($orig, $final)
 {
     $diff = new WordLevelDiff($orig, $final);
     $div = '<div class="difftext">';
     foreach ($diff->orig() as $line) {
         $div .= "\n" . '<div class="original"><tt class="prefix">-</tt>' . $line . '</div>';
     }
     $this->result .= $div . "</div>\n";
     $div = '<div class="difftext">';
     foreach ($diff->_final() as $line) {
         $div .= "\n" . '<div class="final"><tt class="prefix">+</tt>' . $line . '</div>';
     }
     $this->result .= $div . "</div>\n";
 }
 function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->_final();
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         if ($this->type == 'sidebyside') {
             print '<tbody class="mod"><tr>' . $this->deletedLine($line, 'l') . $this->addedLine($aline, 'r') . "</tr></tbody>\n";
         } else {
             print '<tbody class="mod"><tr>' . $this->deletedLine($line, 'l') . "</tr></tbody>\n";
         }
     }
     $this->_added($add);
     // If any leftovers
 }
示例#5
0
文件: Diff.php 项目: sedrion/moniwiki
function fancy_diff($diff, $options = array())
{
    global $DBInfo;
    include_once "lib/difflib.php";
    $diff = str_replace("<", "&lt;", $diff);
    $lines = explode("\n", $diff);
    // trash the last empty line;
    $end = end($lines);
    //if (!isset($end[0])) array_pop($lines);
    $out = "";
    #unset($lines[0]); unset($lines[1]);
    $omarker = 0;
    $orig = array();
    $new = array();
    foreach ($lines as $line) {
        if (empty($omarker) and empty($line[0])) {
            continue;
        }
        $marker = $line[0];
        if (in_array($marker, array('-', '+', '@'))) {
            $line = substr($line, 1);
        }
        if ($marker == "@") {
            if (isset($out[0])) {
                $out .= '</div>';
            }
            $out .= '<div class="diff-sep">@' . "{$line}</div><div class='diff-highlight'>";
            continue;
        } else {
            if ($marker == "-") {
                $omarker = 1;
                $orig[] = $line;
                continue;
            } else {
                if ($marker == "+") {
                    $omarker = 1;
                    $new[] = $line;
                    continue;
                } else {
                    if ($marker == "\\") {
                        continue;
                    } else {
                        if ($omarker) {
                            $omarker = 0;
                            $buf = "";
                            $result = new WordLevelDiff($orig, $new, $DBInfo->charset);
                            if (empty($options['inline'])) {
                                foreach ($result->orig() as $ll) {
                                    $buf .= "<div class=\"diff-removed\">{$ll}</div>\n";
                                }
                                foreach ($result->_final() as $ll) {
                                    $buf .= "<div class=\"diff-added\">{$ll}</div>\n";
                                }
                            } else {
                                foreach ($result->all(null, '', false) as $ll) {
                                    $buf .= "<div class=\"diff\">{$ll}</div>\n";
                                }
                            }
                            $orig = array();
                            $new = array();
                            $line = $buf . $line . "<br />";
                        } else {
                            if ($marker == " " and !$omarker) {
                                $line .= "<br />";
                            } else {
                                $line .= "<br />";
                            }
                        }
                    }
                }
            }
        }
        $out .= $line . "\n";
    }
    $out .= '</div>';
    return $out;
}