Ejemplo n.º 1
0
 /**
  * Filling in the field array
  * $this->exclude_array is used to filter fields if needed.
  *
  * @param string $table Table name
  * @param integer $id Record ID
  * @param array $fieldArray Default values, Preset $fieldArray with 'pid' maybe (pid and uid will be not be overridden anyway)
  * @param array $incomingFieldArray Is which fields/values you want to set. There are processed and put into $fieldArray if OK
  * @param integer $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted.
  * @param string $status Is 'new' or 'update'
  * @param integer $tscPID TSconfig PID
  * @return array Field Array
  * @todo Define visibility
  */
 public function fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $realPid, $status, $tscPID)
 {
     // Initialize:
     \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($table);
     $originalLanguageRecord = NULL;
     $originalLanguage_diffStorage = NULL;
     $diffStorageFlag = FALSE;
     // Setting 'currentRecord' and 'checkValueRecord':
     if (strstr($id, 'NEW')) {
         // Must have the 'current' array - not the values after processing below...
         $currentRecord = $checkValueRecord = $fieldArray;
         // IF $incomingFieldArray is an array, overlay it.
         // The point is that when new records are created as copies with flex type fields there might be a field containing information about which DataStructure to use and without that information the flexforms cannot be correctly processed.... This should be OK since the $checkValueRecord is used by the flexform evaluation only anyways...
         if (is_array($incomingFieldArray) && is_array($checkValueRecord)) {
             $checkValueRecord = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($checkValueRecord, $incomingFieldArray);
         }
     } else {
         // We must use the current values as basis for this!
         $currentRecord = $checkValueRecord = $this->recordInfo($table, $id, '*');
         // This is done to make the pid positive for offline versions; Necessary to have diff-view for pages_language_overlay in workspaces.
         \TYPO3\CMS\Backend\Utility\BackendUtility::fixVersioningPid($table, $currentRecord);
         // Get original language record if available:
         if (is_array($currentRecord) && $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField'] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && intval($currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']]) > 0) {
             $lookUpTable = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'] ? $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'] : $table;
             $originalLanguageRecord = $this->recordInfo($lookUpTable, $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']], '*');
             \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($lookUpTable, $originalLanguageRecord);
             $originalLanguage_diffStorage = unserialize($currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']]);
         }
     }
     $this->checkValue_currentRecord = $checkValueRecord;
     // In the following all incoming value-fields are tested:
     // - Are the user allowed to change the field?
     // - Is the field uid/pid (which are already set)
     // - perms-fields for pages-table, then do special things...
     // - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue
     // If everything is OK, the field is entered into $fieldArray[]
     foreach ($incomingFieldArray as $field => $fieldValue) {
         if (!in_array($table . '-' . $field, $this->exclude_array) && !$this->data_disableFields[$table][$id][$field]) {
             // The field must be editable.
             // Checking if a value for language can be changed:
             $languageDeny = $GLOBALS['TCA'][$table]['ctrl']['languageField'] && !strcmp($GLOBALS['TCA'][$table]['ctrl']['languageField'], $field) && !$this->BE_USER->checkLanguageAccess($fieldValue);
             if (!$languageDeny) {
                 // Stripping slashes - will probably be removed the day $this->stripslashes_values is removed as an option...
                 if ($this->stripslashes_values) {
                     if (is_array($fieldValue)) {
                         \TYPO3\CMS\Core\Utility\GeneralUtility::stripSlashesOnArray($fieldValue);
                     } else {
                         $fieldValue = stripslashes($fieldValue);
                     }
                 }
                 switch ($field) {
                     case 'uid':
                     case 'pid':
                         // Nothing happens, already set
                         break;
                     case 'perms_userid':
                     case 'perms_groupid':
                     case 'perms_user':
                     case 'perms_group':
                     case 'perms_everybody':
                         // Permissions can be edited by the owner or the administrator
                         if ($table == 'pages' && ($this->admin || $status == 'new' || $this->pageInfo($id, 'perms_userid') == $this->userid)) {
                             $value = intval($fieldValue);
                             switch ($field) {
                                 case 'perms_userid':
                                     $fieldArray[$field] = $value;
                                     break;
                                 case 'perms_groupid':
                                     $fieldArray[$field] = $value;
                                     break;
                                 default:
                                     if ($value >= 0 && $value < pow(2, 5)) {
                                         $fieldArray[$field] = $value;
                                     }
                                     break;
                             }
                         }
                         break;
                     case 't3ver_oid':
                     case 't3ver_id':
                     case 't3ver_wsid':
                     case 't3ver_state':
                     case 't3ver_count':
                     case 't3ver_stage':
                     case 't3ver_tstamp':
                         // t3ver_label is not here because it CAN be edited as a regular field!
                         break;
                     default:
                         if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
                             // Evaluating the value
                             $res = $this->checkValue($table, $field, $fieldValue, $id, $status, $realPid, $tscPID);
                             if (isset($res['value'])) {
                                 $fieldArray[$field] = $res['value'];
                             }
                             // Add the value of the original record to the diff-storage content:
                             if ($this->updateModeL10NdiffData && $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']) {
                                 $originalLanguage_diffStorage[$field] = $this->updateModeL10NdiffDataClear ? '' : $originalLanguageRecord[$field];
                                 $diffStorageFlag = TRUE;
                             }
                             // If autoversioning is happening we need to perform a nasty hack. The case is parallel to a similar hack inside checkValue_group_select_file().
                             // When a copy or version is made of a record, a search is made for any RTEmagic* images in fields having the "images" soft reference parser applied.
                             // That should be TRUE for RTE fields. If any are found they are duplicated to new names and the file reference in the bodytext is updated accordingly.
                             // However, with auto-versioning the submitted content of the field will just overwrite the corrected values. This leaves a) lost RTEmagic files and b) creates a double reference to the old files.
                             // The only solution I can come up with is detecting when auto versioning happens, then see if any RTEmagic images was copied and if so make a stupid string-replace of the content !
                             if ($this->autoVersioningUpdate === TRUE) {
                                 if (is_array($this->RTEmagic_copyIndex[$table][$id][$field])) {
                                     foreach ($this->RTEmagic_copyIndex[$table][$id][$field] as $oldRTEmagicName => $newRTEmagicName) {
                                         $fieldArray[$field] = str_replace(' src="' . $oldRTEmagicName . '"', ' src="' . $newRTEmagicName . '"', $fieldArray[$field]);
                                     }
                                 }
                             }
                         } elseif ($GLOBALS['TCA'][$table]['ctrl']['origUid'] === $field) {
                             // Allow value for original UID to pass by...
                             $fieldArray[$field] = $fieldValue;
                         }
                         break;
                 }
             }
         }
     }
     // Add diff-storage information:
     if ($diffStorageFlag && !isset($fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']])) {
         // If the field is set it would probably be because of an undo-operation - in which case we should not update the field of course...
         $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
     }
     // Checking for RTE-transformations of fields:
     $types_fieldConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getTCAtypes($table, $currentRecord);
     $theTypeString = \TYPO3\CMS\Backend\Utility\BackendUtility::getTCAtypeValue($table, $currentRecord);
     if (is_array($types_fieldConfig)) {
         foreach ($types_fieldConfig as $vconf) {
             // Write file configuration:
             // inserted array_merge($currentRecord,$fieldArray) 170502
             $eFile = \TYPO3\CMS\Core\Html\RteHtmlParser::evalWriteFile($vconf['spec']['static_write'], array_merge($currentRecord, $fieldArray));
             // RTE transformations:
             if (!$this->dontProcessTransformations) {
                 if (isset($fieldArray[$vconf['field']])) {
                     // Look for transformation flag:
                     switch ((string) $incomingFieldArray['_TRANSFORM_' . $vconf['field']]) {
                         case 'RTE':
                             $RTEsetup = $this->BE_USER->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($tscPID));
                             $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $table, $vconf['field'], $theTypeString);
                             // Set alternative relative path for RTE images/links:
                             $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
                             // Get RTE object, draw form and set flag:
                             $RTEobj = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEgetObj();
                             if (is_object($RTEobj)) {
                                 $fieldArray[$vconf['field']] = $RTEobj->transformContent('db', $fieldArray[$vconf['field']], $table, $vconf['field'], $currentRecord, $vconf['spec'], $thisConfig, $RTErelPath, $currentRecord['pid']);
                             } else {
                                 debug('NO RTE OBJECT FOUND!');
                             }
                             break;
                     }
                 }
             }
             // Write file configuration:
             if (is_array($eFile)) {
                 $mixedRec = array_merge($currentRecord, $fieldArray);
                 $SW_fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($eFile['editFile']);
                 $parseHTML = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\RteHtmlParser');
                 /** @var $parseHTML \TYPO3\CMS\Core\Html\RteHtmlParser */
                 $parseHTML->init('', '');
                 $eFileMarker = $eFile['markerField'] && trim($mixedRec[$eFile['markerField']]) ? trim($mixedRec[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###';
                 // Must replace the marker if present in content!
                 $insertContent = str_replace($eFileMarker, '', $mixedRec[$eFile['contentField']]);
                 $SW_fileNewContent = $parseHTML->substituteSubpart($SW_fileContent, $eFileMarker, LF . $insertContent . LF, 1, 1);
                 \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($eFile['editFile'], $SW_fileNewContent);
                 // Write status:
                 if (!strstr($id, 'NEW') && $eFile['statusField']) {
                     $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($id), array($eFile['statusField'] => $eFile['relEditFile'] . ' updated ' . date('d-m-Y H:i:s') . ', bytes ' . strlen($mixedRec[$eFile['contentField']])));
                 }
             } elseif ($eFile && is_string($eFile)) {
                 $this->log($table, $id, 2, 0, 1, 'Write-file error: \'%s\'', 13, array($eFile), $realPid);
             }
         }
     }
     // Return fieldArray
     return $fieldArray;
 }
