blob: a9942e2d4dc5487f981400ca5e86b93f75603233 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
class NYTBridge extends FeedExpander
{
const MAINTAINER = 'IceWreck';
const NAME = 'New York Times Bridge';
const URI = 'https://www.nytimes.com/';
const CACHE_TIMEOUT = 900; // 15 minutes
const DESCRIPTION = 'RSS feed for the New York Times';
public function collectData()
{
$url = 'https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml';
$this->collectExpandableDatas($url, 40);
}
protected function parseItem(array $item)
{
$article = '';
try {
$articlePage = getSimpleHTMLDOM($item['uri']);
} catch (HttpException $e) {
// 403 Forbidden, This means we got anti-bot response
if ($e->getCode() === 403) {
return $item;
}
throw $e;
}
// handle subtitle
$subtitle = $articlePage->find('p.css-w6ymp8', 0);
if ($subtitle != null) {
$article .= '<strong>' . $subtitle->plaintext . '</strong>';
}
// figure contain's the main article image
$article .= $articlePage->find('figure', 0) . '<br />';
// section.meteredContent has the actual article
foreach ($articlePage->find('section.meteredContent p') as $element) {
$article .= '' . $element . '';
}
$item['content'] = $article;
return $item;
}
}
|