Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

t3lib_diff Class Reference

List of all members.

Public Member Functions

 makeDiffDisplay ($str1, $str2)
 This will produce a color-marked-up diff output in HTML from the input strings.
 getDiff ($str1, $str2)
 Produce a diff (with the "diff" application on unix) between two strings The function will write the two input strings to temporary files, then execute the diff program, delete the temp files and return the result.
 addClearBuffer ($clearBuffer, $last=0)
 Will bring down the length of strings to < 150 chars if they were longer than 200 chars.
 explodeStringIntoWords ($str)
 Explodes the input string into words.
 tagSpace ($str, $rev=0)
 Adds a space character before and after HTML tags (more precisely any found < or >).

Public Attributes

 $stripTags = 0
 $diffOptions = ''
 $clearBufferIdx = 0

Member Function Documentation

t3lib_diff::addClearBuffer clearBuffer,
last = 0
 

Will bring down the length of strings to < 150 chars if they were longer than 200 chars.

This done by preserving the 70 first and last chars and concatenate those strings with "..." and a number indicating the string length

Parameters:
string The input string.
boolean If set, it indicates that the string should just end with ... (thus no "complete" ending)
Returns:
string Processed string. private

Definition at line 187 of file class.t3lib_diff.php.

Referenced by makeDiffDisplay().

00187                                                    {
00188       if (strlen($clearBuffer)>200) {
00189          $clearBuffer=($this->clearBufferIdx?t3lib_div::fixed_lgd_cs($clearBuffer,70):'').'['.strlen($clearBuffer).']'.(!$last?t3lib_div::fixed_lgd_cs($clearBuffer,-70):'');
00190       }
00191       $this->clearBufferIdx++;
00192       return $clearBuffer;
00193    }

t3lib_diff::explodeStringIntoWords str  ) 
 

Explodes the input string into words.

This is done by splitting first by lines, then by space char. Each word will be in stored as a value in an array. Lines will be indicated by two subsequent empty values.

Parameters:
string The string input
Returns:
array Array with words. private

Definition at line 203 of file class.t3lib_diff.php.

Referenced by makeDiffDisplay().

00203                                           {
00204       $strArr = t3lib_div::trimExplode(chr(10),$str);
00205       $outArray=array();
00206       reset($strArr);
00207       while(list(,$lineOfWords)=each($strArr))  {
00208          $allWords = t3lib_div::trimExplode(' ',$lineOfWords,1);
00209          $outArray = array_merge($outArray,$allWords);
00210          $outArray[]='';
00211          $outArray[]='';
00212       }
00213       return $outArray;
00214    }

t3lib_diff::getDiff str1,
str2
 

Produce a diff (with the "diff" application on unix) between two strings The function will write the two input strings to temporary files, then execute the diff program, delete the temp files and return the result.

Parameters:
string String 1
string String 2
Returns:
array The result from the exec() function call. private

Definition at line 160 of file class.t3lib_diff.php.

References TYPO3_OS.

Referenced by makeDiffDisplay().

00160                                  {
00161       if (TYPO3_OS!='WIN') {
00162             // Create file 1 and write string
00163          $file1 = t3lib_div::tempnam('diff1_');
00164          t3lib_div::writeFile($file1,$str1);
00165             // Create file 2 and write string
00166          $file2 = t3lib_div::tempnam('diff2_');
00167          t3lib_div::writeFile($file2,$str2);
00168             // Perform diff.
00169          $cmd = $GLOBALS['TYPO3_CONF_VARS']['BE']['diff_path'].' '.$this->diffOptions.' '.$file1.' '.$file2;
00170          exec($cmd,$res);
00171 
00172          unlink($file1);
00173          unlink($file2);
00174 
00175          return $res;
00176       }
00177    }

t3lib_diff::makeDiffDisplay str1,
str2
 

This will produce a color-marked-up diff output in HTML from the input strings.

Parameters:
string String 1
string String 2
Returns:
string Formatted output.

Definition at line 86 of file class.t3lib_diff.php.

References $a, addClearBuffer(), explodeStringIntoWords(), getDiff(), and tagSpace().

