-
Notifications
You must be signed in to change notification settings - Fork 0
/
spine.php
75 lines (61 loc) · 1.92 KB
/
spine.php
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
<?php
require_once("itemref.php");
class spine {
private $epub = null;
private $toc = null;
private $itemrefs = null;
//costruttore
function __construct($epub) {
$this->epub = $epub;
$this->itemrefs = array();
$this->import();
}
public function import() {
$xml = $this->epub->getOpf()->spine;
$manifest = $this->epub->getManifest();
$attr = $xml->attributes();
$this->toc = $manifest->getItemById((string)$attr["toc"]);
foreach($xml->itemref as $itemref){
$attr = $itemref->attributes();
$item = $manifest->getItemById((string)$attr["idref"]);
$linear = true;
if(($attr["linear"] == "no") and isset($attr["linear"])) $linear = false;
$itemref = new itemref($item, $linear);
$this->addItemref($itemref);
}
}
public function addItemref($itemref) {
array_push($this->itemrefs, $itemref);
}
public function insertItemref($itemref, $after) {
if($after != null) {
$itemrefs = $this->itemrefs;
$this->itemrefs = array();
foreach($itemrefs as $item) {
$this->addItemref($item);
if($after == $item) $this->addItemref($itemref);
}
} else {
array_unshift($this->itemrefs, $itemref);
}
}
public function getItemrefs() {
return $this->itemrefs;
}
public function getItemrefById($id) {
foreach($this->itemrefs as $itemref) {
if($itemref->getItem()->getId() == $id) return $itemref;
}
return null;
}
public function asXml($spine) {
foreach($this->itemrefs as $itemref) {
$nodo = $spine->addChild("itemref");
$nodo->addAttribute("idref", $itemref->getItem()->getId());
$linear = "no";
if($itemref->getLinear()) $linear = "yes";
$nodo->addAttribute("linear", $linear);
}
}
}
?>