diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-07-11 09:21:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-11 09:21:49 +0200 |
commit | f39152ad6e62f1ea43f501e88a8839526d77ef6c (patch) | |
tree | 5bdf25175149ad32c99d956028cd81c1eed56642 /src | |
parent | c7fcca533d90f2c285b64ce7b2f1186273719fe7 (diff) | |
parent | eeabca8090ebf9a084b6b823ddf7c6493b956d4c (diff) | |
download | wallabag-f39152ad6e62f1ea43f501e88a8839526d77ef6c.tar.gz wallabag-f39152ad6e62f1ea43f501e88a8839526d77ef6c.tar.zst wallabag-f39152ad6e62f1ea43f501e88a8839526d77ef6c.zip |
Merge pull request #3266 from egilli/export-domain-as-author
Use the article publisher as author for exported files
Diffstat (limited to 'src')
4 files changed, 35 insertions, 6 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 8a206124..9277e1a1 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -180,6 +180,7 @@ class EntryRestController extends WallabagRestController | |||
180 | return $this->get('wallabag_core.helper.entries_export') | 180 | return $this->get('wallabag_core.helper.entries_export') |
181 | ->setEntries($entry) | 181 | ->setEntries($entry) |
182 | ->updateTitle('entry') | 182 | ->updateTitle('entry') |
183 | ->updateAuthor('entry') | ||
183 | ->exportAs($request->attributes->get('_format')); | 184 | ->exportAs($request->attributes->get('_format')); |
184 | } | 185 | } |
185 | 186 | ||
diff --git a/src/Wallabag/CoreBundle/Command/ExportCommand.php b/src/Wallabag/CoreBundle/Command/ExportCommand.php index 0dacb734..c2e4be05 100644 --- a/src/Wallabag/CoreBundle/Command/ExportCommand.php +++ b/src/Wallabag/CoreBundle/Command/ExportCommand.php | |||
@@ -56,6 +56,7 @@ class ExportCommand extends ContainerAwareCommand | |||
56 | $data = $this->getContainer()->get('wallabag_core.helper.entries_export') | 56 | $data = $this->getContainer()->get('wallabag_core.helper.entries_export') |
57 | ->setEntries($entries) | 57 | ->setEntries($entries) |
58 | ->updateTitle('All') | 58 | ->updateTitle('All') |
59 | ->updateAuthor('All') | ||
59 | ->exportJsonData(); | 60 | ->exportJsonData(); |
60 | file_put_contents($filePath, $data); | 61 | file_put_contents($filePath, $data); |
61 | } catch (\InvalidArgumentException $e) { | 62 | } catch (\InvalidArgumentException $e) { |
diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index 6fad122e..35a22046 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php | |||
@@ -33,6 +33,7 @@ class ExportController extends Controller | |||
33 | return $this->get('wallabag_core.helper.entries_export') | 33 | return $this->get('wallabag_core.helper.entries_export') |
34 | ->setEntries($entry) | 34 | ->setEntries($entry) |
35 | ->updateTitle('entry') | 35 | ->updateTitle('entry') |
36 | ->updateAuthor('entry') | ||
36 | ->exportAs($format); | 37 | ->exportAs($format); |
37 | } catch (\InvalidArgumentException $e) { | 38 | } catch (\InvalidArgumentException $e) { |
38 | throw new NotFoundHttpException($e->getMessage()); | 39 | throw new NotFoundHttpException($e->getMessage()); |
@@ -76,6 +77,7 @@ class ExportController extends Controller | |||
76 | return $this->get('wallabag_core.helper.entries_export') | 77 | return $this->get('wallabag_core.helper.entries_export') |
77 | ->setEntries($entries) | 78 | ->setEntries($entries) |
78 | ->updateTitle($method) | 79 | ->updateTitle($method) |
80 | ->updateAuthor($method) | ||
79 | ->exportAs($format); | 81 | ->exportAs($format); |
80 | } catch (\InvalidArgumentException $e) { | 82 | } catch (\InvalidArgumentException $e) { |
81 | throw new NotFoundHttpException($e->getMessage()); | 83 | throw new NotFoundHttpException($e->getMessage()); |
diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index cd74cc4f..64d82193 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php | |||
@@ -18,7 +18,7 @@ class EntriesExport | |||
18 | private $logoPath; | 18 | private $logoPath; |
19 | private $title = ''; | 19 | private $title = ''; |
20 | private $entries = []; | 20 | private $entries = []; |
21 | private $authors = ['wallabag']; | 21 | private $author = 'wallabag'; |
22 | private $language = ''; | 22 | private $language = ''; |
23 | private $footerTemplate = '<div style="text-align:center;"> | 23 | private $footerTemplate = '<div style="text-align:center;"> |
24 | <p>Produced by wallabag with %EXPORT_METHOD%</p> | 24 | <p>Produced by wallabag with %EXPORT_METHOD%</p> |
@@ -73,6 +73,33 @@ class EntriesExport | |||
73 | } | 73 | } |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Sets the author for one entry or category. | ||
77 | * | ||
78 | * The publishers are used, or the domain name if empty. | ||
79 | * | ||
80 | * @param string $method Method to get articles | ||
81 | * | ||
82 | * @return EntriesExport | ||
83 | */ | ||
84 | public function updateAuthor($method) | ||
85 | { | ||
86 | if ('entry' !== $method) { | ||
87 | $this->author = $method . ' authors'; | ||
88 | |||
89 | return $this; | ||
90 | } | ||
91 | |||
92 | $this->author = $this->entries[0]->getDomainName(); | ||
93 | |||
94 | $publishedBy = $this->entries[0]->getPublishedBy(); | ||
95 | if (!empty($publishedBy)) { | ||
96 | $this->author = implode(', ', $publishedBy); | ||
97 | } | ||
98 | |||
99 | return $this; | ||
100 | } | ||
101 | |||
102 | /** | ||
76 | * Sets the output format. | 103 | * Sets the output format. |
77 | * | 104 | * |
78 | * @param string $format | 105 | * @param string $format |
@@ -128,9 +155,7 @@ class EntriesExport | |||
128 | $book->setLanguage($this->language); | 155 | $book->setLanguage($this->language); |
129 | $book->setDescription('Some articles saved on my wallabag'); | 156 | $book->setDescription('Some articles saved on my wallabag'); |
130 | 157 | ||
131 | foreach ($this->authors as $author) { | 158 | $book->setAuthor($this->author, $this->author); |
132 | $book->setAuthor($author, $author); | ||
133 | } | ||
134 | 159 | ||
135 | // I hope this is a non existant address :) | 160 | // I hope this is a non existant address :) |
136 | $book->setPublisher('wallabag', 'wallabag'); | 161 | $book->setPublisher('wallabag', 'wallabag'); |
@@ -196,7 +221,7 @@ class EntriesExport | |||
196 | * Book metadata | 221 | * Book metadata |
197 | */ | 222 | */ |
198 | $content->set('title', $this->title); | 223 | $content->set('title', $this->title); |
199 | $content->set('author', implode($this->authors)); | 224 | $content->set('author', $this->author); |
200 | $content->set('subject', $this->title); | 225 | $content->set('subject', $this->title); |
201 | 226 | ||
202 | /* | 227 | /* |
@@ -247,7 +272,7 @@ class EntriesExport | |||
247 | * Book metadata | 272 | * Book metadata |
248 | */ | 273 | */ |
249 | $pdf->SetCreator(PDF_CREATOR); | 274 | $pdf->SetCreator(PDF_CREATOR); |
250 | $pdf->SetAuthor('wallabag'); | 275 | $pdf->SetAuthor($this->author); |
251 | $pdf->SetTitle($this->title); | 276 | $pdf->SetTitle($this->title); |
252 | $pdf->SetSubject('Articles via wallabag'); | 277 | $pdf->SetSubject('Articles via wallabag'); |
253 | $pdf->SetKeywords('wallabag'); | 278 | $pdf->SetKeywords('wallabag'); |