forked from RSS-Bridge/rss-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASRockNewsBridge] Add Bridge (RSS-Bridge#1526)
* [ASRockNewsBridge] Add Bridge
- Loading branch information
1 parent
8c15f78
commit fba7e85
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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 = array(); | ||
|
||
const CACHE_TIMEOUT = 3600; // 1 hour | ||
|
||
public function collectData() { | ||
|
||
$html = getSimpleHTMLDOM(self::URI . '/news/index.asp') | ||
or returnServerError('Could not request: ' . self::URI . '/news/index.asp'); | ||
|
||
$html = defaultLinkTo($html, self::URI . '/news/'); | ||
|
||
foreach($html->find('div.inner > a') as $index => $a) { | ||
$item = array(); | ||
|
||
$articlePath = $a->href; | ||
|
||
$articlePageHtml = getSimpleHTMLDOMCached($articlePath, self::CACHE_TIMEOUT) | ||
or returnServerError('Could not request: ' . $articlePath); | ||
|
||
$articlePageHtml = defaultLinkTo($articlePageHtml, self::URI); | ||
|
||
$contents = $articlePageHtml->find('div.Contents', 0); | ||
|
||
$item['uri'] = $articlePath; | ||
$item['title'] = $contents->find('h5', 0)->innertext; | ||
|
||
$contents->find('h5', 0)->outertext = ''; | ||
|
||
$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 ''; | ||
} | ||
} |