9c9333ff8943c876beccdbdae5a1a677755f443c
2 /***************************************************************
5 * (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Contains class for icon generation in the backend
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 85: class t3lib_iconWorks
42 * 100: function getIconImage($table,$row=array(),$backPath,$params='',$shaded=FALSE)
43 * 118: function getIcon($table,$row=array(),$shaded=FALSE)
44 * 264: function skinImg($backPath,$src,$wHattribs='',$outputMode=0)
46 * SECTION: Other functions
47 * 353: function makeIcon($iconfile,$mode, $user, $protectSection,$absFile,$iconFileName_stateTagged)
48 * 475: function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h)
49 * 505: function imagecreatefrom($file)
50 * 522: function imagemake($im, $path)
53 * (This index is automatically created/updated by the extension "extdeveval")
59 * Icon generation, backend
60 * This library has functions that returns - and if necessary creates - the icon for an element in TYPO3
62 * Expects global vars:
65 * - $TCA, $PAGES_TYPES
69 * These functions are strongly related to the interface of TYPO3.
70 * The class is included in eg. init.php
71 * ALL functions called without making a class instance, eg. "t3lib_iconWorks::getIconImage()"
73 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
77 final class t3lib_iconWorks
{
79 public static $fileSpriteIconNames = array(
80 'htm' => 'mimetypes-text-html',
81 'html' => 'mimetypes-text-html',
82 'css' => 'mimetypes-text-css',
83 'js' => 'mimetypes-text-js',
84 'csv' => 'mimetypes-text-csv',
85 'php' => 'mimetypes-text-php',
86 'php6' => 'mimetypes-text-php',
87 'php5' => 'mimetypes-text-php',
88 'php4' => 'mimetypes-text-php',
89 'php3' => 'mimetypes-text-php',
90 'inc' => 'mimetypes-text-php',
91 'ts' => 'mimetypes-text-ts',
92 'txt' => 'mimetypes-text-text',
93 'class' => 'mimetypes-text-text',
94 'tmpl' => 'mimetypes-text-text',
95 'jpg' => 'mimetypes-media-image',
96 'jpeg' => 'mimetypes-media-image',
97 'gif' => 'mimetypes-media-image',
98 'png' => 'mimetypes-media-image',
99 'bmp' => 'mimetypes-media-image',
100 'tif' => 'mimetypes-media-image',
101 'tga' => 'mimetypes-media-image',
102 'psd' => 'mimetypes-media-image',
103 'eps' => 'mimetypes-media-image',
104 'avi' => 'mimetypes-media-video',
105 'mpg' => 'mimetypes-media-video',
106 'mpeg' => 'mimetypes-media-video',
107 'mov' => 'mimetypes-media-video',
108 'wav' => 'mimetypes-media-audio',
109 'mp3' => 'mimetypes-media-audio',
110 'mid' => 'mimetypes-media-audio',
111 'swf' => 'mimetypes-media-flash',
112 'swa' => 'mimetypes-media-flash',
113 'exe' => 'mimetypes-executable-executable',
114 'com' => 'mimetypes-executable-executable',
115 't3x' => 'mimetypes-compressed',
116 't3d' => 'mimetypes-compressed',
117 'zip' => 'mimetypes-compressed',
118 'tgz' => 'mimetypes-compressed',
119 'gz' => 'mimetypes-compressed',
120 'pdf' => 'mimetypes-pdf',
121 'doc' => 'mimetypes-word',
122 'sxw' => 'mimetypes-word',
123 'rtf' => 'mimetypes-word',
124 'xls' => 'mimetypes-excel',
125 'sxc' => 'mimetypes-excel',
126 'ppt' => 'mimetypes-powerpoint',
127 'mount' => 'apps-filetree-mount',
128 'folder' => 'apps-filetree-folder-default',
129 'default' => 'mimetypes-other-other'
133 * Returns an icon image tag, 18x16 pixels, based on input information.
134 * This function is recommended to use in your backend modules.
137 * @param string The table name
138 * @param array The table row ("enablefields" are at least needed for correct icon display and for pages records some more fields in addition!)
139 * @param string The backpath to the main TYPO3 directory (relative path back to PATH_typo3)
140 * @param string Additional attributes for the image tag
141 * @param boolean If set, the icon will be grayed/shaded
142 * @return string <img>-tag
145 public static function getIconImage($table, $row = array(), $backPath, $params = '', $shaded = FALSE) {
147 self
::skinImg($backPath, self
::getIcon($table, $row, $shaded), 'width="18" height="16"') .
148 (trim($params) ?
' ' . trim($params) : '');
149 if (!stristr($str, 'alt="')) {
157 * Creates the icon for input table/row
158 * Returns filename for the image icon, relative to PATH_typo3
161 * @param string The table name
162 * @param array The table row ("enablefields" are at least needed for correct icon display and for pages records some more fields in addition!)
163 * @param boolean If set, the icon will be grayed/shaded
164 * @return string Icon filename
165 * @see getIconImage()
167 public static function getIcon($table, $row = array(), $shaded = FALSE) {
168 global $TCA, $PAGES_TYPES, $ICON_TYPES;
171 $doNotGenerateIcon = $GLOBALS['TYPO3_CONF_VARS']['GFX']['noIconProc']; // If set, the icon will NOT be generated with GDlib. Rather the icon will be looked for as [iconfilename]_X.[extension]
172 $doNotRenderUserGroupNumber = TRUE; // If set, then the usergroup number will NOT be printed unto the icon. NOTICE. the icon is generated only if a default icon for groups is not found... So effectively this is ineffective...
175 if ($TCA[$table]['ctrl']['versioningWS']) {
176 switch ((int) $row['t3ver_state']) {
178 return 'gfx/i/shadow_hide.png';
181 return 'gfx/i/shadow_delete.png';
184 return 'gfx/i/shadow_moveto_plh.png';
187 return 'gfx/i/shadow_moveto_pointer.png';
192 // First, find the icon file name. This can depend on configuration in TCA, field values and more:
193 if ($table == 'pages') {
194 // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
195 if ($row['nav_hide'] && ($row['doktype'] == t3lib_pageSelect
::DOKTYPE_DEFAULT ||
$row['doktype'] == t3lib_pageSelect
::DOKTYPE_ADVANCED
)) {
196 $row['doktype'] = t3lib_pageSelect
::DOKTYPE_HIDE_IN_MENU
;
197 } // Workaround to change the icon if "Hide in menu" was set
199 if (!$iconfile = $PAGES_TYPES[$row['doktype']]['icon']) {
200 $iconfile = $PAGES_TYPES['default']['icon'];
202 if ($row['module'] && $ICON_TYPES[$row['module']]['icon']) {
203 $iconfile = $ICON_TYPES[$row['module']]['icon'];
206 if (!$iconfile = $TCA[$table]['ctrl']['typeicons'][$row[$TCA[$table]['ctrl']['typeicon_column']]]) {
207 $iconfile = (($TCA[$table]['ctrl']['iconfile']) ?
$TCA[$table]['ctrl']['iconfile'] : $table . '.gif');
211 // Setting path of iconfile if not already set. Default is "gfx/i/"
212 if (!strstr($iconfile, '/')) {
213 $iconfile = 'gfx/i/' . $iconfile;
216 // Setting the absolute path where the icon should be found as a file:
217 if (substr($iconfile, 0, 3) == '../') {
218 $absfile = PATH_site
. substr($iconfile, 3);
220 $absfile = PATH_typo3
. $iconfile;
223 // Initializing variables, all booleans except otherwise stated:
226 $futuretiming = FALSE;
227 $user = FALSE; // In fact an integer value...
229 $protectSection = FALSE; // Set, if a page-record (only pages!) has the extend-to-subpages flag set.
230 $noIconFound = $row['_NO_ICON_FOUND'] ?
TRUE : FALSE;
231 // + $shaded which is also boolean!
233 // Icon state based on "enableFields":
234 if (is_array($TCA[$table]['ctrl']['enablecolumns'])) {
235 $enCols = $TCA[$table]['ctrl']['enablecolumns'];
236 // If "hidden" is enabled:
237 if ($enCols['disabled']) {
238 if ($row[$enCols['disabled']]) {
242 // If a "starttime" is set and higher than current time:
243 if ($enCols['starttime']) {
244 if ($GLOBALS['EXEC_TIME'] < intval($row[$enCols['starttime']])) {
246 // ...And if "endtime" is NOT set:
247 if (intval($row[$enCols['endtime']]) == 0) {
248 $futuretiming = TRUE;
252 // If an "endtime" is set:
253 if ($enCols['endtime']) {
254 if (intval($row[$enCols['endtime']]) > 0) {
255 if (intval($row[$enCols['endtime']]) < $GLOBALS['EXEC_TIME']) {
256 $timing = TRUE; // End-timing applies at this point.
258 $futuretiming = TRUE; // End-timing WILL apply in the future for this element.
262 // If a user-group field is set:
263 if ($enCols['fe_group']) {
264 $user = $row[$enCols['fe_group']];
265 if ($user && $doNotRenderUserGroupNumber) {
267 } // Limit for user number rendering!
271 // If "deleted" flag is set (only when listing records which are also deleted!)
272 if ($col = $row[$TCA[$table]['ctrl']['delete']]) {
275 // Detecting extendToSubpages (for pages only)
276 if ($table == 'pages' && $row['extendToSubpages'] && ($hidden ||
$timing ||
$futuretiming ||
$user)) {
277 $protectSection = TRUE;
280 // If ANY of the booleans are set it means we have to alter the icon:
281 if ($hidden ||
$timing ||
$futuretiming ||
$user ||
$deleted ||
$shaded ||
$noIconFound) {
287 } elseif ($noIconFound) { // This is ONLY for creating icons with "?" on easily...
288 $string = 'no_icon_found';
297 if (!$string && $futuretiming) {
298 $string = 'futuretiming';
302 ($hidden ?
'h' : '') .
303 ($timing ?
't' : '') .
304 ($futuretiming ?
'f' : '') .
306 ($protectSection ?
'p' : '') .
307 ($shaded ?
's' : '');
310 // Create tagged icon file name:
311 $iconFileName_stateTagged = preg_replace('/.([[:alnum:]]+)$/', '__' . $flags . '.\1', basename($iconfile));
313 // Check if tagged icon file name exists (a tagget icon means the icon base name with the flags added between body and extension of the filename, prefixed with underscore)
314 if (@is_file
(dirname($absfile) . '/' . $iconFileName_stateTagged) || @is_file
($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . '/' . dirname($iconfile) . '/' . $iconFileName_stateTagged)) { // Look for [iconname]_xxxx.[ext]
315 return dirname($iconfile) . '/' . $iconFileName_stateTagged;
316 } elseif ($doNotGenerateIcon) { // If no icon generation can be done, try to look for the _X icon:
317 $iconFileName_X = preg_replace('/.([[:alnum:]]+)$/', '__x.\1', basename($iconfile));
318 if (@is_file
(dirname($absfile) . '/' . $iconFileName_X)) {
319 return dirname($iconfile) . '/' . $iconFileName_X;
321 return 'gfx/i/no_icon_found.gif';
323 } else { // Otherwise, create the icon:
324 $theRes = self
::makeIcon($GLOBALS['BACK_PATH'] . $iconfile, $string, $user, $protectSection, $absfile, $iconFileName_stateTagged);
333 * Returns the src=... for the input $src value OR any alternative found in $TBE_STYLES['skinImg']
334 * Used for skinning the TYPO3 backend with an alternative set of icons
337 * @param string Current backpath to PATH_typo3 folder
338 * @param string Icon file name relative to PATH_typo3 folder
339 * @param string Default width/height, defined like 'width="12" height="14"'
340 * @param integer Mode: 0 (zero) is default and returns src/width/height. 1 returns value of src+backpath, 2 returns value of w/h.
341 * @return string Returns ' src="[backPath][src]" [wHattribs]'
344 public static function skinImg($backPath, $src, $wHattribs = '', $outputMode = 0) {
346 static $cachedSkinImages = array();
348 $imageId = md5($backPath . $src . $wHattribs . $outputMode);
350 if (isset($cachedSkinImages[$imageId])) {
351 return $cachedSkinImages[$imageId];
353 // Setting source key. If the icon is refered to inside an extension, we homogenize the prefix to "ext/":
354 $srcKey = preg_replace('/^(\.\.\/typo3conf\/ext|sysext|ext)\//', 'ext/', $src);
355 #if ($src!=$srcKey)debug(array($src, $srcKey));
357 // LOOKING for alternative icons:
358 if ($GLOBALS['TBE_STYLES']['skinImg'][$srcKey]) { // Slower or faster with is_array()? Could be used.
359 list($src, $wHattribs) = $GLOBALS['TBE_STYLES']['skinImg'][$srcKey];
360 } elseif ($GLOBALS['TBE_STYLES']['skinImgAutoCfg']) { // Otherwise, test if auto-detection is enabled:
362 // Search for alternative icon automatically:
363 $fExt = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['forceFileExtension'];
364 $scaleFactor = ($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['scaleFactor'] ?
$GLOBALS['TBE_STYLES']['skinImgAutoCfg']['scaleFactor'] : 1); // Scaling factor
365 $lookUpName = ($fExt ?
preg_replace('/\.[[:alnum:]]+$/', '', $srcKey) . '.' . $fExt : $srcKey); // Set filename to look for
367 if ($fExt && !@is_file
($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . $lookUpName)) {
368 // fallback to original filename if icon with forced extension doesn't exists
369 $lookUpName = $srcKey;
372 if (@is_file
($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . $lookUpName)) { // If there is a file...
373 $iInfo = @getimagesize
($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . $lookUpName); // Get width/height:
375 // Set $src and $wHattribs:
376 $src = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'] . $lookUpName;
377 $wHattribs = 'width="' . round($iInfo[0] * $scaleFactor) . '" height="' . round($iInfo[1] * $scaleFactor) . '"';
380 // In any case, set currect src / wHattrib - this way we make sure that an entry IS found next time we hit the function,
381 // regardless of whether it points to a alternative icon or just the current.
382 $GLOBALS['TBE_STYLES']['skinImg'][$srcKey] = array($src, $wHattribs); // Set default...
385 // DEBUG: This doubles the size of all icons - for testing/debugging:
386 // if (preg_match('/^width="([0-9]+)" height="([0-9]+)"$/', $wHattribs, $reg)) $wHattribs='width="'.($reg[1]*2).'" height="'.($reg[2]*2).'"';
389 // rendering disabled (greyed) icons using _i (inactive) as name suffix ("_d" is already used)
391 $srcBasename = basename($src);
392 if (preg_match('/(.*)_i(\....)$/', $srcBasename, $matches)) {
393 $temp_path = dirname(PATH_thisScript
) . '/';
394 if (!@is_file
($temp_path . $backPath . $src)) {
395 $srcOrg = preg_replace('/_i' . preg_quote($matches[2]) . '$/', $matches[2], $src);
396 $src = self
::makeIcon($backPath . $srcOrg, 'disabled', 0, FALSE, $temp_path . $backPath . $srcOrg, $srcBasename);
401 // Return icon source/wHattributes:
403 switch ($outputMode) {
405 $output = ' src="' . $backPath . $src . '" ' . $wHattribs;
408 $output = $backPath . $src;
411 $output = $wHattribs;
415 $cachedSkinImages[$imageId] = $output;
420 /***********************************
424 ***********************************/
427 * Creates the icon file for the function getIcon()
429 * @param string Original unprocessed Icon file, relative path to PATH_typo3
430 * @param string Mode string, eg. "deleted" or "futuretiming" determining how the icon will look
431 * @param integer The number of the fe_group record uid if applicable
432 * @param boolean Flag determines if the protected-section icon should be applied.
433 * @param string Absolute path to file from which to create the icon.
434 * @param string The filename that this icon should have had, basically [icon base name]_[flags].[extension] - used for part of temporary filename
435 * @return string Filename relative to PATH_typo3
438 public static function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged) {
439 $iconFileName = 'icon_' . t3lib_div
::shortMD5($iconfile . '|' . $mode . '|-' . $user . '|' . $protectSection) . '_' . $iconFileName_stateTagged . '.' . ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ?
'png' : 'gif');
440 $mainpath = '../typo3temp/' . $iconFileName;
441 $path = PATH_site
. 'typo3temp/' . $iconFileName;
444 if (file_exists(PATH_typo3
. 'icons/' . $iconFileName)) { // Returns if found in typo3/icons/
445 return 'icons/' . $iconFileName;
446 } elseif (file_exists($path)) { // Returns if found in ../typo3temp/icons/
448 } else { // Makes icon:
449 if (file_exists($absFile)) {
450 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
452 // Create image pointer, if possible
453 $im = self
::imagecreatefrom($absFile);
458 // Converting to gray scale, dimming the icon:
459 if (($mode == 'disabled') OR ($mode != 'futuretiming' && $mode != 'no_icon_found' && !(!$mode && $user))) {
460 for ($c = 0; $c < ImageColorsTotal($im); $c++
) {
461 $cols = ImageColorsForIndex($im, $c);
462 $newcol = round(($cols['red'] +
$cols['green'] +
$cols['blue']) / 3);
463 $lighten = ($mode == 'disabled') ?
2.5 : 2;
464 $newcol = round(255 - ((255 - $newcol) / $lighten));
465 ImageColorSet($im, $c, $newcol, $newcol, $newcol);
468 // Applying user icon, if there are access control on the item:
470 if ($user < 100) { // Apply user number only if lower than 100
471 $black = ImageColorAllocate($im, 0, 0, 0);
472 imagefilledrectangle($im, 0, 0, (($user > 10) ?
9 : 5), 8, $black);
474 $white = ImageColorAllocate($im, 255, 255, 255);
475 imagestring($im, 1, 1, 1, $user, $white);
478 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_group.gif');
483 self
::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
485 // Applying overlay based on mode:
490 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_deleted.gif');
493 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
496 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
499 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden_timing.gif');
501 case 'no_icon_found':
502 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_no_icon_found.gif');
505 // is already greyed - nothing more
510 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden.gif');
517 self
::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
520 // Protect-section icon:
521 if ($protectSection) {
522 $ol_im = self
::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_sub5.gif');
526 self
::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
529 // Create the image as file, destroy GD image and return:
530 @self
::imagemake($im, $path);
531 t3lib_div
::gif_compress($path, 'IM');
538 return $GLOBALS['BACK_PATH'] . 'gfx/fileicons/default.gif';
544 * The necessity of using this function for combining two images if GD is version 2 is that
545 * GD2 cannot manage to combine two indexed-color images without totally spoiling everything.
546 * In class.t3lib_stdgraphic this was solved by combining the images onto a first created true color image
547 * However it has turned out that this method will not work if the indexed png-files contains transparency.
548 * So I had to turn my attention to ImageMagick - my 'enemy of death'.
549 * And so it happend - ImageMagick is now used to combine my two indexed-color images with transparency. And that works.
550 * 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+)
551 * 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.
553 * For parameters, see PHP function "imagecopyresized()"
555 * @param pointer see PHP function "imagecopyresized()"
556 * @param pointer see PHP function "imagecopyresized()"
557 * @param integer see PHP function "imagecopyresized()"
558 * @param integer see PHP function "imagecopyresized()"
559 * @param integer see PHP function "imagecopyresized()"
560 * @param integer see PHP function "imagecopyresized()"
561 * @param integer see PHP function "imagecopyresized()"
562 * @param integer see PHP function "imagecopyresized()"
563 * @param integer see PHP function "imagecopyresized()"
564 * @param integer see PHP function "imagecopyresized()"
568 public static function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
569 imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
573 * Create new image pointer from input file (either gif/png, in case the wrong format it is converted by t3lib_div::read_png_gif())
575 * @param string Absolute filename of the image file from which to start the icon creation.
576 * @return mixed If success, image pointer, otherwise "-1"
578 * @see t3lib_div::read_png_gif
580 public static function imagecreatefrom($file) {
581 $file = t3lib_div
::read_png_gif($file, $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']);
582 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
583 return $file ?
imagecreatefrompng($file) : -1;
585 return $file ?
imagecreatefromgif($file) : -1;
590 * Write the icon in $im pointer to $path
592 * @param pointer Pointer to GDlib image resource
593 * @param string Absolute path to the filename in which to write the icon.
597 public static function imagemake($im, $path) {
598 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
599 @ImagePng
($im, $path);
601 @ImageGif
($im, $path);
603 if (@is_file
($path)) {
604 t3lib_div
::fixPermissions($path);
609 /**********************************************
612 * The Sprite Icon API helps you to quickly get the HTML for any icon you want
613 * this is typically wrapped in a <span> tag with corresponding CSS classes that
614 * will be responsible for the
616 * There are three ways to use this API:
618 * 1) for any given TCA record
619 * $spriteIconHtml = t3lib_iconWorks::getSpriteIconForRecord('pages', $row);
621 * 2) for any given file
622 * $spriteIconHtml = t3lib_iconWorks::getSpriteIconForFile('myimage.png');
624 * 3) for any other icon you know the name
625 * $spriteIconHtml = t3lib_iconWorks::getSpriteIcon('actions-document-open');
627 **********************************************/
630 * This generic method is used throughout the TYPO3 Backend to show icons in any variation which are not
631 * bound to any file type (see getSpriteIconForFile) or database record (see getSpriteIconForRecord)
633 * Generates a HTML tag with proper CSS classes. The TYPO3 skin has defined these CSS classes
634 * already to have a pre-defined background image, and the correct background-position to show
635 * the necessary icon.
637 * @param string $iconName the name of the icon to fetch
638 * @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)
639 * @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)
640 * @return string the full HTML tag (usually a <span>)
643 public static function getSpriteIcon($iconName, array $options = array(), array $overlays = array()) {
644 $innerHtml = (isset($options['html']) ?
$options['html'] : NULL);
645 $tagName = (isset($options['tagName']) ?
$options['tagName'] : NULL);
647 // deal with the overlays
648 if (count($overlays)) {
649 foreach ($overlays as $overlayIconName => $overlayOptions) {
650 $overlayOptions['html'] = $innerHtml;
651 $overlayOptions['class'] = (isset($overlayOptions['class']) ?
$overlayOptions['class'] . ' ' : '') . 't3-icon-overlay';
652 $innerHtml = self
::getSpriteIcon($overlayIconName, $overlayOptions);
656 // check if whished icon is available
657 $iconName = (in_array($iconName, $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable']) ||
$iconName == 'empty-empty' ?
$iconName : 'status-status-icon-missing');
659 // create the CSS class
660 $options['class'] = self
::getSpriteIconClasses($iconName) . (isset($options['class']) ?
' ' . $options['class'] : '');
662 unset($options['html']);
663 unset($options['tagName']);
664 return self
::buildSpriteHtmlIconTag($options, $innerHtml, $tagName);
669 * This method is used throughout the TYPO3 Backend to show icons for a file type
671 * Generates a HTML tag with proper CSS classes. The TYPO3 skin has defined these CSS classes
672 * already to have a pre-defined background image, and the correct background-position to show
673 * the necessary icon.
675 * @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"
676 * @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)
677 * @return string the full HTML tag (usually a <span>)
680 public static function getSpriteIconForFile($fileExtension, array $options = array()) {
681 $innerHtml = (isset($options['html']) ?
$options['html'] : NULL);
682 $tagName = (isset($options['tagName']) ?
$options['tagName'] : NULL);
684 // create the CSS class
685 $options['class'] = self
::mapFileExtensionToSpriteIconClass($fileExtension) . (isset($options['class']) ?
' ' . $options['class'] : '');
687 unset($options['html']);
688 unset($options['tagName']);
689 return self
::buildSpriteHtmlIconTag($options, $innerHtml, $tagName);
694 * Generates the spriteicon css classes name for a given path or fileExtension
695 * usually called from getSpriteIconForFile or ExtJs Provider
697 * @param string fileExtension can be jpg, gif etc, but also be 'mount' or 'folder', but can also be a full path which will be resolved then
698 * @return string the string of the CSS class, see t3lib_iconworks::$fileSpriteIconNames
701 public static function mapFileExtensionToSpriteIconClass($fileExtension) {
702 return self
::getSpriteIconClasses(self
::mapFileExtensionToSpriteIconName($fileExtension));
706 * Generates the spriteicon name for a given path or fileExtension
707 * usually called from mapFileExtensionToSpriteIconClass and tceforms
709 * @param string fileExtension can be jpg, gif etc, but also be 'mount' or 'folder', but can also be a full path which will be resolved then
710 * @return string the string of the CSS class, see t3lib_iconworks::$fileSpriteIconNames
713 public static function mapFileExtensionToSpriteIconName($fileExtension) {
715 // if the file is a whole file with name etc (mainly, if it has a "." or a "/"),
716 // then it is checked whether it is a valid directory
717 if (strpos($fileExtension, '.') !== FALSE ||
strpos($fileExtension, '/') !== FALSE) {
719 // check if it is a directory
720 $filePath = dirname(t3lib_div
::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $fileExtension;
721 $path = t3lib_div
::resolveBackPath($filePath);
722 if (is_dir($path) ||
substr($fileExtension, -1) === '/' ||
substr($fileExtension, -1) === '\\') {
723 $fileExtension = 'folder';
725 if (($pos = strrpos($fileExtension, '.')) !== FALSE) {
726 $fileExtension = strtolower(substr($fileExtension, $pos +
1));
728 $fileExtension = 'default';
733 // if the file extension is not valid
734 // then use the default one
735 if (!isset(self
::$fileSpriteIconNames[$fileExtension])) {
736 $fileExtension = 'default';
738 $iconName = self
::$fileSpriteIconNames[$fileExtension];
745 * This method is used throughout the TYPO3 Backend to show icons for a DB record
747 * Generates a HTML tag with proper CSS classes. The TYPO3 skin has defined these CSS classes
748 * already to have a pre-defined background image, and the correct background-position to show
749 * the necessary icon.
751 * @param string $table the TCA table name
752 * @param array $row the DB record of the TCA table
753 * @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)
754 * @return string the full HTML tag (usually a <span>)
757 public static function getSpriteIconForRecord($table, array $row, array $options = array()) {
758 $innerHtml = (isset($options['html']) ?
$options['html'] : NULL);
759 $tagName = (isset($options['tagName']) ?
$options['tagName'] : NULL);
761 // overlay this record icon with the status of the row
762 $overlaySpriteIconName = self
::mapRecordOverlayToSpriteIconName($table, $row);
763 if ($overlaySpriteIconName) {
764 $overlayOptions = array(
765 'html' => $innerHtml,
766 'class' => 't3-icon-overlay'
768 $innerHtml = self
::getSpriteIcon($overlaySpriteIconName, $overlayOptions);
771 // fetch the name for the CSS class, based on the $row
772 $options['class'] = self
::mapRecordTypeToSpriteIconClass($table, $row) . (isset($options['class']) ?
' ' . $options['class'] : '');
774 unset($options['html']);
775 unset($options['tagName']);
776 return self
::buildSpriteHtmlIconTag($options, $innerHtml, $tagName);
781 * this helper functions looks up the column that is used for the type of
782 * the chosen TCA table. And then fetches the corresponding class
783 * based on the chosen iconsprite class in this TCA
785 * - [ctrl][typeicon_column]
787 * This method solely takes care of the type of this record, not any
788 * statuses, used for overlays.
789 * You should not use this directly besides if you need classes for ExtJS iconCls.
791 * see t3lib/stddb/tables.php for an example with the TCA table "pages"
793 * @param string $table the TCA table
794 * @param array $row the selected record
795 * @return string the CSS class for the sprite icon of that DB record
798 public static function mapRecordTypeToSpriteIconClass($table, array $row) {
799 return self
::getSpriteIconClasses(self
::mapRecordTypeToSpriteIconName($table, $row));
803 * this helper functions looks up the column that is used for the type of
804 * the chosen TCA table. And then fetches the corresponding iconname
805 * based on the chosen iconsprite class in this TCA
807 * - [ctrl][typeicon_column]
809 * This method solely takes care of the type of this record, not any
810 * statuses, used for overlays.
811 * You should not use this directly besides if you need it in tceforms/core classes
813 * see t3lib/stddb/tables.php for an example with the TCA table "pages"
815 * @param string $table the TCA table
816 * @param array $row the selected record
817 * @return string the CSS class for the sprite icon of that DB record
820 public static function mapRecordTypeToSpriteIconName($table, array $row) {
821 $recordType = array();
823 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_column'])) {
824 $column = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
826 if (isset($row[$column])) {
827 $recordType[1] = $row[$column];
829 $recordType[1] = 'default';
832 // workaround to give nav_hide pages a complete different icon
833 // although it's not a separate doctype
834 // and to give root-pages an own icon
835 if ($table === 'pages') {
836 if ($row['nav_hide']) {
837 $recordType[2] = $recordType[1] . '-hideinmenu';
839 if ($row['is_siteroot']) {
840 $recordType[3] = $recordType[1] . '-root';
842 if ($row['module']) {
843 $recordType[4] = 'contains-' . $row['module'];
847 if (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
848 foreach ($recordType AS $key => $type) {
849 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type])) {
850 $recordType[$key] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type];
852 unset($recordType[$key]);
855 $recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
856 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask'])) {
857 $recordType[5] = str_replace('###TYPE###', $row[$column], $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask']);
859 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'])) {
860 $recordType[6] = t3lib_div
::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'], array('row' => $row), $ref);
863 foreach ($recordType AS $key => $type) {
864 $recordType[$key] = 'tcarecords-' . $table . '-' . $type;
866 $recordType[0] = 'tcarecords-' . $table . '-default';
869 if (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
870 $recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
872 $recordType[0] = 'tcarecords-' . $table . '-default';
876 foreach ($recordType as $iconName) {
877 if (in_array($iconName, $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'])) {
881 return 'status-status-icon-missing';
886 * this helper functions checks if the DB record ($row) has any special status
887 * based on the TCA settings like hidden, starttime etc, and then returns a specific
888 * Sprite icon class for the overlay of this DB record
889 * This method solely takes care of the overlay of this record, not any type
891 * Please note that this only returns one overlay, one status, that is prioritized
892 * by $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconRecordOverlayPriorities']
893 * We wanted to not have these icons blown over by tons of overlays, so this is limited
896 * see t3lib/config_default.php for the default options, you will find
897 * $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconRecordOverlayNames'] that shows
898 * the list of CSS classes that will be used for the sprites, mapped to the statuses here
900 * @param string $table the TCA table
901 * @param array $row the selected record
902 * @return string the CSS class for the sprite icon of that DB record
905 public static function mapRecordOverlayToSpriteIconName($table, array $row) {
906 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
908 // Calculate for a given record the actual visibility at the moment
911 'starttime' => FALSE,
913 'futureendtime' => FALSE,
916 'protectedSection' => FALSE,
917 'nav_hide' => ($row['nav_hide'] ?
TRUE : FALSE),
918 'noIconFound' => ($row['_NO_ICON_FOUND'] ?
TRUE : FALSE),
921 // Icon state based on "enableFields":
922 if (is_array($tcaCtrl['enablecolumns'])) {
923 $enCols = $tcaCtrl['enablecolumns'];
924 // If "hidden" is enabled:
925 if ($tcaCtrl['enablecolumns']['disabled'] && $row[$tcaCtrl['enablecolumns']['disabled']]) {
926 $status['hidden'] = TRUE;
928 // If a "starttime" is set and higher than current time:
929 if ($tcaCtrl['enablecolumns']['starttime'] && $GLOBALS['EXEC_TIME'] < intval($row[$tcaCtrl['enablecolumns']['starttime']])) {
930 $status['starttime'] = TRUE;
933 // If an "endtime" is set
934 if ($tcaCtrl['enablecolumns']['endtime']) {
935 if (intval($row[$tcaCtrl['enablecolumns']['endtime']]) > 0) {
936 if (intval($row[$tcaCtrl['enablecolumns']['endtime']]) < $GLOBALS['EXEC_TIME']) {
937 // End-timing applies at this point.
938 $status['endtime'] = TRUE;
940 // End-timing WILL apply in the future for this element.
941 $status['futureendtime'] = TRUE;
945 // If a user-group field is set
946 if ($tcaCtrl['enablecolumns']['fe_group'] && $row[$tcaCtrl['enablecolumns']['fe_group']]) {
947 $status['fe_group'] = TRUE;
951 // If "deleted" flag is set (only when listing records which are also deleted!)
952 if ($row[$tcaCtrl['delete']]) {
953 $status['deleted'] = TRUE;
956 // Detecting extendToSubpages (for pages only)
957 if ($table == 'pages' && $row['extendToSubpages']) {
958 $status['protectedSection'] = TRUE;
962 // now only show the status with the highest priority
963 $priorities = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayPriorities'];
966 foreach ($priorities as $priority) {
967 if ($status[$priority]) {
968 $iconName = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayNames'][$priority];
978 * generic method to create the final CSS classes based on the sprite icon name
979 * with the base class and splits the name into parts
980 * is usually called by the methods that are responsible for fetching the names
981 * out of the file name, or the record type
983 * @param string $name iconname like 'actions-document-new'
984 * @return string a list of all CSS classes needed for the HTML tag
987 public static function getSpriteIconClasses($iconName) {
988 $cssClasses = $baseCssClass = 't3-icon';
989 $parts = explode('-', $iconName);
991 if (count($parts) > 1) {
992 // will be something like "t3-icon-actions"
993 $cssClasses .= ' ' . ($baseCssClass . '-' . $parts[0]);
994 // will be something like "t3-icon-actions-document"
995 $cssClasses .= ' ' . ($baseCssClass . '-' . $parts[0] . '-' . $parts[1]);
996 // will be something like "t3-icon-document-new"
997 $cssClasses .= ' ' . ($baseCssClass . '-' . substr($iconName, strlen($parts[0]) +
1));
1004 * low level function that generates the HTML tag for the sprite icon
1005 * is usually called by the three API classes (getSpriteIcon, getSpriteIconForFile, getSpriteIconForRecord)
1006 * it does not care about classes or anything else, but just plainly builds the HTML tag
1008 * @param array $tagAttributes an associative array of additional tagAttributes for the HTML tag
1009 * @param string $innerHtml (optional) the content within the tag, a " " by default
1010 * @param string $tagName (optional) the name of the HTML element that should be used (span by default)
1012 protected static function buildSpriteHtmlIconTag(array $tagAttributes, $innerHtml = NULL, $tagName = NULL) {
1013 $innerHtml = ($innerHtml === NULL ?
' ' : $innerHtml);
1014 $tagName = ($tagName === NULL ?
'span' : $tagName);
1016 foreach ($tagAttributes as $attribute => $value) {
1017 $attributes .= ' ' . htmlspecialchars($attribute) . '="' . htmlspecialchars($value) . '"';
1019 return '<' . $tagName . $attributes . '>' . $innerHtml . '</' . $tagName . '>';