@@ -18,94 +18,94 @@ |
||
| 18 | 18 | class StreamedFile extends \Fab\Media\FileUpload\UploadedFileAbstract |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $inputName = 'qqfile'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $uploadFolder; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $name; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Save the file to the specified path |
|
| 38 | - * |
|
| 39 | - * @throws EmptyPropertyException |
|
| 40 | - * @return boolean true on success |
|
| 41 | - */ |
|
| 42 | - public function save() |
|
| 43 | - { |
|
| 44 | - |
|
| 45 | - if (is_null($this->uploadFolder)) { |
|
| 46 | - throw new EmptyPropertyException('Upload folder is not defined', 1361787579); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if (is_null($this->name)) { |
|
| 50 | - throw new EmptyPropertyException('File name is not defined', 1361787580); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $input = fopen("php://input", "r"); |
|
| 54 | - $temp = tmpfile(); |
|
| 55 | - $realSize = stream_copy_to_stream($input, $temp); |
|
| 56 | - fclose($input); |
|
| 57 | - |
|
| 58 | - if ($realSize != $this->getSize()) { |
|
| 59 | - return false; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $target = fopen($this->getFileWithAbsolutePath(), "w"); |
|
| 63 | - fseek($temp, 0, SEEK_SET); |
|
| 64 | - stream_copy_to_stream($temp, $target); |
|
| 65 | - fclose($target); |
|
| 66 | - |
|
| 67 | - return true; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Get the original file name. |
|
| 72 | - * |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public function getOriginalName() |
|
| 76 | - { |
|
| 77 | - return $_GET[$this->inputName]; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get the file size |
|
| 82 | - * |
|
| 83 | - * @throws \Exception |
|
| 84 | - * @return integer file-size in byte |
|
| 85 | - */ |
|
| 86 | - public function getSize() |
|
| 87 | - { |
|
| 88 | - if (isset($GLOBALS['_SERVER']['CONTENT_LENGTH'])) { |
|
| 89 | - return (int)$GLOBALS['_SERVER']['CONTENT_LENGTH']; |
|
| 90 | - } else { |
|
| 91 | - throw new \Exception('Getting content length is not supported.'); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Get MIME type of file. |
|
| 97 | - * |
|
| 98 | - * @return string|boolean MIME type. eg, text/html, false on error |
|
| 99 | - */ |
|
| 100 | - public function getMimeType() |
|
| 101 | - { |
|
| 102 | - $this->checkFileExistence(); |
|
| 103 | - if (function_exists('finfo_file')) { |
|
| 104 | - $fileInfo = new \finfo(); |
|
| 105 | - return $fileInfo->file($this->getFileWithAbsolutePath(), FILEINFO_MIME_TYPE); |
|
| 106 | - } elseif (function_exists('mime_content_type')) { |
|
| 107 | - return mime_content_type($this->getFileWithAbsolutePath()); |
|
| 108 | - } |
|
| 109 | - return false; |
|
| 110 | - } |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $inputName = 'qqfile'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $uploadFolder; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $name; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Save the file to the specified path |
|
| 38 | + * |
|
| 39 | + * @throws EmptyPropertyException |
|
| 40 | + * @return boolean true on success |
|
| 41 | + */ |
|
| 42 | + public function save() |
|
| 43 | + { |
|
| 44 | + |
|
| 45 | + if (is_null($this->uploadFolder)) { |
|
| 46 | + throw new EmptyPropertyException('Upload folder is not defined', 1361787579); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if (is_null($this->name)) { |
|
| 50 | + throw new EmptyPropertyException('File name is not defined', 1361787580); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $input = fopen("php://input", "r"); |
|
| 54 | + $temp = tmpfile(); |
|
| 55 | + $realSize = stream_copy_to_stream($input, $temp); |
|
| 56 | + fclose($input); |
|
| 57 | + |
|
| 58 | + if ($realSize != $this->getSize()) { |
|
| 59 | + return false; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $target = fopen($this->getFileWithAbsolutePath(), "w"); |
|
| 63 | + fseek($temp, 0, SEEK_SET); |
|
| 64 | + stream_copy_to_stream($temp, $target); |
|
| 65 | + fclose($target); |
|
| 66 | + |
|
| 67 | + return true; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Get the original file name. |
|
| 72 | + * |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public function getOriginalName() |
|
| 76 | + { |
|
| 77 | + return $_GET[$this->inputName]; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get the file size |
|
| 82 | + * |
|
| 83 | + * @throws \Exception |
|
| 84 | + * @return integer file-size in byte |
|
| 85 | + */ |
|
| 86 | + public function getSize() |
|
| 87 | + { |
|
| 88 | + if (isset($GLOBALS['_SERVER']['CONTENT_LENGTH'])) { |
|
| 89 | + return (int)$GLOBALS['_SERVER']['CONTENT_LENGTH']; |
|
| 90 | + } else { |
|
| 91 | + throw new \Exception('Getting content length is not supported.'); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Get MIME type of file. |
|
| 97 | + * |
|
| 98 | + * @return string|boolean MIME type. eg, text/html, false on error |
|
| 99 | + */ |
|
| 100 | + public function getMimeType() |
|
| 101 | + { |
|
| 102 | + $this->checkFileExistence(); |
|
| 103 | + if (function_exists('finfo_file')) { |
|
| 104 | + $fileInfo = new \finfo(); |
|
| 105 | + return $fileInfo->file($this->getFileWithAbsolutePath(), FILEINFO_MIME_TYPE); |
|
| 106 | + } elseif (function_exists('mime_content_type')) { |
|
| 107 | + return mime_content_type($this->getFileWithAbsolutePath()); |
|
| 108 | + } |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -18,38 +18,38 @@ |
||
| 18 | 18 | class FormResultCompiler extends \TYPO3\CMS\Backend\Form\FormResultCompiler |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * JavaScript bottom code |
|
| 23 | - * |
|
| 24 | - * @param string $formname The identification of the form on the page. |
|
| 25 | - * @return string A section with JavaScript - if $update is false, embedded in <script></script> |
|
| 26 | - */ |
|
| 27 | - protected function JSbottom($formname = 'forms[0]') |
|
| 28 | - { |
|
| 29 | - |
|
| 30 | - $out = parent::JSbottom($formname); |
|
| 31 | - |
|
| 32 | - $enableMediaFilePicker = (bool)$this->getBackendUser()->getTSConfigVal('options.vidi.enableMediaFilePicker'); |
|
| 33 | - if ($enableMediaFilePicker) { |
|
| 34 | - |
|
| 35 | - $pageRenderer = $this->getPageRenderer(); |
|
| 36 | - $pageRenderer->loadRequireJsModule('TYPO3/CMS/Media/MediaFormEngine', 'function(MediaFormEngine) { |
|
| 21 | + /** |
|
| 22 | + * JavaScript bottom code |
|
| 23 | + * |
|
| 24 | + * @param string $formname The identification of the form on the page. |
|
| 25 | + * @return string A section with JavaScript - if $update is false, embedded in <script></script> |
|
| 26 | + */ |
|
| 27 | + protected function JSbottom($formname = 'forms[0]') |
|
| 28 | + { |
|
| 29 | + |
|
| 30 | + $out = parent::JSbottom($formname); |
|
| 31 | + |
|
| 32 | + $enableMediaFilePicker = (bool)$this->getBackendUser()->getTSConfigVal('options.vidi.enableMediaFilePicker'); |
|
| 33 | + if ($enableMediaFilePicker) { |
|
| 34 | + |
|
| 35 | + $pageRenderer = $this->getPageRenderer(); |
|
| 36 | + $pageRenderer->loadRequireJsModule('TYPO3/CMS/Media/MediaFormEngine', 'function(MediaFormEngine) { |
|
| 37 | 37 | MediaFormEngine.vidiModuleUrl = \'' . BackendUtility::getModuleUrl(VidiModule::getSignature()) . '\'; |
| 38 | 38 | MediaFormEngine.vidiModulePrefix = \'' . VidiModule::getParameterPrefix() . '\'; |
| 39 | 39 | MediaFormEngine.browserUrl = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('wizard_element_browser')) . '; |
| 40 | 40 | }'); |
| 41 | - } |
|
| 42 | - |
|
| 43 | - return $out; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Returns an instance of the current Backend User. |
|
| 48 | - * |
|
| 49 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 50 | - */ |
|
| 51 | - protected function getBackendUser() |
|
| 52 | - { |
|
| 53 | - return $GLOBALS['BE_USER']; |
|
| 54 | - } |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + return $out; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Returns an instance of the current Backend User. |
|
| 48 | + * |
|
| 49 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 50 | + */ |
|
| 51 | + protected function getBackendUser() |
|
| 52 | + { |
|
| 53 | + return $GLOBALS['BE_USER']; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -20,45 +20,45 @@ |
||
| 20 | 20 | class DownloadButton extends AbstractComponentView |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Renders a "download" button to be placed in the grid. |
|
| 25 | - * |
|
| 26 | - * @param Content $object |
|
| 27 | - * @return string |
|
| 28 | - * @throws \InvalidArgumentException |
|
| 29 | - */ |
|
| 30 | - public function render(Content $object = null) |
|
| 31 | - { |
|
| 23 | + /** |
|
| 24 | + * Renders a "download" button to be placed in the grid. |
|
| 25 | + * |
|
| 26 | + * @param Content $object |
|
| 27 | + * @return string |
|
| 28 | + * @throws \InvalidArgumentException |
|
| 29 | + */ |
|
| 30 | + public function render(Content $object = null) |
|
| 31 | + { |
|
| 32 | 32 | |
| 33 | - $button = $this->makeLinkButton() |
|
| 34 | - ->setHref($this->getDownloadUri($object)) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - ]) |
|
| 39 | - ->setClasses('btn-download') |
|
| 40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:download')) |
|
| 41 | - ->setIcon($this->getIconFactory()->getIcon('actions-system-extension-download', Icon::SIZE_SMALL)) |
|
| 42 | - ->render(); |
|
| 33 | + $button = $this->makeLinkButton() |
|
| 34 | + ->setHref($this->getDownloadUri($object)) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + ]) |
|
| 39 | + ->setClasses('btn-download') |
|
| 40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:download')) |
|
| 41 | + ->setIcon($this->getIconFactory()->getIcon('actions-system-extension-download', Icon::SIZE_SMALL)) |
|
| 42 | + ->render(); |
|
| 43 | 43 | |
| 44 | - return $button; |
|
| 45 | - } |
|
| 44 | + return $button; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param Content $object |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - protected function getDownloadUri(Content $object) |
|
| 52 | - { |
|
| 53 | - $urlParameters = [ |
|
| 54 | - MediaModule::getParameterPrefix() => [ |
|
| 55 | - 'controller' => 'Asset', |
|
| 56 | - 'action' => 'download', |
|
| 57 | - 'forceDownload' => true, |
|
| 58 | - 'file' => $object->getUid(), |
|
| 59 | - ], |
|
| 60 | - ]; |
|
| 61 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 62 | - } |
|
| 47 | + /** |
|
| 48 | + * @param Content $object |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + protected function getDownloadUri(Content $object) |
|
| 52 | + { |
|
| 53 | + $urlParameters = [ |
|
| 54 | + MediaModule::getParameterPrefix() => [ |
|
| 55 | + 'controller' => 'Asset', |
|
| 56 | + 'action' => 'download', |
|
| 57 | + 'forceDownload' => true, |
|
| 58 | + 'file' => $object->getUid(), |
|
| 59 | + ], |
|
| 60 | + ]; |
|
| 61 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
@@ -20,43 +20,43 @@ |
||
| 20 | 20 | class LinkCreatorButton extends AbstractComponentView |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Renders a "link-creator" button to be placed in the grid. |
|
| 25 | - * |
|
| 26 | - * @param Content $object |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function render(Content $object = null) |
|
| 30 | - { |
|
| 31 | - $button = ''; |
|
| 32 | - if ($this->getModuleLoader()->hasPlugin('linkCreator')) { |
|
| 33 | - $button = $this->makeLinkButton() |
|
| 34 | - ->setHref($this->getLinkCreatorUri($object)) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - ]) |
|
| 39 | - ->setClasses('btn-linkCreator') |
|
| 40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:create_link')) |
|
| 41 | - ->setIcon($this->getIconFactory()->getIcon('apps-pagetree-page-shortcut-external-root', Icon::SIZE_SMALL)) |
|
| 42 | - ->render(); |
|
| 43 | - } |
|
| 44 | - return $button; |
|
| 45 | - } |
|
| 23 | + /** |
|
| 24 | + * Renders a "link-creator" button to be placed in the grid. |
|
| 25 | + * |
|
| 26 | + * @param Content $object |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function render(Content $object = null) |
|
| 30 | + { |
|
| 31 | + $button = ''; |
|
| 32 | + if ($this->getModuleLoader()->hasPlugin('linkCreator')) { |
|
| 33 | + $button = $this->makeLinkButton() |
|
| 34 | + ->setHref($this->getLinkCreatorUri($object)) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + ]) |
|
| 39 | + ->setClasses('btn-linkCreator') |
|
| 40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:create_link')) |
|
| 41 | + ->setIcon($this->getIconFactory()->getIcon('apps-pagetree-page-shortcut-external-root', Icon::SIZE_SMALL)) |
|
| 42 | + ->render(); |
|
| 43 | + } |
|
| 44 | + return $button; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param Content $object |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - protected function getLinkCreatorUri(Content $object) |
|
| 52 | - { |
|
| 53 | - $urlParameters = array( |
|
| 54 | - MediaModule::getParameterPrefix() => array( |
|
| 55 | - 'controller' => 'LinkCreator', |
|
| 56 | - 'action' => 'show', |
|
| 57 | - 'file' => $object->getUid(), |
|
| 58 | - ), |
|
| 59 | - ); |
|
| 60 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 61 | - } |
|
| 47 | + /** |
|
| 48 | + * @param Content $object |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + protected function getLinkCreatorUri(Content $object) |
|
| 52 | + { |
|
| 53 | + $urlParameters = array( |
|
| 54 | + MediaModule::getParameterPrefix() => array( |
|
| 55 | + 'controller' => 'LinkCreator', |
|
| 56 | + 'action' => 'show', |
|
| 57 | + 'file' => $object->getUid(), |
|
| 58 | + ), |
|
| 59 | + ); |
|
| 60 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -20,43 +20,43 @@ |
||
| 20 | 20 | class ImageEditorButton extends AbstractComponentView |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Renders a "image-editor" button to be placed in the grid. |
|
| 25 | - * |
|
| 26 | - * @param Content $object |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function render(Content $object = null) |
|
| 30 | - { |
|
| 31 | - $button = ''; |
|
| 32 | - if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
| 33 | - $button = $this->makeLinkButton() |
|
| 34 | - ->setHref($this->getImageEditorUri($object)) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - ]) |
|
| 39 | - ->setClasses('btn-imageEditor') |
|
| 40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
| 41 | - ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-edit', Icon::SIZE_SMALL)) |
|
| 42 | - ->render(); |
|
| 43 | - } |
|
| 44 | - return $button; |
|
| 45 | - } |
|
| 23 | + /** |
|
| 24 | + * Renders a "image-editor" button to be placed in the grid. |
|
| 25 | + * |
|
| 26 | + * @param Content $object |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function render(Content $object = null) |
|
| 30 | + { |
|
| 31 | + $button = ''; |
|
| 32 | + if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
| 33 | + $button = $this->makeLinkButton() |
|
| 34 | + ->setHref($this->getImageEditorUri($object)) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + ]) |
|
| 39 | + ->setClasses('btn-imageEditor') |
|
| 40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
| 41 | + ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-edit', Icon::SIZE_SMALL)) |
|
| 42 | + ->render(); |
|
| 43 | + } |
|
| 44 | + return $button; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param Content $object |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - protected function getImageEditorUri(Content $object) |
|
| 52 | - { |
|
| 53 | - $urlParameters = array( |
|
| 54 | - MediaModule::getParameterPrefix() => array( |
|
| 55 | - 'controller' => 'ImageEditor', |
|
| 56 | - 'action' => 'show', |
|
| 57 | - 'file' => $object->getUid(), |
|
| 58 | - ), |
|
| 59 | - ); |
|
| 60 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 61 | - } |
|
| 47 | + /** |
|
| 48 | + * @param Content $object |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + protected function getImageEditorUri(Content $object) |
|
| 52 | + { |
|
| 53 | + $urlParameters = array( |
|
| 54 | + MediaModule::getParameterPrefix() => array( |
|
| 55 | + 'controller' => 'ImageEditor', |
|
| 56 | + 'action' => 'show', |
|
| 57 | + 'file' => $object->getUid(), |
|
| 58 | + ), |
|
| 59 | + ); |
|
| 60 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -20,44 +20,44 @@ |
||
| 20 | 20 | class FilePickerButton extends AbstractComponentView |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Renders a "file-picker" button to be placed in the grid. |
|
| 25 | - * |
|
| 26 | - * @param Content $object |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function render(Content $object = null) |
|
| 30 | - { |
|
| 31 | - $button = ''; |
|
| 32 | - if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
| 33 | - $button = $this->makeLinkButton() |
|
| 34 | - ->setHref($this->getFilePickerUri($object)) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - ]) |
|
| 39 | - ->setClasses('btn-filePicker') |
|
| 40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
| 41 | - ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-export', Icon::SIZE_SMALL)) |
|
| 42 | - ->render(); |
|
| 23 | + /** |
|
| 24 | + * Renders a "file-picker" button to be placed in the grid. |
|
| 25 | + * |
|
| 26 | + * @param Content $object |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function render(Content $object = null) |
|
| 30 | + { |
|
| 31 | + $button = ''; |
|
| 32 | + if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
| 33 | + $button = $this->makeLinkButton() |
|
| 34 | + ->setHref($this->getFilePickerUri($object)) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + ]) |
|
| 39 | + ->setClasses('btn-filePicker') |
|
| 40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:edit_image')) |
|
| 41 | + ->setIcon($this->getIconFactory()->getIcon('extensions-media-image-export', Icon::SIZE_SMALL)) |
|
| 42 | + ->render(); |
|
| 43 | 43 | |
| 44 | - } |
|
| 45 | - return $button; |
|
| 46 | - } |
|
| 44 | + } |
|
| 45 | + return $button; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param Content $object |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - protected function getFilePickerUri(Content $object) |
|
| 53 | - { |
|
| 54 | - $urlParameters = array( |
|
| 55 | - MediaModule::getParameterPrefix() => array( |
|
| 56 | - 'controller' => 'Asset', |
|
| 57 | - 'action' => 'download', |
|
| 58 | - 'file' => $object->getUid(), |
|
| 59 | - ), |
|
| 60 | - ); |
|
| 61 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 62 | - } |
|
| 48 | + /** |
|
| 49 | + * @param Content $object |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + protected function getFilePickerUri(Content $object) |
|
| 53 | + { |
|
| 54 | + $urlParameters = array( |
|
| 55 | + MediaModule::getParameterPrefix() => array( |
|
| 56 | + 'controller' => 'Asset', |
|
| 57 | + 'action' => 'download', |
|
| 58 | + 'file' => $object->getUid(), |
|
| 59 | + ), |
|
| 60 | + ); |
|
| 61 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -23,248 +23,248 @@ |
||
| 23 | 23 | class ActionPermissionFacet implements FacetInterface |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $name = '__action_permission'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $suggestions = array( |
|
| 40 | - 'r' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.read_only', |
|
| 41 | - 'w' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.write', |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $fieldNameAndPath = ''; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - protected $dataType; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var bool |
|
| 56 | - */ |
|
| 57 | - protected $canModifyMatcher = false; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Constructor of a Generic Facet in Vidi. |
|
| 61 | - * |
|
| 62 | - * @param string $name |
|
| 63 | - * @param string $label |
|
| 64 | - * @param array $suggestions |
|
| 65 | - * @param string $fieldNameAndPath |
|
| 66 | - */ |
|
| 67 | - public function __construct($name = '', $label = '', array $suggestions = [], $fieldNameAndPath = '') |
|
| 68 | - { |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getName() |
|
| 75 | - { |
|
| 76 | - return $this->name; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getLabel() |
|
| 83 | - { |
|
| 84 | - return $this->getLanguageService()->sL($this->label); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return array |
|
| 89 | - */ |
|
| 90 | - public function getSuggestions() |
|
| 91 | - { |
|
| 92 | - $suggestions = []; |
|
| 93 | - foreach ($this->suggestions as $key => $label) { |
|
| 94 | - $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $suggestions; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - public function hasSuggestions() |
|
| 104 | - { |
|
| 105 | - return true; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $dataType |
|
| 110 | - * @return $this |
|
| 111 | - */ |
|
| 112 | - public function setDataType($dataType) |
|
| 113 | - { |
|
| 114 | - $this->dataType = $dataType; |
|
| 115 | - return $this; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public function canModifyMatcher() |
|
| 122 | - { |
|
| 123 | - return $this->canModifyMatcher; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param Matcher $matcher |
|
| 128 | - * @param $value |
|
| 129 | - * @return Matcher |
|
| 130 | - */ |
|
| 131 | - public function modifyMatcher(Matcher $matcher, $value) |
|
| 132 | - { |
|
| 133 | - return $matcher; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param AfterFindContentObjectsSignalArguments $signalArguments |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function modifyResultSet(AfterFindContentObjectsSignalArguments $signalArguments) |
|
| 141 | - { |
|
| 142 | - |
|
| 143 | - if ($signalArguments->getDataType() === 'sys_file') { |
|
| 144 | - |
|
| 145 | - $queryParts = $this->getQueryParts(); |
|
| 146 | - |
|
| 147 | - if (!empty($queryParts)) { |
|
| 148 | - $permission = $this->getPermissionValue($queryParts); |
|
| 149 | - |
|
| 150 | - if ($permission) { |
|
| 151 | - |
|
| 152 | - // We are force to query the content repository again here without limit |
|
| 153 | - $matcher = $signalArguments->getMatcher(); |
|
| 154 | - $order = $signalArguments->getOrder(); |
|
| 155 | - $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order); |
|
| 156 | - |
|
| 157 | - $filteredObjects = []; |
|
| 158 | - foreach ($objects as $object) { |
|
| 159 | - |
|
| 160 | - $file = $this->getFileConverter()->convert($object->getUid()); |
|
| 161 | - if ($permission === 'read' && !$file->checkActionPermission('write')) { |
|
| 162 | - $filteredObjects[] = $object; |
|
| 163 | - } elseif ($permission === 'write' && $file->checkActionPermission('write')) { |
|
| 164 | - $filteredObjects[] = $object; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Only take part of the array according to offset and limit. |
|
| 169 | - $offset = $signalArguments->getOffset(); |
|
| 170 | - $limit = $signalArguments->getLimit(); |
|
| 171 | - $signalArguments->setContentObjects(array_slice($filteredObjects, $offset, $limit)); |
|
| 172 | - |
|
| 173 | - // Count number of records |
|
| 174 | - $signalArguments->setNumberOfObjects(count($filteredObjects)); |
|
| 175 | - $signalArguments->setHasBeenProcessed(true); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return array($signalArguments); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @return array |
|
| 185 | - */ |
|
| 186 | - protected function getQueryParts() |
|
| 187 | - { |
|
| 188 | - |
|
| 189 | - // Transmit recursive selection parameter. |
|
| 190 | - $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
| 191 | - $parameters = GeneralUtility::_GP($parameterPrefix); |
|
| 192 | - |
|
| 193 | - $queryParts = []; |
|
| 194 | - if (!empty($parameters['searchTerm'])) { |
|
| 195 | - $query = rawurldecode($parameters['searchTerm']); |
|
| 196 | - $queryParts = json_decode($query, true); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $queryParts; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Retrieve the search permission value. |
|
| 204 | - * |
|
| 205 | - * @param array $queryParts |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - protected function getPermissionValue(array $queryParts) |
|
| 209 | - { |
|
| 210 | - $permission = ''; |
|
| 211 | - |
|
| 212 | - // Check also amongst labels. |
|
| 213 | - $labelReadOnly = $this->getLanguageService()->sL($this->suggestions['r']); |
|
| 214 | - $labelWrite = $this->getLanguageService()->sL($this->suggestions['w']); |
|
| 215 | - |
|
| 216 | - foreach ($queryParts as $queryPart) { |
|
| 217 | - $facetName = key($queryPart); |
|
| 218 | - $value = $queryPart[$facetName]; |
|
| 219 | - if ($facetName === $this->name) { |
|
| 220 | - |
|
| 221 | - if ($value === 'r' || $value === $labelReadOnly) { |
|
| 222 | - $permission = 'read'; |
|
| 223 | - } elseif ($value === 'w' || $value === $labelWrite) { |
|
| 224 | - $permission = 'write'; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - return $permission; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Magic method implementation for retrieving state. |
|
| 233 | - * |
|
| 234 | - * @param array $states |
|
| 235 | - * @return $this |
|
| 236 | - */ |
|
| 237 | - static public function __set_state($states) |
|
| 238 | - { |
|
| 239 | - return new ActionPermissionFacet($states['name'], $states['label'], $states['suggestions'], $states['fieldNameAndPath']); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return \TYPO3\CMS\Lang\LanguageService |
|
| 244 | - */ |
|
| 245 | - protected function getLanguageService() |
|
| 246 | - { |
|
| 247 | - return $GLOBALS['LANG']; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @return ContentToFileConverter |
|
| 252 | - * @throws \InvalidArgumentException |
|
| 253 | - */ |
|
| 254 | - protected function getFileConverter() |
|
| 255 | - { |
|
| 256 | - return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Get the Vidi Module Loader. |
|
| 261 | - * |
|
| 262 | - * @return ModuleLoader |
|
| 263 | - * @throws \InvalidArgumentException |
|
| 264 | - */ |
|
| 265 | - protected function getModuleLoader() |
|
| 266 | - { |
|
| 267 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 268 | - } |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $name = '__action_permission'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $suggestions = array( |
|
| 40 | + 'r' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.read_only', |
|
| 41 | + 'w' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.write', |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $fieldNameAndPath = ''; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + protected $dataType; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var bool |
|
| 56 | + */ |
|
| 57 | + protected $canModifyMatcher = false; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Constructor of a Generic Facet in Vidi. |
|
| 61 | + * |
|
| 62 | + * @param string $name |
|
| 63 | + * @param string $label |
|
| 64 | + * @param array $suggestions |
|
| 65 | + * @param string $fieldNameAndPath |
|
| 66 | + */ |
|
| 67 | + public function __construct($name = '', $label = '', array $suggestions = [], $fieldNameAndPath = '') |
|
| 68 | + { |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getName() |
|
| 75 | + { |
|
| 76 | + return $this->name; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getLabel() |
|
| 83 | + { |
|
| 84 | + return $this->getLanguageService()->sL($this->label); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return array |
|
| 89 | + */ |
|
| 90 | + public function getSuggestions() |
|
| 91 | + { |
|
| 92 | + $suggestions = []; |
|
| 93 | + foreach ($this->suggestions as $key => $label) { |
|
| 94 | + $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $suggestions; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + public function hasSuggestions() |
|
| 104 | + { |
|
| 105 | + return true; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $dataType |
|
| 110 | + * @return $this |
|
| 111 | + */ |
|
| 112 | + public function setDataType($dataType) |
|
| 113 | + { |
|
| 114 | + $this->dataType = $dataType; |
|
| 115 | + return $this; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public function canModifyMatcher() |
|
| 122 | + { |
|
| 123 | + return $this->canModifyMatcher; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param Matcher $matcher |
|
| 128 | + * @param $value |
|
| 129 | + * @return Matcher |
|
| 130 | + */ |
|
| 131 | + public function modifyMatcher(Matcher $matcher, $value) |
|
| 132 | + { |
|
| 133 | + return $matcher; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param AfterFindContentObjectsSignalArguments $signalArguments |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function modifyResultSet(AfterFindContentObjectsSignalArguments $signalArguments) |
|
| 141 | + { |
|
| 142 | + |
|
| 143 | + if ($signalArguments->getDataType() === 'sys_file') { |
|
| 144 | + |
|
| 145 | + $queryParts = $this->getQueryParts(); |
|
| 146 | + |
|
| 147 | + if (!empty($queryParts)) { |
|
| 148 | + $permission = $this->getPermissionValue($queryParts); |
|
| 149 | + |
|
| 150 | + if ($permission) { |
|
| 151 | + |
|
| 152 | + // We are force to query the content repository again here without limit |
|
| 153 | + $matcher = $signalArguments->getMatcher(); |
|
| 154 | + $order = $signalArguments->getOrder(); |
|
| 155 | + $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order); |
|
| 156 | + |
|
| 157 | + $filteredObjects = []; |
|
| 158 | + foreach ($objects as $object) { |
|
| 159 | + |
|
| 160 | + $file = $this->getFileConverter()->convert($object->getUid()); |
|
| 161 | + if ($permission === 'read' && !$file->checkActionPermission('write')) { |
|
| 162 | + $filteredObjects[] = $object; |
|
| 163 | + } elseif ($permission === 'write' && $file->checkActionPermission('write')) { |
|
| 164 | + $filteredObjects[] = $object; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Only take part of the array according to offset and limit. |
|
| 169 | + $offset = $signalArguments->getOffset(); |
|
| 170 | + $limit = $signalArguments->getLimit(); |
|
| 171 | + $signalArguments->setContentObjects(array_slice($filteredObjects, $offset, $limit)); |
|
| 172 | + |
|
| 173 | + // Count number of records |
|
| 174 | + $signalArguments->setNumberOfObjects(count($filteredObjects)); |
|
| 175 | + $signalArguments->setHasBeenProcessed(true); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return array($signalArguments); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @return array |
|
| 185 | + */ |
|
| 186 | + protected function getQueryParts() |
|
| 187 | + { |
|
| 188 | + |
|
| 189 | + // Transmit recursive selection parameter. |
|
| 190 | + $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
| 191 | + $parameters = GeneralUtility::_GP($parameterPrefix); |
|
| 192 | + |
|
| 193 | + $queryParts = []; |
|
| 194 | + if (!empty($parameters['searchTerm'])) { |
|
| 195 | + $query = rawurldecode($parameters['searchTerm']); |
|
| 196 | + $queryParts = json_decode($query, true); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $queryParts; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Retrieve the search permission value. |
|
| 204 | + * |
|
| 205 | + * @param array $queryParts |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + protected function getPermissionValue(array $queryParts) |
|
| 209 | + { |
|
| 210 | + $permission = ''; |
|
| 211 | + |
|
| 212 | + // Check also amongst labels. |
|
| 213 | + $labelReadOnly = $this->getLanguageService()->sL($this->suggestions['r']); |
|
| 214 | + $labelWrite = $this->getLanguageService()->sL($this->suggestions['w']); |
|
| 215 | + |
|
| 216 | + foreach ($queryParts as $queryPart) { |
|
| 217 | + $facetName = key($queryPart); |
|
| 218 | + $value = $queryPart[$facetName]; |
|
| 219 | + if ($facetName === $this->name) { |
|
| 220 | + |
|
| 221 | + if ($value === 'r' || $value === $labelReadOnly) { |
|
| 222 | + $permission = 'read'; |
|
| 223 | + } elseif ($value === 'w' || $value === $labelWrite) { |
|
| 224 | + $permission = 'write'; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + return $permission; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Magic method implementation for retrieving state. |
|
| 233 | + * |
|
| 234 | + * @param array $states |
|
| 235 | + * @return $this |
|
| 236 | + */ |
|
| 237 | + static public function __set_state($states) |
|
| 238 | + { |
|
| 239 | + return new ActionPermissionFacet($states['name'], $states['label'], $states['suggestions'], $states['fieldNameAndPath']); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return \TYPO3\CMS\Lang\LanguageService |
|
| 244 | + */ |
|
| 245 | + protected function getLanguageService() |
|
| 246 | + { |
|
| 247 | + return $GLOBALS['LANG']; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @return ContentToFileConverter |
|
| 252 | + * @throws \InvalidArgumentException |
|
| 253 | + */ |
|
| 254 | + protected function getFileConverter() |
|
| 255 | + { |
|
| 256 | + return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Get the Vidi Module Loader. |
|
| 261 | + * |
|
| 262 | + * @return ModuleLoader |
|
| 263 | + * @throws \InvalidArgumentException |
|
| 264 | + */ |
|
| 265 | + protected function getModuleLoader() |
|
| 266 | + { |
|
| 267 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | } |
@@ -19,45 +19,45 @@ |
||
| 19 | 19 | class ProcessedFileController extends ActionController |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Initializes the controller before invoking an action method. |
|
| 24 | - */ |
|
| 25 | - public function initializeAction() |
|
| 26 | - { |
|
| 27 | - |
|
| 28 | - // Configure property mapping to retrieve the file object. |
|
| 29 | - if ($this->arguments->hasArgument('file')) { |
|
| 30 | - |
|
| 31 | - /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
| 32 | - $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
| 33 | - |
|
| 34 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
| 35 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Create a processed file according to some configuration. |
|
| 41 | - * |
|
| 42 | - * @param File $file |
|
| 43 | - * @param array $processingConfiguration |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public function createAction(File $file, array $processingConfiguration = []) |
|
| 47 | - { |
|
| 48 | - $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); |
|
| 49 | - |
|
| 50 | - $response = array( |
|
| 51 | - 'success' => true, |
|
| 52 | - 'original' => $file->getUid(), |
|
| 53 | - 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), |
|
| 54 | - 'publicUrl' => $processedFile->getPublicUrl(), |
|
| 55 | - 'width' => $processedFile->getProperty('width'), |
|
| 56 | - 'height' => $processedFile->getProperty('height'), |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - header("Content-Type: text/json"); |
|
| 60 | - return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
| 61 | - } |
|
| 22 | + /** |
|
| 23 | + * Initializes the controller before invoking an action method. |
|
| 24 | + */ |
|
| 25 | + public function initializeAction() |
|
| 26 | + { |
|
| 27 | + |
|
| 28 | + // Configure property mapping to retrieve the file object. |
|
| 29 | + if ($this->arguments->hasArgument('file')) { |
|
| 30 | + |
|
| 31 | + /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
| 32 | + $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
| 33 | + |
|
| 34 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
| 35 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Create a processed file according to some configuration. |
|
| 41 | + * |
|
| 42 | + * @param File $file |
|
| 43 | + * @param array $processingConfiguration |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public function createAction(File $file, array $processingConfiguration = []) |
|
| 47 | + { |
|
| 48 | + $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); |
|
| 49 | + |
|
| 50 | + $response = array( |
|
| 51 | + 'success' => true, |
|
| 52 | + 'original' => $file->getUid(), |
|
| 53 | + 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), |
|
| 54 | + 'publicUrl' => $processedFile->getPublicUrl(), |
|
| 55 | + 'width' => $processedFile->getProperty('width'), |
|
| 56 | + 'height' => $processedFile->getProperty('height'), |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + header("Content-Type: text/json"); |
|
| 60 | + return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | } |
@@ -18,15 +18,15 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Renders a button for uploading assets. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - $parameterPrefix = MediaModule::getParameterPrefix(); |
|
| 29 | - $output = " |
|
| 21 | + /** |
|
| 22 | + * Renders a button for uploading assets. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + $parameterPrefix = MediaModule::getParameterPrefix(); |
|
| 29 | + $output = " |
|
| 30 | 30 | <script> |
| 31 | 31 | |
| 32 | 32 | window.Media = window.Media || {}; |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | </script>"; |
| 36 | 36 | |
| 37 | - return $output; |
|
| 38 | - } |
|
| 37 | + return $output; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | } |