[TASK] Remove last XCLASS statements
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / media / scripts / fe_adminLib.inc
index 07c4953..9893e06 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2009 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
+
 /**
  * FE admin lib
  *
- * $Id$
- * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
- *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
- */
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- *  132: class user_feAdmin
- *  179:     function init($content,$conf)
- *
- *              SECTION: Data processing
- *  409:     function parseValues()
- *  504:     function processFiles($cmdParts,$theField)
- *  610:     function overrideValues()
- *  626:     function defaultValues()
- *  645:     function evalValues()
- *  767:     function userProcess($mConfKey,$passVar)
- *  785:     function userProcess_alt($confVal,$confArr,$passVar)
- *
- *              SECTION: Database manipulation functions
- *  827:     function save()
- *  885:     function deleteRecord()
- *  915:     function deleteFilesFromRecord($uid)
- *
- *              SECTION: Command "display" functions
- *  972:     function displayDeleteScreen()
- * 1000:     function displayCreateScreen()
- * 1023:     function displayEditScreen()
- * 1074:     function displayEditForm($origArr)
- * 1102:     function procesSetFixed()
- *
- *              SECTION: Template processing functions
- * 1189:     function removeRequired($templateCode,$failure)
- * 1207:     function getPlainTemplate($key,$r='')
- * 1224:     function modifyDataArrForFormUpdate($inputArr)
- * 1293:     function setCObjects($templateCode,$currentArr=array(),$markerArray='',$specialPrefix='')
- *
- *              SECTION: Emailing
- * 1355:     function sendInfoMail()
- * 1403:     function compileMail($key, $DBrows, $recipient, $setFixedConfig=array())
- * 1449:     function sendMail($recipient, $admin, $content='', $adminContent='')
- * 1494:     function isHTMLContent($c)
- * 1515:     function sendHTMLMail($content,$recipient,$dummy,$fromEmail,$fromName,$replyTo='')
- *
- *              SECTION: Various helper functions
- * 1599:     function aCAuth($r)
- * 1613:     function authCode($r,$extra='')
- * 1639:     function setfixed($markerArray, $setfixed, $r)
- * 1675:     function setfixedHash($recCopy,$fields='')
- * 1696:     function isPreview()
- * 1705:     function createFileFuncObj()
- * 1716:     function clearCacheIfSet()
- * 1731:     function getFailure($theField, $theCmd, $label)
- *
- * TOTAL FUNCTIONS: 33
- * (This index is automatically created/updated by the extension "extdeveval")
- *
- */
-
-require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');             // For use with images.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/**
  * This library provides a HTML-template file based framework for Front End creating/editing/deleting records authenticated by email or fe_user login.
