X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FHelper%2FEntriesExport.php;h=6082f6b9c47f444a6c5abad61dd167032d8f815b;hb=bf22266a6230be105ec9a91eccf00e489108405c;hp=bd11b4b8d2fb655f177a5a6cd65a1e2889b1fe8c;hpb=385e651684b98762241107d6fd0310fc42b44965;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index bd11b4b8..6082f6b9 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -45,7 +45,7 @@ class EntriesExport */ public function setEntries($entries) { - if (!is_array($entries)) { + if (!\is_array($entries)) { $this->language = $entries->getLanguage(); $entries = [$entries]; } @@ -64,7 +64,7 @@ class EntriesExport */ public function updateTitle($method) { - $this->title = $method.' articles'; + $this->title = $method . ' articles'; if ('entry' === $method) { $this->title = $this->entries[0]->getTitle(); @@ -85,7 +85,7 @@ class EntriesExport public function updateAuthor($method) { if ('entry' !== $method) { - $this->author = $method.' authors'; + $this->author = $method . ' authors'; return $this; } @@ -109,7 +109,7 @@ class EntriesExport */ public function exportAs($format) { - $functionName = 'produce'.ucfirst($format); + $functionName = 'produce' . ucfirst($format); if (method_exists($this, $functionName)) { return $this->$functionName(); } @@ -134,12 +134,12 @@ class EntriesExport */ $content_start = "\n" - ."\n" - .'' - ."\n" - ."wallabag articles book\n" - ."\n" - ."\n"; + . "\n" + . '' + . "\n" + . "wallabag articles book\n" + . "\n" + . "\n"; $bookEnd = "\n\n"; @@ -150,8 +150,6 @@ class EntriesExport */ $book->setTitle($this->title); - // Could also be the ISBN number, prefered for published books, or a UUID. - $book->setIdentifier($this->title, EPub::IDENTIFIER_URI); // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc. $book->setLanguage($this->language); $book->setDescription('Some articles saved on my wallabag'); @@ -174,6 +172,8 @@ class EntriesExport $book->setCoverImage('Cover.png', file_get_contents($this->logoPath), 'image/png'); } + $entryIds = []; + /* * Adding actual entries */ @@ -188,12 +188,18 @@ class EntriesExport // in filenames, we limit to A-z/0-9 $filename = preg_replace('/[^A-Za-z0-9\-]/', '', $entry->getTitle()); - $titlepage = $content_start.'

'.$entry->getTitle().'

'.$this->getExportInformation('PHPePub').$bookEnd; + $titlepage = $content_start . '

' . $entry->getTitle() . '

' . $this->getExportInformation('PHPePub') . $bookEnd; $book->addChapter('Title', 'Title.html', $titlepage, true, EPub::EXTERNAL_REF_ADD); - $chapter = $content_start.$entry->getContent().$bookEnd; - $book->addChapter($entry->getTitle(), htmlspecialchars($filename).'.html', $chapter, true, EPub::EXTERNAL_REF_ADD); + $chapter = $content_start . $entry->getContent() . $bookEnd; + $book->addChapter($entry->getTitle(), htmlspecialchars($filename) . '.html', $chapter, true, EPub::EXTERNAL_REF_ADD); + + $entryIds[] = $entry->getId(); } + // Could also be the ISBN number, prefered for published books, or a UUID. + $hash = sha1(sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds))); + $book->setIdentifier(sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI); + $book->buildTOC(); return Response::create( @@ -202,7 +208,7 @@ class EntriesExport [ 'Content-Description' => 'File Transfer', 'Content-type' => 'application/epub+zip', - 'Content-Disposition' => 'attachment; filename="'.$this->title.'.epub"', + 'Content-Disposition' => 'attachment; filename="' . $this->title . '.epub"', 'Content-Transfer-Encoding' => 'binary', ] ); @@ -254,7 +260,7 @@ class EntriesExport 'Accept-Ranges' => 'bytes', 'Content-Description' => 'File Transfer', 'Content-type' => 'application/x-mobipocket-ebook', - 'Content-Disposition' => 'attachment; filename="'.$this->title.'.mobi"', + 'Content-Disposition' => 'attachment; filename="' . $this->title . '.mobi"', 'Content-Transfer-Encoding' => 'binary', ] ); @@ -282,7 +288,7 @@ class EntriesExport * Front page */ $pdf->AddPage(); - $intro = '

'.$this->title.'

'.$this->getExportInformation('tcpdf'); + $intro = '

' . $this->title . '

' . $this->getExportInformation('tcpdf'); $pdf->writeHTMLCell(0, 0, '', '', $intro, 0, 1, 0, true, '', true); @@ -295,7 +301,7 @@ class EntriesExport } $pdf->AddPage(); - $html = '

'.$entry->getTitle().'

'; + $html = '

' . $entry->getTitle() . '

'; $html .= $entry->getContent(); $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); @@ -310,7 +316,7 @@ class EntriesExport [ 'Content-Description' => 'File Transfer', 'Content-type' => 'application/pdf', - 'Content-Disposition' => 'attachment; filename="'.$this->title.'.pdf"', + 'Content-Disposition' => 'attachment; filename="' . $this->title . '.pdf"', 'Content-Transfer-Encoding' => 'binary', ] ); @@ -325,7 +331,7 @@ class EntriesExport { $delimiter = ';'; $enclosure = '"'; - $handle = fopen('php://memory', 'rb+'); + $handle = fopen('php://memory', 'b+r'); fputcsv($handle, ['Title', 'URL', 'Content', 'Tags', 'MIME Type', 'Language', 'Creation date'], $delimiter, $enclosure); @@ -356,7 +362,7 @@ class EntriesExport 200, [ 'Content-type' => 'application/csv', - 'Content-Disposition' => 'attachment; filename="'.$this->title.'.csv"', + 'Content-Disposition' => 'attachment; filename="' . $this->title . '.csv"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -374,7 +380,7 @@ class EntriesExport 200, [ 'Content-type' => 'application/json', - 'Content-Disposition' => 'attachment; filename="'.$this->title.'.json"', + 'Content-Disposition' => 'attachment; filename="' . $this->title . '.json"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -392,7 +398,7 @@ class EntriesExport 200, [ 'Content-type' => 'application/xml', - 'Content-Disposition' => 'attachment; filename="'.$this->title.'.xml"', + 'Content-Disposition' => 'attachment; filename="' . $this->title . '.xml"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -408,7 +414,7 @@ class EntriesExport $content = ''; $bar = str_repeat('=', 100); foreach ($this->entries as $entry) { - $content .= "\n\n".$bar."\n\n".$entry->getTitle()."\n\n".$bar."\n\n"; + $content .= "\n\n" . $bar . "\n\n" . $entry->getTitle() . "\n\n" . $bar . "\n\n"; $html = new Html2Text($entry->getContent(), ['do_links' => 'none', 'width' => 100]); $content .= $html->getText(); } @@ -418,7 +424,7 @@ class EntriesExport 200, [ 'Content-type' => 'text/plain', - 'Content-Disposition' => 'attachment; filename="'.$this->title.'.txt"', + 'Content-Disposition' => 'attachment; filename="' . $this->title . '.txt"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -456,7 +462,7 @@ class EntriesExport ]); if ('tcpdf' === $type) { - return str_replace('%IMAGE%', '', $info); + return str_replace('%IMAGE%', '', $info); } return str_replace('%IMAGE%', '', $info);