Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYPO3 7.6 compatility #23

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions Classes/Controller/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ protected function processFiles()
$uploadedUrl = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'), '/');
$uploadedUrl .= '/' . trim($uploadFolder, '/') . '/';
$uploadedUrl .= trim($uploadedFileName, '/');

$tmp['uploaded_url'] = $uploadedUrl;
$tmp['size'] = $files['size'][$field][$idx];
if (is_array($files['type'][$field][$idx])) {
Expand Down Expand Up @@ -1109,6 +1109,8 @@ protected function init()

$this->gp = $this->utilityFuncs->getMergedGP();

$this->gp['randomID'] = preg_replace('/[^0-9a-z]/', '', preg_quote($this->gp['randomID']));

$randomID = $this->gp['randomID'];
if (!$randomID) {
if ($this->settings['uniqueFormID']) {
Expand Down Expand Up @@ -1434,7 +1436,12 @@ protected function addCSS()
$file = $fileOptions['file'];
if (strlen(trim($file)) > 0) {
$file = $this->utilityFuncs->resolveRelPathFromSiteRoot($file);
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
if (version_compare(TYPO3_version, '8.0.0', '>='))
{
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
} else {
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
}
$pageRenderer->addCssFile(
$file,
$fileOptions['alternate'] ? 'alternate stylesheet' : 'stylesheet',
Expand All @@ -1461,7 +1468,12 @@ protected function addJS()
$file = $fileOptions['file'];
if (strlen(trim($file)) > 0) {
$file = $this->utilityFuncs->resolveRelPathFromSiteRoot($file);
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
if (version_compare(TYPO3_version, '8.0.0', '>='))
{
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
} else {
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
}
$pageRenderer->addJsFile(
$file,
$fileOptions['type'] ? $fileOptions['type'] : 'text/javascript',
Expand All @@ -1486,7 +1498,12 @@ protected function addJSFooter()
$file = $fileOptions['file'];
if (strlen(trim($file)) > 0) {
$file = $this->utilityFuncs->resolveRelPathFromSiteRoot($file);
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
if (version_compare(TYPO3_version, '8.0.0', '>='))
{
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
} else {
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
}
$pageRenderer->addJsFooterFile(
$file,
$fileOptions['type'] ? $fileOptions['type'] : 'text/javascript',
Expand Down Expand Up @@ -1569,4 +1586,4 @@ protected function initializeDebuggers()
}
}

}
}
29 changes: 19 additions & 10 deletions Classes/Logger/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public function process()
//set params
$table = 'tx_formhandler_log';

$doDisableIPlog = $this->utilityFuncs->getSingle($this->settings, 'disableIPlog');
$fields['ip'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR');
if (intval($doDisableIPlog) === 1) {
unset($fields['ip']);
$doEnableIPlog = $this->utilityFuncs->getSingle($this->settings, 'enableIPlog');
$fields['ip'] = 'disabled';
if (intval($doEnableIPlog) === 1) {
$fields['ip'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR');
}
$fields['tstamp'] = time();
$fields['crdate'] = time();
Expand All @@ -48,25 +48,34 @@ public function process()
ksort($this->gp);
$keys = array_keys($this->gp);

$logParams = $this->gp;
$logParamsFull = $this->gp;

if ($this->settings['fields.']) {
foreach ($this->settings['fields.'] as $field => $fieldConf) {
$field = str_replace('.', '', $field);
if ($fieldConf['ifIsEmpty'] && (empty($logParams[$field]) || !isset($logParams[$field]))) {
if ($fieldConf['ifIsEmpty'] && (empty($logParamsFull[$field]) || !isset($logParamsFull[$field]))) {
$value = $this->utilityFuncs->getSingle($fieldConf, 'ifIsEmpty');
$logParams[$field] = $value;
$logParamsFull[$field] = $value;
}
if (intval($this->utilityFuncs->getSingle($fieldConf, 'nullIfEmpty')) === 1 && (empty($logParams[$field]) || !isset($logParams[$field]))) {
unset($logParams[$field]);
if (intval($this->utilityFuncs->getSingle($fieldConf, 'nullIfEmpty')) === 1 && (empty($logParamsFull[$field]) || !isset($logParamsFull[$field]))) {
unset($logParamsFull[$field]);
}
}
}
if ($this->settings['excludeFields']) {
$excludeFields = $this->utilityFuncs->getSingle($this->settings, 'excludeFields');
$excludeFields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $excludeFields);
foreach ($excludeFields as $excludeField) {
unset($logParams[$excludeField]);
unset($logParamsFull[$excludeField]);
}
}

$logParams = [];
if ($this->settings['includeFields']) {
$includeFields = $this->utilityFuncs->getSingle($this->settings, 'includeFields');
$includeFields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $includeFields);
foreach ($includeFields as $includeField) {
$logParams[$includeField] = $logParamsFull[$includeField];
}
}

Expand Down
11 changes: 6 additions & 5 deletions Classes/Utility/TcaUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,28 @@ public function addFields_predefinedJS($config)
*/
public function addFields_predefined($config)
{
$pid = FALSE;
if (!isset($config['flexParentDatabaseRow'])) {
throw new \Exception('could not load config[flexParentDatabaseRow]', 1481134575);
}
$pid = $config['flexParentDatabaseRow']['pid'];

if (is_array($GLOBALS['SOBE']->editconf['tt_content']) && reset($GLOBALS['SOBE']->editconf['tt_content']) === 'new') {
$pid = key($GLOBALS['SOBE']->editconf['tt_content']);

//Formhandler inserted after existing content element
if(intval($pid) < 0) {
$element = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('pid', 'tt_content', 'uid=' . abs($pid));
$pid = $element['pid'];
}
}

$contentUid = $config['row']['uid'] ?: 0;
$contentUid = $config['flexParentDatabaseRow']['uid'] ?: 0;
if (!$pid) {
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('pid', 'tt_content', 'uid=' . $contentUid);
if ($row) {
$pid = $row['pid'];
}
}

$ts = $this->loadTS($pid);

$predef = [];
Expand Down Expand Up @@ -182,5 +185,3 @@ public function loadTS($pageUid)
}

}

?>
2 changes: 1 addition & 1 deletion Classes/Validator/ErrorCheck/MaxLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function check()
$max = $this->utilityFuncs->getSingle($this->settings['params'], 'value');
if (isset($this->gp[$this->formFieldName]) &&
mb_strlen(trim($this->gp[$this->formFieldName]), $GLOBALS['TSFE']->renderCharset) > 0 &&
intval($max) > 0 &&
intval($max) >= 0 &&
mb_strlen(trim($this->gp[$this->formFieldName]), $GLOBALS['TSFE']->renderCharset) > $max
) {

Expand Down
20 changes: 10 additions & 10 deletions Classes/View/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,39 +439,39 @@ protected function fillDefaultMarkers()
}
$markers['###HIDDEN_FIELDS###'] = '
<input type="hidden" name="id" value="' . $GLOBALS['TSFE']->id . '" />
<input type="hidden" name="' . $name . '" value="1" />
<input type="hidden" name="' . htmlspecialchars($name) . '" value="1" />
';

$name = 'randomID';
if ($this->globals->getFormValuesPrefix()) {
$name = $this->globals->getFormValuesPrefix() . '[randomID]';
}
$markers['###HIDDEN_FIELDS###'] .= '
<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($this->gp['randomID']) . '" />
<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($this->gp['randomID']) . '" />
';

$name = 'removeFile';
if ($this->globals->getFormValuesPrefix()) {
$name = $this->globals->getFormValuesPrefix() . '[removeFile]';
}
$markers['###HIDDEN_FIELDS###'] .= '
<input type="hidden" id="removeFile-' . htmlspecialchars($this->gp['randomID']) . '" name="' . $name . '" value="" />
<input type="hidden" id="removeFile-' . htmlspecialchars($this->gp['randomID']) . '" name="' . htmlspecialchars($name) . '" value="" />
';

$name = 'removeFileField';
if ($this->globals->getFormValuesPrefix()) {
$name = $this->globals->getFormValuesPrefix() . '[removeFileField]';
}
$markers['###HIDDEN_FIELDS###'] .= '
<input type="hidden" id="removeFileField-' . htmlspecialchars($this->gp['randomID']) . '" name="' . $name . '" value="" />
<input type="hidden" id="removeFileField-' . htmlspecialchars($this->gp['randomID']) . '" name="' . htmlspecialchars($name) . '" value="" />
';

$name = 'submitField';
if ($this->globals->getFormValuesPrefix()) {
$name = $this->globals->getFormValuesPrefix() . '[submitField]';
}
$markers['###HIDDEN_FIELDS###'] .= '
<input type="hidden" id="submitField-' . htmlspecialchars($this->gp['randomID']) . '" name="' . $name . '" value="" />
<input type="hidden" id="submitField-' . htmlspecialchars($this->gp['randomID']) . '" name="' . htmlspecialchars($name) . '" value="" />
';

$name = 'formToken';
Expand Down Expand Up @@ -517,7 +517,7 @@ protected function fillDefaultMarkers()
$markers['###formValuesPrefix###'] = $this->globals->getFormValuesPrefix();

if ($this->gp['generated_authCode']) {
$markers['###auth_code###'] = $this->gp['generated_authCode'];
$markers['###auth_code###'] = htmlspecialchars($this->gp['generated_authCode']);
}

$markers['###ip###'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR');
Expand Down Expand Up @@ -766,7 +766,7 @@ public function fillFileMarkers(&$markers)
$maxCount = $fieldSettings['errorCheck.'][$key . '.']['maxCount'];
$markers['###' . $replacedFieldname . '_maxCount###'] = $maxCount;

$fileCount = count($sessionFiles[$replacedFieldname]);
$fileCount = (is_array($sessionFiles) && is_array($sessionFiles[$replacedFieldname])) ? count($sessionFiles[$replacedFieldname]) : 0;
$markers['###' . $replacedFieldname . '_fileCount###'] = $fileCount;

$remaining = $maxCount - $fileCount;
Expand Down Expand Up @@ -849,8 +849,8 @@ public function fillFileMarkers(&$markers)
$onClick .= 'return false;';

$link = '<a
href="javascript:void(0)"
class="formhandler_removelink"
href="javascript:void(0)"
class="formhandler_removelink"
onclick="' . str_replace(["\n", ' '], '', $onClick) . '"
>' . $text . '</a>';
}
Expand Down Expand Up @@ -1305,4 +1305,4 @@ protected function createStepBar($currentStep, $lastStep, $buttonNameBack = '',
}
return $content;
}
}
}
38 changes: 19 additions & 19 deletions Resources/Private/Layouts/Default.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<f:be.container
includeJsFiles="{0:'{f:uri.resource(path:\'JavaScript/module.js\')}'}"
includeJsFiles="{0:'{f:uri.resource(path:\'JavaScript/module.js\')}'}"
loadJQuery="TRUE"
loadExtJsTheme="FALSE"
enableClickMenu="FALSE"
includeRequireJsModules="{
0:'TYPO3/CMS/Backend/Modal',
1:'TYPO3/CMS/Backend/DateTimePicker'
0:'TYPO3/CMS/Backend/Modal',
1:'TYPO3/CMS/Backend/DateTimePicker'
}"
>
<div class="typo3-fullDoc">
<div id="typo3-docheader">
<div class="typo3-docheader-functions">
</div>
</div>
<div id="typo3-docbody">
<div id="typo3-inner-docbody">
<f:render section="headline" />
<div class="typo3-fullDoc">
<div id="typo3-docheader">
<div class="typo3-docheader-functions">
</div>
</div>
<div id="typo3-docbody">
<div id="typo3-inner-docbody">
<f:render section="headline" />

<f:flashMessages renderMode="div" />
<div id="formhandler-module">
<f:render section="content" />
</div>
</div>
</div>
</div>
</f:be.container>
<f:flashMessages />
<div id="formhandler-module">
<f:render section="content" />
</div>
</div>
</div>
</div>
</f:be.container>
59 changes: 59 additions & 0 deletions class.ext_update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
namespace Typoheads\Formhandler;

use TYPO3\CMS\Backend\Utility\BackendUtility;

class ext_update
{
public function main()
{
$pluginsToMigrate = $this->countListTypePlugins();
if ($pluginsToMigrate > 0) {
$this->migrateListTypePlugins();
}
$remainingPluginsToMigrate = $this->countListTypePlugins();
if ($remainingPluginsToMigrate === 0) {
return "Success: Migrated $pluginsToMigrate formhandler plugins from list_type to CType. The forms should now show up again in the frontend.";
} else {
return "Error: $pluginsToMigrate formhandler plugins should have been migrated, but $remainingPluginsToMigrate are still left.";
}
}

/**
* Activate update script if any pre 2.1 plugins are in the database
*
* @return bool
*/
public function access()
{
return $this->countListTypePlugins() > 0;
}

private function countListTypePlugins()
{
return $this->getDb()->exec_SELECTcountRows(
'*',
'tt_content',
'CType = \'list\' AND list_type = \'formhandler_pi1\'' . BackendUtility::deleteClause('tt_content')
);
}

private function migrateListTypePlugins()
{
$this->getDb()->exec_UPDATEquery(
'tt_content',
'CType = \'list\' AND list_type = \'formhandler_pi1\'' . BackendUtility::deleteClause('tt_content'),
[
'CType' => 'formhandler_pi1'
]
);
}

/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
private function getDb()
{
return $GLOBALS['TYPO3_DB'];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"psr-4": {
"Typoheads\\Formhandler\\": "Classes"
},
"classmap": ["Resources/PHP/tcpdf/tcpdf.php"]
"classmap": ["Resources/PHP/tcpdf/tcpdf.php","Resources/PHP/filtreatment"]
},
"replace": {
"formhandler": "self.version",
Expand Down
Loading