Beispiel #1
0
 public function testRenderFixesSpaces()
 {
     $htmlRenderer = new \Diff_Renderer_Html_Array();
     $htmlRenderer->diff = new \Diff(array('    a'), array('a'));
     $result = $htmlRenderer->render();
     static::assertEquals(array(array(array('tag' => 'replace', 'base' => array('offset' => 0, 'lines' => array('<del>&nbsp; &nbsp;</del>a')), 'changed' => array('offset' => 0, 'lines' => array('<ins></ins>a'))))), $result);
 }
Beispiel #2
0
 /**
  * Render a and return diff with changes between the two sequences
  * displayed inline (under each other)
  *
  * @return string The generated inline diff.
  */
 public function render()
 {
     $changes = parent::render();
     if (empty($changes)) {
         return '';
     }
     $html = "\n" . '<div class="change">';
     // Add the field name
     if (isset($this->options['field'])) {
         $html .= "\n<h2>" . $this->options['field'] . '</h2>';
     }
     $html .= "\n<dl>";
     foreach ($changes as $i => $blocks) {
         // If this is a separate block, we're condensing code so output …,
         // indicating a significant portion of the code has been collapsed
         if ($i > 0) {
             $html .= '<dt class="skipped">…</dt>';
         }
         foreach ($blocks as $change) {
             // Equal changes should be shown on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $line) {
                     $html .= "\n  " . '<dt class="' . $change['tag'] . ' left">' . ($line ?: '&nbsp;') . '</dt>';
                 }
             } elseif ($change['tag'] == 'insert') {
                 foreach ($change['changed']['lines'] as $line) {
                     $html .= "\n " . '<dt class="' . $change['tag'] . ' right"><ins>' . ($line ?: '&nbsp;') . '</ins></dt>';
                 }
             } elseif ($change['tag'] == 'delete') {
                 foreach ($change['base']['lines'] as $line) {
                     $html .= "\n  " . '<dt class="' . $change['tag'] . ' left"><del>' . ($line ?: '&nbsp;') . '</del></dt>';
                 }
             } elseif ($change['tag'] == 'replace') {
                 foreach ($change['base']['lines'] as $line) {
                     $html .= "\n  " . '<dt class="' . $change['tag'] . ' left"><span>' . ($line ?: '&nbsp;') . '</span></dt>';
                 }
                 foreach ($change['changed']['lines'] as $line) {
                     $html .= "\n  " . '<dd class="' . $change['tag'] . ' right"><span>' . ($line ?: '&nbsp;') . '</span></dd>';
                 }
             }
         }
     }
     $html .= "\n</dl>\n</div>\n";
     return $html;
 }
Beispiel #3
0
 /**
  * Render the diff and return the generated markup
  *
  * @return string The generated markup
  */
 public function render()
 {
     $changes = parent::render();
     if (empty($changes)) {
         return '';
     }
     $html = "\n" . '<div class="change">';
     // Add the field name
     if (isset($this->options['field'])) {
         $html .= "\n<h2>" . $this->options['field'] . '</h2>';
     }
     $html .= "\n<dl>";
     foreach ($changes as $i => $blocks) {
         if ($i > 0) {
             $html .= '<dt class="skipped">…</dt>';
         }
         foreach ($blocks as $change) {
             // Show equal changes on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $line) {
                     $html .= "\n  " . '<dt class="' . $change['tag'] . ' left">' . ($line ?: '&nbsp;') . '</dt>';
                 }
             } elseif ($change['tag'] == 'insert') {
                 foreach ($change['changed']['lines'] as $line) {
                     $html .= "\n " . '<dt class="' . $change['tag'] . ' right"><ins>' . ($line ?: '&nbsp;') . '</ins></dt>';
                 }
             } elseif ($change['tag'] == 'delete') {
                 foreach ($change['base']['lines'] as $line) {
                     $html .= "\n  " . '<dt class="' . $change['tag'] . ' left"><del>' . ($line ?: '&nbsp;') . '</del></dt>';
                 }
             } elseif ($change['tag'] == 'replace') {
                 foreach ($change['base']['lines'] as $line) {
                     $html .= "\n  " . '<dt class="' . $change['tag'] . ' left"><span>' . ($line ?: '&nbsp;') . '</span></dt>';
                 }
                 foreach ($change['changed']['lines'] as $line) {
                     $html .= "\n  " . '<dd class="' . $change['tag'] . ' right"><span>' . ($line ?: '&nbsp;') . '</span></dd>';
                 }
             }
         }
     }
     $html .= "\n</dl>\n</div>\n";
     return $html;
 }
