[BUGFIX] Remove deprecation log entries for SpriteManager
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Sprite / SpriteManager.php
1 <?php
2 namespace TYPO3\CMS\Backend\Sprite;
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * TYPO3 sprite manager, used in BE and in FE if a BE user is logged in.
21 *
22 * This class builds CSS definitions of registered icons, writes TCA definitions
23 * and registers sprite icons in a cache file.
24 *
25 * A configurable handler class does the business task.
26 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
27 */
28 class SpriteManager
29 {
30 /**
31 * @var string Directory for cached sprite informations
32 */
33 public static $tempPath = 'typo3temp/sprites/';
34
35 /**
36 * Is sprite manager initialized
37 */
38 protected static $isInitialized = false;
39
40 /**
41 * Initialize sprite manager.
42 * Loads registered sprite configuration from cache, or
43 * rebuilds new cache before registration.
44 *
45 * @return void
46 */
47 public static function initialize()
48 {
49 if (!static::isInitialized()) {
50 $cacheIdentifier = static::getCacheIdentifier();
51 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
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
62 /**
63 * Whether the sprite manager is initialized.
64 *
65 * @return bool TRUE if sprite manager is initialized
66 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
67 */
68 public static function isInitialized()
69 {
70 return self::$isInitialized;
71 }
72
73 /**
74 * Set up sprite icon data and create cache entry calling the registered generator.
75 *
76 * Stuff the compiled $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable']
77 * global into php code cache.
78 *
79 * @throws \RuntimeException
80 * @return void
81 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
82 */
83 protected static function buildSpriteDataAndCreateCacheEntry()
84 {
85 $handlerClass = $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconGenerator_handler'];
86 /** @var $handler \TYPO3\CMS\Backend\Sprite\SpriteIconGeneratorInterface */
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) . ';';
112 /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
113 GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent);
114 }
115
116 /**
117 * Get cache identifier for $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable']
118 *
119 * @return string
120 */
121 protected static function getCacheIdentifier()
122 {
123 return 'sprites_' . sha1((TYPO3_version . PATH_site . 'spriteManagement'));
124 }
125
126 /**
127 * API for extensions to register own sprites.
128 *
129 * Get an array of icon names and the styleSheetFile with defined sprite icons.
130 * The stylesheet filename should contain the extension name to be unique.
131 *
132 * Naming conventions:
133 * - IconName: extensions-$extKey-$iconName
134 * - CSS class for loading the sprite: t3-icon-extensions-$extKey
135 * - CSS class for single icons: t3-icon-$extKey-$iconName
136 *
137 * @param array $icons Icon names
138 * @param string $styleSheetFile Stylesheet filename relative to PATH_typo3. Skins do not need to supply the $styleSheetFile, if the CSS file is within the registered stylesheet folders
139 * @return void
140 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
141 */
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
151 /**
152 * API for extensions to register new sprite images which can be used with
153 * \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('extensions-$extKey-iconName');
154 *
155 * @param array $icons Icons to be registered, $iconname => $iconFile, $iconFile must be relative to PATH_site
156 * @param string $extKey Extension key
157 * @return void
158 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
159 */
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
168 /**
169 * API to register new type icons for tables which use "typeicon_classes"
170 * Can be used to provide icons for "modules" in pages table
171 *
172 * @param string $table Table name to which the type icon should be added
173 * @param string $type Type column name of the table
174 * @param string $iconFile Icon filename, relative to PATH_typo3
175 * @return void
176 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
177 */
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 }