/**
	 * lessc
	 *
	 * @return void
	 */
	public function lessc( $files )
	{

		// create outputfolder if it does not exist
		if( !is_dir( $this->outputfolder ) )
		{
			t3lib_div::mkdir_deep( '', $this->outputfolder );
		}

		// compile each less-file
		foreach( $files as $file )
		{
			//get only the name of less file
			$filename = array_pop( explode( '/', $file ) );

			$md5 = md5( $filename . md5_file( $file ) );

			$outputfile = $this->outputfolder . substr( $filename, 0, -5 ) . '_' . $md5 . '.css';

			if( $this->configuration['other']['forceMode'] && file_exists( $outputfile ) )
			{
				unlink( $outputfile );
			}

			if( !file_exists( $outputfile ) )
			{
				$compressed = $this->configuration['other']['compressed'] ? '--compress' : '';

				/* Define directories for @import scripts */
				$importDirs = '';
				if( isset( $this->configuration['other']['importDirs'] ) )
				{
					$importDirs = implode( ':', Tx_T3Less_Utility_Utilities::splitAndResolveDirNames( $this->configuration['other']['importDirs'] ) );
				}

				$lesscCommand = sprintf( 'lessc %s --line-numbers=\'comments\' --include-path=%s %s > %s 2>&1', $compressed, $importDirs, $file, $outputfile );
				$lesscOutput = array( );
				$lesscStatus = 0;
				exec( $lesscCommand, $lesscOutput, $lesscStatus );

				t3lib_div::fixPermissions( $outputfile, FALSE );
			}
		}

		// unlink compiled files which have no equal source less-file
		if( $this->configuration['other']['unlinkCssFilesWithNoSourceFile'] == 1 )
		{
			$this->unlinkGeneratedFilesWithNoSourceFile( $files );
		}

		$files = t3lib_div::getFilesInDir( $this->outputfolder, "css" );
		//respect given sort order defined in TS
		usort( $files, array( $this, 'getSortOrderPhp' ) );

		foreach( $files as $cssFile )
		{
			$excludeFromPageRender = isset( $this->configuration['phpcompiler']['filesettings'][substr( $cssFile, 0, -37 )]['excludeFromPageRenderer'] ) ? $this->configuration['phpcompiler']['filesettings'][substr( $cssFile, 0, -37 )]['excludeFromPageRenderer'] : 0;
			if( !$excludeFromPageRender || $excludeFromPageRender == 0 )
			{
				// array with filesettings from TS
				$tsOptions = $this->configuration['phpcompiler']['filesettings'][substr( $cssFile, 0, -37 )];

				$GLOBALS['TSFE']->getPageRenderer()->addCssFile(
					$this->outputfolder . $cssFile, $rel = 'stylesheet', $media = isset( $tsOptions['media'] ) ? $tsOptions['media'] : 'all', $title = isset( $tsOptions['title'] ) ? $tsOptions['title'] : '', $compress = isset( $tsOptions['compress'] ) && $tsOptions['compress'] >= '0' ? (boolean) $tsOptions['compress'] : TRUE, $forceOnTop = isset( $tsOptions['forceOnTop'] ) && $tsOptions['forceOnTop'] >= '0' ? (boolean) $tsOptions['forceOnTop'] : FALSE, $allWrap = isset( $tsOptions['allWrap'] ) ? $tsOptions['allWrap'] : '', $excludeFromConcatenation = isset( $tsOptions['excludeFromConcatenation'] ) && $tsOptions['excludeFromConcatenation'] >= '0' ? (boolean) $tsOptions['excludeFromConcatenation'] : FALSE
				);
			}
		}
	}
	function checkForAdditionalConfiguration( $less )
	{
		/* Define directories for @import scripts */
		if( isset( $this->configuration['other']['importDirs'] ) )
		{
			$importDirs = explode( ',', str_replace( ', ', ',', $this->configuration['other']['importDirs'] ) );
			foreach( $importDirs as $importDir )
			{
				$less->addImportDir( Tx_T3Less_Utility_Utilities::getPath( $importDir ) );
			}
		}
		// register custom functions, #36273

		if( is_array( $this->configuration['phpcompiler']['registerFunctions'] ) )
		{
			foreach( $this->configuration['phpcompiler']['registerFunctions'] as $key => $funcRef )
			{
				$parts = explode( '->', $funcRef );

				if( count( $parts ) == 2 )
				{
					$hookObject = t3lib_div::getUserObj( $parts[0] );
					if( is_object( $hookObject ) && method_exists( $hookObject, $parts[1] ) )
					{
						$less->registerFunction( $key, array( $hookObject, $parts[1] ) );
					}
				}
			}
		}
	}
	/**
	 * action base
	 *
	 */
	public function baseAction()
	{
		if( TYPO3_MODE != 'FE' )
		{
			return;
		}

		$files = array( );
		// compiler activated?
		if( $this->configuration['other']['activateCompiler'] )
		{
			// folders defined?
			if( $this->lessfolder && $this->outputfolder )
			{
				// are there files in the defined less folder?
				if( t3lib_div::getFilesInDir( $this->lessfolder, "less", TRUE ) )
				{
					$files = t3lib_div::getFilesInDir( $this->lessfolder, "less", TRUE );
				}
				else
				{
					echo Tx_T3Less_Utility_Utilities::wrapErrorMessage( Tx_Extbase_Utility_Localization::translate( 'noLessFilesInFolder', $this->extensionName, $arguments = array( 's' => $this->lessfolder ) ) );
				}
			}
			else
			{
				echo Tx_T3Less_Utility_Utilities::wrapErrorMessage( Tx_Extbase_Utility_Localization::translate( 'emptyPathes', $this->extensionName ) );
			}
		}


		/* Hook to pass less-files from other extension, see manual */
		if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3less']['addForeignLessFiles'] ) )
		{
			foreach( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3less']['addForeignLessFiles'] as $hookedFilePath )
			{
				$hookPath = Tx_T3Less_Utility_Utilities::getPath( $hookedFilePath );
				$files[] = t3lib_div::getFilesInDir( $hookPath, "less", TRUE );
			}
			$files = Tx_T3Less_Utility_Utilities::flatArray( null, $files );
		}

		switch( $this->configuration['enable']['mode'] )
		{
			case 'PHP-Compiler':
				$controller = t3lib_div::makeInstance( 'Tx_T3Less_Controller_LessPhpController' );
				$controller->lessPhp( $files );
				break;

			case 'JS-Compiler':
				$controller = t3lib_div::makeInstance( 'Tx_T3Less_Controller_LessJsController' );
				$controller->lessJs( $files );
				break;

			case 'JS-Compiler via Node.js':
				$controller = t3lib_div::makeInstance( 'Tx_T3Less_Controller_LessJsNodeController' );
				if( $controller->isLesscInstalled() )
				{
					$controller->lessc( $files );
				}
				else
				{
					echo Tx_T3Less_Utility_Utilities::wrapErrorMessage( Tx_Extbase_Utility_Localization::translate( 'lesscRequired', $this->extensionName ) );
				}
				break;
		}
	}