2015-02-01 18:46:59 +03:00
|
|
|
<?php
|
|
|
|
class FourchanBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const MAINTAINER = "mitsukarenai";
|
|
|
|
const NAME = "4chan";
|
2016-09-04 15:07:58 +03:00
|
|
|
const URI = "https://boards.4chan.org/";
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 300; // 5min
|
2016-08-30 12:23:55 +03:00
|
|
|
const DESCRIPTION = "Returns posts from the specified thread";
|
2016-08-27 22:03:26 +03:00
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const PARAMETERS = array( array(
|
2016-09-04 15:07:58 +03:00
|
|
|
'c'=>array(
|
|
|
|
'name'=>'Thread category',
|
2016-08-28 21:06:10 +03:00
|
|
|
'required'=>true
|
2016-09-04 15:07:58 +03:00
|
|
|
),
|
|
|
|
't'=>array(
|
|
|
|
'name'=>'Thread number',
|
|
|
|
'type'=>'number',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-27 22:03:26 +03:00
|
|
|
));
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-09-04 15:07:58 +03:00
|
|
|
public function getURI(){
|
|
|
|
return static::URI.$this->getInput('c').'/thread/'.$this->getInput('t');
|
2015-02-01 18:46:59 +03:00
|
|
|
|
2016-09-04 15:07:58 +03:00
|
|
|
}
|
2015-02-01 18:46:59 +03:00
|
|
|
|
2016-09-04 15:07:58 +03:00
|
|
|
public function collectData(){
|
2015-02-01 18:46:59 +03:00
|
|
|
|
2016-09-26 00:22:33 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI())
|
|
|
|
or returnServerError("Could not request 4chan, thread not found");
|
2015-02-01 18:46:59 +03:00
|
|
|
|
|
|
|
foreach($html->find('div.postContainer') as $element) {
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['id'] = $element->find('.post', 0)->getAttribute('id');
|
2016-09-04 15:07:58 +03:00
|
|
|
$item['uri'] = $this->getURI().'#'.$item['id'];
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['timestamp'] = $element->find('span.dateTime', 0)->getAttribute('data-utc');
|
|
|
|
$item['author'] = $element->find('span.name', 0)->plaintext;
|
2015-02-01 18:46:59 +03:00
|
|
|
|
2016-09-01 23:53:01 +03:00
|
|
|
$file=$element->find('.file', 0);
|
|
|
|
if(!empty($file) ) {
|
2016-08-22 19:55:59 +03: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 18:46:59 +03:00
|
|
|
}
|
|
|
|
if(!empty($element->find('span.subject', 0)->innertext )) {
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['subject'] = $element->find('span.subject', 0)->innertext;
|
2015-02-01 18:46:59 +03:00
|
|
|
}
|
|
|
|
|
2016-09-04 15:08:39 +03:00
|
|
|
$item['title'] = 'reply '.$item['id'].' | '.$item['author'];
|
|
|
|
if(isset($item['subject'])){
|
|
|
|
$item['title'] = $item['subject'].' - '.$item['title'];
|
|
|
|
}
|
2015-02-01 18:46:59 +03:00
|
|
|
|
2016-09-04 15:08:39 +03:00
|
|
|
$content = $element->find('.postMessage', 0)->innertext;
|
|
|
|
$content = str_replace('href="#p','href="'.$this->getURI().'#p',$content);
|
|
|
|
$item['content'] = '<span id="'.$item['id'].'">'.$content.'</span>';
|
|
|
|
if(isset($item['image'])){
|
|
|
|
$item['content'] = '<a href="'.$item['image'].'">'
|
|
|
|
.'<img alt="'.$item['id'].'" src="'.$item['imageThumb'].'" />'
|
|
|
|
.'</a><br>'
|
|
|
|
.$item['content'];
|
|
|
|
}
|
2015-02-01 18:46:59 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2015-02-02 15:00:15 +03:00
|
|
|
$this->items = array_reverse($this->items);
|
2015-02-01 18:46:59 +03:00
|
|
|
}
|
|
|
|
}
|