]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #3266 from egilli/export-domain-as-author
authorJérémy Benoist <j0k3r@users.noreply.github.com>
Tue, 11 Jul 2017 07:21:49 +0000 (09:21 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Jul 2017 07:21:49 +0000 (09:21 +0200)
Use the article publisher as author for exported files

src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/CoreBundle/Command/ExportCommand.php
src/Wallabag/CoreBundle/Controller/ExportController.php
src/Wallabag/CoreBundle/Helper/EntriesExport.php

index 8a2061243a98baeff54644ea84d98ff0ffc8e797..9277e1a19f093837efbb34540bc0996b02d32bc0 100644 (file)
@@ -180,6 +180,7 @@ class EntryRestController extends WallabagRestController
         return $this->get('wallabag_core.helper.entries_export')
             ->setEntries($entry)
             ->updateTitle('entry')
+            ->updateAuthor('entry')
             ->exportAs($request->attributes->get('_format'));
     }
 
index 0dacb73406f013b19433325c477b785ae8a41545..c2e4be05c9a87aac64a8cb63b42e9d3ac16b2e15 100644 (file)
@@ -56,6 +56,7 @@ class ExportCommand extends ContainerAwareCommand
             $data = $this->getContainer()->get('wallabag_core.helper.entries_export')
                 ->setEntries($entries)
                 ->updateTitle('All')
+                ->updateAuthor('All')
                 ->exportJsonData();
             file_put_contents($filePath, $data);
         } catch (\InvalidArgumentException $e) {
index 6fad122e1bf88b3241288dad1abe4fcfa06b1ab5..35a2204606005e21a02e66bdc4a8a5d311555770 100644 (file)
@@ -33,6 +33,7 @@ class ExportController extends Controller
             return $this->get('wallabag_core.helper.entries_export')
                 ->setEntries($entry)
                 ->updateTitle('entry')
+                ->updateAuthor('entry')
                 ->exportAs($format);
         } catch (\InvalidArgumentException $e) {
             throw new NotFoundHttpException($e->getMessage());
@@ -76,6 +77,7 @@ class ExportController extends Controller
             return $this->get('wallabag_core.helper.entries_export')
                 ->setEntries($entries)
                 ->updateTitle($method)
+                ->updateAuthor($method)
                 ->exportAs($format);
         } catch (\InvalidArgumentException $e) {
             throw new NotFoundHttpException($e->getMessage());
index cd74cc4f866a8e6e2b2a3d7e5b7fa63fe52008d0..64d8219325d532e3eed2f8d88a7b31286489f26f 100644 (file)
@@ -18,7 +18,7 @@ class EntriesExport
     private $logoPath;
     private $title = '';
     private $entries = [];
-    private $authors = ['wallabag'];
+    private $author = 'wallabag';
     private $language = '';
     private $footerTemplate = '<div style="text-align:center;">
         <p>Produced by wallabag with %EXPORT_METHOD%</p>
@@ -72,6 +72,33 @@ class EntriesExport
         return $this;
     }
 
+    /**
+     * Sets the author for one entry or category.
+     *
+     * The publishers are used, or the domain name if empty.
+     *
+     * @param string $method Method to get articles
+     *
+     * @return EntriesExport
+     */
+    public function updateAuthor($method)
+    {
+        if ('entry' !== $method) {
+            $this->author = $method . ' authors';
+
+            return $this;
+        }
+
+        $this->author = $this->entries[0]->getDomainName();
+
+        $publishedBy = $this->entries[0]->getPublishedBy();
+        if (!empty($publishedBy)) {
+            $this->author = implode(', ', $publishedBy);
+        }
+
+        return $this;
+    }
+
     /**
      * Sets the output format.
      *
@@ -128,9 +155,7 @@ class EntriesExport
         $book->setLanguage($this->language);
         $book->setDescription('Some articles saved on my wallabag');
 
-        foreach ($this->authors as $author) {
-            $book->setAuthor($author, $author);
-        }
+        $book->setAuthor($this->author, $this->author);
 
         // I hope this is a non existant address :)
         $book->setPublisher('wallabag', 'wallabag');
@@ -196,7 +221,7 @@ class EntriesExport
          * Book metadata
          */
         $content->set('title', $this->title);
-        $content->set('author', implode($this->authors));
+        $content->set('author', $this->author);
         $content->set('subject', $this->title);
 
         /*
@@ -247,7 +272,7 @@ class EntriesExport
          * Book metadata
          */
         $pdf->SetCreator(PDF_CREATOR);
-        $pdf->SetAuthor('wallabag');
+        $pdf->SetAuthor($this->author);
         $pdf->SetTitle($this->title);
         $pdf->SetSubject('Articles via wallabag');
         $pdf->SetKeywords('wallabag');