[TASK] TS Parser: Remove resolving of resources and filenames 30/27130/7
authorBenjamin Mack <benni@typo3.org>
Mon, 8 Sep 2014 21:55:29 +0000 (23:55 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Wed, 10 Sep 2014 07:59:52 +0000 (09:59 +0200)
The functionality for using direct resources with TypoScript
templates was removed with TYPO3 CMS 6.1. However
the code still supports the resources, also the resolving
of the resources and files within tslib/media - a directory
which does not even exist anymore.
The patch removes all functionality in the core.

Resolves: #55442
Releases: 6.3
Change-Id: Idc3f4585a2ed59a5814ec9629c0a1f256da69b91
Reviewed-on: http://review.typo3.org/27130
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/t3editor/Classes/CodeCompletion.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php

index 0d0b27f..ea379fd 100644 (file)
@@ -134,11 +134,6 @@ class ExtendedTemplateService extends \TYPO3\CMS\Core\TypoScript\TemplateService
        /**
         * @todo Define visibility
         */
-       public $resourceCheck = 0;
-
-       /**
-        * @todo Define visibility
-        */
        public $ext_lineNumberOffset = 0;
 
        /**
@@ -208,39 +203,7 @@ class ExtendedTemplateService extends \TYPO3\CMS\Core\TypoScript\TemplateService
         */
        protected $lnToScript = NULL;
 
-       /**
-        * This flattens a hierarchical setuparray to $this->flatSetup
-        * The original function fetched the resource-file if any ('file.'). This functions doesn't.
-        *
-        * @param       [type]          $setupArray: ...
-        * @param       [type]          $prefix: ...
-        * @param       [type]          $resourceFlag: ...
-        * @return      [type]          ...
-        * @todo Define visibility
-        */
-       public function flattenSetup($setupArray, $prefix, $resourceFlag) {
-               if (is_array($setupArray)) {
-                       // Setting absolute prefixed path for relative resources.
-                       $this->getFileName_backPath = PATH_site;
-                       foreach ($setupArray as $key => $val) {
-                               // We don't want 'TSConstantEditor' in the flattend setup.
-                               if ($prefix || substr($key, 0, 16) != 'TSConstantEditor') {
-                                       if (is_array($val)) {
-                                               $this->flattenSetup($val, $prefix . $key, $key == 'file.');
-                                       } elseif ($resourceFlag && $this->resourceCheck) {
-                                               $this->flatSetup[$prefix . $key] = $this->getFileName($val);
-                                               if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix . $key], 0, strlen($this->removeFromGetFilePath)) == $this->removeFromGetFilePath) {
-                                                       $this->flatSetup[$prefix . $key] = substr($this->flatSetup[$prefix . $key], strlen($this->removeFromGetFilePath));
-                                               }
-                                       } else {
-                                               $this->flatSetup[$prefix . $key] = $val;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       /**
+       /*
         * [Describe function...]
         *
         * @param       [type]          $all: ...
index ae88d1a..b1acc13 100644 (file)
@@ -57,12 +57,6 @@ class TemplateService {
         */
        public $backend_info = 0;
 
-       // Set from the backend - used to set an absolute path (PATH_site) so that relative resources are properly found with getFileName()
-       /**
-        * @todo Define visibility
-        */
-       public $getFileName_backPath = '';
-
        // Externally set breakpoints (used by Backend Modules)
        /**
         * @todo Define visibility
@@ -331,7 +325,6 @@ class TemplateService {
                $this->whereClause .= 'AND (starttime<=' . $GLOBALS['SIM_ACCESS_TIME'] . ') AND (endtime=0 OR endtime>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
                // Sets the paths from where TypoScript resources are allowed to be used:
                $this->allowedPaths = array(
-                       'media/',
                        $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'],
                        // fileadmin/ path
                        'uploads/',
@@ -1076,20 +1069,17 @@ class TemplateService {
         *
         * @param array $setupArray TypoScript array
         * @param string $prefix Prefix to the object path. Used for recursive calls to this function.
-        * @param boolean $resourceFlag If set, then the constant value will be resolved as a TypoScript "resource" data type. Also used internally during recursive calls so that all subproperties for properties named "file." will be resolved as resources.
         * @return void
         * @see generateConfig()
         * @todo Define visibility
         */
-       public function flattenSetup($setupArray, $prefix, $resourceFlag) {
+       public function flattenSetup($setupArray, $prefix) {
                if (is_array($setupArray)) {
                        foreach ($setupArray as $key => $val) {
                                if ($prefix || substr($key, 0, 16) != 'TSConstantEditor') {
                                        // We don't want 'TSConstantEditor' in the flattend setup on the first level (190201)
                                        if (is_array($val)) {
-                                               $this->flattenSetup($val, $prefix . $key, $key == 'file.');
-                                       } elseif ($resourceFlag) {
-                                               $this->flatSetup[$prefix . $key] = $this->getFileName($val);
+                                               $this->flattenSetup($val, $prefix . $key);
                                        } else {
                                                $this->flatSetup[$prefix . $key] = $val;
                                        }
@@ -1211,18 +1201,16 @@ class TemplateService {
        }
 
        /**
-        * Returns the reference to a 'resource' in TypoScript.
-        * This could be from the filesystem if '/' is found in the value $fileFromSetup, else from the resource-list
+        * Returns the reference used for the frontend inclusion, checks against allowed paths for inclusion.
         *
         * @param string $fileFromSetup TypoScript "resource" data type value.
-        * @return string Resulting filename, if any.
-        * @todo Define visibility
+        * @return string Resulting filename, is either a full absolute URL or a relative path
         */
        public function getFileName($fileFromSetup) {
                $file = trim($fileFromSetup);
                if (!$file) {
                        return;
-               } elseif (strstr($file, '../')) {
+               } elseif (strpos($file, '../') !== FALSE) {
                        if ($this->tt_track) {
                                $GLOBALS['TT']->setTSlogMessage('File path "' . $file . '" contained illegal string "../"!', 3);
                        }
@@ -1233,52 +1221,35 @@ class TemplateService {
                if (isset($this->fileCache[$hash])) {
                        return $this->fileCache[$hash];
                }
-               if (substr($file, 0, 4) === 'EXT:') {
-                       $newFile = '';
-                       list($extKey, $script) = explode('/', substr($file, 4), 2);
-                       if ($extKey && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
-                               $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extKey);
-                               $newFile = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($extPath) . $script;
-                       }
-                       if (!@file_exists((PATH_site . $newFile))) {
-                               if ($this->tt_track) {
-                                       $GLOBALS['TT']->setTSlogMessage('Extension media file "' . $newFile . '" was not found!', 3);
-                               }
-                               return;
-                       } else {
-                               $file = $newFile;
-                       }
-               }
-               if (parse_url($file) !== FALSE) {
+
+               // if this is an URL, it can be returned directly
+               $urlScheme = parse_url($file, PHP_URL_SCHEME);
+               if ($urlScheme === 'https' || $urlScheme === 'http') {
                        return $file;
                }
-               // Find
-               if (strpos($file, '/') !== FALSE) {
-                       // If the file is in the media/ folder but it doesn't exist,
-                       // it is assumed that it's in the tslib folder
-                       if (GeneralUtility::isFirstPartOfStr($file, 'media/') && !file_exists(($this->getFileName_backPath . $file))) {
-                               $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('cms') . 'tslib/' . $file;
+
+               // this call also resolves EXT:myext/ files
+               $file = GeneralUtility::getFileAbsFileName($file);
+               if (!$file) {
+                       if ($this->tt_track) {
+                               $GLOBALS['TT']->setTSlogMessage('File "' . $fileFromSetup . '" was not found!', 3);
                        }
-                       if (file_exists($this->getFileName_backPath . $file)) {
-                               $outFile = $file;
-                               $fileInfo = GeneralUtility::split_fileref($outFile);
-                               $OK = 0;
-                               foreach ($this->allowedPaths as $val) {
-                                       if (substr($fileInfo['path'], 0, strlen($val)) == $val) {
-                                               $OK = 1;
-                                               break;
-                                       }
-                               }
-                               if ($OK) {
-                                       $this->fileCache[$hash] = $outFile;
-                                       return $outFile;
-                               } elseif ($this->tt_track) {
-                                       $GLOBALS['TT']->setTSlogMessage('"' . $file . '" was not located in the allowed paths: (' . implode(',', $this->allowedPaths) . ')', 3);
-                               }
-                       } elseif ($this->tt_track) {
-                               $GLOBALS['TT']->setTSlogMessage('"' . $this->getFileName_backPath . $file . '" is not a file (non-uploads/.. resource, did not exist).', 3);
+                       return;
+               }
+
+               $file = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($file);
+
+               // Check if the found file is in the allowed paths
+               foreach ($this->allowedPaths as $val) {
+                       if (GeneralUtility::isFirstPartOfStr($file, $val)) {
+                               $this->fileCache[$hash] = $file;
+                               return $file;
                        }
                }
+
+               if ($this->tt_track) {
+                       $GLOBALS['TT']->setTSlogMessage('"' . $file . '" was not located in the allowed paths: (' . implode(',', $this->allowedPaths) . ')', 3);
+               }
        }
 
        /**
@@ -1316,19 +1287,20 @@ class TemplateService {
        }
 
        /**
-        * Reads the fileContent of $fName and returns it.
-        * Similar to GeneralUtility::getUrl()
+        * Reads the fileContent of $fileName and returns it.
+        * Similar to GeneralUtility::getUrl() but with an additional check if the path is allowed
         *
-        * @param string $fName Absolute filepath to record
-        * @return string The content returned
+        * @param string $fileName Absolute filepath to record
+        * @return NULL|string The content returned
         * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::fileResource(), \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::MULTIMEDIA(), GeneralUtility::getUrl()
         * @todo Define visibility
         */
-       public function fileContent($fName) {
-               $incFile = $this->getFileName($fName);
-               if ($incFile) {
-                       return @file_get_contents($incFile);
+       public function fileContent($fileName) {
+               $fileName = $this->getFileName($fileName);
+               if ($fileName) {
+                       return GeneralUtility::getUrl($fileName);
                }
+               return NULL;
        }
 
        /**
index 9e19569..2b9dfad 100644 (file)
@@ -739,7 +739,7 @@ return array(
                'defaultTypoScript_constants.' => array(),              // Lines of TS to include after a static template with the uid = the index in the array (Constants)
                'defaultTypoScript_setup' => '',                // String (textarea). Enter lines of default TypoScript, setup-field.
                'defaultTypoScript_setup.' => array(),          // Lines of TS to include after a static template with the uid = the index in the array (Setup)
-               'additionalAbsRefPrefixDirectories' => '',              // Enter additional directories to be prepended with absRefPrefix. Directories must be comma-separated. TYPO3 already prepends the following directories: media/, typo3conf/ext/, fileadmin/
+               'additionalAbsRefPrefixDirectories' => '',              // Enter additional directories to be prepended with absRefPrefix. Directories must be comma-separated. TYPO3 already prepends the following directories: typo3conf/ext/, fileadmin/
                'IPmaskMountGroups' => array( // This allows you to specify an array of IPmaskLists/fe_group-uids. If the REMOTE_ADDR of the user matches an IPmaskList, then the given fe_group is add to the gr_list. So this is an automatic mounting of a user-group. But no fe_user is logged in though! This feature is implemented for the default frontend user authentication and might not be implemented for alternative authentication services.
                        // array('IPmaskList_1','fe_group uid'), array('IPmaskList_2','fe_group uid')
                ),
index 4078c9e..79044f0 100644 (file)
@@ -6869,7 +6869,6 @@ class ContentObjectRenderer {
         * @param array $conf TypoScript properties for this function
         * @param string $text The text string to write onto the GIFBUILDER file
         * @return array The modified $gifbuilderConf array
-        * @see media/scripts/postit.inc
         * @todo Define visibility
         */
        public function gifBuilderTextBox($gifbuilderConf, $conf, $text) {
index d658fa6..3629383 100644 (file)
@@ -106,8 +106,6 @@ class CodeCompletion {
                $tsParser->linkObjects = TRUE;
                $tsParser->ext_regLinenumbers = FALSE;
                $tsParser->bType = $bType;
-               $tsParser->resourceCheck = 1;
-               $tsParser->removeFromGetFilePath = PATH_site;
                $tsParser->generateConfig();
                $result = $this->treeWalkCleanup($tsParser->setup);
                return $result;
index a36cf5d..5844481 100644 (file)
@@ -293,8 +293,6 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends \TYPO3\CMS
                $tmpl->ext_regLinenumbers = TRUE;
                $tmpl->ext_regComments = $this->pObj->MOD_SETTINGS['ts_browser_showComments'];
                $tmpl->bType = $bType;
-               $tmpl->resourceCheck = 1;
-               $tmpl->removeFromGetFilePath = PATH_site;
                if ($this->pObj->MOD_SETTINGS['ts_browser_type'] == 'const') {
                        $tmpl->ext_constants_BRP = (int)GeneralUtility::_GP('breakPointLN');
                } else {