3969e32b8307bc67387f5049d5c390201d7dd4b1
2 * basic flickr search uses flickr jsonp api
3 * http://www.flickr.com/services/api/
5 * uses the "example api_key" 519b66e3fd8d8080e27a64fe51101e2c
6 * should update with a different "public" key sometime soon
7 * http://www.flickr.com/services/rest/?method=flickr.test.echo&format=json&api_key=519b66e3fd8d8080e27a64fe51101e2c
9 * we look for licenses from method=flickr.photos.licenses.getInfo
10 * per http://commons.wikimedia.org/wiki/Special:Upload?uselang=fromflickr
11 * we are interested in:
12 * (4) Attribution License
13 * (5) Attribution-ShareAlike License,
14 * (7) No known copyright restrictions,
15 * (8) United States Government Work
18 var flickrSearch = function ( iObj
) {
19 return this.init( iObj
);
21 flickrSearch
.prototype = {
22 dtUrl
: 'http://www.flickr.com/photos/',
23 // @@todo probably would be good to read the api-key from configuration
24 apikey
: '2867787a545cc66c0bce6f2e57aca1d1',
25 // what licence we are interested in
26 _licence_keys
: '4,5,7,8',
27 _srctypes
: ['t', 'sq', 's', 'm', 'o'],
29 '4' : 'http://creativecommons.org/licenses/by/3.0/',
30 '5' : 'http://creativecommons.org/licenses/by-sa/3.0/',
31 '7' : 'http://www.flickr.com/commons/usage/',
32 '8' : 'http://www.usa.gov/copyright.shtml'
34 init:function( iObj
) {
35 // init base class and inherit:
36 var baseSearch
= new baseRemoteSearch( iObj
);
37 for ( var i
in baseSearch
) {
38 if ( typeof this[i
] == 'undefined' ) {
39 this[i
] = baseSearch
[i
];
41 this['parent_' + i
] = baseSearch
[i
];
44 // inherit the cp settings for
46 getSearchResults:function() {
48 js_log( "flickr::getSearchResults" );
49 // call parent (sets loading sate and other setup stuff)
50 this.parent_getSearchResults();
51 // setup the flickr request:
53 'method':'flickr.photos.search',
55 'license':this._licence_keys
,
56 'api_key':this.apikey
,
57 'per_page': this.cp
.limit
,
58 'page' : this.cp
.offset
,
59 'text': $j( '#rsd_q' ).val(),
60 'extras' : 'license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, url_o'
64 'url':this.cp
.api_url
,
65 'jsonCB':'jsoncallback',
67 _this
.addResults( data
);
68 _this
.loading
= false;
71 addResults:function( data
) {
73 if ( data
.photos
&& data
.photos
.photo
) {
75 this.num_results
= data
.photos
.total
;
76 if ( this.num_results
> this.cp
.offset
+ this.cp
.limit
) {
77 this.more_results
= true;
79 for ( var resource_id
in data
.photos
.photo
) {
80 var resource
= data
.photos
.photo
[resource_id
];
83 'titleKey' : resource
.title
+ '.jpg',
84 'resourceKey': resource
.id
,
85 'link' : _this
.dtUrl
+ resource
.pathalias
+ '/' + resource
.id
,
86 'title' : resource
.title
,
87 'thumbwidth' : resource
.width_t
,
88 'thumbheight': resource
.height_t
,
89 'desc' : resource
.title
,
90 // set the license: (rsd is a pointer to the parent remoteSearchDriver )
91 'license' : this.rsd
.getLicenceFromUrl( _this
.licenceMap
[ resource
.license
] ),
93 // assume image/jpeg for "photos"
96 // set all the provided srcs:
98 for ( var i
in _this
._srctypes
) {
99 var st
= _this
._srctypes
[i
];
100 // if resource has a url add it to the srcSet:
101 if ( resource
['url_' + st
] ) {
102 rObj
['srcSet'][st
] = {
103 'h': resource
['height_' + st
],
104 'w': resource
['width_' + st
],
105 'src': resource
['url_' + st
]
107 // set src to the largest
108 rObj
['src'] = resource
['url_' + st
];
112 _this
.resultsObj
[ resource_id
] = rObj
;
116 // return image transform via callback
117 getImageObj:function( rObj
, size
, callback
) {
119 var skey
= this.getSrcTypeKey( rObj
, size
.width
)
121 'url' : rObj
.srcSet
[ skey
].src
,
122 'width' : rObj
.srcSet
[ skey
].w
,
123 'height' : rObj
.srcSet
[ skey
].h
127 getImageTransform:function( rObj
, opt
) {
129 return rObj
.srcSet
[ this.getSrcTypeKey( rObj
, opt
.width
) ].src
;
132 getSrcTypeKey:function( rObj
, width
) {
134 if ( rObj
.srcSet
['sq'] )
136 } else if ( width
<= 100 ) {
137 if ( rObj
.srcSet
['t'] )
139 } else if ( width
<= 240 ) {
140 if ( rObj
.srcSet
['s'] )
142 } else if ( width
<= 500 ) {
143 if ( rObj
.srcSet
['m'] )
146 if ( rObj
.srcSet
['o'] )
149 // original was missing return medium or small
150 if ( rObj
.srcSet
['m'] )
152 if ( rObj
.srcSet
['s'] )