From 3b69c71197517c64f692bf8e6e088b72d33252e4 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Sun, 1 Feb 2015 16:46:59 +0100 Subject: [PATCH] [4chan] new bridge --- bridges/FourchanBridge.php | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bridges/FourchanBridge.php diff --git a/bridges/FourchanBridge.php b/bridges/FourchanBridge.php new file mode 100644 index 00000000..e6068af7 --- /dev/null +++ b/bridges/FourchanBridge.php @@ -0,0 +1,65 @@ +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) ? ''.$item->id.'
' : '') . ''.$element->find('.postMessage', 0)->innertext.''; + $this->items[] = $item; + } + } + + public function getName(){ + return '4chan'; + } + + public function getURI(){ + return 'https://www.4chan.org/'; + } + + public function getCacheDuration(){ + return 300; // 5min + } +}