diff options
author | tcit <tcit@tcit.fr> | 2014-07-24 21:56:04 +0200 |
---|---|---|
committer | tcit <tcit@tcit.fr> | 2014-07-24 21:56:04 +0200 |
commit | fb9df0c269f36703909b8b259abbdbed29881ecd (patch) | |
tree | 03069262fe6a7bd5891f5649d31fc057b3ca8541 /inc/3rdparty/libraries/MOBIClass/Prc.php | |
parent | c70bfefc68fcc96b1ce57845e5b2942a596239ec (diff) | |
download | wallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.tar.gz wallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.tar.zst wallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.zip |
use directly MOBIClass
Diffstat (limited to 'inc/3rdparty/libraries/MOBIClass/Prc.php')
-rw-r--r-- | inc/3rdparty/libraries/MOBIClass/Prc.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/inc/3rdparty/libraries/MOBIClass/Prc.php b/inc/3rdparty/libraries/MOBIClass/Prc.php new file mode 100644 index 00000000..c40b5805 --- /dev/null +++ b/inc/3rdparty/libraries/MOBIClass/Prc.php | |||
@@ -0,0 +1,97 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of Prc | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class Prc extends FileElement { | ||
9 | public function __construct($settings, $records){ | ||
10 | parent::__construct(array( | ||
11 | "title"=>new FileString(32), | ||
12 | "attributes"=>new FileShort(), | ||
13 | "version"=>new FileShort(), | ||
14 | "creationTime"=>new FileDate(), | ||
15 | "modificationTime"=>new FileDate(), | ||
16 | "backupTime"=>new FileDate(), | ||
17 | "modificationNumber"=>new FileInt(), | ||
18 | "appInfoID"=>new FileInt(), | ||
19 | "sortInfoID"=>new FileInt(), | ||
20 | "prcType"=>new FileString(4), | ||
21 | "creator"=>new FileString(4), | ||
22 | "uniqueIDSeed"=>new FileInt(), | ||
23 | "nextRecordListID"=>new FileInt(), | ||
24 | "numberRecords"=>new FileShort(), | ||
25 | "recordList"=>new FileElement(), | ||
26 | "filler"=>new FileShort(), | ||
27 | "records"=>new FileElement() | ||
28 | )); | ||
29 | |||
30 | //Set values from the info block | ||
31 | foreach($this->elements as $name => $val){ | ||
32 | if($settings->exists($name)){ | ||
33 | $this->get($name)->set($settings->get($name)); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | $this->get("numberRecords")->set(sizeof($records)); | ||
38 | |||
39 | $i = 0; | ||
40 | foreach($records as $record){ | ||
41 | $offset = new FileInt(); | ||
42 | $attr = new FileByte(); | ||
43 | $uniqueID = new FileTri($i); | ||
44 | |||
45 | $this->elements["recordList"]->add("Rec".$i, new FileElement(array( | ||
46 | "offset"=>$offset, | ||
47 | "attribute"=>$attr, | ||
48 | "uniqueID"=>$uniqueID | ||
49 | ))); | ||
50 | |||
51 | $this->elements["records"]->add("Rec".$i, $record); | ||
52 | $i++; | ||
53 | } | ||
54 | |||
55 | $this->updateOffsets($records); | ||
56 | } | ||
57 | |||
58 | public function getByteLength(){ | ||
59 | throw new Exception("Test"); | ||
60 | } | ||
61 | |||
62 | public function updateOffsets($records){ | ||
63 | $base = $this->offsetToEntry("records"); | ||
64 | |||
65 | $i = 0; | ||
66 | |||
67 | foreach($records as $record){ | ||
68 | $el = $this->elements["recordList"]->get("Rec".$i); | ||
69 | |||
70 | $local = $this->elements["records"]->offsetToEntry("Rec".$i); | ||
71 | |||
72 | $el->get("offset")->set($base+$local); | ||
73 | |||
74 | $i++; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public function save($file){ | ||
79 | $handle = fopen($file, "w"); | ||
80 | fwrite($handle, $this->serialize()); | ||
81 | fclose($handle); | ||
82 | } | ||
83 | |||
84 | public function output(){ | ||
85 | echo $this->serialize(); | ||
86 | } | ||
87 | |||
88 | public function __toString(){ | ||
89 | $output = "Prc (".$this->getByteLength()." bytes): {\n"; | ||
90 | foreach($this->elements as $key=>$value){ | ||
91 | $output .= "\t".$key.": ".$value."\n"; | ||
92 | } | ||
93 | $output .= "}"; | ||
94 | return $output; | ||
95 | } | ||
96 | } | ||
97 | ?> | ||