]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/send2kindle/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(0x50),
42 "unknown"=>new FileString(32),
43 "drmOffset"=>new FileInt(0xFFFFFFFF),
44 "drmCount"=>new FileInt(0xFFFFFFFF),
45 "drmSize"=>new FileInt(),
46 "drmFlags"=>new FileInt(),
47 "mobiFiller"=>new FileString(12),
48 "offset192"=>new FileShort(0x01),
49 "offset194"=>new FileShort(),
50 "offset196"=>new FileInt(0x01),
51 "offset200"=>new FileInt(),
52 "offset204"=>new FileInt(0x01),
53 "offset208"=>new FileInt(),
54 "offset212"=>new FileInt(0x01),
55 "offset216"=>new FileString(8),
56 "offset224"=>new FileInt(0xFFFFFFFF),
57 "offset228"=>new FileInt(),
58 "offset232"=>new FileString(8),
59 "offset240"=>new FileInt(0x01),
60 "offset244"=>new FileInt(0xFFFFFFFF),
62 "exthIdentifier"=>new FileString("EXTH", 4),
63 "exthHeaderLength"=>new FileInt(),
64 "exthRecordCount"=>new FileInt(),
65 "exthRecords"=>new FileElement(),
66 "exthPadding"=>new FileString(),//added the 2 extra pad bytes that comes before name/title
67 //"fullNamePadding"=>new FileString(100),
68 "fullName"=>new FileString()
71 //Set values from the info block
72 foreach($settings->values
as $name => $val){
74 if($this->elements
->exists($name)){
75 $this->elements
->get($name)->set($settings->get($name));
79 $els = $settings->values
;
81 $exthElems = new FileElement();
84 foreach($els as $name=>$val){
85 $type = EXTHHelper
::textToType($name);
87 $type = new FileInt($type);
88 $length = new FileInt(8+
strlen($val));
89 $data = new FileString($val);
91 $exthElems->add("type".$i, $type);
92 $exthElems->add("length".$i, $length);
93 $exthElems->add("data".$i, $data);
99 $this->elements
->get("firstImageIndex")->set($textRecords+
2);
101 $this->elements
->get("firstNonBookIndex")->set($textRecords+
2+
$images);
102 $this->elements
->get("reserved")->set(str_pad("", 40, chr(255), STR_PAD_RIGHT
));
103 $this->elements
->get("exthRecordCount")->set($i);
104 $this->elements
->set("exthRecords", $exthElems);
107 $this->elements
->get("exthPadding")->set(str_pad("", $pad+
2, "\0", STR_PAD_RIGHT
));
108 $this->elements
->get("exthHeaderLength")->set(12+
$l+
$pad);
111 $this->elements
->get("recordCount")->set($textRecords);
113 $this->elements
->get("fullNameOffset")->set($this->elements
->offsetToEntry("fullName"));//need to be checked
114 $this->elements
->get("fullNameLength")->set(strlen($settings->get("title")));
115 $this->elements
->get("fullName")->set($settings->get("title"));
116 $this->elements
->get("textLength")->set($textLength);
118 $this->elements
->get("offset194")->set($textRecords+
2+
$images);
119 $this->elements
->get("offset200")->set($textRecords+
4+
$images);
120 $this->elements
->get("offset208")->set($textRecords+
3+
$images);
121 $this->elements
->get("offset232")->set(str_pad("", 8, chr(255), STR_PAD_RIGHT
));
124 public function getByteLength(){
125 return $this->getLength();
128 public function getLength(){
129 return $this->elements
->getByteLength();
132 public function get(){
136 public function set($elements){
137 throw new Exception("Unallowed set");
140 public function serialize() {
141 return $this->elements
->serialize();
144 public function unserialize($data) {
145 $this->elements
->unserialize($data);
148 public function __toString(){
149 $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n";
150 $output .= $this->elements
;