aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-07-03 13:56:39 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-07-03 13:56:39 +0200
commitc18a2476b601bc6b9893462d9be680c2e13c89e8 (patch)
treee1e2d162251b7069236ce66bc57694695d5571bb /src
parentd0ec2ddd2354e39badd947c2214f47193784b1c7 (diff)
downloadwallabag-c18a2476b601bc6b9893462d9be680c2e13c89e8.tar.gz
wallabag-c18a2476b601bc6b9893462d9be680c2e13c89e8.tar.zst
wallabag-c18a2476b601bc6b9893462d9be680c2e13c89e8.zip
CS
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php12
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php140
2 files changed, 76 insertions, 76 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index a2e913af..8a206124 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -354,11 +354,11 @@ class EntryRestController extends WallabagRestController
354 ]); 354 ]);
355 } 355 }
356 356
357 if (!is_null($data['isArchived'])) { 357 if (null !== $data['isArchived']) {
358 $entry->setArchived((bool) $data['isArchived']); 358 $entry->setArchived((bool) $data['isArchived']);
359 } 359 }
360 360
361 if (!is_null($data['isStarred'])) { 361 if (null !== $data['isStarred']) {
362 $entry->setStarred((bool) $data['isStarred']); 362 $entry->setStarred((bool) $data['isStarred']);
363 } 363 }
364 364
@@ -366,7 +366,7 @@ class EntryRestController extends WallabagRestController
366 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $data['tags']); 366 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $data['tags']);
367 } 367 }
368 368
369 if (!is_null($data['isPublic'])) { 369 if (null !== $data['isPublic']) {
370 if (true === (bool) $data['isPublic'] && null === $entry->getUid()) { 370 if (true === (bool) $data['isPublic'] && null === $entry->getUid()) {
371 $entry->generateUid(); 371 $entry->generateUid();
372 } elseif (false === (bool) $data['isPublic']) { 372 } elseif (false === (bool) $data['isPublic']) {
@@ -457,11 +457,11 @@ class EntryRestController extends WallabagRestController
457 $contentProxy->updatePublishedAt($entry, $data['publishedAt']); 457 $contentProxy->updatePublishedAt($entry, $data['publishedAt']);
458 } 458 }
459 459
460 if (!is_null($data['isArchived'])) { 460 if (null !== $data['isArchived']) {
461 $entry->setArchived((bool) $data['isArchived']); 461 $entry->setArchived((bool) $data['isArchived']);
462 } 462 }
463 463
464 if (!is_null($data['isStarred'])) { 464 if (null !== $data['isStarred']) {
465 $entry->setStarred((bool) $data['isStarred']); 465 $entry->setStarred((bool) $data['isStarred']);
466 } 466 }
467 467
@@ -470,7 +470,7 @@ class EntryRestController extends WallabagRestController
470 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $data['tags']); 470 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $data['tags']);
471 } 471 }
472 472
473 if (!is_null($data['isPublic'])) { 473 if (null !== $data['isPublic']) {
474 if (true === (bool) $data['isPublic'] && null === $entry->getUid()) { 474 if (true === (bool) $data['isPublic'] && null === $entry->getUid()) {
475 $entry->generateUid(); 475 $entry->generateUid();
476 } elseif (false === (bool) $data['isPublic']) { 476 } elseif (false === (bool) $data['isPublic']) {
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index 5622cc83..656ac6ee 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -67,6 +67,76 @@ class ContentProxy
67 } 67 }
68 68
69 /** 69 /**
70 * Use a Symfony validator to ensure the language is well formatted.
71 *
72 * @param Entry $entry
73 * @param string $value Language to validate and save
74 */
75 public function updateLanguage(Entry $entry, $value)
76 {
77 // some lang are defined as fr-FR, es-ES.
78 // replacing - by _ might increase language support
79 $value = str_replace('-', '_', $value);
80
81 $errors = $this->validator->validate(
82 $value,
83 (new LocaleConstraint())
84 );
85
86 if (0 === count($errors)) {
87 $entry->setLanguage($value);
88
89 return;
90 }
91
92 $this->logger->warning('Language validation failed. ' . (string) $errors);
93 }
94
95 /**
96 * Use a Symfony validator to ensure the preview picture is a real url.
97 *
98 * @param Entry $entry
99 * @param string $value URL to validate and save
100 */
101 public function updatePreviewPicture(Entry $entry, $value)
102 {
103 $errors = $this->validator->validate(
104 $value,
105 (new UrlConstraint())
106 );
107
108 if (0 === count($errors)) {
109 $entry->setPreviewPicture($value);
110
111 return;
112 }
113
114 $this->logger->warning('PreviewPicture validation failed. ' . (string) $errors);
115 }
116
117 /**
118 * Update date.
119 *
120 * @param Entry $entry
121 * @param string $value Date to validate and save
122 */
123 public function updatePublishedAt(Entry $entry, $value)
124 {
125 $date = $value;
126
127 // is it a timestamp?
128 if (filter_var($date, FILTER_VALIDATE_INT) !== false) {
129 $date = '@' . $value;
130 }
131
132 try {
133 $entry->setPublishedAt(new \DateTime($date));
134 } catch (\Exception $e) {
135 $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $entry->getUrl(), 'date' => $value]);
136 }
137 }
138
139 /**
70 * Stock entry with fetched or imported content. 140 * Stock entry with fetched or imported content.
71 * Will fall back to OpenGraph data if available. 141 * Will fall back to OpenGraph data if available.
72 * 142 *
@@ -155,74 +225,4 @@ class ContentProxy
155 { 225 {
156 return !empty($content['title']) && !empty($content['html']) && !empty($content['url']); 226 return !empty($content['title']) && !empty($content['html']) && !empty($content['url']);
157 } 227 }
158
159 /**
160 * Use a Symfony validator to ensure the language is well formatted.
161 *
162 * @param Entry $entry
163 * @param string $value Language to validate and save
164 */
165 public function updateLanguage(Entry $entry, $value)
166 {
167 // some lang are defined as fr-FR, es-ES.
168 // replacing - by _ might increase language support
169 $value = str_replace('-', '_', $value);
170
171 $errors = $this->validator->validate(
172 $value,
173 (new LocaleConstraint())
174 );
175
176 if (0 === count($errors)) {
177 $entry->setLanguage($value);
178
179 return;
180 }
181
182 $this->logger->warning('Language validation failed. ' . (string) $errors);
183 }
184
185 /**
186 * Use a Symfony validator to ensure the preview picture is a real url.
187 *
188 * @param Entry $entry
189 * @param string $value URL to validate and save
190 */
191 public function updatePreviewPicture(Entry $entry, $value)
192 {
193 $errors = $this->validator->validate(
194 $value,
195 (new UrlConstraint())
196 );
197
198 if (0 === count($errors)) {
199 $entry->setPreviewPicture($value);
200
201 return;
202 }
203
204 $this->logger->warning('PreviewPicture validation failed. ' . (string) $errors);
205 }
206
207 /**
208 * Update date.
209 *
210 * @param Entry $entry
211 * @param string $value Date to validate and save
212 */
213 public function updatePublishedAt(Entry $entry, $value)
214 {
215 $date = $value;
216
217 // is it a timestamp?
218 if (filter_var($date, FILTER_VALIDATE_INT) !== false) {
219 $date = '@'.$value;
220 }
221
222 try {
223 $entry->setPublishedAt(new \DateTime($date));
224 } catch (\Exception $e) {
225 $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $entry->getUrl(), 'date' => $value]);
226 }
227 }
228} 228}