config = $config; $this->debug = $config->get_boolean( 'minify.debug' ); $this->buffer = $buffer; $this->minify_helpers = $minify_helpers; // ignored files $this->ignore_js_files = $this->config->get_array( 'minify.reject.files.js' ); $this->ignore_js_files = array_map( array( '\W3TC\Util_Environment', 'normalize_file' ), $this->ignore_js_files ); // define embed type $this->embed_type = array( 'head' => $this->config->get_string( 'minify.js.header.embed_type' ), 'body' => $this->config->get_string( 'minify.js.body.embed_type' ) ); } /** * Does auto-minification * * @return string buffer of minified content */ public function execute() { // find all script tags $buffer_nocomments = preg_replace( '~\s*~s', '', $this->buffer ); $matches = null; // end of
means another group of scripts, cannt be combined if ( !preg_match_all( '~(|)~is', $buffer_nocomments, $matches ) ) { $matches = null; } if ( is_null( $matches ) ) { return $this->buffer; } $script_tags = $matches[1]; $script_tags = apply_filters( 'w3tc_minify_js_script_tags', $script_tags ); // pass scripts $this->files_to_minify = array( 'sync' => array( 'embed_pos' => 0, 'files' => array() ), 'async' => array( 'embed_pos' => 0, 'files' => array() ), 'defer' => array( 'embed_pos' => 0, 'files' => array() ) ); for ( $n = 0; $n < count( $script_tags ); $n++ ) { $this->process_script_tag( $script_tags[$n], $n ); } $this->flush_collected( 'sync', '' ); $this->flush_collected( 'async', '' ); $this->flush_collected( 'defer', '' ); return $this->buffer; } /** * Returns list of minified scripts * * @return array */ public function get_debug_minified_urls() { return $this->debug_minified_urls; } /** * Processes script tag * * @param unknown $script_tag * @return void */ private function process_script_tag( $script_tag, $script_tag_number ) { if ( $this->debug ) { Minify_Core::log( 'processing tag ' . substr( $script_tag, 0, 150 ) ); } $tag_pos = strpos( $this->buffer, $script_tag ); if ( $tag_pos === false ) { // script is external but not found, skip processing it if ( $this->debug ) { Minify_Core::log( 'script not found:' . $script_tag ); } return; } $match = null; if ( !preg_match( '~