2 namespace TYPO3\CMS\Backend\Utility;
44 'htm' =>
'mimetypes-text-html',
45 'html' =>
'mimetypes-text-html',
46 'css' =>
'mimetypes-text-css',
47 'js' =>
'mimetypes-text-js',
48 'csv' =>
'mimetypes-text-csv',
49 'php' =>
'mimetypes-text-php',
50 'php6' =>
'mimetypes-text-php',
51 'php5' =>
'mimetypes-text-php',
52 'php4' =>
'mimetypes-text-php',
53 'php3' =>
'mimetypes-text-php',
54 'inc' =>
'mimetypes-text-php',
55 'ts' =>
'mimetypes-text-ts',
56 'txt' =>
'mimetypes-text-text',
57 'class' =>
'mimetypes-text-text',
58 'tmpl' =>
'mimetypes-text-text',
59 'jpg' =>
'mimetypes-media-image',
60 'jpeg' =>
'mimetypes-media-image',
61 'gif' =>
'mimetypes-media-image',
62 'png' =>
'mimetypes-media-image',
63 'bmp' =>
'mimetypes-media-image',
64 'tif' =>
'mimetypes-media-image',
65 'tiff' =>
'mimetypes-media-image',
66 'tga' =>
'mimetypes-media-image',
67 'psd' =>
'mimetypes-media-image',
68 'eps' =>
'mimetypes-media-image',
69 'ai' =>
'mimetypes-media-image',
70 'svg' =>
'mimetypes-media-image',
71 'pcx' =>
'mimetypes-media-image',
72 'avi' =>
'mimetypes-media-video',
73 'mpg' =>
'mimetypes-media-video',
74 'mpeg' =>
'mimetypes-media-video',
75 'mov' =>
'mimetypes-media-video',
76 'wav' =>
'mimetypes-media-audio',
77 'mp3' =>
'mimetypes-media-audio',
78 'mid' =>
'mimetypes-media-audio',
79 'swf' =>
'mimetypes-media-flash',
80 'swa' =>
'mimetypes-media-flash',
81 'exe' =>
'mimetypes-application',
82 'com' =>
'mimetypes-application',
83 't3x' =>
'mimetypes-compressed',
84 't3d' =>
'mimetypes-compressed',
85 'zip' =>
'mimetypes-compressed',
86 'tgz' =>
'mimetypes-compressed',
87 'gz' =>
'mimetypes-compressed',
88 'pdf' =>
'mimetypes-pdf',
89 'doc' =>
'mimetypes-word',
90 'dot' =>
'mimetypes-word',
91 'docm' =>
'mimetypes-word',
92 'docx' =>
'mimetypes-word',
93 'dotm' =>
'mimetypes-word',
94 'dotx' =>
'mimetypes-word',
95 'sxw' =>
'mimetypes-word',
96 'rtf' =>
'mimetypes-word',
97 'xls' =>
'mimetypes-excel',
98 'xlsm' =>
'mimetypes-excel',
99 'xlsx' =>
'mimetypes-excel',
100 'xltm' =>
'mimetypes-excel',
101 'xltx' =>
'mimetypes-excel',
102 'sxc' =>
'mimetypes-excel',
103 'pps' =>
'mimetypes-powerpoint',
104 'ppsx' =>
'mimetypes-powerpoint',
105 'ppt' =>
'mimetypes-powerpoint',
106 'pptm' =>
'mimetypes-powerpoint',
107 'pptx' =>
'mimetypes-powerpoint',
108 'potm' =>
'mimetypes-powerpoint',
109 'potx' =>
'mimetypes-powerpoint',
110 'mount' =>
'apps-filetree-mount',
111 'folder' =>
'apps-filetree-folder-default',
112 'default' =>
'mimetypes-other-other'
133 public static function getIcon($table, $row = array(), $shaded =
false)
139 $doNotRenderUserGroupNumber =
true;
141 if (!empty(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'versioningWS']) && !empty($row[
't3ver_state'])) {
144 return 'gfx/i/shadow_hide.png';
147 return 'gfx/i/shadow_delete.png';
150 return 'gfx/i/shadow_moveto_plh.png';
153 return 'gfx/i/shadow_moveto_pointer.png';
158 if ($table ===
'pages') {
159 $iconfile =
$GLOBALS[
'PAGES_TYPES'][$row[
'doktype']][
'icon'];
160 if (empty($iconfile)) {
161 $iconfile =
$GLOBALS[
'PAGES_TYPES'][
'default'][
'icon'];
165 if (empty($iconfile)) {
166 $iconfile =
$GLOBALS[
'TCA'][$table][
'ctrl'][
'iconfile'] ?: $table .
'.gif';
170 if (!strstr($iconfile,
'/')) {
171 $iconfile =
'gfx/i/' . $iconfile;
174 if (substr($iconfile, 0, 3) ==
'../') {
175 $absfile = PATH_site . substr($iconfile, 3);
177 $absfile = PATH_typo3 . $iconfile;
182 $futuretiming =
false;
187 $protectSection =
false;
188 $noIconFound = (bool)$row[
'_NO_ICON_FOUND'];
191 if (is_array(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'])) {
192 $enCols =
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'];
194 if ($enCols[
'disabled']) {
195 if ($row[$enCols[
'disabled']]) {
200 if ($enCols[
'starttime']) {
201 if (
$GLOBALS[
'EXEC_TIME'] < (
int)$row[$enCols[
'starttime']]) {
204 if ((
int)$row[$enCols[
'endtime']] === 0) {
205 $futuretiming =
true;
210 if ($enCols[
'endtime']) {
211 if ((
int)$row[$enCols[
'endtime']] > 0) {
212 if ((
int)$row[$enCols[
'endtime']] <
$GLOBALS[
'EXEC_TIME']) {
217 $futuretiming =
true;
222 if ($enCols[
'fe_group']) {
223 $user = $row[$enCols[
'fe_group']];
224 if ($user && $doNotRenderUserGroupNumber) {
230 if ($col = $row[
$GLOBALS[
'TCA'][$table][
'ctrl'][
'delete']]) {
234 if ($table ==
'pages' && $row[
'extendToSubpages'] && ($hidden || $timing || $futuretiming || $user)) {
235 $protectSection =
true;
238 if ($hidden || $timing || $futuretiming || $user || $deleted || $shaded || $noIconFound) {
246 $string =
'no_icon_found';
255 if (!$string && $futuretiming) {
256 $string =
'futuretiming';
258 $flags .= ($hidden ?
'h' :
'') . ($timing ?
't' :
'') . ($futuretiming ?
'f' :
'') . ($user ?
'u' :
'') . ($protectSection ?
'p' :
'') . ($shaded ?
's' :
'');
261 $iconFileName_stateTagged = preg_replace(
'/.([[:alnum:]]+)$/',
'__' . $flags .
'.\\1', basename($iconfile));
263 if (@is_file((dirname($absfile) .
'/' . $iconFileName_stateTagged)) || @is_file((
$GLOBALS[
'TBE_STYLES'][
'skinImgAutoCfg'][
'absDir'] .
'/' . dirname($iconfile) .
'/' . $iconFileName_stateTagged))) {
265 return dirname($iconfile) .
'/' . $iconFileName_stateTagged;
268 $theRes = self::makeIcon(
$GLOBALS[
'BACK_PATH'] . $iconfile, $string, $user, $protectSection, $absfile, $iconFileName_stateTagged);
288 public static function skinImg($backPath, $src, $wHattribs =
'', $outputMode = 0)
291 static $cachedSkinImages = array();
292 $imageId = md5($backPath . $src . $wHattribs . $outputMode);
293 if (isset($cachedSkinImages[$imageId])) {
294 return $cachedSkinImages[$imageId];
297 $srcKey = preg_replace(
'/^(\\.\\.\\/typo3conf\\/ext|sysext|ext)\\//',
'ext/', $src);
299 if (
$GLOBALS[
'TBE_STYLES'][
'skinImg'][$srcKey]) {
301 list($src, $wHattribs) =
$GLOBALS[
'TBE_STYLES'][
'skinImg'][$srcKey];
305 $fExt =
$GLOBALS[
'TBE_STYLES'][
'skinImgAutoCfg'][
'forceFileExtension'];
306 $scaleFactor =
$GLOBALS[
'TBE_STYLES'][
'skinImgAutoCfg'][
'scaleFactor'] ?: 1;
308 $lookUpName = $fExt ? preg_replace(
'/\\.[[:alnum:]]+$/',
'', $srcKey) .
'.' . $fExt : $srcKey;
310 if ($fExt && !@is_file((
$GLOBALS[
'TBE_STYLES'][
'skinImgAutoCfg'][
'absDir'] . $lookUpName))) {
312 $lookUpName = $srcKey;
315 if (@is_file((
$GLOBALS[
'TBE_STYLES'][
'skinImgAutoCfg'][
'absDir'] . $lookUpName))) {
317 $iInfo = @getimagesize((
$GLOBALS[
'TBE_STYLES'][
'skinImgAutoCfg'][
'absDir'] . $lookUpName));
320 $src =
$GLOBALS[
'TBE_STYLES'][
'skinImgAutoCfg'][
'relDir'] . $lookUpName;
321 $wHattribs =
'width="' . round($iInfo[0] * $scaleFactor) .
'" height="' . round($iInfo[1] * $scaleFactor) .
'"';
325 $GLOBALS[
'TBE_STYLES'][
'skinImg'][$srcKey] = array($src, $wHattribs);
329 $srcBasename = basename($src);
330 if (preg_match(
'/(.*)_i(\\....)$/', $srcBasename, $matches)) {
331 $temp_path = dirname(PATH_thisScript) .
'/';
332 if (!@is_file(($temp_path . $backPath . $src))) {
333 $srcOrg = preg_replace(
'/_i' . preg_quote($matches[2],
'/') .
'$/', $matches[2], $src);
334 $src = self::makeIcon($backPath . $srcOrg,
'disabled', 0,
false, $temp_path . $backPath . $srcOrg, $srcBasename);
339 switch ($outputMode) {
341 $output =
' src="' . $backPath . $src .
'" ' . $wHattribs;
344 $output = $backPath . $src;
347 $output = $wHattribs;
350 $cachedSkinImages[$imageId] = $output;
372 public static function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged)
374 $iconFileName =
GeneralUtility::shortMD5(($iconfile .
'|' . $mode .
'|-' . $user .
'|' . $protectSection)) .
'_' . $iconFileName_stateTagged .
'.' . (
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'gdlib_png'] ?
'png' :
'gif');
375 $mainpath =
'../typo3temp/Icons/' . $iconFileName;
376 $path = PATH_site .
'typo3temp/Icons/' . $iconFileName;
377 if (file_exists($path)) {
382 if (file_exists($absFile)) {
383 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'gdlib']) {
385 $im = self::imagecreatefrom($absFile);
390 if ($mode ==
'disabled' or $mode !=
'futuretiming' && $mode !=
'no_icon_found' && !(!$mode && $user)) {
391 $totalImageColors = ImageColorsTotal($im);
392 for ($c = 0; $c < $totalImageColors; $c++) {
393 $cols = ImageColorsForIndex($im, $c);
394 $newcol = round(($cols[
'red'] + $cols[
'green'] + $cols[
'blue']) / 3);
395 $lighten = $mode ==
'disabled' ? 2.5 : 2;
396 $newcol = round(255 - (255 - $newcol) / $lighten);
397 ImageColorSet($im, $c, $newcol, $newcol, $newcol);
404 $black = ImageColorAllocate($im, 0, 0, 0);
405 imagefilledrectangle($im, 0, 0, $user > 10 ? 9 : 5, 8, $black);
406 $white = ImageColorAllocate($im, 255, 255, 255);
407 imagestring($im, 1, 1, 1, $user, $white);
409 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_group.gif');
413 self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
420 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_deleted.gif');
423 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_timing.gif');
426 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_timing.gif');
429 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_hidden_timing.gif');
431 case 'no_icon_found':
432 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_no_icon_found.gif');
441 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_hidden.gif');
447 self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
451 if ($protectSection) {
452 $ol_im = self::imagecreatefrom(
$GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_sub5.gif');
456 self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
459 $targetDirectory = dirname($path);
460 if (!@is_dir($targetDirectory)) {
463 @self::imagemake($im, $path);
472 return $GLOBALS[
'BACK_PATH'] .
'typo3/sysext/backend/Resources/Public/Images/Overlay/default.gif';
502 public static function imagecopyresized(&$destinationImage, $sourceImage, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight)
504 imagecopyresized($destinationImage, $sourceImage, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
522 return $GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'gdlib_png'] ? imagecreatefrompng($file) : imagecreatefromgif($file);
535 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'gdlib_png']) {
536 @ImagePng($im, $path);
538 @ImageGif($im, $path);
540 if (@is_file($path)) {
586 public static function getSpriteIcon($iconName, array $options = array(), array $overlays = array())
590 if (empty($options) && empty($overlays)) {
591 if (isset(static::$spriteIconCache[$iconName])) {
592 return static::$spriteIconCache[$iconName];
594 $iconIsCacheable =
true;
596 $iconIsCacheable =
false;
599 $innerHtml = isset($options[
'html']) ? $options[
'html'] : null;
600 $tagName = isset($options[
'tagName']) ? $options[
'tagName'] : null;
603 foreach ($overlays as $overlayIconName => $overlayOptions) {
604 $overlayOptions[
'html'] = $innerHtml;
605 $overlayOptions[
'class'] = (isset($overlayOptions[
'class']) ? $overlayOptions[
'class'] .
' ' :
'') .
't3-icon-overlay';
606 $innerHtml = self::getSpriteIcon($overlayIconName, $overlayOptions);
609 $availableIcons = isset(
$GLOBALS[
'TBE_STYLES'][
'spriteIconApi'][
'iconsAvailable'])
610 ? (array)
$GLOBALS[
'TBE_STYLES'][
'spriteIconApi'][
'iconsAvailable']
612 if ($iconName !==
'empty-empty' && !in_array($iconName, $availableIcons,
true)) {
613 $iconName =
'status-status-icon-missing';
617 $options[
'class'] = self::getSpriteIconClasses($iconName) . (isset($options[
'class']) ?
' ' . $options[
'class'] :
'');
618 unset($options[
'html'], $options[
'tagName']);
619 $spriteHtml = self::buildSpriteHtmlIconTag($options, $innerHtml, $tagName);
622 if ($iconIsCacheable) {
623 static::$spriteIconCache[$iconName] = $spriteHtml;
645 if ($options !== null) {
650 return $iconFactory->getIconForFileExtension($fileExtension)->render();
663 return self::getSpriteIconClasses(self::mapFileExtensionToSpriteIconName($fileExtension));
678 if (strpos($fileExtension,
'.') !==
false || strpos($fileExtension,
'/') !==
false) {
682 if (is_dir($path) || substr($fileExtension, -1) ===
'/' || substr($fileExtension, -1) ===
'\\') {
683 $fileExtension =
'folder';
685 if (($pos = strrpos($fileExtension,
'.')) !==
false) {
686 $fileExtension = strtolower(substr($fileExtension, $pos + 1));
688 $fileExtension =
'default';
694 if (!isset(self::$fileSpriteIconNames[$fileExtension])) {
695 $fileExtension =
'default';
697 $iconName = self::$fileSpriteIconNames[$fileExtension];
719 if ($options !== null) {
724 return $iconFactory->getIconForRecord($table, $row,
Icon::SIZE_SMALL)->render();
746 public static function getSpriteIconForResource(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, array $options = array(), array $overlays = null)
749 if ($overlays !== null) {
754 return $iconFactory->getIconForResource($resource,
Icon::SIZE_SMALL, null, $options)->render();
779 return self::getSpriteIconClasses(self::mapRecordTypeToSpriteIconName($table, $row));
802 $recordType = array();
804 if (isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_column'])) {
805 $column =
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_column'];
806 if (isset($row[$column])) {
807 $recordType[1] = $row[$column];
809 $recordType[1] =
'default';
814 if ($table ===
'pages') {
815 if ($row[
'nav_hide']) {
816 $recordType[2] = $recordType[1] .
'-hideinmenu';
818 if ($row[
'is_siteroot']) {
819 $recordType[3] = $recordType[1] .
'-root';
821 if ($row[
'module']) {
822 $recordType[4] =
'contains-' . $row[
'module'];
824 if ((
int)$row[
'content_from_pid'] > 0) {
825 $recordType[4] = (int)$row[
'nav_hide'] === 0 ?
'page-contentFromPid' :
'page-contentFromPid-hideinmenu';
828 if (is_array(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'])) {
829 foreach ($recordType as $key => $type) {
830 if (isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'][$type])) {
831 $recordType[$key] =
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'][$type];
833 unset($recordType[$key]);
836 $recordType[0] =
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'][
'default'];
837 if (isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'][
'mask'])) {
838 $recordType[5] = str_replace(
'###TYPE###', $row[$column],
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'][
'mask']);
840 if (isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'][
'userFunc'])) {
841 $parameters = array(
'row' => $row);
845 foreach ($recordType as &$type) {
846 $type =
'tcarecords-' . $table .
'-' . $type;
849 $recordType[0] =
'tcarecords-' . $table .
'-default';
852 if (is_array(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'])) {
853 $recordType[0] =
$GLOBALS[
'TCA'][$table][
'ctrl'][
'typeicon_classes'][
'default'];
855 $recordType[0] =
'tcarecords-' . $table .
'-default';
859 if (is_array(
$GLOBALS[
'TBE_STYLES'][
'spriteIconApi'][
'iconsAvailable'])) {
860 foreach ($recordType as $iconName) {
861 if (in_array($iconName,
$GLOBALS[
'TBE_STYLES'][
'spriteIconApi'][
'iconsAvailable'])) {
867 return 'status-status-icon-missing';
883 $cssClasses = ($baseCssClass =
't3-icon');
884 $parts = explode(
'-', $iconName);
885 if (count($parts) > 1) {
887 $cssClasses .=
' ' . ($baseCssClass .
'-' . $parts[0]);
889 $cssClasses .=
' ' . ($baseCssClass .
'-' . $parts[0] .
'-' . $parts[1]);
891 $cssClasses .=
' ' . ($baseCssClass .
'-' . substr($iconName, (strlen($parts[0]) + 1)));
912 $innerHtml = $innerHtml === null ?
' ' : $innerHtml;
913 $tagName = $tagName === null ?
'span' : $tagName;
915 foreach ($tagAttributes as $attribute => $value) {
916 $attributes .=
' ' . htmlspecialchars($attribute) .
'="' . htmlspecialchars($value) .
'"';
919 return '<' . $tagName . $attributes .
'>' . $innerHtml .
'</' . $tagName .
'>';