Skip to content

Commit 1f58e31

Browse files
authored
Merge pull request #32 from samwilson/photos
Move some photos methods and improve docs
2 parents bab195b + 3c61bc1 commit 1f58e31

File tree

2 files changed

+198
-32
lines changed

2 files changed

+198
-32
lines changed

src/PhotosApi.php

Lines changed: 166 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,171 @@ public function addTags($photoId, $tags)
7373
], true);
7474
}
7575

76-
//flickr.photos.delete
77-
//flickr.photos.getAllContexts
78-
//flickr.photos.getContactsPhotos
79-
//flickr.photos.getContactsPublicPhotos
80-
//flickr.photos.getContext
81-
//flickr.photos.getCounts
82-
//flickr.photos.getExif
83-
//flickr.photos.getFavorites
76+
/**
77+
* Delete a photo from flickr.
78+
*
79+
* @link https://www.flickr.com/services/api/flickr.photos.delete.html
80+
* @param $photoId string The ID of the photo to delete.
81+
* @return bool
82+
*/
83+
public function delete($photoId)
84+
{
85+
return (bool)$this->flickr->request('flickr.photos.delete', ['photo_id'=>$photoId], true);
86+
}
87+
88+
/**
89+
* Returns all visible sets and pools the photo belongs to.
90+
*
91+
* @link https://www.flickr.com/services/api/flickr.photos.getAllContexts.html
92+
* @param $photoId string The photo to return information for.
93+
* @return bool
94+
*/
95+
public function getAllContexts($photoId)
96+
{
97+
return $this->request('flickr.photos.getAllContexts', ['photo_id'=>$photoId]);
98+
}
99+
100+
/**
101+
* Fetch a list of recent photos from the calling users' contacts.
102+
*
103+
* @link https://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html
104+
* @param $count int|null Number of photos to return. Defaults to 10, maximum 50. This is only used if single_photo
105+
* is not passed.
106+
* @param $justFriends bool|null Set as 1 to only show photos from friends and family (excluding regular contacts).
107+
* @param $singlePhoto bool|null Only fetch one photo (the latest) per contact, instead of all photos in
108+
* chronological order.
109+
* @param $includeSelf bool|null Whether to include photos from the calling user.
110+
* @param $extras string|string[] An array or comma-delimited list of extra information to fetch for each returned
111+
* record. Currently supported fields include: license, date_upload, date_taken, owner_name, icon_server,
112+
* original_format, last_update. For more information see extras under flickr.photos.search.
113+
* @return mixed
114+
*/
115+
public function getContactsPhotos(
116+
$count = null,
117+
$justFriends = null,
118+
$singlePhoto = null,
119+
$includeSelf = null,
120+
$extras = null
121+
) {
122+
if (is_array($extras)) {
123+
$extras = join(',', $extras);
124+
}
125+
$params = [
126+
'count' => $count,
127+
'just_friends' => $justFriends,
128+
'single_photo' => $singlePhoto,
129+
'include_self'=> $includeSelf,
130+
'extras' => $extras
131+
];
132+
$response = $this->flickr->request('flickr.photos.getContactsPhotos', $params);
133+
return isset($response['photos']['photo']) ? $response['photos']['photo'] : false;
134+
}
135+
136+
/**
137+
* Fetch a list of recent public photos from a users' contacts.
138+
*
139+
* @link https://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html
140+
* @param $userId string The NSID of the user to fetch photos for.
141+
* @param $count int|null Number of photos to return. Defaults to 10, maximum 50. This is only used if $singlePhoto
142+
* is false.
143+
* @param $justFriends bool|null Whether to only show photos from friends and family (excluding regular contacts).
144+
* @param $singlePhoto bool|null Only fetch one photo (the latest) per contact, instead of all photos in
145+
* chronological order.
146+
* @param $includeSelf bool|null Whether to include photos from the user specified by $userId.
147+
* @param $extras string|string[]|null Array or comma-delimited list of extra information to fetch for each returned
148+
* record. Currently supported fields are: license, date_upload, date_taken, owner_name, icon_server,
149+
* original_format, last_update.
150+
* @return mixed
151+
*/
152+
public function getContactsPublicPhotos(
153+
$userId,
154+
$count = null,
155+
$justFriends = null,
156+
$singlePhoto = null,
157+
$includeSelf = null,
158+
$extras = null
159+
) {
160+
if (is_array($extras)) {
161+
$extras = join(',', $extras);
162+
}
163+
$params = [
164+
'user_id' => $userId,
165+
'count' => $count,
166+
'just_friends' => $justFriends,
167+
'single_photo' => $singlePhoto,
168+
'include_self'=> $includeSelf,
169+
'extras' => $extras
170+
];
171+
$response = $this->flickr->request('flickr.photos.getContactsPublicPhotos', $params);
172+
return isset($response['photos']['photo']) ? $response['photos']['photo'] : false;
173+
}
174+
175+
/**
176+
* Returns next and previous photos for a photo in a photostream.
177+
*
178+
* @link https://www.flickr.com/services/api/flickr.photos.getContext.html
179+
* @param $photoId string The ID of the photo to fetch the context for.
180+
* @return mixed
181+
*/
182+
public function getContext($photoId)
183+
{
184+
return $this->flickr->request('flickr.photos.getContext', ['photo_id' => $photoId]);
185+
}
186+
187+
/**
188+
* Gets a list of photo counts for the given date ranges for the calling user.
189+
*
190+
* @link https://www.flickr.com/services/api/flickr.photos.getCounts.html
191+
* @param $dates string|string[]|null Array or comma-delimited list of unix timestamps, denoting the periods to
192+
* return counts for. They should be specified smallest first.
193+
* @param $takenDates string|string[]|null Array or comma-delimited list of MySQL datetimes, denoting the periods to
194+
* return counts for. They should be specified smallest first.
195+
* @return bool
196+
*/
197+
public function getCounts($dates = null, $takenDates = null)
198+
{
199+
if (is_array($dates)) {
200+
$dates = join(',', $dates);
201+
}
202+
if (is_array($takenDates)) {
203+
$takenDates = join(',', $takenDates);
204+
}
205+
$params = ['dates' => $dates, 'taken_dates' => $takenDates];
206+
$response = $this->flickr->request('flickr.photos.getCounts', $params);
207+
return isset($response['photocounts']['photocount']) ? $response['photocounts']['photocount'] : false;
208+
}
209+
210+
/**
211+
* Retrieve a list of EXIF/TIFF/GPS tags for a given photo. The calling user must have permission to view the photo.
212+
*
213+
* @link https://www.flickr.com/services/api/flickr.photos.getExif.html
214+
* @param $photoId string The ID of the photo to fetch information for.
215+
* @param $secret string|null The secret for the photo. If the correct secret is passed then permissions-checking is
216+
* skipped. This enables the 'sharing' of individual photos by passing around the ID and secret.
217+
* @return mixed
218+
*/
219+
public function getExif($photoId, $secret = null)
220+
{
221+
$response = $this->flickr->request('flickr.photos.getExif', ['photo_id'=>$photoId, 'secret'=>$secret]);
222+
return isset($response['photo']) ? $response['photo'] : false;
223+
}
224+
225+
/**
226+
* Returns the list of people who have favorited a given photo.
227+
*
228+
* @link https://www.flickr.com/services/api/flickr.photos.getFavorites.html
229+
* @param $photoId string The ID of the photo to fetch the favoriters list for.
230+
* @param $page int|null The page of results to return. If this argument is omitted, it defaults to 1.
231+
* @param $perPage int|null Number of users to return per page. If this argument is omitted, it defaults to 10. The
232+
* maximum allowed value is 50.
233+
* @return mixed
234+
*/
235+
public function getFavorites($photoId, $page = null, $perPage = null)
236+
{
237+
$params = ['photo_id'=>$photoId, 'page'=>$page, 'per_page'=>$perPage];
238+
$response = $this->flickr->request('flickr.photos.getFavorites', $params);
239+
return isset($response['photo']) ? $response['photo'] : false;
240+
}
84241

