$v ) { if ( preg_match( '/^(wordpress_logged_in_|wp-postpass_|comment_author_|woocommerce_items_in_cart|wp_woocommerce_session_)/', (string) $name ) ) { return; } } $uri = isset( $_SERVER['REQUEST_URI'] ) ? (string) $_SERVER['REQUEST_URI'] : '/'; $query = (string) parse_url( $uri, PHP_URL_QUERY ); if ( '' !== $query ) { parse_str( $query, $params ); foreach ( array_keys( $params ) as $k ) { if ( ! preg_match( '/^(utm_|fbclid|gclid|msclkid|mc_|_ga|yclid|ttclid|twclid|dclid|srsltid)/', (string) $k ) ) { return; } } } $path = (string) parse_url( $uri, PHP_URL_PATH ); if ( ! empty( $cfg['exclude'] ) ) { foreach ( $cfg['exclude'] as $re ) { if ( @preg_match( $re, $path ) ) { return; } } } $ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? (string) $_SERVER['HTTP_USER_AGENT'] : ''; $mobile = ! empty( $cfg['mobile'] ) && preg_match( '/Mobile|Android|iPhone|iPod|Opera Mini|IEMobile|BlackBerry/i', $ua ); $https = ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== $_SERVER['HTTPS'] ) || ( isset( $_SERVER['SERVER_PORT'] ) && '443' === (string) $_SERVER['SERVER_PORT'] ) || ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ); $host = isset( $_SERVER['HTTP_HOST'] ) ? strtolower( preg_replace( '/:\d+$/', '', (string) $_SERVER['HTTP_HOST'] ) ) : ''; $host = preg_replace( '/[^a-z0-9.\-_]/i', '', $host ); if ( '' === $host || ( ! empty( $cfg['host'] ) && $host !== $cfg['host'] ) ) { return; } $cpath = preg_replace( '#[^a-zA-Z0-9/\-_.%~]#', '', $path ); $cpath = str_replace( '..', '', $cpath ); $cpath = '/' . trim( $cpath, '/' ); if ( '/' !== $cpath ) { $cpath .= '/'; } $accept = isset( $_SERVER['HTTP_ACCEPT'] ) ? (string) $_SERVER['HTTP_ACCEPT'] : ''; $img = ''; if ( ! empty( $cfg['webp'] ) ) { if ( ! empty( $cfg['avif'] ) && false !== strpos( $accept, 'image/avif' ) ) { $img = '-avif'; } elseif ( false !== strpos( $accept, 'image/webp' ) ) { $img = '-webp'; } } $file = $base . 'pages/' . $host . $cpath . 'index' . ( $mobile ? '-mobile' : '' ) . ( $https ? '-https' : '' ) . $img . '.html'; if ( ! is_file( $file ) ) { return; } $mtime = (int) filemtime( $file ); if ( time() - $mtime > (int) $cfg['lifespan'] ) { return; } $lm = gmdate( 'D, d M Y H:i:s', $mtime ) . ' GMT'; header( 'X-Velox-Cache: HIT' ); header( 'Last-Modified: ' . $lm ); header( 'Cache-Control: max-age=0, must-revalidate' ); if ( ! empty( $cfg['mobile'] ) ) { header( 'Vary: User-Agent', false ); } if ( ! empty( $cfg['webp'] ) ) { header( 'Vary: Accept', false ); } if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) && strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) >= $mtime ) { http_response_code( 304 ); exit; } header( 'Content-Type: text/html; charset=UTF-8' ); // Send a pre-compressed copy when the browser accepts it (Brotli first, then gzip). $ae = isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ? (string) $_SERVER['HTTP_ACCEPT_ENCODING'] : ''; // With "dynamic Brotli" on and no ready .br copy, leave the plain file to the web server's Brotli filter. $skip_gz = ! empty( $cfg['brotli_dynamic'] ) && false !== stripos( $ae, 'br' ) && ! is_file( $file . '.br' ); if ( ! $skip_gz && ! ini_get( 'zlib.output_compression' ) ) { foreach ( array( 'br', 'gzip' ) as $enc ) { $ext = 'br' === $enc ? '.br' : '.gz'; if ( false !== stripos( $ae, $enc ) && is_file( $file . $ext ) ) { header( 'Content-Encoding: ' . $enc ); header( 'Vary: Accept-Encoding', false ); header( 'Content-Length: ' . filesize( $file . $ext ) ); readfile( $file . $ext ); exit; } } } header( 'Content-Length: ' . filesize( $file ) ); readfile( $file ); exit; } )();