Changeset 877


Ignore:
Timestamp:
12/26/07 04:28:00 (4 years ago)
Author:
bogdanpasoi@…
Message:

New diff.

Location:
trunk/www
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/controllers/textblock.php

    r852 r877  
    44require_once(IA_ROOT_DIR . "common/db/textblock.php"); 
    55require_once(IA_ROOT_DIR . "common/textblock.php"); 
     6require_once(IA_ROOT_DIR . "common/diff.php"); 
    67 
    7 // smart ass diff 
    8 function string_diff($string1, $string2) { 
    9     $name1 = tempnam(IA_ROOT_DIR.'attach/', "ia"); 
    10     $name2 = tempnam(IA_ROOT_DIR.'attach/', "ia"); 
    11     $fp1 = fopen($name1, "w"); 
    12     if (!$fp1) { 
    13         flash_error("Eroare la comparare!"); 
    14         request(url_home()); 
    15     } 
    16     $string1 .= "\n"; 
    17     fputs($fp1, $string1); 
    18     fclose($fp1); 
    19  
    20     $fp2 = fopen($name2, "w"); 
    21     if (!$fp2) { 
    22         flash_error("Eroare la comparare!"); 
    23         request(url_home()); 
    24     } 
    25     $string2 .= "\n"; 
    26     fputs($fp2, $string2); 
    27     fclose($fp2); 
    28  
    29     ob_start(); 
    30     system("diff -au ".$name1." ".$name2); 
    31     $ret = ob_get_contents(); 
    32     ob_end_clean(); 
    33     if (!unlink($name1)) { 
    34         flash_error("Eroare la comparare!"); 
    35         request(url_home()); 
    36     } 
    37     if (!unlink($name2)) { 
    38         flash_error("Eroare la comparare!"); 
    39         request(url_home()); 
    40     } 
    41     return $ret; 
    42 } 
    438 
    449// View a plain textblock. 
     
    12691    log_assert_valid(textblock_validate($revto)); 
    12792 
    128     $diff_title = string_diff($revfrom['title'], $revto['title']); 
    129     $diff_content = string_diff($revfrom['text'], $revto['text']); 
     93    $diff_title = string_diff(array($revfrom['title'], $revto['title'])); 
     94    $diff_content = string_diff(array($revfrom['text'], $revto['text'])); 
    13095 
    13196    $view = array(); 
     
    13499    $view['revfrom_id'] = $revfrom_id; 
    135100    $view['revto_id'] = $revto_id; 
    136     $view['diff_title'] = explode("\n", $diff_title); 
    137     $view['diff_content'] = explode("\n", $diff_content); 
     101    $view['diff_title'] = $diff_title; 
     102    $view['diff_content'] = $diff_content; 
    138103    execute_view_die('views/textblock_diff.php', $view); 
    139104} 
  • trunk/www/static/css/screen.css

    r876 r877  
    683683.diff { 
    684684    font-family: monospace; 
     685    border: #999988 solid 1px;   
     686    margin-bottom: 1em; 
    685687} 
    686688 
    687689.diff .deleted { 
    688     display: block; 
    689     background-color: #F66; 
     690    background-color: #FFDDDD; 
     691    border: #CC0000 solid 1px; 
     692    display: block; 
    690693} 
    691694 
    692695.diff .added { 
    693     display: block; 
    694     background-color: #6F6; 
     696    background-color: #DDFFDD; 
     697    border: #00AA00 solid 1px; 
     698    display: block; 
    695699} 
    696700 
    697701.diff span { 
    698     margin: .5em 0 .5em 0; 
    699     display: block; 
     702    margin: .2em .2em; 
    700703} 
    701704 
  • trunk/www/views/textblock_diff.php

    r852 r877  
    1212<?php 
    1313 
    14 function diff_print_color_line($s) 
    15 { 
    16     if (preg_match("/^(---|\+\+\+)/", $s)) { 
    17         return; 
     14function print_diff($diff) { 
     15    foreach ($diff as $block) { 
     16        echo '<div class="diff">'; 
     17        foreach ($block as $op) { 
     18            echo '<span class="'.$op['type'].'">'; 
     19            foreach ($op['lines'] as $line) { 
     20                echo str_replace('  ', '&nbsp;&nbsp;', htmlentities($line)); 
     21                echo '<br/>'; 
     22            } 
     23            echo '</span>'; 
     24        } 
     25        echo '</div>'; 
    1826    } 
    19     if (preg_match("/^(@@)/", $s)) { 
    20         echo "<hr />"; 
    21         return; 
    22     } 
    23     if (strlen($s) > 0 && $s[0] == '+') { 
    24         $class = "added"; 
    25     } else if (strlen($s) > 0 && $s[0] == '-') { 
    26         $class = "deleted"; 
    27     } else { 
    28         $class = "normal"; 
    29     } 
    30     echo "<span class=\"$class\">".htmlentities(substr($s, 1))."</span>"; 
    3127} 
    3228 
    33 if (count($view['diff_title']) <= 1) { 
     29if (empty($view['diff_title'])) { 
    3430    echo "<h3>Nu exista diferente intre titluri.</h3>"; 
    3531} 
    3632else { 
    3733    echo "<h3>Diferente intre titluri:</h3>"; 
    38     echo "<div class=\"diff\">"; 
    39     for ($i = 0; $i+1 < count($view['diff_title']); $i++) { 
    40         $s = $view['diff_title'][$i]; 
    41         $class = diff_print_color_line($s); 
    42     } 
    43     echo "</div>"; 
     34    print_diff($view['diff_title']); 
    4435} 
    4536?> 
    4637 
    4738<?php 
    48 if (count($view['diff_content']) <= 1) { 
     39if (empty($view['diff_content'])) { 
    4940    echo "<h3>Nu exista diferente intre continut.</h3>"; 
    5041} 
    5142else { 
    5243    echo "<h3>Diferente intre continut:</h3>"; 
    53     echo '<div class="diff">'; 
    54     for ($i = 0; $i+1 < count($view['diff_content']); $i++) { 
    55         $s = $view['diff_content'][$i]; 
    56         $class = diff_print_color_line($s); 
    57     } 
    58     echo "</div>"; 
     44    print_diff($view['diff_content']); 
    5945} 
    6046?> 
Note: See TracChangeset for help on using the changeset viewer.