Merge pull request #1 from seblucas/master

Merge seblucas - Aug 27
This commit is contained in:
sb domo 2013-09-01 02:56:57 -07:00
commit b9e4e356c7
15 changed files with 278 additions and 110 deletions

View file

@ -1,3 +1,8 @@
0.6.2 -
* Added server side rendering for devices like PRS-T2 / Kindle.
* Added a configuration item to tweak how thumbnail are handled.
*
0.6.1 - 20130730
* Properly close the lightbox when clicking in a link. Reported by le_.
* Fix the book by languages list when the language is not found in the resources. Reported by le_.

View file

@ -6,10 +6,15 @@
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
define ("VERSION", "0.6.1");
define ("VERSION", "0.6.2");
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

@ -563,3 +563,97 @@ order by substr (upper (sort), 1, 1)");
}
}
function getJson ($complete = false) {
global $config;
$page = getURLParam ("page", Base::PAGE_INDEX);
$query = getURLParam ("query");
$qid = getURLParam ("id");
$n = getURLParam ("n", "1");
$database = GetUrlParam (DB);
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$out = array ( "title" => $currentPage->title);
$entries = array ();
foreach ($currentPage->entryArray as $entry) {
array_push ($entries, $entry->getContentArray ());
}
if (!is_null ($currentPage->book)) {
$out ["book"] = $currentPage->book->getFullContentArray ();
}
$out ["databaseId"] = GetUrlParam (DB, "");
$out ["databaseName"] = Base::getDbName ();
$out ["page"] = $page;
$out ["entries"] = $entries;
$out ["isPaginated"] = 0;
if ($currentPage->isPaginated ()) {
$prevLink = $currentPage->getPrevLink ();
$nextLink = $currentPage->getNextLink ();
$out ["isPaginated"] = 1;
$out ["prevLink"] = "";
if (!is_null ($prevLink)) {
$out ["prevLink"] = $prevLink->hrefXhtml ();
}
$out ["nextLink"] = "";
if (!is_null ($nextLink)) {
$out ["nextLink"] = $nextLink->hrefXhtml ();
}
$out ["maxPage"] = $currentPage->getMaxPage ();
$out ["currentPage"] = $currentPage->n;
}
if (!is_null (getURLParam ("complete")) || $complete) {
$out ["const"] = array ("version" => VERSION, "i18n" => array (
"coverAlt" => localize("i18n.coversection"),
"authorsTitle" => localize("authors.title"),
"bookwordTitle" => localize("bookword.title"),
"tagsTitle" => localize("tags.title"),
"seriesTitle" => localize("series.title"),
"customizeTitle" => localize ("customize.title"),
"aboutTitle" => localize ("about.title"),
"previousAlt" => localize ("paging.previous.alternate"),
"nextAlt" => localize ("paging.next.alternate"),
"searchAlt" => localize ("search.alternate"),
"sortAlt" => localize ("sort.alternate"),
"homeAlt" => localize ("home.alternate"),
"permalinkAlt" => localize ("permalink.alternate"),
"pubdateTitle" => localize("pubdate.title"),
"languagesTitle" => localize("language.title"),
"contentTitle" => localize("content.summary"),
"sortorderAsc" => localize("search.sortorder.asc"),
"sortorderDesc" => localize("search.sortorder.desc"),
"customizeEmail" => localize("customize.email")),
"url" => array (
"detailUrl" => "index.php?page=13&id={0}&db={1}",
"coverUrl" => "fetch.php?id={0}&db={1}",
"thumbnailUrl" => "fetch.php?height=" . $config['cops_html_thumbnail_height'] . "&id={0}&db={1}"),
"config" => array (
"use_fancyapps" => $config ["cops_use_fancyapps"],
"max_item_per_page" => $config['cops_max_item_per_page'],
"html_tag_filter" => $config['cops_html_tag_filter']));
if ($config['cops_thumbnail_handling'] == "1") {
$out ["const"]["url"]["thumbnailUrl"] = $out ["const"]["url"]["coverUrl"];
} else if (!empty ($config['cops_thumbnail_handling'])) {
$out ["const"]["url"]["thumbnailUrl"] = $config['cops_thumbnail_handling'];
}
}
$out ["containsBook"] = 0;
if ($currentPage->containsBook ()) {
$out ["containsBook"] = 1;
}
$out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database);
if ($page == Base::PAGE_ABOUT) {
$temp = preg_replace ("/\<h1\>About COPS\<\/h1\>/", "<h1>About COPS " . VERSION . "</h1>", file_get_contents('about.html'));
$out ["fullhtml"] = $temp;
}
$out ["homeurl"] = "index.php";
if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database);
return $out;
}

