Exemple #1
0
function getDetails($db, $id, $type, $langs, $offset)
{
    global $format, $callback;
    // request
    $request = "SELECT\n\t\t\t\ttags->'addr:street' AS \"street\",\n\t\t\t\ttags->'addr:housenumber' AS \"housenumber\",\n\t\t\t\ttags->'addr:housename' AS \"housename\",\n\t\t\t\ttags->'addr:country' AS \"country\",\n\t\t\t\ttags->'addr:postcode' AS \"postcode\",\n\t\t\t\ttags->'addr:city' AS \"city\",\n\t\t\t\ttags->'addr:suburb' AS \"suburb\",\n\t\t\t\ttags->'addr:province' AS \"province\",\n\t\t\t\ttags->'addr:unit' AS \"unit\",\n\t\t\t\ttags->'addr:floor' AS \"floor\",\n\t\t\t\ttags->'addr:door' AS \"door\",\n\t\t\t\ttags->'phone' AS \"phone1\",\n\t\t\t\ttags->'contact:phone' AS \"phone2\",\n\t\t\t\ttags->'addr:phone' AS \"phone3\",\n\t\t\t\ttags->'fax' AS \"fax1\",\n\t\t\t\ttags->'contact:fax' AS \"fax2\",\n\t\t\t\ttags->'addr:fax' AS \"fax3\",\n\t\t\t\ttags->'website' AS \"website1\",\n\t\t\t\ttags->'url' AS \"website2\",\n\t\t\t\ttags->'url:official' AS \"website3\",\n\t\t\t\ttags->'contact:website' AS \"website4\",\n\t\t\t\ttags->'operator' AS \"operator\",\n\t\t\t\ttags->'email' AS \"email1\",\n\t\t\t\ttags->'contact:email' AS \"email2\",\n\t\t\t\ttags->'addr:email' AS \"email3\",\n\t\t\t\ttags->'opening_hours' AS \"openinghours\",\n\t\t\t\ttags->'service_times' AS \"servicetimes\",\n\t\t\t\ttags->'image' AS \"image\"\n\t\t\tFROM " . $type . "s WHERE (id = " . $id . ");";
    $wikipediarequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 9) = 'wikipedia';";
    $namerequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 4) = 'name';";
    // connnecting to database
    $connection = connectToDatabase($db);
    // if there is no connection
    if (!$connection) {
        exit;
    }
    $response = requestDetails($request, $connection);
    $wikipediaresponse = requestDetails($wikipediarequest, $connection);
    $nameresponse = requestDetails($namerequest, $connection);
    pg_close($connection);
    if ($response) {
        if ($format == "text") {
            echo textDetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset);
        } else {
            if ($format == "json") {
                echo jsonDetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type, $callback);
            } else {
                echo xmlDetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type);
            }
        }
        return true;
    } else {
        return false;
    }
}
function getDetails($ptdb, $id, $type, $langs, $offset)
{
    global $format, $callback;
    // request
    $wikipediarequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 9) = 'wikipedia';";
    $namerequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 4) = 'name';";
    // connnecting to database
    $connection = connectToDatabase($ptdb);
    // if there is no connection
    if (!$connection) {
        exit;
    }
    $wikipediaresponse = requestDetails($wikipediarequest, $connection);
    $nameresponse = requestDetails($namerequest, $connection);
    pg_close($connection);
    $response = tagTransform("../locales/departures.xml", getTags($ptdb, $id, $type), $type);
    if ($response) {
        if ($format == "text") {
            echo textDetailsOut($response, $nameresponse, $wikipediaresponse, $langs, $offset);
        } else {
            if ($format == "json") {
                echo jsonDetailsOut($response, $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type, $callback);
            } else {
                echo xmlDetailsOut($response, $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type);
            }
        }
        return true;
    } else {
        return false;
    }
}
function getDetails($db, $id, $type, $langs, $offset)
{
    global $format;
    global $callback;
    // request
    $request = "SELECT\n\t\t\t\ttags->'addr:street' AS \"street\",\n\t\t\t\ttags->'addr:housenumber' AS \"housenumber\",\n\t\t\t\ttags->'addr:country' AS \"country\",\n\t\t\t\ttags->'addr:postcode' AS \"postcode\",\n\t\t\t\ttags->'addr:city' AS \"city\",\n\t\t\t\ttags->'addr:housename' AS \"housename\",\n\t\t\t\ttags->'addr:suburb' AS \"suburb\",\n\t\t\t\ttags->'addr:province' AS \"province\",\n\t\t\t\ttags->'addr:unit' AS \"unit\",\n\t\t\t\ttags->'addr:floor' AS \"floor\",\n\t\t\t\ttags->'addr:door' AS \"door\",\n\t\t\t\ttags->'wikipedia' AS \"wikipedia\",\n\t\t\t\ttags->'phone' AS \"phone1\",\n\t\t\t\ttags->'contact:phone' AS \"phone2\",\n\t\t\t\ttags->'addr:phone' AS \"phone3\",\n\t\t\t\ttags->'phone:mobile' AS \"mobilephone1\",\n\t\t\t\ttags->'contact:mobile' AS \"mobilephone2\",\n\t\t\t\ttags->'fax' AS \"fax1\",\n\t\t\t\ttags->'contact:fax' AS \"fax2\",\n\t\t\t\ttags->'addr:fax' AS \"fax3\",\n\t\t\t\ttags->'website' AS \"website1\",\n\t\t\t\ttags->'url' AS \"website2\",\n\t\t\t\ttags->'url:official' AS \"website3\",\n\t\t\t\ttags->'contact:website' AS \"website4\",\n\t\t\t\ttags->'operator' AS \"operator\",\n\t\t\t\ttags->'email' AS \"email1\",\n\t\t\t\ttags->'contact:email' AS \"email2\",\n\t\t\t\ttags->'addr:email' AS \"email3\",\n\t\t\t\ttags->'opening_hours' AS \"openinghours\",\n\t\t\t\ttags->'service_times' AS \"servicetimes\",\n\t\t\t\ttags->'fee' AS \"fee\",\n\t\t\t\ttags->'toll' AS \"toll\",\n\t\t\t\ttags->'ref' AS \"ref\",\n\t\t\t\ttags->'capacity' AS \"capacity\",\n\t\t\t\ttags->'internet_access' AS \"internet_access\",\n\t\t\t\ttags->'image' AS \"image\",\n\t\t\t\ttags->'image:panorama' AS \"panorama\",\n\t\t\t\ttags->'description' AS \"description\",\n\t\t\t\ttags->'stars' AS \"stars\",\n\t\t\t\ttags->'cuisine' AS \"cuisine\",\n\t\t\t\ttags->'smoking' AS \"smoking\",\n\t\t\t\ttags->'biergarten' AS \"biergarten\",\n\t\t\t\ttags->'beer_garden' AS \"beer_garden\",\n\t\t\t\ttags->'brewery' AS \"beer\",\n\t\t\t\ttags->'microbrewery' AS \"microbrewery\",\n\t\t\t\ttags->'fuel:diesel' AS \"diesel\",\n\t\t\t\ttags->'fuel:GTL_diesel' AS \"gtldiesel\",\n\t\t\t\ttags->'fuel:HGV_diesel' AS \"hgvdiesel\",\n\t\t\t\ttags->'fuel:biodiesel' AS \"biodiesel\",\n\t\t\t\ttags->'fuel_octane_91' AS \"octane91\",\n\t\t\t\ttags->'fuel:octane_95' AS \"octane95\",\n\t\t\t\ttags->'fuel:octane_98' AS \"octane98\",\n\t\t\t\ttags->'fuel:octane_100' AS \"octane100\",\n\t\t\t\ttags->'fuel:octane_98_leaded' AS \"octane98l\",\n\t\t\t\ttags->'fuel:1_25' AS \"fuel25\",\n\t\t\t\ttags->'fuel:1_50' AS \"fuel50\",\n\t\t\t\ttags->'fuel:alcohol' AS \"alcohol\",\n\t\t\t\ttags->'fuel:ethanol' AS \"ethanol\",\n\t\t\t\ttags->'fuel:methanol' AS \"methanol\",\n\t\t\t\ttags->'fuel:svo' AS \"svo\",\n\t\t\t\ttags->'fuel:e85' AS \"e85\",\n\t\t\t\ttags->'fuel:biogas' AS \"biogas\",\n\t\t\t\ttags->'fuel:lpg' AS \"lpg\",\n\t\t\t\ttags->'fuel:cng' AS \"cng\",\n\t\t\t\ttags->'fuel:LH2' AS \"lh2\",\n\t\t\t\ttags->'fuel:electricity' AS \"electro\",\n\t\t\t\ttags->'fuel:adblue' AS \"adblue\",\n\t\t\t\ttags->'car_wash' AS \"carwash\",\n\t\t\t\ttags->'car_repair' AS \"carrepair\",\n\t\t\t\ttags->'shop' AS \"shop\",\n\t\t\t\ttags->'kiosk' AS \"kiosk\",\n\t\t\t\ttags->'ele' AS \"ele\",\n\t\t\t\ttags->'population' AS \"population\",\n\t\t\t\ttags->'iata' AS \"iata\",\n\t\t\t\ttags->'icao' AS \"icao\",\n\t\t\t\ttags->'disused' AS \"disused\",\n\t\t\t\ttags->'wheelchair' AS \"wheelchair\",\n\t\t\t\ttags->'wheelchair:toilets' AS \"wheelchair:toilets\",\n\t\t\t\ttags->'wheelchair:rooms' AS \"wheelchair:rooms\",\n\t\t\t\ttags->'wheelchair:access' AS \"wheelchair:access\",\n\t\t\t\ttags->'wheelchair:places' AS \"wheelchair:places\"\n\t\t\tFROM " . $type . "s WHERE (id = " . $id . ");";
    $wikipediarequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 9) = 'wikipedia';";
    $namerequest = "SELECT\n\t\t\t\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t\t\t) AS foo\n\t\t\t\t\t\t\tWHERE substring(foo.keys from 1 for 4) = 'name';";
    // connnecting to database
    $connection = connectToDatabase($db);
    // if there is no connection
    if (!$connection) {
        exit;
    }
    $response = requestDetails($request, $connection);
    $wikipediaresponse = requestDetails($wikipediarequest, $connection);
    $nameresponse = requestDetails($namerequest, $connection);
    pg_close($connection);
    if ($response) {
        if ($format == "text") {
            echo textMoredetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset);
        } else {
            if ($format == "json") {
                echo jsonMoredetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type, $callback);
            } else {
                echo xmlMoredetailsOut($response[0], $nameresponse, $wikipediaresponse, $langs, $offset, $id, $type);
            }
        }
        return true;
    } else {
        return false;
    }
}
function getLatLon($id, $type)
{
    global $db;
    if (isValidId($id) && isValidType($type)) {
        $connection = connectToDatabase($db);
        if (!$connection) {
            exit;
        }
        $query = "SELECT\n\t\t\t\t\t\tid, ST_X(geom), ST_Y(geom)\n\t\t\t\t\t\tFROM " . $_GET[$type] . "s\n\t\t\t\t\t\tWHERE (id = " . $_GET[$id] . ");";
        $response = requestDetails($query, $connection);
        pg_close($connection);
        if (!$response) {
            $connection = connectToDatabase($ptdb);
            if (!$connection) {
                exit;
            }
            $response = requestDetails($query, $connection);
            pg_close($connection);
            if (!$response) {
                return false;
            }
        }
        foreach ($response as $element) {
            return array($element['st_x'], $element['st_y']);
        }
    }
    return false;
}
function getTags($db, $id, $type)
{
    // request
    $request = "SELECT tags FROM " . $type . "s WHERE (id = " . $id . ");";
    // connnecting to database
    $connection = connectToDatabase($db);
    // if there is no connection
    if (!$connection) {
        exit;
    }
    $response = requestDetails($request, $connection);
    pg_close($connection);
    if ($response) {
        $text = substr($response[0]['tags'], 1, -1);
        $temp = explode("\", \"", $text);
        for ($i = 0; $i < count($temp); $i++) {
            $tag = explode("\"=>\"", $temp[$i]);
            $tags[$tag[0]] = $tag[1];
        }
        return $tags;
    } else {
        return false;
    }
}
Exemple #6
0
}
// get the most important langs of the user
if (isset($lang)) {
    $langs = array($lang);
} else {
    $langs = getLangs();
}
// connnecting to database
$connection = connectToDatabase($db);
// if there is no connection
if (!$connection) {
    exit;
}
// request
$request = "SELECT\n\t\t\t\t\tfoo.keys, foo.values\n\t\t\t\t\tFROM (\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\tskeys(tags) AS keys,\n\t\t\t\t\t\t\tsvals(tags) AS values\n\t\t\t\t\t\tFROM " . $type . "s\n\t\t\t\t\t\tWHERE (id = " . $id . ")\n\t\t\t\t\t) AS foo\n\t\t\t\t\tWHERE substring(foo.keys from 1 for 4) = 'name';";
$response = requestDetails($request, $connection, $type);
pg_close($connection);
$name = getNameDetail($langs, $response);
if ($format == "xml") {
    echo xmlNameOut($name[0], $name[1], $id, $type);
} else {
    if ($format == "json") {
        echo jsonNameOut($name[0], $name[1], $id, $type, $callback);
    } else {
        echo textNameOut($name[0], $id, $type);
    }
}
// output of name data in plain text format
function textNameOut($name, $id, $type)
{
    global $db;