Index: t3lib/interfaces/interface.t3lib_spritemanager_spriteicongenerator.php =================================================================== --- t3lib/interfaces/interface.t3lib_spritemanager_spriteicongenerator.php (Revision 0) +++ t3lib/interfaces/interface.t3lib_spritemanager_spriteicongenerator.php (Revision 0) @@ -0,0 +1,56 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* A copy is found in the textfile GPL.txt and important notices to the license +* from the author is found in LICENSE.txt distributed with these scripts. +* +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + +/** + * Interface all handlers in t3lib_spriteManager has to implement. + * + * @author Steffen Ritter + * @package TYPO3 + * @subpackage t3lib + */ +interface t3lib_spriteManager_spriteIconGenerator { + + /** + * the implementation of this function has to do the main task + * this function will be called if the extension list changed or + * registered icons in TBE_STYLES[spriteManager] changed + * + * @return void + */ + public function generate(); + + /** + * the spriteManager will call this function after the call to "generate" + * it should return an array of all sprite-icon-names generated through the run + * + * @retun array all generated/detected sprite-icon-names + */ + public function getAvailableIconNames(); +} + +?> \ No newline at end of file Index: t3lib/config_default.php =================================================================== --- t3lib/config_default.php (Revision 7574) +++ t3lib/config_default.php (Arbeitskopie) @@ -259,6 +259,7 @@ 'explicitConfirmationOfTranslation' => FALSE, // If set, then the diff-data of localized records is not saved automatically when updated but requires that a translator clicks the special finish_translation/save/close button that becomes available. 'elementVersioningOnly' => FALSE, // If true, only element versioning is allowed in the backend. This is recommended for new installations of TYPO3 4.2+ since "page" and "branch" versioning types are known for the drawbacks of loosing ids and "element" type versions supports moving now. 'versionNumberInFilename' => FALSE, // Boolean. If true, included CSS and JS files will have the timestamp embedded in the filename, ie. filename.1269312081.js. This will make browsers and proxies reload the files if they change (thus avoiding caching issues). IMPORTANT: this feature requires this .htaccess rule to work: RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]. If false the filemtime will be appended as a query-string. + 'spriteIconGenerator_handler' => '', // String: Used to register own/other spriteGenerating Handler, they have to implement the interface t3lib_spriteManager_spriteIconGenerator 'AJAX' => array( // array of key-value pairs for a unified use of AJAX calls in the TYPO3 backend. Keys are the unique ajaxIDs where the value will be resolved to call a method in an object. See ajax.php and the classes/class.typo3ajax.php for more information. 'SC_alt_db_navframe::expandCollapse' => 'typo3/alt_db_navframe.php:SC_alt_db_navframe->ajaxExpandCollapse', 'SC_alt_file_navframe::expandCollapse' => 'typo3/alt_file_navframe.php:SC_alt_file_navframe->ajaxExpandCollapse', Index: t3lib/class.t3lib_spritemanager.php =================================================================== --- t3lib/class.t3lib_spritemanager.php (Revision 0) +++ t3lib/class.t3lib_spritemanager.php (Revision 0) @@ -0,0 +1,179 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* A copy is found in the textfile GPL.txt and important notices to the license +* from the author is found in LICENSE.txt distributed with these scripts. +* +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + +/** + * TYPO3 Sprite Manager, it is initiated from BE and FE if BE-User ist active + * Its task will be to build css-definitions for registered Icons of Extensions, + * TCA-Tables and so on, so that they will be usuable through sprite-icon-api. + * An special configurable handler-class will process the "real" task so that the user + * may differ between details of generation and their caching. + * + * @author Steffen Ritter + * @package TYPO3 + * @subpackage t3lib + */ +class t3lib_spriteManager { + public static $tempPath = 'typo3temp/sprites/'; + + /** + *@var t3lib_spriteManager_spriteIconGenerator + */ + protected $handler = NULL; + + /** + * @var array + */ + protected $iconNames = array(); + + /** + * @var string the file name the current cache file + */ + protected $tempFileName = ''; + + /** + * class constructor checks if cache has to be rebuild and initiates the rebuild + * instantiates the handler class + * + * @param boolean $regenerate with set to false, cache won't be regenerated if needed (useful for feediting) + * @return void + */ + function __construct($regenerate = TRUE) { + // we check for existance of our targetDirectory + if (!is_dir(PATH_site . t3lib_spriteManager::$tempPath)) { + t3lib_div::mkdir(PATH_site . t3lib_spriteManager::$tempPath); + } + // create a fileName, the hash includes all icons and css-styles registered and the extlist + $this->tempFileName = PATH_site . t3lib_spriteManager::$tempPath . md5(serialize($GLOBALS['TBE_STYLES']['spriteManager']) . $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList']) . '.inc'; + // if no cache-file for the current config ist present, regenerate it + if(!@file_exists($this->tempFileName)) { + // regenerate if allowed + if($regenerate) { + $handlerClass = ( + $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconGenerator_handler'] ? + $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconGenerator_handler'] : + 't3lib_spriteManager_simpleHandler' + ); + $this->handler = t3lib_div::makeInstance($handlerClass); + // check if the handler could be loaded and implements the needed interface + if(!$this->handler || !($this->handler instanceof t3lib_spriteManager_spriteIconGenerator)) { + throw new Exception("class in TYPO3_CONF_VARS[BE][spriteIconGenerator_handler] does not exist, or does not implement t3lib_spriteManager_spriteIconGenerator"); + } + // all went good? to go for rebuild + $this->rebuildCache(); + } else { + // use old file if present + list($this->tempFileName) = t3lib_div::getFilesInDir(PATH_site . t3lib_spriteManager::$tempPath, 'inc', 1); + } + } + } + + /** + * this method calls the main methods from the handler classes + * merges the results with the data from the skin, and cache it + * + * @return void + */ + protected function rebuildCache() { + // ask the handlerClass to kindly rebuild our data + $this->handler->generate(); + + // get active skin Name + list($activeSkin) = $GLOBALS['TBE_STYLES']['skins']; + $activeSkin = $activeSkin['name']; + + // merge icon names whith them provided by the skin, + // registered from "complete sprites" and the ones detected + // by the handlerclass + $this->iconNames = array_merge( + (array)$GLOBALS['TBE_STYLES']['skins'][$activeSkin]['availableSpriteIcons'], + (array)$GLOBALS['TBE_STYLES']['spriteManager']['spriteIconsAvailable'], + $this->handler->getAvailableIconNames() + ); + + // serialize found icons, and cache them to file + $cacheString = addslashes(serialize($this->iconNames)); + $fileContent = ''; + + // delete old cache files + $oldFiles = t3lib_div::getFilesInDir(PATH_site . t3lib_spriteManager::$tempPath, 'inc', 1); + foreach($oldFiles AS $file) { + @unlink($file); + } + // and write the new one + t3lib_div::writeFile($this->tempFileName, $fileContent); + } + + + /** + * includes the generated cacheFile, if present + * + * @return void + */ + public function loadCacheFile() { + if(@file_exists($this->tempFileName)) { + include_once($this->tempFileName); + } + } + + /** + * if an extension has an pregenerated sprite, it might register it here. + * Giving the "available" iconNames and the styleSheetFile where the sprite icons are defined (make shure the css filename contains the extname to be unique). + * the iconnames and the stylesheet must follow the conventions as follows: + * IconName: extensions-$extKey-$iconName. + * Class for loading the sprite: t3-icon-extensions-$extKey + * Class for single icons: t3-icon-$extKey-$iconName + * NOTE: do not use this for skins, stylesheets of skins will be included automatically. + * Available icons of skins should be located manually (extTables) to $GLOBALS[TBE_STYLES][skins][skinName][availableIcons] + * + * @param array icons the names of the introduced icons + * @parram string $styleSheetFile the name of the styleshet file relative to PATH_site + */ + public static function addIconSprite(array $icons, $styleSheetFile) { + $GLOBALS['TBE_STYLES']['spriteManager']['spriteIconsAvailable'] = array_merge( + $GLOBALS['TBE_STYLES']['spriteManager']['spriteIconsAvailable'], + $icons + ); + + $GLOBALS['TBE_STYLES']['spriteManager']['cssFiles'][] = $styleSheetFile; + } + + /** + * will allow Ext-Developers to register their icons to get included in sprites, + * they may use them afterwards with t3lib_iconWorks::getSpriteIcon('extensions-$extKey-iconName'); + * @param array $icons array which contains the adding icons array ( $iconname => $iconFile) $iconFile relative to PATH_typo3 + * @param string $extKey string of the extension which adds the icons + * @return void + */ + public static function addSingleIcons(array $icons, $extKey = '') { + foreach ($icons AS $iconName => $iconFile) { + $GLOBALS['TBE_STYLES']['spriteManager']['singleIcons']['extensions-' . $extKey . '-' . $iconName] = $iconFile; + } + } +} + +?> \ No newline at end of file Index: t3lib/core_autoload.php =================================================================== --- t3lib/core_autoload.php (Revision 7574) +++ t3lib/core_autoload.php (Arbeitskopie) @@ -126,6 +126,9 @@ 't3lib_utility_client' => PATH_t3lib . 'utility/class.t3lib_utility_client.php', 't3lib_utility_http' => PATH_t3lib . 'utility/class.t3lib_utility_http.php', 't3lib_utility_mail' => PATH_t3lib . 'utility/class.t3lib_utility_mail.php', + 't3lib_spritemanager' => PATH_t3lib . 'class.t3lib_spritemanager.php', + 't3lib_spritemanager_spriteicongenerator' => PATH_t3lib . 'interfaces/interface.t3lib_spritemanager_spriteicongenerator.php', + 't3lib_spritemanager_simplehandler' => PATH_t3lib . 'spriteManager/class.t3lib_spritemanager_simplehandler.php', 'tslib_adminpanel' => PATH_tslib . 'class.tslib_adminpanel.php', 'tslib_cobj' => PATH_tslib . 'class.tslib_content.php', 'tslib_frameset' => PATH_tslib . 'class.tslib_content.php', Index: t3lib/spriteManager/class.t3lib_spritemanager_simplehandler.php =================================================================== --- t3lib/spriteManager/class.t3lib_spritemanager_simplehandler.php (Revision 0) +++ t3lib/spriteManager/class.t3lib_spritemanager_simplehandler.php (Revision 0) @@ -0,0 +1,246 @@ + +* All rights reserved +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* A copy is found in the textfile GPL.txt and important notices to the license +* from the author is found in LICENSE.txt distributed with these scripts. +* +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + + +/** + * A class with an concrete implementation of t3lib_spriteManager_spriteIconGenerator. + * It is the standard / fallback handler of the spriteManager. + * This implementation won't generate sprites at all. It will just render css-definitions + * for all registered icons so that they may be used through t3lib_iconWorks::getSpriteIcon* + * Without the css classes generated here, icons of for example tca records would be empty. + * + * @author Steffen Ritter + * @package TYPO3 + * @subpackage t3lib + */ +class t3lib_spriteManager_simpleHandler implements t3lib_spriteManager_spriteIconGenerator { + /** + * all "registered" Icons available through sprite-api will cumuluated within + * @var array + */ + protected $iconNames = array(); + + /** + * contains the content of the CSS file to write + * @var String + */ + protected $styleSheetData = "/* Auto-Generated via t3lib_spriteManager_simpleHandler */\n"; + + /** + * css-template for each sprite-icon of an tca-record-symbol + * @var String + */ + protected $styleSheetTemplateTCA = ' + .t3-icon-###TABLE###-###TYPE### { + background-position: 0px 0px !important; + background-image: url(\'###IMAGE###\') !important; + } +'; + /** + * css template for single Icons registered by extension authors + * @var String + */ + protected $styleSheetTemplateExtIcons = ' + .t3-icon-###NAME### { + background-position: 0px 0px; + background-image: url(\'###IMAGE###\'); + } +'; + /** + * path to css file for generated styles + * @var String + */ + protected $cssTcaFile = ""; + + /** + * constructor just init's the temp-file-name + * @return void + */ + function __construct() { + // the fileName is prefixed with "z" since the concatenator orders files per name + $this->cssTcaFile = PATH_site . t3lib_spriteManager::$tempPath . 'zextensions.css'; + } + + /** + * Interface function. This will be called from the spriteManager to refresh + * all caches. + * + * @return void + */ + public function generate() { + // generate Icons for all TCA tables + $this->buildTcaSpriteIcons(); + + // generate IconData for single Icons registered + $this->buildExtensionSpriteIcons(); + + // include registered Sprites + $this->loadRegisteredSprites(); + + // cache results in the CSS file + t3lib_div::writeFile($this->cssTcaFile, $this->styleSheetData); + } + + + /** + * This function builds an css class for every single icon registered via + * t3lib_spriteManager::addSingleIcons to use them via t3lib_iconWorks::getSpriteIcon + * In the simpleHandler the icon just will be added as css-background-image. + * + * @return void + */ + protected function buildExtensionSpriteIcons() { + // backpath from the stylesheet file ($cssTcaFile) to typo3 dir + // in order to set the background-image URL paths correct + $iconPath = '../../' . TYPO3_mainDir; + + foreach((array)$GLOBALS['TBE_STYLES']['spriteManager']['singleIcons'] AS $iconName => $iconFile) { + $css = str_replace('###NAME###', str_replace('extensions-', '', $iconName), $this->styleSheetTemplateExtIcons); + $css = str_replace('###IMAGE###', t3lib_div::resolveBackPath($iconPath . $iconFile), $css); + + $this->iconNames[] = $iconName; + $this->styleSheetData .= $css; + } + } + + /** + * loads all StyleSheets Files registered through t3lib_spriteManager::addIconSprite + * in fact the stylesheet-files are copied to t3lib_spriteManager::tempPath where they automatically + * will be included from via template.php and t3lib_compressor. + * + * @return void + */ + protected function loadRegisteredSprites() { + // saves which CSS Files are currently "allowed to be in place" + $allowedCSSFilesinTempDir = array(basename($this->cssTcaFile)); + // process every registeres file + foreach((array)$GLOBALS['TBE_STYLES']['spriteManager']['cssFiles'] AS $file) { + $fileName = basename($file); + // file should be present + $allowedCSSFilesinTempDir[] = $fileName; + // get-Cache Filename + $unique = md5($fileName . filemtime(PATH_site . $file) . filesize(PATH_site . $file)); + $cacheFile = PATH_site . t3lib_spriteManager::$tempPath . $fileName . $unique . '.css'; + if(!file_exists($cacheFile)) { + copy(PATH_site . $file, $cacheFile); + } + } + // get all .css files in dir + $cssFilesPresentInTempDir = t3lib_div::getFilesInDir(PATH_site . t3lib_spriteManager::$tempPath , '.css', 0); + // and delete old ones which are not needed anymore + $filesToDelete = array_diff($cssFilesPresentInTempDir, $allowedCSSFilesinTempDir); + foreach ($filesToDelete AS $file) { + unlink(PATH_site . t3lib_spriteManager::$tempPath . $file); + } + } + + /** + * public-interface function: getter for iconNames + * will return the detected icon-names which may be used throug t3lib_iconWorks::getSpriteIcon + * + * @return array all generated and registred sprite-icon-names + */ + public function getAvailableIconNames() { + return $this->iconNames; + } + + /** + * this method creates SpriteIcon names for all tables in TCA (including their possible type-icons) + * where there is no "typeicon_classes" of this TCA table ctrl section (moved form t3lib_iconWorks) + * + * @return void + */ + protected function buildTcaSpriteIcons() { + $TCAtables = array_keys($GLOBALS['TCA']); + + // delete old tempFiles + @unlink($this->cssTcaFile); + + // backpath from the stylesheet file ($cssTcaFile) to typo3 dir + // in order to set the background-image URL paths correct + $iconPath = '../../' . TYPO3_mainDir; + + // path (relative from typo3 dir) for skin-Images + if (isset($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'])) { + $skinPath = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir']; + } else { + $skinPath = ''; + } + + // check every table in the TCA, if an icon is needed + foreach ($TCAtables as $tableName) { + + // this method is only needed for TCA tables where + // typeicon_classes are not configured + if (!is_array($GLOBALS['TCA'][$tableName]['ctrl']['typeicon_classes'])) { + $tcaCtrl = $GLOBALS['TCA'][$tableName]['ctrl']; + + $template = str_replace('###TABLE###', $tableName, $this->styleSheetTemplateTCA); + + // adding the default Icon (without types) + if (isset($tcaCtrl['iconfile'])) { + // in CSS wie need a path relative to the css file + // [TCA][ctrl][iconfile] defines icons without path info to reside in /gfx/i/ + if (strpos($tcaCtrl['iconfile'], '/') !== FALSE) { + $icon = $tcaCtrl['iconfile']; + } else { + $icon = $skinPath . 'gfx/i/' . $tcaCtrl['iconfile']; + } + + $icon = t3lib_div::resolveBackPath($iconPath . $icon); + + // saving default icon + $stylesString = str_replace('###TYPE###', 'default', $template); + $stylesString = str_replace('###IMAGE###', $icon, $stylesString); + $this->styleSheetData .= $stylesString; + $this->iconNames[] = 'tcarecords-' . $tableName . '-default'; + } + + // if records types are available, register them + if (isset($tcaCtrl['typeicon_column']) && is_array($tcaCtrl['typeicons'])) { + foreach ($tcaCtrl['typeicons'] as $type => $icon) { + + // in CSS wie need a path relative to the css file + // [TCA][ctrl][iconfile] defines icons without path info to reside in /gfx/i/ + if (strpos($icon, '/') === FALSE) { + $icon = $skinPath . 'gfx/i/' . $icon; + } + + $icon = t3lib_div::resolveBackPath($iconPath . $icon); + $stylesString = str_replace('###TYPE###', $type, $template); + $stylesString = str_replace('###IMAGE###', $icon, $stylesString); + // saving type icon + $this->styleSheetData .= $stylesString; + $this->iconNames[] = 'tcarecords-' . $tableName . '-' . $type; + } + } + } + } + } +} + +?> \ No newline at end of file Index: typo3/init.php =================================================================== --- typo3/init.php (Revision 7574) +++ typo3/init.php (Arbeitskopie) @@ -394,6 +394,9 @@ include (PATH_typo3conf.TYPO3_extTableDef_script); } + // load TYPO3 SpriteGenerating API +$spriteManager = t3lib_div::makeInstance('t3lib_spriteManager', TRUE); +$spriteManager->loadCacheFile(); // ******************************* Index: typo3/sysext/cms/tslib/index_ts.php =================================================================== --- typo3/sysext/cms/tslib/index_ts.php (Revision 7574) +++ typo3/sysext/cms/tslib/index_ts.php (Arbeitskopie) @@ -345,6 +345,10 @@ // Admin Panel & Frontend editing // ***************************************** if ($TSFE->beUserLogin) { + // if a BE User is present load the spriteManager for frontend-editing + $spriteManager = t3lib_div::makeInstance('t3lib_spriteManager', FALSE); + $spriteManager->loadCacheFile(); + $BE_USER->initializeFrontendEdit(); if ($BE_USER->adminPanel instanceof tslib_AdminPanel) { $LANG = t3lib_div::makeInstance('language');