[TASK] Remove check to non existing folder in IconUtility::makeIcon
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Utility / IconUtility.php
1 <?php
2 namespace TYPO3\CMS\Backend\Utility;
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\Imaging\GraphicalFunctions;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Core\Versioning\VersionState;
20
21 /**
22 * Contains class for icon generation in the backend
23 * This library has functions that returns - and if necessary creates - the icon for an element in TYPO3
24 *
25 * Expects global vars:
26 * - $BACK_PATH
27 * - PATH_typo3
28 * - $TCA, $PAGES_TYPES
29 *
30 *
31 * Notes:
32 * These functions are strongly related to the interface of TYPO3.
33 * Static class, functions called without making a class instance.
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 class IconUtility {
38
39 /**
40 * @var string[]
41 */
42 static public $fileSpriteIconNames = array(
43 'htm' => 'mimetypes-text-html',
44 'html' => 'mimetypes-text-html',
45 'css' => 'mimetypes-text-css',
46 'js' => 'mimetypes-text-js',
47 'csv' => 'mimetypes-text-csv',
48 'php' => 'mimetypes-text-php',
49 'php6' => 'mimetypes-text-php',
50 'php5' => 'mimetypes-text-php',
51 'php4' => 'mimetypes-text-php',
52 'php3' => 'mimetypes-text-php',
53 'inc' => 'mimetypes-text-php',
54 'ts' => 'mimetypes-text-ts',
55 'txt' => 'mimetypes-text-text',
56 'class' => 'mimetypes-text-text',
57 'tmpl' => 'mimetypes-text-text',
58 'jpg' => 'mimetypes-media-image',
59 'jpeg' => 'mimetypes-media-image',
60 'gif' => 'mimetypes-media-image',
61 'png' => 'mimetypes-media-image',
62 'bmp' => 'mimetypes-media-image',
63 'tif' => 'mimetypes-media-image',
64 'tiff' => 'mimetypes-media-image',
65 'tga' => 'mimetypes-media-image',
66 'psd' => 'mimetypes-media-image',
67 'eps' => 'mimetypes-media-image',
68 'ai' => 'mimetypes-media-image',
69 'svg' => 'mimetypes-media-image',
70 'pcx' => 'mimetypes-media-image',
71 'avi' => 'mimetypes-media-video',
72 'mpg' => 'mimetypes-media-video',
73 'mpeg' => 'mimetypes-media-video',
74 'mov' => 'mimetypes-media-video',
75 'wav' => 'mimetypes-media-audio',
76 'mp3' => 'mimetypes-media-audio',
77 'mid' => 'mimetypes-media-audio',
78 'swf' => 'mimetypes-media-flash',
79 'swa' => 'mimetypes-media-flash',
80 'exe' => 'mimetypes-executable-executable',
81 'com' => 'mimetypes-executable-executable',
82 't3x' => 'mimetypes-compressed',
83 't3d' => 'mimetypes-compressed',
84 'zip' => 'mimetypes-compressed',
85 'tgz' => 'mimetypes-compressed',
86 'gz' => 'mimetypes-compressed',
87 'pdf' => 'mimetypes-pdf',
88 'doc' => 'mimetypes-word',
89 'dot' => 'mimetypes-word',
90 'docm' => 'mimetypes-word',
91 'docx' => 'mimetypes-word',
92 'dotm' => 'mimetypes-word',
93 'dotx' => 'mimetypes-word',
94 'sxw' => 'mimetypes-word',
95 'rtf' => 'mimetypes-word',
96 'xls' => 'mimetypes-excel',
97 'xlsm' => 'mimetypes-excel',
98 'xlsx' => 'mimetypes-excel',
99 'xltm' => 'mimetypes-excel',
100 'xltx' => 'mimetypes-excel',
101 'sxc' => 'mimetypes-excel',
102 'pps' => 'mimetypes-powerpoint',
103 'ppsx' => 'mimetypes-powerpoint',
104 'ppt' => 'mimetypes-powerpoint',
105 'pptm' => 'mimetypes-powerpoint',
106 'pptx' => 'mimetypes-powerpoint',
107 'potm' => 'mimetypes-powerpoint',
108 'potx' => 'mimetypes-powerpoint',
109 'mount' => 'apps-filetree-mount',
110 'folder' => 'apps-filetree-folder-default',
111 'default' => 'mimetypes-other-other',
112 );
113
114 /**
115 * Array of icons rendered by getSpriteIcon(). This contains only icons
116 * without overlays or options. These are the most common form.
117 *
118 * @var array
119 */
120 static protected $spriteIconCache = array();
121
122 /**
123 * Creates the icon for input table/row
124 * Returns filename for the image icon, relative to PATH_typo3
125 *
126 * @param string $table The table name
127 * @param array $row The table row ("enablefields" are at least needed for correct icon display and for pages records some more fields in addition!)
128 * @param bool $shaded If set, the icon will be grayed/shaded
129 * @return string Icon filename
130 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8, use IconUtility::getSpriteIcon() instead
131 */
132 static public function getIcon($table, $row = array(), $shaded = FALSE) {
133 GeneralUtility::logDeprecatedFunction();
134 // Flags
135 // If set, then the usergroup number will NOT be printed unto the icon. NOTICE.
136 // The icon is generated only if a default icon for groups is not found... So effectively this is ineffective.
137 $doNotRenderUserGroupNumber = TRUE;
138 // Shadow
139 if (!empty($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) && !empty($row['t3ver_state'])) {
140 switch (VersionState::cast($row['t3ver_state'])) {
141 case new VersionState(VersionState::NEW_PLACEHOLDER):
142 return 'gfx/i/shadow_hide.png';
143 break;
144 case new VersionState(VersionState::DELETE_PLACEHOLDER):
145 return 'gfx/i/shadow_delete.png';
146 break;
147 case new VersionState(VersionState::MOVE_PLACEHOLDER):
148 return 'gfx/i/shadow_moveto_plh.png';
149 break;
150 case new VersionState(VersionState::MOVE_POINTER):
151 return 'gfx/i/shadow_moveto_pointer.png';
152 break;
153 }
154 }
155 // First, find the icon file name. This can depend on configuration in TCA, field values and more:
156 if ($table == 'pages') {
157 $iconfile = $GLOBALS['PAGES_TYPES'][$row['doktype']]['icon'];
158 if (!$iconfile) {
159 $iconfile = $GLOBALS['PAGES_TYPES']['default']['icon'];
160 }
161 } else {
162 if (!($iconfile = $GLOBALS['TCA'][$table]['ctrl']['typeicons'][$row[$GLOBALS['TCA'][$table]['ctrl']['typeicon_column']]])) {
163 $iconfile = $GLOBALS['TCA'][$table]['ctrl']['iconfile'] ?: $table . '.gif';
164 }
165 }
166 // Setting path of iconfile if not already set. Default is "gfx/i/"
167 if (!strstr($iconfile, '/')) {
168 $iconfile = 'gfx/i/' . $iconfile;
169 }
170 // Setting the absolute path where the icon should be found as a file:
171 if (substr($iconfile, 0, 3) == '../') {
172 $absfile = PATH_site . substr($iconfile, 3);
173 } else {
174 $absfile = PATH_typo3 . $iconfile;
175 }
176 // Initializing variables, all booleans except otherwise stated:
177 $hidden = FALSE;
178 $timing = FALSE;
179 $futuretiming = FALSE;
180 // In fact an integer value
181 $user = FALSE;
182 $deleted = FALSE;
183 // Set, if a page-record (only pages!) has the extend-to-subpages flag set.
184 $protectSection = FALSE;
185 $noIconFound = $row['_NO_ICON_FOUND'] ? TRUE : FALSE;
186 // + $shaded which is also boolean!
187 // Icon state based on "enableFields":
188 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
189 $enCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
190 // If "hidden" is enabled:
191 if ($enCols['disabled']) {
192 if ($row[$enCols['disabled']]) {
193 $hidden = TRUE;
194 }
195 }
196 // If a "starttime" is set and higher than current time:
197 if ($enCols['starttime']) {
198 if ($GLOBALS['EXEC_TIME'] < (int)$row[$enCols['starttime']]) {
199 $timing = TRUE;
200 // And if "endtime" is NOT set:
201 if ((int)$row[$enCols['endtime']] === 0) {
202 $futuretiming = TRUE;
203 }
204 }
205 }
206 // If an "endtime" is set:
207 if ($enCols['endtime']) {
208 if ((int)$row[$enCols['endtime']] > 0) {
209 if ((int)$row[$enCols['endtime']] < $GLOBALS['EXEC_TIME']) {
210 // End-timing applies at this point.
211 $timing = TRUE;
212 } else {
213 // End-timing WILL apply in the future for this element.
214 $futuretiming = TRUE;
215 }
216 }
217 }
218 // If a user-group field is set:
219 if ($enCols['fe_group']) {
220 $user = $row[$enCols['fe_group']];
221 if ($user && $doNotRenderUserGroupNumber) {
222 $user = 100;
223 }
224 }
225 }
226 // If "deleted" flag is set (only when listing records which are also deleted!)
227 if ($col = $row[$GLOBALS['TCA'][$table]['ctrl']['delete']]) {
228 $deleted = TRUE;
229 }
230 // Detecting extendToSubpages (for pages only)
231 if ($table == 'pages' && $row['extendToSubpages'] && ($hidden || $timing || $futuretiming || $user)) {
232 $protectSection = TRUE;
233 }
234 // If ANY of the booleans are set it means we have to alter the icon:
235 if ($hidden || $timing || $futuretiming || $user || $deleted || $shaded || $noIconFound) {
236 $flags = '';
237 $string = '';
238 if ($deleted) {
239 $string = 'deleted';
240 $flags = 'd';
241 } elseif ($noIconFound) {
242 // This is ONLY for creating icons with "?" on easily...
243 $string = 'no_icon_found';
244 $flags = 'x';
245 } else {
246 if ($hidden) {
247 $string .= 'hidden';
248 }
249 if ($timing) {
250 $string .= 'timing';
251 }
252 if (!$string && $futuretiming) {
253 $string = 'futuretiming';
254 }
255 $flags .= ($hidden ? 'h' : '') . ($timing ? 't' : '') . ($futuretiming ? 'f' : '') . ($user ? 'u' : '') . ($protectSection ? 'p' : '') . ($shaded ? 's' : '');
256 }
257 // Create tagged icon file name:
258 $iconFileName_stateTagged = preg_replace('/.([[:alnum:]]+)$/', '__' . $flags . '.\\1', basename($iconfile));
259 // Check if tagged icon file name exists (a tagged icon means the icon base name with the flags added between body and extension of the filename, prefixed with underscore)
260 if (@is_file((dirname($absfile) . '/' . $iconFileName_stateTagged)) || @is_file(($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . '/' . dirname($iconfile) . '/' . $iconFileName_stateTagged))) {
261 // Look for [iconname]_xxxx.[ext]
262 return dirname($iconfile) . '/' . $iconFileName_stateTagged;
263 } else {
264 // Otherwise, create the icon:
265 $theRes = self::makeIcon($GLOBALS['BACK_PATH'] . $iconfile, $string, $user, $protectSection, $absfile, $iconFileName_stateTagged);
266 return $theRes;
267 }
268 } else {
269 return $iconfile;
270 }
271 }
272
273 /**
274 * Returns the src=... for the input $src value OR any alternative found in $TBE_STYLES['skinImg']
275 * Used for skinning the TYPO3 backend with an alternative set of icons
276 *
277 * @param string $backPath Current backpath to PATH_typo3 folder
278 * @param string $src Icon file name relative to PATH_typo3 folder
279 * @param string $wHattribs Default width/height, defined like 'width="12" height="14"'
280 * @param int $outputMode Mode: 0 (zero) is default and returns src/width/height. 1 returns value of src+backpath, 2 returns value of w/h.
281 * @return string Returns ' src="[backPath][src]" [wHattribs]'
282 * @see skinImgFile()
283 */
284 static public function skinImg($backPath, $src, $wHattribs = '', $outputMode = 0) {
285 static $cachedSkinImages = array();
286 $imageId = md5($backPath . $src . $wHattribs . $outputMode);
287 if (isset($cachedSkinImages[$imageId])) {
288 return $cachedSkinImages[$imageId];
289 }
290 // Setting source key. If the icon is referred to inside an extension, we homogenize the prefix to "ext/":
291 $srcKey = preg_replace('/^(\\.\\.\\/typo3conf\\/ext|sysext|ext)\\//', 'ext/', $src);
292 // LOOKING for alternative icons:
293 if ($GLOBALS['TBE_STYLES']['skinImg'][$srcKey]) {
294 // Slower or faster with is_array()? Could be used.
295 list($src, $wHattribs) = $GLOBALS['TBE_STYLES']['skinImg'][$srcKey];
296 } elseif ($GLOBALS['TBE_STYLES']['skinImgAutoCfg']) {
297 // Otherwise, test if auto-detection is enabled:
298 // Search for alternative icon automatically:
299 $fExt = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['forceFileExtension'];
300 $scaleFactor = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['scaleFactor'] ?: 1;
301 // Scaling factor
302 $lookUpName = $fExt ? preg_replace('/\\.[[:alnum:]]+$/', '', $srcKey) . '.' . $fExt : $srcKey;
303 // Set filename to look for
304 if ($fExt && !@is_file(($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . $lookUpName))) {
305 // Fallback to original filename if icon with forced extension doesn't exists
306 $lookUpName = $srcKey;
307 }
308 // If file is found:
309 if (@is_file(($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . $lookUpName))) {
310 // If there is a file...
311 $iInfo = @getimagesize(($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . $lookUpName));
312 // Get width/height:
313 // Set $src and $wHattribs:
314 $src = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'] . $lookUpName;
315 $wHattribs = 'width="' . round($iInfo[0] * $scaleFactor) . '" height="' . round($iInfo[1] * $scaleFactor) . '"';
316 }
317 // In any case, set currect src / wHattrib - this way we make sure that an entry IS found next time we hit the function,
318 // regardless of whether it points to a alternative icon or just the current.
319 $GLOBALS['TBE_STYLES']['skinImg'][$srcKey] = array($src, $wHattribs);
320 }
321 // Rendering disabled (greyed) icons using _i (inactive) as name suffix ("_d" is already used)
322 $matches = array();
323 $srcBasename = basename($src);
324 if (preg_match('/(.*)_i(\\....)$/', $srcBasename, $matches)) {
325 $temp_path = dirname(PATH_thisScript) . '/';
326 if (!@is_file(($temp_path . $backPath . $src))) {
327 $srcOrg = preg_replace('/_i' . preg_quote($matches[2], '/') . '$/', $matches[2], $src);
328 $src = self::makeIcon($backPath . $srcOrg, 'disabled', 0, FALSE, $temp_path . $backPath . $srcOrg, $srcBasename);
329 }
330 }
331 // Return icon source/wHattributes:
332 $output = '';
333 switch ($outputMode) {
334 case 0:
335 $output = ' src="' . $backPath . $src . '" ' . $wHattribs;
336 break;
337 case 1:
338 $output = $backPath . $src;
339 break;
340 case 2:
341 $output = $wHattribs;
342 break;
343 }
344 $cachedSkinImages[$imageId] = $output;
345 return $output;
346 }
347
348 /***********************************
349 *
350 * Other functions
351 *
352 ***********************************/
353 /**
354 * Creates the icon file for the function getIcon()
355 *
356 * @param string $iconfile Original unprocessed Icon file, relative path to PATH_typo3
357 * @param string $mode Mode string, eg. "deleted" or "futuretiming" determining how the icon will look
358 * @param int $user The number of the fe_group record uid if applicable
359 * @param bool $protectSection Flag determines if the protected-section icon should be applied.
360 * @param string $absFile Absolute path to file from which to create the icon.
361 * @param string $iconFileName_stateTagged The filename that this icon should have had, basically [icon base name]_[flags].[extension] - used for part of temporary filename
362 * @return string Filename relative to PATH_typo3
363 * @access private
364 */
365 static public function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged) {
366 $iconFileName = 'icon_' . GeneralUtility::shortMD5(($iconfile . '|' . $mode . '|-' . $user . '|' . $protectSection)) . '_' . $iconFileName_stateTagged . '.' . ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? 'png' : 'gif');
367 $mainpath = '../typo3temp/' . $iconFileName;
368 $path = PATH_site . 'typo3temp/' . $iconFileName;
369 if (file_exists($path)) {
370 // Returns if found in ../typo3temp/icons/
371 return $mainpath;
372 } else {
373 // Makes icon:
374 if (file_exists($absFile)) {
375 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
376 // Create image pointer, if possible
377 $im = self::imagecreatefrom($absFile);
378 if ($im < 0) {
379 return $iconfile;
380 }
381 // Converting to gray scale, dimming the icon:
382 if ($mode == 'disabled' or $mode != 'futuretiming' && $mode != 'no_icon_found' && !(!$mode && $user)) {
383 $totalImageColors = ImageColorsTotal($im);
384 for ($c = 0; $c < $totalImageColors; $c++) {
385 $cols = ImageColorsForIndex($im, $c);
386 $newcol = round(($cols['red'] + $cols['green'] + $cols['blue']) / 3);
387 $lighten = $mode == 'disabled' ? 2.5 : 2;
388 $newcol = round(255 - (255 - $newcol) / $lighten);
389 ImageColorSet($im, $c, $newcol, $newcol, $newcol);
390 }
391 }
392 // Applying user icon, if there are access control on the item:
393 if ($user) {
394 if ($user < 100) {
395 // Apply user number only if lower than 100
396 $black = ImageColorAllocate($im, 0, 0, 0);
397 imagefilledrectangle($im, 0, 0, $user > 10 ? 9 : 5, 8, $black);
398 $white = ImageColorAllocate($im, 255, 255, 255);
399 imagestring($im, 1, 1, 1, $user, $white);
400 }
401 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_group.gif');
402 if ($ol_im < 0) {
403 return $iconfile;
404 }
405 self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
406 }
407 // Applying overlay based on mode:
408 if ($mode) {
409 unset($ol_im);
410 switch ($mode) {
411 case 'deleted':
412 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_deleted.gif');
413 break;
414 case 'futuretiming':
415 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
416 break;
417 case 'timing':
418 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
419 break;
420 case 'hiddentiming':
421 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden_timing.gif');
422 break;
423 case 'no_icon_found':
424 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_no_icon_found.gif');
425 break;
426 case 'disabled':
427 // is already greyed - nothing more
428 $ol_im = 0;
429 break;
430 case 'hidden':
431
432 default:
433 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden.gif');
434 }
435 if ($ol_im < 0) {
436 return $iconfile;
437 }
438 if ($ol_im) {
439 self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
440 }
441 }
442 // Protect-section icon:
443 if ($protectSection) {
444 $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_sub5.gif');
445 if ($ol_im < 0) {
446 return $iconfile;
447 }
448 self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
449 }
450 // Create the image as file, destroy GD image and return:
451 @self::imagemake($im, $path);
452 GraphicalFunctions::gifCompress($path, 'IM');
453 ImageDestroy($im);
454 return $mainpath;
455 } else {
456 return $iconfile;
457 }
458 } else {
459 return $GLOBALS['BACK_PATH'] . 'gfx/default.gif';
460 }
461 }
462 }
463
464 /**
465 * The necessity of using this function for combining two images if GD is version 2 is that
466 * GD2 cannot manage to combine two indexed-color images without totally spoiling everything.
467 * In class \TYPO3\CMS\Core\Imaging\GraphicalFunctions this was solved by combining the images
468 * onto a first created true color image.
469 * However it has turned out that this method will not work if the indexed png-files contains transparency.
470 * So I had to turn my attention to ImageMagick - my 'enemy of death'.
471 * And so it happend - ImageMagick is now used to combine my two indexed-color images with transparency. And that works.
472 * Of course it works only if ImageMagick is able to create valid png-images - which you cannot be sure of with older versions (still 5+)
473 * The only drawback is (apparently) that IM creates true-color png's. The transparency of these will not be shown by MSIE on windows at this time (although it's straight 0%/100% transparency!) and the file size may be larger.
474 *
475 * @param resource $destinationImage Destination image
476 * @param resource $sourceImage Source image
477 * @param int $destinationX Destination x-coordinate
478 * @param int $destinationY Destination y-coordinate
479 * @param int $sourceX Source x-coordinate
480 * @param int $sourceY Source y-coordinate
481 * @param int $destinationWidth Destination width
482 * @param int $destinationHeight Destination height
483 * @param int $sourceWidth Source width
484 * @param int $sourceHeight Source height
485 * @return void
486 * @access private
487 * @see \TYPO3\CMS\Core\Imaging\GraphicalFunctions::imagecopyresized()
488 */
489 static public function imagecopyresized(&$destinationImage, $sourceImage, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight) {
490 imagecopyresized($destinationImage, $sourceImage, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
491 }
492
493 /**
494 * Create new image pointer from input file (either gif/png, in case the wrong format it is converted by \TYPO3\CMS\Core\Imaging\GraphicalFunctions::readPngGif())
495 *
496 * @param string $file Absolute filename of the image file from which to start the icon creation.
497 * @return resource|int If success, image pointer, otherwise -1
498 * @access private
499 * @see \TYPO3\CMS\Core\Imaging\GraphicalFunctions::readPngGif
500 */
501 static public function imagecreatefrom($file) {
502 $file = GraphicalFunctions::readPngGif($file, $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']);
503 if (!$file) {
504 return -1;
505 }
506
507 return $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? imagecreatefrompng($file) : imagecreatefromgif($file);
508 }
509
510 /**
511 * Write the icon in $im pointer to $path
512 *
513 * @param resource $im Pointer to GDlib image resource
514 * @param string $path Absolute path to the filename in which to write the icon.
515 * @return void
516 * @access private
517 */
518 static public function imagemake($im, $path) {
519 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
520 @ImagePng($im, $path);
521 } else {
522 @ImageGif($im, $path);
523 }
524 if (@is_file($path)) {
525 GeneralUtility::fixPermissions($path);
526 }
527 }
528
529 /**********************************************
530 * SPRITE ICON API
531 *
532 * The Sprite Icon API helps you to quickly get the HTML for any icon you want
533 * this is typically wrapped in a <span> tag with corresponding CSS classes that
534 * will be responsible for the
535 *
536 * There are four ways to use this API:
537 *
538 * 1) for any given TCA record
539 * $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $row);
540 *
541 * 2) for any given File of Folder object
542 * $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForResource($fileOrFolderObject);
543 *
544 * 3) for any given file
545 * $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('myimage.png');
546 *
547 * 4) for any other icon you know the name
548 * $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open');
549 *
550 **********************************************/
551 /**
552 * This generic method is used throughout the TYPO3 Backend to show icons
553 * in any variation which are not bound to any resource object (see getSpriteIconForResource)
554 * or database record (see getSpriteIconForRecord)
555 *
556 * Generates a HTML tag with proper CSS classes. The TYPO3 skin has
557 * defined these CSS classes already to have a pre-defined background image,
558 * and the correct background-position to show the necessary icon.
559 *
560 * If no options or overlays are given, the icon will be cached in
561 * $spriteIconCache.
562 *
563 * @param string $iconName The name of the icon to fetch
564 * @param array $options An associative array with additional options and attributes for the tag. by default, the key is the name of the attribute, and the value is the parameter string that is set. However, there are some additional special reserved keywords that can be used as keys: "html" (which is the HTML that will be inside the icon HTML tag), "tagName" (which is an alternative tagName than "span"), and "class" (additional class names that will be merged with the sprite icon CSS classes)
565 * @param array $overlays An associative array with the icon-name as key, and the options for this overlay as an array again (see the parameter $options again)
566 *
567 * @return string The full HTML tag (usually a <span>)
568 * @access public
569 */
570 static public function getSpriteIcon($iconName, array $options = array(), array $overlays = array()) {
571 // Check if icon can be cached and return cached version if present
572 if (empty($options) && empty($overlays)) {
573 if (isset(static::$spriteIconCache[$iconName])) {
574 return static::$spriteIconCache[$iconName];
575 }
576 $iconIsCacheable = TRUE;
577 } else {
578 $iconIsCacheable = FALSE;
579 }
580
581 $innerHtml = isset($options['html']) ? $options['html'] : NULL;
582 $tagName = isset($options['tagName']) ? $options['tagName'] : NULL;
583
584 // Deal with the overlays
585 foreach ($overlays as $overlayIconName => $overlayOptions) {
586 $overlayOptions['html'] = $innerHtml;
587 $overlayOptions['class'] = (isset($overlayOptions['class']) ? $overlayOptions['class'] . ' ' : '') . 't3-icon-overlay';
588 $innerHtml = self::getSpriteIcon($overlayIconName, $overlayOptions);
589 }
590
591 $availableIcons = isset($GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'])
592 ? (array)$GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable']
593 : array();
594 if ($iconName !== 'empty-empty' && !in_array($iconName, $availableIcons, TRUE)) {
595 $iconName = 'status-status-icon-missing';
596 }
597
598 // Create the CSS class
599 $options['class'] = self::getSpriteIconClasses($iconName) . (isset($options['class']) ? ' ' . $options['class'] : '');
600 unset($options['html'], $options['tagName']);
601 $spriteHtml = self::buildSpriteHtmlIconTag($options, $innerHtml, $tagName);
602
603 // Store result in cache if possible
604 if ($iconIsCacheable) {
605 static::$spriteIconCache[$iconName] = $spriteHtml;
606 }
607 return $spriteHtml;
608 }
609
610 /**
611 * This method is used throughout the TYPO3 Backend to show icons for a file type
612 *
613 * Generates a HTML tag with proper CSS classes. The TYPO3 skin has defined these CSS classes
614 * already to have a pre-defined background image, and the correct background-position to show
615 * the necessary icon.
616 *
617 * @param string $fileExtension The name of the icon to fetch, can be a file extension, full file path or one of the special keywords "folder" or "mount
618 * @param array $options An associative array with additional options and attributes for the tag. by default, the key is the name of the attribute, and the value is the parameter string that is set. However, there are some additional special reserved keywords that can be used as keys: "html" (which is the HTML that will be inside the icon HTML tag), "tagName" (which is an alternative tagName than "span"), and "class" (additional class names that will be merged with the sprite icon CSS classes)
619 * @return string The full HTML tag (usually a <span>)
620 * @access public
621 */
622 static public function getSpriteIconForFile($fileExtension, array $options = array()) {
623 $innerHtml = isset($options['html']) ? $options['html'] : NULL;
624 $tagName = isset($options['tagName']) ? $options['tagName'] : NULL;
625 // Create the CSS class
626 $options['class'] = self::mapFileExtensionToSpriteIconClass($fileExtension) . (isset($options['class']) ? ' ' . $options['class'] : '');
627 unset($options['html']);
628 unset($options['tagName']);
629 return self::buildSpriteHtmlIconTag($options, $innerHtml, $tagName);
630 }
631
632 /**
633 * Generates the spriteicon css classes name for a given path or fileExtension
634 * usually called from getSpriteIconForFile or ExtJs Provider
635 *
636 * @param string $fileExtension FileExtension can be jpg, gif etc, but also be 'mount' or 'folder', but can also be a full path which will be resolved then
637 * @return string The string of the CSS class, see \TYPO3\CMS\Backend\Utility\IconUtility::$fileSpriteIconNames
638 * @access private
639 */
640 static public function mapFileExtensionToSpriteIconClass($fileExtension) {
641 return self::getSpriteIconClasses(self::mapFileExtensionToSpriteIconName($fileExtension));
642 }
643
644 /**
645 * Generates the spriteicon name for a given path or fileExtension
646 * usually called from mapFileExtensionToSpriteIconClass and tceforms
647 *
648 * @param string $fileExtension FileExtension can be jpg, gif etc, but also be 'mount' or 'folder', but can also be a full path which will be resolved then
649 * @return string The string of the CSS class, see \TYPO3\CMS\Backend\Utility\IconUtility::$fileSpriteIconNames
650 * @access private
651 */
652 static public function mapFileExtensionToSpriteIconName($fileExtension) {
653 // If the file is a whole file with name etc (mainly, if it has a "." or a "/"),
654 // then it is checked whether it is a valid directory
655 if (strpos($fileExtension, '.') !== FALSE || strpos($fileExtension, '/') !== FALSE) {
656 // Check if it is a directory
657 $filePath = dirname(GeneralUtility::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $fileExtension;
658 $path = GeneralUtility::resolveBackPath($filePath);
659 if (is_dir($path) || substr($fileExtension, -1) === '/' || substr($fileExtension, -1) === '\\') {
660 $fileExtension = 'folder';
661 } else {
662 if (($pos = strrpos($fileExtension, '.')) !== FALSE) {
663 $fileExtension = strtolower(substr($fileExtension, $pos + 1));
664 } else {
665 $fileExtension = 'default';
666 }
667 }
668 }
669 // If the file extension is not valid
670 // then use the default one
671 if (!isset(self::$fileSpriteIconNames[$fileExtension])) {
672 $fileExtension = 'default';
673 }
674 $iconName = self::$fileSpriteIconNames[$fileExtension];
675 return $iconName;
676 }
677
678 /**
679 * This method is used throughout the TYPO3 Backend to show icons for a DB record
680 *
681 * Generates a HTML tag with proper CSS classes. The TYPO3 skin has defined these CSS classes
682 * already to have a pre-defined background image, and the correct background-position to show
683 * the necessary icon.
684 *
685 * @param string $table The TCA table name
686 * @param array $row The DB record of the TCA table
687 * @param array $options An associative array with additional options and attributes for the tag. by default, the key is the name of the attribute, and the value is the parameter string that is set. However, there are some additional special reserved keywords that can be used as keys: "html" (which is the HTML that will be inside the icon HTML tag), "tagName" (which is an alternative tagName than "span"), and "class" (additional class names that will be merged with the sprite icon CSS classes)
688 * @return string The full HTML tag (usually a <span>)
689 * @access public
690 */
691 static public function getSpriteIconForRecord($table, array $row, array $options = array()) {
692 $innerHtml = isset($options['html']) ? $options['html'] : NULL;
693 $tagName = isset($options['tagName']) ? $options['tagName'] : NULL;
694 // Overlay this record icon with the status of the row
695 $overlaySpriteIconName = self::mapRecordOverlayToSpriteIconName($table, $row);
696 if ($overlaySpriteIconName) {
697 $overlayOptions = array(
698 'html' => $innerHtml,
699 'class' => 't3-icon-overlay'
700 );
701 $innerHtml = self::getSpriteIcon($overlaySpriteIconName, $overlayOptions);
702 }
703 // Fetch the name for the CSS class, based on the $row
704 $options['class'] = self::mapRecordTypeToSpriteIconClass($table, $row) . (isset($options['class']) ? ' ' . $options['class'] : '');
705 unset($options['html']);
706 unset($options['tagName']);
707 return self::buildSpriteHtmlIconTag($options, $innerHtml, $tagName);
708 }
709
710 /**
711 * This method is used throughout the TYPO3 Backend to show icons for files and folders
712 *
713 * The method takes care of the translation of file extension to proper icon and for folders
714 * it will return the icon depending on the role of the folder.
715 *
716 * If the given resource is a folder there are some additional options that can be used:
717 * - mount-root => TRUE (to indicate this is the root of a mount)
718 * - folder-open => TRUE (to indicate that the folder is opened in the file tree)
719 *
720 * There is a hook in place to manipulate the icon name and overlays.
721 *
722 * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource
723 * @param array $options An associative array with additional options and attributes for the tag. See self::getSpriteIcon()
724 * @param array $overlays An associative array with the icon-name as key, and the options for this overlay as an array again (see the parameter $options again)
725 * @return string
726 * @throws \UnexpectedValueException
727 */
728 static public function getSpriteIconForResource(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, array $options = array(), array $overlays = array()) {
729 // Folder
730 if ($resource instanceof \TYPO3\CMS\Core\Resource\FolderInterface) {
731 $iconName = NULL;
732 $role = $resource->getRole();
733 // non browsable storage
734 if ($resource->getStorage()->isBrowsable() === FALSE && !empty($options['mount-root'])) {
735 $iconName = 'apps-filetree-folder-locked';
736 } else {
737 // storage root
738 if ($resource->getStorage()->getRootLevelFolder()->getIdentifier() === $resource->getIdentifier()) {
739 $iconName = 'apps-filetree-root';
740 }
741
742
743 // user/group mount root
744 if (!empty($options['mount-root'])) {
745 $iconName = 'apps-filetree-mount';
746 if ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_READONLY_MOUNT) {
747 $overlays['status-overlay-locked'] = array();
748 } elseif ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_USER_MOUNT) {
749 $overlays['status-overlay-access-restricted'] = array();
750 }
751 }
752
753 if ($iconName === NULL) {
754 // in folder tree view $options['folder-open'] can define a open folder icon
755 if (!empty($options['folder-open'])) {
756 $iconName = 'apps-filetree-folder-opened';
757 } else {
758 $iconName = 'apps-filetree-folder-default';
759 }
760
761 if ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_TEMPORARY) {
762 $iconName = 'apps-filetree-folder-temp';
763 } elseif ($role === \TYPO3\CMS\Core\Resource\FolderInterface::ROLE_RECYCLER) {
764 $iconName = 'apps-filetree-folder-recycler';
765 }
766 }
767
768 // if locked add overlay
769 if ($resource instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder ||
770 !$resource->getStorage()->checkFolderActionPermission('add', $resource)
771 ) {
772 $overlays['status-overlay-locked'] = array();
773 }
774 }
775
776
777
778 // File
779 } else {
780 $iconName = self::mapFileExtensionToSpriteIconName($resource->getExtension());
781
782 if ($resource instanceof \TYPO3\CMS\Core\Resource\File && $resource->isMissing()) {
783 $overlays['status-overlay-missing'] = array();
784 }
785 }
786
787 // Hook: allow some other process to influence the choice of icon and overlays
788 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'])) {
789 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideResourceIcon'] as $classRef) {
790 $hookObject = GeneralUtility::getUserObj($classRef);
791 if (!$hookObject instanceof IconUtilityOverrideResourceIconHookInterface) {
792 throw new \UnexpectedValueException('$hookObject must implement interface ' . \TYPO3\CMS\Backend\Utility\IconUtilityOverrideResourceIconHookInterface::class, 1393574895);
793 }
794 $hookObject->overrideResourceIcon($resource, $iconName, $options, $overlays);
795 }
796 }
797
798 unset($options['mount-root']);
799 unset($options['folder-open']);
800 return self::getSpriteIcon($iconName, $options, $overlays);
801 }
802
803 /**
804 * this helper functions looks up the column that is used for the type of
805 * the chosen TCA table. And then fetches the corresponding class
806 * based on the chosen iconsprite class in this TCA
807 * The TCA looks up
808 * - [ctrl][typeicon_column]
809 * -
810 * This method solely takes care of the type of this record, not any
811 * statuses, used for overlays.
812 * You should not use this directly besides if you need classes for ExtJS iconCls.
813 *
814 * see ext:core/Configuration/TCA/pages.php for an example with the TCA table "pages"
815 *
816 * @param string $table The TCA table
817 * @param array $row The selected record
818 * @return string The CSS class for the sprite icon of that DB record
819 * @access private
820 */
821 static public function mapRecordTypeToSpriteIconClass($table, array $row) {
822 return self::getSpriteIconClasses(self::mapRecordTypeToSpriteIconName($table, $row));
823 }
824
825 /**
826 * this helper functions looks up the column that is used for the type of
827 * the chosen TCA table. And then fetches the corresponding iconname
828 * based on the chosen iconsprite class in this TCA
829 * The TCA looks up
830 * - [ctrl][typeicon_column]
831 * -
832 * This method solely takes care of the type of this record, not any
833 * statuses, used for overlays.
834 * You should not use this directly besides if you need it in tceforms/core classes
835 *
836 * see ext:core/Configuration/TCA/pages.php for an example with the TCA table "pages"
837 *
838 * @param string $tableThe TCA table
839 * @param array $row The selected record
840 * @return string The CSS class for the sprite icon of that DB record
841 * @access private
842 */
843 static public function mapRecordTypeToSpriteIconName($table, array $row) {
844 $recordType = array();
845 $ref = NULL;
846 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_column'])) {
847 $column = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
848 if (isset($row[$column])) {
849 $recordType[1] = $row[$column];
850 } else {
851 $recordType[1] = 'default';
852 }
853 // Workaround to give nav_hide pages a complete different icon
854 // Although it's not a separate doctype
855 // and to give root-pages an own icon
856 if ($table === 'pages') {
857 if ($row['nav_hide']) {
858 $recordType[2] = $recordType[1] . '-hideinmenu';
859 }
860 if ($row['is_siteroot']) {
861 $recordType[3] = $recordType[1] . '-root';
862 }
863 if ($row['module']) {
864 $recordType[4] = 'contains-' . $row['module'];
865 }
866 if ((int)$row['content_from_pid'] > 0) {
867 $recordType[4] = (int)$row['nav_hide'] === 0 ? 'page-contentFromPid' : 'page-contentFromPid-hideinmenu';
868 }
869 }
870 if (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
871 foreach ($recordType as $key => $type) {
872 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type])) {
873 $recordType[$key] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type];
874 } else {
875 unset($recordType[$key]);
876 }
877 }
878 $recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
879 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask'])) {
880 $recordType[5] = str_replace('###TYPE###', $row[$column], $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask']);
881 }
882 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'])) {
883 $parameters = array('row' => $row);
884 $recordType[6] = GeneralUtility::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'], $parameters, $ref);
885 }
886 } else {
887 foreach ($recordType as &$type) {
888 $type = 'tcarecords-' . $table . '-' . $type;
889 }
890 unset($type);
891 $recordType[0] = 'tcarecords-' . $table . '-default';
892 }
893 } else {
894 if (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
895 $recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
896 } else {
897 $recordType[0] = 'tcarecords-' . $table . '-default';
898 }
899 }
900 krsort($recordType);
901 if (is_array($GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'])) {
902 foreach ($recordType as $iconName) {
903 if (in_array($iconName, $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'])) {
904 return $iconName;
905 }
906 }
907 }
908 return 'status-status-icon-missing';
909 }
910
911 /**
912 * this helper functions checks if the DB record ($row) has any special status
913 * based on the TCA settings like hidden, starttime etc, and then returns a specific
914 * Sprite icon class for the overlay of this DB record
915 * This method solely takes care of the overlay of this record, not any type
916 *
917 * Please note that this only returns one overlay, one status, that is prioritized
918 * by $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconRecordOverlayPriorities']
919 * We wanted to not have these icons blown over by tons of overlays, so this is limited
920 * to just one.
921 *
922 * see ext:core/Configuration/DefaultConfiguration.php for the default options, you will find
923 * $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconRecordOverlayNames'] that shows
924 * the list of CSS classes that will be used for the sprites, mapped to the statuses here
925 *
926 * @param string $table The TCA table
927 * @param array $row The selected record
928 * @return string The CSS class for the sprite icon of that DB record
929 * @access private
930 */
931 static public function mapRecordOverlayToSpriteIconName($table, array $row) {
932 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
933 // Calculate for a given record the actual visibility at the moment
934 $status = array(
935 'hidden' => FALSE,
936 'starttime' => FALSE,
937 'endtime' => FALSE,
938 'futureendtime' => FALSE,
939 'fe_group' => FALSE,
940 'deleted' => FALSE,
941 'protectedSection' => FALSE,
942 'nav_hide' => $row['nav_hide'] ? TRUE : FALSE,
943 'noIconFound' => $row['_NO_ICON_FOUND'] ? TRUE : FALSE
944 );
945 // Icon state based on "enableFields":
946 if (is_array($tcaCtrl['enablecolumns'])) {
947 $enCols = $tcaCtrl['enablecolumns'];
948 // If "hidden" is enabled:
949 if ($tcaCtrl['enablecolumns']['disabled'] && $row[$tcaCtrl['enablecolumns']['disabled']]) {
950 $status['hidden'] = TRUE;
951 }
952 // If a "starttime" is set and higher than current time:
953 if ($tcaCtrl['enablecolumns']['starttime'] && $GLOBALS['EXEC_TIME'] < (int)$row[$tcaCtrl['enablecolumns']['starttime']]) {
954 $status['starttime'] = TRUE;
955 }
956 // If an "endtime" is set
957 if ($tcaCtrl['enablecolumns']['endtime']) {
958 if ((int)$row[$tcaCtrl['enablecolumns']['endtime']] > 0) {
959 if ((int)$row[$tcaCtrl['enablecolumns']['endtime']] < $GLOBALS['EXEC_TIME']) {
960 // End-timing applies at this point.
961 $status['endtime'] = TRUE;
962 } else {
963 // End-timing WILL apply in the future for this element.
964 $status['futureendtime'] = TRUE;
965 }
966 }
967 }
968 // If a user-group field is set
969 if ($tcaCtrl['enablecolumns']['fe_group'] && $row[$tcaCtrl['enablecolumns']['fe_group']]) {
970 $status['fe_group'] = TRUE;
971 }
972 }
973 // If "deleted" flag is set (only when listing records which are also deleted!)
974 if ($row[$tcaCtrl['delete']]) {
975 $status['deleted'] = TRUE;
976 }
977 // Detecting extendToSubpages (for pages only)
978 if ($table == 'pages' && $row['extendToSubpages']) {
979 $status['protectedSection'] = TRUE;
980 }
981 // Hook: allow some other process to influence the choice of icon overlay
982 // The method called receives the table name, the current row and the current status array as parameters
983 // The status array should be passed as a reference and in order to be modified within the hook
984 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'])) {
985 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'] as $classRef) {
986 $hookObject = GeneralUtility::getUserObj($classRef);
987 if (method_exists($hookObject, 'overrideIconOverlay')) {
988 $hookObject->overrideIconOverlay($table, $row, $status);
989 }
990 }
991 }
992 // Now only show the status with the highest priority
993 $priorities = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayPriorities'];
994 $iconName = '';
995 if (is_array($priorities)) {
996 foreach ($priorities as $priority) {
997 if ($status[$priority]) {
998 $iconName = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayNames'][$priority];
999 break;
1000 }
1001 }
1002 }
1003 return $iconName;
1004 }
1005
1006 /**
1007 * generic method to create the final CSS classes based on the sprite icon name
1008 * with the base class and splits the name into parts
1009 * is usually called by the methods that are responsible for fetching the names
1010 * out of the file name, or the record type
1011 *
1012 * @param string $iconName Iconname like 'actions-document-new'
1013 * @return string A list of all CSS classes needed for the HTML tag
1014 */
1015 static public function getSpriteIconClasses($iconName) {
1016 $cssClasses = ($baseCssClass = 't3-icon');
1017 $parts = explode('-', $iconName);
1018 if (count($parts) > 1) {
1019 // Will be something like "t3-icon-actions"
1020 $cssClasses .= ' ' . ($baseCssClass . '-' . $parts[0]);
1021 // Will be something like "t3-icon-actions-document"
1022 $cssClasses .= ' ' . ($baseCssClass . '-' . $parts[0] . '-' . $parts[1]);
1023 // Will be something like "t3-icon-document-new"
1024 $cssClasses .= ' ' . ($baseCssClass . '-' . substr($iconName, (strlen($parts[0]) + 1)));
1025 }
1026 static::emitBuildSpriteIconClassesSignal($iconName, $cssClasses);
1027 return $cssClasses;
1028 }
1029
1030 /**
1031 * low level function that generates the HTML tag for the sprite icon
1032 * is usually called by the three API classes (getSpriteIcon, getSpriteIconForFile, getSpriteIconForRecord)
1033 * it does not care about classes or anything else, but just plainly builds the HTML tag
1034 *
1035 * @param array $tagAttributes An associative array of additional tagAttributes for the HTML tag
1036 * @param string $innerHtml The content within the tag, a "&nbsp;" by default
1037 * @param string $tagName The name of the HTML element that should be used (span by default)
1038 * @return string The sprite html icon tag
1039 */
1040 static protected function buildSpriteHtmlIconTag(array $tagAttributes, $innerHtml = NULL, $tagName = NULL) {
1041 list($tagAttributes, $innerHtml, $tagName) = static::emitBuildSpriteHtmlIconTagSignal($tagAttributes, $innerHtml, $tagName);
1042
1043 $innerHtml = $innerHtml === NULL ? ' ' : $innerHtml;
1044 $tagName = $tagName === NULL ? 'span' : $tagName;
1045 $attributes = '';
1046 foreach ($tagAttributes as $attribute => $value) {
1047 $attributes .= ' ' . htmlspecialchars($attribute) . '="' . htmlspecialchars($value) . '"';
1048 }
1049
1050 return '<' . $tagName . $attributes . '>' . $innerHtml . '</' . $tagName . '>';
1051 }
1052
1053 /**
1054 * @param array $tagAttributes An associative array of additional tagAttributes for the HTML tag
1055 * @param string $innerHtml The content within the tag, NULL by default
1056 * @param string $tagName The name of the HTML element that should be used (span by default), NULL by default
1057 * @return array
1058 */
1059 static protected function emitBuildSpriteHtmlIconTagSignal(array $tagAttributes, $innerHtml, $tagName) {
1060 return static::getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Backend\Utility\IconUtility::class, 'buildSpriteHtmlIconTag', array($tagAttributes, $innerHtml, $tagName));
1061 }
1062
1063 /**
1064 * Emits a signal right after the CSS classes are built. This is useful if somebody only
1065 * fetches the CSS classes via IconUtility and not the whole sprite span tag.
1066 *
1067 * @param string $iconName The name of the icon
1068 * @param string $cssClasses the CSS classes to be used as a string
1069 */
1070 static protected function emitBuildSpriteIconClassesSignal($iconName, &$cssClasses) {
1071 static::getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Backend\Utility\IconUtility::class, 'buildSpriteIconClasses', array($iconName, &$cssClasses));
1072 }
1073
1074 /**
1075 * Get the SignalSlot dispatcher
1076 *
1077 * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
1078 */
1079 static protected function getSignalSlotDispatcher() {
1080 return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
1081 }
1082
1083 }