From a45d45f0ef88bc05977245a90c45e8d67c8ecd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 11 Feb 2014 18:03:19 +0100 Subject: [PATCH] Reorganize a little the epubfs file --- epubfs.php | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/epubfs.php b/epubfs.php index 5010db4..d4afb9f 100644 --- a/epubfs.php +++ b/epubfs.php @@ -12,23 +12,7 @@ function notFound () { $_SERVER['REDIRECT_STATUS'] = 404; } -$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)); - -$book->initSpineComponent (); - -if (!isset ($_GET["comp"])) { - notFound (); - return; -} - -$component = $_GET["comp"]; - -try { +function getComponentContent ($book, $component, $add) { $data = $book->component ($component); $directory = dirname ($component); @@ -61,6 +45,30 @@ try { $data = preg_replace_callback ("/(\@import\s+)[\"'](.*?)[\"'];/", $callback, $data); $data = preg_replace_callback ("/(src:\s*url\()(.*?)\)/", $callback, $data); + return $data; +} + +if (php_sapi_name() === 'cli') { return; } + +$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)); + +$book->initSpineComponent (); + +if (!isset ($_GET["comp"])) { + notFound (); + return; +} + +$component = $_GET["comp"]; + +try { + $data = getComponentContent ($book, $component, $add); + $expires = 60*60*24*14; header("Pragma: public"); header("Cache-Control: maxage=".$expires);