1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
require __DIR__.'/../init.php';
global $config;
$name = $_REQUEST['name'] ?? '';
$theme = $_REQUEST['theme'] ?? '';
if ($theme != 'light' && $theme != 'dark') {
http_response_code(403);
exit;
}
if (!$config['is_dev'] || !$name || !file_exists($path = ROOT.'/htdocs/scss/entries/'.$name.'/'.$theme.'.scss')) {
// logError(__FILE__.': access denied');
http_response_code(403);
exit;
}
// logInfo(__FILE__.': continuing, path='.$path);
$cmd = 'sassc -t expanded '.escapeshellarg($path);
$descriptorspec = [
0 => ['pipe', 'r'], // stdin
1 => ['pipe', 'w'], // stdout
2 => ['pipe', 'w'], // stderr
];
$process = proc_open($cmd, $descriptorspec, $pipes, ROOT);
if (!is_resource($process)) {
http_response_code(500);
logError('could not open sassc process');
exit;
}
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$code = proc_close($process);
if ($code) {
http_response_code(500);
logError('sassc('.$path.') returned '.$code);
logError($stderr);
exit;
}
header('Content-Type: text/css');
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
echo $stdout;
|