85242
/**
86243
* Get information about a photo. The calling user must have permission to view the photo.
@@ -124,7 +281,7 @@ public function getSets($photoIds, $userId = null)
124281
if (!isset($sets['photoset'])) {
125282
return false;
126283
}
127-
284+
128285
// for users with more than 500 albums, we must search the photoId page by page (thanks, Flickr...)
129286
foreach (range(1, $sets['pages']) as $pageNum) {
130287
if ($pageNum > 1) {

src/PhpFlickr.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,59 +1071,68 @@ public function photos_addTags($photoId, $tags)
10711071
return $this->photos()->addTags($photoId, $tags);
10721072
}
10731073

1074+
/**
1075+
* @deprecated
1076+
*/
10741077
public function photos_delete($photo_id)
10751078
{
1076-
/* https://www.flickr.com/services/api/flickr.photos.delete.html */
1077-
$this->request("flickr.photos.delete", array("photo_id"=>$photo_id), true);
1078-
return $this->parsed_response ? true : false;
1079+
return $this->photos()->delete($photo_id);
10791080
}
10801081

1082+
/**
1083+
* @deprecated
1084+
*/
10811085
public function photos_getAllContexts($photo_id)
10821086
{
1083-
/* https://www.flickr.com/services/api/flickr.photos.getAllContexts.html */
1084-
$this->request("flickr.photos.getAllContexts", array("photo_id"=>$photo_id));
1085-
return $this->parsed_response ? $this->parsed_response : false;
1087+
return $this->photos()->getAllContexts($photo_id);
10861088
}
10871089