Beispiel #4
0
 /**
  * Render a and return diff with changes between the two sequences
  * displayed side by side.
  *
  * @return string The generated side by side diff.
  */
 public function render()
 {
     $changes = parent::render();
     $html = '';
     if (empty($changes)) {
         return $html;
     }
     $html .= '<table class="Differences DifferencesSideBySide">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th colspan="2">The Original Version of the file</th>';
     $html .= '<th colspan="2">The Modified Version on your WordPress system</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     foreach ($changes as $i => $blocks) {
         if ($i > 0) {
             $html .= '<tbody class="Skipped">';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '</tbody>';
         }
         foreach ($blocks as $change) {
             $html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
             // Equal changes should be shown on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $no => $line) {
                     $fromLine = $change['base']['offset'] + $no + 1;
                     $toLine = $change['changed']['offset'] + $no + 1;
                     $html .= '<tr>';
                     $html .= '<th>' . $fromLine . '</th>';
                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '<th>' . $toLine . '</th>';
                     $html .= '<td class="Right"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '</tr>';
                 }
             } else {
                 if ($change['tag'] == 'insert') {
                     foreach ($change['changed']['lines'] as $no => $line) {
                         $toLine = $change['changed']['offset'] + $no + 1;
                         $html .= '<tr>';
                         $html .= '<th>&nbsp;</th>';
                         $html .= '<td class="Left">&nbsp;</td>';
                         $html .= '<th>' . $toLine . '</th>';
                         $html .= '<td class="Right"><ins>' . $line . '</ins>&nbsp;</td>';
                         $html .= '</tr>';
                     }
                 } else {
                     if ($change['tag'] == 'delete') {
                         foreach ($change['base']['lines'] as $no => $line) {
                             $fromLine = $change['base']['offset'] + $no + 1;
                             $html .= '<tr>';
                             $html .= '<th>' . $fromLine . '</th>';
                             $html .= '<td class="Left"><del>' . $line . '</del>&nbsp;</td>';
                             $html .= '<th>&nbsp;</th>';
                             $html .= '<td class="Right">&nbsp;</td>';
                             $html .= '</tr>';
                         }
                     } else {
                         if ($change['tag'] == 'replace') {
                             if (count($change['base']['lines']) >= count($change['changed']['lines'])) {
                                 foreach ($change['base']['lines'] as $no => $line) {
                                     $fromLine = $change['base']['offset'] + $no + 1;
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     if (!isset($change['changed']['lines'][$no])) {
                                         $toLine = '&nbsp;';
                                         $changedLine = '&nbsp;';
                                     } else {
                                         $toLine = $change['base']['offset'] + $no + 1;
                                         $changedLine = '<span>' . $change['changed']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<th>' . $toLine . '</th>';
                                     $html .= '<td class="Right">' . $changedLine . '</td>';
                                     $html .= '</tr>';
                                 }
                             } else {
                                 foreach ($change['changed']['lines'] as $no => $changedLine) {
                                     if (!isset($change['base']['lines'][$no])) {
                                         $fromLine = '&nbsp;';
                                         $line = '&nbsp;';
                                     } else {
                                         $fromLine = $change['base']['offset'] + $no + 1;
                                         $line = '<span>' . $change['base']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     $toLine = $change['changed']['offset'] + $no + 1;
                                     $html .= '<th>' . $toLine . '</th>';
                                     $html .= '<td class="Right">' . $changedLine . '</td>';
                                     $html .= '</tr>';
                                 }
                             }
                         }
                     }
                 }
             }
             $html .= '</tbody>';
         }
     }
     $html .= '</table>';
     return $html;
 }
