aboutsummaryrefslogtreecommitdiff
path: root/bridges/FlickrTagBridge.php
blob: 61f59a266eaa98fed868288065ad1e21febb3316 (plain) (blame)
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
62
63
64
65
66
<?php
class FlickrTagBridge extends BridgeAbstract{

	public function loadMetadatas() {

		$this->maintainer = "erwang";
		$this->name = "Flickr TagUser";
		$this->uri = "http://www.flickr.com/";
		$this->description = "Returns the tagged or user images from Flickr";
		$this->update = "2016-08-09";

		$this->parameters["By keyword"] =
		'[
			{
				"name" : "Keyword",
				"identifier" : "q"
			}
		]';

		$this->parameters["By username"] =
		'[
			{
				"name" : "Username",
				"identifier" : "u"
			}
		]';
	}

    public function collectData(array $param){
        $html = $this->file_get_html('http://www.flickr.com/search/?q=vendee&s=rec') or $this->returnError('Could not request Flickr.', 404);
        if (isset($param['q'])) {   /* keyword search mode */
            $this->request = $param['q'];
            $html = $this->file_get_html('http://www.flickr.com/search/?q='.urlencode($this->request).'&s=rec') or $this->returnError('No results for this query.', 404);
        }
        elseif (isset($param['u'])) {   /* user timeline mode */
            $this->request = $param['u'];
            $html = $this->file_get_html('http://www.flickr.com/photos/'.urlencode($this->request).'/') or $this->returnError('Requested username can\'t be found.', 404);
        }
        
        else {
            $this->returnError('You must specify a keyword or a Flickr username.', 400);
        }

        foreach($html->find('span.photo_container') as $element) {
            $item = new \Item();
            $item->uri = 'http://flickr.com'.$element->find('a',0)->href;
            $thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
            $item->content = '<a href="' . $item->uri . '"><img src="' . $thumbnailUri . '" /></a>'; // FIXME: Filter javascript ?
            $item->title = $element->find('a',0)->title;
            $this->items[] = $item;
        }
    }

    public function getName(){
        return 'Flickr Tag';
    }

    public function getURI(){
        return 'http://www.flickr.com/search/';
    }

    public function getCacheDuration(){
        return 21600; // 6 hours
    }
}