|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* COPS (Calibre OPDS PHP Server) HTML main script |
|
4
|
|
|
* |
|
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
6
|
|
|
* @author Sébastien Lucas <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
require_once dirname(__FILE__) . '/config.php'; |
|
11
|
|
|
require_once dirname(__FILE__) . '/base.php'; |
|
12
|
|
|
|
|
13
|
|
|
// If we detect that an OPDS reader try to connect try to redirect to feed.php |
|
14
|
|
|
if (preg_match('/(MantanoReader|FBReader|Stanza|Marvin|Aldiko|Moon\+ Reader|Chunky|AlReader|EBookDroid|BookReader|CoolReader|PageTurner|books\.ebook\.pdf\.reader|com\.hiwapps\.ebookreader|OpenBook)/', $_SERVER['HTTP_USER_AGENT'])) { |
|
15
|
|
|
header('location: feed.php'); |
|
16
|
|
|
exit(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
$page = getURLParam('page', Base::PAGE_INDEX); |
|
20
|
|
|
$query = getURLParam('query'); |
|
21
|
|
|
$qid = getURLParam('id'); |
|
22
|
|
|
$n = getURLParam('n', '1'); |
|
23
|
|
|
$database = GetUrlParam(DB); |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
// Access the database ASAP to be sure it's readable, redirect if that's not the case. |
|
27
|
|
|
// It has to be done before any header is sent. |
|
28
|
|
|
Base::checkDatabaseAvailability(); |
|
29
|
|
|
|
|
30
|
|
|
if ($config ['cops_fetch_protect'] == '1') { |
|
31
|
|
|
session_start(); |
|
32
|
|
|
if (!isset($_SESSION['connected'])) { |
|
33
|
|
|
$_SESSION['connected'] = 0; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
header('Content-Type:text/html;charset=utf-8'); |
|
38
|
|
|
|
|
39
|
|
|
$data = array('title' => $config['cops_title_default'], |
|
40
|
|
|
'version' => VERSION, |
|
41
|
|
|
'opds_url' => $config['cops_full_url'] . 'feed.php', |
|
42
|
|
|
'customHeader' => '', |
|
43
|
|
|
'template' => getCurrentTemplate(), |
|
44
|
|
|
'server_side_rendering' => useServerSideRendering(), |
|
45
|
|
|
'current_css' => getCurrentCss(), |
|
46
|
|
|
'favico' => $config['cops_icon'], |
|
47
|
|
|
'getjson_url' => 'getJSON.php?' . addURLParameter(getQueryString(), 'complete', 1)); |
|
48
|
|
|
if (preg_match('/Kindle/', $_SERVER['HTTP_USER_AGENT'])) { |
|
49
|
|
|
$data['customHeader'] = '<style media="screen" type="text/css"> html { font-size: 75%; -webkit-text-size-adjust: 75%; -ms-text-size-adjust: 75%; }</style>'; |
|
50
|
|
|
} |
|
51
|
|
|
$headcontent = file_get_contents('templates/' . getCurrentTemplate() . '/file.html'); |
|
52
|
|
|
$template = new doT(); |
|
53
|
|
|
$dot = $template->template($headcontent, NULL); |
|
54
|
|
|
echo($dot($data)); |
|
55
|
|
|
?><body> |
|
56
|
|
|
<?php |
|
57
|
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); |
|
58
|
|
|
if (useServerSideRendering()) { |
|
59
|
|
|
// Get the data |
|
60
|
|
|
$data = JSONRenderer::getJson(true); |
|
61
|
|
|
|
|
62
|
|
|
echo serverSideRender($data); |
|
63
|
|
|
} |
|
64
|
|
|
?> |
|
65
|
|
|
</body> |
|
66
|
|
|
</html> |
|
67
|
|
|
|