Beispiel #5
0
 /**
  * Render a and return diff with changes between the two sequences
  * displayed inline (under each other)
  *
  * @return string The generated inline diff.
  */
 public function render()
 {
     $changes = parent::render();
     $html = '';
     if (empty($changes)) {
         return $html;
     }
     $html .= '<table class="Differences DifferencesInline">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th>Old</th>';
     $html .= '<th>New</th>';
     $html .= '<th>Differences</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     foreach ($changes as $i => $blocks) {
         // If this is a separate block, we're condensing code so output ...,
         // indicating a significant portion of the code has been collapsed as
         // it is the same
         if ($i > 0) {
             $html .= '<tbody class="Skipped">';
             $html .= '<th>&hellip;</th>';
             $html .= '<th>&hellip;</th>';
             $html .= '<td>&nbsp;</td>';
             $html .= '</tbody>';
         }
         foreach ($blocks as $change) {
             $html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
             // Equal changes should be shown on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $no => $line) {
                     $fromLine = $change['base']['offset'] + $no + 1;
                     $toLine = $change['changed']['offset'] + $no + 1;
                     $html .= '<tr>';
                     $html .= '<th>' . $fromLine . '</th>';
                     $html .= '<th>' . $toLine . '</th>';
                     $html .= '<td class="Left">' . $line . '</td>';
                     $html .= '</tr>';
                 }
             } else {
                 if ($change['tag'] == 'insert') {
                     foreach ($change['changed']['lines'] as $no => $line) {
                         $toLine = $change['changed']['offset'] + $no + 1;
                         $html .= '<tr>';
                         $html .= '<th>&nbsp;</th>';
                         $html .= '<th>' . $toLine . '</th>';
                         $html .= '<td class="Right"><ins>' . $line . '</ins>&nbsp;</td>';
                         $html .= '</tr>';
                     }
                 } else {
                     if ($change['tag'] == 'delete') {
                         foreach ($change['base']['lines'] as $no => $line) {
                             $fromLine = $change['base']['offset'] + $no + 1;
                             $html .= '<tr>';
                             $html .= '<th>' . $fromLine . '</th>';
                             $html .= '<th>&nbsp;</th>';
                             $html .= '<td class="Left"><del>' . $line . '</del>&nbsp;</td>';
                             $html .= '</tr>';
                         }
                     } else {
                         if ($change['tag'] == 'replace') {
                             foreach ($change['base']['lines'] as $no => $line) {
                                 $fromLine = $change['base']['offset'] + $no + 1;
                                 $html .= '<tr>';
                                 $html .= '<th>' . $fromLine . '</th>';
                                 $html .= '<th>&nbsp;</th>';
                                 $html .= '<td class="Left"><span>' . $line . '</span></td>';
                                 $html .= '</tr>';
                             }
                             foreach ($change['changed']['lines'] as $no => $line) {
                                 $toLine = $change['changed']['offset'] + $no + 1;
                                 $html .= '<tr>';
                                 $html .= '<th>' . $toLine . '</th>';
                                 $html .= '<th>&nbsp;</th>';
                                 $html .= '<td class="Right"><span>' . $line . '</span></td>';
                                 $html .= '</tr>';
                             }
                         }
                     }
                 }
             }
             $html .= '</tbody>';
         }
     }
     $html .= '</table>';
     return $html;
 }
