Exemplo n.º 1
0
    }
    include CONST_BasePath . '/lib/template/search-batch-json.php';
    exit;
} else {
    if (!(isset($_GET['q']) && $_GET['q']) && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/') {
        $sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
        // reverse order of '/' separated string
        $aPhrases = explode('/', $sQuery);
        $aPhrases = array_reverse($aPhrases);
        $sQuery = join(', ', $aPhrases);
        $oGeocode->setQuery($sQuery);
    } else {
        $oGeocode->setQueryFromParams($_GET);
    }
}
$hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
$aSearchResults = $oGeocode->lookup();
if ($aSearchResults === false) {
    $aSearchResults = array();
}
$sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1");
logEnd($oDB, $hLog, sizeof($aSearchResults));
$bAsText = $oGeocode->getIncludePolygonAsText();
$sQuery = $oGeocode->getQueryString();
$sViewBox = $oGeocode->getViewBoxString();
$bShowPolygons = isset($_GET['polygon']) && $_GET['polygon'];
$aExcludePlaceIDs = $oGeocode->getExcludedPlaceIDs();
$sMoreURL = CONST_Website_BaseURL . 'search.php?format=' . urlencode($sOutputFormat) . '&exclude_place_ids=' . join(',', $oGeocode->getExcludedPlaceIDs());
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
    $sMoreURL .= '&accept-language=' . $_SERVER["HTTP_ACCEPT_LANGUAGE"];
}
Exemplo n.º 2
0
    }
}
if (!isset($_GET['place_id'])) {
    echo "Please select a place id";
    exit;
}
$iPlaceID = (int) $_GET['place_id'];
$iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_tiger where place_id = ' . $iPlaceID);
if ($iParentPlaceID) {
    $iPlaceID = $iParentPlaceID;
}
$iParentPlaceID = $oDB->getOne('select parent_place_id from location_property_aux where place_id = ' . $iPlaceID);
if ($iParentPlaceID) {
    $iPlaceID = $iParentPlaceID;
}
$hLog = logStart($oDB, 'details', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
// Make sure the point we are reporting on is fully indexed
//$sSQL = "UPDATE placex set indexed = true where indexed = false and place_id = $iPlaceID";
//$oDB->query($sSQL);
// Get the details for this point
$sSQL = "select place_id, osm_type, osm_id, class, type, name, admin_level, housenumber, street, isin, postcode, calculated_country_code as country_code, importance, wikipedia,";
$sSQL .= " to_char(indexed_date, 'YYYY-MM-DD HH24:MI') as indexed_date, parent_place_id, rank_address, rank_search, get_searchrank_label(rank_search) as rank_search_label, get_name_by_language(name,{$sLanguagePrefArraySQL}) as localname, ";
$sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, ";
//$sSQL .= " ST_Area(geometry::geography) as area, ";
$sSQL .= " ST_y(centroid) as lat, ST_x(centroid) as lon,";
$sSQL .= " case when importance = 0 OR importance IS NULL then 0.75-(rank_search::float/40) else importance end as calculated_importance, ";
$sSQL .= " ST_AsText(CASE WHEN ST_NPoints(geometry) > 5000 THEN ST_SimplifyPreserveTopology(geometry, 0.0001) ELSE geometry END) as outlinestring";
$sSQL .= " from placex where place_id = {$iPlaceID}";
$aPointDetails = $oDB->getRow($sSQL);
if (PEAR::IsError($aPointDetails)) {
    failInternalError("Could not get details of place object.", $sSQL, $aPointDetails);
Exemplo n.º 3
0
            $aCountryCodes[] = "'" . strtolower($sCountryCode) . "'";
        }
    }
    $sCountryCodesSQL = join(',', $aCountryCodes);
}
// Search query
$sQuery = isset($_GET['q']) ? trim($_GET['q']) : '';
if (!$sQuery && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/') {
    $sQuery = substr($_SERVER['PATH_INFO'], 1);
    // reverse order of '/' seperated string
    $aPhrases = explode('/', $sQuery);
    $aPhrases = array_reverse($aPhrases);
    $sQuery = join(', ', $aPhrases);
}
if ($sQuery) {
    $hLog = logStart($oDB, 'search', $sQuery, $aLangPrefOrder);
    // Hack to make it handle "new york, ny" (and variants) correctly
    $sQuery = str_ireplace(array('New York, ny', 'new york, new york', 'New York ny', 'new york new york'), 'new york city, ny', $sQuery);
    if (isset($aLangPrefOrder['name:en'])) {
        $sQuery = preg_replace('/\\bil\\b/', 'illinois', $sQuery);
        $sQuery = preg_replace('/\\bal\\b/', 'alabama', $sQuery);
        $sQuery = preg_replace('/\\bla\\b/', 'louisiana', $sQuery);
        $sQuery = preg_replace('/\\bde louisiana\\b/', 'de la', $sQuery);
    }
    // If we have a view box create the SQL
    // Small is the actual view box, Large is double (on each axis) that
    $sViewboxCentreSQL = $sViewboxSmallSQL = $sViewboxLargeSQL = false;
    if (isset($_GET['viewboxlbrt']) && $_GET['viewboxlbrt']) {
        $aCoOrdinatesLBRT = explode(',', $_GET['viewboxlbrt']);
        $_GET['viewbox'] = $aCoOrdinatesLBRT[0] . ',' . $aCoOrdinatesLBRT[3] . ',' . $aCoOrdinatesLBRT[2] . ',' . $aCoOrdinatesLBRT[1];
    }
Exemplo n.º 4
0
$oDB =& getDB();
ini_set('memory_limit', '200M');
// Format for output
$sOutputFormat = 'xml';
if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2')) {
    $sOutputFormat = $_GET['format'];
}
// Show address breakdown
$bShowAddressDetails = true;
if (isset($_GET['addressdetails'])) {
    $bShowAddressDetails = (bool) $_GET['addressdetails'];
}
// Prefered language
$aLangPrefOrder = getPrefferedLangauges();
$sLanguagePrefArraySQL = "ARRAY[" . join(',', array_map("getDBQuoted", $aLangPrefOrder)) . "]";
$hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
if (isset($_GET['osm_type']) && isset($_GET['osm_id']) && (int) $_GET['osm_id'] && ($_GET['osm_type'] == 'N' || $_GET['osm_type'] == 'W' || $_GET['osm_type'] == 'R')) {
    $iPlaceID = $oDB->getOne("select place_id from placex where osm_type = '" . $_GET['osm_type'] . "' and osm_id = " . (int) $_GET['osm_id'] . " order by type = 'postcode' asc");
    if (!$iPlaceID) {
        $sError = 'OSM ID Not Found';
    }
} else {
    // Location to look up
    $fLat = (double) $_GET['lat'];
    $fLon = (double) $_GET['lon'];
    $sPointSQL = "ST_SetSRID(ST_Point({$fLon},{$fLat}),4326)";
    // Zoom to rank, this could probably be calculated but a lookup gives fine control
    $aZoomRank = array(0 => 2, 1 => 2, 2 => 2, 3 => 4, 4 => 4, 5 => 8, 6 => 10, 7 => 10, 8 => 12, 9 => 12, 10 => 17, 11 => 17, 12 => 18, 13 => 18, 14 => 22, 15 => 22, 16 => 26, 17 => 26, 18 => 30, 19 => 30);
    $iMaxRank = isset($_GET['zoom']) && isset($aZoomRank[$_GET['zoom']]) ? $aZoomRank[$_GET['zoom']] : 28;
    // Find the nearest point
    $fSearchDiam = 0.0001;
    if (!file_exists($APP_INCLUDE)) {
        die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n");
    }
    require_once $APP_INCLUDE;
}
// Check for jobs every $interval seconds
$interval = 5;
$INTERVAL = getenv('INTERVAL');
if (!empty($INTERVAL)) {
    $interval = $INTERVAL;
}
$worker = new ResqueScheduler\Worker(ResqueScheduler\ResqueScheduler::QUEUE_NAME);
$worker->registerLogger($logger);
$worker->logLevel = $logLevel;
$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
    file_put_contents($PIDFILE, getmypid()) or die('Could not write PID information to ' . $PIDFILE);
}
logStart($logger, array('message' => '*** Starting scheduler worker ' . $worker, 'data' => array('type' => 'start', 'worker' => (string) $worker)), $logLevel);
$worker->work($interval);
function logStart($logger, $message, $logLevel)
{
    if ($logger === null || $logger->getInstance() === null) {
        fwrite(STDOUT, ($logLevel == Resque_Worker::LOG_NORMAL ? "" : "[" . strftime('%T %Y-%m-%d') . "] ") . $message['message'] . "\n");
    } else {
        list($host, $pid, $queues) = explode(':', $message['data']['worker'], 3);
        $message['data']['worker'] = $host . ':' . $pid;
        $message['data']['queues'] = explode(',', $queues);
        $logger->getInstance()->addInfo($message['message'], $message['data']);
    }
}