/** * Method to set GET/POST for this class and load the configuration * * @param array The GET/POST values * @param array The TypoScript configuration * @return void */ public function init($gp, $tsConfig) { $this->gp = $gp; $this->settings = $tsConfig; $redirect = Tx_Formhandler_StaticFuncs::pi_getFFvalue($this->cObj->data['pi_flexform'], 'redirect_page', 'sMISC'); if ($redirect) { $this->settings['redirectPage'] = $redirect; } }
/** * The main method called by the controller * * @return array The probably modified GET/POST parameters */ public function process() { $firstInsertInfo = array(); if (is_array($this->gp['saveDB'])) { if (isset($this->settings['table'])) { foreach ($this->gp['saveDB'] as $idx => $insertInfo) { if ($insertInfo['table'] === $this->settings['table']) { $firstInsertInfo = $insertInfo; break; } } } if (empty($firstInsertInfo)) { reset($this->gp['saveDB']); $firstInsertInfo = current($this->gp['saveDB']); } } $table = $firstInsertInfo['table']; $uid = $firstInsertInfo['uid']; $uidField = $firstInsertInfo['uidField']; if (!$uidField) { $uidField = 'uid'; } if ($table && $uid && $uidField) { $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, $uidField . '=' . $uid); if ($res) { $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $authCode = $this->generateAuthCode($row); $this->gp['generated_authCode'] = $authCode; // looking for the page, which should be used for the authCode Link // first look for TS-setting 'authCodePage', second look for redirect_page-setting, third use actual page $authCodePage = ''; if (isset($this->settings['authCodePage'])) { $authCodePage = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'authCodePage'); } else { $authCodePage = Tx_Formhandler_StaticFuncs::pi_getFFvalue($this->cObj->data['pi_flexform'], 'redirect_page', 'sMISC'); } if (!$authCodePage) { $authCodePage = $GLOBALS['TSFE']->id; } //create the parameter-array for the authCode Link $paramsArray = array_merge($firstInsertInfo, array('authCode' => $authCode)); // If we have set a formValuesPrefix, add it to the parameter-array if (!empty(Tx_Formhandler_Globals::$formValuesPrefix)) { $paramsArray = array(Tx_Formhandler_Globals::$formValuesPrefix => $paramsArray); } // create the link, using typolink function, use baseUrl if set, else use t3lib_div::getIndpEnv('TYPO3_SITE_URL') $url = $this->cObj->getTypoLink_URL($authCodePage, $paramsArray); $tmpArr = parse_url($url); if (empty($tmpArr['scheme'])) { $url = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . ltrim($url, '/'); } $this->gp['authCodeUrl'] = $url; } } return $this->gp; }
/** * Method to set GET/POST for this class and load the configuration * * @param array The GET/POST values * @param array The TypoScript configuration * @return void */ public function init($gp, $tsConfig) { $this->settings = $tsConfig; $flexformValue = Tx_Formhandler_StaticFuncs::pi_getFFvalue($this->cObj->data['pi_flexform'], 'required_fields', 'sMISC'); if ($flexformValue) { $fields = t3lib_div::trimExplode(',', $flexformValue); foreach ($fields as $field) { if (!is_array($this->settings['fieldConf.'][$field . '.']['errorCheck.'])) { $this->settings['fieldConf.'][$field . '.']['errorCheck.'] = array(); } if (!array_search('required', $this->settings['fieldConf.'][$field . '.']['errorCheck.'])) { array_push($this->settings['fieldConf.'][$field . '.']['errorCheck.'], 'required'); } } } $this->gp = $gp; }
/** * Fills the file specific markers: * * ###[fieldname]_minSize### * ###[fieldname]_maxSize### * ###[fieldname]_allowedTypes### * ###[fieldname]_maxCount### * ###[fieldname]_fileCount### * ###[fieldname]_remainingCount### * * ###[fieldname]_uploadedFiles### * ###total_uploadedFiles### * * @param array &$markers Reference to the markers array * @return void */ public function fillFileMarkers(&$markers) { $settings = $this->parseSettings(); $flexformValue = Tx_Formhandler_StaticFuncs::pi_getFFvalue($this->cObj->data['pi_flexform'], 'required_fields', 'sMISC'); if ($flexformValue) { $fields = t3lib_div::trimExplode(',', $flexformValue); if (is_array($settings['validators.'])) { // Searches the index of Tx_Formhandler_Validator_Default foreach ($settings['validators.'] as $index => $validator) { if ($validator['class'] == 'Tx_Formhandler_Validator_Default') { break; } } } else { $index = 1; } // Adds the value. foreach ($fields as $idx => $field) { $settings['validators.'][$index . '.']['config.']['fieldConf.'][$field . '.']['errorCheck.'] = array(); $settings['validators.'][$index . '.']['config.']['fieldConf.'][$field . '.']['errorCheck.']['1'] = 'required'; } } $sessionFiles = Tx_Formhandler_Globals::$session->get('files'); //parse validation settings if (is_array($settings['validators.'])) { foreach ($settings['validators.'] as $key => $validatorSettings) { if (is_array($validatorSettings['config.']) && is_array($validatorSettings['config.']['fieldConf.'])) { foreach ($validatorSettings['config.']['fieldConf.'] as $fieldname => $fieldSettings) { $replacedFieldname = str_replace('.', '', $fieldname); if (is_array($fieldSettings['errorCheck.'])) { foreach ($fieldSettings['errorCheck.'] as $key => $check) { switch ($check) { case 'fileMinSize': $minSize = $fieldSettings['errorCheck.'][$key . '.']['minSize']; $markers['###' . $replacedFieldname . '_minSize###'] = t3lib_div::formatSize($minSize, ' Bytes | KB | MB | GB'); break; case 'fileMaxSize': $maxSize = $fieldSettings['errorCheck.'][$key . '.']['maxSize']; $markers['###' . $replacedFieldname . '_maxSize###'] = t3lib_div::formatSize($maxSize, ' Bytes | KB | MB | GB'); break; case 'fileAllowedTypes': $types = $fieldSettings['errorCheck.'][$key . '.']['allowedTypes']; $markers['###' . $replacedFieldname . '_allowedTypes###'] = $types; break; case 'fileMaxCount': $maxCount = $fieldSettings['errorCheck.'][$key . '.']['maxCount']; $markers['###' . $replacedFieldname . '_maxCount###'] = $maxCount; $fileCount = count($sessionFiles[str_replace('.', '', $fieldname)]); $markers['###' . $replacedFieldname . '_fileCount###'] = $fileCount; $remaining = $maxCount - $fileCount; $markers['###' . $replacedFieldname . '_remainingCount###'] = $remaining; break; case 'fileMinCount': $minCount = $fieldSettings['errorCheck.'][$key . '.']['minCount']; $markers['###' . $replacedFieldname . '_minCount###'] = $minCount; break; case 'required': case 'fileRequired': case 'jmRecaptcha': case 'captcha': case 'srFreecap': case 'mathguard': $requiredSign = Tx_Formhandler_StaticFuncs::getSingle($settings, 'requiredSign'); if (strlen($requiredSign) === 0) { $requiredSign = '*'; } $markers['###required_' . $replacedFieldname . '###'] = $requiredSign; break; } } } } } } } if (is_array($sessionFiles)) { $singleWrap = $settings['singleFileMarkerTemplate.']['singleWrap']; $totalMarkerSingleWrap = $settings['totalFilesMarkerTemplate.']['singleWrap']; $totalWrap = $settings['singleFileMarkerTemplate.']['totalWrap']; $totalMarkersTotalWrap = $settings['totalFilesMarkerTemplate.']['totalWrap']; foreach ($sessionFiles as $field => $files) { foreach ($files as $idx => $fileInfo) { $filename = $fileInfo['name']; $thumb = ''; if (intval($settings['singleFileMarkerTemplate.']['showThumbnails']) === 1 || intval($settings['singleFileMarkerTemplate.']['showThumbnails']) === 2) { $imgConf['image.'] = $settings['singleFileMarkerTemplate.']['image.']; $thumb = $this->getThumbnail($imgConf, $fileInfo); } $text = Tx_Formhandler_StaticFuncs::getSingle($settings['files.'], 'customRemovalText'); if (strlen($text) === 0) { $text = 'X'; } $link = ''; $uploadedFileName = $fileInfo['uploaded_name']; if (!$uploadedFileName) { $uploadedFileName = $fileInfo['name']; } if (Tx_Formhandler_Globals::$ajaxHandler && $settings['files.']['enableAjaxFileRemoval']) { $link = Tx_Formhandler_Globals::$ajaxHandler->getFileRemovalLink($text, $field, $uploadedFileName); } elseif ($settings['files.']['enableFileRemoval']) { $submitName = 'step-' . Tx_Formhandler_Globals::$session->get('currentStep') . '-reload'; if (Tx_Formhandler_Globals::$formValuesPrefix) { $submitName = Tx_Formhandler_Globals::$formValuesPrefix . '[' . $submitName . ']'; } $onClick = "\n\t\t\t\t\t\t\tdocument.getElementById('removeFile-" . Tx_Formhandler_Globals::$randomID . "').value='" . $uploadedFileName . "';\n\t\t\t\t\t\t\tdocument.getElementById('removeFileField-" . Tx_Formhandler_Globals::$randomID . "').value='" . $field . "';\n\t\t\t\t\t\t\tdocument.getElementById('submitField-" . Tx_Formhandler_Globals::$randomID . "').name='" . $submitName . "';\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t"; if (Tx_Formhandler_Globals::$formID) { $onClick .= "document.getElementById('" . Tx_Formhandler_Globals::$formID . "').submit();"; } else { $onClick .= 'document.forms[0].submit();'; } $onClick .= 'return false;'; $link = '<a href="javascript:void(0)" class="formhandler_removelink" onclick="' . str_replace(array("\n", ' '), '', $onClick) . '" >' . $text . '</a>'; } if (strlen($singleWrap) > 0 && strstr($singleWrap, '|')) { $wrappedFilename = str_replace('|', $filename . $link, $singleWrap); $wrappedThumb = str_replace('|', $thumb . $link, $singleWrap); $wrappedThumbFilename = str_replace('|', $thumb . ' ' . $filename . $link, $singleWrap); } else { $wrappedFilename = $filename . $link; $wrappedThumb = $thumb . $link; $wrappedThumbFilename = $thumb . ' ' . $filename . $link; } if (intval($settings['singleFileMarkerTemplate.']['showThumbnails']) === 1) { $markers['###' . $field . '_uploadedFiles###'] .= $wrappedThumb; } elseif (intval($settings['singleFileMarkerTemplate.']['showThumbnails']) === 2) { $markers['###' . $field . '_uploadedFiles###'] .= $wrappedThumbFilename; } else { $markers['###' . $field . '_uploadedFiles###'] .= $wrappedFilename; } $uploadedFileName = $fileInfo['name']; if (!$uploadedFileName) { $uploadedFileName = $fileInfo['uploaded_name']; } if (intval($settings['totalFilesMarkerTemplate.']['showThumbnails']) === 1 || intval($settings['totalFilesMarkerTemplate.']['showThumbnails']) === 2) { $imgConf['image.'] = $settings['totalFilesMarkerTemplate.']['image.']; if (!$imgconf['image.']) { $imgConf['image.'] = $settings['singleFileMarkerTemplate.']['image.']; } $thumb = $this->getThumbnail($imgConf, $fileInfo); } if (strlen($totalMarkerSingleWrap) > 0 && strstr($totalMarkerSingleWrap, '|')) { $wrappedFilename = str_replace('|', $filename . $link, $totalMarkerSingleWrap); $wrappedThumb = str_replace('|', $thumb . $link, $totalMarkerSingleWrap); $wrappedThumbFilename = str_replace('|', $thumb . ' ' . $filename . $link, $totalMarkerSingleWrap); } else { $wrappedFilename = $filename . $link; $wrappedThumb = $thumb . $link; $wrappedThumbFilename = $thumb . $filename . $link; } if (intval($settings['totalFilesMarkerTemplate.']['showThumbnails']) === 1) { $markers['###total_uploadedFiles###'] .= $wrappedThumb; } elseif (intval($settings['totalFilesMarkerTemplate.']['showThumbnails']) === 2) { $markers['###total_uploadedFiles###'] .= wrappedThumbFilename; } else { $markers['###total_uploadedFiles###'] .= $wrappedFilename; } } if (strlen($totalWrap) > 0 && strstr($totalWrap, '|')) { $markers['###' . $field . '_uploadedFiles###'] = str_replace('|', $markers['###' . $field . '_uploadedFiles###'], $totalWrap); } $markers['###' . $field . '_uploadedFiles###'] = '<div id="Tx_Formhandler_UploadedFiles_' . $field . '">' . $markers['###' . $field . '_uploadedFiles###'] . '</div>'; } if (strlen($totalMarkersTotalWrap) > 0 && strstr($totalMarkersTotalWrap, '|')) { $markers['###total_uploadedFiles###'] = str_replace('|', $markers['###total_uploadedFiles###'], $totalMarkersTotalWrap); } $markers['###TOTAL_UPLOADEDFILES###'] = $markers['###total_uploadedFiles###']; $markers['###total_uploadedfiles###'] = $markers['###total_uploadedFiles###']; } $requiredSign = Tx_Formhandler_StaticFuncs::getSingle($settings, 'requiredSign'); if (strlen($requiredSign) === 0) { $requiredSign = '*'; } $markers['###required###'] = $requiredSign; $markers['###REQUIRED###'] = $markers['###required###']; }
/** * Parses the email settings in flexform of a specific type (admin|user] * * @param array $currentSettings The current settings array containing the settings made via TypoScript * @param string $type (admin|user) * @param array $optionsToParse Array containing all option names to parse. * @return array The parsed email settings */ private function parseEmailSettingsByType($currentSettings, $type, $optionsToParse = array()) { $typeLower = strtolower($type); $typeUpper = strtoupper($type); $section = 'sEMAIL' . $typeUpper; $emailSettings = $currentSettings; foreach ($optionsToParse as $idx => $option) { $value = Tx_Formhandler_StaticFuncs::pi_getFFvalue($this->cObj->data['pi_flexform'], $option, $section); if (strlen($value) > 0) { $emailSettings[$option] = $value; if (isset($this->gp[$value])) { $emailSettings[$option] = $this->gp[$value]; } } else { switch ($option) { case 'to_email': case 'to_name': case 'sender_email': case 'replyto_email': case 'cc_email': case 'bcc_email': case 'return_path': $emailSettings[$option] = $this->parseList($currentSettings, $type, $option); break; case 'subject': case 'sender_name': case 'replyto_name': case 'cc_name': case 'bcc_name': $emailSettings[$option] = $this->parseValue($currentSettings, $type, $option); break; case 'attachment': $emailSettings[$option] = $this->parseFilesList($currentSettings, $type, $option); break; case 'attachPDF': if (isset($currentSettings['attachPDF.']) && is_array($currentSettings['attachPDF.'])) { $generatorClass = $currentSettings['attachPDF.']['class']; if ($generatorClass) { $generatorClass = Tx_Formhandler_StaticFuncs::prepareClassName($generatorClass); $generator = $this->componentManager->getComponent($generatorClass); $generator->init($this->gp, $currentSettings['attachPDF.']['config.']); $file = $generator->process(); unset($currentSettings['attachPDF.']); $emailSettings['attachPDF'] = $file; } } elseif ($currentSettings['attachPDF']) { $emailSettings['attachPDF'] = $currentSettings['attachPDF']; } break; case 'htmlEmailAsAttachment': if (isset($currentSettings['htmlEmailAsAttachment']) && !strcmp($currentSettings['htmlEmailAsAttachment'], '1')) { $emailSettings['htmlEmailAsAttachment'] = 1; } break; case 'filePrefix': if (isset($currentSettings['filePrefix'])) { $emailSettings['filePrefix'] = $currentSettings['filePrefix']; } break; case 'plain.': if (isset($currentSettings['plain.'])) { $emailSettings['plain.'] = $currentSettings['plain.']; } break; case 'html.': if (isset($currentSettings['html.'])) { $emailSettings['html.'] = $currentSettings['html.']; } break; } } } $this->fillLangMarkersInSettings($emailSettings); return $emailSettings; }
public function validateConfig() { $options = array(array('to_email', 'sEMAILADMIN', 'finishers', 'Tx_Formhandler_Finisher_Mail'), array('to_email', 'sEMAILUSER', 'finishers', 'Tx_Formhandler_Finisher_Mail'), array('redirect_page', 'sMISC', 'finishers', 'Tx_Formhandler_Finisher_Redirect'), array('required_fields', 'sMISC', 'validators', 'Tx_Formhandler_Validator_Default')); foreach ($options as $idx => $option) { $fieldName = $option[0]; $flexformSection = $option[1]; $component = $option[2]; $componentName = $option[3]; $value = Tx_Formhandler_StaticFuncs::pi_getFFvalue($this->cObj->data['pi_flexform'], $fieldName, $flexformSection); // Check if a Mail Finisher can be found in the config $isConfigOk = FALSE; if (is_array($this->settings[$component . '.'])) { foreach ($this->settings[$component . '.'] as $idx => $finisher) { if ($finisher['class'] == $componentName || @is_subclass_of($finisher['class'], $componentName)) { $isConfigOk = TRUE; break; } elseif ($finisher['class'] == str_replace('Tx_Formhandler_', '', $componentName) || @is_subclass_of('Tx_Formhandler_' . $finisher['class'], $componentName)) { $isConfigOk = TRUE; break; } } } // Throws an Exception if a problem occurs if ($value != '' && !$isConfigOk) { Tx_Formhandler_StaticFuncs::throwException('missing_component', $component, $value, $componentName); } } }