]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/send2kindle/MOBIClass/RecordFactory.php
8bf0c97db04b590072a2dac271d499c150547307
4 * Helper class to help with creating records from a
11 * Settings for the record factory
17 * Create the helper class
18 * @param Settings $settings The Settings to be used for the records
20 public function __construct($settings){
21 $this->settings
= $settings;
25 * Create records from a data string
27 * @return array(Record)
29 public function createRecords($data){
31 $size = $this->settings
->get("recordSize");
32 $compression = $this->settings
->get("compression");
34 $dataEntries = mb_str_split($data, $size);
36 for($i = 0, $len = sizeof($dataEntries); $i < $len; $i++
){
37 $records[$i] = new Record($dataEntries[$i]);
38 $records[$i]->compress($compression);
44 public function createEOFRecord(){
45 return new Record(0xe98e0d0a);
48 public function createFCISRecord($textLength){
50 $r .= $this->asString(20, 4);
51 $r .= $this->asString(16, 4);
52 $r .= $this->asString(1, 4);
53 $r .= $this->asString(0, 4);
54 $r .= $this->asString($textLength, 4);
55 $r .= $this->asString(0, 4);
56 $r .= $this->asString(32, 4);
57 $r .= $this->asString(8, 4);
58 $r .= $this->asString(1, 2);
59 $r .= $this->asString(1, 2);
60 $r .= $this->asString(0, 4);
61 return new Record($r);
64 public function createFLISRecord(){
66 $this->elements
= new FileElement(array(
67 "offsetL0"=>new FileString("FLIS", 4), //FLIS
68 "offsetL4"=>new FileInt(0x08),
69 "offsetL8"=>new FileShort(0x41),
70 "offsetL10"=>new FileTri(),
71 "offsetL16"=>new FileInt(0xFFFFFFFF),
72 "offsetL20"=>new FileShort(0x01),
73 "offsetL22"=>new FileShort(0x03),
74 "offsetL24"=>new FileInt(0x03),
75 "offsetL28"=>new FileInt(0x01),
76 "offsetL32"=>new FileInt(0xFFFFFFFF)
80 $r .= $this->asString(8, 4);
81 $r .= $this->asString(65, 2);
82 $r .= $this->asString(0, 2);
83 $r .= $this->asString(0, 4);
84 $r .= $this->asString(-1, 4);
85 $r .= $this->asString(1, 2);
86 $r .= $this->asString(3, 2);
87 $r .= $this->asString(3, 4);
88 $r .= $this->asString(1, 4);
89 $r .= $this->asString(-1, 4);
90 return new Record($r);*/
93 private function asString($int, $size){
95 for($i = 0; $i < $size; $i++
){
96 if($i > 0) $out = " ".$out;
97 $byte = dechex($int & 0xFF);
98 if(strlen($byte) == 1) $byte = "0".$byte;
105 public function __toString() {
106 $out = "Record Factory: {\n";
107 $out .= "\tRecord Size: ".$this->settings
->get("recordSize")."\n";
108 $out .= "\tCompression: ".$this->settings
->get("compression")."\n";
113 function mb_str_split($string, $split_length = 1){
114 mb_internal_encoding('UTF-8');
115 mb_regex_encoding('UTF-8');
117 $split_length = ($split_length <= 0) ? 1 : $split_length;
119 $mb_strlen = mb_strlen($string, 'utf-8');
123 for($i = 0; $i < $mb_strlen; $i +
= $split_length){
124 $array[] = mb_substr($string, $i, $split_length);