This repository has been archived by the owner on Feb 23, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
BrowserCache_Core.php
109 lines (87 loc) · 2.69 KB
/
BrowserCache_Core.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace W3TC;
/**
* Browsercache core
*/
class BrowserCache_Core {
/**
* Returns replace extensions
*
* @return array
*/
public function get_replace_extensions( $config ) {
$types = array();
$extensions = array();
if ( $config->get_boolean( 'browsercache.cssjs.replace' ) ) {
$types = array_merge( $types, array_keys( $this->_get_cssjs_types() ) );
}
if ( $config->get_boolean( 'browsercache.html.replace' ) ) {
$types = array_merge( $types, array_keys( $this->_get_html_types() ) );
}
if ( $config->get_boolean( 'browsercache.other.replace' ) ) {
$types = array_merge( $types, array_keys( $this->_get_other_types() ) );
}
foreach ( $types as $type ) {
$extensions = array_merge( $extensions, explode( '|', $type ) );
}
return $extensions;
}
/**
* Returns replace extensions
*
* @return array
*/
public function get_replace_querystring_extensions( $config ) {
$extensions = array();
if ( $config->get_boolean( 'browsercache.cssjs.replace' ) )
$this->_fill_extensions( $extensions, $this->_get_cssjs_types(), 'replace' );
if ( $config->get_boolean( 'browsercache.html.replace' ) )
$this->_fill_extensions( $extensions, $this->_get_html_types(), 'replace' );
if ( $config->get_boolean( 'browsercache.other.replace' ) )
$this->_fill_extensions( $extensions, $this->_get_other_types(), 'replace' );
if ( $config->get_boolean( 'browsercache.cssjs.querystring' ) )
$this->_fill_extensions( $extensions, $this->_get_cssjs_types(), 'querystring' );
if ( $config->get_boolean( 'browsercache.html.querystring' ) )
$this->_fill_extensions( $extensions, $this->_get_html_types(), 'querystring' );
if ( $config->get_boolean( 'browsercache.other.querystring' ) )
$this->_fill_extensions( $extensions, $this->_get_other_types(), 'querystring' );
return $extensions;
}
private function _fill_extensions( &$extensions, $types, $operation ) {
foreach ( array_keys( $types ) as $type ) {
$type_extensions = explode( '|', $type );
foreach ( $type_extensions as $ext ) {
if ( !isset( $extensions[$ext] ) )
$extensions[$ext] = array();
$extensions[$ext][$operation] = true;
}
}
}
/**
* Returns CSS/JS mime types
*
* @return array
*/
private function _get_cssjs_types() {
$mime_types = include W3TC_INC_DIR . '/mime/cssjs.php';
return $mime_types;
}
/**
* Returns HTML mime types
*
* @return array
*/
private function _get_html_types() {
$mime_types = include W3TC_INC_DIR . '/mime/html.php';
return $mime_types;
}
/**
* Returns other mime types
*
* @return array
*/
private function _get_other_types() {
$mime_types = include W3TC_INC_DIR . '/mime/other.php';
return $mime_types;
}
}