Esempio n. 1
0
 /**
  * Returns a component object from the cache. If there is no object stored already, a new one is created and stored in the cache.
  *
  * @param string $componentName
  * @return mixed
  * @author Robert Lemke <*****@*****.**>
  * @author adapted for TYPO3v4 by Jochen Rau <*****@*****.**>
  */
 public function getComponent($componentName)
 {
     $componentName = $this->utilityFuncs->prepareClassName($componentName);
     //Avoid component manager creating multiple instances of itself
     if (get_class($this) === $componentName) {
         return $this;
     }
     $arguments = array_slice(func_get_args(), 1, NULL, TRUE);
     /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
     $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
     $componentObject = $objectManager->get($componentName, $arguments);
     return $componentObject;
 }
 /**
  * Initialize the class. Read GET parameters
  *
  * @return void
  */
 protected function init()
 {
     if (isset($_GET['pid'])) {
         $id = intval($_GET['pid']);
     } else {
         $id = intval($_GET['id']);
     }
     $this->componentManager = GeneralUtility::makeInstance(\Typoheads\Formhandler\Component\Manager::class);
     \Typoheads\Formhandler\Utility\GeneralUtility::initializeTSFE($id);
     $elementUID = intval($_GET['uid']);
     $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $elementUID . $GLOBALS['TSFE']->cObj->enableFields('tt_content'));
     if (!empty($row)) {
         $GLOBALS['TSFE']->cObj->data = $row;
         $GLOBALS['TSFE']->cObj->current = 'tt_content_' . $elementUID;
     }
     Globals::setCObj($GLOBALS['TSFE']->cObj);
     $randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID'));
     Globals::setRandomID($randomID);
     Globals::setAjaxMode(TRUE);
     if (!Globals::getSession()) {
         $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
         $sessionClass = \Typoheads\Formhandler\Utility\GeneralUtility::getPreparedClassName($ts['session.'], 'Session\\PHP');
         Globals::setSession($this->componentManager->getComponent($sessionClass));
     }
     $this->settings = Globals::getSession()->get('settings');
     //init ajax
     if ($this->settings['ajax.']) {
         $class = \Typoheads\Formhandler\Utility\GeneralUtility::getPreparedClassName($this->settings['ajax.'], 'AjaxHandler\\JQuery');
         $ajaxHandler = $this->componentManager->getComponent($class);
         Globals::setAjaxHandler($ajaxHandler);
         $ajaxHandler->init($this->settings['ajax.']['config.']);
         $ajaxHandler->initAjax();
     }
 }
 /**
  * Retrieves the data of the given auth code from the database.
  * Before executing the query to get the auth code data expired auth codes are deleted from the database if this is not disabled in the settings.
  * If a valid auth code is found the code is refreshed to prevent expiration whil the user accesses a protected page.
  *
  * @param string $authCode the submitted auth code
  * @return \Tx\Authcode\Domain\Model\AuthCode|NULL NULL if no data was found, otherwise an associative array of the auth code data
  */
 public function getAuthCodeDataFromDB($authCode)
 {
     $this->formhandlerUtils->debugMessage('Trying to read auth code data from database');
     $authCode = $this->authCodeRepository->findOneByAuthCode($authCode);
     if (isset($authCode)) {
         $this->authCodeRepository->refreshAuthCode($authCode);
     }
     return $authCode;
 }
 /**
  * Main method of the dispatcher. This method is called as a user function.
  *
  * @return string rendered view
  * @param string $content
  * @param array $setup The TypoScript config
  */
 public function main($content, $setup)
 {
     $this->pi_USER_INT_obj = 1;
     $this->componentManager = GeneralUtility::makeInstance(\Typoheads\Formhandler\Component\Manager::class);
     $this->globals = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\Globals::class);
     $this->utilityFuncs = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\GeneralUtility::class);
     try {
         //init flexform
         $this->pi_initPIflexForm();
         /*
          * Parse values from flexform:
          * - Template file
          * - Translation file
          * - Predefined form
          * - E-mail settings
          * - Required fields
          * - Redirect page
          */
         $templateFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 'sDEF');
         $langFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'lang_file', 'sDEF');
         $predef = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'predefined', 'sDEF');
         $this->globals->setCObj($this->cObj);
         $this->globals->getCObj()->setCurrentVal($predef);
         if ($setup['usePredef']) {
             $predef = $this->utilityFuncs->getSingle($setup, 'usePredef');
         }
         $this->globals->setPredef($predef);
         $this->globals->setOverrideSettings($setup);
         /*
          * set controller:
          * 1. Default controller
          * 2. TypoScript
          */
         $controller = '\\Typoheads\\Formhandler\\Controller\\Form';
         if ($setup['controller']) {
             $controller = $setup['controller'];
         }
         /** @var \Typoheads\Formhandler\Controller\AbstractController $controller */
         $controller = $this->componentManager->getComponent($controller);
         if (isset($content)) {
             $controller->setContent($this->componentManager->getComponent($this->utilityFuncs->prepareClassName('Typoheads\\Formhandler\\Controller\\Content'), $content));
         }
         if (strlen($templateFile) > 0) {
             $controller->setTemplateFile($templateFile);
         }
         if (strlen($langFile) > 0) {
             $controller->setLangFiles([$langFile]);
         }
         if (strlen($predef) > 0) {
             $controller->setPredefined($predef);
         }
         $result = $controller->process();
     } catch (\Exception $e) {
         \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getFile() . '(' . $e->getLine() . ')' . ' ' . $e->getMessage(), 'formhandler', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
         $result = $this->utilityFuncs->getTranslatedMessage($this->globals->getLangFiles(), 'fe-exception');
         if (!$result) {
             $result = '<div style="color:red; font-weight: bold">' . $this->utilityFuncs->getExceptionMessage('fe-exception') . '</div>';
         }
         if ($this->globals->getSession() && $this->globals->getSession()->get('debug')) {
             $result = '<div style="color:red; font-weight: bold">' . $e->getMessage() . '</div>';
             $result .= '<div style="color:red; font-weight: bold">File: ' . $e->getFile() . '(' . $e->getLine() . ')</div>';
             $result .= '<div style="color:red; font-weight: bold">' . $e->getTraceAsString() . '</div>';
         }
     }
     if ($this->globals->getSession() && $this->globals->getSession()->get('debug')) {
         $debuggers = $this->globals->getDebuggers();
         foreach ($debuggers as $idx => $debugger) {
             $debugger->outputDebugLog();
         }
     }
     return $result;
 }
 /**
  * improved copy from dam_index
  *
  * Returns HTML of a box with a step counter and "back" and "next" buttons
  * Use label "next"/"prev" or "next_[stepnumber]"/"prev_[stepnumber]" for specific step in language file as button text.
  *
  * <code>
  * #set background color
  * plugin.Tx_Formhandler.settings.stepbar_color = #EAEAEA
  * #use default CSS, written to temp file
  * plugin.Tx_Formhandler.settings.useDefaultStepBarStyles = 1
  * </code>
  *
  * @author Johannes Feustel
  * @param    integer $currentStep current step (begins with 1)
  * @param    integer $lastStep last step
  * @param    string $buttonNameBack name attribute of the back button
  * @param    string $buttonNameFwd name attribute of the forward button
  * @return    string    HTML code
  */
 protected function createStepBar($currentStep, $lastStep, $buttonNameBack = '', $buttonNameFwd = '')
 {
     //colors
     $bgcolor = '#EAEAEA';
     $bgcolor = $this->settings['stepbar_color'] ? $this->settings['stepbar_color'] : $bgcolor;
     $nrcolor = \Typoheads\Formhandler\Utility\GeneralUtility::modifyHTMLcolor($bgcolor, 30, 30, 30);
     $errorbgcolor = '#dd7777';
     $errornrcolor = \Typoheads\Formhandler\Utility\GeneralUtility::modifyHTMLcolor($errorbgcolor, 30, 30, 30);
     $classprefix = $this->globals->getFormValuesPrefix() . '_stepbar';
     $css = [];
     $css[] = '.' . $classprefix . ' { background:' . $bgcolor . '; padding:4px;}';
     $css[] = '.' . $classprefix . '_error { background: ' . $errorbgcolor . ';}';
     $css[] = '.' . $classprefix . '_steps { margin-left:50px; margin-right:25px; vertical-align:middle; font-family:Verdana,Arial,Helvetica; font-size:22px; font-weight:bold; }';
     $css[] = '.' . $classprefix . '_steps span { color:' . $nrcolor . '; margin-left:5px; margin-right:5px; }';
     $css[] = '.' . $classprefix . '_error .' . $classprefix . '_steps span { color:' . $errornrcolor . '; margin-left:5px; margin-right:5px; }';
     $css[] = '.' . $classprefix . '_steps .' . $classprefix . '_currentstep { color:  #000;}';
     $css[] = '#stepsFormButtons { margin-left:25px;vertical-align:middle;}';
     $content = '';
     $buttons = '';
     for ($i = 1; $i <= $lastStep; $i++) {
         $class = '';
         if ($i == $currentStep) {
             $class = 'class="' . $classprefix . '_currentstep"';
         }
         $stepName = $this->utilityFuncs->getTranslatedMessage($this->langFiles, 'step-' . $i);
         if (strlen($stepName) === 0) {
             $stepName = $i;
         }
         $content .= '<span ' . $class . ' >' . $stepName . '</span>';
     }
     $content = '<span class="' . $classprefix . '_steps' . '">' . $content . '</span>';
     //if not the first step, show back button
     if ($currentStep > 1) {
         //check if label for specific step
         $message = $this->utilityFuncs->getTranslatedMessage($this->langFiles, 'prev_' . $currentStep);
         if (strlen($message) === 0) {
             $message = $this->utilityFuncs->getTranslatedMessage($this->langFiles, 'prev');
         }
         $buttons .= '<input type="submit" name="' . $buttonNameBack . '" value="' . trim($message) . '" class="button_prev" style="margin-right:10px;" />';
     }
     $message = $this->utilityFuncs->getTranslatedMessage($this->langFiles, 'next_' . $currentStep);
     if (strlen($message) === 0) {
         $message = $this->utilityFuncs->getTranslatedMessage($this->langFiles, 'next');
     }
     $buttons .= '<input type="submit" name="' . $buttonNameFwd . '" value="' . trim($message) . '" class="button_next" />';
     $content .= '<span id="stepsFormButtons">' . $buttons . '</span>';
     //wrap
     $classes = $classprefix;
     if ($this->errors) {
         $classes = $classes . ' ' . $classprefix . '_error';
     }
     $content = '<div class="' . $classes . '" >' . $content . '</div>';
     //add default css to page
     if ($this->settings['useDefaultStepBarStyles']) {
         $css = implode("\n", $css);
         $css = TSpagegen::inline2TempFile($css, 'css');
         if (version_compare(TYPO3_version, '4.3.0') >= 0) {
             $css = '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($css) . '" />';
         }
         $GLOBALS['TSFE']->additionalHeaderData[$this->extKey . '_' . $classprefix] .= $css;
     }
     return $content;
 }
 /**
  * Initialize the AJAX validation view.
  *
  * @param string $content The raw content
  * @return Tx_Formhandler_View_AjaxValidation The view class
  */
 protected function initView($content)
 {
     $viewClass = '\\Typoheads\\Formhandler\\View\\AjaxValidation';
     $view = $this->componentManager->getComponent($viewClass);
     $view->setLangFiles(\Typoheads\Formhandler\Utility\GeneralUtility::readLanguageFiles([], $this->settings));
     $view->setSettings($this->settings);
     $templateName = 'AJAX';
     $template = str_replace('###fieldname###', htmlspecialchars($_GET['field']), $content);
     $template = '###TEMPLATE_' . $templateName . '###' . $template . '###TEMPLATE_' . $templateName . '###';
     $view->setTemplate($template, 'AJAX');
     return $view;
 }