/** * import CSV-Data in step-by-step mode * * @return string HTML form */ function cmd_displayImport() { $step = GeneralUtility::_GP('importStep'); $defaultConf = array('remove_existing' => 0, 'first_fieldname' => 0, 'valid_email' => 0, 'remove_dublette' => 0, 'update_unique' => 0); if (GeneralUtility::_GP('CSV_IMPORT')) { $importerConfig = GeneralUtility::_GP('CSV_IMPORT'); if ($step['next'] == 'mapping') { $this->indata = GeneralUtility::array_merge($defaultConf, $importerConfig); } else { $this->indata = $importerConfig; } } if (empty($this->indata)) { $this->indata = array(); } if (empty($this->params)) { $this->params = array(); } // merge it with inData, but inData has priority. $this->indata = GeneralUtility::array_merge($this->params, $this->indata); $currentFileInfo = BasicFileUtility::getTotalFileInfo($this->indata['newFile']); $currentFileName = $currentFileInfo['file']; $currentFileSize = GeneralUtility::formatSize($currentFileInfo['size']); $currentFileMessage = $currentFileName . ' (' . $currentFileSize . ')'; if (empty($this->indata['csv']) && !empty($_FILES['upload_1']['name'])) { $this->indata['newFile'] = $this->checkUpload(); // TYPO3 6.0 returns an object... if (is_object($this->indata['newFile'][0])) { $storageConfig = $this->indata['newFile'][0]->getStorage()->getConfiguration(); $this->indata['newFile'] = $storageConfig['basePath'] . ltrim($this->indata['newFile'][0]->getIdentifier(), '/'); } } elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) { if ((strpos($currentFileInfo['file'], 'import') === false ? 0 : 1) && $currentFileInfo['realFileext'] === 'txt') { //do nothing } else { unset($this->indata['newFile']); } } if ($this->indata['back']) { $stepCurrent = $step['back']; } elseif ($this->indata['next']) { $stepCurrent = $step['next']; } elseif ($this->indata['update']) { $stepCurrent = 'mapping'; } if (strlen($this->indata['csv']) > 0) { $this->indata['mode'] = 'csv'; $this->indata['newFile'] = $this->writeTempFile(); } elseif (!empty($this->indata['newFile'])) { $this->indata['mode'] = 'file'; } else { unset($stepCurrent); } //check if "email" is mapped if ($stepCurrent === 'import') { $map = $this->indata['map']; $error = array(); //check noMap $newMap = GeneralUtility::removeArrayEntryByValue(array_unique($map), 'noMap'); if (empty($newMap)) { $error[] = 'noMap'; } elseif (!GeneralUtility::inArray($map, 'email')) { $error[] = 'email'; } if ($error) { $stepCurrent = 'mapping'; } } $out = ""; switch ($stepCurrent) { case 'conf': //get list of sysfolder //TODO: maybe only subtree von this->id?? $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title', 'pages', 'doktype = 254 AND ' . $GLOBALS['BE_USER']->getPagePermsClause(3) . BackendUtility::deleteClause('pages') . BackendUtility::BEenableFields('pages'), '', 'uid'); $optStorage = array(); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { if (BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1))) { $optStorage[] = array($row['uid'], $row['title'] . ' [uid:' . $row['uid'] . ']'); } } $GLOBALS['TYPO3_DB']->sql_free_result($res); $optDelimiter = array(array('comma', $GLOBALS['LANG']->getLL('mailgroup_import_separator_comma')), array('semicolon', $GLOBALS['LANG']->getLL('mailgroup_import_separator_semicolon')), array('colon', $GLOBALS['LANG']->getLL('mailgroup_import_separator_colon')), array('tab', $GLOBALS['LANG']->getLL('mailgroup_import_separator_tab'))); $optEncap = array(array('doubleQuote', ' " '), array('singleQuote', " ' ")); //TODO: make it variable? $optUnique = array(array('email', 'email'), array('name', 'name')); $this->params['inputDisable'] == 1 ? $disableInput = 'disabled="disabled"' : ($disableInput = ''); //show configuration $out = '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_header_conf') . '</h3>'; $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_storage'), $this->makeDropdown('CSV_IMPORT[storage]', $optStorage, $this->indata['storage'])); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_remove_existing'), '<input type="checkbox" name="CSV_IMPORT[remove_existing]" value="1"' . (!$this->indata['remove_existing'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_first_fieldnames'), '<input type="checkbox" name="CSV_IMPORT[first_fieldname]" value="1"' . (!$this->indata['first_fieldname'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_separator'), $this->makeDropdown('CSV_IMPORT[delimiter]', $optDelimiter, $this->indata['delimiter'], $disableInput)); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_encapsulation'), $this->makeDropdown('CSV_IMPORT[encapsulation]', $optEncap, $this->indata['encapsulation'], $disableInput)); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_csv_validemail-description'), '<input type="checkbox" name="CSV_IMPORT[valid_email]" value="1"' . (!$this->indata['valid_email'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_csv_dublette-description'), '<input type="checkbox" name="CSV_IMPORT[remove_dublette]" value="1"' . (!$this->indata['remove_dublette'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/> '); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_update_unique'), '<input type="checkbox" name="CSV_IMPORT[update_unique]" value="1"' . (!$this->indata['update_unique'] ? '' : ' checked="checked"') . ' ' . $disableInput . '/>'); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_record_unique'), $this->makeDropdown('CSV_IMPORT[record_unique]', $optUnique, $this->indata['record_unique'], $disableInput)); $out .= $this->formatTable($tblLines, array('width=300', 'nowrap'), 0, array(0, 1)); $out .= '<br /><br />'; $out .= '<input type="submit" name="CSV_IMPORT[back]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_back') . '" /> <input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_next') . '" />' . $this->makeHidden(array('CMD' => 'displayImport', 'importStep[next]' => 'mapping', 'importStep[back]' => 'upload', 'CSV_IMPORT[newFile]' => $this->indata['newFile'])); break; case 'mapping': //show charset selector $cs = array_unique(array_values($GLOBALS['LANG']->csConvObj->synonyms)); $charSets = array(); foreach ($cs as $charset) { $charSets[] = array($charset, $charset); } if (!isset($this->indata['charset'])) { $this->indata['charset'] = 'iso-8859-1'; } $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_charset') . '</h3>'; $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_charset_choose'), $this->makeDropdown('CSV_IMPORT[charset]', $charSets, $this->indata['charset'])); $out .= $this->formatTable($tblLines, array('nowrap', 'nowrap'), 0, array(1, 1), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist"'); $out .= '<input type="submit" name="CSV_IMPORT[update]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_update') . '"/>'; unset($tblLines); //show mapping form $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_conf') . '</h3>'; if ($this->indata['first_fieldname']) { //read csv $csvData = $this->readExampleCSV(4); $csv_firstRow = $csvData[0]; $csvData = array_slice($csvData, 1); } else { //read csv $csvData = $this->readExampleCSV(3); $fieldsAmount = count($csvData[0]); $csv_firstRow = array(); for ($i = 0; $i < $fieldsAmount; $i++) { $csv_firstRow[] = 'field_' . $i; } } //read tt_address TCA $no_map = array('image'); $tt_address_fields = array_keys($GLOBALS['TCA']['tt_address']['columns']); foreach ($no_map as $v) { $tt_address_fields = GeneralUtility::removeArrayEntryByValue($tt_address_fields, $v); } $mapFields = array(); foreach ($tt_address_fields as $map) { $mapFields[] = array($map, str_replace(':', '', $GLOBALS['LANG']->sL($GLOBALS['TCA']['tt_address']['columns'][$map]['label']))); } //add 'no value' array_unshift($mapFields, array('noMap', $GLOBALS['LANG']->getLL('mailgroup_import_mapping_mapTo'))); $mapFields[] = array('cats', $GLOBALS['LANG']->getLL('mailgroup_import_mapping_categories')); reset($csv_firstRow); reset($csvData); $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_number'), $GLOBALS['LANG']->getLL('mailgroup_import_mapping_description'), $GLOBALS['LANG']->getLL('mailgroup_import_mapping_mapping'), $GLOBALS['LANG']->getLL('mailgroup_import_mapping_value')); for ($i = 0; $i < count($csv_firstRow); $i++) { //example CSV $exampleLines = array(); for ($j = 0; $j < count($csvData); $j++) { $exampleLines[] = array($csvData[$j][$i]); } $tblLines[] = array($i + 1, $csv_firstRow[$i], $this->makeDropdown('CSV_IMPORT[map][' . $i . ']', $mapFields, $this->indata['map'][$i]), $this->formatTable($exampleLines, array('nowrap'), 0, array(0), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist" style="width:100%; border:0px; margin:0px;"')); } if ($error) { $out .= '<h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_error') . '</h3>'; $out .= $GLOBALS['LANG']->getLL('mailgroup_import_mapping_error_detail') . '<br /><ul>'; foreach ($error as $errorDetail) { $out .= '<li>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_error_' . $errorDetail) . '</li>'; } $out .= '</ul>'; } //additional options $tblLinesAdd = array(); //header $tblLinesAdd[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_all_html'), '<input type="checkbox" name="CSV_IMPORT[all_html]" value="1"' . (!$this->indata['all_html'] ? '' : ' checked="checked"') . '/> '); //get categories $temp = BackendUtility::getModTSconfig($this->parent->id, 'TCEFORM.sys_dmail_group.select_categories.PAGE_TSCONFIG_IDLIST'); if (is_numeric($temp['value'])) { $rowCat = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_dmail_category', 'pid IN (' . $temp['value'] . ')' . BackendUtility::deleteClause('sys_dmail_category') . BackendUtility::BEenableFields('sys_dmail_category')); if (!empty($rowCat)) { $tblLinesAdd[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_cats'), ''); if ($this->indata['update_unique']) { $tblLinesAdd[] = array($GLOBALS['LANG']->getLL('mailgroup_import_mapping_cats_add'), '<input type="checkbox" name="CSV_IMPORT[add_cat]" value="1"' . ($this->indata['add_cat'] ? ' checked="checked"' : '') . '/> '); } foreach ($rowCat as $k => $v) { $tblLinesAdd[] = array(' ' . htmlspecialchars($v['category']), '<input type="checkbox" name="CSV_IMPORT[cat][' . $k . ']" value="' . $v['uid'] . '"' . ($this->indata['cat'][$k] != $v['uid'] ? '' : ' checked="checked"') . '/> '); } } } $out .= $this->formatTable($tblLines, array('nowrap', 'nowrap', 'nowrap', 'nowrap'), 1, array(0, 0, 1, 1), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist"'); $out .= '<br /><br />'; //additional options $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_mapping_conf_add') . '</h3>'; $out .= $this->formatTable($tblLinesAdd, array('nowrap', 'nowrap'), 0, array(1, 1), 'border="0" cellpadding="0" cellspacing="0" class="typo3-dblist"'); $out .= '<br /><br />'; $out .= '<input type="submit" name="CSV_IMPORT[back]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_back') . '"/> <input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_next') . '"/>' . $this->makeHidden(array('CMD' => 'displayImport', 'importStep[next]' => 'import', 'importStep[back]' => 'conf', 'CSV_IMPORT[newFile]' => $this->indata['newFile'], 'CSV_IMPORT[storage]' => $this->indata['storage'], 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'])); break; case 'import': //show import messages $out .= '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_ready_import') . '</h3>'; $out .= $GLOBALS['LANG']->getLL('mailgroup_import_ready_import_label') . '<br /><br />'; $out .= '<input type="submit" name="CSV_IMPORT[back]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_back') . '" /> <input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_import') . '" />' . $this->makeHidden(array('CMD' => 'displayImport', 'importStep[next]' => 'startImport', 'importStep[back]' => 'mapping', 'CSV_IMPORT[newFile]' => $this->indata['newFile'], 'CSV_IMPORT[storage]' => $this->indata['storage'], 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], 'CSV_IMPORT[all_html]' => $this->indata['all_html'], 'CSV_IMPORT[add_cat]' => $this->indata['add_cat'], 'CSV_IMPORT[charset]' => $this->indata['charset'])); $hiddenMapped = array(); foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); } if (is_array($this->indata['cat'])) { foreach ($this->indata['cat'] as $k => $catUID) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUID); } } $out .= implode('', $hiddenMapped); break; case 'startImport': //starting import & show errors //read csv if ($this->indata['first_fieldname']) { //read csv $csvData = $this->readCSV(); $csvData = array_slice($csvData, 1); } else { //read csv $csvData = $this->readCSV(); } //show not imported record and reasons, $result = $this->doImport($csvData); $out = '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_done') . '</h3>'; $defaultOrder = array('new', 'update', 'invalid_email', 'double'); if (!empty($this->params['resultOrder'])) { $resultOrder = GeneralUtility::trimExplode(',', $this->params['resultOrder']); } else { $resultOrder = array(); } $diffOrder = array_diff($defaultOrder, $resultOrder); $endOrder = array_merge($resultOrder, $diffOrder); foreach ($endOrder as $order) { $tblLines = array(); $tblLines[] = array($GLOBALS['LANG']->getLL('mailgroup_import_report_' . $order)); if (is_array($result[$order])) { foreach ($result[$order] as $k => $v) { $mapKeys = array_keys($v); $tblLines[] = array($k + 1, $v[$mapKeys[0]], $v['email']); } } $out .= $this->formatTable($tblLines, array('nowrap', 'first' => 'colspan="3"'), 1, array(1)); } //back button $out .= $this->makeHidden(array('CMD' => 'displayImport', 'importStep[back]' => 'import', 'CSV_IMPORT[newFile]' => $this->indata['newFile'], 'CSV_IMPORT[storage]' => $this->indata['storage'], 'CSV_IMPORT[remove_existing]' => $this->indata['remove_existing'], 'CSV_IMPORT[first_fieldname]' => $this->indata['first_fieldname'], 'CSV_IMPORT[delimiter]' => $this->indata['delimiter'], 'CSV_IMPORT[encapsulation]' => $this->indata['encapsulation'], 'CSV_IMPORT[valid_email]' => $this->indata['valid_email'], 'CSV_IMPORT[remove_dublette]' => $this->indata['remove_dublette'], 'CSV_IMPORT[update_unique]' => $this->indata['update_unique'], 'CSV_IMPORT[record_unique]' => $this->indata['record_unique'], 'CSV_IMPORT[all_html]' => $this->indata['all_html'], 'CSV_IMPORT[charset]' => $this->indata['charset'])); $hiddenMapped = array(); foreach ($this->indata['map'] as $fieldNr => $fieldMapped) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[map][' . $fieldNr . ']', $fieldMapped); } if (is_array($this->indata['cat'])) { foreach ($this->indata['cat'] as $k => $catUID) { $hiddenMapped[] = $this->makeHidden('CSV_IMPORT[cat][' . $k . ']', $catUID); } } $out .= implode('', $hiddenMapped); break; case 'upload': default: //show upload file form $out = '<hr /><h3>' . $GLOBALS['LANG']->getLL('mailgroup_import_header_upload') . '</h3>'; $tempDir = $this->userTempFolder(); $tblLines[] = $GLOBALS['LANG']->getLL('mailgroup_import_upload_file') . '<input type="file" name="upload_1" size="30" />'; if ($this->indata['mode'] == 'file' && !((strpos($currentFileInfo['file'], 'import') === false ? 0 : 1) && $currentFileInfo['realFileext'] === 'txt')) { $tblLines[] = $GLOBALS['LANG']->getLL('mailgroup_import_current_file') . '<b>' . $currentFileMessage . '</b>'; } if ((strpos($currentFileInfo['file'], 'import') === false ? 0 : 1) && $currentFileInfo['realFileext'] === 'txt') { $handleCSV = fopen($this->indata['newFile'], 'r'); $this->indata['csv'] = fread($handleCSV, filesize($this->indata['newFile'])); fclose($handleCSV); } $tblLines[] = ''; $tblLines[] = '<b>' . $GLOBALS['LANG']->getLL('mailgroup_import_or') . '</b>'; $tblLines[] = ''; $tblLines[] = $GLOBALS['LANG']->getLL('mailgroup_import_paste_csv'); $tblLines[] = '<textarea name="CSV_IMPORT[csv]" rows="25" wrap="off"' . $this->parent->doc->formWidthText(48, '', 'off') . '>' . GeneralUtility::formatForTextarea($this->indata['csv']) . '</textarea>'; $tblLines[] = '<input type="submit" name="CSV_IMPORT[next]" value="' . $GLOBALS['LANG']->getLL('mailgroup_import_next') . '" />'; $out .= implode('<br />', $tblLines); $out .= '<input type="hidden" name="CMD" value="displayImport" /> <input type="hidden" name="importStep[next]" value="conf" /> <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempDir) . '" ' . ($_POST['importNow'] ? 'disabled' : '') . '/> <input type="hidden" name="file[upload][1][data]" value="1" /> <input type="hidden" name="CSV_IMPORT[newFile]" value ="' . $this->indata['newFile'] . '">'; break; } $theOutput = $this->parent->doc->section($GLOBALS['LANG']->getLL('mailgroup_import') . BackendUtility::cshItem($this->cshTable, 'mailgroup_import', $GLOBALS['BACK_PATH']), $out, 1, 1, 0, TRUE); /** * Hook for cmd_displayImport * use it to manipulate the steps in the import process */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport'])) { $hookObjectsArr = array(); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['cmd_displayImport'] as $classRef) { $hookObjectsArr[] =& GeneralUtility::getUserObj($classRef); } } if (is_array($hookObjectsArr)) { foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'cmd_displayImport')) { $theOutput = ''; $theOutput = $hookObj->cmd_displayImport($this); } } } return $theOutput; }
/** * action feeditAction * Bearbeiten eines bestehenden Datensatzes aus fremder Tabelle starten. * Dazu Kopie in tx_nnfesubmit_domain_model_entry anlegen und zum Formular weiterleiten * * @return array */ public function feeditAction($params) { $this->settings = $this->settingsUtility->getSettings(); $uid = intval($params['uid']); $type = $params['type']; $settings = $this->settings[$type]; $extName = $settings['extension']; // Prüfen, ob Datensatz in fremder Tabelle exisitert if (!($data = $this->tableService->getEntry($settings, $uid))) { return $this->anyHelper->addFlashMessage('Kein Eintrag gefunden', "In der Tabelle {$settings['tablename']} wurde kein Datensatz mit der uid={$uid} gefunden.", 'ERROR'); } // Datensatz zum Bearbeiten anlegen if (!($entry = $this->entryRepository->getEntryForExt($uid, $type))) { $entry = $this->objectManager->get('\\Nng\\Nnfesubmit\\Domain\\Model\\Entry'); $this->entryRepository->add($entry); $this->persistenceManager->persistAll(); //$unique_filename = $this->basicFileFunctions->getUniqueName($file, 'uploads/tx_nnfesubmit/'); //if (\TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($files['tmp_name'][$k], $unique_filename)) { } // Media zurück in den Ordner uploads/tx_nnfesubmit kopieren $media = $settings['media']; foreach ($media as $k => $path) { if ($data[$k]) { $unique_filename = $this->basicFileFunctions->getUniqueName(trim(basename($data[$k])), 'uploads/tx_nnfesubmit/'); \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($path . $data[$k], $unique_filename); if (!file_exists($unique_filename)) { $this->anyHelper->addFlashMessage('Datei nicht kopiert', 'Die Datei ' . $data[$k] . ' konnte nicht kopiert werden.', 'WARNING'); } } } //$entry->setFeUser( $GLOBALS['TSFE']->fe_user->user['uid'] ); $entry->setCruserId($GLOBALS['TSFE']->fe_user->user['uid']); $entry->setSrcuid($uid); $entry->setExt($type); $entry->setData(json_encode($data)); $this->entryRepository->update($entry); $this->persistenceManager->persistAll(); $entryUid = $entry->getUid(); $newAdminKey = ''; if ($params['adminKey'] && $this->anyHelper->validateKeyForUid($uid, $params['adminKey'], 'admin')) { $newAdminKey = $this->anyHelper->createKeyForUid($entryUid, 'admin'); } //http://adhok.99grad.de/index.php?id=17&id=17&nnf%5B193%5D%5Buid%5D=3&cHash=f14da214fc18a7f53b4da7342f3abe64&eID=nnfesubmit&action=feedit&type=nnfilearchive&uid=21&key=02bc7442 $this->anyHelper->httpRedirect($settings['editPid'], array('nnf' => $params['nnf'], 'tx_nnfesubmit_nnfesubmit[key]' => $this->anyHelper->createKeyForUid($entryUid), 'tx_nnfesubmit_nnfesubmit[adminKey]' => $newAdminKey, 'tx_nnfesubmit_nnfesubmit[entry]' => $entryUid, 'tx_nnfesubmit_nnfesubmit[pluginUid]' => intval($params['pluginUid']), 'tx_nnfesubmit_nnfesubmit[returnUrl]' => $params['returnUrl'])); // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($entry); // $this->editAction( $entry->getUid() ); die; }
/** * Checks, if a path is within the mountpoints of the backend user * * @param string $folder Absolute filepath * @return boolean If the input path is found in the backend users filemounts, then return TRUE. * @deprecated since 6.2 - will be removed two versions later without replacement */ public function checkFolder($folder) { GeneralUtility::logDeprecatedFunction(); return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? TRUE : FALSE; }
/** * Copies any "RTEmagic" image files found in record with table/id to new names. * Usage: After copying a record this function should be called to search for "RTEmagic"-images inside the record. If such are found they should be duplicated to new names so all records have a 1-1 relation to them. * Reason for copying RTEmagic files: a) if you remove an RTEmagic image from a record it will remove the file - any other record using it will have a lost reference! b) RTEmagic images keeps an original and a copy. The copy always is re-calculated to have the correct physical measures as the HTML tag inserting it defines. This is calculated from the original. Two records using the same image could have difference HTML-width/heights for the image and the copy could only comply with one of them. If you don't want a 1-1 relation you should NOT use RTEmagic files but just insert it as a normal file reference to a file inside fileadmin/ folder * * @param string $table Table name * @param int $theNewSQLID Record UID * @return void */ public function copyRecord_fixRTEmagicImages($table, $theNewSQLID) { // Creating fileFunc object. if (!$this->fileFunc) { $this->fileFunc = GeneralUtility::makeInstance(BasicFileUtility::class); $this->include_filefunctions = 1; } // Select all RTEmagic files in the reference table from the table/ID $where = join(' AND ', array('ref_table=' . $this->databaseConnection->fullQuoteStr('_FILE', 'sys_refindex'), 'ref_string LIKE ' . $this->databaseConnection->fullQuoteStr('%/RTEmagic%', 'sys_refindex'), 'softref_key=' . $this->databaseConnection->fullQuoteStr('images', 'sys_refindex'), 'tablename=' . $this->databaseConnection->fullQuoteStr($table, 'sys_refindex'), 'recuid=' . (int) $theNewSQLID)); $rteFileRecords = $this->databaseConnection->exec_SELECTgetRows('*', 'sys_refindex', $where, '', 'sorting DESC'); // Traverse the files found and copy them: if (!is_array($rteFileRecords)) { return; } foreach ($rteFileRecords as $rteFileRecord) { $filename = basename($rteFileRecord['ref_string']); if (!GeneralUtility::isFirstPartOfStr($filename, 'RTEmagicC_')) { continue; } $fileInfo = array(); $fileInfo['exists'] = @is_file(PATH_site . $rteFileRecord['ref_string']); $fileInfo['original'] = substr($rteFileRecord['ref_string'], 0, -strlen($filename)) . 'RTEmagicP_' . preg_replace('/\\.[[:alnum:]]+$/', '', substr($filename, 10)); $fileInfo['original_exists'] = @is_file(PATH_site . $fileInfo['original']); // CODE from tx_impexp and class.rte_images.php adapted for use here: if (!$fileInfo['exists'] || !$fileInfo['original_exists']) { if ($this->enableLogging) { $this->newlog('Trying to copy RTEmagic files (' . $rteFileRecord['ref_string'] . ' / ' . $fileInfo['original'] . ') but one or both were missing', 1); } continue; } // Initialize; Get directory prefix for file and set the original name: $dirPrefix = dirname($rteFileRecord['ref_string']) . '/'; $rteOrigName = basename($fileInfo['original']); // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file! if ($rteOrigName && GeneralUtility::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) { // RTE: // From the "original" RTE filename, produce a new "original" destination filename which is unused. $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix); // Create copy file name: $pI = pathinfo($rteFileRecord['ref_string']); $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension']; if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)) { // Making copies: GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName); GeneralUtility::upload_copy_move(PATH_site . $rteFileRecord['ref_string'], $copyDestName); clearstatcache(); // Register this: $this->RTEmagic_copyIndex[$rteFileRecord['tablename']][$rteFileRecord['recuid']][$rteFileRecord['field']][$rteFileRecord['ref_string']] = PathUtility::stripPathSitePrefix($copyDestName); // Check and update the record using \TYPO3\CMS\Core\Database\ReferenceIndex if (@is_file($copyDestName)) { /** @var ReferenceIndex $sysRefObj */ $sysRefObj = GeneralUtility::makeInstance(ReferenceIndex::class); $error = $sysRefObj->setReferenceValue($rteFileRecord['hash'], PathUtility::stripPathSitePrefix($copyDestName), false, true); if ($this->enableLogging && $error) { echo $this->newlog(ReferenceIndex::class . '::setReferenceValue(): ' . $error, 1); } } elseif ($this->enableLogging) { $this->newlog('File "' . $copyDestName . '" was not created!', 1); } } elseif ($this->enableLogging) { $this->newlog('Could not construct new unique names for file!', 1); } } elseif ($this->enableLogging) { $this->newlog('Maybe directory of file was not within "uploads/"?', 1); } } }
/** * Initialize class variables * * @return void */ public function initVariables() { // Main GPvars: $this->pointer = GeneralUtility::_GP('pointer'); $this->bparams = GeneralUtility::_GP('bparams'); $this->P = GeneralUtility::_GP('P'); $this->expandPage = GeneralUtility::_GP('expandPage'); $this->expandFolder = GeneralUtility::_GP('expandFolder'); $this->PM = GeneralUtility::_GP('PM'); // Site URL // Current site url $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); $this->determineScriptUrl(); // Find "mode" $this->mode = GeneralUtility::_GP('mode'); if (!$this->mode) { $this->mode = 'rte'; } // Init fileProcessor $this->fileProcessor = GeneralUtility::makeInstance(BasicFileUtility::class); $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); }
/** * Returns a unique absolute path of a file or folder. * * @param string $path * the path of a file or folder relative to the calling extension's * upload directory, must not be empty * * @return string the unique absolute path of a file or folder * * @throws \InvalidArgumentException */ public function getUniqueFileOrFolderPath($path) { if (empty($path)) { throw new \InvalidArgumentException('The first parameter $path must not be empty.', 1334439457); } if (!self::$fileNameProcessor) { self::$fileNameProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility'); } return self::$fileNameProcessor->getUniqueName(basename($path), $this->uploadFolderPath . GeneralUtility::dirname($path)); }
/** * Copies any "RTEmagic" image files found in record with table/id to new names. * Usage: After copying a record this function should be called to search for "RTEmagic"-images inside the record. If such are found they should be duplicated to new names so all records have a 1-1 relation to them. * Reason for copying RTEmagic files: a) if you remove an RTEmagic image from a record it will remove the file - any other record using it will have a lost reference! b) RTEmagic images keeps an original and a copy. The copy always is re-calculated to have the correct physical measures as the HTML tag inserting it defines. This is calculated from the original. Two records using the same image could have difference HTML-width/heights for the image and the copy could only comply with one of them. If you don't want a 1-1 relation you should NOT use RTEmagic files but just insert it as a normal file reference to a file inside fileadmin/ folder * * @param string $table Table name * @param integer $theNewSQLID Record UID * @return void * @todo Define visibility */ public function copyRecord_fixRTEmagicImages($table, $theNewSQLID) { // Creating fileFunc object. if (!$this->fileFunc) { $this->fileFunc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility'); $this->include_filefunctions = 1; } // Select all RTEmagic files in the reference table from the table/ID $recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE', 'sys_refindex') . ' AND ref_string LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('%/RTEmagic%', 'sys_refindex') . ' AND softref_key=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('images', 'sys_refindex') . ' AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') . ' AND recuid=' . intval($theNewSQLID), '', 'sorting DESC'); // Traverse the files found and copy them: if (is_array($recs)) { foreach ($recs as $rec) { $filename = basename($rec['ref_string']); $fileInfo = array(); if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($filename, 'RTEmagicC_')) { $fileInfo['exists'] = @is_file(PATH_site . $rec['ref_string']); $fileInfo['original'] = substr($rec['ref_string'], 0, -strlen($filename)) . 'RTEmagicP_' . preg_replace('/\\.[[:alnum:]]+$/', '', substr($filename, 10)); $fileInfo['original_exists'] = @is_file(PATH_site . $fileInfo['original']); // CODE from tx_impexp and class.rte_images.php adapted for use here: if ($fileInfo['exists'] && $fileInfo['original_exists']) { // Initialize; Get directory prefix for file and set the original name: $dirPrefix = dirname($rec['ref_string']) . '/'; $rteOrigName = basename($fileInfo['original']); // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file! if ($rteOrigName && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) { // RTE: // From the "original" RTE filename, produce a new "original" destination filename which is unused. $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix); // Create copy file name: $pI = pathinfo($rec['ref_string']); $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension']; if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($copyDestName)) { // Making copies: \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName); \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . $rec['ref_string'], $copyDestName); clearstatcache(); // Register this: $this->RTEmagic_copyIndex[$rec['tablename']][$rec['recuid']][$rec['field']][$rec['ref_string']] = substr($copyDestName, strlen(PATH_site)); // Check and update the record using the t3lib_refindex class: if (@is_file($copyDestName)) { $sysRefObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex'); $error = $sysRefObj->setReferenceValue($rec['hash'], substr($copyDestName, strlen(PATH_site)), FALSE, TRUE); if ($error) { echo $this->newlog('TYPO3\\CMS\\Core\\Database\\ReferenceIndex::setReferenceValue(): ' . $error, 1); } } else { $this->newlog('File "' . $copyDestName . '" was not created!', 1); } } else { $this->newlog('Could not construct new unique names for file!', 1); } } else { $this->newlog('Maybe directory of file was not within "uploads/"?', 1); } } else { $this->newlog('Trying to copy RTEmagic files (' . $rec['ref_string'] . ' / ' . $fileInfo['original'] . ') but one or both were missing', 1); } } } } }
/** * Import users from CSV after all necessary mapping info has been provided. * * @return string formatted HTML to be printed */ public function importUsers() { // we need the UIDs of existing users later if we want to update users // unfortunately, sql_insert_id() doesn't work for SQL UPDATE statements // even though the MySQL reference handbook tells you so... $res = $this->getDatabaseConnection()->exec_SELECTquery($this->uniqueUserIdentifier . ',uid', $this->userTypeDBTable, 'pid=' . $this->defaultUserData['pid']); while ($row = $this->getDatabaseConnection()->sql_fetch_row($res)) { $users[] = $row[0]; $userIDS[] = $row[1]; } $this->getDatabaseConnection()->sql_free_result($res); // read the import file $CSV = $this->readDataFromFile(false); /** * Hook added on request of Franz Ripfel: * hook for pre-processing of read-in data. At this time of the import session, we have read in * the CSV as an array and pass it and the object itself to the external function as a REFERENCE. * Your external function may manipulate the array as it likes (fx. delete, alter datasets). * See function readCSV() for import details. */ if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rs_userimp']['beforeImportHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rs_userimp']['beforeImportHook'] as $_classRef) { $_procObj =& GeneralUtility::getUserObj($_classRef); $CSV = $_procObj->manipulateData($CSV, $this); } } $content = ''; // line counter $n = 0; // $main[] holds all read CSV values $users = array(); foreach ($CSV as $row) { // we are not working with numerical indexes, // so we need the keys for CSV values foreach ($this->numMap as $key => $value) { $sub[$key] = $row[$value]; } // merge in defaultUserData[] $users[$n] = array_merge($sub, $this->defaultUserData); // substitute customValues if ($this->enableAutoValues && is_array($this->inData['autoval'])) { // to save time, only defined values get computed foreach ($this->inData['autoval'] as $key2 => $val2) { // we need a second array for to store generated custom values // because it might happen that a user maps a field to a new value // and later wants to map the original field again (would have been overwritten by then). // the original value is preserved that way and may // be used throughout the whole mapping process. $sub2[$n][$this->inData['fieldmap'][$key2]] = $this->generateCustomValue($users[$n][$this->inData['fieldmap'][$key2]], $this->inData['customValue'][$key2], $row); } // merge the 2 arrays, $sub2 takes precedence $users[$n] = array_merge($users[$n], $sub2[$n]); } if (array_key_exists('useEMailAsUsername', $this->inData['settings']) && $this->inData['settings']['useEMailAsUsername'] == 1) { // Use e-mail as username if requested $users[$n]['username'] = $users[$n]['email']; } if (array_key_exists('generatePassword', $this->inData['settings']) && $this->inData['settings']['generatePassword'] == 1) { // Generate random password if configured $users[$n]['password'] = \Visol\RsUserimp\Utility\Algorithms::generateRandomString(32); } unset($sub); $n++; } // some counters $i = 0; // total users imported $j = 0; // total users skipped $m = 0; // total users read from CSV $u = 0; // total users updated // process users one by one foreach ($users as $user) { $msg = array(); $importUser = TRUE; $updateUser = FALSE; // check the imported user data - values are manipulated // and are passed by REFERENCE switch ((string) $this->userType) { case 'FE': $msg[] = $this->checkUserDataFE($user, $importUser); break; case 'TT': $msg[] = $this->checkUserDataTT($user, $importUser); break; case 'BE': $msg[] = $this->checkUserDataBE($user, $importUser); break; default: die($this->getLanguageService()->getLL('f1.tab5.error.unknownFatalError')); } // the user array has now only valid values // handle the user array: check if we have users, rename them if necessary, // skip import if necessary. // if we have already users in the DB... if (!empty($users) && $importUser) { // the username already exists while (in_array($user[$this->uniqueUserIdentifier], $users)) { if (!$this->enableAutoRename && !$this->enableUpdate) { $msg = array(); $msg[] = $this->getLanguageService()->getLL('f1.tab5.error.duplicateUserName'); $importUser = FALSE; // jump out of while break 1; } elseif ($this->enableUpdate) { //$msg = array(); //$msg[] = ;//$this->getLanguageService()->getLL('f1.tab5.error.duplicateUserName'); $updateUser = TRUE; break 1; } elseif ($this->enableAutoRename) { // rename current import users $newName = $user[$this->uniqueUserIdentifier] . '0'; // $msg[] = $this->getLanguageService()->getLL('f1.tab5.error.renamed'); // check for max value if (strlen($newName) > 39) { $msg = array(); $msg[] = $this->getLanguageService()->getLL('f1.tab5.error.userNameTooLong'); $importUser = FALSE; // jump out of while break 1; } else { $user[$this->uniqueUserIdentifier] = $newName; $main[$i][$this->uniqueUserIdentifier] = $user[$this->uniqueUserIdentifier]; } } } } // Use TCAdefaults to set default field values if the fields affected were not set by the import table $targetPidTsConfig = GeneralUtility::removeDotsFromTS(BackendUtility::getPagesTSconfig($user['pid'])); if (array_key_exists('TCAdefaults', $targetPidTsConfig) && array_key_exists($this->userTypeDBTable, $targetPidTsConfig['TCAdefaults'])) { $tcaDefaults = $targetPidTsConfig['TCAdefaults'][$this->userTypeDBTable]; foreach ($tcaDefaults as $key => $value) { if (!array_key_exists($key, $user)) { $user[$key] = $value; } } } $uid = $userIDS[$m]; if ($importUser) { if ($updateUser) { // Update existing user // SQL injection prevention foreach ($user as $key => $val) { $user[$key] = $this->getDatabaseConnection()->quoteStr($val, $this->userTypeDBTable); } $res = $this->getDatabaseConnection()->exec_UPDATEquery($this->userTypeDBTable, $this->uniqueUserIdentifier . "='" . $main[$m][$this->uniqueUserIdentifier] . "'", $user); // set uid $GLOBALS['BE_USER']->writelog(1, 1, 0, '', 'User %s [UID %s] updated by CSV import action', array($user['username'], $uid)); $content .= '<li><strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.userUpdated'), $user[$this->uniqueUserIdentifier], $userIDS[$m]) . '</strong> ' . (!empty($msg) ? implode(',', $msg) : '') . '</li>'; $u++; // BEWARE: updated users are added to the rollback dataset!!! $rollbackDataTemp[] = $uid; } else { // Insert new user // SQL injection prevention foreach ($user as $key => $val) { $user[$key] = $this->getDatabaseConnection()->quoteStr($val, $this->userTypeDBTable); } $res = $this->getDatabaseConnection()->exec_INSERTquery($this->userTypeDBTable, $user); // get uid $uid = $this->getDatabaseConnection()->sql_insert_id(); $GLOBALS['BE_USER']->writelog(1, 1, 0, '', 'User %s [UID %s] created by CSV import action', array($user[$this->uniqueUserIdentifier], $uid)); $users[] = $user[$this->uniqueUserIdentifier]; $i++; $content .= '<li><strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.userInserted'), $user[$this->uniqueUserIdentifier], $user['name'], $uid) . '</strong> ' . (!empty($msg) ? implode(',', $msg) : '') . '</li>'; $rollbackDataTemp[] = $uid; } } else { $export[] = $CSV[$m]; $content .= '<li><strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.userSkipped'), $user[$this->uniqueUserIdentifier], $uid) . '</strong> ' . (!empty($msg) ? implode(',', $msg) : '') . '</li>'; $j++; } $m++; } $content = '<strong>' . sprintf($this->getLanguageService()->getLL('f1.tab5.usersImported'), $m, $i, $u, $j) . '</strong><ul class="import-log">' . $content . '</ul>'; /** * If createDropFile is set, create a drop file which holds all skipped users. * The CSV format is determined by the import settings, so this file may be edited and re-imported * by simply using the previous preset (mapping). */ if ($this->createDropFile && is_array($export)) { $fileInfo = \TYPO3\CMS\Core\Utility\File\BasicFileUtility::getTotalFileInfo($this->file); $newFileName = 'DROPPED_' . $fileInfo['file']; $fileContent = array(); $fileContent[0][] = $this->columnNamesFromCSV; $fileContent = array_merge($fileContent[0], $export); $newAbsFile = GeneralUtility::getFileAbsFileName('uploads/tx_rsuserimp/' . 'DROPPED_' . $fileInfo['file']); //PATH_site.'typo3temp/'.$newFileName; $newRelFile = '/uploads/tx_rsuserimp/' . $newFileName; fputcsv($newAbsFile, $fileContent, $this->fieldDelimiter, $this->fieldEncaps); $content .= '<div align="center"><a href="' . $newRelFile . '">' . $this->getLanguageService()->getLL('f1.tab5.downloadFile') . '</a>'; } if (!empty($rollbackDataTemp)) { $fileInfo = \TYPO3\CMS\Core\Utility\File\BasicFileUtility::getTotalFileInfo($this->file); $file = $fileInfo['file']; $rollbackDataSets = implode(",", $rollbackDataTemp); $rollbackData = array('crdate' => time(), 'target_pid' => $this->defaultUserData['pid'], 'user_uid' => $GLOBALS['BE_USER']->user['uid'], 'title' => 'Import session of user ' . $GLOBALS['BE_USER']->user['username'] . ' [UID ' . $GLOBALS['BE_USER']->user['uid'] . ']: ' . $i . ' users imported to PID ' . $this->defaultUserData['pid'], 'usertype' => $this->userType, 'db_table' => $this->userTypeDBTable, 'unique_identifier' => $this->uniqueUserIdentifier, 'num_imp' => $i, 'num_drop' => $j, 'num_upd' => $u, 'file' => $file, 'dropfile' => $newAbsFile, 'active' => '1', 'deleted' => '0', 'session_data' => $rollbackDataSets); $res = $this->getDatabaseConnection()->exec_INSERTquery('tx_rsuserimp_sessions', $rollbackData); //insert } /** * After parsing the CSV file, the file gets deleted by either moving it to the recycler (if * present) or by deleting it. */ $FILE = array(); $FILE['delete'][] = array('data' => $this->file); $fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $fileProcessor->init($this->getBackendUserAuthentication()->getFileMountRecords(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->user['fileoper_perms']); // use recycler: 0 = no, 1 = if available, 2 = always $fileProcessor->useRecycler = $this->useRecycler; $fileProcessor->start($FILE); $fileProcessor->processData(); return $content; }
/** * Adds and css and javascript to BE form. * * @return void */ protected function addStylesAndJavascriptToForm() { $extCssRel = ExtensionManagementUtility::extRelPath('t3kit_extension_tools') . 'Resources/Public/Css/BE/iconFontSelector.css'; $pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class); $pageRenderer->addCssFile(BasicFileUtility::slashPath($this->cssFileInformation['relativePath']) . $this->cssFileInformation['basename']); $pageRenderer->addCssFile($extCssRel); }
/** * Processing of files. * NOTICE: for now files can be handled only on creation of records. But a more advanced feature is that PREVIEW of files is handled. * * @param array $cmdParts Array with cmd-parts (from parseValues()). This will for example contain information about allowed file extensions and max size of uploaded files. * @param string $theField The fieldname with the files. * * @return void * @see parseValues() */ protected function processFiles($cmdParts, $theField) { // First, make an array with the filename and file reference, whether the file is just uploaded or a preview $filesArr = []; if (is_string($this->dataArr[$theField])) { // files from preview. $tmpArr = explode(',', $this->dataArr[$theField]); foreach ($tmpArr as $val) { $valParts = explode('|', $val); $filesArr[] = ['name' => $valParts[1], 'tmp_name' => PATH_site . 'typo3temp/' . $valParts[0]]; } } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name'])) { // Files from upload foreach ($_FILES['FE'][$this->theTable][$theField]['name'] as $kk => $vv) { if ($vv) { $tmpFile = GeneralUtility::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]); if ($tmpFile) { $this->unlinkTempFiles[] = $tmpFile; $filesArr[] = ['name' => $vv, 'tmp_name' => $tmpFile]; } } } } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField])) { // Files from upload foreach ($_FILES['FE']['name'][$this->theTable][$theField] as $kk => $vv) { if ($vv) { $tmpFile = GeneralUtility::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]); if ($tmpFile) { $this->unlinkTempFiles[] = $tmpFile; $filesArr[] = ['name' => $vv, 'tmp_name' => $tmpFile]; } } } } // Then verify the files in that array; check existence, extension and size $this->dataArr[$theField] = ''; $finalFilesArr = []; if (count($filesArr)) { $extArray = GeneralUtility::trimExplode(';', strtolower($cmdParts[1]), 1); $maxSize = intval($cmdParts[3]); foreach ($filesArr as $infoArr) { $fI = pathinfo($infoArr['name']); if (GeneralUtility::verifyFilenameAgainstDenyPattern($fI['name'])) { if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray)) { $tmpFile = $infoArr['tmp_name']; if (@is_file($tmpFile)) { if (!$maxSize || filesize($tmpFile) < $maxSize * 1024) { $finalFilesArr[] = $infoArr; } elseif ($this->conf['debug']) { debug('Size is beyond ' . $maxSize . ' kb (' . filesize($tmpFile) . ' bytes) and the file cannot be saved.'); } } elseif ($this->conf['debug']) { debug('Surprisingly there was no file for ' . $vv . ' in ' . $tmpFile); } } elseif ($this->conf['debug']) { debug('Extension "' . $fI['extension'] . '" not allowed'); } } elseif ($this->conf['debug']) { debug('Filename matched illegal pattern.'); } } } // Copy the files in the resulting array to the proper positions based on preview/non-preview. $fileNameList = []; $uploadPath = ''; foreach ($finalFilesArr as $infoArr) { if ($this->isPreview()) { // If the form is a preview form (and data is therefore not going into the database...) do this. $this->createFileFuncObj(); $fI = pathinfo($infoArr['name']); $tmpFilename = $this->theTable . '_' . GeneralUtility::shortmd5(uniqid($infoArr['name'])) . '.' . $fI['extension']; $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site . 'typo3temp/'); GeneralUtility::upload_copy_move($infoArr['tmp_name'], $theDestFile); // Setting the filename in the list $fI2 = pathinfo($theDestFile); $fileNameList[] = $fI2['basename'] . '|' . $infoArr['name']; } else { $this->createFileFuncObj(); if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) { $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder']; } if ($uploadPath !== '') { $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site . $uploadPath); GeneralUtility::upload_copy_move($infoArr['tmp_name'], $theDestFile); // Setting the filename in the list $fI2 = pathinfo($theDestFile); $fileNameList[] = $fI2['basename']; $this->filesStoredInUploadFolders[] = $theDestFile; } } // Implode the list of filenames $this->dataArr[$theField] = implode(',', $fileNameList); } }