Skip to content
This repository was archived by the owner on Nov 4, 2023. It is now read-only.

Commit 872ed43

Browse files
Initial import
1 parent 9cff009 commit 872ed43

File tree

219 files changed

+82364
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+82364
-0
lines changed

Classes/Ajax/RemoveFile.php

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
namespace Typoheads\Formhandler\Ajax;
3+
/* *
4+
* This script is part of the TYPO3 project - inspiring people to share! *
5+
* *
6+
* TYPO3 is free software; you can redistribute it and/or modify it under *
7+
* the terms of the GNU General Public License version 2 as published by *
8+
* the Free Software Foundation. *
9+
* *
10+
* This script is distributed in the hope that it will be useful, but *
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12+
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13+
* Public License for more details. *
14+
* */
15+
use TYPO3\CMS\Core\Utility\GeneralUtility;
16+
17+
/**
18+
* A class removing uploaded files. This class is called via AJAX.
19+
*
20+
* @author Reinhard Führicht <[email protected]>
21+
*/
22+
class RemoveFile {
23+
24+
/**
25+
* Main method of the class.
26+
*
27+
* @return string The HTML list of remaining files to be displayed in the form
28+
*/
29+
public function main() {
30+
$this->init();
31+
$content = '';
32+
33+
if ($this->fieldName) {
34+
$sessionFiles = $this->globals->getSession()->get('files');
35+
if (is_array($sessionFiles)) {
36+
37+
foreach ($sessionFiles as $field => $files) {
38+
39+
if (!strcmp($field, $this->fieldName)) {
40+
41+
//get upload folder
42+
$uploadFolder = $this->utilityFuncs->getTempUploadFolder();
43+
44+
//build absolute path to upload folder
45+
$uploadPath = $this->utilityFuncs->getTYPO3Root() . $uploadFolder;
46+
47+
$found = FALSE;
48+
foreach ($files as $key=>&$fileInfo) {
49+
if (!strcmp($fileInfo['uploaded_name'], $this->uploadedFileName)) {
50+
$found = TRUE;
51+
unset($sessionFiles[$field][$key]);
52+
if(file_exists($uploadPath . $fileInfo['uploaded_name'])) {
53+
unlink($uploadPath . $fileInfo['uploaded_name']);
54+
}
55+
}
56+
}
57+
if (!$found) {
58+
foreach ($files as $key=>&$fileInfo) {
59+
if (!strcmp($fileInfo['name'], $this->uploadedFileName)) {
60+
$found = TRUE;
61+
unset($sessionFiles[$field][$key]);
62+
if(file_exists($uploadPath . $fileInfo['name'])) {
63+
unlink($uploadPath . $fileInfo['name']);
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}
71+
72+
$this->globals->getSession()->set('files', $sessionFiles);
73+
74+
// Add the content to or Result Box: #formResult
75+
if (is_array($sessionFiles) && !empty($sessionFiles[$field])) {
76+
$markers = array();
77+
$view = $this->componentManager->getComponent('View\\Form');
78+
$view->setSettings($this->settings);
79+
$view->fillFileMarkers($markers);
80+
$langMarkers = $this->utilityFuncs->getFilledLangMarkers($markers['###'. $this->fieldName . '_uploadedFiles###'], $this->langFiles);
81+
$markers['###'. $this->fieldName . '_uploadedFiles###'] = $this->globals->getCObj()->substituteMarkerArray($markers['###'. $this->fieldName . '_uploadedFiles###'], $langMarkers);
82+
$content = $markers['###'. $this->fieldName . '_uploadedFiles###'];
83+
}
84+
}
85+
print $content;
86+
}
87+
88+
/**
89+
* Initialize the class. Read GET parameters
90+
*
91+
* @return void
92+
*/
93+
protected function init() {
94+
$this->fieldName = htmlspecialchars($_GET['field']);
95+
$this->uploadedFileName = htmlspecialchars($_GET['uploadedFileName']);
96+
if (isset($_GET['pid'])) {
97+
$this->id = intval($_GET['pid']);
98+
} else {
99+
$this->id = intval($_GET['id']);
100+
}
101+
102+
$this->componentManager = GeneralUtility::makeInstance(\Typoheads\Formhandler\Component\Manager::class);
103+
$this->globals = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\Globals::class);
104+
$this->utilityFuncs = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\GeneralUtility::class);
105+
$this->utilityFuncs->initializeTSFE($this->id);
106+
$this->globals->setCObj($GLOBALS['TSFE']->cObj);
107+
$randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID'));
108+
$this->globals->setRandomID($randomID);
109+
110+
if(!$this->globals->getSession()) {
111+
$ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
112+
$sessionClass = $this->utilityFuncs->getPreparedClassName($ts['session.'], 'Session\\PHP');
113+
$this->globals->setSession($sessionClass);
114+
}
115+
116+
$this->settings = $this->globals->getSession()->get('settings');
117+
$this->langFiles = $this->utilityFuncs->readLanguageFiles(array(), $this->settings);
118+
119+
//init ajax
120+
if ($this->settings['ajax.']) {
121+
$class = $this->utilityFuncs->getPreparedClassName($this->settings['ajax.'], 'AjaxHandler\\JQuery');
122+
$ajaxHandler = $this->componentManager->getComponent($class);
123+
$this->globals->setAjaxHandler($ajaxHandler);
124+
125+
$ajaxHandler->init($this->settings['ajax.']['config.']);
126+
$ajaxHandler->initAjax();
127+
}
128+
}
129+
130+
}
131+
132+
$obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Typoheads\Formhandler\Ajax\RemoveFile::class);
133+
$obj->main();

Classes/Ajax/Submit.php

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
namespace Typoheads\Formhandler\Ajax;
3+
/* *
4+
* This script is part of the TYPO3 project - inspiring people to share! *
5+
* *
6+
* TYPO3 is free software; you can redistribute it and/or modify it under *
7+
* the terms of the GNU General Public License version 2 as published by *
8+
* the Free Software Foundation. *
9+
* *
10+
* This script is distributed in the hope that it will be useful, but *
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12+
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13+
* Public License for more details. *
14+
* */
15+
use TYPO3\CMS\Core\Utility\GeneralUtility;
16+
17+
/**
18+
* A class calling the controller and returning the form content as JSON. This class is called via AJAX.
19+
*
20+
* @author Reinhard Führicht <[email protected]>
21+
*/
22+
23+
class Submit {
24+
25+
/**
26+
* Main method of the class.
27+
*
28+
* @return string The HTML list of remaining files to be displayed in the form
29+
*/
30+
public function main() {
31+
$this->init();
32+
$content = '';
33+
34+
$settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_formhandler_pi1.'];
35+
$settings['usePredef'] = $this->globals->getSession()->get('predef');
36+
37+
$content = $GLOBALS['TSFE']->cObj->cObjGetSingle('USER', $settings);
38+
39+
$content = '{' . json_encode('form') . ':' . json_encode($content, JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS) . '}';
40+
print $content;
41+
}
42+
43+
/**
44+
* Initialize the class. Read GET parameters
45+
*
46+
* @return void
47+
*/
48+
protected function init() {
49+
if (isset($_GET['pid'])) {
50+
$this->id = intval($_GET['pid']);
51+
} else {
52+
$this->id = intval($_GET['id']);
53+
}
54+
55+
$this->componentManager = GeneralUtility::makeInstance(\Typoheads\Formhandler\Component\Manager::class);
56+
$this->globals = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\Globals::class);
57+
$this->utilityFuncs = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\GeneralUtility::class);
58+
$this->utilityFuncs->initializeTSFE($this->id);
59+
60+
$elementUID = intval($_GET['uid']);
61+
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $elementUID . $GLOBALS['TSFE']->cObj->enableFields('tt_content'));
62+
if(!empty($row)) {
63+
$GLOBALS['TSFE']->cObj->data = $row;
64+
$GLOBALS['TSFE']->cObj->current = 'tt_content_' . $elementUID;
65+
}
66+
67+
$this->globals->setCObj($GLOBALS['TSFE']->cObj);
68+
$randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID'));
69+
$this->globals->setRandomID($randomID);
70+
$this->globals->setAjaxMode(TRUE);
71+
if(!$this->globals->getSession()) {
72+
$ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
73+
$sessionClass = $this->utilityFuncs->getPreparedClassName($ts['session.'], 'Session\PHP');
74+
$this->globals->setSession($this->componentManager->getComponent($sessionClass));
75+
}
76+
77+
$this->settings = $this->globals->getSession()->get('settings');
78+
$this->langFiles = $this->utilityFuncs->readLanguageFiles(array(), $this->settings);
79+
80+
//init ajax
81+
if ($this->settings['ajax.']) {
82+
$class = $this->utilityFuncs->getPreparedClassName($this->settings['ajax.'], 'AjaxHandler\JQuery');
83+
$ajaxHandler = $this->componentManager->getComponent($class);
84+
$this->globals->setAjaxHandler($ajaxHandler);
85+
86+
$ajaxHandler->init($this->settings['ajax.']['config.']);
87+
$ajaxHandler->initAjax();
88+
}
89+
}
90+
91+
}
92+
93+
$obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Typoheads\Formhandler\Ajax\Submit::class);
94+
$obj->main();

