-
Notifications
You must be signed in to change notification settings - Fork 1k
/
SIMARBridge.php
65 lines (55 loc) · 2.14 KB
/
SIMARBridge.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
<?php
class SIMARBridge extends BridgeAbstract
{
const NAME = 'SIMAR';
const URI = 'http://www.simar-louresodivelas.pt/';
const DESCRIPTION = 'Verificar estado da rede SIMAR';
const MAINTAINER = 'somini';
const PARAMETERS = [
'Público' => [
'interventions' => [
'type' => 'checkbox',
'name' => 'Incluir Intervenções?',
'defaultValue' => 'checked',
]
]
];
public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI());
$e_home = $html->find('#home', 0)
or returnServerError('Invalid site structure');
foreach ($e_home->find('span') as $element) {
$item = [];
$item['title'] = 'Rotura: ' . $element->plaintext;
$item['content'] = $element->innertext;
$item['uid'] = 'urn:sha1:' . hash('sha1', $item['content']);
$this->items[] = $item;
}
if ($this->getInput('interventions')) {
$e_main1 = $html->find('#menu1', 0)
or returnServerError('Invalid site structure');
foreach ($e_main1->find('a') as $element) {
$item = [];
$item['title'] = 'Intervenção: ' . $element->plaintext;
$item['uri'] = $this->getURI() . $element->href;
$item['content'] = $element->innertext;
/* Try to get the actual contents for this kind of item */
$item_html = getSimpleHTMLDOMCached($item['uri']);
if ($item_html) {
$e_item = $item_html->find('.auto-style59', 0);
foreach ($e_item->find('p') as $paragraph) {
/* Remove empty paragraphs */
if (preg_match('/^(\W| )+$/', $paragraph->innertext) == 1) {
$paragraph->outertext = '';
}
}
if ($e_item) {
$item['content'] = $e_item->innertext;
}
}
$this->items[] = $item;
}
}
}
}