diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-13 09:43:14 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-13 09:43:14 +0200 |
commit | f2e5fdc3666a2a6525b4202ab48df05efeebaf5c (patch) | |
tree | f559474e248a33c472fe0b260641866be5c0def3 /src/Wallabag/CoreBundle/Helper/EntriesExport.php | |
parent | a417b869237763ee115982d6367a82aa6174d74e (diff) | |
parent | 86732aa01cf0ad0fb5279f38ce75a9bedbbb66e1 (diff) | |
download | wallabag-f2e5fdc3666a2a6525b4202ab48df05efeebaf5c.tar.gz wallabag-f2e5fdc3666a2a6525b4202ab48df05efeebaf5c.tar.zst wallabag-f2e5fdc3666a2a6525b4202ab48df05efeebaf5c.zip |
Merge pull request #1916 from wallabag/cleanup
Convert array + phpDoc
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/EntriesExport.php | 75 |
1 files changed, 52 insertions, 23 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index d0680c3f..0cf835b4 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php | |||
@@ -18,10 +18,10 @@ class EntriesExport | |||
18 | private $wallabagUrl; | 18 | private $wallabagUrl; |
19 | private $logoPath; | 19 | private $logoPath; |
20 | private $title = ''; | 20 | private $title = ''; |
21 | private $entries = array(); | 21 | private $entries = []; |
22 | private $authors = array('wallabag'); | 22 | private $authors = ['wallabag']; |
23 | private $language = ''; | 23 | private $language = ''; |
24 | private $tags = array(); | 24 | private $tags = []; |
25 | private $footerTemplate = '<div style="text-align:center;"> | 25 | private $footerTemplate = '<div style="text-align:center;"> |
26 | <p>Produced by wallabag with %EXPORT_METHOD%</p> | 26 | <p>Produced by wallabag with %EXPORT_METHOD%</p> |
27 | <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> | 27 | <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> |
@@ -41,12 +41,14 @@ class EntriesExport | |||
41 | * Define entries. | 41 | * Define entries. |
42 | * | 42 | * |
43 | * @param array|Entry $entries An array of entries or one entry | 43 | * @param array|Entry $entries An array of entries or one entry |
44 | * | ||
45 | * @return EntriesExport | ||
44 | */ | 46 | */ |
45 | public function setEntries($entries) | 47 | public function setEntries($entries) |
46 | { | 48 | { |
47 | if (!is_array($entries)) { | 49 | if (!is_array($entries)) { |
48 | $this->language = $entries->getLanguage(); | 50 | $this->language = $entries->getLanguage(); |
49 | $entries = array($entries); | 51 | $entries = [$entries]; |
50 | } | 52 | } |
51 | 53 | ||
52 | $this->entries = $entries; | 54 | $this->entries = $entries; |
@@ -62,6 +64,8 @@ class EntriesExport | |||
62 | * Sets the category of which we want to get articles, or just one entry. | 64 | * Sets the category of which we want to get articles, or just one entry. |
63 | * | 65 | * |
64 | * @param string $method Method to get articles | 66 | * @param string $method Method to get articles |
67 | * | ||
68 | * @return EntriesExport | ||
65 | */ | 69 | */ |
66 | public function updateTitle($method) | 70 | public function updateTitle($method) |
67 | { | 71 | { |
@@ -78,6 +82,8 @@ class EntriesExport | |||
78 | * Sets the output format. | 82 | * Sets the output format. |
79 | * | 83 | * |
80 | * @param string $format | 84 | * @param string $format |
85 | * | ||
86 | * @return Response | ||
81 | */ | 87 | */ |
82 | public function exportAs($format) | 88 | public function exportAs($format) |
83 | { | 89 | { |
@@ -91,6 +97,8 @@ class EntriesExport | |||
91 | 97 | ||
92 | /** | 98 | /** |
93 | * Use PHPePub to dump a .epub file. | 99 | * Use PHPePub to dump a .epub file. |
100 | * | ||
101 | * @return Response | ||
94 | */ | 102 | */ |
95 | private function produceEpub() | 103 | private function produceEpub() |
96 | { | 104 | { |
@@ -162,17 +170,19 @@ class EntriesExport | |||
162 | return Response::create( | 170 | return Response::create( |
163 | $book->getBook(), | 171 | $book->getBook(), |
164 | 200, | 172 | 200, |
165 | array( | 173 | [ |
166 | 'Content-Description' => 'File Transfer', | 174 | 'Content-Description' => 'File Transfer', |
167 | 'Content-type' => 'application/epub+zip', | 175 | 'Content-type' => 'application/epub+zip', |
168 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.epub"', | 176 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.epub"', |
169 | 'Content-Transfer-Encoding' => 'binary', | 177 | 'Content-Transfer-Encoding' => 'binary', |
170 | ) | 178 | ] |
171 | ); | 179 | ); |
172 | } | 180 | } |
173 | 181 | ||
174 | /** | 182 | /** |
175 | * Use PHPMobi to dump a .mobi file. | 183 | * Use PHPMobi to dump a .mobi file. |
184 | * | ||
185 | * @return Response | ||
176 | */ | 186 | */ |
177 | private function produceMobi() | 187 | private function produceMobi() |
178 | { | 188 | { |
@@ -211,18 +221,20 @@ class EntriesExport | |||
211 | return Response::create( | 221 | return Response::create( |
212 | $mobi->toString(), | 222 | $mobi->toString(), |
213 | 200, | 223 | 200, |
214 | array( | 224 | [ |
215 | 'Accept-Ranges' => 'bytes', | 225 | 'Accept-Ranges' => 'bytes', |
216 | 'Content-Description' => 'File Transfer', | 226 | 'Content-Description' => 'File Transfer', |
217 | 'Content-type' => 'application/x-mobipocket-ebook', | 227 | 'Content-type' => 'application/x-mobipocket-ebook', |
218 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.mobi"', | 228 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.mobi"', |
219 | 'Content-Transfer-Encoding' => 'binary', | 229 | 'Content-Transfer-Encoding' => 'binary', |
220 | ) | 230 | ] |
221 | ); | 231 | ); |
222 | } | 232 | } |
223 | 233 | ||
224 | /** | 234 | /** |
225 | * Use TCPDF to dump a .pdf file. | 235 | * Use TCPDF to dump a .pdf file. |
236 | * | ||
237 | * @return Response | ||
226 | */ | 238 | */ |
227 | private function producePdf() | 239 | private function producePdf() |
228 | { | 240 | { |
@@ -266,17 +278,19 @@ class EntriesExport | |||
266 | return Response::create( | 278 | return Response::create( |
267 | $pdf->Output('', 'S'), | 279 | $pdf->Output('', 'S'), |
268 | 200, | 280 | 200, |
269 | array( | 281 | [ |
270 | 'Content-Description' => 'File Transfer', | 282 | 'Content-Description' => 'File Transfer', |
271 | 'Content-type' => 'application/pdf', | 283 | 'Content-type' => 'application/pdf', |
272 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.pdf"', | 284 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.pdf"', |
273 | 'Content-Transfer-Encoding' => 'binary', | 285 | 'Content-Transfer-Encoding' => 'binary', |
274 | ) | 286 | ] |
275 | ); | 287 | ); |
276 | } | 288 | } |
277 | 289 | ||
278 | /** | 290 | /** |
279 | * Inspired from CsvFileDumper. | 291 | * Inspired from CsvFileDumper. |
292 | * | ||
293 | * @return Response | ||
280 | */ | 294 | */ |
281 | private function produceCsv() | 295 | private function produceCsv() |
282 | { | 296 | { |
@@ -284,20 +298,20 @@ class EntriesExport | |||
284 | $enclosure = '"'; | 298 | $enclosure = '"'; |
285 | $handle = fopen('php://memory', 'rb+'); | 299 | $handle = fopen('php://memory', 'rb+'); |
286 | 300 | ||
287 | fputcsv($handle, array('Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language'), $delimiter, $enclosure); | 301 | fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language'], $delimiter, $enclosure); |
288 | 302 | ||
289 | foreach ($this->entries as $entry) { | 303 | foreach ($this->entries as $entry) { |
290 | fputcsv( | 304 | fputcsv( |
291 | $handle, | 305 | $handle, |
292 | array( | 306 | [ |
293 | $entry->getTitle(), | 307 | $entry->getTitle(), |
294 | $entry->getURL(), | 308 | $entry->getURL(), |
295 | // remove new line to avoid crazy results | 309 | // remove new line to avoid crazy results |
296 | str_replace(array("\r\n", "\r", "\n"), '', $entry->getContent()), | 310 | str_replace(["\r\n", "\r", "\n"], '', $entry->getContent()), |
297 | implode(', ', $entry->getTags()->toArray()), | 311 | implode(', ', $entry->getTags()->toArray()), |
298 | $entry->getMimetype(), | 312 | $entry->getMimetype(), |
299 | $entry->getLanguage(), | 313 | $entry->getLanguage(), |
300 | ), | 314 | ], |
301 | $delimiter, | 315 | $delimiter, |
302 | $enclosure | 316 | $enclosure |
303 | ); | 317 | ); |
@@ -310,40 +324,55 @@ class EntriesExport | |||
310 | return Response::create( | 324 | return Response::create( |
311 | $output, | 325 | $output, |
312 | 200, | 326 | 200, |
313 | array( | 327 | [ |
314 | 'Content-type' => 'application/csv', | 328 | 'Content-type' => 'application/csv', |
315 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.csv"', | 329 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.csv"', |
316 | 'Content-Transfer-Encoding' => 'UTF-8', | 330 | 'Content-Transfer-Encoding' => 'UTF-8', |
317 | ) | 331 | ] |
318 | ); | 332 | ); |
319 | } | 333 | } |
320 | 334 | ||
335 | /** | ||
336 | * Dump a JSON file. | ||
337 | * | ||
338 | * @return Response | ||
339 | */ | ||
321 | private function produceJson() | 340 | private function produceJson() |
322 | { | 341 | { |
323 | return Response::create( | 342 | return Response::create( |
324 | $this->prepareSerializingContent('json'), | 343 | $this->prepareSerializingContent('json'), |
325 | 200, | 344 | 200, |
326 | array( | 345 | [ |
327 | 'Content-type' => 'application/json', | 346 | 'Content-type' => 'application/json', |
328 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.json"', | 347 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.json"', |
329 | 'Content-Transfer-Encoding' => 'UTF-8', | 348 | 'Content-Transfer-Encoding' => 'UTF-8', |
330 | ) | 349 | ] |
331 | ); | 350 | ); |
332 | } | 351 | } |
333 | 352 | ||
353 | /** | ||
354 | * Dump a XML file. | ||
355 | * | ||
356 | * @return Response | ||
357 | */ | ||
334 | private function produceXml() | 358 | private function produceXml() |
335 | { | 359 | { |
336 | return Response::create( | 360 | return Response::create( |
337 | $this->prepareSerializingContent('xml'), | 361 | $this->prepareSerializingContent('xml'), |
338 | 200, | 362 | 200, |
339 | array( | 363 | [ |
340 | 'Content-type' => 'application/xml', | 364 | 'Content-type' => 'application/xml', |
341 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.xml"', | 365 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.xml"', |
342 | 'Content-Transfer-Encoding' => 'UTF-8', | 366 | 'Content-Transfer-Encoding' => 'UTF-8', |
343 | ) | 367 | ] |
344 | ); | 368 | ); |
345 | } | 369 | } |
346 | 370 | ||
371 | /** | ||
372 | * Dump a TXT file. | ||
373 | * | ||
374 | * @return Response | ||
375 | */ | ||
347 | private function produceTxt() | 376 | private function produceTxt() |
348 | { | 377 | { |
349 | $content = ''; | 378 | $content = ''; |
@@ -356,11 +385,11 @@ class EntriesExport | |||
356 | return Response::create( | 385 | return Response::create( |
357 | $content, | 386 | $content, |
358 | 200, | 387 | 200, |
359 | array( | 388 | [ |
360 | 'Content-type' => 'text/plain', | 389 | 'Content-type' => 'text/plain', |
361 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.txt"', | 390 | 'Content-Disposition' => 'attachment; filename="'.$this->title.'.txt"', |
362 | 'Content-Transfer-Encoding' => 'UTF-8', | 391 | 'Content-Transfer-Encoding' => 'UTF-8', |
363 | ) | 392 | ] |
364 | ); | 393 | ); |
365 | } | 394 | } |
366 | 395 | ||
@@ -378,7 +407,7 @@ class EntriesExport | |||
378 | return $serializer->serialize( | 407 | return $serializer->serialize( |
379 | $this->entries, | 408 | $this->entries, |
380 | $format, | 409 | $format, |
381 | SerializationContext::create()->setGroups(array('entries_for_user')) | 410 | SerializationContext::create()->setGroups(['entries_for_user']) |
382 | ); | 411 | ); |
383 | } | 412 | } |
384 | 413 | ||