22
33namespace Grav \Plugin \Flickr ;
44require_once (__DIR__ .'/Photoset.php ' );
5+ require_once (__DIR__ .'/Collection.php ' );
56
67use Grav \Common \Grav ;
78use Grav \Plugin \Flickr \Photoset ;
9+ use Grav \Plugin \Flickr \Collection ;
810use Grav \Common \GPM \Response ;
911use Grav \Common \Cache ;
1012
@@ -19,6 +21,7 @@ class FlickrAPI
1921{
2022 protected $ key ;
2123 protected $ secret ;
24+ protected $ user_id ;
2225 protected $ grav ;
2326 protected $ config ;
2427 protected $ cache ;
@@ -32,26 +35,41 @@ public function __construct()
3235 $ this ->config = $ this ->grav ['config ' ];
3336 $ this ->key = $ this ->config ->get ('plugins.flickr.flickr_api_key ' );
3437 $ this ->secret = $ this ->config ->get ('plugins.flickr.flickr_api_secret ' );
38+ $ this ->user_id = $ this ->config ->get ('plugins.flickr.flickr_user_id ' );
3539 $ this ->cache = new Cache ($ this ->grav );
3640 }
3741
38- /**
39- * do some work
40- */
4142 public function photoset ($ id , $ params )
4243 {
4344 $ info = $ this ->request ( ['method ' => 'flickr.photosets.getInfo ' , 'photoset_id ' => $ id ])['photoset ' ];
4445 $ get_photos_params = array_merge (
4546 [ "method " => "flickr.photosets.getPhotos " , "photoset_id " => $ id , 'user_id ' => $ info ['owner ' ], 'extras ' =>
46- '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 ' ],
47+ 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,views,media ' ],
4748 $ this ->get_params ($ params , ['page ' , 'per_page ' , 'privacy_filter ' , 'media ' ]));
4849
4950 $ photos = $ this ->request ( $ get_photos_params )['photoset ' ];
5051 return new Photoset ($ info , $ photos );
5152 }
5253
54+ public function photo ($ id )
55+ {
56+ $ info = $ this ->request ( ['method ' => 'flickr.photos.getInfo ' , 'photo_id ' => $ id ])['photo ' ];
57+ return new Photo ($ info );
58+ }
59+
60+ public function collection ($ id )
61+ {
62+ $ info = $ this ->request ( ['method ' => 'flickr.collections.getTree ' , 'collection_id ' => $ id ])['collections ' ];
63+ foreach ($ info ['collection ' ] as $ collection ) {
64+ if ( ! strpos ($ collection ['id ' ], $ id ) ) {
65+ return new Collection ($ collection , $ this );
66+ }
67+ }
68+ return null ; // TODO
69+ }
70+
5371 private function request ($ params ) {
54- $ url = 'https://api.flickr.com/services/rest/? ' . http_build_query (array_merge ($ params , ['api_key ' => $ this ->key , 'format ' => 'php_serial ' ]));
72+ $ url = 'https://api.flickr.com/services/rest/? ' . http_build_query (array_merge ($ params , ['api_key ' => $ this ->key , 'format ' => 'php_serial ' , ' user_id ' => $ this -> user_id ]));
5573 $ obj = $ this ->cache ->fetch ($ url );
5674 if ($ obj ) {
5775 return $ obj ;
0 commit comments