function api_spec_methods()
{
    $export_keys = array('method', 'description', 'requires_auth', 'parameters', 'errors', 'notes', 'example');
    $defaults = array('method' => 'GET', 'requires_auth' => 0, 'description' => '', 'parameters' => array(), 'errors' => array());
    $methods = array();
    foreach ($GLOBALS['cfg']['api']['methods'] as $name => $details) {
        if (!$details['enabled']) {
            continue;
        }
        if (!$details['documented']) {
            continue;
        }
        $details = array_merge($defaults, $details);
        $method = array('name' => $name);
        foreach ($export_keys as $k) {
            if (!isset($details[$k])) {
                continue;
            }
            $v = $details[$k];
            $method[$k] = $v;
        }
        $rsp = api_spec_utils_example_for_method($name);
        if ($rsp['ok']) {
            $method['example'] = $rsp['example'];
        }
        $methods[] = $method;
    }
    api_output_ok(array('methods' => $methods));
}
function api_dots_dotsForUser()
{
    // these keys not important
    $skipKeys = array("details", "details_json", "index_on", "details_listview", "type_of_co");
    $u = request_str('user');
    $owner = users_get_by_id($u);
    $output = array();
    if ($owner) {
        $dots = dots_get_dots_for_user($owner);
        // please say there is a better way
        if ($dots) {
            foreach ($dots as &$row) {
                $a = array();
                foreach ($row as $k => $v) {
                    if (!in_array($k, $skipKeys)) {
                        $a[$k] = $v;
                    }
                }
                $output[] = $a;
            }
        }
    }
    if (count($output)) {
        api_output_ok($output);
    } else {
        api_output_error();
    }
}
function api_test_echo()
{
    $out = array();
    foreach ($_GET as $k => $ignore) {
        if ($k = filter_strict($k)) {
            $v = filter_strict(get_str($k));
            $out[$k] = $v;
        }
    }
    api_output_ok($out);
}
function api_privatesquare_venues_checkin()
{
    $venue_id = post_str("venue_id");
    $status_id = post_int32("status_id");
    if (!$venue_id) {
        api_output_error(999, "Missing venue ID");
    }
    if (!isset($status_id)) {
        api_output_error(999, "Missing status ID");
    }
    $fsq_user = foursquare_users_get_by_user_id($GLOBALS['cfg']['user']['id']);
    $checkin = array('user_id' => $GLOBALS['cfg']['user']['id'], 'venue_id' => $venue_id, 'status_id' => $status_id);
    # where am I?
    $venue = foursquare_venues_get_by_venue_id($venue_id);
    if (!$venue) {
        $rsp = foursquare_venues_archive_venue($venue_id);
        if ($rsp['ok']) {
            $venue = $rsp['venue'];
        }
    }
    if ($venue) {
        $checkin['locality'] = $venue['locality'];
        $checkin['latitude'] = $venue['latitude'];
        $checkin['longitude'] = $venue['longitude'];
    }
    # check to see if we're checking in to 4sq too
    if ($broadcast = post_str("broadcast")) {
        $method = 'checkins/add';
        $args = array('oauth_token' => $fsq_user['oauth_token'], 'venueId' => $venue_id, 'broadcast' => $broadcast);
        $more = array('method' => 'POST');
        $rsp = foursquare_api_call($method, $args, $more);
        if ($rsp['ok']) {
            $checkin['checkin_id'] = $rsp['rsp']['checkin']['id'];
        }
        # on error, then what?
    }
    if ($GLOBALS['cfg']['enable_feature_weather_tracking']) {
        loadlib("weather_google");
        $rsp = weather_google_conditions($checkin['latitude'], $checkin['longitude']);
        if ($rsp['ok']) {
            $conditions = $rsp['conditions'];
            $conditions['source'] = $rsp['source'];
            $checkin['weather'] = json_encode($conditions);
        }
    }
    $rsp = privatesquare_checkins_create($checkin);
    if (!$rsp['ok']) {
        api_output_error(999, "Check in failed");
    }
    $out = array('checkin' => $rsp['checkin']);
    api_output_ok($out);
}
Beispiel #5
0
function api_test_echo()
{
    $out = array();
    foreach ($_GET as $k => $ignore) {
        if ($GLOBALS['cfg']['api_auth_type'] == 'oauth2' && $k == 'access_token') {
            continue;
        }
        if ($k = filter_strict($k)) {
            $v = filter_strict(get_str($k));
            $out[$k] = $v;
        }
    }
    api_output_ok($out);
}
function api_flickr_favorites_remove()
{
    $flickr_user = api_utils_flickr_ensure_token_perms($GLOBALS['cfg']['user'], 'write');
    $photo_id = post_int64("photo_id");
    if (!$photo_id) {
        api_output_error(999, "Missing photo ID");
    }
    $method = 'flickr.favorites.remove';
    $args = array('photo_id' => $photo_id, 'auth_token' => $flickr_user['auth_token']);
    $rsp = flickr_api_call($method, $args);
    # Just ignore if not in faves already...
    if (!$rsp['ok'] && $rsp['error_code'] != '1') {
        api_output_error(999, $rsp['error']);
    }
    $out = array('photo_id' => $photo_id);
    api_output_ok($out);
}
function api_flickr_photos_friends_faves()
{
    if (!$GLOBALS['cfg']['enable_feature_flickr_push']) {
        api_output_error(999, "disabled");
    }
    if (!$GLOBALS['cfg']['flickr_push_enable_photos_friends_faves']) {
        api_output_error(999, "disabled");
    }
    $topic_map = flickr_push_topic_map("string keys");
    $topic_id = $topic_map["contacts_faves"];
    $sub = flickr_push_subscriptions_get_by_user_and_topic($GLOBALS['cfg']['user'], $topic_id);
    if (!$sub) {
        api_output_error(999, "no subscription");
    }
    $older_than = get_int32("older_than");
    $rsp = flickr_push_photos_for_subscription($sub, $older_than);
    if (!$rsp['ok']) {
        api_output_error(999, $rsp['error']);
    }
    $out = array('photos' => $rsp['rows']);
    $more = array('inline' => 1);
    api_output_ok($out, $more);
}
Beispiel #8
0
<?php

