loadlib("privatesquare_export"); loadlib("reverse_geoplanet"); login_ensure_loggedin($_SERVER['REQUEST_URI']); $owner = $GLOBALS['cfg']['user']; $GLOBALS['smarty']->assign_by_ref("owner", $owner); $venue_id = get_str("venue_id"); $venue = foursquare_venues_get_by_venue_id($venue_id); if (!$venue) { error_404(); } $venue['data'] = json_decode($venue['data'], "as hash"); $venue['locality'] = reverse_geoplanet_get_by_woeid($venue['locality'], 'locality'); # TO DO: account for pagination and > n checkins $more = array('venue_id' => $venue_id); $checkins = privatesquare_checkins_for_user($owner, $more); $venue['checkins'] = $checkins['rows']; $status_map = privatesquare_checkins_status_map(); $broadcast_map = foursquare_checkins_broadcast_map(); $GLOBALS['smarty']->assign_by_ref("status_map", $status_map); $GLOBALS['smarty']->assign_by_ref("broadcast_map", $broadcast_map); $GLOBALS['smarty']->assign_by_ref("venue", $venue); $checkin_crumb = crumb_generate("api", "privatesquare.venues.checkin"); $GLOBALS['smarty']->assign("checkin_crumb", $checkin_crumb); # did we arrive here from a checkin page? $success = get_str("success") ? 1 : 0; $GLOBALS['smarty']->assign("success", $success); $GLOBALS['smarty']->assign("venue_id", $venue_id); $export_formats = privatesquare_export_valid_formats(); $GLOBALS['smarty']->assign("export_formats", array_keys($export_formats)); $GLOBALS['smarty']->display("page_venue.txt"); exit;
<?php include "include/init.php"; dumper(crumb_generate("api", "test.echo")); exit;
function api_foursquare_venues_search() { $lat = request_float('latitude'); $lon = request_float('longitude'); $alt = request_float('altitude'); $query = request_str('query'); # See this? It's a quick and dirty shim until I can figure # out how to pass 'sort' flags via the UI (20120201/straup) # $sort = request_float('sort'); $sort = $GLOBALS['cfg']['foursquare_venues_sort']; $sort_func = "_api_foursquare_venues_sort_by_name"; if ($sort == 'distance') { $sort_func = "_api_foursquare_venues_sort_by_distance"; } if (!$lat || !geo_utils_is_valid_latitude($lat)) { api_output_error(999, "Missing or invalid latitude"); } if (!$lat || !geo_utils_is_valid_longitude($lon)) { api_output_error(999, "Missing or invalid longitude"); } $checkin_crumb = crumb_generate("api", "privatesquare.venues.checkin"); $fsq_user = foursquare_users_get_by_user_id($GLOBALS['cfg']['user']['id']); $method = 'venues/search'; if ($query) { $args = array('oauth_token' => $fsq_user['oauth_token'], 'll' => "{$lat},{$lon}", 'radius' => 1200, 'limit' => 30, 'intent' => 'match', 'query' => $query); $rsp = foursquare_api_call($method, $args); if (!$rsp['ok']) { _api_foursquare_error($rsp); } $venues = $rsp['rsp']['venues']; usort($venues, $sort_func); $out = array('venues' => $venues, 'query' => $query, 'latitude' => $lat, 'longitude' => $lon, 'crumb' => $checkin_crumb); api_output_ok($out); } $random_user = foursquare_users_random_user(); if (!$random_user) { $random_user = $fsq_user; } # https://developer.foursquare.com/docs/venues/search # TO DO: api_call_multi # first get stuff scoped to the current user $args = array('oauth_token' => $fsq_user['oauth_token'], 'll' => "{$lat},{$lon}", 'limit' => 30, 'intent' => 'checkin'); $rsp = foursquare_api_call($method, $args); if (!$rsp['ok']) { _api_foursquare_error($rsp); } $venues = array(); $seen = array(); foreach ($rsp['rsp']['venues'] as $v) { $venues[] = $v; $seen[] = $v['id']; } # now just get whatever $args = array('oauth_token' => $random_user['oauth_token'], 'll' => "{$lat},{$lon}", 'limit' => 30, 'radius' => 800, 'intent' => 'browse'); $rsp = foursquare_api_call($method, $args); if (!$rsp['ok']) { _api_foursquare_error($rsp); } foreach ($rsp['rsp']['venues'] as $v) { if (!in_array($v['id'], $seen)) { $venues[] = $v; } } usort($venues, $sort_func); # go! $out = array('venues' => $venues, 'latitude' => $lat, 'longitude' => $lon, 'crumb' => $checkin_crumb); api_output_ok($out); }
function crumb_qs($key = "") { $crumb = crumb_generate($key); return 'crumb=' . urlencode($crumb); }
function crumb_qs($key, $target = '') { $q = array('crumb' => crumb_generate($key, $target)); return http_build_query($q); }