- * It is used in the extensions "direct_mail_subscription" and "feuser_admin" (and the depreciated(!) static template "plugin.feadmin.dmailsubscription" and "plugin.feadmin.fe_users" which are the old versions of these two extensions)
+ * It is used in the extensions "direct_mail_subscription" and "feuser_admin" (and the deprecated(!) static template "plugin.feadmin.dmailsubscription" and "plugin.feadmin.fe_users" which are the old versions of these two extensions)
  * Further the extensions "t3consultancies" and "t3references" also uses this library but contrary to the "direct_mail_subscription" and "feuser_admin" extensions which relies on external HTML templates which must be adapted these two extensions delivers the HTML template code from inside.
  * Generally the fe_adminLib appears to be hard to use. Personally I feel turned off by all the template-file work involved and since it is very feature rich (and for that sake pretty stable!) there are lots of things that can go wrong - you feel. Therefore I like the concept used by "t3consultancies"/"t3references" since those extensions uses the library by supplying the HTML-template code automatically.
  * Suggestions for improvement and streamlining is welcome so this powerful class could be used more and effectively.
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
- * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=396&cHash=d267c36546
  */
 class user_feAdmin     {
 
                // External, static:
-       var $recInMarkersHSC = TRUE;            // If true, values from the record put into markers going out into HTML will be passed through htmlspecialchars()!
+               // If TRUE, values from the record put into markers going out into HTML will be passed through htmlspecialchars()!
+       var $recInMarkersHSC = TRUE;
 
        var $dataArr = array();
        var $failureMsg = array();
@@ -146,22 +56,29 @@ class user_feAdmin {
        var $preview;
        var $backURL;
        var $recUid;
-       var $failure=0;         // is set if data did not have the required fields set.
-       var $error='';
-       var $saved=0;           // is set if data is saved
+               // is set if data did not have the required fields set.
+       var $failure = 0;
+       var $error = '';
+               // is set if data is saved
+       var $saved = 0;
        var $requiredArr;
        var $currentArr = array();
-       var $previewLabel='';
-       var $nc = '';           // '&no_cache=1' if you want that parameter sent.
+       var $previewLabel = '';
+               // '&no_cache=1' if you want that parameter sent.
+       var $nc = '';
        var $additionalUpdateFields='';
        var $emailMarkPrefix = 'EMAIL_TEMPLATE_';
        var $codeLength;
        var $cmdKey;
-       var $fileFunc='';       // Set to a basic_filefunc object
-       var $filesStoredInUploadFolders=array();                // This array will hold the names of files transferred to the uploads/* folder if any. If the records are NOT saved, these files should be deleted!! Currently this is not working!
+               // Set to a basic_filefunc object
+       var $fileFunc = '';
+               // This array will hold the names of files transferred to the uploads/* folder if any.
+               // If the records are NOT saved, these files should be deleted!! Currently this is not working!
+       var $filesStoredInUploadFolders = array();
 
                // Internal vars, dynamic:
-       var $unlinkTempFiles = array();                 // Is loaded with all temporary filenames used for upload which should be deleted before exit...
+               // Is loaded with all temporary filenames used for upload which should be deleted before exit...
+       var $unlinkTempFiles = array();
 
        /**
         * Main function. Called from TypoScript.
@@ -171,12 +88,11 @@ class user_feAdmin {
         * - saves/emails if such commands are sent
         * - calls functions for display of the screen for editing/creation/deletion etc.
         *
-        * @param       string          Empty string, ignore.
-        * @param       array           TypoScript properties following the USER_INT object which uses this library
-        * @return      string          HTML content
-        * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=396&cHash=d267c36546
+        * @param string Empty string, ignore.
+        * @param array TypoScript properties following the USER_INT object which uses this library
+        * @return string HTML content
         */
-       function init($content,$conf)   {
+       function init($content, $conf) {
                $this->conf = $conf;
 
                        // template file is fetched.
@@ -188,32 +104,55 @@ class user_feAdmin        {
                $this->preview = (string)t3lib_div::_GP('preview');
                        // backURL is a given URL to return to when login is performed
                $this->backURL = t3lib_div::_GP('backURL');
+               if (strstr($this->backURL, '"') || strstr($this->backURL, "'") || preg_match('/(javascript|vbscript):/i', $this->backURL) || stristr($this->backURL, "fromcharcode") || strstr($this->backURL, "<") || strstr($this->backURL, ">")) {
+                               // Clear backURL if it seems to contain XSS code - only URLs are allowed
+                       $this->backURL = '';
+               }
+                       // Remove host from URL: Make sure that $this->backURL maps to the current site
+               $this->backURL = preg_replace('|[A-Za-z]+://[^/]+|', '', $this->backURL);
                        // Uid to edit:
                $this->recUid = t3lib_div::_GP('rU');
                        // Authentication code:
                $this->authCode = t3lib_div::_GP('aC');
-                       // get table
+                       // Get table
                $this->theTable = $this->conf['table'];
-
-               $this->nc = $this->conf['no_cache'] ? '&no_cache=1' : $this->nc;
+                       // Link configuration
+               $linkConf = is_array($this->conf['formurl.']) ? $this->conf['formurl.'] : array();
                        // pid
                $this->thePid = intval($this->conf['pid']) ? intval($this->conf['pid']) : $GLOBALS['TSFE']->id;
-                       //
+
                $this->codeLength = intval($this->conf['authcodeFields.']['codeLength']) ? intval($this->conf['authcodeFields.']['codeLength']) : 8;
 
                        // Setting the hardcoded lists of fields allowed for editing and creation.
-               $this->fieldList=implode(',',t3lib_div::trimExplode(',',$GLOBALS['TCA'][$this->theTable]['feInterface']['fe_admin_fieldList'],1));
+               $this->fieldList=implode(',', t3lib_div::trimExplode(',', $GLOBALS['TCA'][$this->theTable]['feInterface']['fe_admin_fieldList'], 1));
 
-                       // globally substituted markers, fonts and colors.
+                       // Globally substituted markers, fonts and colors.
                $splitMark = md5(microtime());
-               list($this->markerArray['###GW1B###'],$this->markerArray['###GW1E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap1.']));
-               list($this->markerArray['###GW2B###'],$this->markerArray['###GW2E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap2.']));
-               $this->markerArray['###GC1###'] = $this->cObj->stdWrap($this->conf['color1'],$this->conf['color1.']);
-               $this->markerArray['###GC2###'] = $this->cObj->stdWrap($this->conf['color2'],$this->conf['color2.']);
-               $this->markerArray['###GC3###'] = $this->cObj->stdWrap($this->conf['color3'],$this->conf['color3.']);
+               list($this->markerArray['###GW1B###'], $this->markerArray['###GW1E###']) = explode($splitMark, $this->cObj->stdWrap($splitMark, $this->conf['wrap1.']));
+               list($this->markerArray['###GW2B###'], $this->markerArray['###GW2E###']) = explode($splitMark, $this->cObj->stdWrap($splitMark, $this->conf['wrap2.']));
+               $this->markerArray['###GC1###'] = $this->cObj->stdWrap($this->conf['color1'], $this->conf['color1.']);
+               $this->markerArray['###GC2###'] = $this->cObj->stdWrap($this->conf['color2'], $this->conf['color2.']);
+               $this->markerArray['###GC3###'] = $this->cObj->stdWrap($this->conf['color3'], $this->conf['color3.']);
+
+                       // needed for backwards compatibility
+               if (intval($this->conf['no_cache']) && !isset($linkConf['no_cache'])) {
+                       $linkConf['no_cache'] = 1;
+               }
+               if (!$linkConf['parameter']) {
+                       $linkConf['parameter'] = $GLOBALS['TSFE']->id;
+               }
+                       // needed for backwards compatibility
+               if (!$linkConf['additionalParams']) {
+                       $linkConf['additionalParams'] = $this->conf['addParams'];
+               }
+
+               $formURL = $this->cObj->typoLink_URL($linkConf);
+               if (!strstr($formURL, '?')) {
+                       $formURL .= '?';
+               }
 
                        // Initialize markerArray, setting FORM_URL and HIDDENFIELDS
-               $this->markerArray['###FORM_URL###'] = 'index.php?id='.$GLOBALS['TSFE']->id.'&type='.$GLOBALS['TSFE']->type.$this->nc.$this->conf['addParams'];
+               $this->markerArray['###FORM_URL###'] = $formURL;
                $this->markerArray['###FORM_URL_ENC###'] = rawurlencode($this->markerArray['###FORM_URL###']);
                $this->markerArray['###FORM_URL_HSC###'] = htmlspecialchars($this->markerArray['###FORM_URL###']);
 
@@ -233,7 +172,7 @@ class user_feAdmin  {
 
 
                        // Setting cmdKey which is either 'edit' or 'create'
-               switch($this->cmd)      {
+               switch($this->cmd) {
                        case 'edit':
                                $this->cmdKey='edit';
                        break;
@@ -243,74 +182,72 @@ class user_feAdmin        {
                }
                        // Setting requiredArr to the fields in 'required' intersected field the total field list in order to remove invalid fields.
                $this->requiredArr = array_intersect(
-                       t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['required'],1),
-                       t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['fields'],1)
+                       t3lib_div::trimExplode(',', $this->conf[$this->cmdKey.'.']['required'], 1),
+                       t3lib_div::trimExplode(',', $this->conf[$this->cmdKey.'.']['fields'], 1)
                );
 
                        // Setting incoming data. Non-stripped
-               $fe=t3lib_div::_GP('FE');
-               $this->dataArr = $fe[$this->theTable];  // Incoming data.
-
-/*
-               debug($GLOBALS['HTTP_POST_VARS']);
-               debug($GLOBALS['HTTP_GET_VARS']);
-               debug($GLOBALS['HTTP_POST_FILES']);
-*/
+               $fe = t3lib_div::_GP('FE');
+                       // Incoming data.
+               $this->dataArr = $fe[$this->theTable];
+
                        // Checking template file and table value
-               if (!$this->templateCode)       {
+               if (!$this->templateCode) {
                        $content = 'No template file found: '.$this->conf['templateFile'];
                        return $content;
                }
 
-               if (!$this->theTable || !$this->fieldList)      {
+               if (!$this->theTable || !$this->fieldList) {
                        $content = 'Wrong table: '.$this->theTable;
-                       return $content;                // Not listed or editable table!
+                               // Not listed or editable table!
+                       return $content;
                }
 
-               // *****************
-               // If data is submitted, we take care of it here.
-               // *******************
-               if ($this->cmd=='delete' && !$this->preview && !t3lib_div::_GP('doNotSave'))    {       // Delete record if delete command is sent + the preview flag is NOT set.
+                       // If data is submitted, we take care of it here.
+                       // Delete record if delete command is sent + the preview flag is NOT set.
+               if ($this->cmd=='delete' && !$this->preview && !t3lib_div::_GP('doNotSave')) {
                        $this->deleteRecord();
                }
                        // If incoming data is seen...
-               if (is_array($this->dataArr))   {
+               if (is_array($this->dataArr)) {
                                // Evaluation of data:
                        $this->parseValues();
                        $this->overrideValues();
                        $this->evalValues();
-                       if ($this->conf['evalFunc'])    {
-                               $this->dataArr = $this->userProcess('evalFunc',$this->dataArr);
+                       if ($this->conf['evalFunc']) {
+                               $this->dataArr = $this->userProcess('evalFunc', $this->dataArr);
                        }
 
-               /*
-               debug($this->dataArr);
-               debug($this->failure);
-               debug($this->preview);
-               */
-                               // if not preview and no failures, then set data...
-                       if (!$this->failure && !$this->preview && !t3lib_div::_GP('doNotSave')) {       // doNotSave is a global var (eg a 'Cancel' submit button) that prevents the data from being processed
+                               // If not preview and no failures, then set data...
+                               // doNotSave is a global var (eg a 'Cancel' submit button) that prevents the data from being processed
+                       if (!$this->failure && !$this->preview && !t3lib_div::_GP('doNotSave')) {
                                $this->save();
                        } else {
-                               if ($this->conf['debug'])               debug($this->failure);
+                               if ($this->conf['debug']) {
+                                       debug($this->failure);
+                               }
                        }
                } else {
-                       $this->defaultValues(); // If no incoming data, this will set the default values.
-                       $this->preview = 0;     // No preview if data is not received
+                               // If no incoming data, this will set the default values.
+                       $this->defaultValues();
+                               // No preview if data is not received
+                       $this->preview = 0;
                }
-               if ($this->failure)     {$this->preview=0;}     // No preview flag if a evaluation failure has occured
-               $this->previewLabel = $this->preview ? '_PREVIEW' : ''; // Setting preview label prefix.
-
+               if ($this->failure) {
+                               // No preview flag if a evaluation failure has occured
+                       $this->preview = 0;
+               }
+                       // Setting preview label prefix.
+               $this->previewLabel = $this->preview ? '_PREVIEW' : '';
 
-                       // *********************
                        // DISPLAY FORMS:
-                       // ***********************
                if ($this->saved) {
                                // Clear page cache
                        $this->clearCacheIfSet();
 
-                               // Displaying the page here that says, the record has been saved. You're able to include the saved values by markers.
-                       switch($this->cmd)      {
+                               // Displaying the page here that says, the record has been saved.
+                               // You're able to include the saved values by markers.
+                       switch($this->cmd) {
                                case 'delete':
                                        $key='DELETE';
                                break;
@@ -323,11 +260,11 @@ class user_feAdmin        {
                        }
                                // Output message
                        $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_'.$key.'_SAVED###');
-                       $this->setCObjects($templateCode,$this->currentArr);
+                       $this->setCObjects($templateCode, $this->currentArr);
                        $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
                        $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
 
-                               // email message:
+                               // Email message:
                        $this->compileMail(
                                $key.'_SAVED',
                                array($this->currentArr),
@@ -340,12 +277,15 @@ class user_feAdmin        {
                        $this->setCObjects($templateCode);
                        $content = $this->cObj->substituteMarkerArray($templateCode, $this->markerArray);
                } else {
-                               // Finally, if there has been no attempt to save. That is either preview or just displaying and empty or not correctly filled form:
-                       if (!$this->cmd)        {
+                               // Finally, if there has been no attempt to save.
+                               // That is either preview or just displaying and empty or not correctly filled form:
+                       if (!$this->cmd) {
                                $this->cmd=$this->conf['defaultCmd'];
                        }
-                       if ($this->conf['debug'])               debug('Display form: '.$this->cmd,1);
-                       switch($this->cmd)      {
+                       if ($this->conf['debug']) {
+                               debug('Display form: '.$this->cmd, 1);
+                       }
+                       switch($this->cmd) {
                                case 'setfixed':
                                        $content = $this->procesSetFixed();
                                break;
@@ -365,7 +305,7 @@ class user_feAdmin  {
                }
 
                        // Delete temp files:
-               foreach($this->unlinkTempFiles as $tempFileName)        {
+               foreach($this->unlinkTempFiles as $tempFileName) {
                        t3lib_div::unlink_tempfile($tempFileName);
                }
 
@@ -373,28 +313,6 @@ class user_feAdmin {
                return $content;
        }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        /*****************************************
         *
         * Data processing
@@ -407,70 +325,74 @@ class user_feAdmin        {
         * Examples of this could be to force a value to an integer, remove all non-alphanumeric characters, trimming a value, upper/lowercase it, or process it due to special types like files submitted etc.
         * Called from init() if the $this->dataArr is found to be an array
         *
-        * @return      void
+        * @return void
         * @see init()
         */
-       function parseValues()  {
-               if (is_array($this->conf['parseValues.']))      {
-                       reset($this->conf['parseValues.']);
-                       while(list($theField,$theValue)=each($this->conf['parseValues.']))      {
-                               $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
-                               while(list(,$cmd)=each($listOfCommands))        {
-                                       $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
+       function parseValues() {
+               if (is_array($this->conf['parseValues.'])) {
+                       foreach ($this->conf['parseValues.'] as $theField => $theValue) {
+                               $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
+                               foreach ($listOfCommands as $cmd) {
+                                               // Point is to enable parameters after each command enclosed in brackets [..].
+                                               // These will be in position 1 in the array.
+                                       $cmdParts = preg_split('/\[|\]/', $cmd);
                                        $theCmd=trim($cmdParts[0]);
-                                       switch($theCmd) {
+                                       switch($theCmd) {
                                                case 'int':
                                                        $this->dataArr[$theField]=intval($this->dataArr[$theField]);
                                                break;
                                                case 'lower':
                                                case 'upper':
-                                                       $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField],$theCmd);
+                                                       $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField], $theCmd);
                                                break;
                                                case 'nospace':
                                                        $this->dataArr[$theField] = str_replace(' ', '', $this->dataArr[$theField]);
                                                break;
                                                case 'alpha':
-                                                       $this->dataArr[$theField] = ereg_replace('[^a-zA-Z]','',$this->dataArr[$theField]);
+                                                       $this->dataArr[$theField] = preg_replace('/[^a-zA-Z]/', '', $this->dataArr[$theField]);
                                                break;
                                                case 'num':
-                                                       $this->dataArr[$theField] = ereg_replace('[^0-9]','',$this->dataArr[$theField]);
+                                                       $this->dataArr[$theField] = preg_replace('/[^0-9]/', '', $this->dataArr[$theField]);
                                                break;
                                                case 'alphanum':
-                                                       $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9]','',$this->dataArr[$theField]);
+                                                       $this->dataArr[$theField] = preg_replace('/[^a-zA-Z0-9]/', '', $this->dataArr[$theField]);
                                                break;
                                                case 'alphanum_x':
-                                                       $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9_-]','',$this->dataArr[$theField]);
+                                                       $this->dataArr[$theField] = preg_replace('/[^a-zA-Z0-9_-]/', '', $this->dataArr[$theField]);
                                                break;
                                                case 'trim':
                                                        $this->dataArr[$theField] = trim($this->dataArr[$theField]);
                                                break;
                                                case 'random':
-                                                       $this->dataArr[$theField] = substr(md5(uniqid(microtime(),1)),0,intval($cmdParts[1]));
+                                                       $this->dataArr[$theField] = substr(md5(uniqid(microtime(), 1)), 0, intval($cmdParts[1]));
                                                break;
                                                case 'files':
-                                                       if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave'))    {
-                                                               $this->processFiles($cmdParts,$theField);
-                                                       } else unset($this->dataArr[$theField]);        // Fields with files cannot be edited - only created.
+                                                       if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave')) {
+                                                               $this->processFiles($cmdParts, $theField);
+
+                                                       } else {
+                                                                       // Fields with files cannot be edited - only created.
+                                                               unset($this->dataArr[$theField]);
+                                                       }
                                                break;
                                                case 'setEmptyIfAbsent':
-                                                       if (!isset($this->dataArr[$theField]))  {
+                                                       if (!isset($this->dataArr[$theField])) {
                                                                $this->dataArr[$theField]='';
                                                        }
                                                break;
                                                case 'multiple':
-                                                       if (is_array($this->dataArr[$theField]))        {
-                                                               $this->dataArr[$theField] = implode(',',$this->dataArr[$theField]);
+                                                       if (is_array($this->dataArr[$theField])) {
+                                                               $this->dataArr[$theField] = implode(',', $this->dataArr[$theField]);
                                                        }
                                                break;
                                                case 'checkArray':
-                                                       if (is_array($this->dataArr[$theField]))        {
-                                                               reset($this->dataArr[$theField]);
+                                                       if (is_array($this->dataArr[$theField])) {
                                                                $val = 0;
-                                                               while(list($kk,$vv)=each($this->dataArr[$theField]))    {
-                                                                       $kk = t3lib_div::intInRange($kk,0);
-                                                                       if ($kk<=30)    {
-                                                                               if ($vv)        {
-                                                                                       $val|=pow(2,$kk);
+                                                               foreach ($this->dataArr[$theField] as $kk => $vv) {
+                                                                       $kk = t3lib_utility_Math::forceIntegerInRange($kk, 0);
+                                                                       if ($kk<=30) {
+                                                                               if ($vv) {
+                                                                                       $val|=pow(2, $kk);
                                                                                }
                                                                        }
                                                                }
@@ -478,16 +400,16 @@ class user_feAdmin        {
                                                        } else {$this->dataArr[$theField]=0;}
                                                break;
                                                case 'uniqueHashInt':
-                                                       $otherFields = t3lib_div::trimExplode(';',$cmdParts[1],1);
+                                                       $otherFields = t3lib_div::trimExplode(';', $cmdParts[1], 1);
                                                        $hashArray=array();
-                                                       while(list(,$fN)=each($otherFields))    {
+                                                       foreach ($otherFields as $fN) {
                                                                $vv = $this->dataArr[$fN];
-                                                               $vv = ereg_replace('[[:space:]]','',$vv);
-                                                               $vv = ereg_replace('[^[:alnum:]]','',$vv);
+                                                               $vv = preg_replace('/[[:space:]]/', '', $vv);
+                                                               $vv = preg_replace('/[^[:alnum:]]/', '', $vv);
                                                                $vv = strtolower($vv);
                                                                $hashArray[]=$vv;
                                                        }
-                                                       $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)),0,8));
+                                                       $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)), 0, 8));
                                                break;
                                        }
                                }
@@ -499,33 +421,30 @@ class user_feAdmin        {
         * Processing of files.
         * NOTICE: for now files can be handled only on creation of records. But a more advanced feature is that PREVIEW of files is handled.
         *
-        * @param       array           Array with cmd-parts (from parseValues()). This will for example contain information about allowed file extensions and max size of uploaded files.
-        * @param       string          The fieldname with the files.
-        * @return      void
+        * @param array $cmdParts Array with cmd-parts (from parseValues()). This will for example contain information about allowed file extensions and max size of uploaded files.
+        * @param string $theField The fieldname with the files.
+        * @return void
         * @access private
         * @see parseValues()
         */
-       function processFiles($cmdParts,$theField)      {
-//debug($GLOBALS['HTTP_POST_FILES']);
+       function processFiles($cmdParts, $theField) {
                        // First, make an array with the filename and file reference, whether the file is just uploaded or a preview
                $filesArr = array();
-
-               if (is_string($this->dataArr[$theField]))       {               // files from preview.
-                       $tmpArr = explode(',',$this->dataArr[$theField]);
-                       reset($tmpArr);
-                       while(list(,$val)=each($tmpArr))        {
-                               $valParts = explode('|',$val);
+                       // Files from preview.
+               if (is_string($this->dataArr[$theField])) {
+                       $tmpArr = explode(',', $this->dataArr[$theField]);
+                       foreach ($tmpArr as $val) {
+                               $valParts = explode('|', $val);
                                $filesArr[] = array (
                                        'name'=>$valParts[1],
                                        'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0]
                                );
                        }
-               } elseif (is_array($GLOBALS['HTTP_POST_FILES']['FE'][$this->theTable][$theField]['name']))      {       // Files from upload
-                       reset($GLOBALS['HTTP_POST_FILES']['FE'][$this->theTable][$theField]['name']);
-                       while(list($kk,$vv)=each($GLOBALS['HTTP_POST_FILES']['FE'][$this->theTable][$theField]['name']))        {
-                               if ($vv)        {
-                                       $tmpFile = t3lib_div::upload_to_tempfile($GLOBALS['HTTP_POST_FILES']['FE'][$this->theTable][$theField]['tmp_name'][$kk]);
-                                       if ($tmpFile)   {
+               } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name'])) {        // Files from upload
+                       foreach ($_FILES['FE'][$this->theTable][$theField]['name'] as $kk => $vv) {
+                               if ($vv) {
+                                       $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]);
+                                       if ($tmpFile) {
                                                $this->unlinkTempFiles[]=$tmpFile;
                                                $filesArr[] = array (
                                                        'name'=>$vv,
@@ -534,12 +453,11 @@ class user_feAdmin        {
                                        }
                                }
                        }
-               } elseif (is_array($GLOBALS['HTTP_POST_FILES']['FE']['name'][$this->theTable][$theField]))      {       // Files from upload
-                       reset($GLOBALS['HTTP_POST_FILES']['FE']['name'][$this->theTable][$theField]);
-                       while(list($kk,$vv)=each($GLOBALS['HTTP_POST_FILES']['FE']['name'][$this->theTable][$theField]))        {
-                               if ($vv)        {
-                                       $tmpFile = t3lib_div::upload_to_tempfile($GLOBALS['HTTP_POST_FILES']['FE']['tmp_name'][$this->theTable][$theField][$kk]);
-                                       if ($tmpFile)   {
+               } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField])) {        // Files from upload
+                       foreach ($_FILES['FE']['name'][$this->theTable][$theField] as $kk => $vv) {
+                               if ($vv) {
+                                       $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]);
+                                       if ($tmpFile) {
                                                $this->unlinkTempFiles[]=$tmpFile;
                                                $filesArr[] = array (
                                                        'name'=>$vv,
@@ -551,19 +469,18 @@ class user_feAdmin        {
                }
 
                        // Then verify the files in that array; check existence, extension and size
-               $this->dataArr[$theField]='';
-               $finalFilesArr=array();
-               if (count($filesArr))   {
-                       $extArray = t3lib_div::trimExplode(';',strtolower($cmdParts[1]),1);
+               $this->dataArr[$theField] = '';
+               $finalFilesArr = array();
+               if (count($filesArr)) {
+                       $extArray = t3lib_div::trimExplode(';', strtolower($cmdParts[1]), 1);
                        $maxSize = intval($cmdParts[3]);
-                       reset($filesArr);
-                       while(list(,$infoArr)=each($filesArr))  {
+                       foreach ($filesArr as $infoArr) {
                                $fI = pathinfo($infoArr['name']);
-                               if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name']))   {
-                                       if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray))     {
+                               if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name'])) {
+                                       if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray)) {
                                                $tmpFile = $infoArr['tmp_name'];
-                                               if (@is_file($tmpFile)) {
-                                                       if (!$maxSize || filesize($tmpFile)<$maxSize*1024)      {
+                                               if (@is_file($tmpFile)) {
+                                                       if (!$maxSize || filesize($tmpFile)<$maxSize*1024) {
                                                                $finalFilesArr[]=$infoArr;
                                                        } elseif ($this->conf['debug']) {debug('Size is beyond '.$maxSize.' kb ('.filesize($tmpFile).' bytes) and the file cannot be saved.');}
                                                } elseif ($this->conf['debug']) {debug('Surprisingly there was no file for '.$vv.' in '.$tmpFile);}
@@ -572,15 +489,15 @@ class user_feAdmin        {
                        }
                }
                        // Copy the files in the resulting array to the proper positions based on preview/non-preview.
-               reset($finalFilesArr);
-               $fileNameList=array();
-               while(list(,$infoArr)=each($finalFilesArr))     {
-                       if ($this->isPreview()) {               // If the form is a preview form (and data is therefore not going into the database...) do this.
+               $fileNameList = array();
+               foreach ($finalFilesArr as $infoArr) {
+                               // If the form is a preview form (and data is therefore not going into the database...) do this.
+                       if ($this->isPreview()) {
                                $this->createFileFuncObj();
                                $fI = pathinfo($infoArr['name']);
                                $tmpFilename = $this->theTable.'_'.t3lib_div::shortmd5(uniqid($infoArr['name'])).'.'.$fI['extension'];
                                $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site.'typo3temp/');
-                               t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
+                               t3lib_div::upload_copy_move($infoArr['tmp_name'], $theDestFile);
                                        // Setting the filename in the list
                                $fI2 = pathinfo($theDestFile);
                                $fileNameList[] = $fI2['basename'].'|'.$infoArr['name'];
@@ -588,12 +505,12 @@ class user_feAdmin        {
                                $this->createFileFuncObj();
                                $GLOBALS['TSFE']->includeTCA();
                                t3lib_div::loadTCA($this->theTable);
-                               if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField]))   {
+                               if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) {
                                        $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder'];
                                }
-                               if ($uploadPath)        {
+                               if ($uploadPath) {
                                        $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath);
-                                       t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
+                                       t3lib_div::upload_copy_move($infoArr['tmp_name'], $theDestFile);
                                                // Setting the filename in the list
                                        $fI2 = pathinfo($theDestFile);
                                        $fileNameList[] = $fI2['basename'];
@@ -601,21 +518,20 @@ class user_feAdmin        {
                                }
                        }
                                // Implode the list of filenames
-                       $this->dataArr[$theField] = implode(',',$fileNameList);
+                       $this->dataArr[$theField] = implode(',', $fileNameList);
                }
        }
 
        /**
         * Overriding values in $this->dataArr if configured for that in TypoScript ([edit/create].overrideValues)
         *
-        * @return      void
+        * @return void
         * @see init()
         */
-       function overrideValues()       {
-               // Addition of overriding values
-               if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.']))        {
-                       reset($this->conf[$this->cmdKey.'.']['overrideValues.']);
-                       while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['overrideValues.']))        {
+       function overrideValues() {
+                       // Addition of overriding values
+               if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.'])) {
+                       foreach ($this->conf[$this->cmdKey.'.']['overrideValues.'] as $theField => $theValue) {
                                $this->dataArr[$theField] = $theValue;
                        }
                }
@@ -624,14 +540,13 @@ class user_feAdmin        {
        /**
         * Called if there is no input array in $this->dataArr. Then this function sets the default values configured in TypoScript
         *
-        * @return      void
+        * @return void
         * @see init()
         */
-       function defaultValues()        {
+       function defaultValues() {
                        // Addition of default values
-               if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
-                       reset($this->conf[$this->cmdKey.'.']['defaultValues.']);
-                       while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
+               if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
+                       foreach ($this->conf[$this->cmdKey.'.']['defaultValues.'] as $theField => $theValue) {
                                $this->dataArr[$theField] = $theValue;
                        }
                }
@@ -643,135 +558,139 @@ class user_feAdmin      {
         * It will populate arrays like $this->failure and $this->failureMsg with error messages (which can later be displayed in the template). Mostly it does NOT alter $this->dataArr (such parsing of values was done by parseValues())
         * Works based on configuration in TypoScript key [create/edit].evalValues
         *
-        * @return      void
+        * @return void
         * @see init(), parseValues()
         */
-       function evalValues()   {
-               // Check required, set failure if not ok.
-               reset($this->requiredArr);
-               $tempArr=array();
-               while(list(,$theField)=each($this->requiredArr))        {
-                       if (!trim($this->dataArr[$theField]))   {
+       function evalValues() {
+                       // Check required, set failure if not ok.
+               $tempArr = array();
+               foreach ($this->requiredArr as $theField) {
+                       if (!trim($this->dataArr[$theField])) {
                                $tempArr[]=$theField;
                        }
                }
 
-               // Evaluate: This evaluates for more advanced things than 'required' does. But it returns the same error code, so you must let the required-message tell, if further evaluation has failed!
-               $recExist=0;
-               if (is_array($this->conf[$this->cmdKey.'.']['evalValues.']))    {
-                       switch($this->cmd)      {
+                       // Evaluate: This evaluates for more advanced things than 'required' does. But it returns the same error code, so you must let the required-message tell, if further evaluation has failed!
+               $recExist = 0;
+               if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) {
+                       switch($this->cmd) {
                                case 'edit':
-                                       if (isset($this->dataArr['pid']))       {                       // This may be tricked if the input has the pid-field set but the edit-field list does NOT allow the pid to be edited. Then the pid may be false.
+                                               // This may be tricked if the input has the pid-field set but the edit-field list does NOT
+                                               // allow the pid to be edited. Then the pid may be false.
+                                       if (isset($this->dataArr['pid'])) {
                                                $recordTestPid = intval($this->dataArr['pid']);
                                        } else {
-                                               $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$this->dataArr['uid']);
+                                               $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->dataArr['uid']);
                                                $recordTestPid = intval($tempRecArr['pid']);
                                        }
-                                       $recExist=1;
+                                       $recExist = 1;
                                break;
                                default:
-                                       $recordTestPid = $this->thePid ? $this->thePid : t3lib_div::intval_positive($this->dataArr['pid']);
+                                       $recordTestPid = $this->thePid ? $this->thePid : t3lib_utility_Math::convertToPositiveInteger($this->dataArr['pid']);
                                break;
                        }
 
-                       reset($this->conf[$this->cmdKey.'.']['evalValues.']);
-                       while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.']))    {
-                               $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
-                               while(list(,$cmd)=each($listOfCommands))        {
-                                       $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
+                       foreach ($this->conf[$this->cmdKey.'.']['evalValues.'] as $theField => $theValue) {
+                               $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
+                               foreach ($listOfCommands as $cmd) {
+                                       $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
                                        $theCmd = trim($cmdParts[0]);
-                                       switch($theCmd) {
+                                       switch($theCmd) {
                                                case 'uniqueGlobal':
-                                                       if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField],'','','','1'))  {
-                                                               if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid'])     {       // Only issue an error if the record is not existing (if new...) and if the record with the false value selected was not our self.
+                                                       if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, $theField, $this->dataArr[$theField], '', '', '', '1')) {
+                                                                       // Only issue an error if the record is not existing (if new...) and if the record with the false value selected was not our self.
+                                                               if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid']) {
                                                                        $tempArr[]=$theField;
                                                                        $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
                                                                }
                                                        }
                                                break;
                                                case 'uniqueLocal':
-                                                       if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')','','','1'))  {
-                                                               if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid'])     {       // Only issue an error if the record is not existing (if new...) and if the record with the false value selected was not our self.
+                                                       if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, $theField, $this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')', '', '', '1')) {
+                                                                       // Only issue an error if the record is not existing (if new...) and if the record with the false value selected was not our self.
+                                                               if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid']) {
                                                                        $tempArr[]=$theField;
                                                                        $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
                                                                }
                                                        }
                                                break;
                                                case 'twice':
-                                                       if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again']))      {
+                                                       if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again'])) {
                                                                $tempArr[]=$theField;
                                                                $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter the same value twice');
                                                        }
                                                break;
                                                case 'email':
-                                                       if (!$this->cObj->checkEmail($this->dataArr[$theField]))        {
+                                                       if (!t3lib_div::validEmail($this->dataArr[$theField])) {
                                                                $tempArr[]=$theField;
                                                                $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address');
                                                        }
                                                break;
                                                case 'required':
-                                                       if (!trim($this->dataArr[$theField]))   {
+                                                       if (!trim($this->dataArr[$theField])) {
                                                                $tempArr[]=$theField;
                                                                $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a value!');
                                                        }
                                                break;
                                                case 'atLeast':
                                                        $chars=intval($cmdParts[1]);
-                                                       if (strlen($this->dataArr[$theField])<$chars)   {
+                                                       if (strlen($this->dataArr[$theField])<$chars) {
                                                                $tempArr[]=$theField;
                                                                $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at least %s characters!'), $chars);
                                                        }
                                                break;
                                                case 'atMost':
                                                        $chars=intval($cmdParts[1]);
-                                                       if (strlen($this->dataArr[$theField])>$chars)   {
+                                                       if (strlen($this->dataArr[$theField])>$chars) {
                                                                $tempArr[]=$theField;
                                                                $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at most %s characters!'), $chars);
                                                        }
                                                break;
                                                case 'inBranch':
-                                                       $pars = explode(';',$cmdParts[1]);
-                                                       if (intval($pars[0]))   {
+                                                       $pars = explode(';', $cmdParts[1]);
+                                                       if (intval($pars[0])) {
                                                                $pid_list = $this->cObj->getTreeList(
                                                                        intval($pars[0]),
                                                                        intval($pars[1]) ? intval($pars[1]) : 999,
                                                                        intval($pars[2])
                                                                );
-                                                               if (!$pid_list || !t3lib_div::inList($pid_list,$this->dataArr[$theField]))      {
+                                                               if (!$pid_list || !t3lib_div::inList($pid_list, $this->dataArr[$theField])) {
                                                                        $tempArr[]=$theField;
                                                                        $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'The value was not a valid valud from this list: %s'), $pid_list);
                                                                }
                                                        }
                                                break;
                                                case 'unsetEmpty':
-                                                       if (!$this->dataArr[$theField]) {
+                                                       if (!$this->dataArr[$theField]) {
                                                                $hash = array_flip($tempArr);
                                                                unset($hash[$theField]);
                                                                $tempArr = array_keys($hash);
                                                                unset($this->failureMsg[$theField]);
-                                                               unset($this->dataArr[$theField]);       // This should prevent the field from entering the database.
+                                                                       // This should prevent the field from entering the database.
+                                                               unset($this->dataArr[$theField]);
                                                        }
                                                break;
                                        }
                                }
-                               $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode($this->failureMsg[$theField],'<br />') : '';
+                               $this->markerArray['###EVAL_ERROR_FIELD_' . $theField . '###'] = is_array($this->failureMsg[$theField]) ? implode('<br />', $this->failureMsg[$theField]) : '';
                        }
                }
-               $this->failure=implode($tempArr,',');    //$failure will show which fields were not OK
+                       // $failure will show which fields were not OK
+               $this->failure = implode(',', $tempArr);
        }
 
        /**
         * Preforms user processing of input array - triggered right after the function call to evalValues() IF TypoScript property "evalFunc" was set.
         *
-        * @param       string          Key pointing to the property in TypoScript holding the configuration for this processing (here: "evalFunc.*"). Well: at least its safe to say that "parentObj" in this array passed to the function is a reference back to this object.
-        * @param       array           The $this->dataArr passed for processing
-        * @return      array           The processed $passVar ($this->dataArr)
+        * @param string $mConfKey Key pointing to the property in TypoScript holding the configuration for this processing (here: "evalFunc.*"). Well: at least its safe to say that "parentObj" in this array passed to the function is a reference back to this object.
+        * @param array $passVar The $this->dataArr passed for processing
+        * @return array The processed $passVar ($this->dataArr)
         * @see init(), evalValues()
         */
-       function userProcess($mConfKey,$passVar)        {
-               if ($this->conf[$mConfKey])     {
+       function userProcess($mConfKey, $passVar) {
+               if ($this->conf[$mConfKey]) {
                        $funcConf = $this->conf[$mConfKey.'.'];
-                       $funcConf['parentObj']=&$this;
+                       $funcConf['parentObj'] = $this;
                        $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
                }
                return $passVar;
@@ -780,42 +699,21 @@ class user_feAdmin        {
        /**
         * User processing of contnet
         *
-        * @param       string          Value of the TypoScript object triggering the processing.
-        * @param       array           Properties of the TypoScript object triggering the processing. The key "parentObj" in this array is passed to the function as a reference back to this object.
-        * @param       mixed           Input variable to process
-        * @return      mixed           Processed input variable, $passVar
+        * @param string $confVal Value of the TypoScript object triggering the processing.
+        * @param array $confArr Properties of the TypoScript object triggering the processing. The key "parentObj" in this array is passed to the function as a reference back to this object.
+        * @param mixed $passVar Input variable to process
+        * @return mixed Processed input variable, $passVar
         * @see userProcess(), save(), modifyDataArrForFormUpdate()
         */
-       function userProcess_alt($confVal,$confArr,$passVar)    {
-               if ($confVal)   {
+       function userProcess_alt($confVal, $confArr, $passVar) {
+               if ($confVal) {
                        $funcConf = $confArr;
-                       $funcConf['parentObj']=&$this;
+                       $funcConf['parentObj'] = $this;
                        $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($confVal, $funcConf, $passVar);
                }
                return $passVar;
        }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        /*****************************************
         *
         * Database manipulation functions
@@ -825,20 +723,22 @@ class user_feAdmin        {
        /**
         * Performs the saving of records, either edited or created.
         *
-        * @return      void
+        * @return void
         * @see init()
         */
-       function save() {
-               switch($this->cmd)      {
+       function save() {
+               switch($this->cmd) {
                        case 'edit':
                                $theUid = $this->dataArr['uid'];
-                               $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);           // Fetches the original record to check permissions
-                               if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)))    {       // Must be logged in in order to edit  (OR be validated by email)
-                                       $newFieldList = implode(array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['edit.']['fields'],1)),',');
-                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr,$GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))      {
+                                       // Fetches the original record to check permissions
+                               $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
+                                       // Must be logged in in order to edit  (OR be validated by email)
+                               if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))) {
+                                       $newFieldList = implode(',', array_intersect(explode(',', $this->fieldList), t3lib_div::trimExplode(',', $this->conf['edit.']['fields'], 1)));
+                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable, $origArr, $GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'], $this->conf['fe_userEditSelf'])) {
                                                $this->cObj->DBgetUpdate($this->theTable, $theUid, $this->dataArr, $newFieldList, TRUE);
-                                               $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
-                                               $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'],$this->conf['edit.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
+                                               $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
+                                               $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'], $this->conf['edit.']['userFunc_afterSave.'], array('rec'=>$this->currentArr, 'origRec'=>$origArr));
                                                $this->saved=1;
                                        } else {
                                                $this->error='###TEMPLATE_NO_PERMISSIONS###';
@@ -846,33 +746,34 @@ class user_feAdmin        {
                                }
                        break;
                        default:
-                               if ($this->conf['create'])      {
-                                       $newFieldList = implode(array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['create.']['fields'],1)),',');
+                               if ($this->conf['create']) {
+                                       $newFieldList = implode(',', array_intersect(explode(',', $this->fieldList), t3lib_div::trimExplode(',', $this->conf['create.']['fields'], 1)));
                                        $this->cObj->DBgetInsert($this->theTable, $this->thePid, $this->dataArr, $newFieldList, TRUE);
                                        $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
 
-                                       if ($this->theTable=='fe_users' && $this->conf['fe_userOwnSelf'])       {               // enables users, creating logins, to own them self.
-                                               $extraList='';
+                                               // enables users, creating logins, to own them self.
+                                       if ($this->theTable == 'fe_users' && $this->conf['fe_userOwnSelf']) {
+                                               $extraList = '';
                                                $dataArr = array();
                                                if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'])           {
-                                                       $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'];
-                                                       $dataArr[$field]=$newId;
-                                                       $extraList.=','.$field;
+                                                       $field = $GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'];
+                                                       $dataArr[$field] = $newId;
+                                                       $extraList .= ','.$field;
                                                }
-                                               if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'])  {
-                                                       $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'];
-                                                       list($dataArr[$field])=explode(',',$this->dataArr['usergroup']);
-                                                       $dataArr[$field]=intval($dataArr[$field]);
-                                                       $extraList.=','.$field;
+                                               if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id']) {
+                                                       $field = $GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'];
+                                                       list($dataArr[$field]) = explode(',', $this->dataArr['usergroup']);
+                                                       $dataArr[$field] = intval($dataArr[$field]);
+                                                       $extraList .= ','.$field;
                                                }
-                                               if (count($dataArr))    {
+                                               if (count($dataArr)) {
                                                        $this->cObj->DBgetUpdate($this->theTable, $newId, $dataArr, $extraList, TRUE);
                                                }
                                        }
 
-                                       $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$newId);
-                                       $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'],$this->conf['create.']['userFunc_afterSave.'],array('rec'=>$this->currentArr));
-                                       $this->saved=1;
+                                       $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $newId);
+                                       $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'], $this->conf['create.']['userFunc_afterSave.'], array('rec'=>$this->currentArr));
+                                       $this->saved = 1;
                                }
                        break;
                }
@@ -883,17 +784,21 @@ class user_feAdmin        {
         * If the deleted flag should just be set, then it is done so. Otherwise the record truely is deleted along with any attached files.
         * Called from init() if "cmd" was set to "delete" (and some other conditions)
         *
-        * @return      string          void
+        * @return string void
         * @see init()
         */
-       function deleteRecord() {
-               if ($this->conf['delete'])      {       // If deleting is enabled
-                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->recUid);
-                       if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
+       function deleteRecord() {
+                       // If deleting is enabled
+               if ($this->conf['delete']) {
+                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
+                               // Must be logged in OR be authenticated by the aC code in order to delete
+                       if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) {
                                        // If the recUid selects a record.... (no check here)
-                               if (is_array($origArr)) {
-                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))     {       // Display the form, if access granted.
-                                               if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete'])        {       // If the record is fully deleted... then remove the image (or any file) attached.
+                               if (is_array($origArr)) {
+                                               // Display the form, if access granted.
+                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable, $origArr, $GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'], $this->conf['fe_userEditSelf'])) {
+                                                       // If the record is fully deleted... then remove the image (or any file) attached.
+                                               if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete']) {
                                                        $this->deleteFilesFromRecord($this->recUid);
                                                }
                                                $this->cObj->DBgetDelete($this->theTable, $this->recUid, TRUE);
@@ -911,28 +816,26 @@ class user_feAdmin        {
         * Deletes the files attached to a record and updates the record.
         * Table/uid is $this->theTable/$uid
         *
-        * @param       integer         Uid number of the record to delete from $this->theTable
-        * @return      void
+        * @param integer $uid Uid number of the record to delete from $this->theTable
+        * @return void
         * @access private
         * @see deleteRecord()
         */
-       function deleteFilesFromRecord($uid)    {
+       function deleteFilesFromRecord($uid) {
                $table = $this->theTable;
-               $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table,$uid);
+               $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table, $uid);
 
                $GLOBALS['TSFE']->includeTCA();
                t3lib_div::loadTCA($table);
-               reset($GLOBALS['TCA'][$table]['columns']);
-               $iFields=array();
-               while(list($field,$conf)=each($GLOBALS['TCA'][$table]['columns']))      {
-                       if ($conf['config']['type']=='group' && $conf['config']['internal_type']=='file')       {
+               $iFields = array();
+               foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $conf) {
+                       if ($conf['config']['type'] == 'group' && $conf['config']['internal_type']=='file') {
 
                                $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($field => ''));
 
-                               $delFileArr = explode(',',$rec[$field]);
-                               reset($delFileArr);
-                               while(list(,$n)=each($delFileArr))      {
-                                       if ($n) {
+                               $delFileArr = explode(',', $rec[$field]);
+                               foreach ($delFileArr as $n) {
+                                       if ($n) {
                                                $fpath = $conf['config']['uploadfolder'].'/'.$n;
                                                unlink($fpath);
                                        }
@@ -941,26 +844,6 @@ class user_feAdmin {
                }
        }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        /*****************************************
         *
         * Command "display" functions
@@ -970,16 +853,19 @@ class user_feAdmin        {
        /**
         * Creates the preview display of delete actions
         *
-        * @return      string          HTML content
+        * @return string HTML content
         * @see init()
         */
-       function displayDeleteScreen()  {
-               if ($this->conf['delete'])      {       // If deleting is enabled
-                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->recUid);
-                       if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
+       function displayDeleteScreen() {
+                       // If deleting is enabled
+               if ($this->conf['delete']) {
+                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
+                               // Must be logged in OR be authenticated by the aC code in order to delete
+                       if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) {
                                        // If the recUid selects a record.... (no check here)
-                               if (is_array($origArr)) {
-                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))     {       // Display the form, if access granted.
+                               if (is_array($origArr)) {
+                                               // Display the form, if access granted.
+                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable, $origArr, $GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'], $this->conf['fe_userEditSelf'])) {
                                                $this->markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="rU" value="'.$this->recUid.'" />';
                                                $content = $this->getPlainTemplate('###TEMPLATE_DELETE_PREVIEW###', $origArr);
                                        } else {        // Else display error, that you could not edit that particular record...
@@ -998,22 +884,26 @@ class user_feAdmin        {
        /**
         * Creates the "create" screen for records
         *
-        * @return      string          HTML content
+        * @return string HTML content
         * @see init()
         */
-       function displayCreateScreen()  {
-               if ($this->conf['create'])      {
-                       $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser||$this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###'));
+       function displayCreateScreen() {
+               if ($this->conf['create']) {
+                       $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser || $this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###'));
                        $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
                        if (!$failure)  $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');
 
-                       $templateCode = $this->removeRequired($templateCode,$failure);
+                       $templateCode = $this->removeRequired($templateCode, $failure);
                        $this->setCObjects($templateCode);
 
+                       if (!is_array($this->dataArr)) {
+                               $this->dataArr = array();
+                       }
+
                        $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
                        if ($this->conf['create.']['preview'] && !$this->previewLabel)  {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
                        $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
-                       $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
+                       $content .= $this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
                }
                return $content;
        }
@@ -1021,17 +911,18 @@ class user_feAdmin       {
        /**
         * Creates the edit-screen for records
         *
-        * @return      string          HTML content
+        * @return string HTML content
         * @see init()
         */
-       function displayEditScreen()    {
-               if ($this->conf['edit'])        {       // If editing is enabled
-                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid);
-
-                       if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to edit
+       function displayEditScreen() {
+                       // If editing is enabled
+               if ($this->conf['edit']) {
+                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid);
+                               // Must be logged in OR be authenticated by the aC code in order to edit
+                       if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) {
                                        // If the recUid selects a record.... (no check here)
-                               if (is_array($origArr)) {
-                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))     {       // Display the form, if access granted.
+                               if (is_array($origArr)) {
+                                       if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable, $origArr, $GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'], $this->conf['fe_userEditSelf']))  {       // Display the form, if access granted.
                                                $content=$this->displayEditForm($origArr);
                                        } else {        // Else display error, that you could not edit that particular record...
                                                $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
@@ -1039,15 +930,16 @@ class user_feAdmin       {
                                } elseif ($GLOBALS['TSFE']->loginUser) {        // If the recUid did not select a record, we display a menu of records. (eg. if no recUid)
                                        $lockPid = $this->conf['edit.']['menuLockPid'] ? ' AND pid='.intval($this->thePid) : '';
 
-                                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->theTable, '1 '.$lockPid.$this->cObj->DBmayFEUserEditSelect($this->theTable,$GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'],$this->conf['fe_userEditSelf']).$GLOBALS['TSFE']->sys_page->deleteClause($this->theTable));
+                                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->theTable, '1 '.$lockPid.$this->cObj->DBmayFEUserEditSelect($this->theTable, $GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'], $this->conf['fe_userEditSelf']).$GLOBALS['TSFE']->sys_page->deleteClause($this->theTable));
 
-                                       if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {       // If there are menu-items ...
+                                               // If there are menu-items ...
+                                       if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
                                                $templateCode = $this->getPlainTemplate('###TEMPLATE_EDITMENU###');
-                                               $out='';
+                                               $out = '';
                                                $itemCode = $this->cObj->getSubpart($templateCode, '###ITEM###');
-                                               while($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
+                                               while ($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                                        $markerArray = $this->cObj->fillInMarkerArray(array(), $menuRow, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
-                                                       $markerArray = $this->setCObjects($itemCode,$menuRow,$markerArray,'ITEM_');
+                                                       $markerArray = $this->setCObjects($itemCode, $menuRow, $markerArray, 'ITEM_');
                                                        $out.= $this->cObj->substituteMarkerArray($itemCode, $markerArray);
                                                }
                                                $content=$this->cObj->substituteSubpart($templateCode, '###ALLITEMS###', $out);
@@ -1070,29 +962,33 @@ class user_feAdmin       {
         * Subfunction for displayEditScreen(); Takes a record and creates an edit form based on the template code for it.
         * This function is called if the user is editing a record and permitted to do so. Checked in displayEditScreen()
         *
-        * @param       array           The array with the record to edit
-        * @return      string          HTML content
+        * @param array $origArr The array with the record to edit
+        * @return string HTML content
         * @access private
         * @see displayEditScreen()
         */
-       function displayEditForm($origArr)      {
+       function displayEditForm($origArr) {
                $currentArr = is_array($this->dataArr) ? $this->dataArr+$origArr : $origArr;
 
-               if ($this->conf['debug'])       debug('displayEditForm(): '.'###TEMPLATE_EDIT'.$this->previewLabel.'###',1);
+               if ($this->conf['debug']) {
+                       debug('displayEditForm(): ###TEMPLATE_EDIT' . $this->previewLabel . '###', 1);
+               }
                $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_EDIT'.$this->previewLabel.'###');
                $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
                if (!$failure)  {$templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');}
 
-               $templateCode = $this->removeRequired($templateCode,$failure);
+               $templateCode = $this->removeRequired($templateCode, $failure);
 
-               $this->setCObjects($templateCode,$currentArr);
+               $this->setCObjects($templateCode, $currentArr);
 
                $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
 
                $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="FE['.$this->theTable.'][uid]" value="'.$currentArr['uid'].'" />';
-               if ($this->conf['edit.']['preview'] && !$this->previewLabel)    {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
+               if ($this->conf['edit.']['preview'] && !$this->previewLabel) {
+                       $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';
+               }
                $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
-               $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form',  'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
+               $content .= $this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
 
                return $content;
        }
@@ -1101,31 +997,32 @@ class user_feAdmin       {
         * Processes socalled "setfixed" commands. These are commands setting a certain field in a certain record to a certain value. Like a link you can click in an email which will unhide a record to enable something. Or likewise a link which can delete a record by a single click.
         * The idea is that only some allowed actions like this is allowed depending on the configured TypoScript.
         *
-        * @return      string          HTML content displaying the status of the action
+        * @return string HTML content displaying the status of the action
         */
-       function procesSetFixed()       {
-               if ($this->conf['setfixed'])    {
+       function procesSetFixed() {
+               if ($this->conf['setfixed']) {
                        $theUid = intval($this->recUid);
-                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $theUid);
+                       $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
                        $fD = t3lib_div::_GP('fD');
                        $sFK = t3lib_div::_GP('sFK');
 
                        $fieldArr=array();
-                       if (is_array($fD) || $sFK=='DELETE')    {
-                               if (is_array($fD))      {
-                                       reset($fD);
-                                       while(list($field,$value)=each($fD))    {
+                       if (is_array($fD) || $sFK == 'DELETE') {
+                               if (is_array($fD)) {
+                                       foreach ($fD as $field => $value) {
                                                $origArr[$field]=$value;
                                                $fieldArr[]=$field;
                                        }
                                }
-                               $theCode = $this->setfixedHash($origArr,$origArr['_FIELDLIST']);
-                               if (!strcmp($this->authCode,$theCode))  {
-                                       if ($sFK=='DELETE')     {
+                               $theCode = $this->setfixedHash($origArr, $origArr['_FIELDLIST']);
+                               if (!strcmp($this->authCode, $theCode)) {
+                                       if ($sFK == 'DELETE') {
                                                $this->cObj->DBgetDelete($this->theTable, $theUid, TRUE);
                                        } else {
-                                               $newFieldList = implode(array_intersect(t3lib_div::trimExplode(',',$this->fieldList),t3lib_div::trimExplode(',',implode($fieldArr,','),1)),',');
+                                               $newFieldList = implode(',', array_intersect(t3lib_div::trimExplode(',', $this->fieldList), t3lib_div::trimExplode(',', implode($fieldArr, ','), 1)));
                                                $this->cObj->DBgetUpdate($this->theTable, $theUid, $fD, $newFieldList, TRUE);
+                                               $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
+                                               $this->userProcess_alt($this->conf['setfixed.']['userFunc_afterSave'], $this->conf['setfixed.']['userFunc_afterSave.'], array('rec'=>$this->currentArr, 'origRec'=>$origArr));
                                        }
 
                                                // Outputting template
@@ -1148,36 +1045,12 @@ class user_feAdmin      {
                return $content;
        }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        /*****************************************
         *
         * Template processing functions
         *
         *****************************************/
 
-
-
        /**
         * Remove required parts from template code string
         *       Works like this:
@@ -1186,14 +1059,13 @@ class user_feAdmin      {
         *
         *              Only fields that are found in $this->requiredArr is processed.
         *
-        * @param       string          The template HTML code
-        * @param       string          Comma list of fields which has errors (and therefore should not be removed)
-        * @return      string          The processed template HTML code
+        * @param string $templateCode The template HTML code
+        * @param string $failure Comma list of fields which has errors (and therefore should not be removed)
+        * @return string The processed template HTML code
         */
-       function removeRequired($templateCode,$failure) {
-               reset($this->requiredArr);
-               while(list(,$theField)=each($this->requiredArr))        {
-                       if (!t3lib_div::inList($failure,$theField))     {
+       function removeRequired($templateCode, $failure) {
+               foreach ($this->requiredArr as $theField) {
+                       if (!t3lib_div::inList($failure, $theField)) {
                                $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELD_'.$theField.'###', '');
                        }
                }
@@ -1203,16 +1075,18 @@ class user_feAdmin      {
        /**
         * Returns template subpart HTML code for the key given
         *
-        * @param       string          Subpart marker to return subpart for.
-        * @param       array           Optional data record array. If set, then all fields herein will also be substituted if found as markers in the template
-        * @return      string          The subpart with all markers found in current $this->markerArray substituted.
+        * @param string $key Subpart marker to return subpart for.
+        * @param array $r Optional data record array. If set, then all fields herein will also be substituted if found as markers in the template
+        * @return string The subpart with all markers found in current $this->markerArray substituted.
         * @see tslib_cObj::fillInMarkerArray()
         */
-       function getPlainTemplate($key,$r='')   {
-               if ($this->conf['debug'])       debug('getPlainTemplate(): '.$key,1);
+       function getPlainTemplate($key, $r = '') {
+               if ($this->conf['debug']) {
+                       debug('getPlainTemplate(): ' . $key, 1);
+               }
                $templateCode = $this->cObj->getSubpart($this->templateCode, $key);
-               $this->setCObjects($templateCode,is_array($r)?$r:array());
-               return  $this->cObj->substituteMarkerArray(
+               $this->setCObjects($templateCode, is_array($r) ? $r : array());
+               return $this->cObj->substituteMarkerArray(
                                $templateCode,
                                is_array($r) ? $this->cObj->fillInMarkerArray($this->markerArray, $r, '', TRUE, 'FIELD_', $this->recInMarkersHSC) : $this->markerArray
                        );
@@ -1221,48 +1095,48 @@ class user_feAdmin      {
        /**
         * Modifies input array for passing on to tslib_cObj::getUpdateJS() which produces some JavaScript for form evaluation or the like.
         *
-        * @param       array           The data array
-        * @return      array           The processed input array
+        * @param array $inputArr The data array
+        * @return array The processed input array
         * @see displayCreateScreen(), displayEditForm(), tslib_cObj::getUpdateJS()
         */
-       function modifyDataArrForFormUpdate($inputArr)  {
-               if (is_array($this->conf[$this->cmdKey.'.']['evalValues.']))    {
-                       reset($this->conf[$this->cmdKey.'.']['evalValues.']);
-                       while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.']))    {
-                               $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
-                               while(list(,$cmd)=each($listOfCommands))        {
-                                       $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
+       function modifyDataArrForFormUpdate($inputArr) {
+               if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) {
+                       foreach ($this->conf[$this->cmdKey.'.']['evalValues.'] as $theField => $theValue) {
+                               $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
+                               foreach ($listOfCommands as $cmd) {
+                                               // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
+                                       $cmdParts = preg_split('/\[|\]/', $cmd);
                                        $theCmd = trim($cmdParts[0]);
-                                       switch($theCmd) {
+                                       switch($theCmd) {
                                                case 'twice':
-                                                       if (isset($inputArr[$theField]))        {
-                                                               if (!isset($inputArr[$theField.'_again']))      {
+                                                       if (isset($inputArr[$theField])) {
+                                                               if (!isset($inputArr[$theField.'_again'])) {
                                                                        $inputArr[$theField.'_again'] = $inputArr[$theField];
                                                                }
-                                                               $this->additionalUpdateFields.=','.$theField.'_again';
+                                                               $this->additionalUpdateFields .= ','.$theField.'_again';
                                                        }
                                                break;
                                        }
                                }
                        }
                }
-               if (is_array($this->conf['parseValues.']))      {
-                       reset($this->conf['parseValues.']);
-                       while(list($theField,$theValue)=each($this->conf['parseValues.']))      {
-                               $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
-                               while(list(,$cmd)=each($listOfCommands))        {
-                                       $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
+               if (is_array($this->conf['parseValues.'])) {
+                       foreach ($this->conf['parseValues.'] as $theField => $theValue) {
+                               $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
+                               foreach ($listOfCommands as $cmd) {
+                                               // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
+                                       $cmdParts = preg_split('/\[|\]/', $cmd);
                                        $theCmd = trim($cmdParts[0]);
-                                       switch($theCmd) {
+                                       switch($theCmd) {
                                                case 'multiple':
-                                                       if (isset($inputArr[$theField]) && !$this->isPreview()) {
-                                                               $inputArr[$theField] = explode(',',$inputArr[$theField]);
+                                                       if (isset($inputArr[$theField]) && !$this->isPreview()) {
+                                                               $inputArr[$theField] = explode(',', $inputArr[$theField]);
                                                        }
                                                break;
                                                case 'checkArray':
-                                                       if ($inputArr[$theField] && !$this->isPreview())        {
-                                                               for($a=0;$a<=30;$a++)   {
-                                                                       if ($inputArr[$theField] & pow(2,$a))   {
+                                                       if ($inputArr[$theField] && !$this->isPreview()) {
+                                                               for($a=0;$a<=30;$a++) {
+                                                                       if ($inputArr[$theField] & pow(2, $a)) {
                                                                                $alt_theField = $theField.']['.$a;
                                                                                $inputArr[$alt_theField] = 1;
                                                                                $this->additionalUpdateFields.=','.$alt_theField;
@@ -1275,46 +1149,44 @@ class user_feAdmin      {
                        }
                }
 
-
                $inputArr = $this->userProcess_alt(
                        $this->conf['userFunc_updateArray'],
                        $this->conf['userFunc_updateArray.'],
                        $inputArr
                );
 
-               return $inputArr;
+               return $this->escapeHTML($inputArr);
        }
 
        /**
         * Will render TypoScript cObjects (configured in $this->conf['cObjects.']) and add their content to keys in a markerArray, either the array passed to the function or the internal one ($this->markerArray) if the input $markerArray is not set.
         *
-        * @param       string          The current template code string. Is used to check if the marker string is found and if not, the content object is not rendered!
-        * @param       array           An alternative data record array (if empty then $this->dataArr is used)
-        * @param       mixed           An alternative markerArray to fill in (instead of $this->markerArray). If you want to set the cobjects in the internal $this->markerArray, then just set this to non-array value.
-        * @param       string          Optional prefix to set for the marker strings.
-        * @return      array           The processed $markerArray (if given).
+        * @param string $templateCode The current template code string. Is used to check if the marker string is found and if not, the content object is not rendered!
+        * @param array $currentArr An alternative data record array (if empty then $this->dataArr is used)
+        * @param mixed $markerArray An alternative markerArray to fill in (instead of $this->markerArray). If you want to set the cobjects in the internal $this->markerArray, then just set this to non-array value.
+        * @param string $specialPrefix Optional prefix to set for the marker strings.
+        * @return array The processed $markerArray (if given).
         */
-       function setCObjects($templateCode,$currentArr=array(),$markerArray='',$specialPrefix='')       {
-               if (is_array($this->conf['cObjects.'])) {
-                       reset($this->conf['cObjects.']);
+       function setCObjects($templateCode, $currentArr = array(), $markerArray = '', $specialPrefix = '') {
+               if (is_array($this->conf['cObjects.'])) {
 
-                       while(list($theKey,$theConf)=each($this->conf['cObjects.']))    {
-                               if (!strstr($theKey,'.'))       {
-                                       if (strstr($templateCode,'###'.$specialPrefix.'CE_'.$theKey.'###'))     {
+                       foreach ($this->conf['cObjects.'] as $theKey => $theConf) {
+                               if (!strstr($theKey, '.')) {
+                                       if (strstr($templateCode, '###' . $specialPrefix . 'CE_' . $theKey . '###')) {
                                                $cObjCode = $this->cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
 
-                                               if (!is_array($markerArray))    {
+                                               if (!is_array($markerArray)) {
                                                        $this->markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
                                                } else {
                                                        $markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
                                                }
                                        }
-                                       if (strstr($templateCode,'###'.$specialPrefix.'PCE_'.$theKey.'###'))    {
+                                       if (strstr($templateCode, '###' . $specialPrefix . 'PCE_' . $theKey . '###')) {
                                                $local_cObj =t3lib_div::makeInstance('tslib_cObj');
-                                               $local_cObj->start(count($currentArr)?$currentArr:$this->dataArr,$this->theTable);
+                                               $local_cObj->start(count($currentArr) ? $currentArr : $this->dataArr, $this->theTable);
                                                $cObjCode = $local_cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
 
-                                               if (!is_array($markerArray))    {
+                                               if (!is_array($markerArray)) {
                                                        $this->markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
                                                } else {
                                                        $markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
@@ -1326,24 +1198,6 @@ class user_feAdmin       {
                return $markerArray;
        }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        /*****************************************
         *
         * Emailing
@@ -1353,37 +1207,37 @@ class user_feAdmin      {
        /**
         * Sends info mail to user
         *
-        * @return      string          HTML content message
-        * @see init(),compileMail(), sendMail()
+        * @return string HTML content message
+        * @see init(), compileMail(), sendMail()
         */
-       function sendInfoMail() {
-               if ($this->conf['infomail'] && $this->conf['email.']['field'])  {
+       function sendInfoMail() {
+               if ($this->conf['infomail'] && $this->conf['email.']['field']) {
                        $fetch = t3lib_div::_GP('fetch');
-                       if (isset($fetch))      {
+                       if ($fetch) {
                                        // Getting infomail config.
-                               $key= trim(t3lib_div::_GP('key'));
-                               if (is_array($this->conf['infomail.'][$key.'.']))               {
+                               $key = trim(t3lib_div::_GP('key'));
+                               if (is_array($this->conf['infomail.'][$key.'.'])) {
                                        $config = $this->conf['infomail.'][$key.'.'];
                                } else {
                                        $config = $this->conf['infomail.']['default.'];
                                }
-                               $pidLock='';
-                               if (!$config['dontLockPid'])    {
+                               $pidLock = '';
+                               if (!$config['dontLockPid']) {
                                        $pidLock='AND pid IN ('.$this->thePid.') ';
                                }
 
                                        // Getting records
-                               if (t3lib_div::testInt($fetch)) {
-                                       $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,'uid',$fetch,$pidLock,'','','1');
+                               if (t3lib_utility_Math::canBeInterpretedAsInteger($fetch)) {
+                                       $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, 'uid', $fetch, $pidLock, '', '', '1');
                                } elseif ($fetch) {     // $this->conf['email.']['field'] must be a valid field in the table!
-                                       $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$this->conf['email.']['field'],$fetch,$pidLock,'','','100');
+                                       $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, $this->conf['email.']['field'], $fetch, $pidLock, '', '', '100');
                                }
 
                                        // Processing records
-                               if (is_array($DBrows))  {
+                               if (is_array($DBrows)) {
                                        $recipient = $DBrows[0][$this->conf['email.']['field']];
                                        $this->compileMail($config['label'], $DBrows, $recipient, $this->conf['setfixed.']);
-                               } elseif ($this->cObj->checkEmail($fetch)) {
+                               } elseif (t3lib_div::validEmail($fetch)) {
                                        $this->sendMail($fetch, '', trim($this->cObj->getSubpart($this->templateCode, '###'.$this->emailMarkPrefix.'NORECORD###')));
                                }
 
@@ -1398,15 +1252,15 @@ class user_feAdmin      {
        /**
         * Compiles and sends a mail based on input values + template parts. Looks for a normal and an "-admin" template and may send both kinds of emails. See documentation in TSref.
         *
-        * @param       string          A key which together with $this->emailMarkPrefix will identify the part from the template code to use for the email.
-        * @param       array           An array of records which fields are substituted in the templates
-        * @param       mixed           Mail recipient. If string then its supposed to be an email address. If integer then its a uid of a fe_users record which is looked up and the email address from here is used for sending the mail.
-        * @param       array           Additional fields to set in the markerArray used in the substitution process
-        * @return      void
+        * @param string $key A key which together with $this->emailMarkPrefix will identify the part from the template code to use for the email.
+        * @param array $DBrows An array of records which fields are substituted in the templates
+        * @param mixed $recipient Mail recipient. If string then its supposed to be an email address. If integer then its a uid of a fe_users record which is looked up and the email address from here is used for sending the mail.
+        * @param array $setFixedConfig Additional fields to set in the markerArray used in the substitution process
+        * @return void
         */
-       function compileMail($key, $DBrows, $recipient, $setFixedConfig=array())        {
+       function compileMail($key, $DBrows, $recipient, $setFixedConfig = array()) {
                $GLOBALS['TT']->push('compileMail');
-               $mailContent='';
+               $mailContent = '';
                $key = $this->emailMarkPrefix.$key;
 
                $userContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'###'));
@@ -1414,10 +1268,9 @@ class user_feAdmin       {
                $userContent['rec'] = $this->cObj->getSubpart($userContent['all'], '###SUB_RECORD###');
                $adminContent['rec'] = $this->cObj->getSubpart($adminContent['all'], '###SUB_RECORD###');
 
-               reset($DBrows);
-               while(list(,$r)=each($DBrows))  {
-                       $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $r,'',0);
-                       $markerArray = $this->setCObjects($userContent['rec'].$adminContent['rec'],$r,$markerArray,'ITEM_');
+               foreach ($DBrows as $r) {
+                       $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $r, '', 0);
+                       $markerArray = $this->setCObjects($userContent['rec'] . $adminContent['rec'], $r, $markerArray, 'ITEM_');
                        $markerArray['###SYS_AUTHCODE###'] = $this->authCode($r);
                        $markerArray = $this->setfixed($markerArray, $setFixedConfig, $r);
 
@@ -1428,8 +1281,8 @@ class user_feAdmin        {
                if ($userContent['all'])        $userContent['final'] .=$this->cObj->substituteSubpart($userContent['all'], '###SUB_RECORD###', $userContent['accum']);
                if ($adminContent['all'])       $adminContent['final'].=$this->cObj->substituteSubpart($adminContent['all'], '###SUB_RECORD###', $adminContent['accum']);
 
-               if (t3lib_div::testInt($recipient))     {
-                       $fe_userRec = $GLOBALS['TSFE']->sys_page->getRawRecord('fe_users',$recipient);
+               if (t3lib_utility_Math::canBeInterpretedAsInteger($recipient)) {
+                       $fe_userRec = $GLOBALS['TSFE']->sys_page->getRawRecord('fe_users', $recipient);
                        $recipient=$fe_userRec['email'];
                }
 
@@ -1440,21 +1293,23 @@ class user_feAdmin      {
        }
 
        /**
-        * Actually sends the requested mails (through $this->cObj->sendNotifyEmail)
+        * Actually sends the requested mails (through $this->cObj->sendNotifyEmail or through $this->sendHTMLMail).
+        * As of TYPO3 v4.3 with autoloader, a check for $GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail'] has been included for backwards compatibility.
         *
-        * @param       string          Recipient email address (or list)
-        * @param       string          Possible "admin" email address. Will enable sending of admin emails if also $adminContent is provided
-        * @param       string          Content for the regular email to user
-        * @param       string          Content for the admin email to administrator
-        * @return      void
+        * @param string $recipient Recipient email address (or list)
+        * @param string $recipient Possible "admin" email address. Will enable sending of admin emails if also $adminContent is provided
+        * @param string $content Content for the regular email to user
+        * @param string $adminContent Content for the admin email to administrator
+        * @return void
         * @access private
         * @see compileMail(), sendInfoMail()
         */
-       function sendMail($recipient, $admin, $content='', $adminContent='')    {
+       function sendMail($recipient, $admin, $content = '', $adminContent = '') {
                        // Admin mail:
-               if ($admin && $adminContent)    {
-                       if (!$this->isHTMLContent($adminContent))       {
-                               $admMail = $this->cObj->sendNotifyEmail($adminContent,
+               if ($admin && $adminContent) {
+                       if (!$this->isHTMLContent($adminContent) || !$GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail']) {
+                               $admMail = $this->cObj->sendNotifyEmail(
+                                                                       strip_tags($adminContent),
                                                                        $admin,
                                                                        '',
                                                                        $this->conf['email.']['from'],
@@ -1472,17 +1327,18 @@ class user_feAdmin      {
                        }
                }
                        // user mail:
-               if (!$this->isHTMLContent($content))    {
-                       $this->cObj->sendNotifyEmail($content,
+               if (!$this->isHTMLContent($content) || !$GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail']) {
+                       $this->cObj->sendNotifyEmail(
+                                                               strip_tags($content),
                                                                $recipient,
-                                                               '',                     // ($admMail ? '' : $admin),            // If the special administration mail was not found and send, the regular is...
+                                                               '',
                                                                $this->conf['email.']['from'],
                                                                $this->conf['email.']['fromName']
                                                );
                } else {
                        $this->sendHTMLMail($content,
                                                                $recipient,
-                                                               '',                     // ($admMail ? '' : $admin),            // If the special administration mail was not found and send, the regular is...
+                                                               '',
                                                                $this->conf['email.']['from'],
                                                                $this->conf['email.']['fromName']
                                                );
@@ -1492,175 +1348,148 @@ class user_feAdmin    {
        /**
         * Detects if content is HTML (looking for <html> tag as first and last in string)
         *
-        * @param       string          Content string to test
-        * @return      boolean         Returns true if the content begins and ends with <html></html>-tags
+        * @param string $c Content string to test
+        * @return boolean Returns TRUE if the content begins and ends with <html></html>-tags
         */
-       function isHTMLContent($c)      {
+       function isHTMLContent($c) {
                $c = trim($c);
-               $first = strtolower(substr($c,0,6));
-               $last = strtolower(substr($c,-7));
-               if ($first.$last=='<html></html>')      return 1;
+               $first = strtolower(substr($c, 0, 6));
+               $last = strtolower(substr($c, -7));
+               if ($first . $last == '<html></html>') {
+                       return 1;
+               }
        }
 
        /**
         * Sending HTML email, using same parameters as tslib_cObj::sendNotifyEmail()
-        * NOTICE: "t3lib_htmlmail" library must be included for this to work, otherwise an error message is outputted.
         *
-        * @param       string          The message content. If blank, no email is sent.
-        * @param       string          Comma list of recipient email addresses
-        * @param       string          IGNORE this parameter
-        * @param       string          "From" email address
-        * @param       string          Optional "From" name
-        * @param       string          Optional "Reply-To" header email address.
-        * @return      void
+        * @param string $content The message content. If blank, no email is sent.
+        * @param string $recipient Comma list of recipient email addresses
+        * @param string $dummy IGNORE this parameter
+        * @param string $fromEmail "From" email address
+        * @param string $fromName Optional "From" name
+        * @param string $replyTo Optional "Reply-To" header email address.
+        * @return void
         * @access private
         * @see sendMail(), tslib_cObj::sendNotifyEmail()
         */
-       function sendHTMLMail($content,$recipient,$dummy,$fromEmail,$fromName,$replyTo='')      {
-               if (trim($recipient) && trim($content)) {
-                       $cls=t3lib_div::makeInstanceClassName('t3lib_htmlmail');
-                       if (class_exists($cls)) {       // If htmlmail lib is included, then generate a nice HTML-email
-                               $parts = spliti('<title>|</title>',$content,3);
-                               $subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message';
-
-                               $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail');
-                               $Typo3_htmlmail->start();
-                               $Typo3_htmlmail->useBase64();
-
-                               $Typo3_htmlmail->subject = $subject;
-                               $Typo3_htmlmail->from_email = $fromEmail;
-                               $Typo3_htmlmail->from_name = $fromName;
-                               $Typo3_htmlmail->replyto_email = $replyTo ? $replyTo : $fromEmail;
-                               $Typo3_htmlmail->replyto_name = $replyTo ? '' : $fromName;
-                               $Typo3_htmlmail->organisation = '';
-                               $Typo3_htmlmail->priority = 3;
-
-                                       // HTML
-                               $Typo3_htmlmail->theParts['html']['content'] = $content;        // Fetches the content of the page
-                               $Typo3_htmlmail->theParts['html']['path'] = '';
-                               $Typo3_htmlmail->extractMediaLinks();
-                               $Typo3_htmlmail->extractHyperLinks();
-                               $Typo3_htmlmail->fetchHTMLMedia();
-                               $Typo3_htmlmail->substMediaNamesInHTML(0);      // 0 = relative
-                               $Typo3_htmlmail->substHREFsInHTML();
-                               $Typo3_htmlmail->setHTML($Typo3_htmlmail->encodeMsg($Typo3_htmlmail->theParts['html']['content']));
-
-                                       // PLAIN
-                               $Typo3_htmlmail->addPlain('');
-
-                                       // SET Headers and Content
-                               $Typo3_htmlmail->setHeaders();
-                               $Typo3_htmlmail->setContent();
-                               $Typo3_htmlmail->setRecipient($recipient);
-
-               //              debug($Typo3_htmlmail->theParts);
-                               $Typo3_htmlmail->sendtheMail();
-                       } else {
-                               debug('SYSTEM ERROR: No HTML-mail library loaded. Set "page.config.incT3Lib_htmlmail = 1" is your TypoScript template.');
-                       }
+       function sendHTMLMail($content, $recipient, $dummy, $fromEmail, $fromName, $replyTo = '') {
+               if (trim($recipient) && trim($content)) {
+                       $parts = preg_split('/<title>|<\/title>/i', $content, 3);
+                       $subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message';
+
+                       $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail');
+                       $Typo3_htmlmail->start();
+                       $Typo3_htmlmail->useBase64();
+
+                       $Typo3_htmlmail->subject = $subject;
+                       $Typo3_htmlmail->from_email = $fromEmail;
+                       $Typo3_htmlmail->from_name = $fromName;
+                       $Typo3_htmlmail->replyto_email = $replyTo ? $replyTo : $fromEmail;
+                       $Typo3_htmlmail->replyto_name = $replyTo ? '' : $fromName;
+                       $Typo3_htmlmail->organisation = '';
+                       $Typo3_htmlmail->priority = 3;
+
+                               // HTML
+                               // Fetches the content of the page
+                       $Typo3_htmlmail->theParts['html']['content'] = $content;
+                       $Typo3_htmlmail->theParts['html']['path'] = '';
+                       $Typo3_htmlmail->extractMediaLinks();
+                       $Typo3_htmlmail->extractHyperLinks();
+                       $Typo3_htmlmail->fetchHTMLMedia();
+                               // 0 = relative
+                       $Typo3_htmlmail->substMediaNamesInHTML(0);
+                       $Typo3_htmlmail->substHREFsInHTML();
+                       $Typo3_htmlmail->setHTML($Typo3_htmlmail->encodeMsg($Typo3_htmlmail->theParts['html']['content']));
+
+                               // PLAIN
+                       $Typo3_htmlmail->addPlain('');
+
+                               // SET Headers and Content
+                       $Typo3_htmlmail->setHeaders();
+                       $Typo3_htmlmail->setContent();
+                       $Typo3_htmlmail->setRecipient($recipient);
+
+                       $Typo3_htmlmail->sendtheMail();
                }
        }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        /*****************************************
         *
         * Various helper functions
         *
         *****************************************/
 
-
        /**
-        * Returns true if authentication is OK based on the "aC" code which is a GET parameter set from outside with a hash string which must match some internal hash string.
+        * Returns TRUE if authentication is OK based on the "aC" code which is a GET parameter set from outside with a hash string which must match some internal hash string.
         * This allows to authenticate editing without having a fe_users login
         * Uses $this->authCode which is set in init() by "t3lib_div::_GP('aC');"
         *
-        * @param       array           The data array for which to evaluate authentication
-        * @return      boolean         True if authenticated OK
+        * @param array $r The data array for which to evaluate authentication
+        * @return boolean TRUE if authenticated OK
         * @see authCode(), init()
         */
-       function aCAuth($r)     {
-               if ($this->authCode && !strcmp($this->authCode,$this->authCode($r)))    {
-                       return true;
+       function aCAuth($r) {
+               if ($this->authCode && !strcmp($this->authCode, $this->authCode($r))) {
+                       return TRUE;
                }
        }
 
        /**
         * Creating authentication hash string based on input record and the fields listed in TypoScript property "authcodeFields"
         *
-        * @param       array           The data record
-        * @param       string          Additional string to include in the hash
-        * @return      string          Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
+        * @param array $r The data record
+        * @param string $extra Additional string to include in the hash
+        * @return string Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
         * @see aCAuth()
         */
-       function authCode($r,$extra='') {
-               $l=$this->codeLength;
-               if ($this->conf['authcodeFields'])      {
+       function authCode($r, $extra = '') {
+               $l = $this->codeLength;
+               if ($this->conf['authcodeFields']) {
                        $fieldArr = t3lib_div::trimExplode(',', $this->conf['authcodeFields'], 1);
-                       $value='';
-                       while(list(,$field)=each($fieldArr))    {
-                               $value.=$r[$field].'|';
+                       $value = '';
+                       foreach ($fieldArr as $field) {
+                               $value .= $r[$field].'|';
                        }
-                       $value.=$extra.'|'.$this->conf['authcodeFields.']['addKey'];
-                       if ($this->conf['authcodeFields.']['addDate'])  {
-                               $value.='|'.date($this->conf['authcodeFields.']['addDate']);
+                       $value .= $extra.'|'.$this->conf['authcodeFields.']['addKey'];
+                       if ($this->conf['authcodeFields.']['addDate']) {
+                               $value .= '|'.date($this->conf['authcodeFields.']['addDate']);
                        }
-                       $value.=$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
-                       return substr(md5($value), 0,$l);
+                       $value .= $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
+                       return substr(md5($value), 0, $l);
                }
        }
 
        /**
         * Adding keys to the marker array with "setfixed" GET parameters
         *
-        * @param       array           Marker-array to modify/add a key to.
-        * @param       array           TypoScript properties configuring "setfixed" for the plugin. Basically this is $this->conf['setfixed.'] passed along.
-        * @param       array           The data record
-        * @return      array           Processed $markerArray
+        * @param array $markerArray Marker-array to modify/add a key to.
+        * @param array $setfixed TypoScript properties configuring "setfixed" for the plugin. Basically this is $this->conf['setfixed.'] passed along.
+        * @param array $r The data record
+        * @return array Processed $markerArray
         * @see compileMail()
         */
-       function setfixed($markerArray, $setfixed, $r)  {
-               if (is_array($setfixed))        {
-                       reset($setfixed);
-                       while(list($theKey,$data)=each($setfixed))      {
-                               if (!strcmp($theKey,'DELETE'))  {
+       function setfixed($markerArray, $setfixed, $r) {
+               if (is_array($setfixed)) {
+                       foreach ($setfixed as $theKey => $data) {
+                               if (!strcmp($theKey, 'DELETE')) {
                                        $recCopy = $r;
-                                       $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
-                                       $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
-                                       $markerArray['###SYS_SETFIXED_DELETE###'] = htmlspecialchars($string);
-                               } elseif (strstr($theKey,'.'))  {
-                                       $theKey = substr($theKey,0,-1);
-                                       if (is_array($data))    {
-                                               reset($data);
+                                       $string = '&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
+                                       $string .= '&aC='.$this->setfixedHash($recCopy, $data['_FIELDLIST']);
+                                       $markerArray['###SYS_SETFIXED_DELETE###'] = $string;
+                                       $markerArray['###SYS_SETFIXED_HSC_DELETE###'] = htmlspecialchars($string);
+                               } elseif (strstr($theKey, '.')) {
+                                       $theKey = substr($theKey, 0, -1);
+                                       if (is_array($data)) {
                                                $recCopy = $r;
-                                               $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
-                                               while(list($fieldName,$fieldValue)=each($data)) {
-                                                       $string.='&fD['.$fieldName.']='.rawurlencode($fieldValue);
+                                               $string = '&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
+                                               foreach ($data as $fieldName => $fieldValue) {
+                                                       $string .= '&fD%5B'.$fieldName.'%5D='.rawurlencode($fieldValue);
                                                        $recCopy[$fieldName]=$fieldValue;
                                                }
-                                               $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
-                                               $markerArray['###SYS_SETFIXED_'.$theKey.'###'] = htmlspecialchars($string);
+                                               $string .= '&aC='.$this->setfixedHash($recCopy, $data['_FIELDLIST']);
+                                               $markerArray['###SYS_SETFIXED_'.$theKey.'###'] = $string;
+                                               $markerArray['###SYS_SETFIXED_HSC_'.$theKey.'###'] = htmlspecialchars($string);
                                        }
                                }
                        }
@@ -1671,43 +1500,41 @@ class user_feAdmin      {
        /**
         * Creating hash string for setFixed. Much similar to authCode()
         *
-        * @param       array           The data record
-        * @param       string          List of fields to use
-        * @return      string          Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
-        * @see setfixed(),authCode()
+        * @param array $recCopy The data record
+        * @param string $fields List of fields to use
+        * @return string Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
+        * @see setfixed(), authCode()
         */
-       function setfixedHash($recCopy,$fields='')      {
-               if ($fields)    {
-                       $fieldArr = t3lib_div::trimExplode(',',$fields,1);
-                       reset($fieldArr);
-                       while(list($k,$v)=each($fieldArr))      {
+       function setfixedHash($recCopy, $fields = '') {
+               if ($fields) {
+                       $fieldArr = t3lib_div::trimExplode(',', $fields, 1);
+                       foreach ($fieldArr as $k => $v) {
                                $recCopy_temp[$k]=$recCopy[$v];
                        }
                } else {
-                       $recCopy_temp=$recCopy;
+                       $recCopy_temp = $recCopy;
                }
-               $encStr = implode('|',$recCopy_temp).'|'.$this->conf['authcodeFields.']['addKey'].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
-               $hash = substr(md5($encStr),0,$this->codeLength);
+               $encStr = implode('|', $recCopy_temp) . '|' . $this->conf['authcodeFields.']['addKey'] . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
+               $hash = substr(md5($encStr), 0, $this->codeLength);
                return $hash;
        }
 
-
        /**
-        * Returns true if preview display is on.
+        * Returns TRUE if preview display is on.
         *
-        * @return      boolean
+        * @return boolean
         */
-       function isPreview()    {
+       function isPreview() {
                return ($this->conf[$this->cmdKey.'.']['preview'] && $this->preview);
        }
 
        /**
         * Creates an instance of class "t3lib_basicFileFunctions" in $this->fileFunc (if not already done)
         *
-        * @return      void
+        * @return void
         */
-       function createFileFuncObj()    {
-               if (!$this->fileFunc)   {
+       function createFileFuncObj() {
+               if (!$this->fileFunc) {
                        $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
                }
        }
@@ -1715,10 +1542,10 @@ class user_feAdmin      {
        /**
         * If TypoScript property clearCacheOfPages is set then all page ids in this value will have their cache cleared
         *
-        * @return      void
+        * @return void
         */
-       function clearCacheIfSet()      {
-               if ($this->conf['clearCacheOfPages'])   {
+       function clearCacheIfSet() {
+               if ($this->conf['clearCacheOfPages']) {
                        $cc_pidList = $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['clearCacheOfPages']);
                        $GLOBALS['TSFE']->clearPageCacheContent_pidList($cc_pidList);
                }
@@ -1727,18 +1554,30 @@ class user_feAdmin      {
        /**
         * Returns an error message for the field/command combination inputted. The error message is looked up in the TypoScript properties (evalErrors.[fieldname].[command]) and if empty then the $label value is returned
         *
-        * @param       string          Field name
-        * @param       string          Command identifier string
-        * @param       string          Alternative label, shown if no other error string was found
-        * @return      string          The error message string
+        * @param string $theField Field name
+        * @param string $theCmd Command identifier string
+        * @param string $label Alternative label, shown if no other error string was found
+        * @return string The error message string
         */
-       function getFailure($theField, $theCmd, $label) {
+       function getFailure($theField, $theCmd, $label) {
                return isset($this->conf['evalErrors.'][$theField.'.'][$theCmd]) ? $this->conf['evalErrors.'][$theField.'.'][$theCmd] : $label;
        }
-}
-
 
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc'])  {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc']);
+       /**
+        * Will escape HTML-tags
+        *
+        * @param mixed $var The unescaped data
+        * @return mixed The processed input data
+        */
+       function escapeHTML($var) {
+               if (is_array($var)) {
+                       foreach ($var as $k => $value) {
+                               $var[$k] = $this->escapeHTML($var[$k]);
+                       }
+               } else {
+                       $var = htmlspecialchars($var, ENT_NOQUOTES);
+               }
+               return $var;
+       }
 }
-?>
+?>
\ No newline at end of file