TYPO3 CMS  TYPO3_6-2
SpriteManager.php
Go to the documentation of this file.
1 <?php
3 
18 
30 
34  static public $tempPath = 'typo3temp/sprites/';
35 
39  static protected $isInitialized = FALSE;
40 
48  static public function initialize() {
49  if (!static::isInitialized()) {
50  $cacheIdentifier = static::getCacheIdentifier();
52  $codeCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->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 
67  static public function isInitialized() {
68  return self::$isInitialized;
69  }
70 
80  static protected function buildSpriteDataAndCreateCacheEntry() {
81  $handlerClass = $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconGenerator_handler'];
83  $handler = GeneralUtility::makeInstance($handlerClass);
84  // Throw exception if handler class does not implement required interface
85  if (!$handler instanceof \TYPO3\CMS\Backend\Sprite\SpriteIconGeneratorInterface) {
86  throw new \RuntimeException('Class ' . $handlerClass . ' in $TYPO3_CONF_VARS[BE][spriteIconGenerator_handler] ' . ' does not implement TYPO3\\CMS\\Backend\\Sprite\\SpriteIconGeneratorInterface', 1294586333);
87  }
88  // Create temp directory if missing
89  if (!is_dir((PATH_site . self::$tempPath))) {
90  GeneralUtility::mkdir(PATH_site . self::$tempPath);
91  }
92  // Generate CSS and TCA files, build icon set register
93  $handler->generate();
94  // Get all icons registered from skins, merge with core icon list
95  $availableSkinIcons = (array) $GLOBALS['TBE_STYLES']['spriteIconApi']['coreSpriteImageNames'];
96  foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinData) {
97  $availableSkinIcons = array_merge($availableSkinIcons, (array) $skinData['availableSpriteIcons']);
98  }
99  // Merge icon names provided by the skin, with
100  // registered "complete sprites" and the handler class
101  $iconNames = array_merge($availableSkinIcons, (array) $GLOBALS['TBE_STYLES']['spritemanager']['spriteIconsAvailable'], $handler->getAvailableIconNames());
102  $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'] = $iconNames;
103 
104  $cacheFileContent = '$GLOBALS[\'TBE_STYLES\'][\'spriteIconApi\'][\'iconsAvailable\'] = ';
105  $cacheFileContent .= var_export($iconNames, TRUE) . ';';
107  GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent);
108  }
109 
115  static protected function getCacheIdentifier() {
116  return 'sprites_' . sha1((TYPO3_version . PATH_site . 'spriteManagement'));
117  }
118 
134  static public function addIconSprite(array $icons, $styleSheetFile = '') {
135  $GLOBALS['TBE_STYLES']['spritemanager']['spriteIconsAvailable'] = array_merge((array) $GLOBALS['TBE_STYLES']['spritemanager']['spriteIconsAvailable'], $icons);
136  if ($styleSheetFile !== '') {
137  $GLOBALS['TBE_STYLES']['spritemanager']['cssFiles'][] = $styleSheetFile;
138  }
139  }
140 
149  static public function addSingleIcons(array $icons, $extKey = '') {
150  foreach ($icons as $iconName => $iconFile) {
151  $GLOBALS['TBE_STYLES']['spritemanager']['singleIcons']['extensions-' . $extKey . '-' . $iconName] = $iconFile;
152  }
153  }
154 
164  static public function addTcaTypeIcon($table, $type, $iconFile) {
165  $GLOBALS['TBE_STYLES']['spritemanager']['singleIcons']['tcarecords-' . $table . '-' . $type] = $iconFile;
166  if (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
167  $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type] = 'tcarecords-' . $table . '-' . $type;
168  }
169  }
170 
171 }
static addTcaTypeIcon($table, $type, $iconFile)
static addSingleIcons(array $icons, $extKey='')
if(!defined('TYPO3_MODE')) if(TYPO3_MODE=='BE' &&!(TYPO3_REQUESTTYPE &TYPO3_REQUESTTYPE_INSTALL)) $icons
Definition: ext_tables.php:52
static addIconSprite(array $icons, $styleSheetFile='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]