forked from BoldGrid/w3-total-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cdn_Environment_Nginx.php
74 lines (54 loc) · 1.5 KB
/
Cdn_Environment_Nginx.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace W3TC;
/**
* CDN rules generation for Nginx
*/
class Cdn_Environment_Nginx {
private $c;
public function __construct( $config ) {
$this->c = $config;
}
public function generate( $cdnftp ) {
$rules = '';
$rule = $this->generate_canonical( $cdnftp );
if ( !empty( $rule ) ) {
$rules = $rule . "\n";
}
if ( $this->c->get_boolean( 'cdn.cors_header') ) {
$rules_a = Dispatcher::nginx_rules_for_browsercache_section(
$this->c, 'other', true );
$rules_a[] = 'add_header Access-Control-Allow-Origin "*";';
$rules .=
"location ~ \\.(ttf|ttc|otf|eot|woff|woff2|font.css)\$ {\n" .
' ' . implode( "\n ", $rules_a ) . "\n" .
"}\n";
}
if ( strlen( $rules ) > 0 ) {
$rules =
W3TC_MARKER_BEGIN_CDN . "\n" .
$rules .
W3TC_MARKER_END_CDN . "\n";
}
return $rules;
}
public function generate_canonical( $cdnftp = false ) {
if ( !$this->c->get_boolean( 'cdn.canonical_header' ) ) {
return null;
}
$home = ( $cdnftp ? Util_Environment::home_url_host() : '$host' );
return 'add_header Link "<$scheme://' . $home .
'$request_uri>; rel=\"canonical\"";';
}
public function w3tc_browsercache_rules_section_extensions(
$extensions, $section ) {
// CDN adds own rules for those extensions
if ( $this->c->get_boolean( 'cdn.cors_header') ) {
unset( $extensions['ttf|ttc'] );
unset( $extensions['otf'] );
unset( $extensions['eot'] );
unset( $extensions['woff'] );
unset( $extensions['woff2'] );
}
return $extensions;
}
}