aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/ContentProxy.php
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2020-04-26 15:39:57 +0200
committerGitHub <noreply@github.com>2020-04-26 15:39:57 +0200
commit0e8a0f77d0b643a884e6687bd9c463267852a970 (patch)
tree88c6761b4215637bba34b263015e87750c92a187 /src/Wallabag/CoreBundle/Helper/ContentProxy.php
parent8a8a78a64c116caf81aaa4339906298bdc0e32e0 (diff)
parent71f7e58fbd84e1d15c7a405a3c5872adb937dc37 (diff)
downloadwallabag-0e8a0f77d0b643a884e6687bd9c463267852a970.tar.gz
wallabag-0e8a0f77d0b643a884e6687bd9c463267852a970.tar.zst
wallabag-0e8a0f77d0b643a884e6687bd9c463267852a970.zip
Merge pull request #4026 from wallabag/3760-ignorelist-db
Move Ignore Origin rules to database
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php41
1 files changed, 4 insertions, 37 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index 9c6fa8db..7e93249d 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -19,6 +19,7 @@ class ContentProxy
19{ 19{
20 protected $graby; 20 protected $graby;
21 protected $tagger; 21 protected $tagger;
22 protected $ignoreOriginProcessor;
22 protected $validator; 23 protected $validator;
23 protected $logger; 24 protected $logger;
24 protected $mimeGuesser; 25 protected $mimeGuesser;
@@ -26,10 +27,11 @@ class ContentProxy
26 protected $eventDispatcher; 27 protected $eventDispatcher;
27 protected $storeArticleHeaders; 28 protected $storeArticleHeaders;
28 29
29 public function __construct(Graby $graby, RuleBasedTagger $tagger, ValidatorInterface $validator, LoggerInterface $logger, $fetchingErrorMessage, $storeArticleHeaders = false) 30 public function __construct(Graby $graby, RuleBasedTagger $tagger, RuleBasedIgnoreOriginProcessor $ignoreOriginProcessor, ValidatorInterface $validator, LoggerInterface $logger, $fetchingErrorMessage, $storeArticleHeaders = false)
30 { 31 {
31 $this->graby = $graby; 32 $this->graby = $graby;
32 $this->tagger = $tagger; 33 $this->tagger = $tagger;
34 $this->ignoreOriginProcessor = $ignoreOriginProcessor;
33 $this->validator = $validator; 35 $this->validator = $validator;
34 $this->logger = $logger; 36 $this->logger = $logger;
35 $this->mimeGuesser = new MimeTypeExtensionGuesser(); 37 $this->mimeGuesser = new MimeTypeExtensionGuesser();
@@ -356,7 +358,7 @@ class ContentProxy
356 $diff_keys = array_keys($diff); 358 $diff_keys = array_keys($diff);
357 sort($diff_keys); 359 sort($diff_keys);
358 360
359 if ($this->ignoreUrl($entry->getUrl())) { 361 if ($this->ignoreOriginProcessor->process($entry)) {
360 $entry->setUrl($url); 362 $entry->setUrl($url);
361 363
362 return false; 364 return false;
@@ -396,41 +398,6 @@ class ContentProxy
396 } 398 }
397 399
398 /** 400 /**
399 * Check entry url against an ignore list to replace with content url.
400 *
401 * XXX: move the ignore list in the database to let users handle it
402 *
403 * @param string $url url to test
404 *
405 * @return bool true if url matches ignore list otherwise false
406 */
407 private function ignoreUrl($url)
408 {
409 $ignored_hosts = ['feedproxy.google.com', 'feeds.reuters.com'];
410 $ignored_patterns = ['https?://www\.lemonde\.fr/tiny.*'];
411
412 $parsed_url = parse_url($url);
413
414 $filtered = array_filter($ignored_hosts, function ($var) use ($parsed_url) {
415 return $var === $parsed_url['host'];
416 });
417
418 if ([] !== $filtered) {
419 return true;
420 }
421
422 $filtered = array_filter($ignored_patterns, function ($var) use ($url) {
423 return preg_match("`$var`i", $url);
424 });
425
426 if ([] !== $filtered) {
427 return true;
428 }
429
430 return false;
431 }
432
433 /**
434 * Validate that the given content has at least a title, an html and a url. 401 * Validate that the given content has at least a title, an html and a url.
435 * 402 *
436 * @return bool true if valid otherwise false 403 * @return bool true if valid otherwise false