Ejemplo n.º 2
0
    /**
     * Generation of TCEform elements of the type "text"
     * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
     *
     * @param string $table The table name of the record
     * @param string $field The field name which this element is supposed to edit
     * @param array $row The record data array where the value(s) for the field can be found
     * @param array $PA An array with additional configuration options.
     * @return string The HTML code for the TCEform field
     * @todo Define visibility
     */
    public function getSingleField_typeText($table, $field, $row, &$PA)
    {
        // Init config:
        $config = $PA['fieldConf']['config'];
        $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
        if ($this->renderReadonly || $config['readOnly']) {
            return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
        }
        // Setting columns number:
        $cols = MathUtility::forceIntegerInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
        // Setting number of rows:
        $origRows = $rows = MathUtility::forceIntegerInRange($config['rows'] ? $config['rows'] : 5, 1, 20);
        if (strlen($PA['itemFormElValue']) > $this->charsPerRow * 2) {
            $cols = $this->maxTextareaWidth;
            $rows = MathUtility::forceIntegerInRange(round(strlen($PA['itemFormElValue']) / $this->charsPerRow), count(explode(LF, $PA['itemFormElValue'])), 20);
            if ($rows < $origRows) {
                $rows = $origRows;
            }
        }
        if (in_array('required', $evalList)) {
            $this->requiredFields[$table . '_' . $row['uid'] . '_' . $field] = $PA['itemFormElName'];
        }
        // Init RTE vars:
        // Set TRUE, if the RTE is loaded; If not a normal textarea is shown.
        $RTEwasLoaded = 0;
        // Set TRUE, if the RTE would have been loaded if it wasn't for the disable-RTE flag in the bottom of the page...
        $RTEwouldHaveBeenLoaded = 0;
        // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
        $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
        // Setting up the altItem form field, which is a hidden field containing the value
        $altItem = '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
        $item = '';
        // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
        if ($this->RTEenabled) {
            $p = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
            // If the field is configured for RTE and if any flag-field is not set to disable it.
            if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) {
                BackendUtility::fixVersioningPid($table, $row);
                list($tscPID, $thePidValue) = $this->getTSCpid($table, $row['uid'], $row['pid']);
                // If the pid-value is not negative (that is, a pid could NOT be fetched)
                if ($thePidValue >= 0) {
                    $RTEsetup = $this->getBackendUserAuthentication()->getTSConfig('RTE', BackendUtility::getPagesTSconfig($tscPID));
                    $RTEtypeVal = BackendUtility::getTCAtypeValue($table, $row);
                    $thisConfig = BackendUtility::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal);
                    if (!$thisConfig['disabled']) {
                        if (!$this->disableRTE) {
                            $this->RTEcounter++;
                            // Find alternative relative path for RTE images/links:
                            $eFile = RteHtmlParser::evalWriteFile($specConf['static_write'], $row);
                            $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
                            // Get RTE object, draw form and set flag:
                            $RTEobj = BackendUtility::RTEgetObj();
                            $item = $RTEobj->drawRTE($this, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
                            // Wizard:
                            $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, 1);
                            $RTEwasLoaded = 1;
                        } else {
                            $RTEwouldHaveBeenLoaded = 1;
                            $this->commentMessages[] = $PA['itemFormElName'] . ': RTE is disabled by the on-page RTE-flag (probably you can enable it by the check-box in the bottom of this page!)';
                        }
                    } else {
                        $this->commentMessages[] = $PA['itemFormElName'] . ': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
                    }
                } else {
                    $this->commentMessages[] = $PA['itemFormElName'] . ': PID value could NOT be fetched. Rare error, normally with new records.';
                }
            } else {
                if (!isset($specConf['richtext'])) {
                    $this->commentMessages[] = $PA['itemFormElName'] . ': RTE was not configured for this field in TCA-types';
                }
                if (!(!$p['flag'] || !$row[$p['flag']])) {
                    $this->commentMessages[] = $PA['itemFormElName'] . ': Field-flag (' . $PA['flag'] . ') has been set to disable RTE!';
                }
            }
        }
        // Display ordinary field if RTE was not loaded.
        if (!$RTEwasLoaded) {
            // Show message, if no RTE (field can only be edited with RTE!)
            if ($specConf['rte_only']) {
                $item = '<p><em>' . htmlspecialchars($this->getLL('l_noRTEfound')) . '</em></p>';
            } else {
                if ($specConf['nowrap']) {
                    $wrap = 'off';
                } else {
                    $wrap = $config['wrap'] ?: 'virtual';
                }
                $classes = array();
                if ($specConf['fixed-font']) {
                    $classes[] = 'fixed-font';
                }
                if ($specConf['enable-tab']) {
                    $classes[] = 'enable-tab';
                }
                $formWidthText = $this->formWidthText($cols, $wrap);
                // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
                $res = array();
                if (preg_match('/ class="(.+?)"/', $formWidthText, $res)) {
                    $formWidthText = str_replace(' class="' . $res[1] . '"', '', $formWidthText);
                    $classes = array_merge($classes, explode(' ', $res[1]));
                }
                if (count($classes)) {
                    $class = ' class="tceforms-textarea ' . implode(' ', $classes) . '"';
                } else {
                    $class = 'tceforms-textarea';
                }
                $evalList = GeneralUtility::trimExplode(',', $config['eval'], TRUE);
                foreach ($evalList as $func) {
                    switch ($func) {
                        case 'required':
                            $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
                            break;
                        default:
                            // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
                            // and \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_text_Eval()
                            $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
                            if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
                                $_params = array('value' => $PA['itemFormElValue']);
                                $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
                            }
                    }
                }
                $iOnChange = implode('', $PA['fieldChangeFunc']);
                $item .= '
							<textarea ' . 'id="' . uniqid('tceforms-textarea-') . '" ' . 'name="' . $PA['itemFormElName'] . '"' . $formWidthText . $class . ' ' . 'rows="' . $rows . '" ' . 'wrap="' . $wrap . '" ' . 'onchange="' . htmlspecialchars($iOnChange) . '"' . $this->getPlaceholderAttribute($table, $field, $config, $row) . $PA['onFocus'] . '>' . GeneralUtility::formatForTextarea($PA['itemFormElValue']) . '</textarea>';
                $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, $RTEwouldHaveBeenLoaded);
            }
        }
        // Return field HTML:
        return $item;
    }
