aboutsummaryrefslogtreecommitdiff
path: root/bridges/ASRockNewsBridge.php
diff options
context:
space:
mode:
Diffstat (limited to 'bridges/ASRockNewsBridge.php')
-rw-r--r--bridges/ASRockNewsBridge.php75
1 files changed, 39 insertions, 36 deletions
diff --git a/bridges/ASRockNewsBridge.php b/bridges/ASRockNewsBridge.php
index 6c93798f..1b516377 100644
--- a/bridges/ASRockNewsBridge.php
+++ b/bridges/ASRockNewsBridge.php
@@ -1,55 +1,58 @@
<?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
+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 = [];
- public function collectData() {
+ const CACHE_TIMEOUT = 3600; // 1 hour
- $html = getSimpleHTMLDOM(self::URI . '/news/index.asp');
+ public function collectData()
+ {
+ $html = getSimpleHTMLDOM(self::URI . '/news/index.asp');
- $html = defaultLinkTo($html, self::URI . '/news/');
+ $html = defaultLinkTo($html, self::URI . '/news/');
- foreach($html->find('div.inner > a') as $index => $a) {
- $item = array();
+ foreach ($html->find('div.inner > a') as $index => $a) {
+ $item = [];
- $articlePath = $a->href;
+ $articlePath = $a->href;
- $articlePageHtml = getSimpleHTMLDOMCached($articlePath, self::CACHE_TIMEOUT);
+ $articlePageHtml = getSimpleHTMLDOMCached($articlePath, self::CACHE_TIMEOUT);
- $articlePageHtml = defaultLinkTo($articlePageHtml, self::URI);
+ $articlePageHtml = defaultLinkTo($articlePageHtml, self::URI);
- $contents = $articlePageHtml->find('div.Contents', 0);
+ $contents = $articlePageHtml->find('div.Contents', 0);
- $item['uri'] = $articlePath;
- $item['title'] = $contents->find('h3', 0)->innertext;
+ $item['uri'] = $articlePath;
+ $item['title'] = $contents->find('h3', 0)->innertext;
- $contents->find('h3', 0)->outertext = '';
+ $contents->find('h3', 0)->outertext = '';
- $item['content'] = $contents->innertext;
- $item['timestamp'] = $this->extractDate($a->plaintext);
- $item['enclosures'][] = $a->find('img', 0)->src;
- $this->items[] = $item;
+ $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;
- }
- }
- }
+ if (count($this->items) >= 10) {
+ break;
+ }
+ }
+ }
- private function extractDate($text) {
- $dateRegex = '/^([0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2})/';
+ private function extractDate($text)
+ {
+ $dateRegex = '/^([0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2})/';
- $text = trim($text);
+ $text = trim($text);
- if (preg_match($dateRegex, $text, $matches)) {
- return $matches[1];
- }
+ if (preg_match($dateRegex, $text, $matches)) {
+ return $matches[1];
+ }
- return '';
- }
+ return '';
+ }
}