Beispiel #6
0
 /**
  * Render a and return diff with changes between the two sequences
  * displayed side by side.
  *
  * @return string The generated side by side diff.
  */
 public function render()
 {
     $changes = parent::render();
     $html = '';
     if (empty($changes)) {
         return $html;
     }
     $html .= '<table class="table table-hover table-diff">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th colspan="2">' . strip_tags($this->oldTitle) . '</th>';
     $html .= '<th colspan="2">' . strip_tags($this->newTitle) . '</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     foreach ($changes as $i => $blocks) {
         if ($i > 0) {
             $html .= '<tbody class="Skipped">';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '</tbody>';
         }
         foreach ($blocks as $change) {
             $html .= '<tbody class="diff-change-' . $change['tag'] . '">';
             // Equal changes should be shown on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $no => $line) {
                     $fromLine = $change['base']['offset'] + $no + 1;
                     $toLine = $change['changed']['offset'] + $no + 1;
                     $html .= '<tr>';
                     $html .= '<th>' . $fromLine . '</th>';
                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '<th>' . $toLine . '</th>';
                     $html .= '<td class="Right"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '</tr>';
                 }
             } else {
                 if ($change['tag'] == 'insert') {
                     foreach ($change['changed']['lines'] as $no => $line) {
                         $toLine = $change['changed']['offset'] + $no + 1;
                         $html .= '<tr>';
                         $html .= '<th>&nbsp;</th>';
                         $html .= '<td class="Left">&nbsp;</td>';
                         $html .= '<th>' . $toLine . '</th>';
                         $html .= '<td class="Right"><ins>' . $line . '</ins>&nbsp;</td>';
                         $html .= '</tr>';
                     }
                 } else {
                     if ($change['tag'] == 'delete') {
                         foreach ($change['base']['lines'] as $no => $line) {
                             $fromLine = $change['base']['offset'] + $no + 1;
                             $html .= '<tr>';
                             $html .= '<th>' . $fromLine . '</th>';
                             $html .= '<td class="Left"><del>' . $line . '</del>&nbsp;</td>';
                             $html .= '<th>&nbsp;</th>';
                             $html .= '<td class="Right">&nbsp;</td>';
                             $html .= '</tr>';
                         }
                     } else {
                         if ($change['tag'] == 'replace') {
                             if (count($change['base']['lines']) >= count($change['changed']['lines'])) {
                                 foreach ($change['base']['lines'] as $no => $line) {
                                     $fromLine = $change['base']['offset'] + $no + 1;
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     if (!isset($change['changed']['lines'][$no])) {
                                         $toLine = '&nbsp;';
                                         $changedLine = '&nbsp;';
                                     } else {
                                         $toLine = $change['base']['offset'] + $no + 1;
                                         $changedLine = '<span>' . $change['changed']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<th>' . $toLine . '</th>';
                                     $html .= '<td class="Right">' . $changedLine . '</td>';
                                     $html .= '</tr>';
                                 }
                             } else {
                                 foreach ($change['changed']['lines'] as $no => $changedLine) {
                                     if (!isset($change['base']['lines'][$no])) {
                                         $fromLine = '&nbsp;';
                                         $line = '&nbsp;';
                                     } else {
                                         $fromLine = $change['base']['offset'] + $no + 1;
                                         $line = '<span>' . $change['base']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     $toLine = $change['changed']['offset'] + $no + 1;
                                     $html .= '<th>' . $toLine . '</th>';
                                     $html .= '<td class="Right">' . $changedLine . '</td>';
                                     $html .= '</tr>';
                                 }
                             }
                         }
                     }
                 }
             }
             $html .= '</tbody>';
         }
     }
     $html .= '</table>';
     return $html;
 }
