Changeset 877
- Timestamp:
- 12/26/07 04:28:00 (4 years ago)
- Location:
- trunk/www
- Files:
-
- 3 edited
-
controllers/textblock.php (modified) (3 diffs)
-
static/css/screen.css (modified) (1 diff)
-
views/textblock_diff.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/controllers/textblock.php
r852 r877 4 4 require_once(IA_ROOT_DIR . "common/db/textblock.php"); 5 5 require_once(IA_ROOT_DIR . "common/textblock.php"); 6 require_once(IA_ROOT_DIR . "common/diff.php"); 6 7 7 // smart ass diff8 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 }43 8 44 9 // View a plain textblock. … … 126 91 log_assert_valid(textblock_validate($revto)); 127 92 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'])); 130 95 131 96 $view = array(); … … 134 99 $view['revfrom_id'] = $revfrom_id; 135 100 $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; 138 103 execute_view_die('views/textblock_diff.php', $view); 139 104 } -
trunk/www/static/css/screen.css
r876 r877 683 683 .diff { 684 684 font-family: monospace; 685 border: #999988 solid 1px; 686 margin-bottom: 1em; 685 687 } 686 688 687 689 .diff .deleted { 688 display: block; 689 background-color: #F66; 690 background-color: #FFDDDD; 691 border: #CC0000 solid 1px; 692 display: block; 690 693 } 691 694 692 695 .diff .added { 693 display: block; 694 background-color: #6F6; 696 background-color: #DDFFDD; 697 border: #00AA00 solid 1px; 698 display: block; 695 699 } 696 700 697 701 .diff span { 698 margin: .5em 0 .5em 0; 699 display: block; 702 margin: .2em .2em; 700 703 } 701 704 -
trunk/www/views/textblock_diff.php
r852 r877 12 12 <?php 13 13 14 function diff_print_color_line($s) 15 { 16 if (preg_match("/^(---|\+\+\+)/", $s)) { 17 return; 14 function 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(' ', ' ', htmlentities($line)); 21 echo '<br/>'; 22 } 23 echo '</span>'; 24 } 25 echo '</div>'; 18 26 } 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>";31 27 } 32 28 33 if ( count($view['diff_title']) <= 1) {29 if (empty($view['diff_title'])) { 34 30 echo "<h3>Nu exista diferente intre titluri.</h3>"; 35 31 } 36 32 else { 37 33 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']); 44 35 } 45 36 ?> 46 37 47 38 <?php 48 if ( count($view['diff_content']) <= 1) {39 if (empty($view['diff_content'])) { 49 40 echo "<h3>Nu exista diferente intre continut.</h3>"; 50 41 } 51 42 else { 52 43 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']); 59 45 } 60 46 ?>
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)