Fixed bug #7962: Add icon to selected entry (currently icons are only shown in dropdown)
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_diff.php
index d4de417..42db5ed 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  *
  *
- *   67: class t3lib_diff
- *   86:     function makeDiffDisplay($str1,$str2)
- *  160:     function getDiff($str1,$str2)
- *  187:     function addClearBuffer($clearBuffer,$last=0)
- *  203:     function explodeStringIntoWords($str)
- *  224:     function tagSpace($str,$rev=0)
+ *   66: class t3lib_diff
+ *   86:     function makeDiffDisplay($str1,$str2,$wrapTag='span')
+ *  163:     function getDiff($str1,$str2)
+ *  189:     function addClearBuffer($clearBuffer,$last=0)
+ *  205:     function explodeStringIntoWords($str)
+ *  226:     function tagSpace($str,$rev=0)
  *
  * TOTAL FUNCTIONS: 5
  * (This index is automatically created/updated by the extension "extdeveval")
@@ -58,7 +58,6 @@
 
 /**
  * This class has functions which generates a difference output of a content string
- * Currently works only with LINUX/UNIX
  *
  * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
@@ -72,7 +71,7 @@ class t3lib_diff {
 
                // Internal, dynamic:
        var $clearBufferIdx=0;          // This indicates the number of times the function addClearBuffer has been called - and used to detect the very first call...
-
+       var $differenceLgd=0;
 
 
 
@@ -81,9 +80,10 @@ class t3lib_diff {
         *
         * @param       string          String 1
         * @param       string          String 2
+        * @param       string          Setting the wrapping tag name
         * @return      string          Formatted output.
         */
-       function makeDiffDisplay($str1,$str2)   {
+       function makeDiffDisplay($str1,$str2,$wrapTag='span')   {
                if ($this->stripTags)   {
                        $str1 = strip_tags($str1);
                        $str2 = strip_tags($str2);
@@ -100,19 +100,22 @@ class t3lib_diff {
                        reset($diffRes);
                        $c=0;
                        $diffResArray=array();
+                       $differenceStr = '';
                        while(list(,$lValue)=each($diffRes))    {
                                if (intval($lValue))    {
                                        $c=intval($lValue);
                                        $diffResArray[$c]['changeInfo']=$lValue;
                                }
                                if (substr($lValue,0,1)=='<')   {
-                                       $diffResArray[$c]['old'][]=substr($lValue,2);
+                                       $differenceStr.= $diffResArray[$c]['old'][] = substr($lValue,2);
                                }
                                if (substr($lValue,0,1)=='>')   {
-                                       $diffResArray[$c]['new'][]=substr($lValue,2);
+                                       $differenceStr.= $diffResArray[$c]['new'][] = substr($lValue,2);
                                }
                        }
 
+                       $this->differenceLgd = strlen($differenceStr);
+
                        $outString='';
                        $clearBuffer='';
                        for ($a=-1;$a<count($str1Lines);$a++)   {
@@ -124,10 +127,10 @@ class t3lib_diff {
                                        $outString.=$this->addClearBuffer($clearBuffer);
                                        $clearBuffer='';
                                        if (is_array($diffResArray[$a+1]['old']))       {
-                                               $outString.='<span class="diff-r">'.htmlspecialchars(implode(' ',$diffResArray[$a+1]['old'])).'</span> ';
+                                               $outString.='<'.$wrapTag.' class="diff-r">'.htmlspecialchars(implode(' ',$diffResArray[$a+1]['old'])).'</'.$wrapTag.'> ';
                                        }
                                        if (is_array($diffResArray[$a+1]['new']))       {
-                                               $outString.='<span class="diff-g">'.htmlspecialchars(implode(' ',$diffResArray[$a+1]['new'])).'</span> ';
+                                               $outString.='<'.$wrapTag.' class="diff-g">'.htmlspecialchars(implode(' ',$diffResArray[$a+1]['new'])).'</'.$wrapTag.'> ';
                                        }
                                        $chInfParts = explode(',',$diffResArray[$a+1]['changeInfo']);
                                        if (!strcmp($chInfParts[0],$a+1))       {
@@ -166,6 +169,7 @@ class t3lib_diff {
                t3lib_div::writeFile($file2,$str2);
                        // Perform diff.
                $cmd = $GLOBALS['TYPO3_CONF_VARS']['BE']['diff_path'].' '.$this->diffOptions.' '.$file1.' '.$file2;
+               $res = array();
                exec($cmd,$res);
 
                unlink($file1);