Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Ein paar kleine Anpassungen #1

Merged
merged 16 commits into from
May 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Options -MultiViews

RewriteEngine On
RewriteBase /bbs/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</IfModule>
6 changes: 0 additions & 6 deletions config.php

This file was deleted.

10 changes: 10 additions & 0 deletions config.php.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

# Root dir of Calibre library, should contain the metadata.db
$calibre_dir = '/volume1/library';
# Name of the Calibre library file
$metadata_db = 'metadata.db';
# Application Name
$appname = 'Calibre';

?>
97 changes: 84 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
// Licensed under MIT License, see README.MD/License

require 'lib/rb.php';
require_once 'config.php';
require_once 'lib/Slim/Slim.php';
require_once 'lib/Slim/Views/TwigView.php';
TwigView::$twigDirectory = dirname(__FILE__) . '/lib/Twig';
TwigView::$twigExtensions = array(
'Twig_Extensions_Slim'
);

# Root dir of Calibre library, should contain the metadata.db
$calibre_dir = '/volume1/books';
# Name of the Calibre library file
$metadata_db = 'metadata.db';

$allowedLangs = array('de','en');
$fallbackLang = 'en';

Expand All @@ -23,6 +19,8 @@
'book_details' => "Buchdetails",
'authors' => "Autoren",
'author_details' => "Details Autor",
'tags' => "Schlagwörter",
'tag_details' => "Details Schlagwort",
'booksby' => "Bücher von",
'dl30' => "Die letzten 30",
'download' => "Herunterladen",
Expand All @@ -37,6 +35,8 @@
'book_details' => "Book Details",
'authors' => "Authors",
'author_details' => "Author Details",
'tags' => "Tags",
'tag_details' => "Tag Details",
'booksby' => "Books by",
'dl30' => "Most recent 30",
'download' => "Download",
Expand All @@ -48,8 +48,7 @@
'mdb_error' => 'Calibre database not found or not readable: ');

$globalSettings = array();
require_once 'config.php';
$globalSettings['appname'] = 'BicBucStriim';
$globalSettings['appname'] = $appname;
$globalSettings['version'] = '0.6.1';
$globalSettings['sep'] = ' :: ';
$globalSettings['lang'] = getUserLang($allowedLangs, $fallbackLang);
Expand All @@ -72,6 +71,8 @@
$app->get('/titles/:id/file/:file', 'book');
$app->get('/authors/', 'authors');
$app->get('/authors/:id/', 'author');
$app->get('/tags/', 'tags');
$app->get('/tags/:id/', 'tag');

$app->getLog()->debug("sss");
# Setup the connection to the Calibre metadata db
Expand Down Expand Up @@ -138,13 +139,19 @@ function title($id) {
$author = R::findOne('authors', ' id=?', array($aid->author));
array_push($authors, $author);
}
$tag_ids = R::find('books_tags_link', ' book=?', array($id));
$tags = array();
foreach($tag_ids as $tid) {
$tag = R::findOne('tags', ' id=?', array($tid->tag));
array_push($tags, $tag);
}
$formats = R::find('data', ' book=?', array($id));
$comment = R::findOne('comments', 'book=?', array($id));
if (is_null($comment))
$comment_text = '';
else
$comment_text = $comment->text;
$app->render('title_detail.html',array('page' => mkPage($globalSettings['langa']['book_details']), 'calibre_dir' => $calibre_dir,'book' => $book, 'authors' => $authors, 'formats'=>$formats, 'comment' => $comment_text));
$app->render('title_detail.html',array('page' => mkPage($globalSettings['langa']['book_details']), 'calibre_dir' => $calibre_dir,'book' => $book, 'authors' => $authors, 'tags' => $tags, 'formats'=>$formats, 'comment' => $comment_text));
R::close();
}

Expand Down Expand Up @@ -188,11 +195,14 @@ function book($id, $file) {
}
$book = findBookPath($calibre_dir, $book->path, $file);
R::close();
$app->response()->status(200);
$app->response()->header('Content-type', getMimeType($book));
$app->response()->header('Content-Length',filesize($book));
#$app->response()->write(base64_encode($cover));
readfile($book);
/** readfile has problems with large files (e.g. PDF) caused by php memory limit
* to avoid this the function readfile_chunked() is used. app->response() is not
* working with this solution.
**/
//TODO: Use new streaming functions in SLIM 1.7.0 when released
header("Content-length: ".filesize($book));
header("Content-type: ".getMimeType($book));
readfile_chunked($book);
}

