示例#1
0
/**
 * Compares two HTML files. (This is the main function that everything else supports.)
 * @param string $html1 XHTML for file 1  
 * @param string $html2 XHTML for file 2
 * @return array ($result1,$result2) to be displayed indicating the differences  
 */
function ouwiki_diff_html($html1, $html2)
{
    $lines1 = ouwiki_diff_html_to_lines($html1);
    $lines2 = ouwiki_diff_html_to_lines($html2);
    list($deleted, $added) = ouwiki_diff_words($lines1, $lines2);
    $result1 = ouwiki_diff_add_markers($html1, $deleted, 'ouw_deleted', '<strong class="accesshide">' . get_string('deletedbegins', 'wiki') . '</strong>', '<strong class="accesshide">' . get_string('deletedends', 'wiki') . '</strong>');
    $result2 = ouwiki_diff_add_markers($html2, $added, 'ouw_added', '<strong class="accesshide">' . get_string('addedbegins', 'wiki') . '</strong>', '<strong class="accesshide">' . get_string('addedends', 'wiki') . '</strong>');
    return array($result1, $result2);
}
/**
 * Compares two HTML files. (This is the main function that everything else supports.)
 * @param string $html1 XHTML for file 1  
 * @param string $html2 XHTML for file 2
 * @return array ($result1,$result2,$changes); result1 and result2 are XHTML 
 *   to be displayed indicating the differences, while $changes is the total
 *   number of changed (added or deleted) words. May be 0 if there are no
 *   differences or if differences are only to HTML 
 */
function ouwiki_diff_html($html1, $html2)
{
    $lines1 = ouwiki_diff_html_to_lines($html1);
    $lines2 = ouwiki_diff_html_to_lines($html2);
    list($deleted, $added) = ouwiki_diff_words($lines1, $lines2);
    $changes = count($deleted) + count($added);
    $result1 = ouwiki_diff_add_markers($html1, $deleted, 'ouw_deleted', '<img src="diff_deleted_begins.gif" alt="' . get_string('deletedbegins', 'ouwiki') . '" />', '<img src="diff_added_ends.gif" alt="' . get_string('deletedends', 'ouwiki') . '" />');
    $result2 = ouwiki_diff_add_markers($html2, $added, 'ouw_added', '<img src="diff_added_begins.gif" alt="' . get_string('addedbegins', 'ouwiki') . '" />', '<img src="diff_added_ends.gif" alt="' . get_string('addedends', 'ouwiki') . '" />');
    return array($result1, $result2, $changes);
}
 function test_splitter()
 {
     $lines = ouwiki_diff_html_to_lines($this->html1);
     $this->assertEqual(ouwiki_line::get_as_strings($lines), array(1 => "This is a long paragraph split over several lines and including bold and italic and span tags.", 2 => "This is a second paragraph.", 3 => "This div contain's some greengrocer's apostrophe's.", 4 => "A list", 5 => "With multiple items", 6 => "Some of them have multiple line breaks"));
     $lines = ouwiki_diff_html_to_lines($this->html2);
     $this->assertEqual(ouwiki_line::get_as_strings($lines), array(1 => "This is a long paragraph split over several lines and including bold and italic and span tags.", 2 => "This is a second paragraph which I have added some text to.", 3 => "This div contain's some greengrocer's apostrophe's.", 4 => "A", 5 => "Some of them have multiple line breaks"));
 }