-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepubfs.php
More file actions
91 lines (78 loc) · 2.47 KB
/
epubfs.php
File metadata and controls
91 lines (78 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* source code : COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
* modified for My readings
*/
if(isset($_GET['mylogin'])) $mylogin=$_GET['mylogin'];
else $mylogin="";
if(isset($_GET['mypass'])) $mypass=$_GET['mypass'];
else $mypass="";
require_once('./config/config.php');
if($protect==false||($account[$mylogin]&&$account[$mylogin][0]==$mypass)) {
//OK
} else {
echo "Non autorisé";
die;
}
//Chemin de l'epub
if(isset($_GET['path'])) $mypath=$_GET['path'];
else {
echo "No book path";
die;
}
if(isset($_GET['comp'])) $component=$_GET['comp'];
else {
echo "No component";
die;
}
$add="mylogin=".$mylogin."&mypass=".$mypass."&path=".urlencode($mypath)."&";
require_once ("resources/epub/php-epub-meta/epub.php");
$book = new EPub($mypath);
$book->initSpineComponent ();
try {
$data = getComponentContent ($book, $component, $add);
$expires = 60*60*24*14;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header ("Content-Type: " . $book->componentContentType($component));
echo $data;
}
catch (Exception $e) {
echo $e;
}
function getComponentContent ($book, $component, $add) {
$data = $book->component ($component);
$callback = function ($m) use ($book, $component, $add) {
$method = $m[1];
$path = $m[2];
$end = "";
if (preg_match ("/^src\s*:/", $method)) {
$end = ")";
}
if (preg_match ("/^#/", $path)) {
return "{$method}'{$path}'{$end}";
}
$hash = "";
if (preg_match ("/^(.+)#(.+)$/", $path, $matches)) {
$path = $matches [1];
$hash = "#" . $matches [2];
}
$comp = $book->getComponentName ($component, $path);
if (!$comp) return "{$method}'#'{$end}";
$out = "{$method}'epubfs.php?{$add}comp={$comp}{$hash}'{$end}";
if ($end) {
return $out;
}
return str_replace ("&", "&", $out);
};
$data = preg_replace_callback ("/(src=)[\"']([^:]*?)[\"']/", $callback, $data);
$data = preg_replace_callback ("/(href=)[\"']([^:]*?)[\"']/", $callback, $data);
$data = preg_replace_callback ("/(\@import\s+)[\"'](.*?)[\"'];/", $callback, $data);
$data = preg_replace_callback ("/(src\s*:\s*url\()(.*?)\)/", $callback, $data);
return $data;
}
?>