2020-05-17 21:00:52 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ASRockNewsBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2020-05-17 21:00:52 +03:00
|
|
|
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()
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM(self::URI . '/news/index.asp');
|
2020-05-17 21:00:52 +03:00
|
|
|
|
|
|
|
$html = defaultLinkTo($html, self::URI . '/news/');
|
|
|
|
|
|
|
|
foreach ($html->find('div.inner > a') as $index => $a) {
|
|
|
|
$item = [];
|
|
|
|
|
|
|
|
$articlePath = $a->href;
|
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$articlePageHtml = getSimpleHTMLDOMCached($articlePath, self::CACHE_TIMEOUT);
|
2020-05-17 21:00:52 +03:00
|
|
|
|
|
|
|
$articlePageHtml = defaultLinkTo($articlePageHtml, self::URI);
|
|
|
|
|
|
|
|
$contents = $articlePageHtml->find('div.Contents', 0);
|
|
|
|
|
|
|
|
$item['uri'] = $articlePath;
|
2021-12-18 13:17:16 +03:00
|
|
|
$item['title'] = $contents->find('h3', 0)->innertext;
|
2020-05-17 21:00:52 +03:00
|
|
|
|
2021-12-18 13:17:16 +03:00
|
|
|
$contents->find('h3', 0)->outertext = '';
|
2020-05-17 21:00:52 +03:00
|
|
|
|
|
|
|
$item['content'] = $contents->innertext;
|
|
|
|
$item['timestamp'] = $this->extractDate($a->plaintext);
|
|
|
|
$item['enclosures'][] = $a->find('img', 0)->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 '';
|
|
|
|
}
|
|
|
|
}
|