2016-08-14 12:46:16 +02:00
|
|
|
<?php
|
|
|
|
class AskfmBridge extends BridgeAbstract{
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "az5he6ch";
|
|
|
|
const NAME = "Ask.fm Answers";
|
|
|
|
const URI = "http://ask.fm/";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 300; //5 min
|
2016-08-30 11:23:55 +02:00
|
|
|
const DESCRIPTION = "Returns answers from an Ask.fm user";
|
|
|
|
const PARAMETERS = array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'Ask.fm username'=>array(
|
|
|
|
'u'=>array(
|
|
|
|
'name'=>'Username',
|
|
|
|
'required'=>true
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2016-08-14 12:46:16 +02:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-08-28 01:48:57 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($this->getURI())
|
|
|
|
or $this->returnServerError('Requested username can\'t be found.');
|
2016-08-14 12:46:16 +02:00
|
|
|
|
|
|
|
foreach($html->find('div.streamItem-answer') as $element) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2016-08-30 11:23:55 +02:00
|
|
|
$item['uri'] = self::URI.$element->find('a.streamItemsAge',0)->href;
|
2016-08-14 12:46:16 +02:00
|
|
|
$question = trim($element->find('h1.streamItemContent-question',0)->innertext);
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['title'] = trim(htmlspecialchars_decode($element->find('h1.streamItemContent-question',0)->plaintext, ENT_QUOTES));
|
2016-08-14 12:46:16 +02:00
|
|
|
$answer = trim($element->find('p.streamItemContent-answer',0)->innertext);
|
2016-08-22 18:55:59 +02:00
|
|
|
#$item['update'] = $element->find('a.streamitemsage',0)->data-hint; // Doesn't work, DOM parser doesn't seem to like data-hint, dunno why
|
2016-08-14 12:46:16 +02:00
|
|
|
$visual = $element->find('div.streamItemContent-visual',0)->innertext; // This probably should be cleaned up, especially for YouTube embeds
|
|
|
|
//Fix tracking links, also doesn't work
|
|
|
|
foreach($element->find('a') as $link) {
|
|
|
|
if (strpos($link->href, 'l.ask.fm') !== false) {
|
|
|
|
#$link->href = str_replace('#_=_', '', get_headers($link->href, 1)['Location']); // Too slow
|
|
|
|
$link->href = $link->plaintext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$content = '<p>' . $question . '</p><p>' . $answer . '</p><p>' . $visual . '</p>';
|
|
|
|
// Fix relative links without breaking // scheme used by YouTube stuff
|
2016-08-30 11:23:55 +02:00
|
|
|
$content = preg_replace('#href="\/(?!\/)#', 'href="'.self::URI,$content);
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = $content;
|
2016-08-14 12:46:16 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
2016-08-30 11:23:55 +02:00
|
|
|
return self::NAME.' : '.$this->getInput('u');
|
2016-08-14 12:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
2016-08-30 11:23:55 +02:00
|
|
|
return self::URI.urlencode($this->getInput('u')).'/answers/more?page=0';
|
2016-08-14 12:46:16 +02:00
|
|
|
}
|
|
|
|
}
|