options = $options;
$this->busting_path = $busting_path . get_current_blog_id() . '/';
$this->busting_url = $busting_url . get_current_blog_id() . '/';
}
/**
* Returns a regex-ready string with the excluded filepaths for the Remove Query Strings option
*
* @since 3.3.3
* @author Remy Perona
*
* @return string
*/
protected function get_excluded_files() {
static $excluded_files;
if ( isset( $excluded_files ) ) {
return $excluded_files;
}
/**
* Filters files to exclude from cache busting
*
* @since 2.9.3
* @author Remy Perona
*
* @param array $excluded_files An array of filepath to exclude.
*/
$excluded_files = apply_filters( 'rocket_exclude_cache_busting', [] );
if ( empty( $excluded_files ) ) {
$excluded_files = '';
return $excluded_files;
}
foreach ( $excluded_files as $i => $excluded_file ) {
// Escape character for future use in regex pattern.
$excluded_files[ $i ] = str_replace( '#', '\#', $excluded_file );
}
$excluded_files = implode( '|', $excluded_files );
return $excluded_files;
}
/**
* Remove query strings for CSS files that have one
*
* @since 3.1
* @author Remy Perona
*
* @param string $html HTML content.
* @return string
*/
public function remove_query_strings_css( $html ) {
$html_nocomments = preg_replace( '//Uis', '', $html );
$styles = $this->find( ']+[\s\'"])?href\s*=\s*[\'"]\s*?([^\'"]+\.css(?:\?[^\'"]*)?)\s*?[\'"]([^>]+)?\/?>', $html_nocomments );
if ( ! $styles ) {
return $html;
}
foreach ( $styles as $style ) {
$url = $style[2];
$url = $this->can_replace( $url );
if ( ! $url ) {
continue;
}
$optimized_url = $this->replace_url( $url, 'css' );
if ( ! $optimized_url ) {
continue;
}
$replace_style = str_replace( $style[2], $optimized_url, $style[0] );
$html = str_replace( $style[0], $replace_style, $html );
}
return $html;
}
/**
* Remove query strings for JS files that have one
*
* @since 3.1
* @author Remy Perona
*
* @param string $html HTML content.
* @return string
*/
public function remove_query_strings_js( $html ) {
$html_nocomments = $this->hide_comments( $html );
$scripts = $this->find( '