2017-12-23 23:57:40 +03:00
|
|
|
<?php
|
|
|
|
class PcGamerBridge extends BridgeAbstract
|
|
|
|
{
|
2017-12-25 00:45:56 +03:00
|
|
|
const NAME = 'PC Gamer';
|
2020-02-27 00:10:09 +03:00
|
|
|
const URI = 'https://www.pcgamer.com/archive/';
|
2017-12-25 00:45:56 +03:00
|
|
|
const DESCRIPTION = 'PC Gamer Most Read Stories';
|
2020-02-27 00:10:09 +03:00
|
|
|
const CACHE_TIMEOUT = 3600;
|
|
|
|
const MAINTAINER = 'IceWreck, mdemoss';
|
2017-12-23 23:57:40 +03:00
|
|
|
|
2017-12-25 00:45:56 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$html = getSimpleHTMLDOMCached($this->getURI(), 300);
|
2020-02-27 00:10:09 +03:00
|
|
|
$stories = $html->find('ul.basic-list li.day-article');
|
|
|
|
$i = 0;
|
|
|
|
// Find induvidual stories in the archive page
|
2017-12-25 00:45:56 +03:00
|
|
|
foreach ($stories as $element) {
|
2020-02-27 00:10:09 +03:00
|
|
|
if($i == 15) break;
|
2017-12-25 00:45:56 +03:00
|
|
|
$item['uri'] = $element->find('a', 0)->href;
|
2020-02-27 00:10:09 +03:00
|
|
|
// error_log(print_r($item['uri'], TRUE));
|
2017-12-25 00:45:56 +03:00
|
|
|
$articleHtml = getSimpleHTMLDOMCached($item['uri']);
|
2020-02-27 00:10:09 +03:00
|
|
|
$item['title'] = $element->find('a', 0)->plaintext;
|
2017-12-25 00:45:56 +03:00
|
|
|
$item['timestamp'] = strtotime($articleHtml->find('meta[name=pub_date]', 0)->content);
|
2020-02-27 00:10:09 +03:00
|
|
|
$item['author'] = $articleHtml->find('span.by-author a', 0)->plaintext;
|
|
|
|
|
|
|
|
// Get the article content
|
|
|
|
$articleContents = $articleHtml->find('#article-body', 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
By default the img src has a link to an error image and then the actual image
|
|
|
|
is added in by JS. So we replace the error image with the actual full size image
|
|
|
|
whoose link is in one of the attributes of the img tag
|
|
|
|
*/
|
|
|
|
foreach($articleContents->find('img') as $img) {
|
|
|
|
$imgsrc = $img->getAttribute('data-original-mos');
|
|
|
|
// error_log($imgsrc);
|
|
|
|
$img->src = $imgsrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
$item['content'] = $articleContents;
|
2017-12-25 00:45:56 +03:00
|
|
|
$this->items[] = $item;
|
2020-02-27 00:10:09 +03:00
|
|
|
$i++;
|
2017-12-25 00:45:56 +03:00
|
|
|
}
|
|
|
|
}
|
2017-12-23 23:57:40 +03:00
|
|
|
}
|