Classes/Ajax/Validate.php

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
namespace Typoheads\Formhandler\Ajax;
3+
/* *
4+
* This script is part of the TYPO3 project - inspiring people to share! *
5+
* *
6+
* TYPO3 is free software; you can redistribute it and/or modify it under *
7+
* the terms of the GNU General Public License version 2 as published by *
8+
* the Free Software Foundation. *
9+
* *
10+
* This script is distributed in the hope that it will be useful, but *
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12+
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13+
* Public License for more details. *
14+
*
15+
* */
16+
use TYPO3\CMS\Core\Utility\GeneralUtility;
17+
18+
/**
19+
* A class validating a field via AJAX.
20+
*
21+
* @author Reinhard Führicht <[email protected]>
22+
*/
23+
24+
class Validate {
25+
26+
/**
27+
* Main method of the class.
28+
*
29+
* @return string The HTML list of remaining files to be displayed in the form
30+
*/
31+
public function main() {
32+
$this->init();
33+
if ($this->fieldname) {
34+
$this->globals->setCObj($GLOBALS['TSFE']->cObj);
35+
$randomID = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('randomID'));
36+
$this->globals->setRandomID($randomID);
37+
if(!$this->globals->getSession()) {
38+
$ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
39+
$sessionClass = $this->utilityFuncs->getPreparedClassName($ts['session.'], 'Session\PHP');
40+
$this->globals->setSession($this->componentManager->getComponent($sessionClass));
41+
}
42+
$validator = $this->componentManager->getComponent('\Typoheads\Formhandler\Validator\Ajax');
43+
$errors = array();
44+
$valid = $validator->validateAjax($this->fieldname, $this->value, $errors);
45+
$this->settings = $this->globals->getSession()->get('settings');
46+
$content = '';
47+
if ($valid) {
48+
$content = $this->utilityFuncs->getSingle($this->settings['ajax.']['config.'], 'ok');
49+
if(strlen($content) === 0) {
50+
$content = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('formhandler') . 'Resources/Public/Images/ok.png' . '" />';
51+
} else {
52+
$gp = array(
53+
$_GET['field'] => $_GET['value']
54+
);
55+
$view = $this->initView($content);
56+
$content = $view->render($gp, $errors);
57+
}
58+
$content = '<span class="success">' . $content . '</span>';
59+
} else {
60+
$content = $this->utilityFuncs->getSingle($this->settings['ajax.']['config.'], 'notOk');
61+
if(strlen($content) === 0) {
62+
$content = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('formhandler') . 'Resources/Public/Images/notok.png' . '" />';
63+
} else {
64+
$view = $this->initView($content);
65+
$gp = array(
66+
$_GET['field'] => $_GET['value']
67+
);
68+
$content = $view->render($gp, $errors);
69+
}
70+
$content = '<span class="error">' . $content . '</span>';
71+
}
72+
print $content;
73+
}
74+
}
75+
76+
/**
77+
* Initialize the class. Read GET parameters
78+
*
79+
* @return void
80+
*/
81+
protected function init() {
82+
$this->fieldname = htmlspecialchars(stripslashes($_GET['field']));
83+
$this->value = htmlspecialchars(stripslashes($_GET['value']));
84+
if (isset($_GET['pid'])) {
85+
$this->id = intval($_GET['pid']);
86+
} else {
87+
$this->id = intval($_GET['id']);
88+
}
89+
$this->componentManager = GeneralUtility::makeInstance(\Typoheads\Formhandler\Component\Manager::class);
90+
$this->globals = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\Globals::class);
91+
$this->utilityFuncs = GeneralUtility::makeInstance(\Typoheads\Formhandler\Utility\GeneralUtility::class);
92+
$this->globals->setAjaxMode(TRUE);
93+
$this->utilityFuncs->initializeTSFE($this->id);
94+
}
95+
96+
/**
97+
* Initialize the AJAX validation view.
98+
*
99+
* @param string $content The raw content
100+
* @return Tx_Formhandler_View_AjaxValidation The view class
101+
*/
102+
protected function initView($content) {
103+
$viewClass = '\Typoheads\Formhandler\View\AjaxValidation';
104+
$view = $this->componentManager->getComponent($viewClass);
105+
$view->setLangFiles($this->utilityFuncs->readLanguageFiles(array(), $this->settings));
106+
$view->setSettings($this->settings);
107+
$templateName = 'AJAX';
108+
$template = str_replace('###fieldname###', htmlspecialchars($_GET['field']), $content);
109+
$template = '###TEMPLATE_' . $templateName . '###' . $template . '###TEMPLATE_' . $templateName . '###';
110+
$view->setTemplate($template, 'AJAX');
111+
return $view;
112+
}
113+
114+
}
115+
116+
$obj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Typoheads\Formhandler\Ajax\Validate::class);
117+
$obj->main();

0 commit comments

Comments
 (0)