PluginProbe
Page Optimize / 0.6.1
Page Optimize v0.6.1
trunk 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.5.8 0.6.0 0.6.1 0.6.2 0.6.3
page-optimize / utils.php

utils.php in Page Optimize 0.6.1, at utils.php

45 lines 861 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 = '&amp;' . $q;
39 }
40 }
41
42 return "$url?m={$mtime}{$q}";
43 }
44 }
45