From 1daef22a3db3580291011c8e4df5d5494f42ca0b Mon Sep 17 00:00:00 2001 From: oratosquilla-oratoria Date: Mon, 16 Sep 2019 19:27:01 +0000 Subject: [PATCH] [NFLRUSBridge] Add new bridge (#1285) * [NFLRUSBridge] Add new bridge --- bridges/NFLRUSBridge.php | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bridges/NFLRUSBridge.php diff --git a/bridges/NFLRUSBridge.php b/bridges/NFLRUSBridge.php new file mode 100644 index 00000000..739f4ab5 --- /dev/null +++ b/bridges/NFLRUSBridge.php @@ -0,0 +1,60 @@ + 'January', + 'Февраля' => 'February', + 'Марта' => 'March', + 'Апреля' => 'April', + 'Мая' => 'May', + 'Июня' => 'June', + 'Июля' => 'July', + 'Августа' => 'August', + 'Сентября' => 'September', + 'Октября' => 'October', + 'Ноября' => 'November', + 'Декабря' => 'December', + ); + + if (isset($months[$month])) { + return $months[$month]; + } + return false; + } + + private function extractArticleTimestamp($article) { + $time = $article->find('time', 0); + if($time) { + $timestring = trim($time->plaintext); + $parts = explode(' ', $timestring); + $month = $this->getEnglishMonth($parts[1]); + if ($month) { + $timestring = $parts[0] . ' ' . $month . ' ' . $parts[2]; + return strtotime($timestring); + } + } + return 0; + } + + public function collectData() { + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Unable to get any articles from NFLRUS'); + $html = defaultLinkTo($html, self::URI); + + foreach($html->find('article') as $article) { + $item = array(); + $item['uri'] = $article->find('.b-article__title a', 0)->href; + $item['title'] = $article->find('.b-article__title a', 0)->plaintext; + $item['author'] = $article->find('.link-author', 0)->plaintext; + $item['timestamp'] = $this->extractArticleTimestamp($article); + $item['content'] = $article->find('div', 0)->innertext; + $this->items[] = $item; + } + } +}