📄 fe_adminlib.inc
字号:
default: $key='CREATE'; break; } // Output message $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_'.$key.'_SAVED###'); $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: $this->compileMail( $key.'_SAVED', array($this->currentArr), $this->currentArr[$this->conf['email.']['field']], $this->conf['setfixed.'] ); } elseif ($this->error) { // If there was an error, we return the template-subpart with the error message $templateCode = $this->cObj->getSubpart($this->templateCode, $this->error); $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) { $this->cmd=$this->conf['defaultCmd']; } if ($this->conf['debug']) debug('Display form: '.$this->cmd,1); switch($this->cmd) { case 'setfixed': $content = $this->procesSetFixed(); break; case 'infomail': $content = $this->sendInfoMail(); break; case 'delete': $content = $this->displayDeleteScreen(); break; case 'edit': $content = $this->displayEditScreen(); break; case 'create': $content = $this->displayCreateScreen(); break; } } // Delete temp files: foreach($this->unlinkTempFiles as $tempFileName) { t3lib_div::unlink_tempfile($tempFileName); } // Return content: return $content; } /***************************************** * * Data processing * *****************************************/ /** * Performs processing on the values found in the input data array, $this->dataArr. * The processing is done according to configuration found in TypoScript * 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 * @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. $theCmd=trim($cmdParts[0]); 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); 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]); break; case 'num': $this->dataArr[$theField] = ereg_replace('[^0-9]','',$this->dataArr[$theField]); break; case 'alphanum': $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9]','',$this->dataArr[$theField]); break; case 'alphanum_x': $this->dataArr[$theField] = ereg_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])); 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. break; case 'setEmptyIfAbsent': if (!isset($this->dataArr[$theField])) { $this->dataArr[$theField]=''; } break; case 'multiple': 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]); $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); } } } $this->dataArr[$theField] = $val; } else {$this->dataArr[$theField]=0;} break; case 'uniqueHashInt': $otherFields = t3lib_div::trimExplode(';',$cmdParts[1],1); $hashArray=array(); while(list(,$fN)=each($otherFields)) { $vv = $this->dataArr[$fN]; $vv = ereg_replace('[[:space:]]','',$vv); $vv = ereg_replace('[^[:alnum:]]','',$vv); $vv = strtolower($vv); $hashArray[]=$vv; } $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)),0,8)); break; } } } } } /** * 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 * @access private * @see parseValues() */ function processFiles($cmdParts,$theField) {//debug($_FILES); // 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); $filesArr[] = array ( 'name'=>$valParts[1], 'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0] ); } } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name'])) { // Files from upload reset($_FILES['FE'][$this->theTable][$theField]['name']); while(list($kk,$vv)=each($_FILES['FE'][$this->theTable][$theField]['name'])) { 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, 'tmp_name'=>$tmpFile ); } } } } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField])) { // Files from upload reset($_FILES['FE']['name'][$this->theTable][$theField]); while(list($kk,$vv)=each($_FILES['FE']['name'][$this->theTable][$theField])) { 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, 'tmp_name'=>$tmpFile ); } } } } // 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); $maxSize = intval($cmdParts[3]); reset($filesArr); while(list(,$infoArr)=each($filesArr)) { $fI = pathinfo($infoArr['name']); 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) { $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);} } elseif ($this->conf['debug']) {debug('Extension "'.$fI['extension'].'" not allowed');} } elseif ($this->conf['debug']) {debug('Filename matched illegal pattern.');} } } // 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. $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); // Setting the filename in the list $fI2 = pathinfo($theDestFile); $fileNameList[] = $fI2['basename'].'|'.$infoArr['name']; } else { $this->createFileFuncObj(); $GLOBALS['TSFE']->includeTCA(); t3lib_div::loadTCA($this->theTable); if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) { $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder']; } if ($uploadPath) { $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath); t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile); // Setting the filename in the list $fI2 = pathinfo($theDestFile); $fileNameList[] = $fI2['basename']; $this->filesStoredInUploadFolders[]=$theDestFile; } } // Implode the list of filenames $this->dataArr[$theField] = implode(',',$fileNameList); } } /** * Overriding values in $this->dataArr if configured for that in TypoScript ([edit/create].overrideValues) * * @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.'])) { $this->dataArr[$theField] = $theValue; } } } /** * Called if there is no input array in $this->dataArr. Then this function sets the default values configured in TypoScript * * @return void * @see init() */ 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.'])) { $this->dataArr[$theField] = $theValue; } } } /** * This will evaluate the input values from $this->dataArr to see if they conforms with the requirements configured in TypoScript per field. * For example this could be checking if a field contains a valid email address, a unique value, a value within a certain range etc. * 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 * @see init(), parseValues() */ function evalValues() { // Check required, set failure if not ok. reset($this->requiredArr); $tempArr=array(); while(list(,$theField)=each($this->requiredArr)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -