Esempio n. 1
0
function map_js_defs($spec, $options, $btns)
{
    $key = clb_tag('script', '', '', array('src' => 'http://www.google.com/jsapi?key=' . GOOGLE_API_KEY, 'type' => 'text/javascript'));
    $script = 'google.load(\'maps\', \'2\');' . "\n";
    $script .= 'Event.observe(window, \'load\', function (){map_setup(' . clb_json($options) . ',' . clb_json($btns) . ');});' . "\n";
    $script .= 'var map_marker_spec = ' . clb_json($spec);
    $script = clb_tag('script', '', $script, array('type' => 'text/javascript'));
    return $key . "\n" . $script;
}
Esempio n. 2
0
function pfind_service($prms, $pfind_defs, $type_names, $p2p_paths, $node_types = FALSE)
{
    clb_timing(__LINE__);
    pfind_def_tables($pfind_defs);
    $result = array('error' => 200, 'error_str' => 'no errors');
    //get the query or way points from the request
    $entries = array();
    if (isset($prms['q']) && $prms['q']) {
        $entries[] = $prms['q'];
    } else {
        $w = 0;
        while (isset($prms['w' . $w])) {
            $entries[] = $prms['w' . $w];
            $w++;
        }
    }
    $prop = array();
    $prop['service'] = strtolower(clb_val('json', $prms, 's'));
    //json, xml
    $prop['mode'] = strtolower(clb_val('', $prms, 'm'));
    $prop['units'] = strtolower(clb_val('mi', $prms, 'u'));
    //km, mi
    $prop['opto'] = strtolower(clb_val('best', $prms, 'o'));
    //dist, change, best
    $prop['opacity'] = strtolower(clb_val(0.5, $prms, 't'));
    $prop['color'] = strtolower(clb_val('#0000FF', $prms, 'c'));
    $prop['stroke'] = strtolower(clb_val(5, $prms, 'k'));
    $dist_only = FALSE != clb_val(0, $prms, 'gd');
    //get result from precalculated distances
    $prop['dist_only'] = $dist_only;
    $prop['getSteps'] = !$dist_only && FALSE != clb_val(0, $prms, 'gs');
    $prop['getPolyline'] = !$dist_only && FALSE != clb_val(0, $prms, 'gp');
    $path = FALSE;
    $mode = $prop['mode'];
    if (is_string($p2p_paths)) {
        $path = $p2p_paths;
    } else {
        if (!is_array($p2p_paths)) {
            $result = array('error' => 500, 'error_str' => 'server configuration error: route tables not specified');
        } else {
            if ($mode && isset($p2p_paths[$mode])) {
                $path = $p2p_paths[$mode];
            } else {
                if (isset($p2p_paths['rtm'])) {
                    $node_types = array('rail', 'tube', 'tram');
                    $path = $p2p_paths['rtm'];
                } else {
                    $path = reset($p2p_paths);
                }
            }
        }
    }
    if (is_array($path)) {
        if (!$node_types) {
            $node_types = clb_val(FALSE, $path, 'types');
        }
        //get the types
        $path = clb_val(FALSE, $path, 'path');
    }
    //if types not given as param or with paths, but the mode name is a node type use it as default.
    if (!$node_types && clb_val(FALSE, $type_names, $prop['mode'])) {
        $node_types = $prop['mode'];
    }
    if ($node_types && !is_array($node_types)) {
        $node_types = array($node_types);
    }
    //make types an array if just a single
    if (!$path || !is_string($path) || !is_file($path)) {
        $result = array('error' => 500, 'error_str' => 'server configuration error: route tables could not be loaded');
    } else {
        $waypoints = array();
        $result = pfind_interpret($entries, $mode, $waypoints, $path, $node_types);
        qlog(__LINE__, $mode, $entries, $result);
        if (IS_LOCAL) {
            foreach ($waypoints as $i => $stage) {
                foreach ($stage as $see) {
                    qlog(__LINE__, $i, join(', ', $see));
                }
            }
        }
        clb_timing('interpret');
    }
    if ($result['error'] == 200) {
        $links = FALSE;
        if (!$prop['dist_only'] && is_file($path)) {
            $data = file_get_contents($path);
            //, FILE_BINARY);	//need different p2p files for different combinations of modes
            $links = clb_blob_dec($data);
        }
        clb_timing('load array');
        if (!$links && !$prop['dist_only']) {
            $result = array('error' => 500, 'error_str' => 'point to point data file could not be found/loaded ' . $mode);
            qlog(__LINE__, $result, $mode, $path, $p2p_paths);
        } else {
            $result = pfind_routes($waypoints, $links, $prop, $type_names);
        }
        qlog(__LINE__, clb_timing('find path'));
    }
    //qlog(__LINE__,clb_xml($result, 'RouteFinder'));
    // qlog(__LINE__,clb_json($result, "'"));
    switch ($prop['service']) {
        case 'json':
            $return_data = json_encode($result);
            rs_response('application/json', $return_data, 'UTF-8');
            break;
        case 'javascript':
            $sid = clb_val('', $prms, 'sid');
            $func = clb_val('mfw_dir_result', $prms, 'callback');
            $return_data = clb_json($result, "'");
            $callback = $func . '(\'' . $sid . '\',' . $return_data . ');';
            clb_response('application/javascript', $callback, 'UTF-8');
            break;
        case 'xml':
            $return_data = clb_xml($result, 'RouteFinder');
            clb_response('xml', $return_data, 'UTF-8');
            break;
        case 'php':
            return $result;
            break;
    }
}
Esempio n. 3
0
*/
$result = pfind_service($_REQUEST, $pfind_defs, $editor_types, $p2p_paths);
if ($result['error'] == 604) {
    $_REQUEST['gd'] = 0;
    //turn off distance only
    $_REQUEST['gp'] = 0;
    //turn off polyline
    $_REQUEST['gs'] = 0;
    //turn off steps
    $result = pfind_service($_REQUEST, $pfind_defs, $editor_types, $p2p_paths);
}
switch ($service) {
    case 'javascript':
        $sid = clb_val('', $_REQUEST, 'sid');
        $func = clb_val('mfw_dir_result', $_REQUEST, 'callback');
        $return_data = clb_json($result, "'");
        $callback = $func . '(\'' . $sid . '\',' . $return_data . ');';
        rs_response('application/javascript', $callback, 'UTF-8');
        break;
    case 'json':
        $return_data = json_encode($result);
        rs_response('application/json', $return_data, 'UTF-8');
        break;
    case 'xml':
        $return_data = clb_xml($result, 'RouteFinder');
        rs_response('xml', clb_tag('xml?', '', '', array('version' => '1.0', 'encoding' => 'utf-8')) . clb_tag('responses', '', $return_data), 'UTF-8');
        break;
    default:
        header('x', TRUE, 400);
        //Deliver a 'bad request' response
}
Esempio n. 4
0
 function clb_json($struct, $quot = '"')
 {
     $result = '';
     if (is_array($struct)) {
         $test = join('', array_keys($struct));
         //values packaged by clb_lit() are returned without quotes
         if (count($struct) == 1 && $test == 'literal') {
             return reset($struct);
         }
         $is_arr = is_numeric($test);
         //if all keys are numbers assume a sequential array
         foreach ($struct as $key => $val) {
             if ($is_arr) {
                 $result .= clb_json($val, $quot) . ', ';
             } else {
                 $result .= $quot . $key . $quot . ':' . clb_json($val, $quot) . ', ';
             }
         }
         return ($is_arr ? '[' : '{') . trim($result, ', ') . ($is_arr ? ']' : '}');
     } else {
         if (is_bool($struct)) {
             return $struct ? 'true' : 'false';
         } else {
             if (is_numeric($struct) && preg_match('/^[-1-9]|^0\\./', $struct)) {
                 return $struct;
             }
         }
     }
     return clb_escape($struct, $quot);
 }