1090+
/**
1091+
* @deprecated
1092+
*/
10881093
public function photos_getContactsPhotos($count = null, $just_friends = null, $single_photo = null, $include_self = null, $extras = null)
10891094
{
1090-
/* https://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html */
1091-
$this->request("flickr.photos.getContactsPhotos", array("count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras));
1092-
return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
1095+
return $this->photos()->getContactsPhotos($count, $just_friends, $single_photo, $include_self, $extras);
10931096
}
10941097

1098+
/**
1099+
* @deprecated
1100+
*/
10951101
public function photos_getContactsPublicPhotos($user_id, $count = null, $just_friends = null, $single_photo = null, $include_self = null, $extras = null)
10961102
{
1097-
/* https://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html */
1098-
$this->request("flickr.photos.getContactsPublicPhotos", array("user_id"=>$user_id, "count"=>$count, "just_friends"=>$just_friends, "single_photo"=>$single_photo, "include_self"=>$include_self, "extras"=>$extras));
1099-
return $this->parsed_response ? $this->parsed_response['photos']['photo'] : false;
1103+
return $this->photos()->getContactsPublicPhotos($user_id, $count, $just_friends, $single_photo, $include_self, $extras);
11001104
}
11011105

1106+
/**
1107+
* @deprecated
1108+
*/
11021109
public function photos_getContext($photo_id, $num_prev = null, $num_next = null, $extras = null, $order_by = null)
11031110
{
1104-
/* https://www.flickr.com/services/api/flickr.photos.getContext.html */
1105-
return $this->call('flickr.photos.getContext', array('photo_id' => $photo_id, 'num_prev' => $num_prev, 'num_next' => $num_next, 'extras' => $extras, 'order_by' => $order_by));
1111+
return $this->photos()->getContext($photo_id);
11061112
}
11071113

1114+
/**
1115+
* @deprecated
1116+
*/
11081117
public function photos_getCounts($dates = null, $taken_dates = null)
11091118
{
1110-
/* https://www.flickr.com/services/api/flickr.photos.getCounts.html */
1111-
$this->request("flickr.photos.getCounts", array("dates"=>$dates, "taken_dates"=>$taken_dates));
1112-
return $this->parsed_response ? $this->parsed_response['photocounts']['photocount'] : false;
1119+
return $this->photos()->getCounts($dates, $taken_dates);
11131120
}
11141121

1122+
/**
1123+
* @deprecated
1124+
*/
11151125
public function photos_getExif($photo_id, $secret = null)
11161126
{
1117-
/* https://www.flickr.com/services/api/flickr.photos.getExif.html */
1118-
$this->request("flickr.photos.getExif", array("photo_id"=>$photo_id, "secret"=>$secret));
1119-
return $this->parsed_response ? $this->parsed_response['photo'] : false;
1127+
return $this->photos()->getExif($photo_id, $secret);
11201128
}
11211129

1130+
/**
1131+
* @deprecated
1132+
*/
11221133
public function photos_getFavorites($photo_id, $page = null, $per_page = null)
11231134
{
1124-
/* https://www.flickr.com/services/api/flickr.photos.getFavorites.html */
1125-
$this->request("flickr.photos.getFavorites", array("photo_id"=>$photo_id, "page"=>$page, "per_page"=>$per_page));
1126-
return $this->parsed_response ? $this->parsed_response['photo'] : false;
1135+
return $this->photos()->getFavorites($photo_id, $page, $per_page);
11271136
}
11281137

11291138
/**

0 commit comments

Comments
 (0)