s the filename if the request is WebP compatible * * @since 3.4 * * @param string $filename Cache filename. * @return string */ private function maybe_webp_filename( $filename ) { if ( ! $this->config->get_config( 'cache_webp' ) ) { return $filename; } /** * Force WP Rocket to disable its webp cache. * * @since 3.4 * * @param bool $disable_webp_cache Set to true to disable the webp cache. */ $disable_webp_cache = apply_filters( 'rocket_disable_webp_cache', false ); if ( $disable_webp_cache ) { return $filename; } if ( ! $this->is_browser_webp_compatible() ) { return $filename; } return $filename . '-webp'; } /** * Checks if the browser is WebP compatible * * @since 3.12.6 * * @return bool */ private function is_browser_webp_compatible(): bool { // Only to supporting browsers. $http_accept = $this->config->get_server_input( 'HTTP_ACCEPT', '' ); if ( empty( $http_accept ) && function_exists( 'apache_request_headers' ) ) { $headers = apache_request_headers(); $http_accept = isset( $headers['Accept'] ) ? $headers['Accept'] : ''; } if ( ! empty( $http_accept ) && false !== strpos( $http_accept, 'webp' ) ) { return true; } return $this->is_user_agent_compatible(); } /** * Check the User Agent if the Accept headers is missing the WebP info * * @since 3.12.6 * * @return bool */ private function is_user_agent_compatible(): bool { $user_agent = $this->config->get_server_input( 'HTTP_USER_AGENT' ); if ( empty( $user_agent ) ) { return false; } if ( preg_match( '#Firefox/(?[0-9]{2,})#i', $user_agent, $matches ) ) { if ( 66 >= (int) $matches['version'] ) { return false; } } if ( preg_match( '#(?:iPad|iPhone)(.*)Version/(?[0-9]{2,})#i', $user_agent, $matches ) ) { if ( 14 > (int) $matches['version'] ) { return false; } return true; } if ( preg_match( '#Version/(?[0-9]{2,})(?:.*)Safari#i', $user_agent, $matches ) ) { if ( 16 > (int) $matches['version'] ) { return false; } } return true; } /** * Modifies the filename if dynamic cookies are set * * @param string $filename Cache filename. * @param array $cookies Cookies for the request. * @return string */ private function maybe_dynamic_cookies_filename( $filename, $cookies ) { $cache_dynamic_cookies = $this->config->get_config( 'cache_dynamic_cookies' ); if ( ! $cache_dynamic_cookies ) { return $filename; } foreach ( $cache_dynamic_cookies as $key => $cookie_name ) { if ( is_array( $cookie_name ) ) { if ( isset( $_COOKIE[ $key ] ) ) { foreach ( $cookie_name as $cookie_key ) { if ( '' !== $cookies[ $key ][ $cookie_key ] ) { $cache_key = $cookies[ $key ][ $cookie_key ]; $cache_key = preg_replace( '/[^a-z0-9_\-]/i', '-', $cache_key ); $filename .= '-' . $cache_key; } } } continue; } if ( isset( $cookies[ $cookie_name ] ) && '' !== $cookies[ $cookie_name ] ) { $cache_key = $cookies[ $cookie_name ]; $cache_key = preg_replace( '/[^a-z0-9_\-]/i', '-', $cache_key ); $filename .= '-' . $cache_key; } } return $filename; } /** * Force lowercase on encoded url strings from different alphabets to prevent issues on some hostings. * * @since 3.3 * * @param array $matches Cache path. * @return string Cache path in lowercase. */ protected function reset_lowercase( $matches ) { return strtolower( $matches[0] ); } /** * Sanitizes a string username. * * @param string $user String username. * * @return string */ private function sanitize_user( string $user = '' ): string { return strtolower( rawurlencode( $user ) ); } /** * Check if permalink structure and url match. * * @return bool */ private function maybe_allow_wp_redirect(): bool { $exclusions = implode( '|', $this->wp_redirect_exclusions ); // Return early for excluded urls. if ( preg_match( '#' . $exclusions . '#', $this->tests->get_request_uri_base() ) ) { return false; } $permalink_structure = $this->config->get_config( 'permalink_structure' ); // Last character of permalink. $permalink_last_char = '/' !== substr( $permalink_structure, -1 ) ? '' : '/'; // Request uri without protocol & domain name. $request_uri = $this->tests->get_request_uri_base(); // Last character of request uri. $request_uri_last_char = '/' !== substr( $request_uri, -1 ) ? '' : '/'; // In cases where we have the home with a trailng slash (visible or invisible) // and permalink is without trailing slash. if ( '' === $permalink_last_char ) { // Check for root installation. $request_uri_last_char = '/' === $request_uri ? '' : $request_uri_last_char; /** * Check for subdir installation. * Use config file name to get home request_uri. */ $home = str_replace( $this->config->get_host(), '', basename( $this->config->get_config_file_path()['path'] ) ); $home = str_replace( '.', '/', str_replace( '.php', '', $home ) ); if ( '/' !== $request_uri && rtrim( $request_uri, '/' ) === $home ) { $request_uri_last_char = ''; } } return $permalink_last_char !== $request_uri_last_char; } } خطای پایگاه‌داده

خطا در برقراری ارتباط با پایگاه‌داده