Bridges/EvercadeBridge.php

49 lines
1.8 KiB
PHP
Raw Normal View History

2023-08-11 22:09:51 +02:00
<?php
class EvercadeBridge extends BridgeAbstract {
const MAINTAINER = 'Akamaru';
const NAME = 'Evercade News';
const URI = 'https://evercade.co.uk/blog';
const CACHE_TIMEOUT = 21600; // 21600 = 6h
const DESCRIPTION = 'All the news from Evercade and our community';
public function getIcon(){
return 'https://evercade.co.uk/wp-content/themes/evercade/img/icons/favicon.ico';
}
public function collectData() {
// Retrieve webpage
$pageUrl = self::URI;
$html = getSimpleHTMLDOM($pageUrl)
or returnServerError('Could not request webpage: ' . $pageUrl);
// Process articles
foreach($html->find('div.an-article') as $element) {
if(count($this->items) >= 10) {
break;
}
$article_title = trim(strip_tags($element->find('h2', 0)->innertext));
$article_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('p.excerpt', 0)->innertext));
//$article_timestamp = strtotime($element->find('time', 0)->attr['datetime']);
$article_uid = trim(strip_tags($element->find('h2', 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;
}
}
}
}