aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/WallabagEBooks.class.php
diff options
context:
space:
mode:
authortcit <tcit@tcit.fr>2014-07-25 01:33:31 +0200
committertcit <tcit@tcit.fr>2014-07-25 01:33:31 +0200
commitdc59f164a94ce2ab9e3165aa0090acff8a352493 (patch)
tree6971192e20df1fa6737fad50ef643e4b2bd5957c /inc/poche/WallabagEBooks.class.php
parentdeab6280d3cbe3f8d001ff5214d36399653e3027 (diff)
downloadwallabag-dc59f164a94ce2ab9e3165aa0090acff8a352493.tar.gz
wallabag-dc59f164a94ce2ab9e3165aa0090acff8a352493.tar.zst
wallabag-dc59f164a94ce2ab9e3165aa0090acff8a352493.zip
send2kindle
Diffstat (limited to 'inc/poche/WallabagEBooks.class.php')
-rw-r--r--inc/poche/WallabagEBooks.class.php59
1 files changed, 55 insertions, 4 deletions
diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php
index 2b18b718..a12befa8 100644
--- a/inc/poche/WallabagEBooks.class.php
+++ b/inc/poche/WallabagEBooks.class.php
@@ -151,19 +151,21 @@ class WallabagMobi extends WallabagEBooks
151 * @author Sander Kromwijk 151 * @author Sander Kromwijk
152 */ 152 */
153 153
154 public function produceMobi($send = FALSE) 154 private $_kindle_email;
155
156 public function produceMobi($sendByMail = FALSE)
155 { 157 {
156 158
157 $mobi = new MOBI(); 159 $mobi = new MOBI();
158
159 $content = new MOBIFile(); 160 $content = new MOBIFile();
161
162 $messages = new Messages(); // for later
160 163
161 $content->set("title", $this->bookTitle); 164 $content->set("title", $this->bookTitle);
162 $content->set("author", "wallabag"); 165 $content->set("author", "wallabag");
163 $content->set("subject", $this->bookTitle); 166 $content->set("subject", $this->bookTitle);
164 167
165 # introduction 168 # introduction
166 //$content->appendChapterTitle("Cover");
167 $content->appendParagraph('<div style="text-align:center;" ><p>' . _('Produced by wallabag with PHPMobi') . '</p><p>'. _('Please open <a href="https://github.com/wallabag/wallabag/issues" >an issue</a> if you have trouble with the display of this E-Book on your device.') . '</p></div>'); 169 $content->appendParagraph('<div style="text-align:center;" ><p>' . _('Produced by wallabag with PHPMobi') . '</p><p>'. _('Please open <a href="https://github.com/wallabag/wallabag/issues" >an issue</a> if you have trouble with the display of this E-Book on your device.') . '</p></div>');
168 $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); 170 $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png"));
169 $content->appendPageBreak(); 171 $content->appendPageBreak();
@@ -175,7 +177,56 @@ class WallabagMobi extends WallabagEBooks
175 } 177 }
176 $mobi->setContentProvider($content); 178 $mobi->setContentProvider($content);
177 179
178 $mobi->download($this->bookFileName.".mobi"); 180 if (!$sendByMail) {
181 // we offer file to download
182 $mobi->download($this->bookFileName.'.mobi');
183 }
184 else {
185 // we send file to kindle
186
187 $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory)
188 $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.mobi'));
189
190 $file = 'cache/' . $mobiExportName;
191 $mobi->save($file);
192
193 $file_size = filesize($file);
194 $filename = basename($file);
195 $handle = fopen($file, "r");
196 $content = fread($handle, $file_size);
197 fclose($handle);
198 $content = chunk_split(base64_encode($content));
199
200 $uid = md5(uniqid(time()));
201
202 //generate header for mail
203 $header = "From: wallabag <". $this->wallabag->user->email .">\r\n";
204 $header .= "MIME-Version: 1.0\r\n";
205 $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
206 $header .= "This is a multi-part message in MIME format.\r\n";
207 $header .= "--".$uid."\r\n";
208 $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
209 $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
210 $header .= "send via wallabag\r\n\r\n";
211 $header .= "--".$uid."\r\n";
212 $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n";
213 $header .= "Content-Transfer-Encoding: base64\r\n";
214 $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
215 $header .= $content."\r\n\r\n";
216 $header .= "--".$uid."--";
217
218 # trying to get the kindle email adress
219 if ($this->wallabag->user->getConfigValue('kindleemail'))
220 {
221 #do a try...exeption here
222 mail( $this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header );
223 $messages->add('s', _('The email has been sent to your kindle !'));
224 }
225 else
226 {
227 $messages->add('e', _('You didn\'t set your kindle\'s email adress !'));
228 }
229 }
179 } 230 }
180} 231}
181 232