Skip to content

Commit

Permalink
Update midwinter to use hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
netniV committed May 15, 2022
1 parent dbfab60 commit 19714d6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
28 changes: 15 additions & 13 deletions include/themes/midwinter/main.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
/* prerequisites */
@import url('./css/pre/fonts.css');
@import url('./css/pre/colors.css');
@import url('./css/pre/keyframes.css');
@import url('./css/pre/fonts.css?a23648e6dc13c913f9ae2e993735631b');
@import url('./css/pre/colors.css?6a3d4dc1567013fda818848070dd9939');
@import url('./css/pre/keyframes.css?6d1d6a79b3c3bf783d25ff4a0cb83d59');

/* Cacti core */
@import url('./css/media/core.css') all;
@import url('./css/media/print.css') print;
@import url('./css/media/core.css?9aadb69fc9433c9f0651e07b511dff61') all;
@import url('./css/media/print.css?f8c80271650344f45629199331592924') print;

/* standard mode */
@import url('./css/media/standard.css') screen;
@import url('./css/media/standard-portrait.css') screen and (max-width: 600px);
@import url('./css/media/standard-landscape.css') screen and (min-width: 601px);
@import url('./css/media/standard.css?2458dd4d97dd94d3891b48e239ff6dd8') screen;
@import url('./css/media/standard-portrait.css?1fc97918874907735b4ed825cbfd120c') screen and (max-width: 600px);
@import url('./css/media/standard-landscape.css?857b8dce04e7cb60a0c06942c39fb51d') screen and (min-width: 601px);

/* compact mode */
@import url('./css/media/compact.css') screen;
@import url('./css/media/compact-portrait.css') screen and (max-width: 600px);
@import url('./css/media/compact-landscape.css') screen and (min-width: 601px);
@import url('./css/media/compact.css?0bda9f47e7be64d1c2709f24cd70ba00') screen;
@import url('./css/media/compact-portrait.css?9e14ab5e5fa525193e5cc164dc5a2e0c') screen and (max-width: 600px);
@import url('./css/media/compact-landscape.css?3c35b3dd09c0671a596130206e72113a') screen and (min-width: 601px);

/* extensions & addons */
@import "billboard.midwinter.css";
@import "jquery-ui.midwinter.css";
@import url('billboard.midwinter.css?e442c55720734e56c33de67e26a596de');
@import url('jquery-ui.midwinter.css?debef6327c75b81352f0efd40c83f809');

/* End of file */
52 changes: 52 additions & 0 deletions include/themes/midwinter/update_hash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

function update_hash($file) {
}

function file_search($folder, $pattern_array) {
$return = array();
$iti = new RecursiveDirectoryIterator($folder);
foreach(new RecursiveIteratorIterator($iti) as $file){
$fileParts = explode('.', $file);
if (in_array(strtolower(array_pop($fileParts)), $pattern_array)){
$return[] = $file;
}
}
return $return;
}

function file_hash($match) {
global $cssFile;
$md5File = dirname($cssFile) . '/' . $match[2];
$md5Real = realpath($md5File);
$md5Hash = md5_file($md5File);
$result = $match[1] . $match[2] . '?' . $md5Hash . $match[4];

return $result;
}

function file_update($cssFile) {
$fileContents = file($cssFile);
$fileUpdated = preg_replace_callback_array(
[
'/(@import url\(\')([^?]*)(\?.*)*(\'\))/' => 'file_hash',
'/(@import url\(")([^?]*)(\?.*)*("\))/' => 'file_hash',
], $fileContents
);

if ($fileContents != $fileUpdated) {
echo "file_update(" . $cssFile . ")\n";
file_put_contents($cssFile, $fileUpdated);
}
}

global $cssFile;
$cssFiles = file_search(__DIR__ . '/css', ['css']);
$cssFiles[] = __DIR__ . '/main.css';
$cssFiles[] = __DIR__ . '/billboard.midwinter.css';

foreach ($cssFiles as $cssFile) {
file_update($cssFile);
}

echo PHP_EOL;

0 comments on commit 19714d6

Please sign in to comment.