TYPO3 CMS  TYPO3_7-6
SpriteManager.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 
18 
29 {
33  public static $tempPath = 'typo3temp/sprites/';
34 
38  protected static $isInitialized = false;
39 
47  public static function initialize()
48  {
49  if (!static::isInitialized()) {
50  $cacheIdentifier = static::getCacheIdentifier();
52  $codeCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core');
53  if ($codeCache->has($cacheIdentifier)) {
54  $codeCache->requireOnce($cacheIdentifier);
55  } else {
56  static::buildSpriteDataAndCreateCacheEntry();
57  }
58  self::$isInitialized = true;
59  }
60  }
61 
68  public static function isInitialized()
69  {
70  return self::$isInitialized;
71  }
72 
83  protected static function buildSpriteDataAndCreateCacheEntry()
84  {
85  $handlerClass = $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconGenerator_handler'];
87  $handler = GeneralUtility::makeInstance($handlerClass);
88  // Throw exception if handler class does not implement required interface
89  if (!$handler instanceof \TYPO3\CMS\Backend\Sprite\SpriteIconGeneratorInterface) {
90  throw new \RuntimeException('Class ' . $handlerClass . ' in $TYPO3_CONF_VARS[BE][spriteIconGenerator_handler] ' . ' does not implement ' . \TYPO3\CMS\Backend\Sprite\SpriteIconGeneratorInterface::class, 1294586333);
91  }
92  // Create temp directory if missing
93  if (!is_dir((PATH_site . self::$tempPath))) {
94  GeneralUtility::mkdir(PATH_site . self::$tempPath);
95  }
96  // Generate CSS and TCA files, build icon set register
97  $handler->generate();
98  // Get all icons registered from skins, merge with core icon list
99  $availableSkinIcons = (array)$GLOBALS['TBE_STYLES']['spriteIconApi']['coreSpriteImageNames'];
100  if (isset($GLOBALS['TBE_STYLES']['skins']) && is_array($GLOBALS['TBE_STYLES']['skins'])) {
101  foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinData) {
102  $availableSkinIcons = array_merge($availableSkinIcons, (array)$skinData['availableSpriteIcons']);
103  }
104  }
105  // Merge icon names provided by the skin, with
106  // registered "complete sprites" and the handler class
107  $iconNames = array_merge($availableSkinIcons, (array)$GLOBALS['TBE_STYLES']['spritemanager']['spriteIconsAvailable'], $handler->getAvailableIconNames());
108  $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'] = $iconNames;
109 
110  $cacheFileContent = '$GLOBALS[\'TBE_STYLES\'][\'spriteIconApi\'][\'iconsAvailable\'] = ';
111  $cacheFileContent .= var_export($iconNames, true) . ';';
113  GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent);
114  }
115 
121  protected static function getCacheIdentifier()
122  {
123  return 'sprites_' . sha1((TYPO3_version . PATH_site . 'spriteManagement'));
124  }
125 
142  public static function addIconSprite(array $icons, $styleSheetFile = '')
143  {
144  GeneralUtility::deprecationLog(self::class . ' is deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8');
145  $GLOBALS['TBE_STYLES']['spritemanager']['spriteIconsAvailable'] = array_merge((array)$GLOBALS['TBE_STYLES']['spritemanager']['spriteIconsAvailable'], $icons);
146  if ($styleSheetFile !== '') {
147  $GLOBALS['TBE_STYLES']['spritemanager']['cssFiles'][] = $styleSheetFile;
148  }
149  }
150 
160  public static function addSingleIcons(array $icons, $extKey = '')
161  {
162  GeneralUtility::deprecationLog(self::class . ' is deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8');
163  foreach ($icons as $iconName => $iconFile) {
164  $GLOBALS['TBE_STYLES']['spritemanager']['singleIcons']['extensions-' . $extKey . '-' . $iconName] = $iconFile;
165  }
166  }
167 
178  public static function addTcaTypeIcon($table, $type, $iconFile)
179  {
180  GeneralUtility::deprecationLog(self::class . ' is deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8');
181  $GLOBALS['TBE_STYLES']['spritemanager']['singleIcons']['tcarecords-' . $table . '-' . $type] = $iconFile;
182  if (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
183  $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type] = 'tcarecords-' . $table . '-' . $type;
184  }
185  }
186 }
static addTcaTypeIcon($table, $type, $iconFile)
static addSingleIcons(array $icons, $extKey='')
static addIconSprite(array $icons, $styleSheetFile='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']