$string ) // { // echo $string // } define( "QUASI_DEBUG", FALSE ); function Quasi( $files, $suffix = "" ) { $output = array(); foreach ( $files as $filepath ) { Process( $output, $filepath, $suffix ); } return $output; } function Process( &$output, $filepath, $suffix ) { $content = file_get_contents( $filepath ); $lines = explode( "\n", $content ); $inside = false; $file = ""; $linenum = 0; foreach ( $lines as $line ) { $linenum++; if ( 0 < strlen( $line ) && ("~" == $line[0]) ) { $inside = ! $inside; if ( ! $inside ) { $file = ""; } else { $provisional = substr( $line, 1, -1 ); if ( QuasiEndsWith( $provisional, $suffix ) ) { $file = $provisional; if ( ! array_key_exists( $file, $output ) ) $output[$file] = ""; $output[$file] .= "\n" . "/* Generated from $filepath:$linenum using Quasi.php */" . "\n\n"; } } } else if ( $inside && ("" != $file) ) { $output[$file] .= $line . "\n"; } } } // // Helper functions // function QuasiFilesMatching( $suffix ) { $files = array(); $list = scandir( "." ); foreach ( $list as $index => $file ) { if ( QuasiEndsWith( $file, $suffix ) ) { $files[] = $file; } } return $files; } function QuasiEndsWith( $file, $suffix ) { $length = strlen($suffix); return $length === 0 || (substr($file, -$length) === $suffix); } function QuasiCreateVariablesDictionary( $filename ) { $dict = array(); $variables_file_path = dirname( __FILE__ ) . "/" . $filename; if ( file_exists( $variables_file_path ) ) { $contents = file_get_contents( $variables_file_path ); $lines = explode( "\n", $contents ); foreach ( $lines as $line ) { $trimmed = trim( $line ); if ( 0 === strpos( $trimmed, '--' ) ) { if ( defined( "QUASI_DEBUG" ) && QUASI_DEBUG ) error_log( $trimmed ); $bits = explode( ":", $trimmed ); if ( defined( "QUASI_DEBUG" ) && QUASI_DEBUG ) error_log( var_export( $bits, true ) ); if ( 1 < count( $bits ) ) { $name = trim( $bits[0] ); $value = trim( $bits[1] ); $value = trim( str_replace( ';', '', $value ) ); $key = "var($name)"; if ( defined( "QUASI_DEBUG" ) && QUASI_DEBUG ) error_log( "dict[$key] = $value" ); $dict[$key] = $value . " /* $name */"; } } } } return $dict; } function QuasiRetrieveCSS( $filename ) { $contents = FALSE; $css_file_path = dirname( __FILE__ ) . "/" . $filename; if ( file_exists( $css_file_path ) ) { $contents = file_get_contents( $css_file_path ); } return $contents; } function QuasiReplace( $content, $array ) { foreach ( $array as $key => $value ) { $content = str_replace( $key, $value, $content ); } return $content; }