00086                                           {
00087       if ($this->stripTags)   {
00088          $str1 = strip_tags($str1);
00089          $str2 = strip_tags($str2);
00090       } else {
00091          $str1 = $this->tagSpace($str1);
00092          $str2 = $this->tagSpace($str2);
00093       }
00094       $str1Lines = $this->explodeStringIntoWords($str1);
00095       $str2Lines = $this->explodeStringIntoWords($str2);
00096 
00097       $diffRes = $this->getDiff(implode(chr(10),$str1Lines).chr(10),implode(chr(10),$str2Lines).chr(10));
00098 
00099       if (is_array($diffRes)) {
00100          reset($diffRes);
00101          $c=0;
00102          $diffResArray=array();
00103          while(list(,$lValue)=each($diffRes))   {
00104             if (intval($lValue)) {
00105                $c=intval($lValue);
00106                $diffResArray[$c]['changeInfo']=$lValue;
00107             }
00108             if (substr($lValue,0,1)=='<') {
00109                $diffResArray[$c]['old'][]=substr($lValue,2);
00110             }
00111             if (substr($lValue,0,1)=='>') {
00112                $diffResArray[$c]['new'][]=substr($lValue,2);
00113             }
00114          }
00115 
00116          $outString='';
00117          $clearBuffer='';
00118          for ($a=-1;$a<count($str1Lines);$a++)  {
00119             if (is_array($diffResArray[$a+1]))  {
00120                if (strstr($diffResArray[$a+1]['changeInfo'],'a')) {  // a=Add, c=change, d=delete: If a, then the content is Added after the entry and we must insert the line content as well.
00121                   $clearBuffer.=htmlspecialchars($str1Lines[$a]).' ';
00122                }
00123 
00124                $outString.=$this->addClearBuffer($clearBuffer);
00125                $clearBuffer='';
00126                if (is_array($diffResArray[$a+1]['old'])) {
00127                   $outString.='<span class="diff-r">'.htmlspecialchars(implode(' ',$diffResArray[$a+1]['old'])).'</span> ';
00128                }
00129                if (is_array($diffResArray[$a+1]['new'])) {
00130                   $outString.='<span class="diff-g">'.htmlspecialchars(implode(' ',$diffResArray[$a+1]['new'])).'</span> ';
00131                }
00132                $chInfParts = explode(',',$diffResArray[$a+1]['changeInfo']);
00133                if (!strcmp($chInfParts[0],$a+1))   {
00134                   $newLine = intval($chInfParts[1])-1;
00135                   if ($newLine>$a)  $a=$newLine;   // Security that $a is not set lower than current for some reason...
00136                }
00137             } else {
00138                $clearBuffer.=htmlspecialchars($str1Lines[$a]).' ';
00139             }
00140          }
00141          $outString.=$this->addClearBuffer($clearBuffer,1);
00142 
00143          $outString = str_replace('  ',chr(10),$outString);
00144          if (!$this->stripTags)  {
00145             $outString = $this->tagSpace($outString,1);
00146          }
00147          return $outString;
00148       }
00149    }

t3lib_diff::tagSpace str,
rev = 0
 

Adds a space character before and after HTML tags (more precisely any found < or >).

Parameters:
string String to process
boolean If set, the < > searched for will be < and >
Returns:
string Processed string private

Definition at line 224 of file class.t3lib_diff.php.

Referenced by makeDiffDisplay().

00224                                     {
00225       if ($rev)   {
00226          return str_replace(' &lt;','&lt;',str_replace('&gt; ','&gt;',$str));
00227       } else {
00228          return str_replace('<',' <',str_replace('>','> ',$str));
00229       }
00230    }


Member Data Documentation

t3lib_diff::$clearBufferIdx = 0
 

Definition at line 74 of file class.t3lib_diff.php.

t3lib_diff::$diffOptions = ''
 

Definition at line 71 of file class.t3lib_diff.php.

t3lib_diff::$stripTags = 0
 

Definition at line 70 of file class.t3lib_diff.php.


The documentation for this class was generated from the following file:
Generated on Sun Oct 3 01:06:50 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913