include "include/init.php";
loadlib("reverse_geoplanet");
loadlib("api_output");
$lat = get_str('lat');
$lon = get_str('lon');
$ll = get_str('ll');
$more = array('inline' => get_str('inline'));
if ($ll) {
    list($lat, $lon) = explode(",", $ll, 2);
    $lat = trim($lat);
    $lon = trim($lon);
}
if ($lat == '' || $lon == '') {
    api_output_error(999, "Missing lat/lon", $more);
}
$rsp = reverse_geoplanet($lat, $lon);
if (!$rsp['ok']) {
    api_output_error(999, $rsp['error'], $more);
}
api_output_ok($rsp['data'], $more);
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 api_flickr_photos_geo_possibleCorrections()
{
    $photo_id = get_int64("photo_id");
    $photo = _api_flickr_photos_geo_get_photo($photo_id);
    $type = get_str("place_type");
    if (!$type) {
        api_output_error(999, "Missing place type");
    }
    if (!flickr_places_is_valid_placetype($type)) {
        api_output_error(999, "Invalid place type");
    }
    # TO DO: calculate based on $type
    $radius = 1.5;
    $bbox = geo_utils_bbox_from_point($photo['latitude'], $photo['longitude'], $radius, 'km');
    $bbox = implode(",", array($bbox[1], $bbox[0], $bbox[3], $bbox[2]));
    $method = 'flickr.places.placesForBoundingBox';
    $args = array('bbox' => $bbox, 'place_type' => $type);
    $rsp = flickr_api_call($method, $args);
    if (!$rsp['ok']) {
        api_output_error(999, "Flickr API error");
    }
    $possible = array();
    if ($rsp['rsp']['places']['total']) {
        foreach ($rsp['rsp']['places']['place'] as $place) {
            $possible[] = array('woeid' => $place['woeid'], 'placetype' => $place['place_type'], 'name' => $place['_content']);
        }
    }
    $parent = flickr_places_parent_placetype($type);
    $out = array('place_type' => $type, 'parent_place_type' => $parent, 'places' => $possible);
    return api_output_ok($out);
}