Esempio n. 5
0
 //make a short path network from this node
 $network_d = blow_load_nodes($pnum1s, $p2p_links);
 if (clb_count($network_d)) {
     //get a list of all the node keys in the list
     $targets = array_keys($network_d);
     while (count($targets)) {
         if ((microtime(true) - $time) * 1000 > 60000) {
             $rate = round($batch / (microtime(true) - $time));
             //per second rate
             $pos = round(100 * (($scan1 - $chunk_start) / $chunk_nodes), 3);
             $elapsed = time() - $start_time;
             if ($last_est != $pos) {
                 $last_est = $pos;
                 $estimate = 100 * $elapsed / $pos;
             }
             $txt = clb_json($stats);
             qpre($rate, $txt, $pos, $scan1, gmdate('H:i', $elapsed), 'remaining: ' . ($estimate ? gmdate('H:i', max(0, $estimate - $elapsed)) : 'not ready'));
             //qlog($rate, $txt, $pos, $clock, $scan1);
             $stats = $base_stats;
             $batch = 0;
             $time = microtime(true);
         }
         while (count($targets)) {
             //get most distant other end reached/left
             //ensures $targets always reduces on each loop
             $pnum2 = array_pop($targets);
             //convert platforms to the station
             if (isset($p2p_links['plat2stat'][$pnum])) {
                 $pnum2 = $p2p_links['plat2stat'][$pnum2];
             }
             if ($pnum2 > $pnum1 && in_array($pnum2, $to_save)) {