# List of all authors -> /authors
Expand Down Expand Up @@ -235,6 +245,48 @@ function author($id) {
R::close();
}

#List of all tags -> /tags
function tags() {

global $app;
global $globalSettings;

$tags = R::find('tags', ' 1 ORDER BY name');
$grouped_tags = array();
$initial_tag = "";
foreach ($tags as $tag) {
$ix = mb_strtoupper(mb_substr($tag->name,0,1,'UTF-8'), 'UTF-8');
if ($ix != $initial_tag) {
array_push($grouped_tags, array('initial' => $ix));
$initial_tag = $ix;
}
array_push($grouped_tags, $tag);
}
$app->render('tags.html',array('page' => mkPage($globalSettings['langa']['tags']),'tags' => $grouped_tags));
R::close();

}

#Details of a single tag -> /tags/:id
function tag($id) {
global $app;
global $globalSettings;

$tag = R::findOne('tags', ' id=?', array($id));
if (is_null($tag)) {
$app->getLog()->debug("no tag");
$app->notFound();
}
$book_ids = R::find('books_tags_link', ' tag=?', array($id));
$books = array();
foreach($book_ids as $bid) {
$book = R::findOne('books', ' id=?', array($bid->book));
array_push($books, $book);
}
$app->render('tag_detail.html',array('page' => mkPage($globalSettings['langa']['tag_details']), 'tag' => $tag, 'books' => $books));
R::close();
}

# Return the true path of a book. Works around a strange feature of Calibre
# where middle components of names are capitalized, eg "Aliette de Bodard" -> "Aliette De Bodard".
# The directory name uses the capitalized form, the book path stored in the DB uses the original form.
Expand Down Expand Up @@ -335,5 +387,24 @@ function getUserLang($allowedLangs, $fallbackLang) {
return $fallbackLang;
}

#Utility function to server files
function readfile_chunked($filename) {
global $app;
$app->getLog()->debug('readfile_chunked '.$filename);
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, 1024*1024);
echo $buffer;
ob_flush();
flush();
}
$status = fclose($handle);
return $status;

}

?>
5 changes: 3 additions & 2 deletions templates/author_detail.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{% extends 'main.html' %}

{% block nav %}
<h1>BicBucStriim :: {{ author.name }}</h1>
<h1>{{ page.glob.appname }} :: {{ author.name }}</h1>
<a href="{{page.rot}}/authors/" data-rel="back" data-icon="back" class="ui-btn-right">{{ page.glob.langa.back }}</a>
<div data-role="navbar">
<ul>
<li><a href="{{page.rot}}/">{{page.glob.langa.home}}</a></li>
<li><a href="{{page.rot}}/titles">{{page.glob.langa.titles}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/tags">{{page.glob.langa.tags}}</a></li>
</ul>
</div>
{% endblock %}
Expand Down
5 changes: 3 additions & 2 deletions templates/authors.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% extends 'main.html' %}

{% block nav %}
<h1>BicBucStriim :: {{ page.glob.langa.authors }}</h1>
<h1>{{ page.glob.appname }} :: {{ page.glob.langa.authors }}</h1>
<div data-role="navbar">
<ul>
<li><a href="{{page.rot}}/">{{page.glob.langa.home}}</a></li>
<li><a href="{{page.rot}}/titles">{{page.glob.langa.titles}}</a></li>
<li><a href="{{page.rot}}/authors" class="ui-btn-active">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/authors" class="ui-btn-active">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/tags">{{page.glob.langa.tags}}</a></li>
</ul>
</div>
{% endblock %}
Expand Down
7 changes: 4 additions & 3 deletions templates/index_last30.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@


