[TASK] Replace Space Indent into Tab indent (CGL Cleanup)
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_iconworks.php
index 9c9333f..33417d9 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
-/**
- * Contains class for icon generation in the backend
- *
- * $Id$
- * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
- * XHTML compliant
- *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
- */
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- *   85: class t3lib_iconWorks
- *  100:        function getIconImage($table,$row=array(),$backPath,$params='',$shaded=FALSE)
- *  118:        function getIcon($table,$row=array(),$shaded=FALSE)
- *  264:        function skinImg($backPath,$src,$wHattribs='',$outputMode=0)
- *
- *                       SECTION: Other functions
- *  353:        function makeIcon($iconfile,$mode, $user, $protectSection,$absFile,$iconFileName_stateTagged)
- *  475:        function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h)
- *  505:        function imagecreatefrom($file)
- *  522:        function imagemake($im, $path)
- *
- * TOTAL FUNCTIONS: 7
- * (This index is automatically created/updated by the extension "extdeveval")
- *
- */
-
 
 /**
- * Icon generation, backend
+ * Contains class for icon generation in the backend
  * This library has functions that returns - and if necessary creates - the icon for an element in TYPO3
  *
  * Expects global vars:
@@ -70,7 +40,7 @@
  * The class is included in eg. init.php
  * ALL functions called without making a class instance, eg. "t3lib_iconWorks::getIconImage()"
  *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  */
