2015-10-22 15:51:56 +03:00
|
|
|
<?php
|
|
|
|
class CNETBridge extends BridgeAbstract {
|
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const MAINTAINER = 'ORelio';
|
|
|
|
const NAME = 'CNET News';
|
|
|
|
const URI = 'http://www.cnet.com/';
|
|
|
|
const DESCRIPTION = 'Returns the newest articles. <br /> You may specify a topic found in some section URLs, else all topics are selected.';
|
2016-01-23 23:45:16 +03:00
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 22:03:26 +03:00
|
|
|
'topic'=>array('name'=>'Topic name')
|
|
|
|
));
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
2015-10-22 15:51:56 +03:00
|
|
|
|
|
|
|
function ExtractFromDelimiters($string, $start, $end) {
|
|
|
|
if (strpos($string, $start) !== false) {
|
|
|
|
$section_retrieved = substr($string, strpos($string, $start) + strlen($start));
|
|
|
|
$section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end));
|
|
|
|
return $section_retrieved;
|
|
|
|
} return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function StripWithDelimiters($string, $start, $end) {
|
|
|
|
while (strpos($string, $start) !== false) {
|
|
|
|
$section_to_remove = substr($string, strpos($string, $start));
|
|
|
|
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
|
|
|
|
$string = str_replace($section_to_remove, '', $string);
|
|
|
|
} return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CleanArticle($article_html) {
|
2016-01-23 23:45:16 +03:00
|
|
|
$article_html = '<p>'.substr($article_html, strpos($article_html, '<p>') + 3);
|
|
|
|
$article_html = StripWithDelimiters($article_html, '<span class="credit">', '</span>');
|
2016-02-13 15:52:07 +03:00
|
|
|
$article_html = StripWithDelimiters($article_html, '<script', '</script>');
|
2015-10-22 15:51:56 +03:00
|
|
|
$article_html = StripWithDelimiters($article_html, '<div class="shortcode related-links', '</div>');
|
|
|
|
$article_html = StripWithDelimiters($article_html, '<a class="clickToEnlarge">', '</a>');
|
|
|
|
return $article_html;
|
|
|
|
}
|
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
$pageUrl = self::URI.(empty($this->getInput('topic')) ? '' : 'topics/'.$this->getInput('topic').'/');
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($pageUrl) or $this->returnServerError('Could not request CNET: '.$pageUrl);
|
2015-10-22 15:51:56 +03:00
|
|
|
$limit = 0;
|
|
|
|
|
2016-01-23 23:45:16 +03:00
|
|
|
foreach($html->find('div.assetBody') as $element) {
|
|
|
|
if ($limit < 8) {
|
2015-10-22 15:51:56 +03:00
|
|
|
|
2016-01-23 23:45:16 +03:00
|
|
|
$article_title = trim($element->find('h2', 0)->plaintext);
|
2016-08-30 12:23:55 +03:00
|
|
|
$article_uri = self::URI.($element->find('a', 0)->href);
|
2016-01-23 23:45:16 +03:00
|
|
|
$article_timestamp = strtotime($element->find('time.assetTime', 0)->plaintext);
|
|
|
|
$article_author = trim($element->find('a[rel=author]', 0)->plaintext);
|
2015-10-22 15:51:56 +03:00
|
|
|
|
|
|
|
if (!empty($article_title) && !empty($article_uri) && strpos($article_uri, '/news/') !== false) {
|
|
|
|
|
2016-07-08 20:06:35 +03:00
|
|
|
$article_html = $this->getSimpleHTMLDOM($article_uri) or $this->returnServerError('Could not request CNET: '.$article_uri);
|
2016-01-23 23:45:16 +03:00
|
|
|
|
2016-03-16 21:51:54 +03:00
|
|
|
$article_content = trim(CleanArticle(ExtractFromDelimiters($article_html, '<div class="articleContent', '<footer>')));
|
2015-10-22 15:51:56 +03:00
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $article_uri;
|
|
|
|
$item['title'] = $article_title;
|
|
|
|
$item['author'] = $article_author;
|
|
|
|
$item['timestamp'] = $article_timestamp;
|
|
|
|
$item['content'] = $article_content;
|
2015-10-22 15:51:56 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
2016-09-01 23:53:01 +03:00
|
|
|
$topic=$this->getInput('topic');
|
|
|
|
return 'CNET News Bridge'.(empty($topic) ? '' : ' - '.$topic);
|
2015-10-22 15:51:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration() {
|
|
|
|
return 1800; // 30 minutes
|
|
|
|
}
|
|
|
|
}
|