_show_split_view = $params['show_split_view'];
}
}
/**
* @ignore
*
* @param string $header
* @return string
*/
public function _startBlock( $header ) {
return '';
}
/**
* @ignore
*
* @param array $lines
* @param string $prefix
*/
public function _lines( $lines, $prefix = ' ' ) {
}
/**
* @ignore
*
* @param string $line HTML-escape the value.
* @return string
*/
public function addedLine( $line ) {
return "
";
}
/**
* @ignore
*
* @param string $line HTML-escape the value.
* @return string
*/
public function deletedLine( $line ) {
return "
";
}
/**
* @ignore
*
* @param string $line HTML-escape the value.
* @return string
*/
public function contextLine( $line ) {
return "
";
}
/**
* @ignore
*
* @return string
*/
public function emptyLine() {
return '
';
}
/**
* @ignore
*
* @param array $lines
* @param bool $encode
* @return string
*/
public function _added( $lines, $encode = true ) {
$r = '';
foreach ( $lines as $line ) {
if ( $encode ) {
$processed_line = htmlspecialchars( $line );
/**
* Contextually filters a diffed line.
*
* Filters TextDiff processing of diffed line. By default, diffs are processed with
* htmlspecialchars. Use this filter to remove or change the processing. Passes a context
* indicating if the line is added, deleted or unchanged.
*
* @since 4.1.0
*
* @param string $processed_line The processed diffed line.
* @param string $line The unprocessed diffed line.
* @param string $context The line context. Values are 'added', 'deleted' or 'unchanged'.
*/
$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' );
}
if ( $this->_show_split_view ) {
$r .= '
\n";
}
}
return $r;
}
/**
* @ignore
*
* @param array $lines
* @param bool $encode
* @return string
*/
public function _deleted( $lines, $encode = true ) {
$r = '';
foreach ( $lines as $line ) {
if ( $encode ) {
$processed_line = htmlspecialchars( $line );
/** This filter is documented in wp-includes/wp-diff.php */
$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'deleted' );
}
if ( $this->_show_split_view ) {
$r .= '
\n";
}
}
return $r;
}
/**
* @ignore
*
* @param array $lines
* @param bool $encode
* @return string
*/
public function _context( $lines, $encode = true ) {
$r = '';
foreach ( $lines as $line ) {
if ( $encode ) {
$processed_line = htmlspecialchars( $line );
/** This filter is documented in wp-includes/wp-diff.php */
$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'unchanged' );
}
if ( $this->_show_split_view ) {
$r .= '
\n";
}
}
return $r;
}
/**
* Process changed lines to do word-by-word diffs for extra highlighting.
*
* (TRAC style) sometimes these lines can actually be deleted or added rows.
* We do additional processing to figure that out
*
* @since 2.6.0
*
* @param array $orig
* @param array $final
* @return string
*/
public function _changed( $orig, $final ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.finalFound
$r = '';
/*
* Does the aforementioned additional processing:
* *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes.
* - match is numeric: an index in other column.
* - match is 'X': no match. It is a new row.
* *_rows are column vectors for the orig column and the final column.
* - row >= 0: an index of the $orig or $final array.
* - row < 0: a blank row for that column.
*/
list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final );
// These will hold the word changes as determined by an inline diff.
$orig_diffs = array();
$final_diffs = array();
// Compute word diffs for each matched pair using the inline diff.
foreach ( $orig_matches as $o => $f ) {
if ( is_numeric( $o ) && is_numeric( $f ) ) {
$text_diff = new Text_Diff( 'auto', array( array( $orig[ $o ] ), array( $final[ $f ] ) ) );
$renderer = new $this->inline_diff_renderer();
$diff = $renderer->render( $text_diff );
// If they're too different, don't include any