Changeset 23811
- Timestamp:
- 03/27/2013 11:56:28 AM (12 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/pluggable.php
r23769 r23811 1746 1746 endif; 1747 1747 1748 if ( !function_exists( 'wp_text_diff_with_count' ) ) :1749 /**1750 * Displays a human readable HTML representation of the difference between two strings.1751 * similar to wp_text_diff, but tracks and returns could of lines added and removed1752 *1753 * @since 3.61754 * @see wp_parse_args() Used to change defaults to user defined settings.1755 * @uses Text_Diff1756 * @uses WP_Text_Diff_Renderer_Table1757 *1758 * @param string $left_string "old" (left) version of string1759 * @param string $right_string "new" (right) version of string1760 * @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults.1761 * @return array contains html, linesadded & linesdeletd, empty string if strings are equivalent.1762 */1763 function wp_text_diff_with_count( $left_string, $right_string, $args = null ) {1764 $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' );1765 $args = wp_parse_args( $args, $defaults );1766 1767 if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) )1768 require( ABSPATH . WPINC . '/wp-diff.php' );1769 1770 $left_string = normalize_whitespace( $left_string );1771 $right_string = normalize_whitespace( $right_string );1772 1773 $left_lines = explode( "\n", $left_string );1774 $right_lines = explode( "\n", $right_string) ;1775 1776 $text_diff = new Text_Diff($left_lines, $right_lines );1777 $linesadded = $text_diff->countAddedLines();1778 $linesdeleted = $text_diff->countDeletedLines();1779 1780 $renderer = new WP_Text_Diff_Renderer_Table();1781 $diff = $renderer->render( $text_diff );1782 1783 if ( !$diff )1784 return '';1785 1786 $r = "<table class='diff'>\n";1787 1788 if ( ! empty( $args[ 'show_split_view' ] ) ) {1789 $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";1790 } else {1791 $r .= "<col class='content' />";1792 }1793 1794 if ( $args['title'] || $args['title_left'] || $args['title_right'] )1795 $r .= "<thead>";1796 if ( $args['title'] )1797 $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";1798 if ( $args['title_left'] || $args['title_right'] ) {1799 $r .= "<tr class='diff-sub-title'>\n";1800 $r .= "\t<td></td><th>$args[title_left]</th>\n";1801 $r .= "\t<td></td><th>$args[title_right]</th>\n";1802 $r .= "</tr>\n";1803 }1804 if ( $args['title'] || $args['title_left'] || $args['title_right'] )1805 $r .= "</thead>\n";1806 1807 $r .= "<tbody>\n$diff\n</tbody>\n";1808 $r .= "</table>";1809 1810 return array( 'html' => $r, 'linesadded' => $linesadded, 'linesdeleted' => $linesdeleted );1811 }1812 endif; -
trunk/wp-includes/revision.php
r23769 r23811 143 143 * @since 2.6.0 144 144 * @uses wp_get_post_revisions() 145 * 145 * 146 146 * @param int $post_id The post ID. 147 147 * @param int $user_id optional The post author ID. … … 317 317 do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] ); 318 318 319 $restore_details = array( 320 'restored_revision_id' => $revision_id, 321 'restored_by_user' => get_current_user_id(), 322 'restored_time' => time() 323 ); 324 update_post_meta( $post_id, '_post_restored_from', $restore_details ); 325 319 326 return $post_id; 320 327 } … … 418 425 function wp_first_revision_matches_current_version( $post ) { 419 426 420 if ( ! $post = get_post( $post ) ) 421 return false; 422 423 if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) 424 return false; 425 426 $last_revision = array_shift( $revisions ); 427 428 if ( ! ($last_revision->post_modified == $post->post_modified ) ) 429 return false; 430 431 return true; 432 } 427 if ( ! $post = get_post( $post ) ) 428 return false; 429 430 if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) 431 return false; 432 433 $last_revision = array_shift( $revisions ); 434 435 if ( ! ($last_revision->post_modified == $post->post_modified ) ) 436 return false; 437 438 return true; 439 } 440 441 /** 442 * Displays a human readable HTML representation of the difference between two strings. 443 * similar to wp_text_diff, but tracks and returns could of lines added and removed 444 * 445 * @since 3.6 446 * @see wp_parse_args() Used to change defaults to user defined settings. 447 * @uses Text_Diff 448 * @uses WP_Text_Diff_Renderer_Table 449 * 450 * @param string $left_string "old" (left) version of string 451 * @param string $right_string "new" (right) version of string 452 * @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults. 453 * @return array contains html, linesadded & linesdeletd, empty string if strings are equivalent. 454 */ 455 function wp_text_diff_with_count( $left_string, $right_string, $args = null ) { 456 $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' ); 457 $args = wp_parse_args( $args, $defaults ); 458 459 if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) ) 460 require( ABSPATH . WPINC . '/wp-diff.php' ); 461 462 $left_string = normalize_whitespace( $left_string ); 463 $right_string = normalize_whitespace( $right_string ); 464 465 $left_lines = explode( "\n", $left_string ); 466 $right_lines = explode( "\n", $right_string) ; 467 468 $text_diff = new Text_Diff($left_lines, $right_lines ); 469 $linesadded = $text_diff->countAddedLines(); 470 $linesdeleted = $text_diff->countDeletedLines(); 471 472 $renderer = new WP_Text_Diff_Renderer_Table(); 473 $diff = $renderer->render( $text_diff ); 474 475 if ( !$diff ) 476 return ''; 477 478 $r = "<table class='diff'>\n"; 479 480 if ( ! empty( $args[ 'show_split_view' ] ) ) { 481 $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />"; 482 } else { 483 $r .= "<col class='content' />"; 484 } 485 486 if ( $args['title'] || $args['title_left'] || $args['title_right'] ) 487 $r .= "<thead>"; 488 if ( $args['title'] ) 489 $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n"; 490 if ( $args['title_left'] || $args['title_right'] ) { 491 $r .= "<tr class='diff-sub-title'>\n"; 492 $r .= "\t<td></td><th>$args[title_left]</th>\n"; 493 $r .= "\t<td></td><th>$args[title_right]</th>\n"; 494 $r .= "</tr>\n"; 495 } 496 if ( $args['title'] || $args['title_left'] || $args['title_right'] ) 497 $r .= "</thead>\n"; 498 499 $r .= "<tbody>\n$diff\n</tbody>\n"; 500 $r .= "</table>"; 501 502 return array( 'html' => $r, 'linesadded' => $linesadded, 'linesdeleted' => $linesdeleted ); 503 }
Note: See TracChangeset
for help on using the changeset viewer.