-
Notifications
You must be signed in to change notification settings - Fork 1k
/
OMonlineBridge.php
72 lines (55 loc) · 2.3 KB
/
OMonlineBridge.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class OMonlineBridge extends BridgeAbstract
{
const NAME = 'OM Online Bridge';
const URI = 'https://www.om-online.de';
const DESCRIPTION = 'RSS feed for OM Online';
const MAINTAINER = '[email protected]';
const PARAMETERS = [
[
'ort' => [
'name' => 'Ortsname',
'title' => 'Für die Anzeige von Beitragen nur aus einem Ort oder mehreren Orten
geben einen Orstnamen ein. Mehrere Ortsnamen müssen mit / getrennt eingeben werden,
z.B. Vechta/Cloppenburg. Groß- und Kleinschreibung beachten!'
]
]
];
public function collectData()
{
if (!empty($this->getInput('ort'))) {
$url = sprintf('%s/ort/%s', self::URI, $this->getInput('ort'));
} else {
$url = sprintf('%s', self::URI);
}
$html = getSimpleHTMLDOM($url)
or returnServerError('Could not request: ' . $url);
$html = defaultLinkTo($html, $url);
foreach ($html->find('div.molecule-teaser > a ') as $index => $a) {
$item = [];
$articlePath = $a->href;
$articlePageHtml = getSimpleHTMLDOMCached($articlePath, self::CACHE_TIMEOUT)
or returnServerError('Could not request: ' . $articlePath);
$articlePageHtml = defaultLinkTo($articlePageHtml, self::URI);
$contents = $articlePageHtml->find('div.molecule-article', 0);
$item['uri'] = $articlePath;
$item['title'] = $contents->find('h1', 0)->innertext;
$contents->find('div.col-12 col-md-10 offset-0 offset-md-1', 0);
$item['content'] = $contents->innertext;
$item['timestamp'] = $this->extractDate2($a->plaintext);
$this->items[] = $item;
if (count($this->items) >= 10) {
break;
}
}
}
private function extractDate2($text)
{
$dateRegex = '/^([0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2})/';
$text = trim($text);
if (preg_match($dateRegex, $text, $matches)) {
return $matches[1];
}
return '';
}
}