{% block nav %}
<h1>BicBucStriim :: {{ page.glob.langa.dl30 }}</h1>
<h1>{{ page.glob.appname }} :: {{ page.glob.langa.dl30 }}</h1>
<div data-role="navbar">
<ul>
<li><a href="{{page.rot}}/" class="ui-btn-active">{{page.glob.langa.home}}</a></li>
<li><a href="{{page.rot}}/titles">{{page.glob.langa.titles}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/tags">{{page.glob.langa.tags}}</a></li>
</ul>
</div>
{% endblock %}
Expand All @@ -20,4 +21,4 @@ <h1>BicBucStriim :: {{ page.glob.langa.dl30 }}</h1>
</li>
{% endfor %}
</ul>
{% endblock %}
{% endblock %}
28 changes: 28 additions & 0 deletions templates/tag_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'main.html' %}

{% block nav %}
<h1>{{ page.glob.appname }} :: {{ tag.name }}</h1>
<a href="{{page.rot}}/authors/" data-rel="back" data-icon="back" class="ui-btn-right">{{ page.glob.langa.back }}</a>
<div data-role="navbar">
<ul>
<li><a href="{{page.rot}}/">{{page.glob.langa.home}}</a></li>
<li><a href="{{page.rot}}/titles">{{page.glob.langa.titles}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/tags">{{page.glob.langa.tags}}</a></li>
</ul>
</div>
{% endblock %}

{% block content %}
<section class="author_detail row">
<header>
<h1>{{page.glob.langa.booksby}} {{ tag.name }}:</h1>
</header>
<ul data-role="listview">
{% for book in books %}
<li><a href="{{page.rot}}/titles/{{book.id}}"><i class="icon-book"></i> {{ book.title }}</a></li>
{% endfor %}
</ul>
</section>

{% endblock %}
25 changes: 25 additions & 0 deletions templates/tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'main.html' %}

{% block nav %}
<h1>{{ page.glob.appname }} :: {{ page.glob.langa.tags }}</h1>
<div data-role="navbar">
<ul>
<li><a href="{{page.rot}}/">{{page.glob.langa.home}}</a></li>
<li><a href="{{page.rot}}/titles">{{page.glob.langa.titles}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/tags" class="ui-btn-active">{{page.glob.langa.tags}}</a></li>
</ul>
</div>
{% endblock %}

{% block content %}
<ul data-role="listview" data-filter="true">
{% for tag in tags %}
{% if tag.initial != "" %}
<li data-role="list-divider"> {{ tag.initial }}</li>
{% else %}
<li><a href="{{page.rot}}/tags/{{ tag.id }}">{{ tag.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
13 changes: 11 additions & 2 deletions templates/title_detail.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{% extends 'main.html' %}

{% block nav %}
<h1>BicBucStriim :: {{ book.title }}</h1>
<h1>{{ page.glob.appname }} :: {{ book.title }}</h1>
<a href="{{page.rot}}/titles/" data-rel="back" data-icon="back" class="ui-btn-right">{{ page.glob.langa.back }}</a>
<div data-role="navbar">
<ul>
<li><a href="{{page.rot}}/">{{page.glob.langa.home}}</a></li>
<li><a href="{{page.rot}}/titles">{{page.glob.langa.titles}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/tags">{{page.glob.langa.tags}}</a></li>
</ul>
</div>
{% endblock %}
Expand Down Expand Up @@ -53,6 +54,14 @@ <h2>{{page.glob.langa.comment}}</h2>
{{ comment }}
{% endautoescape %}
</div>
<div data-role="collapsible">
<h2>{{page.glob.langa.tags}}</h2>
<p>
{% for tag in tags %}
<a data-role="button" data-mini="true" data-inline="true" href="{{page.rot}}/tags/{{tag.id}}">{{ tag.name }}</a>
{% endfor %}
</p>
</div>
</section>
</section>

Expand Down
5 changes: 3 additions & 2 deletions templates/titles.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% extends 'main.html' %}

{% block nav %}
<h1>BicBucStriim :: {{ page.glob.langa.titles }}</h1>
<h1>{{ page.glob.appname }} :: {{ page.glob.langa.titles }}</h1>
<div data-role="navbar">
<ul>
<li><a href="{{page.rot}}/">{{page.glob.langa.home}}</a></li>
<li><a href="{{page.rot}}/titles" class="ui-btn-active">{{page.glob.langa.titles}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/authors">{{page.glob.langa.authors}}</a></li>
<li><a href="{{page.rot}}/tags">{{page.glob.langa.tags}}</a></li>
</ul>
</div>
{% endblock %}
Expand Down