Calibre PHP Patches
Two quick patches which should be in the next version of Calibre PHP.
Adding File Size
This shows the sizes of the eBook files. Screenshot shows a demonstration using the free "Hacking The BBC" eBook.
--- /data/web/calibre_php_server-V0.2.7/db.php 2011-11-20 10:19:00.000000000 +0000
+++ db.php 2011-11-20 10:24:16.000000000 +0000
@@ -571,7 +571,7 @@
}
// Formats
- $data = $this->db->query(sprintf('SELECT format,name
+ $data = $this->db->query(sprintf('SELECT format,name,uncompressed_size
FROM data WHERE book=%d', $id));
$fmts = array();
while ($data and $row = $data->fetchArray()) {
@@ -581,7 +581,8 @@
$fmts[] = array
('format' => $row['format'],
'name' => $row['name'],
- 'URL' => "index.php/book_format/$id/$book_name");
+ 'URL' => "index.php/book_format/$id/$book_name",
+ 'size' => round( ($row['uncompressed_size'] / 1024 / 1024), 2) . "MB");
}
$book['formats'] = $fmts;
@@ -809,4 +810,4 @@
}
}
}
-?>
No newline at end of file
+?>
--- /data/web/calibre_php_server-V0.2.7/smarty/templates/books_section.tpl 2011-11-20 10:19:01.000000000 +0000
+++ newTemplates/templates/books_section.tpl 2011-11-20 10:12:04.000000000 +0000
@@ -15,13 +15,13 @@
{{if $books[book].rating_url}}
{{/if}}
{{section name=format loop=$books[book].formats}} - {{$books[book].formats[format].format}}
+ {{$books[book].formats[format].format}} {{$books[book].formats[format].size}}
{{/section}}
+ {{$books[book].formats[format].format}} {{$books[book].formats[format].size}}
{{/section}}
Escaping Ampersands
Because I'm a nerd, I believe in making valid HTML. That means that & should properly be written as &
--- /data/web/calibre_php_server-V0.2.7/smarty/templates/index.tpl 2011-11-20 10:19:01.000000000 +0000
+++ /data/www/calibre/newTemplates/templates/index.tpl 2011-11-19 23:31:17.000000000 +0000
@@ -6,7 +6,7 @@
{{include file="header.tpl" title="Home"}}
<table><tr><td>
<div style="padding-right: 20px; float: left; width: 200px; font-family: 'Arial Rounded MT Bold';">
- <a href="index.php?m=titles&p=1">
+ </a><a href="index.php?m=titles&p=1">
<span style="padding-left:10px">Titles</span></a>
[{{$title_count}}]
</div>
diff -rupN /data/web/calibre_php_server-V0.2.7/modules//book_base.php /data/www/calibre/modules//book_base.php
--- /data/web/calibre_php_server-V0.2.7/modules//book_base.php 2011-11-20 10:19:01.000000000 +0000
+++ /data/www/calibre/modules//book_base.php 2011-11-19 23:29:37.000000000 +0000
@@ -34,10 +34,10 @@
// Get the books for page N
for ($i = min($start, count($books)); $i < min($end, count($books)); $i++) {
$res[] = $books[$i];
- $res[count($res)-1]['cover'] = 'index.php?m=cover&id=' . $books[$i]['id'];
+ $res[count($res)-1]['cover'] = 'index.php?m=cover&id=' . $books[$i]['id'];
if ($short_form)
$res[count($res)-1]['details_url'] =
- 'index.php?m=book&id=' . $books[$i]['id'];
+ 'index.php?m=book&id=' . $books[$i]['id'];
}
$smarty->assign('books', $res);
$p_n_url = '';
@@ -47,7 +47,7 @@
if ($page > 1)
$smarty->assign('page_back', "index.php?{$p_n_url}p=" . ($page-1));
if ($end < count($books))
- $smarty->assign('page_forw', "index.php?$p_n_url&p=" . ($page+1));
+ $smarty->assign('page_forw', "index.php?$p_n_url&p=" . ($page+1));
$smarty->assign('page', $page);
$smarty->assign('maxpage', (int)((count($books)-1)/$config['books_page_count'])+1);
$smarty->assign('sortable_fields', $sortable_fields);
@@ -56,4 +56,4 @@
$smarty->assign('prev_next', $p_n_array);
}
}
-?>
No newline at end of file
+?>
diff -rupN /data/web/calibre_php_server-V0.2.7/modules//category.php /data/www/calibre/modules//category.php
--- /data/web/calibre_php_server-V0.2.7/modules//category.php 2011-11-20 10:19:01.000000000 +0000
+++ /data/www/calibre/modules//category.php 2011-11-19 23:26:57.000000000 +0000
@@ -34,17 +34,17 @@
// item has a rating. Include the URL to display it.
$items[] = array('icon' => get_icon_path($v->category, $db),
'name' => $v->name,
- 'href' => "index.php?m=catval&id=$v->id&p=1&&cat=" .
- urlencode($v->category) . '&v=' . urlencode($v->name),
+ 'href' => "index.php?m=catval&id=$v->id&p=1&cat=" .
+ urlencode($v->category) . '&v=' . urlencode($v->name),
'count' => $v->count,
- 'rating' => "index.php?m=rating&r=" . round($v->avg_rating, 2)
+ 'rating' => "index.php?m=rating&r=" . round($v->avg_rating, 2)
);
} else {
$items[] = array('icon' => get_icon_path($v->category, $db),
'name' => $v->name,
- 'href' => "index.php?m=catval&id=$v->id&p=1&cat=" .
+ 'href' => "index.php?m=catval&id=$v->id&p=1&cat=" .
urlencode($v->category) .
- '&v=' . urlencode($v->name),
+ '&v=' . urlencode($v->name),
'count' => $v->count
);
}
@@ -60,4 +60,4 @@
}
$mod = new DoCategory();
-?>
No newline at end of file
+?>
diff -rupN /data/web/calibre_php_server-V0.2.7/modules//catval.php /data/www/calibre/modules//catval.php
--- /data/web/calibre_php_server-V0.2.7/modules//catval.php 2011-11-20 10:19:01.000000000 +0000
+++ /data/www/calibre/modules//catval.php 2011-11-19 23:29:01.000000000 +0000
@@ -44,7 +44,7 @@
));
$smarty->assign('category_name', $fm = $db->fm->name_for($cat));
$smarty->assign('category_value', $_REQUEST['v']);
- $smarty->assign('up_url', "index.php?m=category&id=$id&cat=".urlencode($cat));
+ $smarty->assign('up_url', "index.php?m=category&id=$id&cat=".urlencode($cat));
}
function template() {
@@ -53,4 +53,4 @@
}
$mod = new DoCatval();
-?>
No newline at end of file
+?>
diff -rupN /data/web/calibre_php_server-V0.2.7/modules//home.php /data/www/calibre/modules//home.php
--- /data/web/calibre_php_server-V0.2.7/modules//home.php 2011-11-20 10:19:01.000000000 +0000
+++ /data/www/calibre/modules//home.php 2011-11-19 23:25:53.000000000 +0000
@@ -21,7 +21,7 @@
$m = $db->fm->metadata_for($k);
$items[] = array( 'icon' => get_icon_path($k, $db),
'name' => $m['name'],
- 'href' => "index.php?m=category&cat=" . urlencode($k),
+ 'href' => "index.php?m=category&cat=" . urlencode($k),
'count'=> count($v)
);
}
@@ -34,4 +34,4 @@
}
}
$mod = new DoHome();
-?>
No newline at end of file
+?>
</td></tr></table>
More
Both patches should be in the official version soon. More to come!