<?php

/**
 * This class generates custom CSS into static CSS file in uploads folder
 * and enqueue it in the frontend
 *
 * CSS is generated only when theme options is saved (changed)
 * Works with LESS (for unlimited color schemes)
 *
 *
 */
require_once( TP_FRAMEWORK_LIBS_DIR . "less/lessc.inc.php" );
require_once( THIM_DIR . "inc/admin/theme-options-to-css.php" );

function generate( $fileout ) {
	$css = "";
	WP_Filesystem();
	$theme_options_data = '';
	global $wp_filesystem;
	$options = get_theme_mods();

 	$compiler = new lessc;
 	$compiler->setFormatter( 'compressed' );

	$theme_options_data .= themeoptions_variation( $options );
	$theme_options_data .= $wp_filesystem->get_contents( THIM_DIR . 'less/theme-options.less' );

	$css .= $compiler->compile( $theme_options_data );
	$css .= customcss();
	// Determine whether Multisite support is enabled
	if ( !$wp_filesystem->put_contents( $fileout, $css, FS_CHMOD_FILE ) ) {
		$wp_filesystem->put_contents( $fileout, $css, LOCK_EX, FS_CHMOD_FILE );
	}
}