TYPO3 CMS  TYPO3_6-2
AbstractSpriteHandler.php
Go to the documentation of this file.
1 <?php
3 
20 
28 
34  protected $iconNames = array();
35 
41  protected $styleSheetData = '';
42 
48  protected $cssTcaFile = '';
49 
55  public function __construct() {
56  // The file name is prefixed with "z" since the concatenator orders files per name
57  $this->cssTcaFile = PATH_site . SpriteManager::$tempPath . 'zextensions.css';
58  $this->styleSheetData = '/* Auto-Generated via ' . get_class($this) . ' */' . LF;
59  }
60 
72  protected function loadRegisteredSprites() {
73  // Saves which CSS Files are currently "allowed to be in place"
74  $allowedCssFilesinTempDir = array(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  // Include registered Sprites
105  $this->loadRegisteredSprites();
106  // Cache results in the CSS file
107  GeneralUtility::writeFile($this->cssTcaFile, $this->styleSheetData);
108  }
109 
116  public function getAvailableIconNames() {
117  return $this->iconNames;
118  }
119 
127  protected function collectTcaSpriteIcons() {
128  $tcaTables = array_keys($GLOBALS['TCA']);
129  $resultArray = array();
130  // Path (relative from typo3 dir) for skin-Images
131  if (isset($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'])) {
132  $skinPath = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'];
133  } else {
134  $skinPath = '';
135  }
136  // check every table in the TCA, if an icon is needed
137  foreach ($tcaTables as $tableName) {
138  // This method is only needed for TCA tables where
139  // typeicon_classes are not configured
140  if (is_array($GLOBALS['TCA'][$tableName]) && !is_array($GLOBALS['TCA'][$tableName]['ctrl']['typeicon_classes'])) {
141  $tcaCtrl = $GLOBALS['TCA'][$tableName]['ctrl'];
142  // Adding the default Icon (without types)
143  if (isset($tcaCtrl['iconfile'])) {
144  // In CSS we need a path relative to the css file
145  if (strpos($tcaCtrl['iconfile'], '/') !== FALSE) {
146  if (GeneralUtility::isFirstPartOfStr($tcaCtrl['iconfile'], 'EXT:')) {
147  list($extensionKey, $relativePath) = explode('/', substr($tcaCtrl['iconfile'], 4), 2);
148  $icon = ExtensionManagementUtility::extRelPath($extensionKey) . $relativePath;
149  } else {
150  $icon = $tcaCtrl['iconfile'];
151  }
152  } else {
153  // [TCA][ctrl][iconfile] defines icons without path info to reside in gfx/i/
154  $icon = $skinPath . 'gfx/i/' . $tcaCtrl['iconfile'];
155  }
156  $icon = GeneralUtility::resolveBackPath($icon);
157  $resultArray['tcarecords-' . $tableName . '-default'] = $icon;
158  }
159  // If records types are available, register them
160  if (isset($tcaCtrl['typeicon_column']) && is_array($tcaCtrl['typeicons'])) {
161  foreach ($tcaCtrl['typeicons'] as $type => $icon) {
162  // In CSS we need a path relative to the css file
163  // [TCA][ctrl][iconfile] defines icons without path info to reside in gfx/i/
164  if (strpos($icon, '/') === FALSE) {
165  $icon = $skinPath . 'gfx/i/' . $icon;
166  } elseif (GeneralUtility::isFirstPartOfStr($icon, 'EXT:')) {
167  list($extensionKey, $relativePath) = explode('/', substr($icon, 4), 2);
168  $icon = ExtensionManagementUtility::extRelPath($extensionKey) . $relativePath;
169  }
170  $icon = GeneralUtility::resolveBackPath($icon);
171  $resultArray['tcarecords-' . $tableName . '-' . $type] = $icon;
172  }
173  }
174  }
175  }
176  return $resultArray;
177  }
178 
179 }
static writeFile($file, $content, $changePermissions=FALSE)
static isFirstPartOfStr($str, $partStr)
static getFilesInDir($path, $extensionList='', $prependPath=FALSE, $order='', $excludePattern='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]