| 1 |
<?php |
| 2 |
|
| 3 |
include_once QUICKWEBP_PLUGIN_PATH . 'admin/rewrite-rules/class-rewrite-rules-abstract.php'; |
| 4 |
|
| 5 |
class Nginx extends Rewrite_Rules_Abstract { |
| 6 |
|
| 7 |
/** |
| 8 |
* Get the path to the file. |
| 9 |
*/ |
| 10 |
protected function get_file_path() { |
| 11 |
$file_path = $this->get_site_root() . 'conf/quickwebp.conf'; |
| 12 |
|
| 13 |
return $file_path; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Get unfiltered new contents to write into the file. |
| 18 |
* |
| 19 |
* @since 1.9 |
| 20 |
* @access protected |
| 21 |
* @author Grégory Viguier |
| 22 |
* |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
protected function get_raw_new_contents() { |
| 26 |
$extensions = 'jpg|jpeg|jpe|png'; |
| 27 |
$home_root = wp_parse_url( home_url( '/' ) ); |
| 28 |
$home_root = $home_root['path']; |
| 29 |
|
| 30 |
return trim( ' |
| 31 |
# BEGIN ' . $this->tag_name . ' |
| 32 |
location ~* ^(' . $home_root . '.+)\.(' . $extensions . ')$ { |
| 33 |
add_header Vary Accept; |
| 34 |
|
| 35 |
if ($http_accept ~* "webp"){ |
| 36 |
set $imwebp A; |
| 37 |
} |
| 38 |
if (-f $request_filename.webp) { |
| 39 |
set $imwebp "${imwebp}B"; |
| 40 |
} |
| 41 |
if ($imwebp = AB) { |
| 42 |
rewrite ^(.*) $1.webp; |
| 43 |
} |
| 44 |
} |
| 45 |
# END ' . $this->tag_name . ''); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
} |