2015-02-01 16:46:59 +01:00
|
|
|
<?php
|
|
|
|
class FourchanBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $maintainer = "mitsukarenai";
|
|
|
|
public $name = "4chan";
|
|
|
|
public $uri = "https://www.4chan.org/";
|
|
|
|
public $description = "Returns posts from the specified thread";
|
|
|
|
|
|
|
|
public $parameters = array( array(
|
|
|
|
't'=>array('name'=>'Thread URL')
|
|
|
|
));
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2015-02-01 16:46:59 +01:00
|
|
|
|
2016-08-28 01:25:33 +02:00
|
|
|
if (!isset($this->getInput('t')))
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnClientError('You must specify the thread URL (?t=...)');
|
2015-02-01 16:46:59 +01:00
|
|
|
|
2016-08-28 01:25:33 +02:00
|
|
|
$thread = parse_url($this->getInput('t')) or $this->returnClientError('This URL seems malformed, please check it.');
|
2015-02-01 16:46:59 +01:00
|
|
|
if($thread['host'] !== 'boards.4chan.org')
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnClientError('4chan thread URL only.');
|
2015-02-01 16:46:59 +01:00
|
|
|
|
|
|
|
if(strpos($thread['path'], 'thread/') === FALSE)
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnClientError('You must specify the thread URL.');
|
2015-02-01 16:46:59 +01:00
|
|
|
|
|
|
|
$url = 'https://boards.4chan.org'.$thread['path'].'';
|
2016-07-08 19:06:35 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($url) or $this->returnServerError("Could not request 4chan, thread not found");
|
2015-02-01 16:46:59 +01:00
|
|
|
|
|
|
|
foreach($html->find('div.postContainer') as $element) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['id'] = $element->find('.post', 0)->getAttribute('id');
|
|
|
|
$item['uri'] = $url.'#'.$item['id'];
|
|
|
|
$item['timestamp'] = $element->find('span.dateTime', 0)->getAttribute('data-utc');
|
|
|
|
$item['author'] = $element->find('span.name', 0)->plaintext;
|
2015-02-01 16:46:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
if(!empty($element->find('.file', 0) ) ) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['image'] = $element->find('.file a', 0)->href;
|
|
|
|
$item['imageThumb'] = $element->find('.file img', 0)->src;
|
|
|
|
if(!isset($item['imageThumb']) and strpos($item['image'], '.swf') !== FALSE)
|
|
|
|
$item['imageThumb'] = 'http://i.imgur.com/eO0cxf9.jpg';
|
2015-02-01 16:46:59 +01:00
|
|
|
}
|
|
|
|
if(!empty($element->find('span.subject', 0)->innertext )) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['subject'] = $element->find('span.subject', 0)->innertext;
|
2015-02-01 16:46:59 +01:00
|
|
|
}
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['title'] = (isset($item['subject']) ? $item['subject'].' - ' : '' ) . 'reply '.$item['id'].' | '.$item['author'];
|
2015-02-01 16:46:59 +01:00
|
|
|
|
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = (isset($item['image']) ? '<a href="'.$item['image'].'"><img alt="'.$item['id'].'" src="'.$item['imageThumb'].'" /></a><br>' : '') . '<span id="'.$item['id'].'">'.$element->find('.postMessage', 0)->innertext.'</span>';
|
2015-02-01 16:46:59 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2015-02-02 13:00:15 +01:00
|
|
|
$this->items = array_reverse($this->items);
|
2015-02-01 16:46:59 +01:00
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2015-02-01 16:46:59 +01:00
|
|
|
public function getCacheDuration(){
|
|
|
|
return 300; // 5min
|
|
|
|
}
|
|
|
|
}
|