WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/21/2013 03:54:11 PM (8 years ago)
Author:
westi
Message:

Revisions: UI Update.

  • Refines the UI to make it clearer and easier to use
  • Introduces weighted tickmarks
  • Fixes comparison bugs.

See #23497 props adamsilverstein

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/pluggable.php

    r23639 r23769  
    17451745}
    17461746endif;
     1747
     1748if ( !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 removed
     1752 *
     1753 * @since 3.6
     1754 * @see wp_parse_args() Used to change defaults to user defined settings.
     1755 * @uses Text_Diff
     1756 * @uses WP_Text_Diff_Renderer_Table
     1757 *
     1758 * @param string $left_string "old" (left) version of string
     1759 * @param string $right_string "new" (right) version of string
     1760 * @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 */
     1763function 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;
Note: See TracChangeset for help on using the changeset viewer.