public static function getInstance()
 {
     if (self::$instance === NULL) {
         self::$instance = new Tx_Formhandler_UtilityFuncs();
         self::$instance->globals = Tx_Formhandler_Globals::getInstance();
     }
     return self::$instance;
 }
 /**
  * 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());
         }
     }
 }
 /**
  * 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();
     }
 }
 /**
  * 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;
 }
 /**
  * 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($_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();
     }
 }