TYPO3 CMS  TYPO3_7-6
AbstractSpriteHandler.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
26 {
32  protected $iconNames = [];
33 
39  protected $styleSheetData = '';
40 
46  protected $cssTcaFile = '';
47 
53  public function __construct()
54  {
55  // The file name is prefixed with "z" since the concatenator orders files per name
56  $this->cssTcaFile = PATH_site . SpriteManager::$tempPath . 'zextensions.css';
57  $this->styleSheetData = '/* Auto-Generated via ' . get_class($this) . ' */' . LF;
58  }
59 
71  protected function loadRegisteredSprites()
72  {
73  // Saves which CSS Files are currently "allowed to be in place"
74  $allowedCssFilesinTempDir = [basename($this->cssTcaFile)];
75  // Process every registeres file
76  foreach ((array)$GLOBALS['TBE_STYLES']['spritemanager']['cssFiles'] as $file) {
77  $fileName = basename($file);
78  // File should be present
79  $allowedCssFilesinTempDir[] = $fileName;
80  // get-Cache Filename
81  $fileStatus = stat(PATH_site . $file);
82  $unique = md5($fileName . $fileStatus['mtime'] . $fileStatus['size']);
83  $cacheFile = PATH_site . SpriteManager::$tempPath . $fileName . $unique . '.css';
84  if (!file_exists($cacheFile)) {
85  copy(PATH_site . $file, $cacheFile);
86  }
87  }
88  // Get all .css files in dir
89  $cssFilesPresentInTempDir = GeneralUtility::getFilesInDir(PATH_site . SpriteManager::$tempPath, '.css', 0);
90  // and delete old ones which are not needed anymore
91  $filesToDelete = array_diff($cssFilesPresentInTempDir, $allowedCssFilesinTempDir);
92  foreach ($filesToDelete as $file) {
93  unlink(PATH_site . SpriteManager::$tempPath . $file);
94  }
95  }
96 
103  public function generate()
104  {
105  // Include registered Sprites
106  $this->loadRegisteredSprites();
107  // Cache results in the CSS file
108  GeneralUtility::writeFile($this->cssTcaFile, $this->styleSheetData);
109  }
110 
117  public function getAvailableIconNames()
118  {
119  return $this->iconNames;
120  }
121 
129  protected function collectTcaSpriteIcons()
130  {
131  $tcaTables = array_keys($GLOBALS['TCA']);
132  $resultArray = [];
133  // Path (relative from typo3 dir) for skin-Images
134  if (isset($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'])) {
135  $skinPath = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'];
136  } else {
137  $skinPath = '';
138  }
139  // check every table in the TCA, if an icon is needed
140  foreach ($tcaTables as $tableName) {
141  // This method is only needed for TCA tables where
142  // typeicon_classes are not configured
143  if (is_array($GLOBALS['TCA'][$tableName]) && !is_array($GLOBALS['TCA'][$tableName]['ctrl']['typeicon_classes'])) {
144  $tcaCtrl = $GLOBALS['TCA'][$tableName]['ctrl'];
145  // Adding the default Icon (without types)
146  if (isset($tcaCtrl['iconfile'])) {
147  // In CSS we need a path relative to the css file
148  // [TCA][ctrl][iconfile] defines icons without path info to reside in gfx/i/
149  if (\TYPO3\CMS\Core\Utility\StringUtility::beginsWith($tcaCtrl['iconfile'], 'EXT:')) {
150  list($extensionKey, $relativePath) = explode('/', substr($tcaCtrl['iconfile'], 4), 2);
151  $pathInfo = PathUtility::pathinfo(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey) . $relativePath);
152  $path = PathUtility::getRelativePathTo($pathInfo['dirname']);
153  $icon = $path . $pathInfo['basename'];
154  } elseif (strpos($tcaCtrl['iconfile'], '/') !== false) {
155  $icon = $tcaCtrl['iconfile'];
156  $icon = GeneralUtility::resolveBackPath($icon);
157  } else {
158  $icon = $skinPath . 'gfx/i/' . $tcaCtrl['iconfile'];
159  $icon = GeneralUtility::resolveBackPath($icon);
160  }
161 
162  $resultArray['tcarecords-' . $tableName . '-default'] = $icon;
163  }
164  }
165  }
166  return $resultArray;
167  }
168 }
static getFilesInDir($path, $extensionList='', $prependPath=false, $order='', $excludePattern='')
static getRelativePathTo($targetPath)
Definition: PathUtility.php:29
static pathinfo($path, $options=null)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static writeFile($file, $content, $changePermissions=false)