forked from reinhardfuehricht/typo3-formhandler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cff009
commit 872ed43
Showing
219 changed files
with
82,364 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
namespace Typoheads\Formhandler\Ajax; | ||
/* * | ||
* This script is part of the TYPO3 project - inspiring people to share! * | ||
* * | ||
* TYPO3 is free software; you can redistribute it and/or modify it under * | ||
* the terms of the GNU General Public License version 2 as published by * | ||
* the Free Software Foundation. * | ||
* * | ||
* This script is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * | ||
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * | ||
* Public License for more details. * | ||
* */ | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* A class removing uploaded files. This class is called via AJAX. | ||
* | ||
* @author Reinhard Führicht <[email protected]> | ||
*/ | ||
class RemoveFile { | ||
|
||
/** | ||
* Main method of the class. | ||
* | ||
* @return string The HTML list of remaining files to be displayed in the form | ||
*/ | ||
public function main() { | ||
$this->init(); | ||
$content = ''; | ||
|
||
if ($this->fieldName) { | ||
$sessionFiles = $this->globals->getSession()->get('files'); | ||
if (is_array($sessionFiles)) { | ||
|
||
foreach ($sessionFiles as $field => $files) { | ||
|
||
if (!strcmp($field, $this->fieldName)) { | ||
|
||
//get upload folder | ||
$uploadFolder = $this->utilityFuncs->getTempUploadFolder(); | ||
|
||
//build absolute path to upload folder | ||
$uploadPath = $this->utilityFuncs->getTYPO3Root() . $uploadFolder; | ||
|
||
$found = FALSE; | ||
foreach ($files as $key=>&$fileInfo) { | ||
if (!strcmp($fileInfo['uploaded_name'], $this->uploadedFileName)) { | ||
$found = TRUE; | ||
unset($sessionFiles[$field][$key]); | ||
if(file_exists($uploadPath . $fileInfo['uploaded_name'])) { | ||
unlink($uploadPath . $fileInfo['uploaded_name']); | ||
} | ||
} | ||
} | ||
if (!$found) { | ||
foreach ($files as $key=>&$fileInfo) { | ||
if (!strcmp($fileInfo['name'], $this->uploadedFileName)) { | ||
$found = TRUE; | ||
unset($sessionFiles[$field][$key]); | ||
if(file_exists($uploadPath . $fileInfo['name'])) { | ||
unlink($uploadPath . $fileInfo['name']); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
$this->globals->getSession()->set('files', $sessionFiles); | ||
|
||
// Add the content to or Result Box: #formResult | ||
if (is_array($sessionFiles) && !empty($sessionFiles[$field])) { | ||
$markers = array(); | ||
$view = $this->componentManager->getComponent('View\\Form'); | ||
$view->setSettings($this->settings); | ||
$view->fillFileMarkers($markers); | ||
$langMarkers = $this->utilityFuncs->getFilledLangMarkers($markers['###'. $this->fieldName . '_uploadedFiles###'], $this->langFiles); | ||
$markers['###'. $this->fieldName . '_uploadedFiles###'] = $this->globals->getCObj()->substituteMarkerArray($markers['###'. $this->fieldName . '_uploadedFiles###'], $langMarkers); | ||
$content = $markers['###'. $this->fieldName . '_uploadedFiles###']; | ||
} | ||
} | ||
print $content; | ||
} | ||
|
||
/** | ||
* 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 = 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); | ||
$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($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(); | ||
} | ||
} | ||
|
||
} | ||
|
||
$obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Typoheads\Formhandler\Ajax\RemoveFile::class); | ||
$obj->main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
namespace Typoheads\Formhandler\Ajax; | ||
/* * | ||
* This script is part of the TYPO3 project - inspiring people to share! * | ||
* * | ||
* TYPO3 is free software; you can redistribute it and/or modify it under * | ||
* the terms of the GNU General Public License version 2 as published by * | ||
* the Free Software Foundation. * | ||
* * | ||
* This script is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * | ||
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * | ||
* Public License for more details. * | ||
* */ | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* A class calling the controller and returning the form content as JSON. This class is called via AJAX. | ||
* | ||
* @author Reinhard Führicht <[email protected]> | ||
*/ | ||
|
||
class Submit { | ||
|
||
/** | ||
* Main method of the class. | ||
* | ||
* @return string The HTML list of remaining files to be displayed in the form | ||
*/ | ||
public function main() { | ||
$this->init(); | ||
$content = ''; | ||
|
||
$settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_formhandler_pi1.']; | ||
$settings['usePredef'] = $this->globals->getSession()->get('predef'); | ||
|
||
$content = $GLOBALS['TSFE']->cObj->cObjGetSingle('USER', $settings); | ||
|
||
$content = '{' . json_encode('form') . ':' . json_encode($content, JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS) . '}'; | ||
print $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 = 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); | ||
$this->utilityFuncs->initializeTSFE($this->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; | ||
} | ||
|
||
$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(); | ||
} | ||
} | ||
|
||
} | ||
|
||
$obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Typoheads\Formhandler\Ajax\Submit::class); | ||
$obj->main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
namespace Typoheads\Formhandler\Ajax; | ||
/* * | ||
* This script is part of the TYPO3 project - inspiring people to share! * | ||
* * | ||
* TYPO3 is free software; you can redistribute it and/or modify it under * | ||
* the terms of the GNU General Public License version 2 as published by * | ||
* the Free Software Foundation. * | ||
* * | ||
* This script is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * | ||
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * | ||
* Public License for more details. * | ||
* | ||
* */ | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* A class validating a field via AJAX. | ||
* | ||
* @author Reinhard Führicht <[email protected]> | ||
*/ | ||
|
||
class Validate { | ||
|
||
/** | ||
* Main method of the class. | ||
* | ||
* @return string The HTML list of remaining files to be displayed in the form | ||
*/ | ||
public function main() { | ||
$this->init(); | ||
if ($this->fieldname) { | ||
$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)); | ||
} | ||
$validator = $this->componentManager->getComponent('\Typoheads\Formhandler\Validator\Ajax'); | ||
$errors = array(); | ||
$valid = $validator->validateAjax($this->fieldname, $this->value, $errors); | ||
$this->settings = $this->globals->getSession()->get('settings'); | ||
$content = ''; | ||
if ($valid) { | ||
$content = $this->utilityFuncs->getSingle($this->settings['ajax.']['config.'], 'ok'); | ||
if(strlen($content) === 0) { | ||
$content = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('formhandler') . 'Resources/Public/Images/ok.png' . '" />'; | ||
} else { | ||
$gp = array( | ||
$_GET['field'] => $_GET['value'] | ||
); | ||
$view = $this->initView($content); | ||
$content = $view->render($gp, $errors); | ||
} | ||
$content = '<span class="success">' . $content . '</span>'; | ||
} else { | ||
$content = $this->utilityFuncs->getSingle($this->settings['ajax.']['config.'], 'notOk'); | ||
if(strlen($content) === 0) { | ||
$content = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('formhandler') . 'Resources/Public/Images/notok.png' . '" />'; | ||
} else { | ||
$view = $this->initView($content); | ||
$gp = array( | ||
$_GET['field'] => $_GET['value'] | ||
); | ||
$content = $view->render($gp, $errors); | ||
} | ||
$content = '<span class="error">' . $content . '</span>'; | ||
} | ||
print $content; | ||
} | ||
} | ||
|
||
/** | ||
* 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']); | ||
} | ||
$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); | ||
$this->globals->setAjaxMode(TRUE); | ||
$this->utilityFuncs->initializeTSFE($this->id); | ||
} | ||
|
||
/** | ||
* 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($this->utilityFuncs->readLanguageFiles(array(), $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; | ||
} | ||
|
||
} | ||
|
||
$obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Typoheads\Formhandler\Ajax\Validate::class); | ||
$obj->main(); |
Oops, something went wrong.