PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 4.1.1
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v4.1.1
4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
quickwebp / admin / rewrite-rules / class-nginx.php

class-nginx.php in QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress 4.1.1, at admin/rewrite-rules/class-nginx.php

62 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 include_once QUICKWEBP_PLUGIN_PATH . 'admin/rewrite-rules/class-rewrite-rules-abstract.php';
5
6 class Quickwebp_Nginx extends Quickwebp_Rewrite_Rules_Abstract {
7
8 /**
9 * Get the path to the file.
10 */
11 protected function get_file_path() {
12 $file_path = $this->get_site_root() . 'conf/quickwebp.conf';
13
14 return $file_path;
15 }
16
17 /**
18 * Get unfiltered new contents to write into the file.
19 *
20 * @since 1.9
21 * @access protected
22 * @author Grégory Viguier
23 *
24 * @return string
25 */
26 protected function get_raw_new_contents() {
27 $home_root = wp_parse_url( home_url( '/' ) );
28 $home_root = $home_root['path'];
29
30 $content = "# BEGIN " . $this->tag_name . "\n";
31 $content .= "location ~* ^($home_root.+)\\.(jpg|jpeg|jpe|png)$ {";
32 $content .= "\n\tadd_header Vary Accept;";
33
34 // Check for AVIF support and file existence
35 $content .= "\n\n\tif (\$http_accept ~* \"avif\") {";
36 $content .= "\n\t\tset \$imavif A;";
37 $content .= "\n\t}";
38 $content .= "\n\tif (-f \$request_filename.avif) {";
39 $content .= "\n\t\tset \$imavif \"\${imavif}B\";";
40 $content .= "\n\t}";
41 $content .= "\n\tif (\$imavif = AB) {";
42 $content .= "\n\t\trewrite ^(.*) \$1.avif break;";
43 $content .= "\n\t}";
44
45 // Check for WebP support and file existence
46 $content .= "\n\n\tif (\$http_accept ~* \"webp\") {";
47 $content .= "\n\t\tset \$imwebp A;";
48 $content .= "\n\t}";
49 $content .= "\n\tif (-f \$request_filename.webp) {";
50 $content .= "\n\t\tset \$imwebp \"\${imwebp}B\";";
51 $content .= "\n\t}";
52 $content .= "\n\tif (\$imwebp = AB) {";
53 $content .= "\n\t\trewrite ^(.*) \$1.webp break;";
54 $content .= "\n\t}";
55
56 $content .= "\n}";
57 $content .= "\n# END " . $this->tag_name;
58
59 return trim( $content );
60 }
61 }
62