raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Diff bastard child of old MediaWiki Diff Formatter.
mp-wp_genesis 4 *
mp-wp_genesis 5 * Basically all that remains is the table structure and some method names.
mp-wp_genesis 6 *
mp-wp_genesis 7 * @package WordPress
mp-wp_genesis 8 * @subpackage Diff
mp-wp_genesis 9 */
mp-wp_genesis 10
mp-wp_genesis 11 if ( !class_exists( 'Text_Diff' ) ) {
mp-wp_genesis 12 /** Text_Diff class */
mp-wp_genesis 13 require( dirname(__FILE__).'/Text/Diff.php' );
mp-wp_genesis 14 /** Text_Diff_Renderer class */
mp-wp_genesis 15 require( dirname(__FILE__).'/Text/Diff/Renderer.php' );
mp-wp_genesis 16 /** Text_Diff_Renderer_inline class */
mp-wp_genesis 17 require( dirname(__FILE__).'/Text/Diff/Renderer/inline.php' );
mp-wp_genesis 18 }
mp-wp_genesis 19
mp-wp_genesis 20 /**
mp-wp_genesis 21 * Table renderer to display the diff lines.
mp-wp_genesis 22 *
mp-wp_genesis 23 * @since 2.6.0
mp-wp_genesis 24 * @uses Text_Diff_Renderer Extends
mp-wp_genesis 25 */
mp-wp_genesis 26 class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
mp-wp_genesis 27
mp-wp_genesis 28 /**
mp-wp_genesis 29 * @see Text_Diff_Renderer::_leading_context_lines
mp-wp_genesis 30 * @var int
mp-wp_genesis 31 * @access protected
mp-wp_genesis 32 * @since 2.6.0
mp-wp_genesis 33 */
mp-wp_genesis 34 var $_leading_context_lines = 10000;
mp-wp_genesis 35
mp-wp_genesis 36 /**
mp-wp_genesis 37 * @see Text_Diff_Renderer::_trailing_context_lines
mp-wp_genesis 38 * @var int
mp-wp_genesis 39 * @access protected
mp-wp_genesis 40 * @since 2.6.0
mp-wp_genesis 41 */
mp-wp_genesis 42 var $_trailing_context_lines = 10000;
mp-wp_genesis 43
mp-wp_genesis 44 /**
mp-wp_genesis 45 * {@internal Missing Description}}
mp-wp_genesis 46 *
mp-wp_genesis 47 * @var float
mp-wp_genesis 48 * @access protected
mp-wp_genesis 49 * @since 2.6.0
mp-wp_genesis 50 */
mp-wp_genesis 51 var $_diff_threshold = 0.6;
mp-wp_genesis 52
mp-wp_genesis 53 /**
mp-wp_genesis 54 * Inline display helper object name.
mp-wp_genesis 55 *
mp-wp_genesis 56 * @var string
mp-wp_genesis 57 * @access protected
mp-wp_genesis 58 * @since 2.6.0
mp-wp_genesis 59 */
mp-wp_genesis 60 var $inline_diff_renderer = 'WP_Text_Diff_Renderer_inline';
mp-wp_genesis 61
mp-wp_genesis 62 /**
mp-wp_genesis 63 * PHP4 Constructor - Call parent constructor with params array.
mp-wp_genesis 64 *
mp-wp_genesis 65 * This will set class properties based on the key value pairs in the array.
mp-wp_genesis 66 *
mp-wp_genesis 67 * @since unknown
mp-wp_genesis 68 *
mp-wp_genesis 69 * @param array $params
mp-wp_genesis 70 */
mp-wp_genesis 71 function Text_Diff_Renderer_Table( $params = array() ) {
mp-wp_genesis 72 $parent = get_parent_class($this);
mp-wp_genesis 73 $this->$parent( $params );
mp-wp_genesis 74 }
mp-wp_genesis 75
mp-wp_genesis 76 /**
mp-wp_genesis 77 * @ignore
mp-wp_genesis 78 *
mp-wp_genesis 79 * @param string $header
mp-wp_genesis 80 * @return string
mp-wp_genesis 81 */
mp-wp_genesis 82 function _startBlock( $header ) {
mp-wp_genesis 83 return '';
mp-wp_genesis 84 }
mp-wp_genesis 85
mp-wp_genesis 86 /**
mp-wp_genesis 87 * @ignore
mp-wp_genesis 88 *
mp-wp_genesis 89 * @param array $lines
mp-wp_genesis 90 * @param string $prefix
mp-wp_genesis 91 */
mp-wp_genesis 92 function _lines( $lines, $prefix=' ' ) {
mp-wp_genesis 93 }
mp-wp_genesis 94
mp-wp_genesis 95 /**
mp-wp_genesis 96 * @ignore
mp-wp_genesis 97 *
mp-wp_genesis 98 * @param string $line HTML-escape the value.
mp-wp_genesis 99 * @return string
mp-wp_genesis 100 */
mp-wp_genesis 101 function addedLine( $line ) {
mp-wp_genesis 102 return "<td>+</td><td class='diff-addedline'>{$line}</td>";
mp-wp_genesis 103 }
mp-wp_genesis 104
mp-wp_genesis 105 /**
mp-wp_genesis 106 * @ignore
mp-wp_genesis 107 *
mp-wp_genesis 108 * @param string $line HTML-escape the value.
mp-wp_genesis 109 * @return string
mp-wp_genesis 110 */
mp-wp_genesis 111 function deletedLine( $line ) {
mp-wp_genesis 112 return "<td>-</td><td class='diff-deletedline'>{$line}</td>";
mp-wp_genesis 113 }
mp-wp_genesis 114
mp-wp_genesis 115 /**
mp-wp_genesis 116 * @ignore
mp-wp_genesis 117 *
mp-wp_genesis 118 * @param string $line HTML-escape the value.
mp-wp_genesis 119 * @return string
mp-wp_genesis 120 */
mp-wp_genesis 121 function contextLine( $line ) {
mp-wp_genesis 122 return "<td> </td><td class='diff-context'>{$line}</td>";
mp-wp_genesis 123 }
mp-wp_genesis 124
mp-wp_genesis 125 /**
mp-wp_genesis 126 * @ignore
mp-wp_genesis 127 *
mp-wp_genesis 128 * @return string
mp-wp_genesis 129 */
mp-wp_genesis 130 function emptyLine() {
mp-wp_genesis 131 return '<td colspan="2">&nbsp;</td>';
mp-wp_genesis 132 }
mp-wp_genesis 133
mp-wp_genesis 134 /**
mp-wp_genesis 135 * @ignore
mp-wp_genesis 136 * @access private
mp-wp_genesis 137 *
mp-wp_genesis 138 * @param array $lines
mp-wp_genesis 139 * @param bool $encode
mp-wp_genesis 140 * @return string
mp-wp_genesis 141 */
mp-wp_genesis 142 function _added( $lines, $encode = true ) {
mp-wp_genesis 143 $r = '';
mp-wp_genesis 144 foreach ($lines as $line) {
mp-wp_genesis 145 if ( $encode )
mp-wp_genesis 146 $line = htmlspecialchars( $line );
mp-wp_genesis 147 $r .= '<tr>' . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
mp-wp_genesis 148 }
mp-wp_genesis 149 return $r;
mp-wp_genesis 150 }
mp-wp_genesis 151
mp-wp_genesis 152 /**
mp-wp_genesis 153 * @ignore
mp-wp_genesis 154 * @access private
mp-wp_genesis 155 *
mp-wp_genesis 156 * @param array $lines
mp-wp_genesis 157 * @param bool $encode
mp-wp_genesis 158 * @return string
mp-wp_genesis 159 */
mp-wp_genesis 160 function _deleted( $lines, $encode = true ) {
mp-wp_genesis 161 $r = '';
mp-wp_genesis 162 foreach ($lines as $line) {
mp-wp_genesis 163 if ( $encode )
mp-wp_genesis 164 $line = htmlspecialchars( $line );
mp-wp_genesis 165 $r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . "</tr>\n";
mp-wp_genesis 166 }
mp-wp_genesis 167 return $r;
mp-wp_genesis 168 }
mp-wp_genesis 169
mp-wp_genesis 170 /**
mp-wp_genesis 171 * @ignore
mp-wp_genesis 172 * @access private
mp-wp_genesis 173 *
mp-wp_genesis 174 * @param array $lines
mp-wp_genesis 175 * @param bool $encode
mp-wp_genesis 176 * @return string
mp-wp_genesis 177 */
mp-wp_genesis 178 function _context( $lines, $encode = true ) {
mp-wp_genesis 179 $r = '';
mp-wp_genesis 180 foreach ($lines as $line) {
mp-wp_genesis 181 if ( $encode )
mp-wp_genesis 182 $line = htmlspecialchars( $line );
mp-wp_genesis 183 $r .= '<tr>' .
mp-wp_genesis 184 $this->contextLine( $line ) . $this->contextLine( $line ) . "</tr>\n";
mp-wp_genesis 185 }
mp-wp_genesis 186 return $r;
mp-wp_genesis 187 }
mp-wp_genesis 188
mp-wp_genesis 189 /**
mp-wp_genesis 190 * Process changed lines to do word-by-word diffs for extra highlighting.
mp-wp_genesis 191 *
mp-wp_genesis 192 * (TRAC style) sometimes these lines can actually be deleted or added rows.
mp-wp_genesis 193 * We do additional processing to figure that out
mp-wp_genesis 194 *
mp-wp_genesis 195 * @access private
mp-wp_genesis 196 * @since 2.6.0
mp-wp_genesis 197 *
mp-wp_genesis 198 * @param array $orig
mp-wp_genesis 199 * @param array $final
mp-wp_genesis 200 * @return string
mp-wp_genesis 201 */
mp-wp_genesis 202 function _changed( $orig, $final ) {
mp-wp_genesis 203 $r = '';
mp-wp_genesis 204
mp-wp_genesis 205 // Does the aforementioned additional processing
mp-wp_genesis 206 // *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes
mp-wp_genesis 207 // match is numeric: an index in other column
mp-wp_genesis 208 // match is 'X': no match. It is a new row
mp-wp_genesis 209 // *_rows are column vectors for the orig column and the final column.
mp-wp_genesis 210 // row >= 0: an indix of the $orig or $final array
mp-wp_genesis 211 // row < 0: a blank row for that column
mp-wp_genesis 212 list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final );
mp-wp_genesis 213
mp-wp_genesis 214
mp-wp_genesis 215 // These will hold the word changes as determined by an inline diff
mp-wp_genesis 216 $orig_diffs = array();
mp-wp_genesis 217 $final_diffs = array();
mp-wp_genesis 218
mp-wp_genesis 219 // Compute word diffs for each matched pair using the inline diff
mp-wp_genesis 220 foreach ( $orig_matches as $o => $f ) {
mp-wp_genesis 221 if ( is_numeric($o) && is_numeric($f) ) {
mp-wp_genesis 222 $text_diff = new Text_Diff( 'auto', array( array($orig[$o]), array($final[$f]) ) );
mp-wp_genesis 223 $renderer = new $this->inline_diff_renderer;
mp-wp_genesis 224 $diff = $renderer->render( $text_diff );
mp-wp_genesis 225
mp-wp_genesis 226 // If they're too different, don't include any <ins> or <dels>
mp-wp_genesis 227 if ( $diff_count = preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) {
mp-wp_genesis 228 // length of all text between <ins> or <del>
mp-wp_genesis 229 $stripped_matches = strlen(strip_tags( join(' ', $diff_matches[0]) ));
mp-wp_genesis 230 // since we count lengith of text between <ins> or <del> (instead of picking just one),
mp-wp_genesis 231 // we double the length of chars not in those tags.
mp-wp_genesis 232 $stripped_diff = strlen(strip_tags( $diff )) * 2 - $stripped_matches;
mp-wp_genesis 233 $diff_ratio = $stripped_matches / $stripped_diff;
mp-wp_genesis 234 if ( $diff_ratio > $this->_diff_threshold )
mp-wp_genesis 235 continue; // Too different. Don't save diffs.
mp-wp_genesis 236 }
mp-wp_genesis 237
mp-wp_genesis 238 // Un-inline the diffs by removing del or ins
mp-wp_genesis 239 $orig_diffs[$o] = preg_replace( '|<ins>.*?</ins>|', '', $diff );
mp-wp_genesis 240 $final_diffs[$f] = preg_replace( '|<del>.*?</del>|', '', $diff );
mp-wp_genesis 241 }
mp-wp_genesis 242 }
mp-wp_genesis 243
mp-wp_genesis 244 foreach ( array_keys($orig_rows) as $row ) {
mp-wp_genesis 245 // Both columns have blanks. Ignore them.
mp-wp_genesis 246 if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 )
mp-wp_genesis 247 continue;
mp-wp_genesis 248
mp-wp_genesis 249 // If we have a word based diff, use it. Otherwise, use the normal line.
mp-wp_genesis 250 $orig_line = isset($orig_diffs[$orig_rows[$row]])
mp-wp_genesis 251 ? $orig_diffs[$orig_rows[$row]]
mp-wp_genesis 252 : htmlspecialchars($orig[$orig_rows[$row]]);
mp-wp_genesis 253 $final_line = isset($final_diffs[$final_rows[$row]])
mp-wp_genesis 254 ? $final_diffs[$final_rows[$row]]
mp-wp_genesis 255 : htmlspecialchars($final[$final_rows[$row]]);
mp-wp_genesis 256
mp-wp_genesis 257 if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row.
mp-wp_genesis 258 $r .= $this->_added( array($final_line), false );
mp-wp_genesis 259 } elseif ( $final_rows[$row] < 0 ) { // Final is blank. This is really a deleted row.
mp-wp_genesis 260 $r .= $this->_deleted( array($orig_line), false );
mp-wp_genesis 261 } else { // A true changed row.
mp-wp_genesis 262 $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->addedLine( $final_line ) . "</tr>\n";
mp-wp_genesis 263 }
mp-wp_genesis 264 }
mp-wp_genesis 265
mp-wp_genesis 266 return $r;
mp-wp_genesis 267 }
mp-wp_genesis 268
mp-wp_genesis 269 /**
mp-wp_genesis 270 * Takes changed blocks and matches which rows in orig turned into which rows in final.
mp-wp_genesis 271 *
mp-wp_genesis 272 * Returns
mp-wp_genesis 273 * *_matches ( which rows match with which )
mp-wp_genesis 274 * *_rows ( order of rows in each column interleaved with blank rows as
mp-wp_genesis 275 * necessary )
mp-wp_genesis 276 *
mp-wp_genesis 277 * @since 2.6.0
mp-wp_genesis 278 *
mp-wp_genesis 279 * @param unknown_type $orig
mp-wp_genesis 280 * @param unknown_type $final
mp-wp_genesis 281 * @return unknown
mp-wp_genesis 282 */
mp-wp_genesis 283 function interleave_changed_lines( $orig, $final ) {
mp-wp_genesis 284
mp-wp_genesis 285 // Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array.
mp-wp_genesis 286 $matches = array();
mp-wp_genesis 287 foreach ( array_keys($orig) as $o ) {
mp-wp_genesis 288 foreach ( array_keys($final) as $f ) {
mp-wp_genesis 289 $matches["$o,$f"] = $this->compute_string_distance( $orig[$o], $final[$f] );
mp-wp_genesis 290 }
mp-wp_genesis 291 }
mp-wp_genesis 292 asort($matches); // Order by string distance.
mp-wp_genesis 293
mp-wp_genesis 294 $orig_matches = array();
mp-wp_genesis 295 $final_matches = array();
mp-wp_genesis 296
mp-wp_genesis 297 foreach ( $matches as $keys => $difference ) {
mp-wp_genesis 298 list($o, $f) = explode(',', $keys);
mp-wp_genesis 299 $o = (int) $o;
mp-wp_genesis 300 $f = (int) $f;
mp-wp_genesis 301
mp-wp_genesis 302 // Already have better matches for these guys
mp-wp_genesis 303 if ( isset($orig_matches[$o]) && isset($final_matches[$f]) )
mp-wp_genesis 304 continue;
mp-wp_genesis 305
mp-wp_genesis 306 // First match for these guys. Must be best match
mp-wp_genesis 307 if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) {
mp-wp_genesis 308 $orig_matches[$o] = $f;
mp-wp_genesis 309 $final_matches[$f] = $o;
mp-wp_genesis 310 continue;
mp-wp_genesis 311 }
mp-wp_genesis 312
mp-wp_genesis 313 // Best match of this final is already taken? Must mean this final is a new row.
mp-wp_genesis 314 if ( isset($orig_matches[$o]) )
mp-wp_genesis 315 $final_matches[$f] = 'x';
mp-wp_genesis 316
mp-wp_genesis 317 // Best match of this orig is already taken? Must mean this orig is a deleted row.
mp-wp_genesis 318 elseif ( isset($final_matches[$f]) )
mp-wp_genesis 319 $orig_matches[$o] = 'x';
mp-wp_genesis 320 }
mp-wp_genesis 321
mp-wp_genesis 322 // We read the text in this order
mp-wp_genesis 323 ksort($orig_matches);
mp-wp_genesis 324 ksort($final_matches);
mp-wp_genesis 325
mp-wp_genesis 326
mp-wp_genesis 327 // Stores rows and blanks for each column.
mp-wp_genesis 328 $orig_rows = $orig_rows_copy = array_keys($orig_matches);
mp-wp_genesis 329 $final_rows = array_keys($final_matches);
mp-wp_genesis 330
mp-wp_genesis 331 // Interleaves rows with blanks to keep matches aligned.
mp-wp_genesis 332 // We may end up with some extraneous blank rows, but we'll just ignore them later.
mp-wp_genesis 333 foreach ( $orig_rows_copy as $orig_row ) {
mp-wp_genesis 334 $final_pos = array_search($orig_matches[$orig_row], $final_rows, true);
mp-wp_genesis 335 $orig_pos = (int) array_search($orig_row, $orig_rows, true);
mp-wp_genesis 336
mp-wp_genesis 337 if ( false === $final_pos ) { // This orig is paired with a blank final.
mp-wp_genesis 338 array_splice( $final_rows, $orig_pos, 0, -1 );
mp-wp_genesis 339 } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows.
mp-wp_genesis 340 $diff_pos = $final_pos - $orig_pos;
mp-wp_genesis 341 while ( $diff_pos < 0 )
mp-wp_genesis 342 array_splice( $final_rows, $orig_pos, 0, $diff_pos++ );
mp-wp_genesis 343 } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows.
mp-wp_genesis 344 $diff_pos = $orig_pos - $final_pos;
mp-wp_genesis 345 while ( $diff_pos < 0 )
mp-wp_genesis 346 array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ );
mp-wp_genesis 347 }
mp-wp_genesis 348 }
mp-wp_genesis 349
mp-wp_genesis 350
mp-wp_genesis 351 // Pad the ends with blank rows if the columns aren't the same length
mp-wp_genesis 352 $diff_count = count($orig_rows) - count($final_rows);
mp-wp_genesis 353 if ( $diff_count < 0 ) {
mp-wp_genesis 354 while ( $diff_count < 0 )
mp-wp_genesis 355 array_push($orig_rows, $diff_count++);
mp-wp_genesis 356 } elseif ( $diff_count > 0 ) {
mp-wp_genesis 357 $diff_count = -1 * $diff_count;
mp-wp_genesis 358 while ( $diff_count < 0 )
mp-wp_genesis 359 array_push($final_rows, $diff_count++);
mp-wp_genesis 360 }
mp-wp_genesis 361
mp-wp_genesis 362 return array($orig_matches, $final_matches, $orig_rows, $final_rows);
mp-wp_genesis 363
mp-wp_genesis 364 /*
mp-wp_genesis 365 // Debug
mp-wp_genesis 366 echo "\n\n\n\n\n";
mp-wp_genesis 367
mp-wp_genesis 368 echo "-- DEBUG Matches: Orig -> Final --";
mp-wp_genesis 369
mp-wp_genesis 370 foreach ( $orig_matches as $o => $f ) {
mp-wp_genesis 371 echo "\n\n\n\n\n";
mp-wp_genesis 372 echo "ORIG: $o, FINAL: $f\n";
mp-wp_genesis 373 var_dump($orig[$o],$final[$f]);
mp-wp_genesis 374 }
mp-wp_genesis 375 echo "\n\n\n\n\n";
mp-wp_genesis 376
mp-wp_genesis 377 echo "-- DEBUG Matches: Final -> Orig --";
mp-wp_genesis 378
mp-wp_genesis 379 foreach ( $final_matches as $f => $o ) {
mp-wp_genesis 380 echo "\n\n\n\n\n";
mp-wp_genesis 381 echo "FINAL: $f, ORIG: $o\n";
mp-wp_genesis 382 var_dump($final[$f],$orig[$o]);
mp-wp_genesis 383 }
mp-wp_genesis 384 echo "\n\n\n\n\n";
mp-wp_genesis 385
mp-wp_genesis 386 echo "-- DEBUG Rows: Orig -- Final --";
mp-wp_genesis 387
mp-wp_genesis 388 echo "\n\n\n\n\n";
mp-wp_genesis 389 foreach ( $orig_rows as $row => $o ) {
mp-wp_genesis 390 if ( $o < 0 )
mp-wp_genesis 391 $o = 'X';
mp-wp_genesis 392 $f = $final_rows[$row];
mp-wp_genesis 393 if ( $f < 0 )
mp-wp_genesis 394 $f = 'X';
mp-wp_genesis 395 echo "$o -- $f\n";
mp-wp_genesis 396 }
mp-wp_genesis 397 echo "\n\n\n\n\n";
mp-wp_genesis 398
mp-wp_genesis 399 echo "-- END DEBUG --";
mp-wp_genesis 400
mp-wp_genesis 401 echo "\n\n\n\n\n";
mp-wp_genesis 402
mp-wp_genesis 403 return array($orig_matches, $final_matches, $orig_rows, $final_rows);
mp-wp_genesis 404 */
mp-wp_genesis 405 }
mp-wp_genesis 406
mp-wp_genesis 407 /**
mp-wp_genesis 408 * Computes a number that is intended to reflect the "distance" between two strings.
mp-wp_genesis 409 *
mp-wp_genesis 410 * @since 2.6.0
mp-wp_genesis 411 *
mp-wp_genesis 412 * @param string $string1
mp-wp_genesis 413 * @param string $string2
mp-wp_genesis 414 * @return int
mp-wp_genesis 415 */
mp-wp_genesis 416 function compute_string_distance( $string1, $string2 ) {
mp-wp_genesis 417 // Vectors containing character frequency for all chars in each string
mp-wp_genesis 418 $chars1 = count_chars($string1);
mp-wp_genesis 419 $chars2 = count_chars($string2);
mp-wp_genesis 420
mp-wp_genesis 421 // L1-norm of difference vector.
mp-wp_genesis 422 $difference = array_sum( array_map( array(&$this, 'difference'), $chars1, $chars2 ) );
mp-wp_genesis 423
mp-wp_genesis 424 // $string1 has zero length? Odd. Give huge penalty by not dividing.
mp-wp_genesis 425 if ( !$string1 )
mp-wp_genesis 426 return $difference;
mp-wp_genesis 427
mp-wp_genesis 428 // Return distance per charcter (of string1)
mp-wp_genesis 429 return $difference / strlen($string1);
mp-wp_genesis 430 }
mp-wp_genesis 431
mp-wp_genesis 432 /**
mp-wp_genesis 433 * @ignore
mp-wp_genesis 434 * @since 2.6.0
mp-wp_genesis 435 *
mp-wp_genesis 436 * @param int $a
mp-wp_genesis 437 * @param int $b
mp-wp_genesis 438 * @return int
mp-wp_genesis 439 */
mp-wp_genesis 440 function difference( $a, $b ) {
mp-wp_genesis 441 return abs( $a - $b );
mp-wp_genesis 442 }
mp-wp_genesis 443
mp-wp_genesis 444 }
mp-wp_genesis 445
mp-wp_genesis 446 /**
mp-wp_genesis 447 * Better word splitting than the PEAR package provides.
mp-wp_genesis 448 *
mp-wp_genesis 449 * @since 2.6.0
mp-wp_genesis 450 * @uses Text_Diff_Renderer_inline Extends
mp-wp_genesis 451 */
mp-wp_genesis 452 class WP_Text_Diff_Renderer_inline extends Text_Diff_Renderer_inline {
mp-wp_genesis 453
mp-wp_genesis 454 /**
mp-wp_genesis 455 * @ignore
mp-wp_genesis 456 * @since 2.6.0
mp-wp_genesis 457 *
mp-wp_genesis 458 * @param string $string
mp-wp_genesis 459 * @param string $newlineEscape
mp-wp_genesis 460 * @return string
mp-wp_genesis 461 */
mp-wp_genesis 462 function _splitOnWords($string, $newlineEscape = "\n") {
mp-wp_genesis 463 $string = str_replace("\0", '', $string);
mp-wp_genesis 464 $words = preg_split( '/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
mp-wp_genesis 465 $words = str_replace( "\n", $newlineEscape, $words );
mp-wp_genesis 466 return $words;
mp-wp_genesis 467 }
mp-wp_genesis 468
mp-wp_genesis 469 }
mp-wp_genesis 470
mp-wp_genesis 471 ?>