summaryrefslogtreecommitdiff
path: root/bridges/WhydBridge.php
blob: d14c22a86b472d7023812fac06e512a1d85caac5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class WhydBridge extends BridgeAbstract {

	const MAINTAINER = 'kranack';
	const NAME = 'Whyd Bridge';
	const URI = 'http://www.whyd.com/';
	const CACHE_TIMEOUT = 600; // 10min
	const DESCRIPTION = 'Returns 10 newest music from user profile';

	const PARAMETERS = array( array(
		'u' => array(
			'name' => 'username/id',
			'required' => true
		)
	));

	private $userName = '';

	public function getIcon() {
		return self::URI . 'assets/favicons/
32-6b62a9f14d5e1a9213090d8f00f286bba3a6022381a76390d1d0926493b12593.png?v=6';
	}

	public function collectData(){
		$html = '';
		if(strlen(preg_replace('/[^0-9a-f]/', '', $this->getInput('u'))) == 24) {
			// is input the userid ?
			$html = getSimpleHTMLDOM(
				self::URI . 'u/' . preg_replace('/[^0-9a-f]/', '', $this->getInput('u'))
			) or returnServerError('No results for this query.');
		} else { // input may be the username
			$html = getSimpleHTMLDOM(
				self::URI . 'search?q=' . urlencode($this->getInput('u'))
			) or returnServerError('No results for this query.');

			for($j = 0; $j < 5; $j++) {
				if(strtolower($html->find('div.user', $j)->find('a', 0)->plaintext) == strtolower($this->getInput('u'))) {
					$html = getSimpleHTMLDOM(
						self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href')
					) or returnServerError('No results for this query');
					break;
				}
			}
		}
		$this->userName = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext;

		for($i = 0; $i < 10; $i++) {
			$track = $html->find('div.post', $i);
			$item = array();
			$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;
		}
	}
	public function getName(){
		return (!empty($this->userName) ? $this->userName . ' - ' : '') . 'Whyd Bridge';
	}
}