mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-23 01:55:27 +03:00
[4chan] new bridge
This commit is contained in:
parent
091bf7872e
commit
3b69c71197
1 changed files with 65 additions and 0 deletions
65
bridges/FourchanBridge.php
Normal file
65
bridges/FourchanBridge.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* RssBridge4chan
|
||||
* @name 4chan
|
||||
* @homepage https://www.4chan.org/
|
||||
* @description Returns posts from the specified thread
|
||||
* @maintainer mitsukarenai
|
||||
* @update 2015-02-01
|
||||
* @use1(t="Thread URL")
|
||||
*/
|
||||
|
||||
class FourchanBridge extends BridgeAbstract{
|
||||
|
||||
public function collectData(array $param){
|
||||
|
||||
if (!isset($param['t']))
|
||||
$this->returnError('You must specify the thread URL (?t=...)', 400);
|
||||
|
||||
$thread = parse_url($param['t']) or $this->returnError('This URL seems malformed, please check it.', 400);
|
||||
if($thread['host'] !== 'boards.4chan.org')
|
||||
$this->returnError('4chan thread URL only.', 400);
|
||||
|
||||
if(strpos($thread['path'], 'thread/') === FALSE)
|
||||
$this->returnError('You must specify the thread URL.', 400);
|
||||
|
||||
$url = 'https://boards.4chan.org'.$thread['path'].'';
|
||||
$html = file_get_html($url) or $this->returnError("Could not request 4chan, thread not found", 404);
|
||||
|
||||
foreach($html->find('div.postContainer') as $element) {
|
||||
$item = new \Item();
|
||||
$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;
|
||||
|
||||
|
||||
if(!empty($element->find('.file', 0) ) ) {
|
||||
$item->image = $element->find('.file a', 0)->href;
|
||||
$item->imageThumb = $element->find('.file img', 0)->src;
|
||||
if(empty($item->imageThumb) and strpos($item->image, '.swf') !== FALSE)
|
||||
$item->imageThumb = 'http://i.imgur.com/eO0cxf9.jpg';
|
||||
}
|
||||
if(!empty($element->find('span.subject', 0)->innertext )) {
|
||||
$item->subject = $element->find('span.subject', 0)->innertext;
|
||||
}
|
||||
$item->title = (!empty($item->subject) ? $item->subject.' - ' : '' ) . 'reply '.$item->id.' | '.$item->author;
|
||||
|
||||
|
||||
$item->content = (!empty($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>';
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return '4chan';
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
return 'https://www.4chan.org/';
|
||||
}
|
||||
|
||||
public function getCacheDuration(){
|
||||
return 300; // 5min
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue