forked from RSS-Bridge/rss-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NFLRUSBridge] Add new bridge (RSS-Bridge#1285)
* [NFLRUSBridge] Add new bridge
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
class NFLRUSBridge extends BridgeAbstract { | ||
|
||
const NAME = 'NFLRUS'; | ||
const URI = 'http://nflrus.ru/'; | ||
const DESCRIPTION = 'Returns the recent articles published on nflrus.ru'; | ||
const MAINTAINER = 'Maxim Shpak'; | ||
|
||
private function getEnglishMonth($month) { | ||
$months = array( | ||
'Января' => '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; | ||
} | ||
} | ||
} |