function privatesquare_export_geojson($fh, $checkins, $more = array())
{
    $features = array();
    $swlat = null;
    $swlon = null;
    $nelat = null;
    $nelon = null;
    foreach ($checkins as $row) {
        # See notes in privatesquare_export_csv for why we're
        # doing this explicitly (20120227/straup)
        $more = array('inflate_weather' => 1);
        privatesquare_export_massage_checkin($row, $more);
        $lat = floatval($row['latitude']);
        $lon = floatval($row['longitude']);
        $swlat = isset($swlat) ? min($swlat, $lat) : $lat;
        $swlon = isset($swlon) ? min($swlon, $lon) : $lon;
        $nelat = isset($nelat) ? max($nelat, $lat) : $lat;
        $nelon = isset($nelon) ? max($nelon, $lon) : $lon;
        $features[] = array('type' => 'Feature', 'id' => $row['id'], 'properties' => $row, 'geometry' => array('type' => 'Point', 'coordinates' => array($lon, $lat)));
    }
    $geojson = array('type' => 'FeatureCollection', 'bbox' => array($swlon, $swlat, $nelon, $nelat), 'features' => $features);
    fwrite($fh, json_encode($geojson));
    if (isset($more['donot_send'])) {
        return okay();
    }
    $map = privatesquare_export_valid_formats();
    $headers = array('Content-type' => $map['geojson']);
    privatesquare_export_send($fh, $headers, $more);
}
function privatesquare_export_send(&$fh, &$headers, $more = array())
{
    rewind($fh);
    $data = stream_get_contents($fh);
    $headers['Content-length'] = strlen($data);
    if (!isset($more['filename']) && !isset($more['inline'])) {
        $map = privatesquare_export_valid_formats("by mimetype");
        $ext = $map[$headers['Content-type']];
        $hash = md5($data);
        $more['filename'] = "privatesquare-{$hash}.{$ext}";
    }
    privatesquare_export_send_headers($headers, $more);
    echo $data;
    exit;
}
function privatesquare_export_csv($fh, $checkins, $more = array())
{
    # TO DO: this works fine until we want to "explode" specific
    # fields (like 'weather') because we need to find all the distinct
    # keys that might be used (across both fields and potential
    # providers: google weather versus some other api). This is
    # either a head scratch or a pain in the ass or both...
    # (2012027/straup)
    $header = 0;
    foreach ($checkins as $row) {
        privatesquare_export_massage_checkin($row);
        if (!$header) {
            fputcsv($fh, array_keys($row));
            $header = 1;
        }
        fputcsv($fh, array_values($row));
    }
    if (isset($more['donot_send'])) {
        return okay();
    }
    $map = privatesquare_export_valid_formats();
    $headers = array('Content-type' => $map['csv']);
    privatesquare_export_send($fh, $headers, $more);
}
Ejemplo n.º 4
0
if ($page = get_int32("page")) {
    $more['page'] = $page;
}
if ($when = get_str("when")) {
    $more['when'] = $when;
    $history_url .= urlencode($when) . "/";
    # TO DO: find some better heuristic for this number
    # besides "pull it out of my ass" (20120206/straup)
    $more['per_page'] = 100;
}
$more['inflate_locality'] = 1;
$rsp = privatesquare_checkins_for_user($owner, $more);
# TO DO: oh god...timezones :-(
if ($when) {
    list($start, $stop) = datetime_when_parse($more['when']);
    $GLOBALS['smarty']->assign("when", $when);
    $GLOBALS['smarty']->assign("start", $start);
    $GLOBALS['smarty']->assign("stop", $stop);
}
$status_map = privatesquare_checkins_status_map();
$GLOBALS['smarty']->assign_by_ref("status_map", $status_map);
$GLOBALS['smarty']->assign("pagination_url", $GLOBALS['cfg']['abs_root_url'] . $history_url);
$GLOBALS['smarty']->assign_by_ref("owner", $owner);
$GLOBALS['smarty']->assign_by_ref("is_own", $is_own);
$export_formats = privatesquare_export_valid_formats();
$GLOBALS['smarty']->assign("export_formats", array_keys($export_formats));
$geo_stats = privatesquare_checkins_utils_geo_stats($rsp['rows']);
$GLOBALS['smarty']->assign_by_ref("geo_stats", $geo_stats);
$GLOBALS['smarty']->assign_by_ref("checkins", $rsp['rows']);
$GLOBALS['smarty']->display("page_user_history.txt");
exit;