/** * Save the current value * * @param mixed $varValue * * @throws \Exception */ protected function save($varValue) { if (\Input::post('FORM_SUBMIT') != $this->strTable) { return; } $arrData = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]; // File names if ($this->strField == 'name') { if (!file_exists(TL_ROOT . '/' . $this->strPath . '/' . $this->varValue . $this->strExtension) || !$this->isMounted($this->strPath . '/' . $this->varValue . $this->strExtension) || $this->varValue === $varValue) { return; } $this->import('Files'); $varValue = utf8_romanize($varValue); // Trigger the save_callback if (is_array($arrData['save_callback'])) { foreach ($arrData['save_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $this); } elseif (is_callable($callback)) { $varValue = $callback($varValue, $this); } } } // The target exists if (strcasecmp($this->strPath . '/' . $this->varValue . $this->strExtension, $this->strPath . '/' . $varValue . $this->strExtension) !== 0 && file_exists(TL_ROOT . '/' . $this->strPath . '/' . $varValue . $this->strExtension)) { throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['fileExists'], $varValue)); } $arrImageTypes = trimsplit(',', strtolower(\Config::get('validImageTypes'))); // Remove potentially existing thumbnails (see #6641) if (in_array(substr($this->strExtension, 1), $arrImageTypes)) { foreach (glob(TL_ROOT . '/assets/images/*/' . $this->varValue . '-*' . $this->strExtension) as $strThumbnail) { $this->Files->delete(str_replace(TL_ROOT . '/', '', $strThumbnail)); } } // Rename the file $this->Files->rename($this->strPath . '/' . $this->varValue . $this->strExtension, $this->strPath . '/' . $varValue . $this->strExtension); // New folders if (stristr($this->intId, '__new__') !== false) { // Update the database if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->strPath . '/' . $varValue . $this->strExtension)) { $this->objActiveRecord = \Dbafs::addResource($this->strPath . '/' . $varValue . $this->strExtension); } $this->log('Folder "' . $this->strPath . '/' . $varValue . $this->strExtension . '" has been created', __METHOD__, TL_FILES); } else { // Update the database if ($this->blnIsDbAssisted) { $syncSource = \Dbafs::shouldBeSynchronized($this->strPath . '/' . $this->varValue . $this->strExtension); $syncTarget = \Dbafs::shouldBeSynchronized($this->strPath . '/' . $varValue . $this->strExtension); if ($syncSource && $syncTarget) { \Dbafs::moveResource($this->strPath . '/' . $this->varValue . $this->strExtension, $this->strPath . '/' . $varValue . $this->strExtension); } elseif ($syncSource) { \Dbafs::deleteResource($this->strPath . '/' . $this->varValue . $this->strExtension); } elseif ($syncTarget) { \Dbafs::addResource($this->strPath . '/' . $varValue . $this->strExtension); } } $this->log('File or folder "' . $this->strPath . '/' . $this->varValue . $this->strExtension . '" has been renamed to "' . $this->strPath . '/' . $varValue . $this->strExtension . '"', __METHOD__, TL_FILES); } // Set the new value so the input field can show it if (\Input::get('act') == 'editAll') { $session = $this->Session->getData(); if (($index = array_search($this->strPath . '/' . $this->varValue . $this->strExtension, $session['CURRENT']['IDS'])) !== false) { $session['CURRENT']['IDS'][$index] = $this->strPath . '/' . $varValue . $this->strExtension; $this->Session->setData($session); } } $this->varValue = $varValue; } elseif ($this->blnIsDbAssisted && $this->objActiveRecord !== null) { // Convert date formats into timestamps if ($varValue != '' && in_array($arrData['eval']['rgxp'], array('date', 'time', 'datim'))) { $objDate = new \Date($varValue, \Date::getFormatFromRgxp($arrData['eval']['rgxp'])); $varValue = $objDate->tstamp; } // Make sure unique fields are unique if ($arrData['eval']['unique'] && $varValue != '' && !$this->Database->isUniqueValue($this->strTable, $this->strField, $varValue, $this->objActiveRecord->id)) { throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrData['label'][0] ?: $this->strField)); } // Handle multi-select fields in "override all" mode if (\Input::get('act') == 'overrideAll' && ($arrData['inputType'] == 'checkbox' || $arrData['inputType'] == 'checkboxWizard') && $arrData['eval']['multiple']) { if ($this->objActiveRecord !== null) { $new = deserialize($varValue, true); $old = deserialize($this->objActiveRecord->{$this->strField}, true); switch (\Input::post($this->strInputName . '_update')) { case 'add': $varValue = array_values(array_unique(array_merge($old, $new))); break; case 'remove': $varValue = array_values(array_diff($old, $new)); break; case 'replace': $varValue = $new; break; } if (!is_array($varValue) || empty($varValue)) { $varValue = ''; } elseif (isset($arrData['eval']['csv'])) { $varValue = implode($arrData['eval']['csv'], $varValue); // see #2890 } else { $varValue = serialize($varValue); } } } // Convert arrays (see #2890) if ($arrData['eval']['multiple'] && isset($arrData['eval']['csv'])) { $varValue = implode($arrData['eval']['csv'], deserialize($varValue, true)); } // Trigger the save_callback if (is_array($arrData['save_callback'])) { foreach ($arrData['save_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $this); } elseif (is_callable($callback)) { $varValue = $callback($varValue, $this); } } } // Save the value if there was no error if (($varValue != '' || !$arrData['eval']['doNotSaveEmpty']) && ($this->varValue != $varValue || $arrData['eval']['alwaysSave'])) { // If the field is a fallback field, empty all other columns if ($arrData['eval']['fallback'] && $varValue != '') { $this->Database->execute("UPDATE " . $this->strTable . " SET " . $this->strField . "=''"); } // Set the correct empty value (see #6284, #6373) if ($varValue === '') { $varValue = \Widget::getEmptyValueByFieldType($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['sql']); } $this->objActiveRecord->{$this->strField} = $varValue; $this->objActiveRecord->save(); $this->blnCreateNewVersion = true; $this->varValue = deserialize($varValue); } } }
public function moveAppend(&$arrSubmittedArray, $arrLabelsArray, $objForm, $arrFields = array()) { file_put_contents('uploadlog.txt', 'Die Funktion wurde aufgerufen'); $this->import('Database'); $_POST[myid] = ''; $_GET[myid] = ''; $files = $this->Input->get('attachfiles'); if ($files == "") { $files = $this->Input->post('attachfiles'); } // get JSON-data if ($files != "") { foreach ($files as $file) { $tmp = split('"elemID"', $file); $file = '{"elemID"' . $tmp[1]; //file_put_contents('check.txt',$file."\n", FILE_APPEND ); if ($obj = json_decode($file)) { $myElem = $obj->elemID; $addToFile = $obj->addToFile; // get uploadFolder $myElemData = $this->Database->prepare("SELECT * FROM tl_form_field WHERE id = " . $myElem)->execute(); $uploadFolder = ''; if ($myElemData->next()) { $tmpFolder = $myElemData->multiuploadFolder; $objUploadFolder = \FilesModel::findByUuid($tmpFolder); $uploadFolder = $objUploadFolder->path; } $uploaded = $obj->files; // Array foreach ($uploaded as $curFile) { if (file_exists(TL_ROOT . '/' . $uploadFolder . '/tmp/' . $addToFile . '/' . $curFile)) { // move files if (!file_exists(TL_ROOT . '/' . $uploadFolder . '/' . $addToFile) && $myElemData->storecase != 'file') { new \Folder($uploadFolder . '/' . $addToFile); \Dbafs::addResource($uploadFolder . '/' . $addToFile); } // use ID as folder or file prename if ($myElemData->storecase == 'file') { $storeFolderPreFile = $addToFile . '_'; } else { $storeFolderPreFile = $addToFile . '/'; } if (copy(TL_ROOT . '/' . $uploadFolder . '/tmp/' . $addToFile . '/' . $curFile, TL_ROOT . '/' . $uploadFolder . '/' . $storeFolderPreFile . $curFile)) { \Dbafs::addResource($uploadFolder . '/' . $storeFolderPreFile . $curFile); @unlink(TL_ROOT . '/' . $uploadFolder . '/tmp/' . $addToFile . '/' . $curFile); \Dbafs::deleteResource($uploadFolder . '/tmp/' . $addToFile . '/' . $curFile); if (in_array($myElemData->sendcase, array('attach', 'all'))) { // Dateien der Mail anhaengen $_SESSION['FILES'][$curFile] = array('name' => $curFile, 'type' => 'file', 'tmp_name' => TL_ROOT . '/' . $uploadFolder . '/' . $storeFolderPreFile . $curFile, 'uploaded' => false); } if (in_array($myElemData->sendcase, array('link', 'all'))) { // Dateien per Link einbinden if (file_exists(TL_ROOT . '/' . $uploadFolder . '/' . $storeFolderPreFile . $curFile)) { $subfolder = str_replace(array('/', '\\'), '', $GLOBALS['TL_CONFIG']['websitePath']); if ($subfolder != '') { $subfolder .= '/'; } $arrSubmittedArray[$myElemData->name] .= "\nhttp://" . $_SERVER['SERVER_NAME'] . '/' . $subfolder . $uploadFolder . '/' . $storeFolderPreFile . $curFile; } } if ($myElemData->sendcase == 'attach') { // Datei-Verlinkung loeschen unset($arrSubmittedArray[$myElemData->name]); unset($arrLabelsArray[$myElemData->name]); } } } } } } //\Dbafs::syncFiles(); } }
/** * Recursively delete files and folders * * @param string $source */ public function delete($source = null) { if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notDeletable']) { $this->log('Table "' . $this->strTable . '" is not deletable', __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } $blnDoNotRedirect = $source !== null; if ($source === null) { $source = $this->intId; } $this->isValid($source); // Delete the file or folder if (!file_exists(TL_ROOT . '/' . $source) || !$this->isMounted($source)) { $this->log('File or folder "' . $source . '" was not mounted or could not be found', __METHOD__, TL_ERROR); $this->redirect('contao/main.php?act=error'); } // Call the ondelete_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['ondelete_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['ondelete_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($source, $this); } elseif (is_callable($callback)) { $callback($source, $this); } } } $this->import('Files'); // Delete the folder or file if (is_dir(TL_ROOT . '/' . $source)) { $this->Files->rrdir($source); } else { $this->Files->delete($source); } // Update the database AFTER the resource has been deleted if ($this->blnIsDbAssisted) { \Dbafs::deleteResource($source); } // Add a log entry $this->log('File or folder "' . str_replace(TL_ROOT . '/', '', $source) . '" has been deleted', __METHOD__, TL_FILES); // Redirect if (!$blnDoNotRedirect) { $this->redirect($this->getReferer()); } }
/** * Delete the folder */ public function delete() { $this->Files->rrdir($this->strFolder); // Update the database if ($this->blnSyncDb) { \Dbafs::deleteResource($this->strFolder); } }
/** * Delete files based on a file list. * * @CtoCommunication Enable * * @param array $arrFileList List with files for deleting. * * @param boolean $blnIsDbafs Flag if we have to change the dbafs system. * * @return array The list with some more information about the deleted file. */ public function deleteFiles($arrFileList, $blnIsDbafs) { if (count($arrFileList) != 0) { // Run each entry in the list.. foreach ($arrFileList as $key => $value) { // Clean up the path. $strPath = $this->objSyncCtoHelper->standardizePath($value['path']); $strFullPath = $this->objSyncCtoHelper->getFullPath($strPath); try { if (!file_exists($strFullPath)) { $arrFileList[$key]['transmission'] = SyncCtoEnum::FILETRANS_SEND; // Remove from dbafs. if ($blnIsDbafs) { \Dbafs::deleteResource($strPath); } } elseif (is_file($strFullPath)) { // Delete the file. if ($this->objFiles->delete($strPath)) { $arrFileList[$key]['transmission'] = SyncCtoEnum::FILETRANS_SEND; // Remove from dbafs. if ($blnIsDbafs) { \Dbafs::deleteResource($strPath); } } else { $arrFileList[$key]['transmission'] = SyncCtoEnum::FILETRANS_SKIPPED; $arrFileList[$key]['error'] = $GLOBALS['TL_LANG']['ERR']['cant_delete_file']; $arrFileList[$key]['skipreason'] = $GLOBALS['TL_LANG']['ERR']['cant_delete_file']; } } elseif (is_dir($strFullPath)) { $this->objFiles->rrdir($strPath); $arrFileList[$key]['transmission'] = SyncCtoEnum::FILETRANS_SEND; // Remove from dbafs. if ($blnIsDbafs) { \Dbafs::deleteResource($strPath); } } } catch (Exception $exc) { $arrFileList[$key]['transmission'] = SyncCtoEnum::FILETRANS_SKIPPED; $arrFileList[$key]['error'] = sprintf('Can not delete file - %s. Exception message: %s', $strPath, $exc->getMessage()); $arrFileList[$key]['skipreason'] = $GLOBALS['TL_LANG']['ERR']['cant_delete_file']; } } } return $arrFileList; }
/** * Rename the folder * * @param string $strNewName The new path * * @return boolean True if the operation was successful */ public function renameTo($strNewName) { $strParent = dirname($strNewName); // Create the parent folder if it does not exist if (!is_dir(TL_ROOT . '/' . $strParent)) { new \Folder($strParent); } $return = $this->Files->rename($this->strFolder, $strNewName); // Update the database AFTER the folder has been renamed $syncSource = \Dbafs::shouldBeSynchronized($this->strFolder); $syncTarget = \Dbafs::shouldBeSynchronized($strNewName); // Synchronize the database if ($syncSource && $syncTarget) { $this->objModel = \Dbafs::moveResource($this->strFolder, $strNewName); } elseif ($syncSource) { $this->objModel = \Dbafs::deleteResource($this->strFolder); } elseif ($syncTarget) { $this->objModel = \Dbafs::addResource($strNewName); } // Reset the object AFTER the database has been updated if ($return != false) { $this->strFolder = $strNewName; } return $return; }
/** * {@inheritDoc} */ public function deleteDir($pathOrUuid) { $path = $this->convertToPath($pathOrUuid); $this->guardNoInvalidUuid($pathOrUuid, $path); $this->guardInUploadPath($path); if ($this->adapter->deleteDir($path)) { \Dbafs::deleteResource($path); return true; } return false; }
/** * Delete the file * * @return boolean True if the operation was successful */ public function delete() { $return = $this->Files->delete($this->strFile); // Update the database if ($this->blnSyncDb) { \Dbafs::deleteResource($this->strFile); } return $return; }