Cleanup #16002: Refactoring of t3lib_spritemanager_SimpleHandler (Thanks to Steffen...
[Packages/TYPO3.CMS.git] / t3lib / spritemanager / class.t3lib_spritemanager_simplehandler.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Steffen Ritter <info@steffen-ritter.net>
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28
29 /**
30 * A class with an concrete implementation of t3lib_spritemanager_SpriteIconGenerator.
31 * It is the standard / fallback handler of the sprite manager.
32 * This implementation won't generate sprites at all. It will just render css-definitions
33 * for all registered icons so that they may be used through t3lib_iconWorks::getSpriteIcon*
34 * Without the css classes generated here, icons of for example tca records would be empty.
35 *
36 * @author Steffen Ritter <info@steffen-ritter.net>
37 * @package TYPO3
38 * @subpackage t3lib
39 */
40 class t3lib_spritemanager_SimpleHandler extends t3lib_spritemanager_AbstractHandler {
41
42 /**
43 * css template for single Icons registered by extension authors
44 * @var String
45 */
46 protected $styleSheetTemplateExtIcons = '
47 .t3-icon-###NAME### {
48 background-position: 0px 0px;
49 background-image: url(\'###IMAGE###\');
50 }
51 ';
52
53 /**
54 * constructor just init's the temp-file-name
55 * @return void
56 */
57 function __construct() {
58 parent::__construct();
59 }
60
61 /**
62 * Interface function. This will be called from the sprite manager to
63 * refresh all caches.
64 *
65 * @return void
66 */
67 public function generate() {
68
69 // generate IconData for single Icons registered
70 $this->buildCssAndRegisterIcons();
71
72 parent::generate();
73 }
74
75
76 /**
77 * This function builds an css class for every single icon registered via
78 * t3lib_SpriteManager::addSingleIcons to use them via t3lib_iconWorks::getSpriteIcon
79 * and TCA-Icons for "classic" record Icons to be uses via t3lib_iconWorks::getSpriteIconForRecord
80 * In the simpleHandler the icon just will be added as css-background-image.
81 *
82 * @return void
83 */
84 protected function buildCssAndRegisterIcons() {
85 // backpath from the stylesheet file ($cssTcaFile) to PATH_site dir
86 // in order to set the background-image URL paths correct
87 $iconPath = '../../' . TYPO3_mainDir;
88
89 $iconsToProcess = array_merge(
90 (array) $GLOBALS['TBE_STYLES']['spritemanager']['singleIcons'],
91 $this->collectTcaSpriteIcons()
92 );
93 foreach ($iconsToProcess as $iconName => $iconFile) {
94 $css = str_replace('###NAME###', str_replace(
95 array('extensions-', 'tcarecords-'), array('', ''), $iconName
96 ), $this->styleSheetTemplateExtIcons);
97 $css = str_replace('###IMAGE###', t3lib_div::resolveBackPath($iconPath . $iconFile), $css);
98
99 $this->iconNames[] = $iconName;
100 $this->styleSheetData .= $css;
101 }
102 }
103 }
104
105 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/spritemanager/class.t3lib_spritemanager_simplehandler.php']) {
106 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/spritemanager/class.t3lib_spritemanager_simplehandler.php']);
107 }
108 ?>