]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/MOBIClass/PalmRecord.php
3 * A Record of a PDB file
7 class PalmRecord
extends FileObject
{
13 public function __construct($settings, $records, $textRecords, $textLength, $images){
14 $this->elements
= new FileElement(array(
15 "compression"=>new FileShort(),
16 "unused"=>new FileShort(),
17 "textLength"=>new FileInt(),
18 "recordCount"=>new FileShort(),
19 "recordSize"=>new FileShort(),
20 "encryptionType"=>new FileShort(),
21 "unused2"=>new FileShort(),
23 "mobiIdentifier"=>new FileString("MOBI", 4),
24 "mobiHeaderLength"=>new FileInt(),
25 "mobiType"=>new FileInt(),
26 "textEncoding"=>new FileInt(),
27 "uniqueID"=>new FileInt(),
28 "fileVersion"=>new FileInt(),
29 "reserved"=>new FileString(40),
30 "firstNonBookIndex"=>new FileInt(),
31 "fullNameOffset"=>new FileInt(),
32 "fullNameLength"=>new FileInt(),
33 "locale"=>new FileInt(),
34 "inputLanguage"=>new FileInt(),
35 "outputLanguage"=>new FileInt(),
36 "minimumVersion"=>new FileInt(),
37 "firstImageIndex"=>new FileInt(),
38 "huffmanRecordOffset"=>new FileInt(),
39 "huffmanRecordCount"=>new FileInt(),
40 "unused3"=>new FileString(8),
41 "exthFlags"=>new FileInt(0x40),
42 "unknown"=>new FileString(32),
43 "drmOffset"=>new FileInt(0xFFFFFFFF),
44 "drmCount"=>new FileShort(0xFFFFFFFF),
45 "drmSize"=>new FileShort(),
46 "drmFlags"=>new FileInt(),
47 "mobiFiller"=>new FileString(72),
49 "exthIdentifier"=>new FileString("EXTH", 4),
50 "exthHeaderLength"=>new FileInt(),
51 "exthRecordCount"=>new FileInt(),
52 "exthRecords"=>new FileElement(),
53 "exthPadding"=>new FileString(),
54 //"fullNamePadding"=>new FileString(100),
55 "fullName"=>new FileString()
58 //Set values from the info block
59 foreach($settings->values
as $name => $val){
61 if($this->elements
->exists($name)){
62 $this->elements
->get($name)->set($settings->get($name));
66 $els = $settings->values
;
68 $exthElems = new FileElement();
71 foreach($els as $name=>$val){
72 $type = EXTHHelper
::textToType($name);
74 $type = new FileInt($type);
75 $length = new FileInt(8+
strlen($val));
76 $data = new FileString($val);
78 $exthElems->add("type".$i, $type);
79 $exthElems->add("length".$i, $length);
80 $exthElems->add("data".$i, $data);
86 $this->elements
->get("firstImageIndex")->set($textRecords+
1);
88 $this->elements
->get("firstNonBookIndex")->set($textRecords+
2+
$images);
89 $this->elements
->get("reserved")->set(str_pad("", 40, chr(255), STR_PAD_RIGHT
));
90 $this->elements
->get("exthRecordCount")->set($i);
91 $this->elements
->set("exthRecords", $exthElems);
94 $this->elements
->get("exthPadding")->set(str_pad("", $pad, "\0", STR_PAD_RIGHT
));
95 $this->elements
->get("exthHeaderLength")->set(12+
$l+
$pad);
98 $this->elements
->get("recordCount")->set($textRecords);
100 $this->elements
->get("fullNameOffset")->set($this->elements
->offsetToEntry("fullName"));
101 $this->elements
->get("fullNameLength")->set(strlen($settings->get("title")));
102 $this->elements
->get("fullName")->set($settings->get("title"));
103 $this->elements
->get("textLength")->set($textLength);
106 public function getByteLength(){
107 return $this->getLength();
110 public function getLength(){
111 return $this->elements
->getByteLength();
114 public function get(){
118 public function set($elements){
119 throw new Exception("Unallowed set");
122 public function serialize() {
123 return $this->elements
->serialize();
126 public function unserialize($data) {
127 $this->elements
->unserialize($data);
130 public function __toString(){
131 $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n";
132 $output .= $this->elements
;