Faster getpreferredstylesheet with custom style support and no dependencies

This commit is contained in:
Juribiyan 2020-06-02 22:24:32 +05:00
parent 751b61bf2c
commit 671d7a4ddd
2 changed files with 20 additions and 13 deletions

View File

@ -29,7 +29,7 @@
title="{$|capitalize}"
{if $__.customstyle eq $}data-custom="true"{/if}/>
{/loop}{/strip}')</script>
<noscript><link rel="stylesheet" href="{$cwebpath}getpreferredstylesheet.php"></noscript>
<noscript><link rel="stylesheet" href="{$cwebpath}getpreferredstylesheet.php?allowed={implode(',', $ku_styles)}&default={$__.ku_defaultstyle}&v={%KU_CSSVER}{if $__.customstyle}&custom={$__.customstyle}&cv={$__.csver}{/if}"></noscript>
<link href="{$cwebpath}css/prettify.css" type="text/css" rel="stylesheet" />
{if $locale eq 'ja'}
{literal}

View File

@ -1,15 +1,22 @@
<?php
$_GLOBALS['skipdb'] = true;
require 'config.php';
$style = $_COOKIE['kustyle'];
if (!$style)
$style = KU_DEFAULTSTYLE;
redirect(KU_WEBPATH.KU_BOARDSFOLDER.'css/'.strtolower($style).'.css?v='.KU_CSSVER);
function redirect($url, $statusCode = 303) {
header('Location: ' . $url, true, $statusCode);
die();
$c = strtolower($_COOKIE['kustyle']);
if ($c && in_array($c, explode(',', $_GET['allowed']))) {
$is_custom = ($c == $_GET['custom']);
$style = $_COOKIE['kustyle'];
}
elseif ($_GET['custom']) {
$style = $_GET['custom'];
$is_custom = true;
}
else {
$style = $_GET['default'];
$is_custom = false;
}
$url = '/css/'.
($is_custom ? 'custom/' : '').
strtolower($style).'.css?v='.
($is_custom ? $_GET['cv'] : $_GET['v']);
header('Location: ' . $url, true, 303);
die();
?>