Просто чтобы обновить это, в конце концов я просто получил все фотографии из фотосета, а затем построил два массива лет и игроков из тегов.Наконец, я использовал запрос, чтобы вернуть правильные фотографии.Я использую отличную библиотеку phpFlickr и вот весь мой скрипт API:
<?php
// Initialise Flickr API library and authentication
require_once("phpFlickr.php");
$f = new phpFlickr('<api key>', '<secret>');
$f->setToken('<token>');
// Get all photos from the photoset
$page = 0;
$perpage = 500;
$all = array('photos' => array(), 'total' => 0);
while ($perpage * $page < $all['total'] || $all['total'] == 0) {
$p = $f->photosets_getPhotos('<photoset number>', 'tags', NULL, $perpage, $page + 1);
$all['total'] = (integer) $p['photoset']['total'];
$all['photos'] += $p['photoset']['photo'];
$page++;
}
// Get all the available years/players from the tags
$years = array();
$players = array();
foreach ($all['photos'] as $key => $photo) {
$photo_tags = explode(' ', $photo['tags']);
$all['photos'][$key]['tags'] = $photo_tags;
foreach ($photo_tags as $tag) {
if (preg_match('/^[0-9]{4}$/', $tag)) {
if (!in_array($tag, $years)) {
$years[] = $tag;
}
} else {
if (!in_array($tag, $players)) {
$players[] = $tag;
}
}
}
}
rsort($years);
sort($players);
// Set year/player tags if set
$tags = array();
if (isset($_GET['year']) && in_array($_GET['year'], $years)) {
$tags['year'] = $_GET['year'];
}
if (isset($_GET['player']) && in_array($_GET['player'], $players)) {
$tags['player'] = $_GET['player'];
}
// Build output array and filter by year/person
$output = array(
'years' => $years,
'players' => $players,
'photos' => array()
);
foreach ($all['photos'] as $key => $photo) {
if (!isset($tags['year']) || in_array($tags['year'], $photo['tags'])) {
if (!isset($tags['player']) || in_array($tags['player'], $photo['tags'])) {
$output['photos'][] = array(
'thumbnail' => $f->buildPhotoURL($photo, 'Square'),
'image' => $f->buildPhotoURL($photo, 'Large'),
'tags' => implode(' ', $photo['tags'])
);
}
}
}
$output['totals']['total'] = count($output['photos']);
// Calculate paging
$output['perpages'] = array(32, 64, 128, 256);
if (isset($_GET['perpage']) && in_array($_GET['perpage'], $output['perpages'])) {
$output['perpage'] = $_GET['perpage'];
} else {
$output['perpage'] = $output['perpages'][0];
}
if ($output['totals']['total'] <= $output['perpage']) {
$output['pages'] = 1;
} else {
$output['pages'] = ceil($output['totals']['total'] / $output['perpage']);
}
if (isset($_GET['page']) && intval($_GET['page']) > 0 && intval($_GET['page']) <= $output['pages']) {
$page = $_GET['page'];
} else {
$page = 1;
}
$output['totals']['recordstart'] = (($page == 1) ? 0 : (($page - 1) * $output['perpage']));
$output['totals']['recordend'] = ($output['totals']['recordstart'] + $output['perpage']) - 1;
if ($output['totals']['recordend'] > ($output['totals']['total'] - 1)) {
$output['totals']['recordend'] = $output['totals']['total'] - 1;
}
$photos = array();
foreach ($output['photos'] as $index => $photo) {
if ($index >= $output['totals']['recordstart'] && $index <= $output['totals']['recordend']) {
$photos[] = $photo;
}
}
unset($output['photos']);
$output['photos'] = $photos;
ob_start("ob_gzhandler");
echo json_encode($output);
Надеюсь, кто-то найдет это полезным!
Дан