17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
41 public function createAction(ServerRequestInterface $request): ResponseInterface
43 $url = $request->getParsedBody()[
'url'];
44 $targetFolderIdentifier = $request->getParsedBody()[
'targetFolder'];
45 $allowedExtensions = GeneralUtility::trimExplode(
',', $request->getParsedBody()[
'allowed'] ?:
'');
49 $file = $this->
addMediaFromUrl($url, $targetFolderIdentifier, $allowedExtensions);
51 $data[
'file'] = $file->getUid();
53 $data[
'error'] = $this->
getLanguageService()->
sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.error.invalid_url');
67 public function mainAction(ServerRequestInterface $request): ResponseInterface
69 $files = $request->getParsedBody()[
'data'];
70 $redirect = $request->getParsedBody()[
'redirect'];
72 if (isset($files[
'newMedia'])) {
73 $newMedia = (array)$files[
'newMedia'];
76 foreach ($newMedia as $media) {
77 if (!empty($media[
'url']) && !empty($media[
'target'])) {
78 $allowed = !empty($media[
'allowed']) ? GeneralUtility::trimExplode(
',', $media[
'allowed']) : [];
81 $flashMessage = GeneralUtility::makeInstance(
84 $this->getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.new_media.added'),
89 $flashMessage = GeneralUtility::makeInstance(
91 $this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.error.invalid_url'),
92 $this->
getLanguageService()->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:online_media.error.new_media.failed'),
98 if (empty($redirect) && $media[
'redirect']) {
99 $redirect = $media[
'redirect'];
104 $redirect = GeneralUtility::sanitizeLocalUrl($redirect);
109 throw new \RuntimeException(
'No redirect after uploading a media found, probably a mis-use of the template not sending the proper Return URL.', 1511945040);
118 protected function addMediaFromUrl($url, $targetFolderIdentifier, array $allowedExtensions = [])
120 $targetFolder =
null;
121 if ($targetFolderIdentifier) {
125 $targetFolder =
null;
128 if ($targetFolder ===
null) {
142 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
145 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
146 $defaultFlashMessageQueue->enqueue($flashMessage);