Zum Inhalt springen

dynamic css - fehlermeldung

Erstellt am 3. Dezember 2006 · 1 Antwort · letzte Antwort am 7. Februar 2007

Tags: Frage

ran2 ·

langsam habe ich dynamic css installiert bekommen.
so einigermaßen funktionier das ersetzen der marker im css auch... nur leider habe ich jetzt immer diese fehlermeldung:

Warning: Invalid argument supplied for foreach() in typo3conf\ext\af_dynamiccss\class.tx_afdynamiccss.php on line 71

hat jemand ne idee ?

liquid ·

Hallo,

hast Du das Problem lösen können? Ich habe auch gerade die Ext installiert, und hatte das gleich Problem.
Und zwar habe ich in der Datei class.tx_afdynamiccss.php einfach einen check eingefügt, ob das array auch ein array ist.
Die veränderte Datei füge ich mal hier ein, vielleicht kann der/die ein oder andere das ja brauchen. Den Autor der ext habe ich auch benachrichtigt.

so long

Sascha

<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2004 Robert Fink (rf@robertfink.de)
*  (c) 2006 Andreas Ferber <af@chaos-agency.de>
*  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.
*
*  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!
***************************************************************/
/**
 * Plugin 'Dynamic CSS' for the 'af_DynamicCSS' extension.
 *
 * @author	Robert Fink <rf@robertfink.de>
 * @author	Andreas Ferber <af@chaos-agency.de>
 */


class tx_afDynamicCSS {

	function outputHook($params, $pObj) {
		$conf = $pObj->tmpl->setup['plugin.']['tx_afdynamiccss.'];
		$this->compileCSS('', $conf);
	}

	function compileCSS ($content, $conf) {
		$maxBytes = $conf['maxBytes'];
		$compress = $conf['compress'];

		$styles = $conf['styles.'];
		$search = array();
		$replace = array();
		if (is_array($styles)) {
			foreach ($styles as $key => $value) {
				$search[] = '/###'.$key.'###/';
				$replace[] = $value;
			}
		}

		$force = true;
		$newmd5 = md5(serialize(array($search, $replace, $compress)));

		$handle = @fopen(PATH_site.'typo3temp/tx_afdynamiccss_state', 'r');
		if ($handle) {
			$oldmd5 = fread($handle, 500);
			fclose($handle);
			if ($oldmd5 == $newmd5) {
				$force = false;
			}
		}

		if (is_array($dirs)) {
			$dirs = $conf['dir.'];
			foreach ($dirs as $dir) {
				$files = glob($dir['dir'].'/*.'.$dir['ext']);
				foreach ($files as $file) {
					$output = $dir['dir'].'/'.basename($file, '.'.$dir['ext']);
					if ($force || !@is_file($output) || filemtime($output) <= filemtime($file)) {
						$handle = fopen($file, 'r');
						if ($handle) {
							$css = fread($handle, $maxBytes);
							fclose($handle);

							$css = preg_replace($search, $replace, $css);
							if ($compress) {
								$css = $this->css_compress($css);
							}

							$handle = fopen($output, 'w');
							if ($handle) {
								fwrite($handle, $css);
								fclose($handle);
							}
						}
					}
				}
			}
		}

		$files = $conf['file.'];
		if (is_array($dirs)) {
			foreach ($files as $file) {
				if ($force || !@is_file($file['output']) || filemtime($file['output']) <= filemtime($file['input'])) {
					$handle = fopen($file['input'], 'r');
					$css = fread($handle, $maxBytes);
					fclose ($handle);

					$css = preg_replace($search, $replace, $css);
					if ($compress) {
						$css = $this->css_compress($css);
					}

					$handle = fopen($file['output'], 'w');
					fwrite($handle, $css);
					fclose($handle);
				}
			}
		}

		$handle = @fopen(PATH_site.'typo3temp/tx_afdynamiccss_state', 'w');
		if ($handle) {
			fwrite($handle, $newmd5);
			fclose($handle);
		}

		return '';
	}

	/**
	 * Very simple CSS optimizer
	 *
	 * @author Andreas Gohr <andi@splitbrain.org>
	 */
	function css_compress($css){
		//strip comments through a callback
		$css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','tx_afdynamiccss_comment_cb',$css);

		//strip (incorrect but common) one line comments
		$css = preg_replace('/(?<!:)\/\/.*$/m','',$css);

		// strip whitespaces
		$css = preg_replace('![\r\n\t ]+!',' ',$css);
		$css = preg_replace('/ ?([:;,{}\/]) ?/','\\1',$css);

		// shorten colors
		$css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1}+)\\3/", "#\\1\\2\\3",$css);

		return $css;
	}

}

/**
 * Callback for css_compress()
 *
 * Keeps short comments (< 5 chars) to maintain typical browser hacks
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function tx_afdynamiccss_comment_cb($matches){
	if(strlen($matches[2]) > 4) return '';
	return $matches[0];
}


if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/af_dynamiccss/class.tx_afdynamiccss.php"])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/af_dynamiccss/class.tx_afdynamiccss.php"]);
}


?>