Commenting to explain what I'm doing

This commit is contained in:
David Walsh 2016-02-23 14:58:53 -06:00
Родитель ff29789fb1
Коммит b17a61aef4
1 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -32,25 +32,32 @@ class SW_Cache_Main {
public function write_sw() {
$files = get_option('wp_sw_cache_files');
$file_keys = array();
if(!$files) {
$files = array();
}
// Will contain items like 'style.css' => {filemtime() of style.css}
$file_keys = array();
// Ensure that every file directed to be cached still exists
foreach($files as $index=>$file) {
$tfile = get_template_directory().'/'.$file;
if(file_exists($tfile)) {
// Use file's last change time in name hash so the SW is updated if any file is updated
$file_keys[get_template_directory_uri().'/'.$file] = filemtime($tfile);
}
}
$file_keys = array_keys($file_keys);
// Serialize the entire array so we match file with time
// This will catch file updates done outside of admin (like updating via FTP)
$name = md5(serialize($file_keys));
self::update_version($name);
// Template content into the JS file
$contents = file_get_contents(dirname(__FILE__).'/lib/service-worker.js');
$contents = str_replace('$name', $name, $contents);
$contents = str_replace('$files', json_encode($file_keys), $contents);
$contents = str_replace('$files', json_encode(array_keys($file_keys)), $contents);
$contents = str_replace('$debug', get_option('wp_sw_cache_debug') ? 'true' : 'false', $contents);
echo $contents;
}