2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-11 23:21:49 +03:00
|
|
|
namespace openvk\Web\Presenters;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-06-11 23:21:49 +03:00
|
|
|
use openvk\Web\Themes\Themepacks;
|
|
|
|
|
|
|
|
final class ThemepacksPresenter extends OpenVKPresenter
|
|
|
|
{
|
|
|
|
protected $banTolerant = true;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function renderResource(string $themepack, string $version, string $resClass, string $resource): void
|
2020-06-11 23:21:49 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if (!isset(Themepacks::i()[$themepack])) {
|
2020-06-11 23:21:49 +03:00
|
|
|
$this->notFound();
|
2025-01-31 18:20:13 +03:00
|
|
|
} else {
|
2020-06-11 23:21:49 +03:00
|
|
|
$theme = Themepacks::i()[$themepack];
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($resClass === "resource") {
|
2020-06-14 18:37:06 +03:00
|
|
|
$data = $theme->fetchStaticResource(chandler_escape_url($resource));
|
2025-01-31 18:20:13 +03:00
|
|
|
} elseif ($resClass === "stylesheet") {
|
|
|
|
if ($resource !== "styles.css") {
|
2020-06-11 23:21:49 +03:00
|
|
|
$this->notFound();
|
2025-01-31 18:20:13 +03:00
|
|
|
} else {
|
2020-06-11 23:21:49 +03:00
|
|
|
$data = $theme->fetchStyleSheet();
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
2020-06-11 23:21:49 +03:00
|
|
|
} else {
|
|
|
|
$this->notFound();
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
if (!$data) {
|
2020-06-11 23:21:49 +03:00
|
|
|
$this->notFound();
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
2020-06-14 18:37:06 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|