Esempio n. 1
0
function flickr_urls_photos_user_place(&$user, &$place, $geo_context = 0)
{
    $places = flickr_urls_photos_user_places($user);
    $url = "{$places}{$place['woeid']}/";
    if ($geo_context) {
        loadlib("flickr_photos_geo");
        $map = flickr_photos_geo_context_map();
        $url .= "{$map[$geo_context]}/";
    }
    return $url;
}
function flickr_photos_places_contexts_for_user_and_place(&$user, &$place, $more = array())
{
    $defaults = array('viewer_id' => 0);
    $more = array_merge($defaults, $more);
    $more['enforce_geoperms'] = 1;
    if (!flickr_places_is_valid_placetype($place['place_type'])) {
        return not_okay("not a valid placetype");
    }
    $query = array("user_id" => $user['id'], $place['place_type'] => $place['woeid']);
    $map = flickr_photos_geo_context_map();
    $contexts = array();
    foreach ($map as $ctx => $ignore) {
        $contexts[$ctx] = 0;
    }
    $rsp = flickr_photos_search_facet($query, 'geocontext', $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    foreach ($rsp['facets'] as $ctx => $count) {
        $contexts[$ctx] = $count;
    }
    return okay(array('contexts' => $contexts));
}
$more = array('viewer_id' => $GLOBALS['cfg']['user']['id']);
if ($page = get_int32("page")) {
    $more['page'] = $page;
}
if ($context = get_str("context")) {
    $str_map = flickr_photos_geo_context_map("string keys");
    if (isset($str_map[$context])) {
        $geo_context = $str_map[$context];
        $more['geocontext'] = $geo_context;
        $GLOBALS['smarty']->assign("context", $context);
        $GLOBALS['smarty']->assign("geo_context", $geo_context);
    }
} else {
    $rsp = flickr_photos_places_contexts_for_user_and_place($owner, $place, $more);
    if ($rsp['ok']) {
        $GLOBALS['smarty']->assign("geo_contexts", $rsp['contexts']);
        $ctx_map = flickr_photos_geo_context_map();
        $GLOBALS['smarty']->assign_by_ref("geo_contexts_map", $ctx_map);
    }
}
$rsp = flickr_photos_places_for_user($owner, $place, $more);
if (!$rsp['ok']) {
    $GLOBALS['cfg']['error'] = $rsp['error'];
} else {
    $pagination_url = flickr_urls_photos_user_place($owner, $place, $geo_context);
    $GLOBALS['smarty']->assign_by_ref("photos", $rsp['rows']);
    $GLOBALS['smarty']->assign("pagination_url", $pagination_url);
}
# go!
$GLOBALS['smarty']->display("page_flickr_photos_user_place.txt");
exit;
function flickr_photos_geo_is_valid_context($context)
{
    $map = flickr_photos_geo_context_map();
    return isset($map[$context]) ? 1 : 0;
}
$GLOBALS['smarty']->assign_by_ref("owner", $owner);
$GLOBALS['smarty']->assign("is_own", $is_own);
$facet = get_str("facet");
$placetypes = flickr_places_valid_placetypes();
if (!$facet || !flickr_places_is_valid_placetype($facet)) {
    $rand = rand(1, count($placetypes));
    $facet = $placetypes[$rand - 1];
}
$GLOBALS['smarty']->assign_by_ref("placetypes", $placetypes);
$GLOBALS['smarty']->assign("facet", $facet);
# TO DO: easter egg to make 'airports' a valid place type/url
# to query by; this will probably mean indexing the place name
# in solr which is probably not a bad idea anyway (20111229/straup)
$more = array('viewer_id' => $GLOBALS['cfg']['user']['id']);
if ($context = get_str("context")) {
    $map = flickr_photos_geo_context_map("string keys");
    if (isset($map[$context])) {
        $geo_context = $map[$context];
        $more['geocontext'] = $geo_context;
        $GLOBALS['smarty']->assign("context", $context);
        $GLOBALS['smarty']->assign("geo_context", $geo_context);
    }
}
$rsp = flickr_photos_places_for_user_facet($owner, $facet, $more);
if ($rsp['ok']) {
    $locations = array();
    foreach ($rsp['facets'] as $woeid => $ignore) {
        $loc = flickr_places_get_by_woeid($woeid);
        $locations[$woeid] = $loc;
    }
    $GLOBALS['smarty']->assign_by_ref("facets", $rsp['facets']);