$uri_or_less ){ //treat as less markup if there are newline characters if( strpos($uri_or_less,"\n") !== false ){ $parser->Parse( $uri_or_less ); continue; } $parser->ParseFile( $file_path, $uri_or_less ); } $compiled = $parser->getCss(); $less_files = $parser->allParsedFiles(); return $compiled; } private static function OutputFile( $compiled_name, $parser_options ){ //custom output file if( !empty($parser_options['output']) ){ //relative to cache directory? if( preg_match('#[\\\\/]#',$parser_options['output']) ){ return $parser_options['output']; } return Less_Cache::$cache_dir.$parser_options['output']; } return Less_Cache::$cache_dir.$compiled_name; } private static function CompiledName( $files ){ //save the file list $temp = array(Less_Version::cache_version); foreach($files as $file){ $temp[] = filemtime($file)."\t".filesize($file)."\t".$file; } return 'lessphp_'.sha1(json_encode($temp)).'.css'; } public static function SetCacheDir( $dir ){ Less_Cache::$cache_dir = $dir; } public static function CheckCacheDir(){ Less_Cache::$cache_dir = str_replace('\\','/',Less_Cache::$cache_dir); Less_Cache::$cache_dir = rtrim(Less_Cache::$cache_dir,'/').'/'; if( !file_exists(Less_Cache::$cache_dir) ){ if( !mkdir(Less_Cache::$cache_dir) ){ throw new Less_Exception_Parser('Less.php cache directory couldn\'t be created: '.Less_Cache::$cache_dir); } }elseif( !is_dir(Less_Cache::$cache_dir) ){ throw new Less_Exception_Parser('Less.php cache directory doesn\'t exist: '.Less_Cache::$cache_dir); }elseif( !is_writable(Less_Cache::$cache_dir) ){ throw new Less_Exception_Parser('Less.php cache directory isn\'t writable: '.Less_Cache::$cache_dir); } } public static function CleanCache(){ static $clean = false; if( $clean ){ return; } $files = scandir(Less_Cache::$cache_dir); if( $files ){ $check_time = time() - 604800; foreach($files as $file){ if( strpos($file,'lessphp_') !== 0 ){ continue; } $full_path = Less_Cache::$cache_dir.'/'.$file; if( filemtime($full_path) > $check_time ){ continue; } unlink($full_path); } } $clean = true; } }