Beispiel #7
0
 /**
  * Render a and return diff with changes between the two sequences
  * displayed inline (under each other)
  *
  * @return string The generated inline diff.
  */
 public function render()
 {
     $changes = parent::render();
     $html = '';
     if (empty($changes)) {
         return $html;
     }
     //custom
     //一度に表示できる行数
     $displayLine = !empty($this->diff->options["display_line"]) ? $this->diff->options["display_line"] : NULL;
     //変更がある差分の行番号を表示するか
     $showChangeLine = !empty($this->diff->options["show_change_line"]) ? $this->diff->options["show_change_line"] : FALSE;
     $isNew = !empty($this->diff->options["is_new"]) ? $this->diff->options["is_new"] : FALSE;
     //1行のみの差分表示の有無
     $singleLine = !empty($this->diff->options["single_line"]) ? $this->diff->options["single_line"] : FALSE;
     $breakFlag = FALSE;
     $count = 0;
     $html .= '<table class="Differences DifferencesInline">';
     //		$html .= '<thead>';
     //		$html .= '<tr>';
     //		$html .= '<th>Old</th>';
     //		$html .= '<th>New</th>';
     //		$html .= '<th>Differences</th>';
     //		$html .= '</tr>';
     //		$html .= '</thead>';
     foreach ($changes as $i => $blocks) {
         // If this is a separate block, we're condensing code so output ...,
         // indicating a significant portion of the code has been collapsed as
         // it is the same
         if ($i > 0) {
             $html .= '<tbody class="Skipped">';
             if ($showChangeLine) {
                 $html .= '<th>&nbsp;</th>';
                 $html .= '<th>&nbsp;</th>';
             }
             $html .= '<td>&hellip;</td>';
             $html .= '</tbody>';
         }
         //custom
         if ($displayLine && $count > $displayLine && $breakFlag) {
             break;
         }
         foreach ($blocks as $change) {
             //custom
             if ($displayLine && $count > $displayLine && $breakFlag) {
                 break;
             }
             $html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
             // Equal changes should be shown on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $no => $line) {
                     $count++;
                     //custom
                     $fromLine = $change['base']['offset'] + $no + 1;
                     $toLine = $change['changed']['offset'] + $no + 1;
                     $html .= '<tr class="Left">';
                     if ($showChangeLine) {
                         $html .= '<td class="row_header">' . $fromLine . '</th>';
                         $html .= '<td class="row_header">' . $toLine . '</th>';
                     }
                     $html .= '<td class="row_content">' . $line . '</td>';
                     $html .= '</tr>';
                     //custom
                     if ($displayLine && $count > $displayLine && $breakFlag) {
                         break;
                     }
                 }
             } else {
                 if ($change['tag'] == 'insert') {
                     $breakFlag = TRUE;
                     foreach ($change['changed']['lines'] as $no => $line) {
                         $count++;
                         //custom
                         $toLine = $change['changed']['offset'] + $no + 1;
                         $html .= '<tr class="Right">';
                         if ($showChangeLine) {
                             $html .= '<td class="row_header">&nbsp;</th>';
                             $html .= '<td class="row_header">' . $toLine . '</th>';
                         }
                         $html .= '<td class="row_content"><ins>' . $line . '</ins>&nbsp;</td>';
                         $html .= '</tr>';
                         //custom
                         if ($displayLine && $count > $displayLine && $breakFlag) {
                             break;
                         }
                     }
                 } else {
                     if ($change['tag'] == 'delete') {
                         $breakFlag = TRUE;
                         foreach ($change['base']['lines'] as $no => $line) {
                             $count++;
                             $fromLine = $change['base']['offset'] + $no + 1;
                             $html .= '<tr class="Left">';
                             if ($showChangeLine) {
                                 $html .= '<td class="row_header">' . $fromLine . '</th>';
                                 $html .= '<td class="row_header">&nbsp;</th>';
                             }
                             $html .= '<td class="row_content"><del>' . $line . '</del>&nbsp;</td>';
                             $html .= '</tr>';
                             //custom
                             if ($displayLine && $count > $displayLine && $breakFlag) {
                                 break;
                             }
                         }
                     } else {
                         if ($change['tag'] == 'replace') {
                             $breakFlag = TRUE;
                             foreach ($change['base']['lines'] as $no => $line) {
                                 $count++;
                                 if (!$isNew) {
                                     $fromLine = $change['base']['offset'] + $no + 1;
                                     $html .= '<tr class="Left">';
                                     if ($showChangeLine) {
                                         $html .= '<td class="row_header">' . $fromLine . '</th>';
                                         $html .= '<td class="row_header">&nbsp;</th>';
                                     }
                                     if (!$singleLine || $singleLine && str_replace([" ", " ", "<del>", "</del>", "<ins>", "</ins>"], "", $line)) {
                                         $html .= '<td class="row_content"><span>' . $line . '</span></td>';
                                     }
                                     $html .= '</tr>';
                                 }
                                 //custom
                                 if ($displayLine && $count > $displayLine && $breakFlag) {
                                     break;
                                 }
                             }
                             foreach ($change['changed']['lines'] as $no => $line) {
                                 $count++;
                                 $toLine = $change['changed']['offset'] + $no + 1;
                                 $html .= '<tr class="Right">';
                                 if ($showChangeLine) {
                                     $html .= '<td class="row_header">&nbsp;</th>';
                                     $html .= '<td class="row_header">' . $toLine . '</th>';
                                 }
                                 if (!$singleLine || $singleLine && str_replace([" ", " ", "<del>", "</del>", "<ins>", "</ins>"], "", $line)) {
                                     $html .= '<td class="row_content"><span>' . $line . '</span></td>';
                                 }
                                 $html .= '</tr>';
                                 //custom
                                 if ($displayLine && $count > $displayLine && $breakFlag) {
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
             $html .= '</tbody>';
         }
         // for block
     }
     $html .= '</table>';
     return $html;
 }
 /**
  * Render a and return diff with changes between the two sequences
  * displayed side by side.
  *
  * @return string The generated side by side diff.
  */
 public function render()
 {
     $changes = parent::render();
     $html = '';
     if (empty($changes)) {
         return $html;
     }
     $html .= '<table class="Differences DifferencesSideBySide table table-striped" style="width: 100%">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th colspan="2" style="width: 50%">' . Sobi::Txt('HISTORY_REVISION_LOADED') . '</th>';
     $html .= '<th colspan="2" style="width: 50%">' . Sobi::Txt('HISTORY_REVISION_CURRENT') . '</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     foreach ($changes as $i => $blocks) {
         if ($i > 0) {
             $html .= '<tbody class="Skipped">';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '</tbody>';
         }
         foreach ($blocks as $change) {
             $html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
             // Equal changes should be shown on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $no => $line) {
                     $fromLine = $change['base']['offset'] + $no + 1;
                     $toLine = $change['changed']['offset'] + $no + 1;
                     $html .= '<tr>';
                     $html .= '<th>' . $fromLine . '</th>';
                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '<th>' . $toLine . '</th>';
                     $html .= '<td class="Right"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '</tr>';
                 }
             } else {
                 if ($change['tag'] == 'insert') {
                     foreach ($change['changed']['lines'] as $no => $line) {
                         $toLine = $change['changed']['offset'] + $no + 1;
                         $html .= '<tr>';
                         $html .= '<th>&nbsp;</th>';
                         $html .= '<td class="Left">&nbsp;</td>';
                         $html .= '<th>' . $toLine . '</th>';
                         $html .= '<td class="Right"><ins>' . $line . '</ins>&nbsp;</td>';
                         $html .= '</tr>';
                     }
                 } else {
                     if ($change['tag'] == 'delete') {
                         foreach ($change['base']['lines'] as $no => $line) {
                             $fromLine = $change['base']['offset'] + $no + 1;
                             $html .= '<tr>';
                             $html .= '<th>' . $fromLine . '</th>';
                             $html .= '<td class="Left"><del>' . $line . '</del>&nbsp;</td>';
                             $html .= '<th>&nbsp;</th>';
                             $html .= '<td class="Right">&nbsp;</td>';
                             $html .= '</tr>';
                         }
                     } else {
                         if ($change['tag'] == 'replace') {
                             if (count($change['base']['lines']) >= count($change['changed']['lines'])) {
                                 foreach ($change['base']['lines'] as $no => $line) {
                                     $fromLine = $change['base']['offset'] + $no + 1;
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     if (!isset($change['changed']['lines'][$no])) {
                                         $toLine = '&nbsp;';
                                         $changedLine = '&nbsp;';
                                     } else {
                                         $toLine = $change['base']['offset'] + $no + 1;
                                         $changedLine = '<span>' . $change['changed']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<th>' . $toLine . '</th>';
                                     $html .= '<td class="Right">' . $changedLine . '</td>';
                                     $html .= '</tr>';
                                 }
                             } else {
                                 foreach ($change['changed']['lines'] as $no => $changedLine) {
                                     if (!isset($change['base']['lines'][$no])) {
                                         $fromLine = '&nbsp;';
                                         $line = '&nbsp;';
                                     } else {
                                         $fromLine = $change['base']['offset'] + $no + 1;
                                         $line = '<span>' . $change['base']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     $toLine = $change['changed']['offset'] + $no + 1;
                                     $html .= '<th>' . $toLine . '</th>';
                                     $html .= '<td class="Right">' . $changedLine . '</td>';
                                     $html .= '</tr>';
                                 }
                             }
                         }
                     }
                 }
             }
             $html .= '</tbody>';
         }
     }
     $html .= '</table>';
     return $html;
 }
Beispiel #9
0
 /**
  * Render a and return diff with changes between the two sequences
  * displayed side by side.
  *
  * @return string The generated side by side diff.
  */
 public function render()
 {
     $changes = parent::render();
     $html = '';
     if (empty($changes)) {
         return $html;
     }
     //custom
     $oldVersion = !empty($this->diff->options["old_version_title"]) ? $this->diff->options["old_version_title"] : "Old Version";
     $newVersion = !empty($this->diff->options["new_version_title"]) ? $this->diff->options["new_version_title"] : "New Version";
     $html .= '<table class="show_diff_draft DifferencesSideBySide">';
     //        $html .= '<table class="Differences DifferencesSideBySide">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th colspan="2">' . $oldVersion . '</th>';
     $html .= '<th colspan="2">' . $newVersion . '</th>';
     //        $html .= '<th colspan="2">Old Version</th>';
     //        $html .= '<th colspan="2">New Version</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     foreach ($changes as $i => $blocks) {
         if ($i > 0) {
             $html .= '<tbody class="Skipped">';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '<th>&hellip;</th><td>&nbsp;</td>';
             $html .= '</tbody>';
         }
         foreach ($blocks as $change) {
             $html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
             // Equal changes should be shown on both sides of the diff
             if ($change['tag'] == 'equal') {
                 foreach ($change['base']['lines'] as $no => $line) {
                     $fromLine = $change['base']['offset'] + $no + 1;
                     $toLine = $change['changed']['offset'] + $no + 1;
                     $html .= '<tr>';
                     $html .= '<th>' . $fromLine . '</th>';
                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '<th>' . $toLine . '</th>';
                     $html .= '<td class="Right"><span>' . $line . '</span>&nbsp;</span></td>';
                     $html .= '</tr>';
                 }
             } else {
                 if ($change['tag'] == 'insert') {
                     foreach ($change['changed']['lines'] as $no => $line) {
                         $toLine = $change['changed']['offset'] + $no + 1;
                         $html .= '<tr>';
                         $html .= '<th>&nbsp;</th>';
                         $html .= '<td class="Left">&nbsp;</td>';
                         $html .= '<th>' . $toLine . '</th>';
                         $html .= '<td class="Right"><ins>' . $line . '</ins>&nbsp;</td>';
                         $html .= '</tr>';
                     }
                 } else {
                     if ($change['tag'] == 'delete') {
                         foreach ($change['base']['lines'] as $no => $line) {
                             $fromLine = $change['base']['offset'] + $no + 1;
                             $html .= '<tr>';
                             $html .= '<th>' . $fromLine . '</th>';
                             $html .= '<td class="Left"><del>' . $line . '</del>&nbsp;</td>';
                             $html .= '<th>&nbsp;</th>';
                             $html .= '<td class="Right">&nbsp;</td>';
                             $html .= '</tr>';
                         }
                     } else {
                         if ($change['tag'] == 'replace') {
                             if (count($change['base']['lines']) >= count($change['changed']['lines'])) {
                                 foreach ($change['base']['lines'] as $no => $line) {
                                     $fromLine = $change['base']['offset'] + $no + 1;
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     if (!isset($change['changed']['lines'][$no])) {
                                         $toLine = '&nbsp;';
                                         $changedLine = '&nbsp;';
                                     } else {
                                         $toLine = $change['base']['offset'] + $no + 1;
                                         $changedLine = '<span>' . $change['changed']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<th>' . $toLine . '</th>';
                                     if (is_numeric($toLine)) {
                                         $html .= '<td class="Right">' . $changedLine . '</td>';
                                     } else {
                                         $html .= '<td class="Right blank">' . $changedLine . '</td>';
                                     }
                                     $html .= '</tr>';
                                 }
                             } else {
                                 foreach ($change['changed']['lines'] as $no => $changedLine) {
                                     if (!isset($change['base']['lines'][$no])) {
                                         $fromLine = '&nbsp;';
                                         $line = '&nbsp;';
                                     } else {
                                         $fromLine = $change['base']['offset'] + $no + 1;
                                         $line = '<span>' . $change['base']['lines'][$no] . '</span>';
                                     }
                                     $html .= '<tr>';
                                     $html .= '<th>' . $fromLine . '</th>';
                                     if (is_numeric($fromLine)) {
                                         $html .= '<td class="Left"><span>' . $line . '</span>&nbsp;</td>';
                                     } else {
                                         $html .= '<td class="Left blank"><span>' . $line . '</span>&nbsp;</td>';
                                     }
                                     $toLine = $change['changed']['offset'] + $no + 1;
                                     $html .= '<th>' . $toLine . '</th>';
                                     $html .= '<td class="Right">' . $changedLine . '</td>';
                                     $html .= '</tr>';
                                 }
                             }
                         }
                     }
                 }
             }
             $html .= '</tbody>';
         }
     }
     $html .= '</table>';
     return $html;
 }