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