Ejemplo n.º 3
0
 /**
  * Processing of the content in $totalRecordcontent based on settings in the types-configuration
  *
  * @param array $totalRecordContent The array of values which has been processed according to their type (eg. "group" or "select")
  * @param array $types_fieldConfig The "types" configuration for the current display of fields.
  * @param integer $tscPID PAGE TSconfig PID
  * @param string $table Table name
  * @param integer $pid PID value
  * @return array The processed version of $totalRecordContent
  * @access private
  * @todo Define visibility
  */
 public function renderRecord_typesProc($totalRecordContent, $types_fieldConfig, $tscPID, $table, $pid)
 {
     foreach ($types_fieldConfig as $vconf) {
         // Find file to write to, if configured:
         $eFile = \TYPO3\CMS\Core\Html\RteHtmlParser::evalWriteFile($vconf['spec']['static_write'], $totalRecordContent);
         // Write file configuration:
         if (is_array($eFile)) {
             if ($eFile['loadFromFileField'] && $totalRecordContent[$eFile['loadFromFileField']]) {
                 // Read the external file, and insert the content between the ###TYPO3_STATICFILE_EDIT### markers:
                 $SW_fileContent = GeneralUtility::getUrl($eFile['editFile']);
                 $parseHTML = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\RteHtmlParser');
                 $parseHTML->init('', '');
                 $totalRecordContent[$vconf['field']] = $parseHTML->getSubpart($SW_fileContent, $eFile['markerField'] && trim($totalRecordContent[$eFile['markerField']]) ? trim($totalRecordContent[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###');
             }
         }
     }
     return $totalRecordContent;
 }