From 2eee535171683845f31b6e05b19e04bfdbbebcff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Maradan?= <3043485+Leomaradan@users.noreply.github.com> Date: Fri, 26 Jul 2019 10:53:09 +0200 Subject: [PATCH] CNET France Bridge (#1214) CNET France News but with filters on title or url --- bridges/CNETFranceBridge.php | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bridges/CNETFranceBridge.php diff --git a/bridges/CNETFranceBridge.php b/bridges/CNETFranceBridge.php new file mode 100644 index 00000000..222c8b9a --- /dev/null +++ b/bridges/CNETFranceBridge.php @@ -0,0 +1,63 @@ + array( + 'title' => array( + 'name' => 'Exclude by title', + 'required' => false, + 'title' => 'Title term, separated by semicolon (;)', + 'defaultValue' => 'bon plan;bons plans;au meilleur prix;des meilleures offres;Amazon Prime Day;RED by SFR ou B&You' + ), + 'url' => array( + 'name' => 'Exclude by url', + 'required' => false, + 'title' => 'URL term, separated by semicolon (;)', + 'defaultValue' => 'bon-plan;bons-plans' + ) + ) + ); + + private $bannedTitle = []; + private $bannedURL = []; + + public function collectData() + { + $title = $this->getInput('title'); + $url = $this->getInput('url'); + + if ($title !== null) { + $this->bannedTitle = explode(';', $title); + } + + if ($url !== null) { + $this->bannedURL = explode(';', $url); + } + + $this->collectExpandableDatas('https://www.cnetfrance.fr/feeds/rss/news/'); + } + + protected function parseItem($feedItem) + { + $item = parent::parseItem($feedItem); + + foreach ($this->bannedTitle as $term) { + if (preg_match('/' . $term . '/mi', $item['title']) === 1) { + return null; + } + } + + foreach ($this->bannedURL as $term) { + if (preg_match('/' . $term . '/mi', $item['uri']) === 1) { + return null; + } + } + + return $item; + } +}