Example #1
0
/**** ... ****/
$error = '';
if (isset($_POST['form_url'])) {
    if (empty($_POST['form_url'])) {
        $error = "Empty or missing form_url.";
    }
    if (empty($error)) {
        $added_form = add_form($context->db, $context->user['id']);
        $added_form['form_url'] = $_POST['form_url'];
        if (!empty($_POST['form_title'])) {
            $added_form['title'] = $_POST['form_title'];
        }
        set_form($context->db, $added_form);
        $message = array('action' => 'import form', 'url' => $_POST['form_url'], 'form_id' => $added_form['id']);
        // queue the task
        queue_task("tasks.parseForm", array("http://" . SERVER_NAME, API_PASSWORD), $message);
        $form_url = 'http://' . get_domain_name() . get_base_dir() . '/form.php?id=' . urlencode($added_form['id']);
        header("Location: {$form_url}");
        exit;
    }
}
if ($context->type == 'text/html') {
    if (!empty($error)) {
        $context->sm->assign('error', $error);
    }
    header("Content-Type: text/html; charset=UTF-8");
    print $context->sm->fetch("add-form.html.tpl");
} else {
    header('HTTP/1.1 400');
    $error = "Unknown type.";
    $context->sm->assign('error', $error);
Example #2
0
/**
 * Convert a string of GeoJSON data to an atlas composition and queue it up.
 */
function compose_from_geojson(&$dbh, $data)
{
    $json = json_decode($data, true);
    if (!is_geojson($json)) {
        return null;
    }
    //
    // Move on to the actual business of converting GeoJSON to an atlas.
    // Start with a global paper size and orientation for the full document.
    //
    $p = $json['properties'];
    $paper_size = is_array($p) && isset($p['paper_size']) ? $p['paper_size'] : 'letter';
    $orientation = is_array($p) && isset($p['orientation']) ? $p['orientation'] : 'portrait';
    $layout = is_array($p) && isset($p['layout']) ? $p['layout'] : 'full-page';
    //
    // "orientation" above refers to the *map*, so if we want half-size
    // we'll need to flip the orientation of the overall printed sheet
    // to accommodate it.
    //
    if ($orientation == 'landscape' && $layout == 'half-page') {
        $orientation = 'portrait';
    } elseif ($orientation == 'portrait' && $layout == 'half-page') {
        $orientation = 'landscape';
    }
    list($printed_width, $printed_height) = get_printed_dimensions($paper_size, $orientation, $layout);
    $printed_aspect = $printed_width / $printed_height;
    $paper_type = "{$orientation}, {$paper_size}";
    $message = array('action' => 'compose', 'paper_size' => $paper_size, 'orientation' => $orientation, 'layout' => $layout, 'pages' => array());
    //
    // Iterate over each feature and determine an appropriate extent and zoom.
    // Each feature in the GeoJSON becomes a single page in the atlas.
    //
    foreach ($json['features'] as $f => $feature) {
        $number = $f + 1;
        //
        // Check the properties for a provider and explicit zoom.
        //
        $p = $feature['properties'];
        $provider = is_array($p) && isset($p['provider']) ? new MMaps_Templated_Spherical_Mercator_Provider($p['provider']) : new MMaps_OpenStreetMap_Provider();
        $explicit_zoom = is_array($p) && is_numeric($p['zoom']);
        $zoom = $explicit_zoom ? intval($p['zoom']) : 16;
        $mark = is_array($p['mark']) ? $p['mark'] : null;
        $fuzzy = is_array($p['fuzzy']) ? $p['fuzzy'] : null;
        $text = isset($p['text']) ? $p['text'] : null;
        //
        // Determine extent based on geometry type and zoom level.
        //
        $extent = null;
        if ($feature['geometry']['type'] == 'Point') {
            $extent = geojson_point_extent($feature['geometry'], $zoom);
        } elseif ($feature['geometry']['type'] == 'Polygon') {
            $extent = geojson_polygon_extent($feature['geometry']);
        } else {
            die_with_code(500, "I don't know how to do this yet, sorry.");
        }
        //
        // If we got this far, we know we have a meaningful zoom and extent
        // for this page, now adjust it to the known aspect ratio of the page.
        //
        $_mmap = MMaps_mapByExtentZoom($provider, $extent[0], $extent[1], $zoom);
        $dim = $_mmap->dimensions;
        $_mmap_center = $_mmap->pointLocation(new MMaps_Point($dim->x / 2, $dim->y / 2));
        $_mmap_aspect = $dim->x / $dim->y;
        if ($printed_aspect > $_mmap_aspect) {
            // paper is wider than the map
            $dim->x *= $printed_aspect / $_mmap_aspect;
        } else {
            // paper is taller than the map
            $dim->y *= $_mmap_aspect / $printed_aspect;
        }
        $mmap = MMaps_mapByCenterZoom($provider, $_mmap_center, $zoom, $dim);
        $provider = join(',', $mmap->provider->templates);
        $northwest = $mmap->pointLocation(new MMaps_Point(0, 0));
        $southeast = $mmap->pointLocation($mmap->dimensions);
        $bounds = array($northwest->lat, $northwest->lon, $southeast->lat, $southeast->lon);
        $message['pages'][] = compact('number', 'provider', 'bounds', 'zoom', 'text', 'mark', 'fuzzy');
    }
    //
    // Make room in the database for the new print and all its pages.
    //
    $print = add_print($dbh, 'nobody');
    $print['paper_size'] = $message['paper_size'];
    $print['orientation'] = $message['orientation'];
    $print['layout'] = $message['layout'];
    $print['north'] = $message['pages'][0]['bounds'][0];
    $print['south'] = $message['pages'][0]['bounds'][2];
    $print['west'] = $message['pages'][0]['bounds'][1];
    $print['east'] = $message['pages'][0]['bounds'][3];
    foreach ($message['pages'] as $_page) {
        $page = add_print_page($dbh, $print['id'], $_page['number']);
        $page['text'] = $_page['text'];
        $page['provider'] = $_page['provider'];
        $page['zoom'] = $_page['zoom'];
        $page['north'] = $_page['bounds'][0];
        $page['south'] = $_page['bounds'][2];
        $page['west'] = $_page['bounds'][1];
        $page['east'] = $_page['bounds'][3];
        set_print_page($dbh, $page);
        $print['north'] = max($print['north'], $page['north']);
        $print['south'] = min($print['south'], $page['south']);
        $print['west'] = min($print['west'], $page['west']);
        $print['east'] = max($print['east'], $page['east']);
    }
    $print['progress'] = 0.1;
    // the first 10% is getting it queued
    set_print($dbh, $print);
    $message['print_id'] = $print['id'];
    // queue the task
    queue_task("tasks.composePrint", array("http://" . SERVER_NAME, API_PASSWORD), $message);
    return $print;
}
Example #3
0
}
if ($scan && $object_id && $expected_etag) {
    $url = s3_unsigned_object_url($object_id, time() + 300, 'HEAD');
    $etag_match = verify_s3_etag($object_id, $expected_etag);
    $attempted_upload = true;
    $acceptable_upload = $etag_match;
} elseif ($scan && $url) {
    // it's probably fine if a whole URL is being sent over
    $attempted_upload = true;
    $acceptable_upload = preg_match('#^http://#', $url);
}
if ($attempted_upload && !$acceptable_upload) {
    die_with_code(400, 'Sorry, something about your file was bad');
}
if ($acceptable_upload && $scan && !$scan['decoded']) {
    queue_task("tasks.decodeScan", array("http://" . SERVER_NAME, API_PASSWORD), array("action" => "decode", "scan_id" => $scan["id"], "url" => $url));
    $context->db->query('START TRANSACTION');
    $scan = get_scan($context->db, $scan['id']);
    $parsed_url = parse_url($url);
    $scan['base_url'] = "http://{$parsed_url['host']}" . dirname($parsed_url['path']);
    $scan['progress'] = 0.1;
    // the first 10% is just getting the thing uploaded
    set_scan($context->db, $scan);
    $context->db->query('COMMIT');
}
if ($attempted_upload) {
    header('Location: http://' . get_domain_name() . get_base_dir() . '/snapshot.php?id=' . urlencode($scan['id']));
}
exit;
//
// Old form stuff down here.