2013-05-14 22:35:43 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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-29 09:43:11 +03:00
|
|
|
$book = new EPub ("c:/Temp/Phare.epub");
|
2013-05-14 22:35:43 +03:00
|
|
|
$book->initSpineComponent ();
|
|
|
|
|
|
|
|
$component = $_GET["comp"];
|
|
|
|
|
|
|
|
if (empty ($component)) {
|
|
|
|
notFound ();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 11:35:15 +03:00
|
|
|
$callback = function ($m) use ($book, $component) {
|
|
|
|
$method = $m[1];
|
|
|
|
$path = $m[2];
|
|
|
|
if (preg_match ("/^#/", $path)) {
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
$comp = $book->getComponentName ($component, $path);
|
|
|
|
return "$method'epubfs.php?comp=$comp'";
|
|
|
|
};
|
|
|
|
|
|
|
|
$data = preg_replace_callback ("/(src=)[\"']([^:]*?)[\"']/", $callback, $data);
|
|
|
|
$data = preg_replace_callback ("/(href=)[\"']([^:]*?)[\"']/", $callback, $data);
|
|
|
|
$data = preg_replace_callback ("/(\@import\s+)[\"'](.*?)[\"'];/", $callback, $data);
|
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 ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|