mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-22 09:35:28 +03:00
7881c87bed
* fix(asrocknews): Trying to get property src of non-object Trying to get property 'src' of non-object at bridges/ASRockNewsBridge.php line 37 * refactor(http): tweak max redirs config * fix(tiktok) * fix(gizmodo) * fix(craig) * fix(nationalg) * fix(roadandtrack) * fix(etsy)
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
class ASRockNewsBridge extends BridgeAbstract
|
|
{
|
|
const NAME = 'ASRock News Bridge';
|
|
const URI = 'https://www.asrock.com';
|
|
const DESCRIPTION = 'Returns latest news articles';
|
|
const MAINTAINER = 'VerifiedJoseph';
|
|
const PARAMETERS = [];
|
|
|
|
const CACHE_TIMEOUT = 3600; // 1 hour
|
|
|
|
public function collectData()
|
|
{
|
|
$html = getSimpleHTMLDOM(self::URI . '/news/index.asp');
|
|
|
|
$html = defaultLinkTo($html, self::URI . '/news/');
|
|
|
|
foreach ($html->find('div.inner > a') as $index => $a) {
|
|
$item = [];
|
|
|
|
$articlePath = $a->href;
|
|
|
|
$articlePageHtml = getSimpleHTMLDOMCached($articlePath, self::CACHE_TIMEOUT);
|
|
|
|
$articlePageHtml = defaultLinkTo($articlePageHtml, self::URI);
|
|
|
|
$contents = $articlePageHtml->find('div.Contents', 0);
|
|
|
|
$item['uri'] = $articlePath;
|
|
$item['title'] = $contents->find('h3', 0)->innertext;
|
|
|
|
$contents->find('h3', 0)->outertext = '';
|
|
|
|
$item['content'] = $contents->innertext;
|
|
$item['timestamp'] = $this->extractDate($a->plaintext);
|
|
|
|
$img = $a->find('img', 0);
|
|
if ($img) {
|
|
$item['enclosures'][] = $img->src;
|
|
}
|
|
|
|
$this->items[] = $item;
|
|
|
|
if (count($this->items) >= 10) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function extractDate($text)
|
|
{
|
|
$dateRegex = '/^([0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2})/';
|
|
|
|
$text = trim($text);
|
|
|
|
if (preg_match($dateRegex, $text, $matches)) {
|
|
return $matches[1];
|
|
}
|
|
|
|
return '';
|
|
}
|
|
}
|