/** * The main method called by the controller * * @return array The probably modified GET/POST parameters */ public function process() { $isSpam = $this->doCheck(); if ($isSpam) { $this->log(TRUE); if ($this->settings['redirectPage']) { Tx_Formhandler_Globals::$session->reset(); Tx_Formhandler_Staticfuncs::doRedirect($this->settings['redirectPage'], $this->settings['correctRedirectUrl'], $this->settings['additionalParams.']); return 'Lousy spammer!'; } else { $view = $this->componentManager->getComponent('Tx_Formhandler_View_AntiSpam'); $view->setLangFiles(Tx_Formhandler_Globals::$langFiles); $view->setPredefined($this->predefined); $templateCode = Tx_Formhandler_Globals::$templateCode; $view->setTemplate($templateCode, 'ANTISPAM'); if (!$view->hasTemplate()) { Tx_Formhandler_StaticFuncs::throwException('spam_detected'); return 'Lousy spammer!'; } $content = $view->render($this->gp, array()); Tx_Formhandler_Globals::$session->reset(); return $content; } } return $this->gp; }
/** * The constructor reading the TS setup into the according attribute * * @return void */ public function __construct() { if (TYPO3_MODE === 'FE') { $this->setup = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->getPrefixedPackageKey() . '.']; if (!is_array($this->setup)) { Tx_Formhandler_StaticFuncs::throwException('missing_config'); } if (is_array(Tx_Formhandler_Globals::$overrideSettings)) { $this->setup = t3lib_div::array_merge_recursive_overrule($this->setup, Tx_Formhandler_Globals::$overrideSettings); } } }
/** * Renders the CSV. * * @return void */ public function process() { $this->pdf = $this->componentManager->getComponent('Tx_Formhandler_Template_TCPDF'); $this->pdf->setHeaderText(Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'headerText')); $this->pdf->setFooterText(Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'footerText')); $this->pdf->AddPage(); $this->pdf->SetFont('Helvetica', '', 12); $view = $this->componentManager->getComponent('Tx_Formhandler_View_PDF'); $this->filename = FALSE; if (intval($this->settings['storeInTempFile']) === 1) { $this->outputPath = t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT'); if ($this->settings['customTempOutputPath']) { $this->outputPath .= Tx_Formhandler_StaticFuncs::sanitizePath($this->settings['customTempOutputPath']); } else { $this->outputPath .= '/typo3temp/'; } $this->filename = $this->outputPath . $this->settings['filePrefix'] . Tx_Formhandler_StaticFuncs::generateHash() . '.pdf'; $this->filenameOnly = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'staticFileName'); if (strlen($this->filenameOnly) === 0) { $this->filenameOnly = basename($this->filename); } } $this->formhandlerSettings = Tx_Formhandler_Globals::$settings; $suffix = $this->formhandlerSettings['templateSuffix']; $this->templateCode = Tx_Formhandler_StaticFuncs::readTemplateFile(FALSE, $this->formhandlerSettings); if ($suffix) { $view->setTemplate($this->templateCode, 'PDF' . $suffix); } if (!$view->hasTemplate()) { $view->setTemplate($this->templateCode, 'PDF'); } if (!$view->hasTemplate()) { Tx_Formhandler_StaticFuncs::throwException('no_pdf_template'); } $view->setComponentSettings($this->settings); $content = $view->render($this->gp, array()); $this->pdf->writeHTML($content); $returns = $this->settings['returnFileName']; if ($this->filename !== FALSE) { $this->pdf->Output($this->filename, 'F'); $downloadpath = $this->filename; if ($returns) { return $downloadpath; } $downloadpath = str_replace(t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '', $downloadpath); header('Location: ' . $downloadpath); exit; } else { $this->pdf->Output('formhandler.pdf', 'D'); exit; } }
/** * Method to define whether the config is valid or not. If no, display a warning on the frontend. * The default value is TRUE. This up to the finisher to overload this method * */ public function validateConfig() { $settings = Tx_Formhandler_Globals::$settings; if (is_array($settings['finishers.'])) { $found = FALSE; foreach ($settings['finishers.'] as $finisherConfig) { if (strstr($finisherConfig['class'], 'Finisher_RestoreLanguage')) { $found = TRUE; } } if (!$found) { Tx_Formhandler_StaticFuncs::throwException('No Finisher_RestoreLanguage found in the TypoScript setup! You have to reset the language to the original value after you changed it using Finisher_SetLanguage'); } } return $found; }
protected function log($markAsSpam = FALSE) { $classesArray = $this->settings['loggers.']; if (isset($classesArray) && is_array($classesArray)) { foreach ($classesArray as $idx => $tsConfig) { if (is_array($tsConfig) && isset($tsConfig['class']) && !empty($tsConfig['class']) && intval($tsConfig['disable']) !== 1) { $className = Tx_Formhandler_StaticFuncs::prepareClassName($tsConfig['class']); Tx_Formhandler_StaticFuncs::Message('calling_class', array($className)); $obj = $this->componentManager->getComponent($className); if ($markAsSpam) { $tsConfig['config.']['markAsSpam'] = 1; } $obj->init($this->gp, $tsConfig['config.']); $obj->process(); } else { Tx_Formhandler_StaticFuncs::throwException('classesarray_error'); } } } }
/** * Main method called by the controller. * * @param array $gp The current GET/POST parameters * @param array $errors The errors occurred in validation * @return string content */ public function render($gp, $errors) { //set GET/POST parameters $this->gp = $gp; //set template $this->template = $this->subparts['template']; if (!$this->template) { Tx_Formhandler_StaticFuncs::throwException('no_template_file'); } $this->errors = $errors; //set language file if (!$this->langFiles) { $this->langFiles = Tx_Formhandler_Globals::$langFiles; } //fill Typoscript markers if (is_array($this->settings['markers.'])) { $this->fillTypoScriptMarkers(); } //read master template if (!$this->masterTemplates) { $this->readMasterTemplates(); } if (!empty($this->masterTemplates)) { $this->replaceMarkersFromMaster(); } if (Tx_Formhandler_Globals::$ajaxHandler) { $markers = array(); Tx_Formhandler_Globals::$ajaxHandler->fillAjaxMarkers($markers); $this->template = $this->cObj->substituteMarkerArray($this->template, $markers); } //fill Typoscript markers if (is_array($this->settings['markers.'])) { $this->fillTypoScriptMarkers(); } $this->substituteHasTranslationSubparts(); if (!$this->gp['submitted']) { $this->storeStartEndBlock(); } elseif (intval(Tx_Formhandler_Globals::$session->get('currentStep')) !== 1) { $this->fillStartEndBlock(); } if (intval($this->settings['fillValueMarkersBeforeLangMarkers']) === 1) { //fill value_[fieldname] markers $this->fillValueMarkers(); } //fill LLL:[language_key] markers $this->fillLangMarkers(); //substitute ISSET markers $this->substituteIssetSubparts(); //fill default markers $this->fillDefaultMarkers(); if (intval($this->settings['fillValueMarkersBeforeLangMarkers']) !== 1) { //fill value_[fieldname] markers $this->fillValueMarkers(); } //fill selected_[fieldname]_value markers and checked_[fieldname]_value markers $this->fillSelectedMarkers(); //fill LLL:[language_key] markers again to make language markers in other markers possible $this->fillLangMarkers(); //fill error_[fieldname] markers if (!empty($errors)) { $this->fillIsErrorMarkers($errors); $this->fillErrorMarkers($errors); } //remove markers that were not substituted $content = Tx_Formhandler_StaticFuncs::removeUnfilledMarkers($this->template); return $this->pi_wrapInBaseClass($content); }
/** * Inits the finisher mapping settings values to internal attributes. * * @return void */ public function init($gp, $settings) { parent::init($gp, $settings); //set table $this->table = $this->settings['table']; if (!$this->table) { Tx_Formhandler_StaticFuncs::throwException('no_table', 'Tx_Formhandler_Finisher_DB'); return; } if (!is_array($this->settings['fields.'])) { Tx_Formhandler_StaticFuncs::throwException('no_fields', 'Tx_Formhandler_Finisher_DB'); return; } //set primary key field $this->key = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'key'); if (strlen($this->key) === 0) { $this->key = 'uid'; } //check whether to update or to insert a record $this->doUpdate = FALSE; if ($this->settings['updateInsteadOfInsert']) { $this->doUpdate = TRUE; } }
/** * Runs the class by calling process() method. * * @author Reinhard Führicht <*****@*****.**> * @param array $classesArray: the configuration array * @return void */ protected function runClasses($classesArray) { $output = ''; if (isset($classesArray) && is_array($classesArray) && intval($classesArray['disable']) !== 1) { foreach ($classesArray as $idx => $tsConfig) { if (is_array($tsConfig) && isset($tsConfig['class']) && !empty($tsConfig['class'])) { if (intval($tsConfig['disable']) !== 1) { $className = Tx_Formhandler_StaticFuncs::prepareClassName($tsConfig['class']); Tx_Formhandler_StaticFuncs::debugMessage('calling_class', array($className)); $obj = $this->componentManager->getComponent($className); $tsConfig['config.'] = $this->addDefaultComponentConfig($tsConfig['config.']); $obj->init($this->gp, $tsConfig['config.']); $obj->validateConfig(); $return = $obj->process(); if (is_array($return)) { //return value is an array. Treat it as the probably modified get/post parameters $this->gp = $return; Tx_Formhandler_Globals::$gp = $this->gp; } else { //return value is no array. treat this return value as output. return $return; } } } else { Tx_Formhandler_StaticFuncs::throwException('classesarray_error'); } } } }
/** * Read template file set in flexform or TypoScript, read the file's contents to $this->templateFile * * @param $settings The formhandler settings * @return void * @author Reinhard Führicht <*****@*****.**> */ public static function readTemplateFile($templateFile, &$settings) { $templateCode = FALSE; //template file was not set in flexform, search TypoScript for setting if (!$templateFile) { if (!$settings['templateFile'] && !!$settings['templateFile.']) { return ''; } $templateFile = $settings['templateFile']; if (isset($settings['templateFile.']) && is_array($settings['templateFile.'])) { $templateFile = Tx_Formhandler_StaticFuncs::getSingle($settings, 'templateFile'); if (strpos($templateFile, "\n") === FALSE) { $templateFile = Tx_Formhandler_StaticFuncs::resolvePath($templateFile); if (!@file_exists($templateFile)) { Tx_Formhandler_StaticFuncs::throwException('template_file_not_found', $templateFile); } $templateCode = t3lib_div::getURL($templateFile); } } else { $templateFile = Tx_Formhandler_StaticFuncs::resolvePath($templateFile); if (!@file_exists($templateFile)) { Tx_Formhandler_StaticFuncs::throwException('template_file_not_found', $templateFile); } $templateCode = t3lib_div::getURL($templateFile); } } else { if (strpos($templateFile, "\n") === FALSE) { $templateFile = Tx_Formhandler_StaticFuncs::resolvePath($templateFile); if (!@file_exists($templateFile)) { Tx_Formhandler_StaticFuncs::throwException('template_file_not_found', $templateFile); } $templateCode = t3lib_div::getURL($templateFile); } else { // given variable $templateFile already contains the template code $templateCode = $templateFile; } } if (strlen($templateCode) === 0) { Tx_Formhandler_StaticFuncs::throwException('empty_template_file', $templateFile); } if (stristr($templateCode, '###TEMPLATE_') === FALSE) { Tx_Formhandler_StaticFuncs::throwException('invalid_template_file', $templateFile); } return $templateCode; }