@@ -119,11 +89,24 @@ final class t3lib_iconWorks {
                'gz' => 'mimetypes-compressed',
                'pdf' => 'mimetypes-pdf',
                'doc' => 'mimetypes-word',
+               'dot' => 'mimetypes-word',
+               'docm' => 'mimetypes-word',
+               'docx' => 'mimetypes-word',
+               'dotm' => 'mimetypes-word',
+               'dotx' => 'mimetypes-word',
                'sxw' => 'mimetypes-word',
                'rtf' => 'mimetypes-word',
                'xls' => 'mimetypes-excel',
+               'xlsm' => 'mimetypes-excel',
+               'xlsx' => 'mimetypes-excel',
+               'xltm' => 'mimetypes-excel',
+               'xltx' => 'mimetypes-excel',
                'sxc' => 'mimetypes-excel',
                'ppt' => 'mimetypes-powerpoint',
+               'pptm' => 'mimetypes-powerpoint',
+               'pptx' => 'mimetypes-powerpoint',
+               'potm' => 'mimetypes-powerpoint',
+               'potx' => 'mimetypes-powerpoint',
                'mount' => 'apps-filetree-mount',
                'folder' => 'apps-filetree-folder-default',
                'default' => 'mimetypes-other-other'
@@ -132,7 +115,6 @@ final class t3lib_iconWorks {
        /**
         * Returns an icon image tag, 18x16 pixels, based on input information.
         * This function is recommended to use in your backend modules.
-        * Usage: 60
         *
         * @param       string          The table name
         * @param       array           The table row ("enablefields" are at least needed for correct icon display and for pages records some more fields in addition!)
@@ -144,8 +126,8 @@ final class t3lib_iconWorks {
         */
        public static function getIconImage($table, $row = array(), $backPath, $params = '', $shaded = FALSE) {
                $str = '<img' .
-                          self::skinImg($backPath, self::getIcon($table, $row, $shaded), 'width="18" height="16"') .
-                          (trim($params) ? ' ' . trim($params) : '');
+                       self::skinImg($backPath, self::getIcon($table, $row, $shaded), 'width="18" height="16"') .
+                       (trim($params) ? ' ' . trim($params) : '');
                if (!stristr($str, 'alt="')) {
                        $str .= ' alt=""';
                }
@@ -156,7 +138,6 @@ final class t3lib_iconWorks {
        /**
         * Creates the icon for input table/row
         * Returns filename for the image icon, relative to PATH_typo3
-        * Usage: 24
         *
         * @param       string          The table name
         * @param       array           The table row ("enablefields" are at least needed for correct icon display and for pages records some more fields in addition!)
@@ -165,14 +146,11 @@ final class t3lib_iconWorks {
         * @see getIconImage()
         */
        public static function getIcon($table, $row = array(), $shaded = FALSE) {
-               global $TCA, $PAGES_TYPES, $ICON_TYPES;
-
                        // Flags:
-               $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]
                $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...
 
                        // Shadow:
-               if ($TCA[$table]['ctrl']['versioningWS']) {
+               if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                        switch ((int) $row['t3ver_state']) {
                                case 1:
                                        return 'gfx/i/shadow_hide.png';
@@ -191,20 +169,13 @@ final class t3lib_iconWorks {
 
                        // First, find the icon file name. This can depend on configuration in TCA, field values and more:
                if ($table == 'pages') {
-                               // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
-                       if ($row['nav_hide'] && ($row['doktype'] == t3lib_pageSelect::DOKTYPE_DEFAULT || $row['doktype'] == t3lib_pageSelect::DOKTYPE_ADVANCED)) {
-                               $row['doktype'] = t3lib_pageSelect::DOKTYPE_HIDE_IN_MENU;
-                       } // Workaround to change the icon if "Hide in menu" was set
-
-                       if (!$iconfile = $PAGES_TYPES[$row['doktype']]['icon']) {
-                               $iconfile = $PAGES_TYPES['default']['icon'];
-                       }
-                       if ($row['module'] && $ICON_TYPES[$row['module']]['icon']) {
-                               $iconfile = $ICON_TYPES[$row['module']]['icon'];
+                       $iconfile = $GLOBALS['PAGES_TYPES'][$row['doktype']]['icon'];
+                       if (!$iconfile) {
+                               $iconfile = $GLOBALS['PAGES_TYPES']['default']['icon'];
                        }
                } else {
-                       if (!$iconfile = $TCA[$table]['ctrl']['typeicons'][$row[$TCA[$table]['ctrl']['typeicon_column']]]) {
-                               $iconfile = (($TCA[$table]['ctrl']['iconfile']) ? $TCA[$table]['ctrl']['iconfile'] : $table . '.gif');
+                       if (!$iconfile = $GLOBALS['TCA'][$table]['ctrl']['typeicons'][$row[$GLOBALS['TCA'][$table]['ctrl']['typeicon_column']]]) {
+                               $iconfile = (($GLOBALS['TCA'][$table]['ctrl']['iconfile']) ? $GLOBALS['TCA'][$table]['ctrl']['iconfile'] : $table . '.gif');
                        }
                }
 
@@ -231,8 +202,8 @@ final class t3lib_iconWorks {
                        // + $shaded which is also boolean!
 
                        // Icon state based on "enableFields":
-               if (is_array($TCA[$table]['ctrl']['enablecolumns'])) {
-                       $enCols = $TCA[$table]['ctrl']['enablecolumns'];
+               if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
+                       $enCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
                                // If "hidden" is enabled:
                        if ($enCols['disabled']) {
                                if ($row[$enCols['disabled']]) {
@@ -269,7 +240,7 @@ final class t3lib_iconWorks {
                }
 
                        // If "deleted" flag is set (only when listing records which are also deleted!)
-               if ($col = $row[$TCA[$table]['ctrl']['delete']]) {
+               if ($col = $row[$GLOBALS['TCA'][$table]['ctrl']['delete']]) {
                        $deleted = TRUE;
                }
                        // Detecting extendToSubpages (for pages only)
@@ -313,13 +284,6 @@ final class t3lib_iconWorks {
                                // 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)
                        if (@is_file(dirname($absfile) . '/' . $iconFileName_stateTagged) || @is_file($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . '/' . dirname($iconfile) . '/' . $iconFileName_stateTagged)) { // Look for [iconname]_xxxx.[ext]
                                return dirname($iconfile) . '/' . $iconFileName_stateTagged;
-                       } elseif ($doNotGenerateIcon) { // If no icon generation can be done, try to look for the _X icon:
-                               $iconFileName_X = preg_replace('/.([[:alnum:]]+)$/', '__x.\1', basename($iconfile));
-                               if (@is_file(dirname($absfile) . '/' . $iconFileName_X)) {
-                                       return dirname($iconfile) . '/' . $iconFileName_X;
-                               } else {
-                                       return 'gfx/i/no_icon_found.gif';
-                               }
                        } else { // Otherwise, create the icon:
                                $theRes = self::makeIcon($GLOBALS['BACK_PATH'] . $iconfile, $string, $user, $protectSection, $absfile, $iconFileName_stateTagged);
                                return $theRes;
@@ -332,7 +296,6 @@ final class t3lib_iconWorks {
        /**
         * Returns the src=... for the input $src value OR any alternative found in $TBE_STYLES['skinImg']
         * Used for skinning the TYPO3 backend with an alternative set of icons
-        * Usage: 336
         *
         * @param       string          Current backpath to PATH_typo3 folder
         * @param       string          Icon file name relative to PATH_typo3 folder
@@ -550,23 +513,22 @@ final class t3lib_iconWorks {
         * 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+)
         * 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.
         *
-        * For parameters, see PHP function "imagecopyresized()"
-        *
-        * @param       pointer         see PHP function "imagecopyresized()"
-        * @param       pointer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @param       integer         see PHP function "imagecopyresized()"
-        * @return      void
+        * @param resource $dstImg destination image
+        * @param resource $srcImg source image
+        * @param integer $dstX destination x-coordinate
+        * @param integer $dstY destination y-coordinate
+        * @param integer $srcX source x-coordinate
+        * @param integer $srcY source y-coordinate
+        * @param integer $dstWidth destination width
+        * @param integer $dstHeight destination height
+        * @param integer $srcWidth source width
+        * @param integer $srcHeight source height
+        * @return void
         * @access private
+        * @see t3lib_stdGraphic::imagecopyresized()
         */
-       public static function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
-               imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
+       public static function imagecopyresized(&$dstImg, $srcImg, $dstX, $dstY, $srcX, $srcY, $dstWidth, $dstHeight, $srcWidth, $srcHeight) {
+               imagecopyresized($dstImg, $srcImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $dstWidth, $dstHeight, $srcWidth, $srcHeight);
        }
 
        /**
@@ -857,12 +819,18 @@ final class t3lib_iconWorks {
                                        $recordType[5] = str_replace('###TYPE###', $row[$column], $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask']);
                                }
                                if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'])) {
-                                       $recordType[6] = t3lib_div::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'], array('row' => $row), $ref);
+                                       $parameters = array('row' => $row);
+                                       $recordType[6] = t3lib_div::callUserFunction(
+                                               $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'],
+                                               $parameters,
+                                               $ref
+                                       );
                                }
                        } else {
-                               foreach ($recordType AS $key => $type) {
-                                       $recordType[$key] = 'tcarecords-' . $table . '-' . $type;
+                               foreach ($recordType as &$type) {
+                                       $type = 'tcarecords-' . $table . '-' . $type;
                                }
+                               unset($type);
                                $recordType[0] = 'tcarecords-' . $table . '-default';
                        }
                } else {
@@ -873,9 +841,11 @@ final class t3lib_iconWorks {
                        }
                }
                krsort($recordType);
-               foreach ($recordType as $iconName) {
-                       if (in_array($iconName, $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'])) {
-                               return $iconName;
+               if (is_array($GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'])) {
+                       foreach ($recordType as $iconName) {
+                               if (in_array($iconName, $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'])) {
+                                       return $iconName;
+                               }
                        }
                }
                return 'status-status-icon-missing';
@@ -958,15 +928,28 @@ final class t3lib_iconWorks {
                        $status['protectedSection'] = TRUE;
                }
 
+                       // Hook: allow some other process to influence the choice of icon overlay
+                       // The method called receives the table name, the current row and the current status array as parameters
+                       // The status array should be passed as a reference and in order to be modified within the hook
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'] as $classRef) {
+                               $hookObject = t3lib_div::getUserObj($classRef);
+                               if (method_exists($hookObject, 'overrideIconOverlay')) {
+                                       $hookObject->overrideIconOverlay($table, $row, $status);
+                               }
+                       }
+               }
 
                        // now only show the status with the highest priority
                $priorities = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayPriorities'];
 
                $iconName = '';
-               foreach ($priorities as $priority) {
-                       if ($status[$priority]) {
-                               $iconName = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayNames'][$priority];
-                               break;
+               if (is_array($priorities)) {
+                       foreach ($priorities as $priority) {
+                               if ($status[$priority]) {
+                                       $iconName = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayNames'][$priority];
+                                       break;
+                               }
                        }
                }