[BUGFIX] Outside storages can never be marked as public 24/28224/3
authorFabien Udriot <fabien.udriot@ecodev.ch>
Mon, 10 Mar 2014 14:23:50 +0000 (15:23 +0100)
committerFrans Saris <franssaris@gmail.com>
Wed, 12 Mar 2014 11:45:20 +0000 (12:45 +0100)
There are some edge cases where "is_public"
can never be true within a storage record in the BE,
for instance for storage located outside
the document root or for storage driven by special driver
such as Flickr, ...

Change-Id: Id7ce8006f182c98d7a908c2e6c49e0c66a7c9da4
Releases: 6.2
Resolves: #56730
Reviewed-on: https://review.typo3.org/28224
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
Reviewed-by: Frans Saris
Tested-by: Frans Saris
typo3/sysext/core/Classes/Resource/Service/UserStorageCapabilityService.php [new file with mode: 0644]
typo3/sysext/core/Configuration/TCA/sys_file_storage.php
typo3/sysext/lang/locallang_core.xlf
typo3/sysext/lang/locallang_tca.xlf

diff --git a/typo3/sysext/core/Classes/Resource/Service/UserStorageCapabilityService.php b/typo3/sysext/core/Classes/Resource/Service/UserStorageCapabilityService.php
new file mode 100644 (file)
index 0000000..963ff1d
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+namespace TYPO3\CMS\Core\Resource\Service;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Fabien Udriot <fabien.udriot@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the text file GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use \TYPO3\CMS\Core\Resource\ResourceFactory;
+
+/**
+ * Utility class to render capabilities of the storage.
+ */
+class UserStorageCapabilityService {
+
+       /**
+        * UserFunc function for rendering field "is_public".
+        * There are some edge cases where "is_public" can never be marked as true in the BE,
+        * for instance for storage located outside the document root or
+        * for storages driven by special driver such as Flickr, ...
+        *
+        * @param array $propertyArray the array with additional configuration options.
+        * @param \TYPO3\CMS\Backend\Form\FormEngine $tceformsObj the TCEforms parent object
+        * @return string
+        */
+       public function renderIsPublic(array $propertyArray, \TYPO3\CMS\Backend\Form\FormEngine $tceformsObj) {
+
+               $isPublic = $GLOBALS['TCA']['sys_file_storage']['columns']['is_public']['config']['default'];
+               $fileRecord = $propertyArray['row'];
+
+               // Makes sure the storage object can be retrieved which is not the case when new storage.
+               if ((int)$propertyArray['row']['uid'] > 0) {
+                       $storage = ResourceFactory::getInstance()->getStorageObject($fileRecord['uid']);
+                       $storageRecord = $storage->getStorageRecord();
+                       $isPublic = $storage->isPublic();
+
+                       // Display a warning to the BE User in case settings is not inline with storage capability.
+                       if ($storageRecord['is_public'] != $storage->isPublic()) {
+                               $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.message.storage_is_no_public'),
+                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.header.storage_is_no_public'),
+                                       \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
+                               );
+
+                               \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
+                       }
+               }
+
+               return $this->renderFileInformationContent($fileRecord, $isPublic);
+       }
+
+       /**
+        * Renders a HTML block containing the checkbox for field "is_public".
+        *
+        * @param array $fileRecord
+        * @param bool $isPublic
+        * @return string
+        */
+       protected function renderFileInformationContent(array $fileRecord, $isPublic) {
+               $template = '
+               <div class="t3-form-field-item">
+                       <input name="data[sys_file_storage][{uid}][is_public]" value="0" type="hidden">
+                       <input class="checkbox" value="1" name="data[sys_file_storage][{uid}][is_public]_0" type="checkbox" %s>
+               </div>';
+
+               $content = sprintf($template,
+                       $isPublic ? 'checked="checked"' : ''
+               );
+
+               return str_replace('{uid}', $fileRecord['uid'], $content);
+       }
+
+}
index 092eec4..9db74bc 100644 (file)
@@ -72,8 +72,9 @@ return array(
                        'exclude' => 0,
                        'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_file_storage.is_public',
                        'config' => array(
-                               'type' => 'check',
-                               'default' => 1
+                               'default' => TRUE,
+                               'type' => 'user',
+                               'userFunc' => 'typo3/sysext/core/Classes/Resource/Service/UserStorageCapabilityService.php:TYPO3\CMS\Core\Resource\Service\UserStorageCapabilityService->renderIsPublic',
                        )
                ),
                'is_writable' => array(
index ede6172..9837677 100644 (file)
@@ -931,6 +931,12 @@ Would you like to save now in order to refresh the display?</source>
                        <trans-unit id="warning.file_missing_text" xml:space="preserve">
                                <source>This file is marked as missing:</source>
                        </trans-unit>
+                       <trans-unit id="warning.header.storage_is_no_public" xml:space="preserve">
+                               <source>Storage is not public</source>
+                       </trans-unit>
+                       <trans-unit id="warning.message.storage_is_no_public" xml:space="preserve">
+                               <source>The storage has been marked to be "publicly available" but is not detected as such by the driver. The setting has been reverted.</source>
+                       </trans-unit>
                        <trans-unit id="error.formProtection.tokenInvalid" xml:space="preserve">
                                <source>Validating the security token of this form has failed. Please reload the form and submit it again.</source>
                        </trans-unit>
index 5718ffe..5f24e46 100644 (file)
                                <source>Is browsable?</source>
                        </trans-unit>
                        <trans-unit id="sys_file_storage.is_public" xml:space="preserve">
-                               <source>Is publically available?</source>
+                               <source>Is publicly available?</source>
                        </trans-unit>
                        <trans-unit id="sys_file_storage.is_writable" xml:space="preserve">
                                <source>Is writable?</source>