コード例 #1
0
 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, $closing)
 {
     wfProfileIn(__METHOD__);
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     # Notice that WordLevelDiff returns HTML-escaped output.
     # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         echo '<tr>' . $this->deletedLine($line) . $this->addedLine($aline) . "</tr>\n";
     }
     foreach ($add as $line) {
         # If any leftovers
         echo '<tr>' . $this->emptyLine() . $this->addedLine($line) . "</tr>\n";
     }
     wfProfileOut(__METHOD__);
 }
コード例 #3
0
ファイル: class.ilPageObject.php プロジェクト: bheyser/qplskl
 /**
  * Compares to revisions of the page
  *
  * @param	int		$a_left		Nr of first revision
  * @param	int		$a_right	Nr of second revision
  */
 function compareVersion($a_left, $a_right)
 {
     // get page objects
     include_once "./Services/COPage/classes/class.ilPageObjectFactory.php";
     $l_page = ilPageObjectFactory::getInstance($this->getParentType(), $this->getId(), $a_left);
     $r_page = ilPageObjectFactory::getInstance($this->getParentType(), $this->getId(), $a_right);
     $l_hashes = $l_page->getPageContentsHashes();
     $r_hashes = $r_page->getPageContentsHashes();
     // determine all deleted and changed page elements
     foreach ($l_hashes as $pc_id => $h) {
         if (!isset($r_hashes[$pc_id])) {
             $l_hashes[$pc_id]["change"] = "Deleted";
         } else {
             if ($l_hashes[$pc_id]["hash"] != $r_hashes[$pc_id]["hash"]) {
                 $l_hashes[$pc_id]["change"] = "Modified";
                 $r_hashes[$pc_id]["change"] = "Modified";
                 include_once "./Services/COPage/mediawikidiff/class.WordLevelDiff.php";
                 // if modified element is a paragraph, highlight changes
                 if ($l_hashes[$pc_id]["content"] != "" && $r_hashes[$pc_id]["content"] != "") {
                     $new_left = str_replace("\n", "<br />", $l_hashes[$pc_id]["content"]);
                     $new_right = str_replace("\n", "<br />", $r_hashes[$pc_id]["content"]);
                     $wldiff = new WordLevelDiff(array($new_left), array($new_right));
                     $new_left = $wldiff->orig();
                     $new_right = $wldiff->closing();
                     $l_page->setParagraphContent($l_hashes[$pc_id]["hier_id"], $new_left[0]);
                     $r_page->setParagraphContent($l_hashes[$pc_id]["hier_id"], $new_right[0]);
                 }
             }
         }
     }
     // determine all new paragraphs
     foreach ($r_hashes as $pc_id => $h) {
         if (!isset($l_hashes[$pc_id])) {
             $r_hashes[$pc_id]["change"] = "New";
         }
     }
     $l_page->addChangeDivClasses($l_hashes);
     $r_page->addChangeDivClasses($r_hashes);
     return array("l_page" => $l_page, "r_page" => $r_page, "l_changes" => $l_hashes, "r_changes" => $r_hashes);
 }
コード例 #4
0
ファイル: Diff.php プロジェクト: pombredanne/tuleap
 function _changed($orig, $final)
 {
     $diff = new WordLevelDiff($orig, $final);
     $this->_lines($diff->orig(), 'original', '-');
     $this->_lines($diff->_final(), 'final', '+');
 }
コード例 #5
0
 public function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         print '<tr>' . $this->deletedLine($line) . $this->addedLine($aline) . "</tr>\n";
     }
     $this->_added($add);
     # If any leftovers
 }
コード例 #6
0
ファイル: diffhtml.php プロジェクト: alienpham/helenekling
 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";
 }
コード例 #7
0
ファイル: DiffEngine.php プロジェクト: kendraio/kendra_hub_v1
 function _changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     // Notice that WordLevelDiff returns HTML-escaped output.
     // Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     while ($line = array_shift($del)) {
         $aline = array_shift($add);
         $this->rows[] = array_merge($this->deletedLine($line), isset($aline) ? $this->addedLine($aline) : $this->emptyLine());
     }
     foreach ($add as $line) {
         // If any leftovers
         $this->rows[] = array_merge($this->emptyLine(), $this->addedLine($line));
     }
 }
コード例 #8
0
 /**
  * Writes the two sets of lines to the output buffer, each enclosed in <tr>.
  *
  * @param string[] $orig
  * @param string[] $closing
  */
 protected function changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     # Notice that WordLevelDiff returns HTML-escaped output.
     # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     $ndel = count($del);
     $nadd = count($add);
     $n = max($ndel, $nadd);
     for ($i = 0; $i < $n; $i++) {
         $delLine = $i < $ndel ? $this->deletedLine($del[$i]) : $this->emptyLine();
         $addLine = $i < $nadd ? $this->addedLine($add[$i]) : $this->emptyLine();
         $this->writeOutput("<tr>{$delLine}{$addLine}</tr>\n");
     }
 }
コード例 #9
0
 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
 }
コード例 #10
0
 /**
  * Writes the two sets of lines to the output buffer, each enclosed in <tr>.
  *
  * @param string[] $orig
  * @param string[] $closing
  */
 protected function changed($orig, $closing)
 {
     $diff = new WordLevelDiff($orig, $closing);
     $del = $diff->orig();
     $add = $diff->closing();
     # Notice that WordLevelDiff returns HTML-escaped output.
     # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
     $line = array_shift($del);
     while ($line) {
         $aline = array_shift($add);
         $this->writeOutput('<tr>' . $this->deletedLine($line) . $this->addedLine($aline) . "</tr>\n");
         $line = array_shift($del);
     }
     foreach ($add as $line) {
         # If any leftovers
         $this->writeOutput('<tr>' . $this->emptyLine() . $this->addedLine($line) . "</tr>\n");
     }
 }
コード例 #11
0
ファイル: Diff.php プロジェクト: sedrion/moniwiki
function smart_diff($diff)
{
    global $DBInfo;
    include_once "lib/difflib.php";
    $diff = str_replace("<", "&lt;", $diff);
    $lines = explode("\n", $diff);
    #unset($lines[0]); unset($lines[1]);
    #print "<pre>";
    #print_r( $lines);
    #print "</pre>";
    $tags = array("", "", "", "");
    $news = array();
    $dels = array();
    $omarker = 0;
    $orig = array();
    $new = array();
    foreach ($lines as $line) {
        $marker = $line[0];
        $line = substr($line, 1);
        if ($marker == '@' and preg_match('/^@\\s\\-(\\d+)(?:,\\d+)?\\s\\+(\\d+)(?:,\\d+)?\\s@@/', $line, $mat)) {
            $lp = $mat[2];
            $lm = $mat[1];
        } else {
            if ($marker == '-') {
                $omarker = 1;
                $orig[] = $line;
                continue;
            } else {
                if ($marker == '+') {
                    $omarker = 2;
                    $new[] = $line;
                    continue;
                } else {
                    if ($marker == "\\") {
                        continue;
                    } else {
                        if ($omarker) {
                            $count = sizeof($new);
                            $ocount = sizeof($orig);
                            $omarker = 0;
                            $buf = '';
                            $result = new WordLevelDiff($orig, $new, $DBInfo->charset);
                            # rearrange output.
                            foreach ($result->all($tags) as $ll) {
                                $buf .= $ll . "\n";
                            }
                            $buf = substr($buf, 0, -1);
                            // drop last added "\n"
                            $orig = array();
                            $new = array();
                            if ($count != 0) {
                                $news[$lp - 1] = $buf;
                                for ($i = 0; $i < $count - 1; $i++) {
                                    $news[$lp + $i] = null;
                                }
                                #for ($i=$count-1;$i>0;$i--) $news[$lp+$i-1]=null;
                            } else {
                                if ($ocount != 0) {
                                    $dels[$lp - 1] = $buf;
                                    for ($i = 0; $i < $ocount - 1; $i++) {
                                        $dels[$lp + $i] = null;
                                    }
                                }
                            }
                            if ($marker == ' ') {
                                $lp += $count + 1;
                                $lm += $ocount + 1;
                            }
                        } else {
                            if ($marker == ' ' and !$omarker) {
                                $lp++;
                                $lm++;
                            }
                        }
                    }
                }
            }
        }
    }
    #print "<pre style='color:black;background-color:#93FF93'>";
    #print_r($news);
    #print "</pre>";
    #print "<pre style='color:black;background-color:#FF9797'>";
    #print_r($dels);
    #print "</pre>";
    return array($news, $dels);
}