]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/MOBIClass/RecordFactory.php
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 $r .= $this->asString(8, 4);
67 $r .= $this->asString(65, 2);
68 $r .= $this->asString(0, 2);
69 $r .= $this->asString(0, 4);
70 $r .= $this->asString(-1, 4);
71 $r .= $this->asString(1, 2);
72 $r .= $this->asString(3, 2);
73 $r .= $this->asString(3, 4);
74 $r .= $this->asString(1, 4);
75 $r .= $this->asString(-1, 4);
76 return new Record($r);
79 private function asString($int, $size){
81 for($i = 0; $i < $size; $i++
){
82 if($i > 0) $out = " ".$out;
83 $byte = dechex($int & 0xFF);
84 if(strlen($byte) == 1) $byte = "0".$byte;
91 public function __toString() {
92 $out = "Record Factory: {\n";
93 $out .= "\tRecord Size: ".$this->settings
->get("recordSize")."\n";
94 $out .= "\tCompression: ".$this->settings
->get("compression")."\n";
99 function mb_str_split($string, $split_length = 1){
100 mb_internal_encoding('UTF-8');
101 mb_regex_encoding('UTF-8');
103 $split_length = ($split_length <= 0) ? 1 : $split_length;
105 $mb_strlen = mb_strlen($string, 'utf-8');
109 for($i = 0; $i < $mb_strlen; $i +
= $split_length){
110 $array[] = mb_substr($string, $i, $split_length);