101 lines
3.7 KiB
PHP
101 lines
3.7 KiB
PHP
<?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_sitepackage_base/Resources/Public/frontend/favicons/generated/apple-touch-icon-57x57.png';
|
|
}
|
|
|
|
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('article.list-teaser') as $element) {
|
|
|
|
if(count($this->items) >= 10) {
|
|
break;
|
|
}
|
|
|
|
$article_title = trim(strip_tags($element->find('h3.list-teaser__title', 0)->innertext));
|
|
|
|
// Find URL
|
|
$article_uri = self::URI . $element->find('h3.list-teaser__title a', 0)->href;
|
|
|
|
// Get meta information (category and date)
|
|
$article_meta = $element->find('div.list-teaser__meta', 0);
|
|
$article_category = '';
|
|
$article_date = '';
|
|
if ($article_meta) {
|
|
$meta_spans = $article_meta->find('span');
|
|
if (count($meta_spans) > 0) {
|
|
$article_category = trim(strip_tags($meta_spans[0]->innertext));
|
|
}
|
|
if (count($meta_spans) > 1) {
|
|
$article_date = trim(strip_tags($meta_spans[1]->innertext));
|
|
}
|
|
}
|
|
|
|
// Get content
|
|
$article_content = '';
|
|
$content_div = $element->find('div.basic-teaser__content p', 0);
|
|
if ($content_div) {
|
|
$article_content = trim(strip_tags($content_div->innertext));
|
|
}
|
|
|
|
// Get image if available
|
|
$article_thumbnail = '';
|
|
$image = $element->find('div.list-teaser__media img', 0);
|
|
if ($image) {
|
|
$article_thumbnail = self::URI . $image->src;
|
|
}
|
|
|
|
// Create unique ID
|
|
$article_uid = $article_title . ' - ' . $article_date;
|
|
|
|
// Store article in items array
|
|
if (!empty($article_title)) {
|
|
$item = array();
|
|
$item['uri'] = $article_uri;
|
|
$item['title'] = $article_title;
|
|
|
|
// Build content with image and text
|
|
$content = '';
|
|
if ($article_thumbnail) {
|
|
$content .= '<img src="' . $article_thumbnail . '" alt="' . $article_title . '">';
|
|
}
|
|
if ($article_content) {
|
|
$content .= '<p>' . $article_content . '</p>';
|
|
}
|
|
if ($article_category) {
|
|
$content .= '<p><b>Kategorie:</b> ' . $article_category . '</p>';
|
|
}
|
|
|
|
$item['content'] = $content;
|
|
|
|
// Set timestamp if date is available
|
|
if ($article_date) {
|
|
$item['timestamp'] = strtotime($article_date);
|
|
}
|
|
|
|
// Set enclosures if image is available
|
|
if ($article_thumbnail) {
|
|
$item['enclosures'] = array($article_thumbnail);
|
|
}
|
|
|
|
$item['uid'] = $article_uid;
|
|
$item['categories'] = array($article_category);
|
|
|
|
$this->items[] = $item;
|
|
}
|
|
}
|
|
}
|
|
}
|