function _media_flickr_photoset_load_photos in Media: Flickr 6
Returns an array of all URLs for photos associated with a photoset, associated by photo code. These will be of the Flickr specified size (1-5), and may be local or remote, based on settings and availability.
Parameters
$photoset: The Flickr photoset id. @param $size Optional. A number from 1-5 (small to large).
1 call to _media_flickr_photoset_load_photos()
- media_flickr_photoset_load_photos in ./
media_flickr.module - Returns an array of all URLs for photos associated with a photoset, associated by photo code. These will be of the Flickr specified size (1-5), and may be local or remote, based on settings and availability.
File
- ./
media_flickr.utilities.inc, line 197 - Utility functions for Media: Flickr.
Code
function _media_flickr_photoset_load_photos($photoset, $size = 5) {
static $photosets;
if (is_null($photosets)) {
$photosets = array();
}
$id = $photoset['photoset']['id'];
// We cache our results in a static variable.
if (is_null($photosets[$id])) {
// Reset the array of photos.
$photosets[$id] = array();
// If we're allowed to store images locally, then grab the latest list
// of local URL's.
if ($store_local = variable_get('media_flickr_store_local', FALSE)) {
$results = db_query("SELECT z.code, f.filepath FROM {media_flickr_sets} s INNER JOIN {media_flickr_sizes} z ON z.code = s.code AND z.size = %d INNER JOIN {files} f ON f.fid = z.fid WHERE s.photoset = '%s'", $size, $photoset['photoset']['id']);
while ($result = db_fetch_object($results)) {
$photosets[$id][$result->code] = $result->filepath;
}
}
// @TODO: remove 'dead' photos from photoset...
// Ensure we have a URL for each photo in the photoset.
// This can be local or remote.
foreach ($photoset['photoset']['photo'] as $photo_code => $photo) {
// If we don't have a URL yet, grab one.
if (!isset($photosets[$id][$photo_code])) {
// If we're allowed to store local photos, then attempt to do so now.
if ($store_local) {
// First ensure we have the photo associated with this photoset.
if (!db_result(db_query("SELECT COUNT(*) FROM {media_flickr_sets} WHERE photoset = '%s' AND code = '%s'", $id, $photo_code))) {
// The photo is newly associated to this photoset. Put it in place.
$record = array(
'photoset' => $id,
'code' => $photo_code,
);
drupal_write_record('media_flickr_sets', $record);
// Now record the metadata associated with a photo.
media_flickr_record_photo($photo_code);
// Now we'll try to grab the URL manually, as it may have already
// been stored locally through another photoset. If not, this will
// attempt to fetch a photo and store it, or return the remote URL.
$photosets[$id][$photo_code] = media_flickr_photo_url_from_size($photo_code, $size);
}
else {
// We have the proper association; we just need this size photo.
// Hopefully we'll grab a local photo. If not, we'll get the remote.
$photosets[$id][$photo_code] = media_flickr_store_local($photo_code, $size);
}
}
else {
// Let's be happy with the remote URL.
$photosets[$id][$photo_code] = media_flickr_photo_remote_url($photo_code, $size);
}
}
}
}
return $photosets[$id];
}