Bridges/FoodwatchBridge.php

49 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2023-08-11 22:09:51 +02:00
<?php
class FoodwatchBridge extends BridgeAbstract {
const MAINTAINER = 'Akamaru';
const NAME = 'Foodwatch.org News';
const URI = 'https://www.foodwatch.org';
const CACHE_TIMEOUT = 21600; // 21600 = 6h
const DESCRIPTION = 'Get the latest news from Foodwatch.org.';
public function getIcon(){
return 'https://www.foodwatch.org/typo3conf/ext/wwt3_site/Resources/Public/Images/Favicons/favicon.ico';
}
public function collectData() {
// Retrieve webpage
$pageUrl = self::URI . '/de/informieren/aktuelle-nachrichten/';
$html = getSimpleHTMLDOM($pageUrl)
or returnServerError('Could not request webpage: ' . $pageUrl);
// Process articles
foreach($html->find('div.list-teaser__content') as $element) {
if(count($this->items) >= 10) {
break;
}
$article_title = trim(strip_tags($element->find('h3', 0)->innertext));
$article_uri = self::URI . substr($element->find('a', 0)->href, 0);
//$article_thumbnail = self::URI . substr($element->find('img', 0)->src, 3);
//$article_content = '<img src="'. $article_thumbnail .'"></a>';
$article_content = trim(strip_tags($element->find('div.list-teaser__main', 0)->innertext));
//$article_timestamp = strtotime($element->find('time', 0)->attr['datetime']);
$article_uid = trim(strip_tags($element->find('div.list-teaser__meta', 0)->innertext));
// Store article in items array
if (!empty($article_title)) {
$item = array();
$item['uri'] = $article_uri;
$item['title'] = $article_title;
//$item['enclosures'] = array($article_thumbnail);
$item['content'] = $article_content;
//$item['timestamp'] = $article_timestamp;
$item['uid'] = $article_uid;
$this->items[] = $item;
}
}
}
}