2013-05-14 22:35:43 +03:00
|
|
|
<?php
|
|
|
|
|
2013-08-30 16:52:28 +03:00
|
|
|
require_once ("config.php");
|
|
|
|
require_once ("base.php");
|
|
|
|
require_once ("book.php");
|
2013-05-14 22:35:43 +03:00
|
|
|
require_once ("resources/php-epub-meta/epub.php");
|
|
|
|
|
|
|
|
function notFound () {
|
|
|
|
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
|
|
|
|
header("Status: 404 Not Found");
|
|
|
|
|
|
|
|
$_SERVER['REDIRECT_STATUS'] = 404;
|
|
|
|
}
|
|
|
|
|
2013-08-30 16:52:28 +03:00
|
|
|
$idData = getURLParam ("data", NULL);
|
|
|
|
$add = "data=$idData&";
|
|
|
|
if (!is_null (GetUrlParam (DB))) $add .= DB . "=" . GetUrlParam (DB) . "&";
|
|
|
|
$myBook = Book::getBookByDataId($idData);
|
|
|
|
|
|
|
|
$book = new EPub ($myBook->getFilePath ("EPUB", $idData));
|
|
|
|
|
2013-05-14 22:35:43 +03:00
|
|
|
$book->initSpineComponent ();
|
|
|
|
|
2014-01-13 23:21:01 +02:00
|
|
|
if (!isset ($_GET["comp"])) {
|
2013-05-14 22:35:43 +03:00
|
|
|
notFound ();
|
2014-01-13 23:21:01 +02:00
|
|
|
return;
|
2013-05-14 22:35:43 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 23:21:01 +02:00
|
|
|
$component = $_GET["comp"];
|
|
|
|
|
2013-05-14 22:35:43 +03:00
|
|
|
try {
|
2013-08-30 11:35:15 +03:00
|
|
|
$data = $book->component ($component);
|
2013-05-14 22:35:43 +03:00
|
|
|
$directory = dirname ($component);
|
|
|
|
|
2013-08-30 16:52:28 +03:00
|
|
|
$callback = function ($m) use ($book, $component, $add) {
|
2013-08-30 11:35:15 +03:00
|
|
|
$method = $m[1];
|
|
|
|
$path = $m[2];
|
2014-01-13 22:43:44 +02:00
|
|
|
$end = "";
|
|
|
|
if (preg_match ("/^src:/", $method)) {
|
|
|
|
$end = ")";
|
|
|
|
}
|
2013-08-30 11:35:15 +03:00
|
|
|
if (preg_match ("/^#/", $path)) {
|
2014-01-13 22:43:44 +02:00
|
|
|
return "{$method}'{$path}'{$end}";
|
2013-08-30 11:35:15 +03:00
|
|
|
}
|
2013-08-30 22:14:59 +03:00
|
|
|
$hash = "";
|
|
|
|
if (preg_match ("/^(.+)#(.+)$/", $path, $matches)) {
|
|
|
|
$path = $matches [1];
|
|
|
|
$hash = "#" . $matches [2];
|
|
|
|
}
|
2013-08-30 11:35:15 +03:00
|
|
|
$comp = $book->getComponentName ($component, $path);
|
2013-08-30 21:59:57 +03:00
|
|
|
if (!$comp) return "#";
|
2014-01-13 23:21:01 +02:00
|
|
|
$out = "{$method}'epubfs.php?{$add}comp={$comp}{$hash}'{$end}";
|
|
|
|
if ($end) {
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
return str_replace ("&", "&", $out);
|
2013-08-30 11:35:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
$data = preg_replace_callback ("/(src=)[\"']([^:]*?)[\"']/", $callback, $data);
|
|
|
|
$data = preg_replace_callback ("/(href=)[\"']([^:]*?)[\"']/", $callback, $data);
|
|
|
|
$data = preg_replace_callback ("/(\@import\s+)[\"'](.*?)[\"'];/", $callback, $data);
|
2014-01-13 23:21:01 +02:00
|
|
|
$data = preg_replace_callback ("/(src:\s*url\()(.*?)\)/", $callback, $data);
|
2013-05-14 22:35:43 +03:00
|
|
|
|
2013-08-30 22:08:07 +03:00
|
|
|
$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');
|
2013-05-14 22:35:43 +03:00
|
|
|
header ("Content-Type: " . $book->componentContentType($component));
|
|
|
|
echo $data;
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
2013-08-30 11:35:15 +03:00
|
|
|
error_log ($e);
|
2013-05-14 22:35:43 +03:00
|
|
|
notFound ();
|
2013-08-30 16:52:28 +03:00
|
|
|
}
|