/** * The constructor for an interceptor setting the component manager and the configuration. * * @param Tx_Formhandler_Component_Manager $componentManager * @param Tx_Formhandler_Configuration $configuration * @return void */ public function __construct(Tx_Formhandler_Component_Manager $componentManager, Tx_Formhandler_Configuration $configuration, Tx_Formhandler_Globals $globals, Tx_Formhandler_UtilityFuncs $utilityFuncs) { $this->componentManager = $componentManager; $this->configuration = $configuration; $this->globals = $globals; $this->utilityFuncs = $utilityFuncs; $this->cObj = $this->globals->getCObj(); }
public static function getInstance() { if (self::$instance === NULL) { self::$instance = new Tx_Formhandler_Globals(); } return self::$instance; }
/** * 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; 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'); Tx_Formhandler_Globals::$predef = $predef; Tx_Formhandler_Globals::$cObj = $this->cObj; Tx_Formhandler_Globals::$overrideSettings = $setup; $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); /* * set controller: * 1. Default controller * 2. TypoScript */ $controller = 'Tx_Formhandler_Controller_Form'; if ($setup['controller']) { $controller = $setup['controller']; } $controller = Tx_Formhandler_StaticFuncs::prepareClassName($controller); $controller = $this->componentManager->getComponent($controller); if (isset($content)) { $controller->setContent($this->componentManager->getComponent('Tx_Formhandler_Content', $content)); } if (strlen($templateFile) > 0) { $controller->setTemplateFile($templateFile); } if (strlen($langFile) > 0) { $controller->setLangFiles(array($langFile)); } if (strlen($predef) > 0) { $controller->setPredefined($predef); } $result = $controller->process(); } catch (Exception $e) { $result = '<div style="color:red; font-weight: bold">Caught exception: ' . $e->getMessage() . '</div>'; $result .= '<div style="color:red; font-weight: bold">File: ' . $e->getFile() . '(' . $e->getLine() . ')</div>'; } if (Tx_Formhandler_Globals::$session && Tx_Formhandler_Globals::$session->get('debug')) { foreach (Tx_Formhandler_Globals::$debuggers as $idx => $debugger) { $debugger->outputDebugLog(); } } return $result; }
/** * The constructor for a view setting the component manager and the configuration. * * @param Tx_Formhandler_Component_Manager $componentManager * @param Tx_Formhandler_Configuration $configuration * @return void */ public function __construct(Tx_Formhandler_Component_Manager $componentManager, Tx_Formhandler_Configuration $configuration, Tx_Formhandler_Globals $globals, Tx_Formhandler_UtilityFuncs $utilityFuncs) { parent::__construct(); $this->componentManager = $componentManager; $this->configuration = $configuration; $this->globals = $globals; $this->utilityFuncs = $utilityFuncs; $this->cObj = $this->globals->getCObj(); $this->pi_loadLL(); $this->initializeView(); }
public function main() { $this->init(); if ($this->fieldname) { $randomID = t3lib_div::_GP('randomID'); Tx_Formhandler_Globals::$randomID = $randomID; $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); $validator = $this->componentManager->getComponent('Tx_Formhandler_Validator_Ajax'); print $validator->validateAjax($this->fieldname, $this->value); } }
/** * The constructor reading the TS setup into the according attribute * * @return void */ public function __construct() { if (TYPO3_MODE === 'FE') { $this->globals = Tx_Formhandler_Globals::getInstance(); $this->utilityFuncs = Tx_Formhandler_UtilityFuncs::getInstance(); $this->setup = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->getPrefixedPackageKey() . '.']; if (!is_array($this->setup)) { $this->utilityFuncs->throwException('missing_config'); } if (is_array($this->globals->getOverrideSettings())) { $this->setup = $this->utilityFuncs->mergeConfiguration($this->setup, $this->globals->getOverrideSettings()); } } }
/** * Interprets a string. If it starts with a { like {field:fieldname} * it calls TYPO3 getData function and returns its value, otherwise returns the string * * @param string $operand The operand to be interpreted * @param array $values The GET/POST values * @return string */ public function parseOperand($operand, $values) { $returnValue = ''; if ($operand[0] == '{') { $data = trim($operand, '{}'); $returnValue = $this->globals->getcObj()->getData($data, $values); } else { $returnValue = $operand; } if ($returnValue === NULL) { $returnValue = ''; } return $returnValue; }
/** * Hook for modifying $content before core's stdWrap does anything * * @param string $content Input value undergoing processing in this function. Possibly substituted by other values fetched from another source. * @param array $configuration TypoScript stdWrap properties * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $parentObject Parent content object * @return string Further processed $content */ public function stdWrapPreProcess($content, array $configuration, \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer &$parentObject) { if (intval($configuration['sanitize']) === 1) { $globals = Tx_Formhandler_Globals::getInstance(); $this->originalGET = $_GET; $this->originalPOST = $_POST; $prefix = $globals->getFormValuesPrefix(); if (strlen($prefix) > 0) { $_GET[$prefix] = $globals->getGP(); $_POST[$prefix] = $globals->getGP(); } else { $_GET = array_merge($_GET, $globals->getGP()); $_POST = array_merge($_POST, $globals->getGP()); } } return $content; }
/** * Initialize the class. Read GET parameters * * @return void */ protected function init() { if (isset($_GET['pid'])) { $this->id = intval($_GET['pid']); } else { $this->id = intval($_GET['id']); } $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); $this->globals = Tx_Formhandler_Globals::getInstance(); $this->utilityFuncs = Tx_Formhandler_UtilityFuncs::getInstance(); tslib_eidtools::connectDB(); $this->utilityFuncs->initializeTSFE($this->id); $elementUID = intval($_GET['uid']); $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $elementUID . ' AND pid=' . $this->id . $GLOBALS['TSFE']->cObj->enableFields('tt_content')); if (!empty($row)) { $GLOBALS['TSFE']->cObj->data = $row; $GLOBALS['TSFE']->cObj->current = 'tt_content_' . $elementUID; } $this->globals->setCObj($GLOBALS['TSFE']->cObj); $randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID')); $this->globals->setRandomID($randomID); $this->globals->setAjaxMode(TRUE); if (!$this->globals->getSession()) { $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.']; $sessionClass = $this->utilityFuncs->getPreparedClassName($ts['session.'], 'Session_PHP'); $this->globals->setSession($this->componentManager->getComponent($sessionClass)); } $this->settings = $this->globals->getSession()->get('settings'); $this->langFiles = $this->utilityFuncs->readLanguageFiles(array(), $this->settings); //init ajax if ($this->settings['ajax.']) { $class = $this->utilityFuncs->getPreparedClassName($this->settings['ajax.'], 'AjaxHandler_JQuery'); $ajaxHandler = $this->componentManager->getComponent($class); $this->globals->setAjaxHandler($ajaxHandler); $ajaxHandler->init($this->settings['ajax.']['config.']); $ajaxHandler->initAjax(); } }
protected function init() { $this->fieldName = $_GET['field']; $this->uploadedFileName = $_GET['uploadedFileName']; if (isset($_GET['pid'])) { $this->id = intval($_GET['pid']); } else { $this->id = intval($_GET['id']); } $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); tslib_eidtools::connectDB(); $this->initializeTSFE($this->id); Tx_Formhandler_Globals::$cObj = $GLOBALS['TSFE']->cObj; $randomID = t3lib_div::_GP('randomID'); Tx_Formhandler_Globals::$randomID = $randomID; if (!Tx_Formhandler_Globals::$session) { $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.']; $sessionClass = 'Tx_Formhandler_Session_PHP'; if ($ts['session.']) { $sessionClass = Tx_Formhandler_StaticFuncs::prepareClassName($ts['session.']['class']); } Tx_Formhandler_Globals::$session = $this->componentManager->getComponent($sessionClass); } $this->settings = Tx_Formhandler_Globals::$session->get('settings'); //init ajax if ($this->settings['ajax.']) { $class = $this->settings['ajax.']['class']; if (!$class) { $class = 'Tx_Formhandler_AjaxHandler_JQuery'; } $class = Tx_Formhandler_StaticFuncs::prepareClassName($class); $ajaxHandler = $this->componentManager->getComponent($class); Tx_Formhandler_Globals::$ajaxHandler = $ajaxHandler; $ajaxHandler->init($this->settings['ajax.']['config.']); $ajaxHandler->initAjax(); } }
public function loadConfig() { if (!Tx_Formhandler_Globals::$session) { $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.']; $sessionClass = 'Tx_Formhandler_Session_PHP'; if ($ts['session.']) { $sessionClass = Tx_Formhandler_StaticFuncs::prepareClassName($ts['session.']['class']); } Tx_Formhandler_Globals::$session = $this->componentManager->getComponent($sessionClass); } $tsConfig = Tx_Formhandler_Globals::$session->get('settings'); $this->settings = array(); if ($tsConfig['validators.']) { foreach ($tsConfig['validators.'] as $idx => $settings) { if (is_array($settings['config.'])) { $this->settings = array_merge($this->settings, $settings['config.']); } } } }
/** * 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'); } } } }
/** * Initialize the class. Read GET parameters * * @return void */ protected function init() { $this->fieldName = htmlspecialchars($_GET['field']); $this->uploadedFileName = htmlspecialchars($_GET['uploadedFileName']); if (isset($_GET['pid'])) { $this->id = intval($_GET['pid']); } else { $this->id = intval($_GET['id']); } $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); $this->globals = Tx_Formhandler_Globals::getInstance(); $this->utilityFuncs = Tx_Formhandler_UtilityFuncs::getInstance(); tslib_eidtools::connectDB(); $this->utilityFuncs->initializeTSFE($this->id); $this->globals->setCObj($GLOBALS['TSFE']->cObj); $randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID')); $this->globals->setRandomID($randomID); if (!$this->globals->getSession()) { $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.']; $sessionClass = $this->utilityFuncs->getPreparedClassName($ts['session.'], 'Session_PHP'); $this->globals->setSession($this->componentManager->getComponent($sessionClass)); } $this->settings = $this->globals->getSession()->get('settings'); $this->langFiles = $this->utilityFuncs->readLanguageFiles(array(), $this->settings); //init ajax if ($this->settings['ajax.']) { $class = $this->utilityFuncs->getPreparedClassName($this->settings['ajax.'], 'AjaxHandler_JQuery'); $ajaxHandler = $this->componentManager->getComponent($class); $this->globals->setAjaxHandler($ajaxHandler); $ajaxHandler->init($this->settings['ajax.']['config.']); $ajaxHandler->initAjax(); } }
/** * 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->globals = Tx_Formhandler_Globals::getInstance(); $this->utilityFuncs = Tx_Formhandler_UtilityFuncs::getInstance(); 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); if ($setup['usePredef']) { $predef = $this->utilityFuncs->getSingle($setup, 'usePredef'); } $this->globals->getCObj()->setCurrentVal($predef); $this->globals->setPredef($predef); $this->globals->setOverrideSettings($setup); $this->componentManager = Tx_Formhandler_Component_Manager::getInstance(); /* * set controller: * 1. Default controller * 2. TypoScript */ $controller = 'Tx_Formhandler_Controller_Form'; if ($setup['controller']) { $controller = $setup['controller']; } $controller = $this->utilityFuncs->prepareClassName($controller); $controller = $this->componentManager->getComponent($controller); if (isset($content)) { $controller->setContent($this->componentManager->getComponent('Tx_Formhandler_Content', $content)); } if (strlen($templateFile) > 0) { $controller->setTemplateFile($templateFile); } if (strlen($langFile) > 0) { $controller->setLangFiles(array($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; }
/** * Initialize the class. Read GET parameters * * @return void */ protected function init() { $this->fieldname = htmlspecialchars(stripslashes($_GET['field'])); $this->value = htmlspecialchars(stripslashes($_GET['value'])); if (isset($_GET['pid'])) { $this->id = intval($_GET['pid']); } else { $this->id = intval($_GET['id']); } tslib_eidtools::connectDB(); $this->globals = Tx_Formhandler_Globals::getInstance(); $this->globals->setAjaxMode(TRUE); $this->utilityFuncs = Tx_Formhandler_UtilityFuncs::getInstance(); $this->utilityFuncs->initializeTSFE($this->id); }
/** * 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 void * @author Robert Lemke <*****@*****.**> * @author adapted for TYPO3v4 by Jochen Rau <*****@*****.**> */ public function getComponent($componentName) { //Avoid component manager creating multiple instances of itself: if (get_class($this) === $componentName) { return $this; } elseif ('Tx_Formhandler_Globals' === $componentName) { return Tx_Formhandler_Globals::getInstance(); } elseif ('Tx_Formhandler_UtilityFuncs' === $componentName) { return Tx_Formhandler_UtilityFuncs::getInstance(); } if (!is_array($this->classFiles)) { $this->classFiles = array(); } $classNameParts = explode('_', $componentName, 3); if (!is_array($this->classFiles[$classNameParts[1]])) { $this->classFiles[$classNameParts[1]] = array(); } if (!array_key_exists($componentName, $this->classFiles[$classNameParts[1]])) { $found = FALSE; //Look for the requested component in other cached packages foreach ($this->classFiles as $packageKey => $classFiles) { if (array_key_exists($componentName, $classFiles)) { $found = TRUE; $arguments = array_slice(func_get_args(), 1, NULL, TRUE); $componentObject = $this->createComponentObject($componentName, $arguments); } } //Component couldn't be found anywhere in the cache if (!$found) { $this->loadClass($componentName); $componentObject = $this->createComponentObject($componentName, array()); } } else { $arguments = array_slice(func_get_args(), 1, NULL, TRUE); // array keys are preserved (TRUE) -> argument array starts with key=1 $componentObject = $this->createComponentObject($componentName, $arguments); } return $componentObject; }
/** * Read language file set in flexform or TypoScript, read the file's path to $this->langFile * * @param $settings The formhandler settings * @return void * @author Reinhard Führicht <*****@*****.**> */ public static function readLanguageFiles($langFiles, &$settings) { //language file was not set in flexform, search TypoScript for setting if (!$langFiles) { $langFiles = array(); if (isset($settings['langFile']) && !isset($settings['langFile.'])) { array_push($langFiles, Tx_Formhandler_StaticFuncs::resolveRelPathFromSiteRoot($settings['langFile'])); } elseif (isset($settings['langFile']) && isset($settings['langFile.'])) { array_push($langFiles, Tx_Formhandler_Globals::getSingle($settings, 'langFile')); } elseif (isset($settings['langFile.']) && is_array($settings['langFile.'])) { foreach ($settings['langFile.'] as $key => $langFile) { if (FALSE === strpos($key, '.')) { if (is_array($settings['langFile.'][$key . '.'])) { array_push($langFiles, Tx_Formhandler_StaticFuncs::getSingle($settings['langFile.'], $key)); } else { array_push($langFiles, Tx_Formhandler_StaticFuncs::resolveRelPathFromSiteRoot($langFile)); } } } } } foreach ($langFiles as $idx => &$langFile) { $langFile = Tx_Formhandler_StaticFuncs::convertToRelativePath($langFile); } return $langFiles; }