From 8f5151b222d554f58a314d7261c74b9b1f88567d Mon Sep 17 00:00:00 2001 From: somini Date: Tue, 16 Apr 2019 08:58:22 +0100 Subject: [PATCH] [SIMARBridge]: Add new bridge (#1055) * [SIMARBridge]: Add new bridge --- bridges/SIMARBridge.php | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bridges/SIMARBridge.php diff --git a/bridges/SIMARBridge.php b/bridges/SIMARBridge.php new file mode 100644 index 00000000..1e446cf5 --- /dev/null +++ b/bridges/SIMARBridge.php @@ -0,0 +1,63 @@ + array( + 'interventions' => array( + 'type' => 'checkbox', + 'name' => 'Incluir Intervenções?', + 'defaultValue' => 'checked', + ) + ) + ); + + public function collectData() { + $html = getSimpleHTMLDOM(self::getURI()) + or returnServerError('Could not load content'); + $e_home = $html->find('#home', 0) + or returnServerError('Invalid site structure'); + + foreach($e_home->find('span') as $element) { + $item = array(); + + $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 = array(); + + $item['title'] = 'Intervenção: ' . $element->plaintext; + $item['uri'] = self::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; + } + } + } +}