Add (again) server side rendering ! the list of user agent need to be completed but it should work.

This commit is contained in:
Sébastien Lucas 2013-08-22 15:20:30 +02:00
parent 9ff4bd2476
commit 9c8ec7fb8a
3 changed files with 46 additions and 0 deletions

View File

@ -10,6 +10,11 @@ define ("VERSION", "0.6.1");
define ("DB", "db");
date_default_timezone_set($config['default_timezone']);
function useServerSideRendering () {
global $config;
return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']);
}
function getURLParam ($name, $default = NULL) {
if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") {
return $_GET[$name];

View File

@ -196,4 +196,20 @@
* 0 : No
*/
$config['cops_html_tag_filter'] = "0";
/*
* Thumbnails are generated on-the-fly so it can be problematic on servers with slow CPU (Raspberry Pi, Dockstar, Piratebox, ...).
* This configuration item allow to customize how thumbnail will be generated
* "" : Generate thumbnail (CPU hungry)
* "1" : always send the full size image (Network hungry)
* any url : Send a constant image as the thumbnail (you can try "images/bookcover.svg")
*/
$config['cops_thumbnail_handling'] = "images/bookcover.svg";
/*
* Contains a list of user agent for browsers not compatible with client side rendering
* For now : Kindle, Sony PRS-T1
* This item is used as regular expression so "." will force server side rendering for all devices
*/
$config['cops_server_side_render'] = ".";//"Kindle|EBRD1101";

View File

@ -17,6 +17,7 @@
require_once ("language.php");
require_once ("customcolumn.php");
require_once ("book.php");
require_once ("resources/doT-php/doT.php");
// If we detect that an OPDS reader try to connect try to redirect to feed.php
if (preg_match("/(MantanoReader|FBReader|Stanza|Aldiko|Moon+ Reader)/", $_SERVER['HTTP_USER_AGENT'])) {
@ -48,6 +49,7 @@
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/normalize/normalize.css") ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("styles/font-awesome.css") ?>" media="screen" />
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss ()) ?>" media="screen" />
<?php if (!useServerSideRendering ()) { ?>
<script type="text/javascript">
$(document).ready(function() {
@ -90,7 +92,30 @@
</script>
<?php } ?>
</head>
<body>
<?php
if (useServerSideRendering ()) {
// Get the templates
$header = file_get_contents('templates/default/header.html');
$footer = file_get_contents('templates/default/footer.html');
$main = file_get_contents('templates/default/main.html');
$bookdetail = file_get_contents('templates/default/bookdetail.html');
$page = file_get_contents('templates/default/page.html');
// Get the data
$data = getJson (true);
// Generate the function for the template
$template = new doT ();
$dot = $template->template ($page, array ("bookdetail" => $bookdetail,
"header" => $header,
"footer" => $footer,
"main" => $main));
// Execute the template
echo $dot ($data);
}
?>
</body>
</html>