openvk/Web/Presenters/ThemepacksPresenter.php

43 lines
1.2 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
2020-06-11 23:21:49 +03:00
namespace openvk\Web\Presenters;
2020-06-11 23:21:49 +03:00
use openvk\Web\Themes\Themepacks;
final class ThemepacksPresenter extends OpenVKPresenter
{
protected $banTolerant = true;
public function renderResource(string $themepack, string $version, string $resClass, string $resource): void
2020-06-11 23:21:49 +03:00
{
if (!isset(Themepacks::i()[$themepack])) {
2020-06-11 23:21:49 +03:00
$this->notFound();
} else {
2020-06-11 23:21:49 +03:00
$theme = Themepacks::i()[$themepack];
}
if ($resClass === "resource") {
$data = $theme->fetchStaticResource(chandler_escape_url($resource));
} elseif ($resClass === "stylesheet") {
if ($resource !== "styles.css") {
2020-06-11 23:21:49 +03:00
$this->notFound();
} else {
2020-06-11 23:21:49 +03:00
$data = $theme->fetchStyleSheet();
}
2020-06-11 23:21:49 +03:00
} else {
$this->notFound();
}
if (!$data) {
2020-06-11 23:21:49 +03:00
$this->notFound();
}
header("Content-Type: " . system_extension_mime_type($resource) ?? "text/plain; charset=unknown-8bit");
2020-06-11 23:21:49 +03:00
header("Content-Size: " . strlen($data));
header("Cache-Control: public, no-transform, max-age=31536000");
exit($data);
}
}