flash.moe/public/css.php
2020-08-20 00:02:37 +00:00

36 lines
1.2 KiB
PHP

<?php
$cssPath = !empty($_GET['path']) && is_string($_GET['path']) ? basename($_GET['path']) : '';
$accentColour = !empty($_GET['accent']) && is_string($_GET['accent']) ? substr($_GET['accent'], 0, 7) : '#555';
header('Content-Type: text/css; charset=utf-8');
if(!is_file('css/' . $cssPath)) {
echo '* { transform: rotate(1deg); }';
return;
}
$css = file_get_contents('css/' . $cssPath);
$css = str_replace("\r", '', $css);
$css = str_replace("\n", '', $css);
$css = preg_replace_callback('#@import "([a-z0-9\./\-]+)";#', function ($matches) {
$path = 'css/' . $matches[1];
$src = file_get_contents($path);
$src = str_replace('url("', 'url("' . dirname($path) . '/', $src);
$src = str_replace('url(\'', 'url(\'' . dirname($path) . '/', $src);
$src = str_replace('url(', 'url(' . dirname($path) . '/', $src);
return $src;
}, $css);
$matchCount = preg_match_all('#--([a-z\-]+):(.*?);#', $css, $matches);
$css = str_replace('var(--language-colour)', 'rgba(68, 68, 68, .5)', $css);
$css = str_replace('var(--accent-colour)', $accentColour, $css);
for($i = 0; $i < $matchCount; $i++) {
$css = str_replace('var(--' . $matches[1][$i] . ')', trim($matches[2][$i]), $css);
}
$css = preg_replace('#:root {(.*?)}#', '', $css);
echo $css;