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