2014-07-18 15:19:02 +04:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-11-09 20:36:50 +03:00
|
|
|
class OpenwhydBridge extends BridgeAbstract
|
|
|
|
{
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'kranack';
|
2019-11-09 20:36:50 +03:00
|
|
|
const NAME = 'Openwhyd Bridge';
|
|
|
|
const URI = 'https://openwhyd.org';
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 600; // 10min
|
2017-02-11 18:16:56 +03:00
|
|
|
const DESCRIPTION = 'Returns 10 newest music from user profile';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const PARAMETERS = [ [
|
|
|
|
'u' => [
|
|
|
|
'name' => 'username/id',
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => '5247f0267e91c862b2b052d0',
|
2017-02-11 18:16:56 +03:00
|
|
|
'required' => true
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2017-02-11 18:16:56 +03:00
|
|
|
]];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
private $userName = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
2019-11-09 20:36:50 +03:00
|
|
|
return self::URI . '/images/favicon.ico';
|
2018-10-26 19:07:34 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2014-07-18 15:19:02 +04:00
|
|
|
$html = '';
|
2018-06-30 00:55:33 +03:00
|
|
|
if (strlen(preg_replace('/[^0-9a-f]/', '', $this->getInput('u'))) == 24) {
|
2017-02-11 18:16:56 +03:00
|
|
|
// is input the userid ?
|
|
|
|
$html = getSimpleHTMLDOM(
|
2019-11-09 20:36:50 +03:00
|
|
|
self::URI . '/u/' . preg_replace('/[^0-9a-f]/', '', $this->getInput('u'))
|
2022-01-02 12:36:09 +03:00
|
|
|
);
|
2017-02-11 18:16:56 +03:00
|
|
|
} else { // input may be the username
|
|
|
|
$html = getSimpleHTMLDOM(
|
2019-11-09 20:36:50 +03:00
|
|
|
self::URI . '/search?q=' . urlencode($this->getInput('u'))
|
2022-01-02 12:36:09 +03:00
|
|
|
);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
for ($j = 0; $j < 5; $j++) {
|
|
|
|
if (strtolower($html->find('div.user', $j)->find('a', 0)->plaintext) == strtolower($this->getInput('u'))) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$html = getSimpleHTMLDOM(
|
|
|
|
self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href')
|
2022-01-02 12:36:09 +03:00
|
|
|
);
|
2017-02-11 18:16:56 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->userName = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
for ($i = 0; $i < 10; $i++) {
|
2014-07-18 15:19:02 +04:00
|
|
|
$track = $html->find('div.post', $i);
|
2017-02-11 18:16:56 +03:00
|
|
|
$item = [];
|
|
|
|
$item['author'] = $track->find('h2', 0)->plaintext;
|
|
|
|
$item['title'] = $track->find('h2', 0)->plaintext;
|
|
|
|
$item['content'] = $track->find('a.thumb', 0) . '<br/>' . $track->find('h2', 0)->plaintext;
|
|
|
|
$item['id'] = self::URI . $track->find('a.no-ajaxy', 0)->getAttribute('href');
|
|
|
|
$item['uri'] = self::URI . $track->find('a.no-ajaxy', 0)->getAttribute('href');
|
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2014-07-18 15:19:02 +04:00
|
|
|
public function getName()
|
|
|
|
{
|
2019-11-09 20:36:50 +03:00
|
|
|
return (!empty($this->userName) ? $this->userName . ' - ' : '') . 'Openwhyd Bridge';
|
2014-07-18 15:19:02 +04:00
|
|
|
}
|
|
|
|
}
|