View file

@ -59,7 +59,7 @@
/*
* Height of thumbnail image for OPDS
*/
$config['cops_opds_thumbnail_height'] = "70";
$config['cops_opds_thumbnail_height'] = "140";
/*
* Height of thumbnail image for HTML
@ -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.png")
*/
$config['cops_thumbnail_handling'] = "";
/*
* 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

@ -131,11 +131,19 @@ class Data extends Base {
$height = $config['cops_html_thumbnail_height'];
}
}
$urlParam = addURLParameter($urlParam, "height", $height);
if ($config['cops_thumbnail_handling'] != "1") {
$urlParam = addURLParameter($urlParam, "height", $height);
}
}
$urlParam = addURLParameter($urlParam, "id", $book->id);
if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title);
if ($config['cops_thumbnail_handling'] != "1" &&
!empty ($config['cops_thumbnail_handling']) &&
$rel == Link::OPDS_THUMBNAIL_TYPE) {
return new Link ($config['cops_thumbnail_handling'], $mime, $rel, $title);
} else {
return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title);
}
}
else
{

View file

@ -17,88 +17,7 @@
require_once ("book.php");
header ("Content-Type:application/json;charset=utf-8");
$page = getURLParam ("page", Base::PAGE_INDEX);
$query = getURLParam ("query");
$qid = getURLParam ("id");
$n = getURLParam ("n", "1");
$database = GetUrlParam (DB);
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$out = array ( "title" => $currentPage->title);
$entries = array ();
foreach ($currentPage->entryArray as $entry) {
array_push ($entries, $entry->getContentArray ());
}
if (!is_null ($currentPage->book)) {
$out ["book"] = $currentPage->book->getFullContentArray ();
}
$out ["databaseId"] = GetUrlParam (DB, "");
$out ["databaseName"] = Base::getDbName ();
$out ["page"] = $page;
$out ["entries"] = $entries;
$out ["isPaginated"] = 0;
if ($currentPage->isPaginated ()) {
$prevLink = $currentPage->getPrevLink ();
$nextLink = $currentPage->getNextLink ();
$out ["isPaginated"] = 1;
$out ["prevLink"] = "";
if (!is_null ($prevLink)) {
$out ["prevLink"] = $prevLink->hrefXhtml ();
}
$out ["nextLink"] = "";
if (!is_null ($nextLink)) {
$out ["nextLink"] = $nextLink->hrefXhtml ();
}
$out ["maxPage"] = $currentPage->getMaxPage ();
$out ["currentPage"] = $currentPage->n;
}
if (!is_null (getURLParam ("complete"))) {
$out ["const"] = array ("version" => VERSION, "i18n" => array (
"coverAlt" => localize("i18n.coversection"),
"authorsTitle" => localize("authors.title"),
"bookwordTitle" => localize("bookword.title"),
"tagsTitle" => localize("tags.title"),
"seriesTitle" => localize("series.title"),
"customizeTitle" => localize ("customize.title"),
"aboutTitle" => localize ("about.title"),
"previousAlt" => localize ("paging.previous.alternate"),
"nextAlt" => localize ("paging.next.alternate"),
"searchAlt" => localize ("search.alternate"),
"sortAlt" => localize ("sort.alternate"),
"homeAlt" => localize ("home.alternate"),
"permalinkAlt" => localize ("permalink.alternate"),
"pubdateTitle" => localize("pubdate.title"),
"languagesTitle" => localize("language.title"),
"contentTitle" => localize("content.summary"),
"sortorderAsc" => localize("search.sortorder.asc"),
"sortorderDesc" => localize("search.sortorder.desc"),
"customizeEmail" => localize("customize.email")),
"url" => array (
"detailUrl" => "index.php?page=13&id={0}&db={1}",
"coverUrl" => "fetch.php?id={0}&db={1}",
"thumbnailUrl" => "fetch.php?height=" . $config['cops_html_thumbnail_height'] . "&id={0}&db={1}"),
"config" => array (
"use_fancyapps" => $config ["cops_use_fancyapps"],
"max_item_per_page" => $config['cops_max_item_per_page'],
"html_tag_filter" => $config['cops_html_tag_filter']));
}
$out ["containsBook"] = 0;
if ($currentPage->containsBook ()) {
$out ["containsBook"] = 1;
}
$out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database);
if ($page == Base::PAGE_ABOUT) {
$out ["fullhtml"] = file_get_contents('about.html');
}
$out ["homeurl"] = "index.php";
if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database);
echo json_encode ($out);
echo json_encode (getJson ());

BIN
images/bookcover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

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'])) {
@ -50,11 +51,12 @@
<script type="text/javascript" src="<?php echo getUrlWithVersion("resources/lru/lru.js") ?>"></script>
<script type="text/javascript" src="<?php echo getUrlWithVersion("util.js") ?>"></script>
<link rel="related" href="<?php echo $config['cops_full_url'] ?>feed.php" type="application/atom+xml;profile=opds-catalog" title="<?php echo $config['cops_title_default']; ?>" />
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" />
<link rel="icon" type="image/vnd.microsoft.icon" href="<?php echo $config['cops_icon']; ?>" />
<link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css?family=Open+Sans:400,300italic,800,300,400italic,600,600italic,700,700italic,800italic' />
<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() {
@ -97,7 +99,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>

File diff suppressed because one or more lines are too long

View file

@ -119,7 +119,9 @@ button.mfp-arrow {
-webkit-appearance: none;
display: block;
padding: 0;
z-index: 1046; }
z-index: 1046;
-webkit-box-shadow: none;
box-shadow: none; }
button::-moz-focus-inner {
padding: 0;
@ -297,7 +299,7 @@ img.mfp-img {
text-align: left;
line-height: 18px;
color: #f3f3f3;
word-break: break-word;
word-wrap: break-word;
padding-right: 36px; }
.mfp-figure small {

96
resources/doT-php/doT.php Normal file
View file

@ -0,0 +1,96 @@
<?php
/**
* PHP renderer for doT templating engine
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
class doT {
public $functionBody;
private $functionCode;
private $def;
private function resolveDefs ($block) {
return preg_replace_callback ("/\{\{#([\s\S]+?)\}\}/", function ($m) {
$d = $m[1];
$d = substr ($d, 4);
if (!array_key_exists ($d, $this->def)) {
return "";
}
if (preg_match ("/\{\{#([\s\S]+?)\}\}/", $this->def [$d])) {
return $this->resolveDefs ($this->def [$d], $this->def);
} else {
return $this->def [$d];
}
}, $block);
}
private function handleDotNotation ($string) {
$out = preg_replace ("/(\w+)\.(.*?)([\s,\)])/", "\$$1[\"$2\"]$3", $string);
$out = preg_replace ("/(\w+)\.([\w\.]*?)$/", "\$$1[\"$2\"] ", $out);
$out = preg_replace ("/\./", '"]["', $out);
// Special hideous case : shouldn't be committed
$out = preg_replace ("/^i /", ' $i ', $out);
return $out;
}
public function template ($string, $def) {
$func = preg_replace ("/'|\\\/", "\\$&", $string);
// deps
if (empty ($def)) {
$func = preg_replace ("/\{\{#([\s\S]+?)\}\}/", "", $func);
} else {
$this->def = $def;
$func = $this->resolveDefs ($func);
}
// interpolate
$func = preg_replace_callback ("/\{\{=([\s\S]+?)\}\}/", function ($m) {
return "' . " . $this->handleDotNotation ($m[1]) . " . '";
}, $func);
// Conditional
$func = preg_replace_callback ("/\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/", function ($m) {
$elsecase = $m[1];
$code = $m[2];
if ($elsecase) {
if ($code) {
return "';} else if (" . $this->handleDotNotation ($code) . ") { $" . "out.='";
} else {
return "';} else { $" . "out.='";
}
} else {
if ($code) {
return "'; if (" . $this->handleDotNotation ($code) . ") { $" . "out.='";
} else {
return "';} $" . "out.='";
}
}
}, $func);
// Iterate
$func = preg_replace_callback ("/\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/", function ($m) {
if (count($m) > 1) {
$iterate = $m[1];
$vname = $m[2];
$iname = $m[3];
$iterate = $this->handleDotNotation ($iterate);
return "'; for (\$$iname = 0; \$$iname < count($iterate); \$$iname++) { \$$vname = $iterate [\$$iname]; \$out.='";
} else {
return "';} $" . "out.='";
}
}, $func);
$func = '$out = \'' . $func . '\'; return $out;';
$this->functionBody = $func;
//$this->functionCode = create_function ('$it', $func);
return create_function ('$it', $func);
}
public function execute ($data) {
return $this->functionCode ($data);
}
}

View file

@ -15,24 +15,24 @@
<br />
{{~}}
</h2>
<h1><a title="{{=it.const.i18n.permalinkAlt}}" rel="bookmark" href="{{=strformat (it.const.url.detailUrl, it.book.id, it.databaseId)}}"><i class="icon-link"></i></a>{{=htmlEscape (it.title)}}</h1>
<h1><a title="{{=it.const.i18n.permalinkAlt}}" rel="bookmark" href="{{=str_format (it.const.url.detailUrl, it.book.id, it.databaseId)}}"><i class="icon-link"></i></a>{{=htmlspecialchars (it.title)}}</h1>
<p class="popupless">
<h3>{{=it.const.i18n.authorsTitle}}: </h3>
{{~it.book.authors:author:j}}
{{? j > 0}}, {{?}}<a href="{{=author.url}}">{{=htmlEscape (author.name)}}</a>
{{~it.book.authors:author:i}}
{{? i > 0}}, {{?}}<a href="{{=author.url}}">{{=htmlspecialchars (author.name)}}</a>
{{~}}
</p>
{{? it.book.tagsName != ""}}
<p class="popupless">
<h3>{{=it.const.i18n.tagsTitle}}: </h3>
{{~it.book.tags:tag:k}}
{{? k > 0}}, {{?}}<a href="{{=tag.url}}">{{=htmlEscape (tag.name)}}</a>
{{~it.book.tags:tag:i}}
{{? i > 0}}, {{?}}<a href="{{=tag.url}}">{{=htmlspecialchars (tag.name)}}</a>
{{~}}
</p>
{{?}}
{{? it.book.seriesName != ""}}
<p class="popupless">
<h3><a href="{{=it.book.seriesurl}}">{{=it.const.i18n.seriesTitle}}</a> : </h3>{{=htmlEscape (it.book.seriesCompleteName)}}
<h3><a href="{{=it.book.seriesurl}}">{{=it.const.i18n.seriesTitle}}</a> : </h3>{{=htmlspecialchars (it.book.seriesCompleteName)}}
</p>
{{?}}
{{? it.book.pubDate != ""}}

View file

@ -10,8 +10,6 @@
<div style="float: left; width: 50%">
<form id="searchForm" action="index.php" method="get">
<div style="float: right">
<!--<label for="submitsearch" class="hicon hicon32"><i class="icon-search"></i></label>
<input id="submitsearch" type="submit" value="Go" class="icon- submit" />-->
<button title="{{=it.const.i18n.searchAlt}}" type="submit" class="hicon hicon32 submit">
<i class="icon-search"></i>
</button>

View file

@ -11,7 +11,7 @@
<article>
<div class="frontpage">
{{? entry.navlink != "#"}}<a href="{{=entry.navlink}}">{{?}}
<h2>{{=htmlEscape (entry.title)}}</h2>
<h2>{{=htmlspecialchars (entry.title)}}</h2>
<h4>{{=entry.content}}</h4>
{{? entry.navlink != "#"}}</a>{{?}}
</div>
@ -20,8 +20,8 @@
<article class="books">
<span class="cover">
{{? entry.book.hasCover == 1}}
<a data-fancybox-group="group" class="fancycover" href="{{=strformat (it.const.url.coverUrl, entry.book.id, it.databaseId)}}">
<img src="{{=strformat (it.const.url.thumbnailUrl, entry.book.id, it.databaseId)}}" alt="{{=it.const.i18n.coverAlt}}" />
<a data-fancybox-group="group" class="fancycover" href="{{=str_format (it.const.url.coverUrl, entry.book.id, it.databaseId)}}">
<img src="{{=str_format (it.const.url.thumbnailUrl, entry.book.id, it.databaseId)}}" alt="{{=it.const.i18n.coverAlt}}" />
</a>
{{?}}
</span>
@ -30,15 +30,15 @@
<a href="{{=data.url}}">{{=data.name}}</a><br />
{{~}}
</h2>
<a class="fancydetail" href="{{=strformat (it.const.url.detailUrl, entry.book.id, it.databaseId)}}">
<a class="fancydetail" href="{{=str_format (it.const.url.detailUrl, entry.book.id, it.databaseId)}}">
<div class="fullclickpopup">
<h2><span class="st">{{=htmlEscape (entry.title)}}</span>
<h2><span class="st">{{=htmlspecialchars (entry.title)}}</span>
{{? entry.book.pubDate != ""}}<span class="sp">({{=entry.book.pubDate}})</span>{{?}}
{{? entry.book.rating != ""}}<span class="sr">{{=entry.book.rating}}</span>{{?}}
</h2>
<h4>{{=it.const.i18n.authorsTitle}} : </h4><span class="sa">{{=htmlEscape (entry.book.authorsName)}}</span><br />
{{? entry.book.tagsName != ""}}<h4>{{=it.const.i18n.tagsTitle}} : </h4><span class="se">{{=htmlEscape (entry.book.tagsName)}}</span><br />{{?}}
{{? entry.book.seriesName != ""}}<h4>{{=it.const.i18n.seriesTitle}} : </h4><span class="ss">{{=htmlEscape (entry.book.seriesName)}} ({{=entry.book.seriesIndex}})</span><br />{{?}}
<h4>{{=it.const.i18n.authorsTitle}} : </h4><span class="sa">{{=htmlspecialchars (entry.book.authorsName)}}</span><br />
{{? entry.book.tagsName != ""}}<h4>{{=it.const.i18n.tagsTitle}} : </h4><span class="se">{{=htmlspecialchars (entry.book.tagsName)}}</span><br />{{?}}
{{? entry.book.seriesName != ""}}<h4>{{=it.const.i18n.seriesTitle}} : </h4><span class="ss">{{=htmlspecialchars (entry.book.seriesName)}} ({{=entry.book.seriesIndex}})</span><br />{{?}}
</div></a>
</article>
{{?}}

View file

@ -69,7 +69,7 @@ function sendToMailAddress (component, dataid) {
$.ajax ({'url': url, 'type': 'post', 'data': { 'data': dataid, 'email': email }, 'success': retourMail});
}
function strformat () {
function str_format () {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
@ -92,7 +92,7 @@ function getCurrentOption (option) {
return $.cookie (option);
}
function htmlEscape(str) {
function htmlspecialchars(str) {
return String(str)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
@ -346,7 +346,7 @@ function search_Submitted (event) {
return;
}
event.preventDefault();
var url = strformat ("index.php?page=9&current={0}&query={1}&db={2}", currentData.page, $("input[name=query]").val (), currentData.databaseId);
var url = str_format ("index.php?page=9&current={0}&query={1}&db={2}", currentData.page, $("input[name=query]").val (), currentData.databaseId);
navigateTo (url);
}