[FEATURE] Allow .ts file extension for static typoscript templates
authorSebastian Michaelsen <michaelsen@t3seo.de>
Mon, 19 Mar 2012 10:38:12 +0000 (11:38 +0100)
committerSusanne Moog <typo3@susannemoog.de>
Sat, 18 Aug 2012 20:34:00 +0000 (22:34 +0200)
At the moment the following static typoscript filenames are allowed:

setup.txt
constants.txt
include_static.txt
include_static_files.txt

* Allow ".ts" as file extensions
* Allow mixed usage of .ts and .txt
* .ts precedes .txt

Change-Id: I0ffd9ef50a07dfbaa8388d525c5ced09d5070103
Fixes: #34922
Releases: 4.8
Reviewed-on: http://review.typo3.org/9736
Reviewed-by: Philipp Gampe
Reviewed-by: Stefan Neufeind
Reviewed-by: Simon Schaufelberger
Tested-by: Simon Schaufelberger
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
t3lib/class.t3lib_tstemplate.php

index 3da6850..4267676 100644 (file)
@@ -588,28 +588,10 @@ class t3lib_TStemplate {
                        // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
                if (trim($row['include_static_file'])) {
                        $include_static_fileArr = t3lib_div::trimExplode(',', $row['include_static_file'], TRUE);
-                               // Traversing list
-                       foreach ($include_static_fileArr as $ISF_file) {
-                               if (substr($ISF_file, 0, 4) == 'EXT:') {
-                                       list($ISF_extKey, $ISF_localPath) = explode('/', substr($ISF_file, 4), 2);
-                                       if (strcmp($ISF_extKey, '') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath, '')) {
-                                               $ISF_localPath = rtrim($ISF_localPath, '/') . '/';
-                                               $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey) . $ISF_localPath;
-                                               if (@is_dir($ISF_filePath)) {
-                                                       $mExtKey = str_replace('_', '', $ISF_extKey . '/' . $ISF_localPath);
-                                                       $subrow = array(
-                                                               'constants' => @is_file($ISF_filePath . 'constants.txt') ? t3lib_div::getUrl($ISF_filePath . 'constants.txt') : '',
-                                                               'config' => @is_file($ISF_filePath . 'setup.txt') ? t3lib_div::getUrl($ISF_filePath . 'setup.txt') : '',
-                                                               'include_static' => @is_file($ISF_filePath . 'include_static.txt') ? implode(',', array_unique(t3lib_div::intExplode(',', t3lib_div::getUrl($ISF_filePath . 'include_static.txt')))) : '',
-                                                               'include_static_file' => @is_file($ISF_filePath . 'include_static_file.txt') ? implode(',', array_unique(explode(',', t3lib_div::getUrl($ISF_filePath . 'include_static_file.txt')))) : '',
-                                                               'title' => $ISF_file,
-                                                               'uid' => $mExtKey
-                                                       );
-                                                       $subrow = $this->prependStaticExtra($subrow);
-
-                                                       $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID);
-                                               }
-                                       }
+                       foreach ($include_static_fileArr as $staticTemplateFolder) {
+                               $subrow = $this->readFromStaticTemplateFolder($staticTemplateFolder);
+                               if (!empty($subrow)) {
+                                       $this->processTemplate($subrow, $idList . ',ext_' . $subrow['uid'], $pid, 'ext_' . $subrow['uid'], $templateID);
                                }
                        }
                }
@@ -634,6 +616,58 @@ class t3lib_TStemplate {
                }
        }
 
+       /**
+        * Reads the static TypoScript from a given folder and returns a virtual sys_template record containing the data
+        *
+        * @param string $staticTemplateFolder Folder to read the static TS from. Path has to start with "EXT:"
+        * @return array
+        */
+       protected function readFromStaticTemplateFolder($staticTemplateFolder) {
+               /** @var $row array Virtual sys_template record, ready to be parsed by $this->processTemplate() */
+               $row = array();
+               if (substr($staticTemplateFolder, 0, 4) === 'EXT:') {
+                       list($extensionKey, $relativePath) = explode('/', substr($staticTemplateFolder, 4), 2);
+                       $templateFolderPath = rtrim(t3lib_extMgm::extPath($extensionKey) . $relativePath, '/') . '/';
+                       if (@is_dir($templateFolderPath)) {
+                               $row = array(
+                                       'title' => $staticTemplateFolder,
+                                       'uid' => str_replace('_', '', $extensionKey . '/' . $templateFolderPath)
+                               );
+
+                                       // .ts has higher priority than .txt
+                               $allowedFileExtensions = array('ts', 'txt');
+                               $allowedFilenamesToFieldname = array(
+                                       'constants' => 'constants',
+                                       'setup' => 'config',
+                                       'include_static' => 'include_static',
+                                       'include_static_file' => 'include_static_file'
+                               );
+
+                                       // read files
+                               foreach ($allowedFileExtensions as $fileExtension) {
+                                       foreach ($allowedFilenamesToFieldname as $filename => $fieldname) {
+                                               $file = $templateFolderPath . $filename . '.' . $fileExtension;
+                                               if (empty($row[$fieldname]) && @is_file($file)) {
+                                                       switch ($filename) {
+                                                               case 'constants':
+                                                               case 'setup':
+                                                                       $row[$fieldname] = t3lib_div::getUrl($file);
+                                                                       break;
+                                                               case 'include_static':
+                                                                       $row[$fieldname] = implode(',', array_unique(t3lib_div::intExplode(',', t3lib_div::getUrl($file))));
+                                                                       break;
+                                                               case 'include_static_file':
+                                                                       $row[$fieldname] = implode(',', array_unique(explode(',', t3lib_div::getUrl($file))));
+                                                       }
+                                               }
+                                       }
+                               }
+                               $row = $this->prependStaticExtra($row);
+                       }
+               }
+               return $row;
+       }
+
        /**
         * Adds the default TypoScript files for extensions if any.
         *