1
0

Update FoodwatchBridge.php

This commit is contained in:
Akamaru
2025-04-03 21:15:47 +02:00
parent 26c50af4c9
commit f57d64d188

View File

@ -8,7 +8,7 @@ class FoodwatchBridge extends BridgeAbstract {
const DESCRIPTION = 'Get the latest news from Foodwatch.org.'; const DESCRIPTION = 'Get the latest news from Foodwatch.org.';
public function getIcon(){ public function getIcon(){
return 'https://www.foodwatch.org/typo3conf/ext/wwt3_site/Resources/Public/Images/Favicons/favicon.ico'; return 'https://www.foodwatch.org/typo3conf/ext/wwt3_sitepackage_base/Resources/Public/frontend/favicons/generated/apple-touch-icon-57x57.png';
} }
public function collectData() { public function collectData() {
@ -18,29 +18,81 @@ class FoodwatchBridge extends BridgeAbstract {
or returnServerError('Could not request webpage: ' . $pageUrl); or returnServerError('Could not request webpage: ' . $pageUrl);
// Process articles // Process articles
foreach($html->find('div.list-teaser__content') as $element) { foreach($html->find('article.list-teaser') as $element) {
if(count($this->items) >= 10) { if(count($this->items) >= 10) {
break; break;
} }
$article_title = trim(strip_tags($element->find('h3', 0)->innertext)); $article_title = trim(strip_tags($element->find('h3.list-teaser__title', 0)->innertext));
$article_uri = self::URI . substr($element->find('a', 0)->href, 0);
//$article_thumbnail = self::URI . substr($element->find('img', 0)->src, 3); // Find URL
//$article_content = '<img src="'. $article_thumbnail .'"></a>'; $article_uri = self::URI . $element->find('h3.list-teaser__title a', 0)->href;
$article_content = trim(strip_tags($element->find('div.list-teaser__main', 0)->innertext));
//$article_timestamp = strtotime($element->find('time', 0)->attr['datetime']); // Get meta information (category and date)
$article_uid = trim(strip_tags($element->find('div.list-teaser__meta', 0)->innertext)); $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 // Store article in items array
if (!empty($article_title)) { if (!empty($article_title)) {
$item = array(); $item = array();
$item['uri'] = $article_uri; $item['uri'] = $article_uri;
$item['title'] = $article_title; $item['title'] = $article_title;
//$item['enclosures'] = array($article_thumbnail);
$item['content'] = $article_content; // Build content with image and text
//$item['timestamp'] = $article_timestamp; $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['uid'] = $article_uid;
$item['categories'] = array($article_category);
$this->items[] = $item; $this->items[] = $item;
} }
} }