aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/MOBIClass/MOBI.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2014-12-14 00:16:22 +0100
committerThomas Citharel <tcit@tcit.fr>2014-12-14 00:16:22 +0100
commitdc69d3e8d895c87f9d26c2d1309e40d6090d4c8d (patch)
tree3cc3bd960df403a6e0645afcd9e4f5bbb68bfc0e /inc/3rdparty/libraries/MOBIClass/MOBI.php
parent9c55ed0923273da886497cb62302a79622e34a74 (diff)
parent9f86454b48dec3c9ecfee8da224112eef0f61441 (diff)
downloadwallabag-dc69d3e8d895c87f9d26c2d1309e40d6090d4c8d.tar.gz
wallabag-dc69d3e8d895c87f9d26c2d1309e40d6090d4c8d.tar.zst
wallabag-dc69d3e8d895c87f9d26c2d1309e40d6090d4c8d.zip
merge epub with all the dev evolutions
Diffstat (limited to 'inc/3rdparty/libraries/MOBIClass/MOBI.php')
-rw-r--r--inc/3rdparty/libraries/MOBIClass/MOBI.php192
1 files changed, 192 insertions, 0 deletions
diff --git a/inc/3rdparty/libraries/MOBIClass/MOBI.php b/inc/3rdparty/libraries/MOBIClass/MOBI.php
new file mode 100644
index 00000000..17e718c1
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/MOBI.php
@@ -0,0 +1,192 @@
1<?php
2require_once(dirname(__FILE__)."/readability/Readability.php");
3require_once(dirname(__FILE__).'/CharacterEntities.php');
4require_once(dirname(__FILE__).'/constants.php');
5require_once(dirname(__FILE__).'/ContentProvider.php');
6require_once(dirname(__FILE__).'/MultipleFileHandler.php');
7require_once(dirname(__FILE__)."/downloaders/FanFictionNet.php");
8require_once(dirname(__FILE__).'/EXTHHelper.php');
9require_once(dirname(__FILE__).'/FileObject.php');
10require_once(dirname(__FILE__).'/FileByte.php');
11require_once(dirname(__FILE__).'/FileDate.php');
12require_once(dirname(__FILE__).'/FileElement.php');
13require_once(dirname(__FILE__).'/FileInt.php');
14require_once(dirname(__FILE__).'/FileRecord.php');
15require_once(dirname(__FILE__).'/FileShort.php');
16require_once(dirname(__FILE__).'/FileString.php');
17require_once(dirname(__FILE__).'/FileTri.php');
18require_once(dirname(__FILE__).'/Http.php');
19require_once(dirname(__FILE__).'/http_build_url.php');
20require_once(dirname(__FILE__).'/ImageHandler.php');
21require_once(dirname(__FILE__).'/MOBIFile.php');
22require_once(dirname(__FILE__).'/OnlineArticle.php');
23require_once(dirname(__FILE__).'/PalmRecord.php');
24require_once(dirname(__FILE__).'/Prc.php');
25require_once(dirname(__FILE__).'/PreprocessedArticle.php');
26require_once(dirname(__FILE__).'/RecognizeURL.php');
27require_once(dirname(__FILE__).'/Record.php');
28require_once(dirname(__FILE__).'/RecordFactory.php');
29require_once(dirname(__FILE__).'/Settings.php');
30
31/**
32 * Description of MOBI.
33 *
34 * Usage:
35 * include("MOBIClass/MOBI.php");
36 *
37 * $mobi = new MOBI();
38 *
39 * //Then use one of the following ways to prepare information (it should be in the form of valid html)
40 * $mobi->setInternetSource($url); //Load URL, the result will be cleaned using a Readability port
41 * $mobi->setFileSource($file); //Load a local file without any extra changes
42 * $mobi->setData($data); //Load data
43 *
44 * //If you want, you can set some optional settings (see Settings.php for all recognized settings)
45 * $options = array(
46 * "title"=>"Insert title here",
47 * "author"=>"Author"
48 * );
49 * $mobi->setOptions($options);
50 *
51 * //Then there are two ways to output it:
52 * $mobi->save($file); //Save the file locally
53 * $mobi->download($name); //Let the client download the file, make sure the page
54 * //that calls it doesn't output anything, otherwise it might
55 * //conflict with the download. $name contains the file name,
56 * //usually something like "title.mobi" (where the title should
57 * //be cleaned so as not to contain illegal characters).
58 *
59 *
60 * @author Sander Kromwijk
61 */
62class MOBI {
63 private $source = false;
64 private $images = array();
65 private $optional = array();
66 private $imgCounter = 0;
67 private $debug = false;
68 private $prc = false;
69
70 public function __construct(){
71
72 }
73
74 public function getTitle(){
75 if(isset($this->optional["title"])){
76 return $this->optional["title"];
77 }
78 return false;
79 }
80
81 /**
82 * Set a content provider as source
83 * @param ContentProvider $content Content Provider to use
84 */
85 public function setContentProvider($content){
86 $this->setOptions($content->getMetaData());
87 $this->setImages($content->getImages());
88 $this->setData($content->getTextData());
89 }
90
91 /**
92 * Set a local file as source
93 * @param string $file Path to the file
94 */
95 public function setFileSource($file){
96 $this->setData(file_get_contents($file));
97 }
98
99 /**
100 * Set the data to use
101 * @param string $data Data to put in the file
102 */
103 public function setData($data){
104 //$data = utf8_encode($data);
105 $data = CharacterEntities::convert($data);
106 //$data = utf8_decode($data);
107 //$this->source = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $data);
108 $this->source = $data;
109 $this->prc = false;
110 }
111
112 /**
113 * Set the images to use
114 * @param array $data Data to put in the file
115 */
116 public function setImages($data){
117 $this->images = $data;
118 $this->prc = false;
119 }
120
121 /**
122 * Set options, usually for things like titles, authors, etc...
123 * @param array $options Options to set
124 */
125 public function setOptions($options){
126 $this->optional = $options;
127 $this->prc = false;
128 }
129
130 /**
131 * Prepare the prc file
132 * @return Prc The file that can be used to be saved/downloaded
133 */
134 private function preparePRC(){
135 if($this->source === false){
136 throw new Exception("No data set");
137 }
138 if($this->prc !== false) return $this->prc;
139
140 $data = $this->source;
141 $len = strlen($data);
142
143 $settings = new Settings($this->optional);
144 $rec = new RecordFactory($settings);
145 $dataRecords = $rec->createRecords($data);
146 $nRecords = sizeof($dataRecords);
147 $mobiHeader = new PalmRecord($settings, $dataRecords, $nRecords, $len, sizeof($this->images));
148 array_unshift($dataRecords, $mobiHeader);
149 $dataRecords = array_merge($dataRecords, $this->images);
150 $dataRecords[] = $rec->createFLISRecord();
151 $dataRecords[] = $rec->createFCISRecord($len);
152 $dataRecords[] = $rec->createEOFRecord();
153 $this->prc = new Prc($settings, $dataRecords);
154 return $this->prc;
155 }
156
157 /**
158 * Save the file locally
159 * @param string $filename Path to save the file
160 */
161 public function save($filename){
162 $prc = $this->preparePRC();
163 $prc->save($filename);
164 }
165
166 /**
167 * Let the client download the file. Warning! No data should be
168 * outputted before or after.
169 * @param string $name Name used for download, usually "title.mobi"
170 */
171 public function download($name){
172 $prc = $this->preparePRC();
173 $data = $prc->serialize();
174 $length = strlen($data);
175
176 if($this->debug) return; //In debug mode, don't start the download
177
178 header("Content-Type: application/x-mobipocket-ebook");
179 header("Content-Disposition: attachment; filename=\"".$name."\"");
180 header("Content-Transfer-Encoding: binary");
181 header("Accept-Ranges: bytes");
182 header("Cache-control: private");
183 header('Pragma: private');
184 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
185 header("Content-Length: ".$length);
186
187 echo $data;
188 //Finished!
189 }
190
191}
192?> \ No newline at end of file