| 1 |
<?php |
| 2 |
|
| 3 |
class Page_Optimize_Utils { |
| 4 |
public static function cache_bust_mtime( $path, $siteurl ) { |
| 5 |
static $dependency_path_mapping; |
| 6 |
|
| 7 |
$url = $siteurl . $path; |
| 8 |
|
| 9 |
if ( strpos( $url, '?m=' ) ) { |
| 10 |
return $url; |
| 11 |
} |
| 12 |
|
| 13 |
$parts = parse_url( $url ); |
| 14 |
if ( ! isset( $parts['path'] ) || empty( $parts['path'] ) ) { |
| 15 |
return $url; |
| 16 |
} |
| 17 |
|
| 18 |
if ( empty( $dependency_path_mapping ) ) { |
| 19 |
$dependency_path_mapping = new Page_Optimize_Dependency_Path_Mapping(); |
| 20 |
} |
| 21 |
|
| 22 |
$file = $dependency_path_mapping->dependency_src_to_fs_path( $url ); |
| 23 |
|
| 24 |
$mtime = false; |
| 25 |
if ( file_exists( $file ) ) { |
| 26 |
$mtime = filemtime( $file ); |
| 27 |
} |
| 28 |
|
| 29 |
if ( ! $mtime ) { |
| 30 |
return $url; |
| 31 |
} |
| 32 |
|
| 33 |
if ( false === strpos( $url, '?' ) ) { |
| 34 |
$q = ''; |
| 35 |
} else { |
| 36 |
list( $url, $q ) = explode( '?', $url, 2 ); |
| 37 |
if ( strlen( $q ) ) { |
| 38 |
$q = '&' . $q; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
return "$url?m={$mtime}{$q}"; |
| 43 |
} |
| 44 |
} |
| 45 |
|