home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / wiki / lib / diff.php < prev    next >
PHP Script  |  2004-03-08  |  1KB  |  48 lines

  1. <?php
  2. // $Id: diff.php,v 1.1 2004/01/12 22:14:05 comsubvie Exp $
  3.  
  4. // Compute the difference between two sets of text.
  5. function diff_compute($text1, $text2)
  6. {
  7.   global $TempDir, $DiffCmd;
  8.  
  9.   $num = function_exists('posix_getpid') ? posix_getpid() : rand();
  10.  
  11.   $temp1 = $TempDir . '/wiki_' . $num . '_1.txt';
  12.   $temp2 = $TempDir . '/wiki_' . $num . '_2.txt';
  13.  
  14.   if(!($h1 = fopen($temp1, 'w')) || !($h2 = fopen($temp2, 'w')))
  15.     { die(LIB_ErrorCreatingTemp); }
  16.  
  17.   if(fwrite($h1, $text1) < 0 || fwrite($h2, $text2) < 0)
  18.     { die(LIB_ErrorWritingTemp); }
  19.  
  20.   fclose($h1);
  21.   fclose($h2);
  22.  
  23.   if (ini_get('safe_mode') and
  24.      (ini_get('safe_mode_exec_dir') != dirname($DiffCmd))) 
  25.     { $diff = LIB_NoDiffAvailableSafeMode; }
  26.   else if (!file_exists($DiffCmd) or !is_readable($DiffCmd)) 
  27.     { $diff = LIB_NoDiffAvailable; }
  28.   else {
  29.     $output = array();
  30.     exec("$DiffCmd $temp1 $temp2", $output);
  31.     $diff = join("\n", $output);
  32.   }
  33.  
  34.   unlink($temp1);
  35.   unlink($temp2);
  36.  
  37.   return $diff;
  38. }
  39.  
  40. // Parse diff output into nice HTML.
  41. function diff_parse($text)
  42. {
  43.   global $DiffEngine;
  44.  
  45.   return parseText($text, $DiffEngine, '');
  46. }
  47.  
  48. ?>