Working with cops

--HG--
extra : rebase_source : 66639c415fc1286e8df50c255d83b0e8f92777d3
This commit is contained in:
Sébastien Lucas 2013-08-30 15:52:28 +02:00
parent 30f801443e
commit ea3da650de
3 changed files with 37 additions and 17 deletions

View file

@ -1,5 +1,8 @@
<?php <?php
require_once ("config.php");
require_once ("base.php");
require_once ("book.php");
require_once ("resources/php-epub-meta/epub.php"); require_once ("resources/php-epub-meta/epub.php");
function notFound () { function notFound () {
@ -9,7 +12,13 @@ function notFound () {
$_SERVER['REDIRECT_STATUS'] = 404; $_SERVER['REDIRECT_STATUS'] = 404;
} }
$book = new EPub ("c:/Temp/Phare.epub"); $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 (); $book->initSpineComponent ();
$component = $_GET["comp"]; $component = $_GET["comp"];
@ -22,14 +31,14 @@ try {
$data = $book->component ($component); $data = $book->component ($component);
$directory = dirname ($component); $directory = dirname ($component);
$callback = function ($m) use ($book, $component) { $callback = function ($m) use ($book, $component, $add) {
$method = $m[1]; $method = $m[1];
$path = $m[2]; $path = $m[2];
if (preg_match ("/^#/", $path)) { if (preg_match ("/^#/", $path)) {
return $path; return $path;
} }
$comp = $book->getComponentName ($component, $path); $comp = $book->getComponentName ($component, $path);
return "$method'epubfs.php?comp=$comp'"; return "$method'epubfs.php?{$add}comp=$comp'";
}; };
$data = preg_replace_callback ("/(src=)[\"']([^:]*?)[\"']/", $callback, $data); $data = preg_replace_callback ("/(src=)[\"']([^:]*?)[\"']/", $callback, $data);
@ -43,6 +52,3 @@ catch (Exception $e) {
error_log ($e); error_log ($e);
notFound (); notFound ();
} }
?>

View file

@ -1,27 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<?php <?php
require_once ("config.php"); require_once ("config.php");
require_once ("base.php"); require_once ("base.php");
require_once ("book.php");
require_once ("resources/php-epub-meta/epub.php"); require_once ("resources/php-epub-meta/epub.php");
header ("Content-Type: text/html;charset=utf-8"); header ("Content-Type: text/html;charset=utf-8");
$book = new EPub ("c:/Temp/Phare.epub"); $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 (); $book->initSpineComponent ();
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="imagetoolbar" content="no" /> <meta http-equiv="imagetoolbar" content="no" />
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" /> <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
<title>COPS's Epub Reader</title> <title>COPS's Epub Reader</title>
<script type="text/javascript" src="<?php echo getUrlWithVersion("js/jquery-1.9.1.min.js") ?>"></script> <script type="text/javascript" src="<?php echo getUrlWithVersion("resources/jQuery/jquery-1.10.2.min.js") ?>"></script>
<script type="text/javascript" src="<?php echo getUrlWithVersion("resources/monocle320/scripts/monocore.js") ?>"></script> <script type="text/javascript" src="<?php echo getUrlWithVersion("resources/monocle/scripts/monocore.js") ?>"></script>
<script type="text/javascript" src="<?php echo getUrlWithVersion("resources/monocle320/scripts/monoctrl.js") ?>"></script> <script type="text/javascript" src="<?php echo getUrlWithVersion("resources/monocle/scripts/monoctrl.js") ?>"></script>
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/monocle320/styles/monocore.css") ?>" media="screen" /> <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/monocle/styles/monocore.css") ?>" media="screen" />
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/monocle320/styles/monoctrl.css") ?>" media="screen" /> <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/monocle/styles/monoctrl.css") ?>" media="screen" />
<script type="text/javascript"> <script type="text/javascript">
Monocle.DEBUG = true; Monocle.DEBUG = true;
var bookData = { var bookData = {
@ -33,7 +39,7 @@ $book->initSpineComponent ();
}, },
getComponent: function (componentId, callback) { getComponent: function (componentId, callback) {
$.ajax({ $.ajax({
url: "epubfs.php?comp=" + componentId, url: "epubfs.php?<?php echo $add ?>comp=" + componentId,
type: 'get', type: 'get',
dataType: 'text', dataType: 'text',
error: function () {alert ("error");}, error: function () {alert ("error");},
@ -42,7 +48,7 @@ $book->initSpineComponent ();
}, },
getMetaData: function(key) { getMetaData: function(key) {
return { return {
title: "A book", title: "<?php echo $myBook->title ?>",
creator: "Inventive Labs" creator: "Inventive Labs"
}[key]; }[key];
} }

View file

@ -194,6 +194,14 @@ class EPub {
$src = $this->toc_xpath->query('x:content', $node)->item(0)->attr('src'); $src = $this->toc_xpath->query('x:content', $node)->item(0)->attr('src');
$src = str_replace ("/", "-SLASH-", $src); $src = str_replace ("/", "-SLASH-", $src);
$contents[] = array("title" => $title, "src" => $src); $contents[] = array("title" => $title, "src" => $src);
$insidenodes = $this->toc_xpath->query('x:navPoint', $node);
foreach($insidenodes as $insidenode){
$title = $this->toc_xpath->query('x:navLabel/x:text', $insidenode)->item(0)->nodeValue;
$src = $this->toc_xpath->query('x:content', $insidenode)->item(0)->attr('src');
$src = str_replace ("/", "-SLASH-", $src);
$contents[] = array("title" => $title, "src" => $src);
}
} }
return $contents; return $contents;
} }