-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.php
44 lines (34 loc) · 861 Bytes
/
utils.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
<?php
class Page_Optimize_Utils {
public static function cache_bust_mtime( $path, $siteurl ) {
static $dependency_path_mapping;
$url = $siteurl . $path;
if ( strpos( $url, '?m=' ) ) {
return $url;
}
$parts = parse_url( $url );
if ( ! isset( $parts['path'] ) || empty( $parts['path'] ) ) {
return $url;
}
if ( empty( $dependency_path_mapping ) ) {
$dependency_path_mapping = new Page_Optimize_Dependency_Path_Mapping();
}
$file = $dependency_path_mapping->dependency_src_to_fs_path( $url );
$mtime = false;
if ( file_exists( $file ) ) {
$mtime = filemtime( $file );
}
if ( ! $mtime ) {
return $url;
}
if ( false === strpos( $url, '?' ) ) {
$q = '';
} else {
list( $url, $q ) = explode( '?', $url, 2 );
if ( strlen( $q ) ) {
$q = '&' . $q;
}
}
return "$url?m={$mtime}{$q}";
}
}