Some temporary fixes for tempramental minifiers
This commit is contained in:
parent
b1549440e0
commit
fc02a68691
@ -35,5 +35,5 @@
|
||||
</table>
|
||||
</form>
|
||||
</main>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=anime_collection') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/anime_collection') ?>"></script>
|
||||
<?php endif ?>
|
@ -65,5 +65,5 @@
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=edit') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
|
||||
<?php endif ?>
|
||||
|
@ -85,5 +85,5 @@
|
||||
</table>
|
||||
</form>
|
||||
</main>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=edit') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
|
||||
<?php endif ?>
|
@ -74,4 +74,4 @@
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<?php $group = ($auth->is_authenticated()) ? 'table_edit' : 'table' ?>
|
||||
<script src="<?= $urlGenerator->asset_url("js.php?g={$group}") ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url("js.php/g/{$group}") ?>"></script>
|
||||
|
@ -40,5 +40,5 @@
|
||||
<img src="{{:cover_image}}" alt="{{:title}}" />
|
||||
</article>
|
||||
</template>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=anime_collection') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/anime_collection') ?>"></script>
|
||||
<?php endif ?>
|
@ -52,5 +52,5 @@
|
||||
<img src="{{:cover_image}}" alt="{{:title}}" />
|
||||
</article>
|
||||
</template>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=anime_collection') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/anime_collection') ?>"></script>
|
||||
<?php endif ?>
|
@ -49,4 +49,4 @@
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=table') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/table') ?>"></script>
|
@ -1,3 +1,3 @@
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=event') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/event') ?>"></script>
|
||||
</body>
|
||||
</html>
|
@ -6,8 +6,8 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="cache-control" content="no-store" />
|
||||
<meta http-equiv="Content-Security-Policy" content="script-src 'self'" />
|
||||
<link rel="stylesheet" href="<?= $urlGenerator->asset_url('css.php?g=base') ?>" />
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=base') ?>"></script>
|
||||
<link rel="stylesheet" href="<?= $urlGenerator->asset_url('css.php/g/base') ?>" />
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/base') ?>"></script>
|
||||
</head>
|
||||
<body class="<?= $escape->attr($url_type) ?> list">
|
||||
<header>
|
||||
|
@ -35,5 +35,5 @@
|
||||
</table>
|
||||
</form>
|
||||
</main>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=manga_collection') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/manga_collection') ?>"></script>
|
||||
<?php endif ?>
|
@ -56,5 +56,5 @@
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=edit') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
|
||||
<?php endif ?>
|
||||
|
@ -85,5 +85,4 @@
|
||||
</table>
|
||||
</form>
|
||||
</main>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=edit') ?>"></script>
|
||||
<?php endif ?>
|
@ -45,4 +45,4 @@
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php?g=table') ?>"></script>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/table') ?>"></script>
|
@ -13,16 +13,19 @@
|
||||
|
||||
namespace Aviat\EasyMin;
|
||||
|
||||
require_once('./min.php');
|
||||
|
||||
/**
|
||||
* Simple CSS Minifier
|
||||
*/
|
||||
class CSSMin {
|
||||
class CSSMin extends BaseMin {
|
||||
|
||||
protected $css_root;
|
||||
protected $path_from;
|
||||
protected $path_to;
|
||||
protected $group;
|
||||
protected $last_modified;
|
||||
protected $requested_time;
|
||||
|
||||
public function __construct(array $config, array $groups)
|
||||
{
|
||||
@ -33,6 +36,11 @@ class CSSMin {
|
||||
$this->group = $groups[$group];
|
||||
$this->last_modified = $this->get_last_modified();
|
||||
|
||||
$this->requested_time = $this->get_if_modified();
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->send();
|
||||
}
|
||||
|
||||
@ -43,16 +51,11 @@ class CSSMin {
|
||||
*/
|
||||
protected function send()
|
||||
{
|
||||
$requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
||||
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
: 0;
|
||||
|
||||
// Send 304 when not modified for faster response
|
||||
if($this->last_modified === $requested_time)
|
||||
/*if($this->last_modified >= $this->requested_time)
|
||||
{
|
||||
header("HTTP/1.1 304 Not Modified");
|
||||
exit();
|
||||
}
|
||||
header('304 Not Modified');
|
||||
die();
|
||||
}*/
|
||||
|
||||
$css = ( ! array_key_exists('debug', $_GET))
|
||||
? $this->compress($this->get_css())
|
||||
@ -69,7 +72,6 @@ class CSSMin {
|
||||
*/
|
||||
public function compress($buffer)
|
||||
{
|
||||
|
||||
//Remove CSS comments
|
||||
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
|
||||
|
||||
@ -119,9 +121,8 @@ class CSSMin {
|
||||
|
||||
//Get the latest modified date
|
||||
rsort($modified);
|
||||
$last_modified = $modified[0];
|
||||
|
||||
return $last_modified;
|
||||
return array_shift($modified);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,18 +134,15 @@ class CSSMin {
|
||||
{
|
||||
$css = '';
|
||||
|
||||
if(isset($this->group))
|
||||
{
|
||||
foreach($this->group as $file)
|
||||
{
|
||||
$new_file = realpath("{$this->css_root}{$file}");
|
||||
$css .= file_get_contents($new_file);
|
||||
}
|
||||
}
|
||||
|
||||
// Correct paths that have changed due to concatenation
|
||||
// based on rules in the config file
|
||||
$css = str_replace($this->path_from, $this->path_to, $css);
|
||||
// $css = str_replace($this->path_from, $this->path_to, $css);
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
@ -18,11 +18,12 @@ use GuzzleHttp\Psr7\Request;
|
||||
|
||||
// Include guzzle
|
||||
require_once('../vendor/autoload.php');
|
||||
require_once('./min.php');
|
||||
|
||||
/**
|
||||
* Simple Javascript minfier, using google closure compiler
|
||||
*/
|
||||
class JSMin {
|
||||
class JSMin extends BaseMin {
|
||||
|
||||
protected $js_root;
|
||||
protected $js_group;
|
||||
@ -43,14 +44,15 @@ class JSMin {
|
||||
$this->cache_file = "{$this->js_root}cache/{$group}";
|
||||
$this->last_modified = $this->get_last_modified();
|
||||
|
||||
$this->requested_time = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
||||
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
: time();
|
||||
$this->requested_time = $this->get_if_modified();
|
||||
|
||||
$this->cache_modified = (is_file($this->cache_file))
|
||||
? filemtime($this->cache_file)
|
||||
: 0;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
// Output some JS!
|
||||
$this->send();
|
||||
}
|
||||
@ -59,11 +61,11 @@ class JSMin {
|
||||
{
|
||||
// If the browser's cached version is up to date,
|
||||
// don't resend the file
|
||||
if($this->last_modified === $this->requested_time)
|
||||
/*if($this->last_modified === $this->requested_time)
|
||||
{
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
|
||||
exit();
|
||||
}
|
||||
}*/
|
||||
|
||||
//Determine what to do: rebuild cache, send files as is, or send cache.
|
||||
// If debug is set, just concatenate
|
||||
@ -86,7 +88,7 @@ class JSMin {
|
||||
// Otherwise, send the cached file
|
||||
else
|
||||
{
|
||||
return $this->output(file_get_contents($cache_file));
|
||||
return $this->output(file_get_contents($this->cache_file));
|
||||
}
|
||||
}
|
||||
|
||||
|
47
public/min.php
Normal file
47
public/min.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Hummingbird Anime Client
|
||||
*
|
||||
* An API client for Hummingbird to manage anime and manga watch lists
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2015 - 2016
|
||||
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace Aviat\EasyMin;
|
||||
|
||||
//Creative rewriting of /g/groupname to ?g=groupname
|
||||
$pi = $_SERVER['PATH_INFO'];
|
||||
$pia = explode('/', $pi);
|
||||
|
||||
$pia_len = count($pia);
|
||||
$i = 1;
|
||||
|
||||
while($i < $pia_len)
|
||||
{
|
||||
$j = $i+1;
|
||||
$j = (isset($pia[$j])) ? $j : $i;
|
||||
|
||||
$_GET[$pia[$i]] = $pia[$j];
|
||||
|
||||
$i = $j + 1;
|
||||
};
|
||||
|
||||
class BaseMin {
|
||||
public function get_if_modified()
|
||||
{
|
||||
return (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER))
|
||||
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
: time();
|
||||
}
|
||||
|
||||
public function get_if_none_match()
|
||||
{
|
||||
return (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER))
|
||||
? $_SERVER['HTTP_IF_NONE_MATCH']
|
||||
: '';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user