Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/16543] Update query-string in stylesheet.css to hashes #6017

Merged
merged 7 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions build/update_stylesheet_querystrings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php declare(strict_types=1);
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

if (php_sapi_name() !== 'cli')
{
die("This program must be run from the command line.\n");
}

if (version_compare(PHP_VERSION, '7.1.3', '<'))
{
die('update_stylesheet_querystrings.php requires at least PHP 7.1.3');
}

// Usage: "$ php build/update_stylesheet_querystrings.php"
$targets = [dirname(dirname(__FILE__)) . '/phpBB/styles/prosilver/theme/stylesheet.css'];

array_map('patch_glob', $targets);

function patch_glob($glob): void
{
array_map('patch_file', glob($glob));
}

function patch_file(string $filepath): void
{
$file = file_get_contents($filepath);
$old = $file;
$new = preg_replace_callback(
'(^@import\\s+url\\([\'"](?<basename>\\w++\\.css)\\?\\K(?:hash|v)=[^\'"]++)m',
function ($match) use ($filepath)
{
$path = dirname($filepath) . DIRECTORY_SEPARATOR . $match['basename'];
$hash = sprintf('%08x', crc32(file_get_contents($path)));

return 'hash=' . $hash;
},
$old
);

if ($new !== $old)
{
file_put_contents($filepath, $new);
}
}
24 changes: 12 additions & 12 deletions phpBB/styles/prosilver/theme/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
--------------------------------------------------------------
*/

@import url("normalize.css?v=3.3");
@import url("base.css?v=3.3");
@import url("utilities.css?v=3.3");
@import url("common.css?v=3.3");
@import url("links.css?v=3.3");
@import url("content.css?v=3.3");
@import url("buttons.css?v=3.3");
@import url("cp.css?v=3.3");
@import url("forms.css?v=3.3");
@import url("icons.css?v=3.3");
@import url("colours.css?v=3.3");
@import url("responsive.css?v=3.3");
@import url("normalize.css?hash=48eb3f89");
@import url("base.css?hash=3a7fafb1");
@import url("utilities.css?hash=1034bac8");
@import url("common.css?hash=009a715d");
@import url("links.css?hash=da040ebb");
@import url("content.css?hash=d7d65e66");
@import url("buttons.css?hash=15c14833");
@import url("cp.css?hash=5cc9ac0c");
@import url("forms.css?hash=18ee8211");
@import url("icons.css?hash=ed93c566");
@import url("colours.css?hash=3b03ccfa");
@import url("responsive.css?hash=438ff202");