Added argument to debugRows() so it can return HTML instead of echo'ing
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_div.php
index e9efcca..bfa3888 100755 (executable)
@@ -1646,7 +1646,7 @@ class t3lib_div {
         * @param       array           First array
         * @param       array           Second array, overruling the first array
         * @param       boolean         If set, keys that are NOT found in $arr0 (first array) will not be set. Thus only existing value can/will be overruled from second array.
-        * @param       boolean         If set, values from $arr1 will overrule if they are empty. Default: true
+        * @param       boolean         If set, values from $arr1 will overrule if they are empty or zero. Default: true
         * @return      array           Resulting array where $arr1 values has overruled $arr0 values
         */
        function array_merge_recursive_overrule($arr0,$arr1,$notAddKeys=0,$includeEmtpyValues=true) {
@@ -1654,17 +1654,17 @@ class t3lib_div {
                while(list($key,$val) = each($arr1)) {
                        if(is_array($arr0[$key])) {
                                if (is_array($arr1[$key]))      {
-                                       $arr0[$key] = t3lib_div::array_merge_recursive_overrule($arr0[$key],$arr1[$key],$notAddKeys);
+                                       $arr0[$key] = t3lib_div::array_merge_recursive_overrule($arr0[$key],$arr1[$key],$notAddKeys,$includeEmtpyValues);
                                }
                        } else {
                                if ($notAddKeys) {
                                        if (isset($arr0[$key])) {
-                                               if ($includeEmtpyValues OR $val) {
+                                               if ($includeEmtpyValues || $val) {
                                                        $arr0[$key] = $val;
                                                }
                                        }
                                } else {
-                                       if ($includeEmtpyValues OR $val) {
+                                       if ($includeEmtpyValues || $val) {
                                                $arr0[$key] = $val;
                                        }
                                }
@@ -1698,10 +1698,8 @@ class t3lib_div {
        function csvValues($row,$delim=',',$quote='"')  {
                reset($row);
                $out=array();
-               while(list(,$value)=each($row)) {
-                       list($valPart) = explode(chr(10),$value);
-                       $valPart = trim($valPart);
-                       $out[]=str_replace($quote,$quote.$quote,$valPart);
+               foreach ($row as $value) {
+                       $out[] = str_replace($quote, $quote.$quote, $value);
                }
                $str = $quote.implode($quote.$delim.$quote,$out).$quote;
                return $str;
@@ -2551,6 +2549,40 @@ class t3lib_div {
        }
 
        /**
+        * Wrapper function for rmdir, allowing recursive deletion of folders and files
+        *
+        * @param       string          Absolute path to folder, see PHP rmdir() function. Removes trailing slash internally.
+        * @param       boolean         Allow deletion of non-empty directories
+        * @return      boolean         true if @rmdir went well!
+        */
+       function rmdir($path,$removeNonEmpty=false)     {
+               $OK = false;
+               $path = preg_replace('|/$|','',$path);  // Remove trailing slash
+
+               if (file_exists($path)) {
+                       $OK = true;
+
+                       if (is_dir($path))      {
+                               if ($removeNonEmpty==true && $handle = opendir($path))  {
+                                       while ($OK && false !== ($file = readdir($handle)))     {
+                                               if ($file=='.' || $file=='..') continue;
+                                               $OK = t3lib_div::rmdir($path.'/'.$file,$removeNonEmpty);
+                                       }
+                                       closedir($handle);
+                               }
+                               if ($OK)        { $OK = rmdir($path); }
+
+                       } else {        // If $dirname is a file, simply remove it
+                               $OK = unlink($path);
+                       }
+
+                       clearstatcache();
+               }
+
+               return $OK;
+       }
+
+       /**
         * Returns an array with the names of folders in a specific path
         * Will return 'error' (string) if there were an error with reading directory content.
         * Usage: 11
@@ -2871,9 +2903,10 @@ class t3lib_div {
         *
         * @param       array           Array of arrays with similar keys
         * @param       string          Table header
+        * @param       boolean         If TRUE, will return content instead of echo'ing out.
         * @return      void            Outputs to browser.
         */
-       function debugRows($rows,$header='')    {
+       function debugRows($rows,$header='',$returnHTML=FALSE)  {
                if (is_array($rows))    {
                        reset($rows);
                        $firstEl = current($rows);
@@ -2897,7 +2930,7 @@ class t3lib_div {
                                        $tCells = array();
                                        foreach($headerColumns as $key) {
                                                $tCells[] = '
-                                                       <td><font face="Verdana,Arial" size="1">'.htmlspecialchars($singleRow[$key]).'</font></td>';
+                                                       <td><font face="Verdana,Arial" size="1">'.(is_array($singleRow[$key]) ? t3lib_div::debugRows($singleRow[$key],'',TRUE) : htmlspecialchars($singleRow[$key])).'</font></td>';
                                        }
                                        $tRows[] = '
                                                <tr>'.implode('',$tCells).'
@@ -2907,7 +2940,7 @@ class t3lib_div {
                                $table = '
                                        <table border="1" cellpadding="1" cellspacing="0" bgcolor="white">'.implode('',$tRows).'
                                        </table>';
-                               echo $table;
+                               if ($returnHTML)        return $table; else echo $table;
                        } else debug('Empty array of rows',$header);
                } else debug('No array of rows',$header);
        }
@@ -3089,8 +3122,8 @@ class t3lib_div {
                        break;
                        case 'REQUEST_URI':
                                        // Typical application of REQUEST_URI is return urls, forms submitting to itself etc. Example: returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))
-                               if ($GLOBALS['TYPO3_CONF_VAR']['SYS']['requestURIvar']) {       // This is for URL rewriters that store the original URI in a server variable (eg ISAPI_Rewriter for IIS: HTTP_X_REWRITE_URL)
-                                       list($v,$n) = explode('|',$GLOBALS['TYPO3_CONF_VAR']['SYS']['requestURIvar']);
+                               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['requestURIvar'])        {       // This is for URL rewriters that store the original URI in a server variable (eg ISAPI_Rewriter for IIS: HTTP_X_REWRITE_URL)
+                                       list($v,$n) = explode('|',$GLOBALS['TYPO3_CONF_VARS']['SYS']['requestURIvar']);
                                        $retVal = $GLOBALS[$v][$n];
                                } elseif (!$_SERVER['REQUEST_URI'])     {       // This is for ISS/CGI which does not have the REQUEST_URI available.
                                        $retVal = '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
@@ -3547,7 +3580,7 @@ class t3lib_div {
                $pA = array();
                foreach($params as $theP)       {
                        $pKV = explode('=', $theP);     // Splitting single param by '=' sign
-                       if (!t3lib_div::inList('id,type,no_cache,cHash,MP,ftu',$pKV[0]))        {
+                       if (!t3lib_div::inList('id,type,no_cache,cHash,MP,ftu',$pKV[0]) && !preg_match('/TSFE_ADMIN_PANEL\[.*?\]/',$pKV[0]))    {
                                $pA[rawurldecode($pKV[0])] = (string)rawurldecode($pKV[1]);
                        }
                }
@@ -4011,7 +4044,7 @@ class t3lib_div {
         * Usage: 447
         *
         * @param       string          Class name to instantiate
-        * @return      object          The object
+        * @return      object          A reference to the object
         */
        function &makeInstance($className)      {
 
@@ -4120,7 +4153,7 @@ class t3lib_div {
         * @param       string          Encoding type: "base64", "quoted-printable", "8bit". Default value is "quoted-printable".
         * @param       string          Charset used in encoding-headers (only if $encoding is set to a valid value which produces such a header)
         * @param       boolean         If set, the header content will not be encoded.
-        * @return      void
+        * @return      boolean         True if mail was accepted for delivery, false otherwise
         */
        function plainMailEncoded($email,$subject,$message,$headers='',$encoding='quoted-printable',$charset='',$dontEncodeHeader=false)        {
                if (!$charset)  {
@@ -4179,7 +4212,11 @@ class t3lib_div {
 
                $headers=trim(implode($linebreak,t3lib_div::trimExplode(chr(10),$headers,1)));  // Make sure no empty lines are there.
 
-               mail($email,$subject,$message,$headers);
+               $ret = @mail($email,$subject,$message,$headers);
+               if (!$ret)      {
+                       t3lib_div::sysLog('Mail to "'.$email.'" could not be sent (Subject: "'.$subject.'").', 'Core', 3);
+               }
+               return $ret;
        }
 
        /**
@@ -4435,6 +4472,9 @@ class t3lib_div {
                        // TYPO3 logging enabled?
                if (!$TYPO3_CONF_VARS['SYS']['systemLog'])      return;
 
+               $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
+               $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
+
                        // use all configured logging options
                foreach (explode(';',$TYPO3_CONF_VARS['SYS']['systemLog'],2) as $log)   {
                        list($type,$destination,$level) = explode(',',$log,4);
@@ -4449,7 +4489,7 @@ class t3lib_div {
                                $file = fopen($destination, 'a');
                                if ($file)     {
                                        flock($file, LOCK_EX);  // try locking, but ignore if not available (eg. on NFS and FAT)
-                                       fwrite($file, date('d/m/Y H:i').$msgLine.chr(10));
+                                       fwrite($file, date($dateFormat.' '.$timeFormat).$msgLine.chr(10));
                                        flock($file, LOCK_UN);    // release the lock
                                        fclose($file);
                                }