TYPO3 API  SVNRelease
class.t3lib_spritemanager_simplehandler.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Steffen Ritter <info@steffen-ritter.net>
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 
00029 /**
00030  * A class with an concrete implementation of t3lib_spritemanager_SpriteIconGenerator.
00031  * It is the standard / fallback handler of the sprite manager.
00032  * This implementation won't generate sprites at all. It will just render css-definitions
00033  * for all registered icons so that they may be used through t3lib_iconWorks::getSpriteIcon*
00034  * Without the css classes generated here, icons of for example tca records would be empty.
00035  *
00036  * @author  Steffen Ritter <info@steffen-ritter.net>
00037  * @package TYPO3
00038  * @subpackage t3lib
00039  */
00040 class t3lib_spritemanager_SimpleHandler extends t3lib_spritemanager_AbstractHandler {
00041 
00042     /**
00043      * css template for single Icons registered by extension authors
00044      * @var String
00045      */
00046     protected $styleSheetTemplateExtIcons = '
00047 .t3-icon-###NAME### {
00048     background-position: 0px 0px !important;
00049     background-image: url(\'###IMAGE###\') !important;
00050 }
00051     ';
00052 
00053     /**
00054      * constructor just init's the temp-file-name
00055      * @return void
00056      */
00057     function __construct() {
00058         parent::__construct();
00059     }
00060 
00061     /**
00062      * Interface function. This will be called from the sprite manager to
00063      * refresh all caches.
00064      *
00065      * @return void
00066      */
00067     public function generate() {
00068 
00069             // generate IconData for single Icons registered
00070         $this->buildCssAndRegisterIcons();
00071 
00072         parent::generate();
00073     }
00074 
00075 
00076     /**
00077      * This function builds an css class for every single icon registered via
00078      * t3lib_SpriteManager::addSingleIcons to use them via t3lib_iconWorks::getSpriteIcon
00079      * and TCA-Icons for "classic" record Icons to be uses via t3lib_iconWorks::getSpriteIconForRecord
00080      * In the simpleHandler the icon just will be added as css-background-image.
00081      *
00082      * @return void
00083      */
00084     protected function buildCssAndRegisterIcons() {
00085             // backpath from the stylesheet file ($cssTcaFile) to PATH_site dir
00086             // in order to set the background-image URL paths correct
00087         $iconPath = '../../' . TYPO3_mainDir;
00088 
00089         $iconsToProcess = array_merge(
00090             (array) $GLOBALS['TBE_STYLES']['spritemanager']['singleIcons'],
00091             $this->collectTcaSpriteIcons()
00092         );
00093         foreach ($iconsToProcess as $iconName => $iconFile) {
00094             $css = str_replace('###NAME###', str_replace(
00095                 array('extensions-', 'tcarecords-'), array('', ''), $iconName
00096             ), $this->styleSheetTemplateExtIcons);
00097             $css = str_replace('###IMAGE###', t3lib_div::resolveBackPath($iconPath . $iconFile), $css);
00098 
00099             $this->iconNames[] = $iconName;
00100             $this->styleSheetData .= $css;
00101         }
00102     }
00103 }
00104 
00105 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/spritemanager/class.t3lib_spritemanager_simplehandler.php'])) {
00106     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/spritemanager/class.t3lib_spritemanager_simplehandler.php']);
00107 }
00108 ?>