-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.php
80 lines (68 loc) · 2.16 KB
/
manifest.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
76
77
78
79
80
<?php
require_once("item.php");
class manifest {
private $epub = null;
private $items = null;
//costruttore
function __construct($epub) {
$this->epub = $epub;
$this->items = array();
$this->import();
}
public function import() {
$xml = $this->epub->getOpf()->manifest;
foreach($xml->item as $item){
$attr = $item->attributes();
if(isset($attr["properties"])) {
$item = new item($attr["id"], $attr["href"], $attr["media-type"], $attr["properties"]);
} else {
$item = new item($attr["id"], $attr["href"], $attr["media-type"]);
}
$this->addItem($item);
}
}
public function addItem($item) {
array_push($this->items, $item);
}
public function removeItem($item) {
$key = array_search($item, $this->items);
unset($this->items[$key]);
}
public function getItemById($id) {
foreach($this->items as $item) {
if($item->getId() == $id) return $item;
}
return null;
}
public function getItemsByMedia_type($media_type) {
$return = array();
foreach($this->items as $item) {
if($item->getMedia_type() == $media_type) array_push($return, $item);
}
return $return;
}
public function getItemsByProperty($property) {
$return = array();
foreach($this->items as $item) {
if($item->getProperties() == $property) array_push($return, $item);
}
return $return;
}
public function getItemByHref($href) {
foreach($this->items as $item) {
if($item->getHref() == $href) return $item;
}
return null;
}
public function asXml($manifest) {
foreach($this->items as $item) {
//var_dump($item);print "<br>";
$nodo = $manifest->addChild("item");
$nodo->addAttribute("id", $item->getId());
$nodo->addAttribute("href", $item->getHref());
$nodo->addAttribute("media-type", $item->getMedia_type());
if(!is_null($item->getProperties())) $nodo->addAttribute("properties", $item->getProperties());
}
}
}
?>