2017-02-15 16:13:32 -05:00
|
|
|
<?php declare(strict_types=1);
|
2016-02-04 21:57:14 -05:00
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2016-02-04 21:57:14 -05:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
2016-02-04 21:57:14 -05:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* PHP version 7
|
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2017 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 4.0
|
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
2016-02-04 21:57:14 -05:00
|
|
|
*/
|
|
|
|
|
2017-02-15 16:13:32 -05:00
|
|
|
|
2016-02-04 21:57:14 -05:00
|
|
|
namespace Aviat\EasyMin;
|
|
|
|
|
|
|
|
//Creative rewriting of /g/groupname to ?g=groupname
|
|
|
|
$pi = $_SERVER['PATH_INFO'];
|
|
|
|
$pia = explode('/', $pi);
|
|
|
|
|
2017-02-15 14:07:22 -05:00
|
|
|
$piaLen = count($pia);
|
2016-02-04 21:57:14 -05:00
|
|
|
$i = 1;
|
|
|
|
|
2017-02-15 14:07:22 -05:00
|
|
|
while($i < $piaLen)
|
2016-02-04 21:57:14 -05:00
|
|
|
{
|
|
|
|
$j = $i+1;
|
|
|
|
$j = (isset($pia[$j])) ? $j : $i;
|
|
|
|
|
|
|
|
$_GET[$pia[$i]] = $pia[$j];
|
|
|
|
|
|
|
|
$i = $j + 1;
|
|
|
|
};
|
|
|
|
|
2016-02-08 10:57:44 -05:00
|
|
|
class FileNotChangedException extends \Exception {}
|
2016-02-04 21:57:14 -05:00
|
|
|
class BaseMin {
|
2016-02-08 10:57:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get value of the if-modified-since header
|
|
|
|
*
|
|
|
|
* @return int - timestamp to compare for cache control
|
|
|
|
*/
|
2017-02-15 14:07:22 -05:00
|
|
|
protected function getIfModified()
|
2016-02-04 21:57:14 -05:00
|
|
|
{
|
|
|
|
return (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER))
|
|
|
|
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
|
|
|
: time();
|
|
|
|
}
|
|
|
|
|
2016-02-08 10:57:44 -05:00
|
|
|
/**
|
|
|
|
* Get value of etag to compare to hash of output
|
|
|
|
*
|
|
|
|
* @return string - the etag to compare
|
|
|
|
*/
|
2017-02-15 14:07:22 -05:00
|
|
|
protected function getIfNoneMatch()
|
2016-02-04 21:57:14 -05:00
|
|
|
{
|
|
|
|
return (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER))
|
|
|
|
? $_SERVER['HTTP_IF_NONE_MATCH']
|
|
|
|
: '';
|
|
|
|
}
|
2016-02-08 10:57:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not to send debug version
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-02-15 14:07:22 -05:00
|
|
|
protected function isNotDebug()
|
2016-02-08 10:57:44 -05:00
|
|
|
{
|
2017-02-15 14:07:22 -05:00
|
|
|
return ! $this->isDebugCall();
|
2016-02-08 10:57:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not to send debug version
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-02-15 14:07:22 -05:00
|
|
|
protected function isDebugCall()
|
2016-02-08 10:57:44 -05:00
|
|
|
{
|
|
|
|
return array_key_exists('debug', $_GET);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send actual output to browser
|
|
|
|
*
|
|
|
|
* @param string $content - the body of the response
|
2017-02-15 14:07:22 -05:00
|
|
|
* @param string $mimeType - the content type
|
|
|
|
* @param int $lastModified - the last modified date
|
2016-02-08 10:57:44 -05:00
|
|
|
* @return void
|
|
|
|
*/
|
2017-02-15 14:07:22 -05:00
|
|
|
protected function sendFinalOutput($content, $mimeType, $lastModified)
|
2016-02-08 10:57:44 -05:00
|
|
|
{
|
|
|
|
//This GZIPs the CSS for transmission to the user
|
|
|
|
//making file size smaller and transfer rate quicker
|
|
|
|
ob_start("ob_gzhandler");
|
|
|
|
|
2017-02-15 14:07:22 -05:00
|
|
|
$expires = $lastModified + 691200;
|
|
|
|
$lastModifiedDate = gmdate('D, d M Y H:i:s', $lastModified);
|
|
|
|
$expiresDate = gmdate('D, d M Y H:i:s', $expires);
|
2016-02-08 10:57:44 -05:00
|
|
|
|
2017-02-15 14:07:22 -05:00
|
|
|
header("Content-Type: {$mimeType}; charset=utf8");
|
2016-02-08 10:57:44 -05:00
|
|
|
header("Cache-control: public, max-age=691200, must-revalidate");
|
2017-02-15 14:07:22 -05:00
|
|
|
header("Last-Modified: {$lastModifiedDate} GMT");
|
|
|
|
header("Expires: {$expiresDate} GMT");
|
2016-02-08 10:57:44 -05:00
|
|
|
|
|
|
|
echo $content;
|
|
|
|
|
|
|
|
ob_end_flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a 304 Not Modified header
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function send304()
|
|
|
|
{
|
|
|
|
header("status: 304 Not Modified", true, 304);
|
|
|
|
}
|
2016-02-04 21:57:14 -05:00
|
|
|
}
|