From: <wis...@us...> - 2017-10-06 09:17:14
|
Revision: 13294 http://sourceforge.net/p/xoops/svn/13294 Author: wishcraft Date: 2017-10-06 09:17:10 +0000 (Fri, 06 Oct 2017) Log Message: ----------- resubmit places.xoops.org Removed Paths: ------------- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/crons/ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/data/ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/help.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/index.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/install/ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/jquery/ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/style.css *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/verify.php Deleted: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md 2017-10-06 07:04:29 UTC (rev 13293) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md 2017-10-06 09:17:10 UTC (rev 13294) @@ -1,34 +0,0 @@ -# Chronolabs Cooperative ~ GeoSpatial Places Lookups API - -## Author: Simon Antony Roberts <wis...@us...> - -This API is a Geospatial service provided by PHP7.0 - it utilises file caches as well as a mysqli database interface to provide and provision both locality keys as well as country and continent keys. - -# SEO Friendly URL - Apache Module Rewrite - -This goes in your API_ROOT_PATH/.htaccess file - - RewriteEngine On - RewriteRule ^v([0-9]{1,2})/([0-9a-zA-Z\ \(\)\-\,\:]+)/([0-9a-zA-Z\ \(\)\-\,\:]+)/([0-9\.]+)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&place=$3&radius=$4&output=$5 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/([0-9a-zA-Z\ \(\)\-\,\:]+)/([0-9a-zA-Z\ \(\)\-\,\:]+)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&place=$3&output=$4 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/(nearby|exactly)/([0-9\.\-]+)/([0-9\.\-]+)/([0-9\.]+)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&latitude=$3&longitude=$4&radius=$5&output=$6 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/(list|maps|details)/([a-zA-Z0-9\ \(\)\-\,]+)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&place=$3&output=$4 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/(address)/([0-9a-z\-\,\ ]+)/(.*?)/([0-9\.]+)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&type=$3&address=$4&radius=$5&output=$6 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/(address)/([0-9a-z\-\,\ ]+)/(.*?)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&type=$3&address=$4&output=$5 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/(address)/(.*?)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&address=$3&output=$4 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/(venues)/([0-9a-z\-\,\ ]+)/([0-9a-zA-Z\ \(\)\-\,\:]+)/([0-9\.]+)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&type=$3&place=$4&radius=$5&output=$6 [L,NC,QSA] - RewriteRule ^v([0-9]{1,2})/(venues)/([0-9a-z\-\,\ ]+)/([0-9a-zA-Z\ \(\)\-\,\:]+)/(raw|html|serial|json|xml).api ./index.php?version=$1&country=$2&type=$3&place=$4&output=$5 [L,NC,QSA] - -# Installing API - -Copy the contents of this distribution to your visually routable path via http(s) etc. Then poll the path required and run the install; - -it requires apache2, nixi, iis etc and best with php5+; - -# Cronjobs/Scheduled Tasks - -There is a couple of cronjobs to be set they are the following after running: $ crontab -e - - */15 * * * * /usr/bin/php -q /var/www/places.snails.email/crons/align-postcode-states.php - */25 * * * * /usr/bin/php -q /var/www/places.snails.email/crons/mining-localities.php - */15 */6 * * * /usr/bin/php -q /var/www/places.snails.email/crons/updating-details.php Deleted: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php 2017-10-06 07:04:29 UTC (rev 13293) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php 2017-10-06 09:17:10 UTC (rev 13294) @@ -1,95 +0,0 @@ -<?php -/** - * Chronolabs REST Geospatial Places Services API - * - * You may not change or alter any portion of this comment or credits - * of supporting developers from this source code or any supporting source code - * which is considered copyrighted (c) material of the original comment or credit authors. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * @copyright Chronolabs Cooperative http://snails.email - * @license GNU GPL 3 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package api - * @since 2.0.1 - * @author Simon Roberts <wis...@us...> - * @subpackage places - * @description Geospatial Places Services API - * @see http://internetfounder.wordpress.com - * @see http://sourceoforge.net/projects/chronolabsapis - * @see https://github.com/Chronolabs-Cooperative/Places-API-PHP - */ - - -if (!is_file(__DIR__ . DIRECTORY_SEPARATOR . 'mainfile.php') || !is_file(__DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'license.php')) -{ - header('Location: ' . "./install"); - exit(0); -} - -require_once __DIR__ . DIRECTORY_SEPARATOR . 'mainfile.php'; - -/** - * Paths - */ -$pu = parse_url($_SERVER['REQUEST_URI']); -$source = (isset($_SERVER['HTTPS'])?'https://':'http://').strtolower($_SERVER['HTTP_HOST']).$pu['path']; -unset($pu); -define('PLACES_URL', $source); -define('API_ROOT_PATH', __DIR__); -define('API_CACHE_PATH', DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'places' . DIRECTORY_SEPARATOR . 'caches'); -define('API_TMP_PATH', DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'places'); - -/** - * Cronjob Constants and Defines - */ -define('API_CRON_NUMBER_COUNTRIES', 7); -define('API_CRON_NUMBER_REGIONS', 250); - -/** - * Times && Limits - */ -define('API_RADIUS_DEFAULT', 0.469); -define('API_GOOGLE_PAGES_RESULTS', 13); -define('API_CACHE_SECONDS', 8444); -define('MAXIMUM_QUERIES', 25); -ini_set('memory_limit', '128M'); - -/** - * Keys & Identify Strings - */ -define('API_GOOGLE_KEY','AIzaSyD0tstaeCtH0gugLJUeYcUSUT_TdXL24Uo'); // Get from: https://developers.google.com/places/web-service/get-api-key = API_GOOGLE_KEY -define('API_PLACES_FIELDS', 'Address|Distance|RegionName|mapref_latitude|mapref_longitude|Latitude_Float|Longitude_Float|Altitude_Feet|Altitude_Meters|key'); -define('API_COUNTRY_FIELDS', 'Country|ISO2|FIPS104|ISO3|ISON|TLD|Capital|Continent|NationalitySingular|NationalityPlural|Currency|CurrencyCode|Population|Records|Updates|Places|Details|key|distance'); -define('API_CONTINENT_FIELDS', 'Continent|key|Population|Records|Places|Details|Updates'); -define('API_VENUE_FIELDS','key|Name|Icon|Id|Reference|Longitude|Latitude|View_NE_Longitude|View_NE_Latitude|View_SW_Longitude|View_SW_Latitude|Vicinity'); -define('API_ADDRESS_FIELDS','key|Unit|Building|Street|Suburb|State|Country|Country_ISO2|Postcode|Council|Longitude|Latitude|View_NE_Longitude|View_NE_Latitude|View_SW_Longitude|View_SW_Latitude|Formatted'); - -/** - * Include libraries - */ -require_once __DIR__ . DIRECTORY_SEPARATOR . 'functions.php'; -require_once __DIR__ . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'file' . DIRECTORY_SEPARATOR . 'apifile.php'; -require_once __DIR__ . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'apicache.php'; - -/** - * Opens Access Origin Via networking Route NPN - */ -header('Access-Control-Allow-Origin: *'); -header('Origin: *'); - -/** - * Turns of GZ Lib Compression for Document Incompatibility - */ -ini_set("zlib.output_compression", 'Off'); -ini_set("zlib.output_compression_level", -1); - -/** - * - * @var constants - */ -define("API_FILE_IO_PEERS", __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'peers.diz'); -define("API_FILE_IO_DOMAINS", __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'domains.diz'); -define("API_FILE_IO_FOOTER", __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'api-localhost.html'); -?> \ No newline at end of file Deleted: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php 2017-10-06 07:04:29 UTC (rev 13293) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php 2017-10-06 09:17:10 UTC (rev 13294) @@ -1,2079 +0,0 @@ -<?php -/** - * Chronolabs REST Geospatial Places Services API - * - * You may not change or alter any portion of this comment or credits - * of supporting developers from this source code or any supporting source code - * which is considered copyrighted (c) material of the original comment or credit authors. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * @copyright Chronolabs Cooperative http://snails.email - * @license GNU GPL 3 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package api - * @since 2.0.1 - * @author Simon Roberts <wis...@us...> - * @subpackage places - * @description Geospatial Places Services API - * @see http://internetfounder.wordpress.com - * @see http://sourceoforge.net/projects/chronolabsapis - * @see https://github.com/Chronolabs-Cooperative/Places-API-PHP - */ - - -if (!function_exists("whitelistGetIP")) { - - /* function whitelistGetIPAddy() - * - * provides an associative array of whitelisted IP Addresses - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return array - */ - function whitelistGetIPAddy() { - return array_merge(whitelistGetNetBIOSIP(), file(dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'whitelist.txt')); - } -} - -if (!function_exists("whitelistGetNetBIOSIP")) { - - /* function whitelistGetNetBIOSIP() - * - * provides an associative array of whitelisted IP Addresses base on TLD and NetBIOS Addresses - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return array - */ - function whitelistGetNetBIOSIP() { - $ret = array(); - foreach(file(dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'whitelist-domains.txt') as $domain) { - $ip = gethostbyname($domain); - $ret[$ip] = $ip; - } - return $ret; - } -} - -if (!function_exists("whitelistGetIP")) { - - /* function whitelistGetIP() - * - * get the True IPv4/IPv6 address of the client using the API - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $asString boolean Whether to return an address or network long integer - * - * @return mixed - */ - function whitelistGetIP($asString = true){ - // Gets the proxy ip sent by the user - $proxy_ip = ''; - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } else - if (!empty($_SERVER['HTTP_X_FORWARDED'])) { - $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; - } else - if (! empty($_SERVER['HTTP_FORWARDED_FOR'])) { - $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; - } else - if (!empty($_SERVER['HTTP_FORWARDED'])) { - $proxy_ip = $_SERVER['HTTP_FORWARDED']; - } else - if (!empty($_SERVER['HTTP_VIA'])) { - $proxy_ip = $_SERVER['HTTP_VIA']; - } else - if (!empty($_SERVER['HTTP_X_COMING_FROM'])) { - $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; - } else - if (!empty($_SERVER['HTTP_COMING_FROM'])) { - $proxy_ip = $_SERVER['HTTP_COMING_FROM']; - } - if (!empty($proxy_ip) && $is_ip = preg_match('/^([0-9]{1,3}.){3,3}[0-9]{1,3}/', $proxy_ip, $regs) && count($regs) > 0) { - $the_IP = $regs[0]; - } else { - $the_IP = $_SERVER['REMOTE_ADDR']; - } - - $the_IP = ($asString) ? $the_IP : ip2long($the_IP); - return $the_IP; - } -} - -if (!function_exists("randomPlacesKey")) { - - /* function randomPlacesKey() - * - * Get a random forensic identify key for a place from the database - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return string(32) - */ - function randomPlacesKey() - { - $sql = "SELECT * FROM `".$GLOBALS['APIDB']->prefix("countries") . "` WHERE `Records` > 1000 ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - $country = $GLOBALS['APIDB']->fetchArray($result); - $sql = "SELECT concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($country['Table']) . "` ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if (list($key) = $GLOBALS['APIDB']->fetchRow($result)) - return $key; - } - $ret = array(); - } - } -} - -if (!function_exists("randomGeoPlace")) { - - /* function randomPlacesKey() - * - * Get a random forensic identify key for a place from the database - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return string(32) - */ - function randomGeoPlace() - { - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `Records` > 1000 ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - $country = $GLOBALS['APIDB']->fetchArray($result); - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix($country['Table']) . "` ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if ($place = $GLOBALS['APIDB']->fetchArray($result)) - return array('country' => $country['Country'], 'iso3' => $country['ISO3'], 'iso2' => $country['ISO2'], 'region' => $place['RegionName']); - } - } - return false; - } -} -if (!function_exists("randomGeoLocation")) { - - /* function randomGeoLocation() - * - * Get a random latitude & longitude for a place from the database - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return array - */ - function randomGeoLocation() - { - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `Records` > 1000 ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - $country = $GLOBALS['APIDB']->fetchArray($result); - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix($country['Table']) . "` ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if ($place = $GLOBALS['APIDB']->fetchArray($result)) - return array('latitude'=>$place['Latitude_Float'], 'longitude' => $place['Longitude_Float']); - } - $ret = array('latitude'=> 0, 'longitude' => 0); - } - } -} - -if (!function_exists("findPlace")) { - - /* function findPlace() - * - * Function that finds a location(s) based in the information passed to the URL - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $country string Country Name, ISO2 or ISO3 or keyword 'Random' for a country to search - * @param $place string Name of place or component of name of places to search for or keyword 'Random' - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * @param $return integer Number of Result to Limit the selection and return of the API - * - * @return array - */ - function findPlace($country = '', $place = '', $format = 'json', $radius = 1) - { - if (empty($radius) || $radius < 1) - $radius = API_RADIUS_DEFAULT; - - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - $numberof = 0; - $sql = ''; - $ret = array(); - if (strlen($country)>3&&strtolower($country)!='list'&&strtolower($country)!='random') { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`Country`) LIKE '".strtolower($country)."' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1"; - - } elseif (strlen($country)>3&&strtolower($country)=='random') { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() LIMIT 1"; - - } elseif (strlen($country)>3&&strtolower($country)=='list') { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY `Country` ASC "; - - } elseif (strlen($country)==3) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`ISO3`) LIKE '".strtolower($country)."' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1 "; - } elseif (strlen($country)==2) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`ISO2`) LIKE '".strtolower($country)."' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1 "; - } elseif (strlen($country)!=2 && strlen($country)!=3) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`Country`) LIKE '%".strtolower($country)."%' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1 "; - } - $numberof=$seconds=$start=$end=0; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $sql = "SELECT count(*) as records FROM `" . $country['Table'] . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - $table = $country['Table']; - if ($format!='xml') - $ret['countries'][$table] = strippedArray($country, explode('|', API_COUNTRY_FIELDS)); - else - $ret['countries'][$table] = strippedArray($country, explode('|', API_COUNTRY_FIELDS)); - - if (strtolower($place)!='random') { - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` WHERE LOWER(`RegionName`) LIKE '" . strtolower($place) . "%' ORDER BY RAND()"; - } elseif (strtolower($place) == 'random' && strtolower($country) == 'random') - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` ORDER BY RAND()"; - elseif (strtolower($place) == 'random' && strtolower($country) != 'random') { - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` ORDER BY RAND()"; - } else { - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` WHERE LOWER(`RegionName`) LIKE '%" . strtolower($place) . "%' ORDER BY RAND()"; - } - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - while ($region = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($seconds==0) - $seconds = 120; - elseif ($end!=0&&$start!=0) - $seconds = $seconds + ($end - $start * 3); - $start = microtime(true); - set_time_limit($seconds); - if (strpos($region['RegionName'], ',')) { - $parts = explode(',',$region['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $region['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($region['RegionName'])); - if ($format!='xml') - $ret['places'][$table][$region['key']] = strippedArray($region, explode('|', API_PLACES_FIELDS)); - else - $ret['places'][$table][$key] = strippedArray($region, explode('|', API_PLACES_FIELDS)); - $numberof++; - - if ($radius != API_RADIUS_DEFAULT) - { - $latitude = $region['Latitude_Float']; - $longitude = $region['Longitude_Float']; - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($latitude) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($latitude) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $longitude . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` HAVING `Distance` <= ".$radius." ORDER BY `Distance`"; - $ret['search']['countries']++; - unset($resultb); - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) { - while ($nearby = $GLOBALS['APIDB']->fetchArray($resultc)) { - if (strpos($nearby['RegionName'], ',')) { - $parts = explode(',',$nearby['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $nearby['RegionName'] = implode(' ', $parts); - } - $keyb = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($nearby['RegionName'])); - if ($format!='xml') - $ret['places'][$table][$region['key']]['nearby'][$keyb] = strippedArray($nearby, explode('|',API_PLACES_FIELDS)); - else - $ret['places'][$table][$key]['nearby'][$keyb] = strippedArray($nearby, explode('|',API_PLACES_FIELDS)); - } - } - } - $end = microtime(true); - } - } - } - } - return $ret; - } -} - - - -if (!function_exists("findNearby")) { - - /* function findNearby() - * - * Function that finds a location(s) near a latitude & longitude - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $latitude float Latitude to search for places near by - * @param $longitude float Longitude to search for places near by - * @param $radius integer Radius that the search bounded by in kilometers (integer only) - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * - * @return array - */ - function findNearby($latitude = 0, $longitude = 0, $radius = 0, $format = 'json') - { - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - $ret = array(); - $ret['search']['places'] = $ret['search']['countries'] = 0; - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($latitude) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($latitude) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $longitude . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` HAVING `Distance` <= ".$radius." ORDER BY `Distance`"; - $ret['search']['countries']++; - unset($resultb); - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - while ($place = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['search']['places']++; - } - } - } - } - $ret['search']['type'] = 'nearby'; - return $ret; - } -} - - - - -if (!function_exists("findExactly")) { - - /* function findNearby() - * - * Function that finds a location(s) near a latitude & longitude - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $latitude float Latitude to search for places near by - * @param $longitude float Longitude to search for places near by - * @param $radius integer Radius that the search bounded by in kilometers (integer only) - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * - * @return array - */ - function findExactly($latitude = 0, $longitude = 0, $radius = 0, $format = 'json') - { - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - $ret = array(); - $places = $ret['search']['countries'] = $ret['search']['places'] = 0; - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - $ret['search']['countries']++; - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($latitude) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($latitude) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $longitude . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` WHERE `Latitude_Float` >= ".($latitude - (111.32 * ($radius / 1000)))." AND `Longitude_Float` >= ".($longitude - (111.32 * ($radius / 1000)))." AND `Latitude_Float` <= ".($latitude + (111.32 * ($radius / 1000)))." AND `Longitude_Float` <= ".($longitude + (111.32 * ($radius / 1000)))." ORDER BY `Distance`"; - unset($resultb); - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - while ($place = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['search']['places']++; - } - } - } - } - $ret['search']['type'] = 'exactly'; - return $ret; - } -} - -if (!function_exists("findKey")) { - - /* function findKey() - * - * Function that reverse lookups a forensic identifier MD6 of country or region and return one or more locations - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $key string the MD5 32 Character Checksum for the place or country to lookup - * @param $radius integer Radius that the search bounded by in kilometers (integer only) - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * - * @return array - */ - function findKey($key = '', $radius = 0, $format = 'json') - { - - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - error_reporting(E_ERROR); - session_start(); - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - - $sql = ''; - $ret = array(); - $found = false; - $ret['results']['count'] = 0; - - if ( strpos($key, ":") > 0 ) - { - $countryid = substr($key, 0, strpos($key, ":") ); - $key = substr($key, strpos($key, ":") + 1); - } else - $countryid = false; - - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) LIKE '".$key."' GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - } - } - if (!isset($table) && !empty($countryid) && $countryid != false) - { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '".$countryid."' GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - } - } - } - - if (empty($countryid) && $countryid == false && $found==false) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, concat(`RegionName`, ', ', '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE md5(concat(`CountryID`, `CordID`)) LIKE '" . $key . "' ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $place = $GLOBALS['APIDB']->fetchArray($resultb); - $table = $cntry['Table']; - $found = true; - if (!isset($country)) - $country = $cntry; - } - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $place['Longitude_Float']; - $ret['latitude'] = $place['Latitude_Float']; - $ret['address'] = $places['Address']; - } - } - } elseif ($found==false && !empty($countryid)) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '$countryid' ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, concat(`RegionName`, ', ', '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE md5(concat(`CountryID`, `CordID`)) LIKE '" . $key . "' ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $place = $GLOBALS['APIDB']->fetchArray($resultb); - $table = $cntry['Table']; - $found=true; - if (!isset($country)) - $country = $cntry; - } - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $place['Longitude_Float']; - $ret['latitude'] = $place['Latitude_Float']; - $ret['address'] = $places['Address']; - } - } - } - - if (empty($countryid) && $countryid == false && $found==false) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`CountryID`, ':', md5(concat('".$cntry['Table']."_venues', `VenueID`, `CordID`, `CountryID`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE md5(concat('".$cntry['Table']."_venues',`VenueID`,`CordID`,`CountryID`)) LIKE '" . $key . "' ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $venue = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, concat(`RegionName`, ', ', '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $venue['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $ctry['Table']; - $found = true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $venue['Longitude']; - $ret['latitude'] = $venue['Latitude']; - $ret['address'] = $venue['Vicinity']; - } - } - } - } elseif ($found==false && !empty($countryid)) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '$countryid' ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`CountryID`, ':', md5(concat('".$cntry['Table']."_venues', `VenueID`, `CordID`, `CountryID`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE md5(concat('".$cntry['Table']."_venues',`VenueID`,`CordID`,`CountryID`)) LIKE '" . $key . "' ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $venue = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, concat(`RegionName`, ', ', '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $venue['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $cntry['Table']; - $found=true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $venue['Longitude']; - $ret['latitude'] = $venue['Latitude']; - $ret['address'] = $venue['Vicinity']; - } - } - } - } - - if (empty($countryid) && $countryid == false && $found==false) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`CountryID`, ':', md5(concat('".$cntry['Table']."_address', `AddressID`, `CordID`, `CountryID`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE md5(concat('".$cntry['Table']."_address',`AddressID`,`CordID`,`CountryID`)) LIKE '" . $key . "' ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $address = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, concat(`RegionName`, ', ', '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $address['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $cntry['Table']; - $found = true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $address['Longitude']; - $ret['latitude'] = $address['Latitude']; - $ret['address'] = $address['Formatted']; - } - } - } - } elseif ($found==false && !empty($countryid)) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '$countryid' ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`CountryID`, ':', md5(concat('".$cntry['Table']."_address', `AddressID`, `CordID`, `CountryID`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE md5(concat('".$cntry['Table']."_address',`AddressID`,`CordID`,`CountryID`)) LIKE '" . $key . "' ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $address = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, concat(`RegionName`, ', ', '".$country['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $address['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $cntry['Table']; - $found=true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $address['Longitude']; - $ret['latitude'] = $address['Latitude']; - $ret['address'] = $address['Formatted']; - } - } - } - } - - if ($radius <= 0 || $radius == API_RADIUS_DEFAULT) - return $ret; - - if ($found == true && $radius > 0) { - if (isset($ret['results']['places'])) - $places = $ret['results']['places']; - elseif (isset($ret['results']['place'])) - $places = $ret['results']['place']; - foreach($places as $table => $values) { - foreach($values as $key => $place) { - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `Table` LIKE '$table' GROUP BY `CountryID` ORDER BY RAND() "; - $result = $GLOBALS['APIDB']->queryF($sql); - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $sql = "SELECT *, concat(`RegionName`, ', ', '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`CountryID`, `CordID`))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($place['Latitude_Float']) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($place['Latitude_Float']) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $place['Longitude_Float'] . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance`, concat(`RegionName`, ', ', '".$country['Country']."') as `Address` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` HAVING `Distance` <= ".$radius." ORDER BY `Distance`"; - $resultb = $GLOBALS['APIDB']->queryF($sql); - while ($place = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($format!='xml') - $ret['results']['nearby']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['nearby']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['nearby']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['nearby']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby']++; - } - } - } - } - if ($ret['results']['nearby']>0) - $ret['results']['type'] = 'keyed'; - } - return $ret; - } -} - -if (!function_exists("getAddressGeoMapping")) -{ - /** - * gets Geo Longitude + Latitude for an known address - * - * @param string $address - * @return number[]|unknown[]|mixed[] - */ - function getAddressGeoMapping($address = '') - { - $geo = json_decode(getURIData('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false'), true); - $latitude = $longitude = 0.0001; - if ($geo['status'] == 'OK') { - $address = array(); - foreach($geo['results'][0]['address_components'] as $values) - { - if (in_array('administrative_area_level_1', $values['types']) && in_array('political', $values['types'])) - $address['State'] = $values['long_name']; - elseif (in_array('administrative_area_level_2', $values['types']) && in_array('political', $values['types'])) - $address['Council'] = $values['short_name']; - elseif (in_array('postal_code', $values['types'])) - $address['Postcode'] = $values['long_name']; - elseif (in_array('subpremise', $values['types'])) - $address['Unit'] = $values['long_name']; - elseif (in_array('street_number', $values['types'])) - $address['Building'] = $values['long_name']; - elseif (in_array('route', $values['types'])) - $address['Street'] = $values['long_na... [truncated message content] |
From: <wis...@us...> - 2017-10-06 22:54:50
|
Revision: 13300 http://sourceforge.net/p/xoops/svn/13300 Author: wishcraft Date: 2017-10-06 22:54:47 +0000 (Fri, 06 Oct 2017) Log Message: ----------- GeoSpatial Places API Service ~ Version 2.3.2! Modified Paths: -------------- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/cache/file.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/logger/apilogger.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/help.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/version.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/index.php Added Paths: ----------- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/assets/media/Life BT Bold Italic/Life BT Bold Italic.ufo/glyphs/F_.glif Added: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/assets/media/Life BT Bold Italic/Life BT Bold Italic.ufo/glyphs/F_.glif =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/assets/media/Life BT Bold Italic/Life BT Bold Italic.ufo/glyphs/F_.glif (rev 0) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/assets/media/Life BT Bold Italic/Life BT Bold Italic.ufo/glyphs/F_.glif 2017-10-06 22:54:47 UTC (rev 13300) @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<glyph name="F" format="1"> + <advance width="1237"/> + <unicode hex="0046"/> + <outline> + <contour> + <point x="240" y="1468" type="line"/> + <point x="291" y="1466"/> + <point x="360" y="1465" type="qcurve" smooth="yes"/> + <point x="405" y="1464"/> + <point x="586" y="1464" type="qcurve"/> + <point x="1286" y="1468" type="line"/> + <point x="1263" y="1337"/> + <point x="1255" y="1282" type="qcurve" smooth="yes"/> + <point x="1236" y="1149"/> + <point x="1229" y="1098" type="qcurve"/> + <point x="1163" y="1098" type="line"/> + <point x="1163" y="1244"/> + <point x="1112" y="1303" type="qcurve"/> + <point x="1059" y="1362"/> + <point x="930" y="1362" type="qcurve" smooth="yes"/> + <point x="791" y="1362" type="line" smooth="yes"/> + <point x="755" y="1362"/> + <point x="744" y="1352" type="qcurve"/> + <point x="732" y="1344"/> + <point x="721" y="1300" type="qcurve"/> + <point x="614" y="815" type="line"/> + <point x="741" y="815" type="line" smooth="yes"/> + <point x="856" y="815"/> + <point x="906" y="851" type="qcurve" smooth="yes"/> + <point x="956" y="887"/> + <point x="981" y="981" type="qcurve"/> + <point x="1047" y="981" type="line"/> + <point x="1011" y="852"/> + <point x="987" y="738" type="qcurve" smooth="yes"/> + <point x="962" y="623"/> + <point x="942" y="508" type="qcurve"/> + <point x="877" y="508" type="line"/> + <point x="883" y="545"/> + <point x="886" y="569" type="qcurve" smooth="yes"/> + <point x="889" y="594"/> + <point x="889" y="610" type="qcurve" smooth="yes"/> + <point x="889" y="668"/> + <point x="858" y="690" type="qcurve" smooth="yes"/> + <point x="826" y="713"/> + <point x="737" y="713" type="qcurve" smooth="yes"/> + <point x="592" y="713" type="line"/> + <point x="483" y="229" type="line" smooth="yes"/> + <point x="479" y="215"/> + <point x="472" y="176" type="qcurve"/> + <point x="469" y="150"/> + <point x="469" y="135" type="qcurve" smooth="yes"/> + <point x="469" y="93"/> + <point x="500" y="77" type="qcurve"/> + <point x="530" y="60"/> + <point x="627" y="59" type="qcurve"/> + <point x="627" y="-6" type="line"/> + <point x="507" y="0"/> + <point x="418" y="3" type="qcurve" smooth="yes"/> + <point x="328" y="6"/> + <point x="266" y="6" type="qcurve" smooth="yes"/> + <point x="171" y="6"/> + <point x="-58" y="-5" type="qcurve"/> + <point x="-76" y="-6" type="line"/> + <point x="-76" y="59" type="line"/> + <point x="30" y="59"/> + <point x="76" y="90" type="qcurve"/> + <point x="120" y="125"/> + <point x="145" y="242" type="qcurve" smooth="yes"/> + <point x="365" y="1235" type="line"/> + <point x="365" y="1237" type="line"/> + <point x="379" y="1305"/> + <point x="379" y="1327" type="qcurve" smooth="yes"/> + <point x="379" y="1368"/> + <point x="352" y="1385" type="qcurve" smooth="yes"/> + <point x="327" y="1400"/> + <point x="240" y="1405" type="qcurve"/> + </contour> + </outline> +</glyph> Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/cache/file.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/cache/file.php 2017-10-06 19:57:52 UTC (rev 13299) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/cache/file.php 2017-10-06 22:54:47 UTC (rev 13300) @@ -110,7 +110,7 @@ 'extension' => '.php', 'prefix' => 'api_', 'lock' => false, - 'serialize' => false, + 'serialize' => true, 'duration' => 31556926); $this->settings = array_merge($defaults, $this->settings); if (!isset($this->file)) { @@ -221,7 +221,11 @@ $data = APIUtility::recursive('stripslashes', $data); } } elseif ($data && empty($this->settings['serialize'])) { - $data = eval($data); + try { + $data = eval($data); + } catch (Exception $e) { + $data = false; + } } $this->file->close(); Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/logger/apilogger.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/logger/apilogger.php 2017-10-06 19:57:52 UTC (rev 13299) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/class/logger/apilogger.php 2017-10-06 22:54:47 UTC (rev 13300) @@ -49,7 +49,7 @@ */ public $usePopup = false; - public $activated = true; + public $activated = false; /** * *@access protected @@ -224,7 +224,7 @@ $trace = false; $errstr = substr($errstr, 8); } - echo sprintf(_API_FATAL_MESSAGE, $errstr); + echo sprintf('Fatal: %s ~ (%s:%s)', $errstr, basename($errfile), $errline); if ($trace && function_exists('debug_backtrace')) { echo "<div style='color:#f0f0f0;background-color:#f0f0f0;'>" . _API_FATAL_BACKTRACE . ':<br>'; $trace = debug_backtrace(); Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php 2017-10-06 19:57:52 UTC (rev 13299) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php 2017-10-06 22:54:47 UTC (rev 13300) @@ -120,7 +120,7 @@ if (list($key) = $GLOBALS['APIDB']->fetchRow($result)) return $key; } - $ret = array(); + return array(); } } } @@ -167,7 +167,7 @@ if ($place = $GLOBALS['APIDB']->fetchArray($result)) return array('latitude'=>$place['Latitude_Float'], 'longitude' => $place['Longitude_Float']); } - $ret = array('latitude'=> 0, 'longitude' => 0); + return array('latitude'=> 0, 'longitude' => 0); } } } Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/help.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/help.php 2017-10-06 19:57:52 UTC (rev 13299) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/help.php 2017-10-06 22:54:47 UTC (rev 13300) @@ -33,11 +33,11 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> -<meta property="og:title" content="Geographical API API Services"/> -<meta property="og:type" content="api"/> +<meta property="og:title" content="<?php echo API_VERSION; ?>"/> +<meta property="og:type" content="api<?php echo API_TYPE; ?>"/> <meta property="og:image" content="<?php echo API_URL; ?>/assets/images/logo_500x500.png"/> <meta property="og:url" content="<?php echo (isset($_SERVER["HTTPS"])?"https://":"http://").$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; ?>" /> -<meta property="og:site_name" content="<?php echo API_LICENSE_COMPANY; ?>"/> +<meta property="og:site_name" content="<?php echo API_VERSION; ?> - <?php echo API_LICENSE_COMPANY; ?>"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="rating" content="general" /> <meta http-equiv="<?php echo $place['iso2']; ?>thor" content="wis...@us..." /> @@ -94,7 +94,7 @@ <body> <div class="main"> <img style="float: right; margin: 11px; width: auto; height: auto; clear: none;" src="<?php echo API_URL; ?>/assets/images/logo_350x350.png" /> - <h1>Geographical API API Services -- <?php echo API_LICENSE_COMPANY; ?></h1> + <h1><?php echo API_VERSION; ?> -- <?php echo API_LICENSE_COMPANY; ?></h1> <p>This is an API Service for conducting a locational search for a place. It provides the longitude, latitude and altitude of place being searched for and provides responses when access the API inclusing JSON, XML, Serialisation, HTML and RAW outputs.</p> <p>You can access the API currently without a key or system it is an open api and was written in response to the many API Services that charge ridiculous amounts for querying such a simple base. The following instructions are how to access the api I hope you enjoy this api as I have writting it!.</p> <h2>Examples of Calls (Using JSON)</h2> Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/version.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/version.php 2017-10-06 19:57:52 UTC (rev 13299) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/version.php 2017-10-06 22:54:47 UTC (rev 13300) @@ -29,5 +29,5 @@ /** * Define API version */ -define('API_VERSION', 'GeoSpatial API API 2.3.1'); +define('API_VERSION', 'GeoSpatial Places API 2.3.2'); define('API_TYPE', 'places'); Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/index.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/index.php 2017-10-06 19:57:52 UTC (rev 13299) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/index.php 2017-10-06 22:54:47 UTC (rev 13300) @@ -21,290 +21,297 @@ * @see https://github.com/Chronolabs-Cooperative/API-API-PHP */ - define('_API_FATAL_MESSAGE', 'Fatal: %s!'); - - include_once __DIR__ . DIRECTORY_SEPARATOR . 'mainfile.ph'; - error_reporting(E_ERROR); - ini_set('display_errors', true); - ini_set('log_errors', true); - ini_set('error_log', __DIR__ . DIRECTORY_SEPARATOR . date('Y-m') .'--error-log.txt'); - - $parts = explode(".", microtime(true)); - mt_srand(mt_rand(-time(), time())/$parts[1]); - mt_srand(mt_rand(-time(), time())/$parts[1]); - mt_srand(mt_rand(-time(), time())/$parts[1]); - mt_srand(mt_rand(-time(), time())/$parts[1]); - $salter = ((float)(mt_rand(0,1)==1?'':'-').$parts[1].'.'.$parts[0]) / sqrt((float)$parts[1].'.'.intval(cosh($parts[0])))*tanh($parts[1]) * mt_rand(1, intval($parts[0] / $parts[1])); - header('Blowfish-salt: '. $salter); - - global $domain, $protocol, $business, $entity, $contact, $referee, $peerings, $source; - require_once __DIR__ . DIRECTORY_SEPARATOR . 'apiconfig.php'; - require_once __DIR__ . DIRECTORY_SEPARATOR . 'verify.php'; - - /** - * URI Path Finding of API URL Source Locality - * @var unknown_type - */ - $odds = $inner = array(); - foreach($_GET as $key => $values) { - if (!isset($inner[$key])) { - $inner[$key] = $values; - } elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) { - if (is_array($values)) { - $odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values; - } else { - $odds[$key][$inner[$key] = $values] = "$values--$key"; - } +define('_API_FATAL_MESSAGE', 'Fatal: %s!'); + +$parts = explode(".", microtime(true)); +mt_srand(mt_rand(-time(), time())/$parts[1]); +mt_srand(mt_rand(-time(), time())/$parts[1]); +mt_srand(mt_rand(-time(), time())/$parts[1]); +mt_srand(mt_rand(-time(), time())/$parts[1]); +$salter = ((float)(mt_rand(0,1)==1?'':'-').$parts[1].'.'.$parts[0]) / sqrt((float)$parts[1].'.'.intval(cosh($parts[0])))*tanh($parts[1]) * mt_rand(1, intval($parts[0] / $parts[1])); +header('Blowfish-salt: '. $salter); + +global $source; +require_once __DIR__ . DIRECTORY_SEPARATOR . 'apiconfig.php'; +require_once __DIR__ . DIRECTORY_SEPARATOR . 'verify.php'; +$GLOBALS['APILogger']->activated = false; + +/** + * URI Path Finding of API URL Source Locality + * @var unknown_type + */ +$odds = $inner = array(); +foreach($_GET as $key => $values) { + if (!isset($inner[$key])) { + $inner[$key] = $values; + } elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) { + if (is_array($values)) { + $odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values; + } else { + $odds[$key][$inner[$key] = $values] = "$values--$key"; } - } - - foreach($_POST as $key => $values) { - if (!isset($inner[$key])) { - $inner[$key] = $values; - } elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) { - if (is_array($values)) { - $odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values; - } else { - $odds[$key][$inner[$key] = $values] = "$values--$key"; - } - } - } - - foreach(parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'], '?')?'&':'?').$_SERVER['QUERY_STRING'], PHP_URL_QUERY) as $key => $values) { - if (!isset($inner[$key])) { - $inner[$key] = $values; - } elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) { - if (is_array($values)) { - $odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values; - } else { - $odds[$key][$inner[$key] = $values] = "$values--$key"; - } - } - } - - $help=false; - if ((!isset($inner['country']) || empty($inner['country'])) && (!isset($inner['place']) || empty($inner['place'])) && (!isset($inner['address']) || empty($inner['address']))) { - $help=true; - } elseif (isset($inner['output']) || !empty($inner['output'])) { - if (isset($inner['country']) && $inner['country'] == 'list') { - $output = trim($inner['output']); - switch ($inner['place']) - { - default: - $mode = 'countries'; - break; - case 'continents': - $mode = 'continents'; - break; - case 'types': - $mode = 'types'; - break; - } - } elseif (isset($inner['country']) && $inner['country'] == 'key') { - $key = trim($inner['place']); - $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; - if ($radius<0) - $radius = 0; - elseif ($radius>245) - $radius = 145; - $output = trim($inner['output']); - $mode = 'key'; - } elseif (isset($inner['country']) && $inner['country'] == 'nearby') { - $latitude = (float)$inner['latitude']; - $longitude = (float)$inner['longitude']; - $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; - if ($radius<0) - $radius = 0; - elseif ($radius>245) - $radius = 145; - $output = trim($inner['output']); - $mode = 'nearby'; - } elseif (isset($inner['country']) && $inner['country'] == 'exactly') { - $latitude = (float)$inner['latitude']; - $longitude = (float)$inner['longitude']; - $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; - if ($radius<0) - $radius = 0; - elseif ($radius>245) - $radius = 145; - $output = trim($inner['output']); - $mode = 'exactly'; - } elseif (isset($inner['country']) && $inner['country'] == 'venues') { - $key = (string)$inner['place']; - $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; - if ($radius<0) - $radius = 0; - elseif ($radius>245) - $radius = 145; - $output = trim($inner['output']); - $type = trim($inner['type']); - $mode = 'venues'; - } elseif (isset($inner['country']) && $inner['country'] == 'maps') { - $key = (string)$inner['place']; - $output = trim($inner['output']); - $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; - $mode = 'maps'; - } elseif (isset($inner['country']) && $inner['country'] == 'details') { - $key = (string)$inner['place']; - $output = trim($inner['output']); - $mode = 'details'; - } elseif (isset($inner['country']) && $inner['country'] == 'address') { - $address = (string)(!isset($inner['place'])?$inner['address']:$inner['place']); - $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; - $output = trim($inner['output']); - $type = trim($inner['type']); - $mode = 'address'; - } else { - $mode = 'place'; - $country = trim($inner['country']); - $place = trim($inner['place']); - $output = trim($inner['output']); - $number = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; - } + } +} + +foreach($_POST as $key => $values) { + if (!isset($inner[$key])) { + $inner[$key] = $values; + } elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) { + if (is_array($values)) { + $odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values; + } else { + $odds[$key][$inner[$key] = $values] = "$values--$key"; + } + } +} + +foreach(parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'], '?')?'&':'?').$_SERVER['QUERY_STRING'], PHP_URL_QUERY) as $key => $values) { + if (!isset($inner[$key])) { + $inner[$key] = $values; + } elseif (!in_array(!is_array($values) ? $values : md5(json_encode($values, true)), array_keys($odds[$key]))) { + if (is_array($values)) { + $odds[$key][md5(json_encode($inner[$key] = $values, true))] = $values; + } else { + $odds[$key][$inner[$key] = $values] = "$values--$key"; + } + } +} + +error_reporting(0); +$help=false; +if ((!isset($inner['country']) || empty($inner['country'])) && (!isset($inner['place']) || empty($inner['place'])) && (!isset($inner['address']) || empty($inner['address']))) { + $help=true; +} elseif (isset($inner['output']) || !empty($inner['output'])) { + if (isset($inner['country']) && $inner['country'] == 'list') { + $output = trim($inner['output']); + switch ($inner['place']) + { + default: + $mode = 'countries'; + break; + case 'continents': + $mode = 'continents'; + break; + case 'types': + $mode = 'types'; + break; + } + } elseif (isset($inner['country']) && $inner['country'] == 'key') { + $key = trim($inner['place']); + $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; + if ($radius<0) + $radius = 0; + elseif ($radius>245) + $radius = 145; + $output = trim($inner['output']); + $mode = 'key'; + } elseif (isset($inner['country']) && $inner['country'] == 'nearby') { + $latitude = (float)$inner['latitude']; + $longitude = (float)$inner['longitude']; + $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; + if ($radius<0) + $radius = 0; + elseif ($radius>245) + $radius = 145; + $output = trim($inner['output']); + $mode = 'nearby'; + } elseif (isset($inner['country']) && $inner['country'] == 'exactly') { + $latitude = (float)$inner['latitude']; + $longitude = (float)$inner['longitude']; + $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; + if ($radius<0) + $radius = 0; + elseif ($radius>245) + $radius = 145; + $output = trim($inner['output']); + $mode = 'exactly'; + } elseif (isset($inner['country']) && $inner['country'] == 'venues') { + $key = (string)$inner['place']; + $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; + if ($radius<0) + $radius = 0; + elseif ($radius>245) + $radius = 145; + $output = trim($inner['output']); + $type = trim($inner['type']); + $mode = 'venues'; + } elseif (isset($inner['country']) && $inner['country'] == 'maps') { + $key = (string)$inner['place']; + $output = trim($inner['output']); + $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; + $mode = 'maps'; + } elseif (isset($inner['country']) && $inner['country'] == 'details') { + $key = (string)$inner['place']; + $output = trim($inner['output']); + $mode = 'details'; + } elseif (isset($inner['country']) && $inner['country'] == 'address') { + $address = (string)(!isset($inner['place'])?$inner['address']:$inner['place']); + $radius = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; + $output = trim($inner['output']); + $type = trim($inner['type']); + $mode = 'address'; } else { - $help=true; + $mode = 'place'; + $country = trim($inner['country']); + $place = trim($inner['place']); + $output = trim($inner['output']); + $number = isset($inner['radius'])?(float)$inner['radius']:API_RADIUS_DEFAULT; } - - if ($help==true) { - http_response_code(400); - include dirname(__FILE__).'/help.php'; - if ($sessions = APICache::read('sessions-'.md5($_SERVER['HTTP_HOST']))) +} else { + $help=true; +} + +error_reporting(0); +if ($help==true) { + http_response_code(400); + include dirname(__FILE__).'/help.php'; + if ($sessions = @APICache::read('sessions-'.md5($_SERVER['HTTP_HOST']))) + { + foreach($sessions as $key => $seconds) + if ($seconds<time()) { - foreach($sessions as $key => $seconds) - if ($seconds<time()) - { - APICache::delete($key); - unset ($sessions[$key]); - } - APICache::write('sessions-'.md5($_SERVER['HTTP_HOST']), $sessions, API_CACHE_SECONDS * API_CACHE_SECONDS * API_CACHE_SECONDS); + @APICache::delete($key); + unset ($sessions[$key]); } - exit; + @APICache::write('sessions-'.md5($_SERVER['HTTP_HOST']), $sessions, API_CACHE_SECONDS * API_CACHE_SECONDS * API_CACHE_SECONDS); } - http_response_code(200); - if ($country == 'random' || $place == 'random') - $keyname = md5(whitelistGetIP(true) . '___' . $_SERVER['HTTP_HOST'] . '___' . $_SERVER['REQUEST_URI']); - else - $keyname = md5($_SERVER['REQUEST_URI']); - if (!$data = APICache::read($keyname)) - { - $retries = 0; - $data = array(); - while (empty($data) || $retries<11) - { - $retries++; - switch ($mode) { - case 'countries': - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `$mode` GROUP BY `CountryID` ORDER BY `Country`"; - $result = $GLOBALS['DebauchDB']->queryF($sql); - while($row = $GLOBALS['DebauchDB']->fetchArray($result)) - { - $table = $row['Table']; - unset($row['Table']); - unset($row['CountryID']); - if ($output!='xml') - $data[$row['key']] = strippedArray($row, explode("|", API_COUNTRY_FIELDS)); - else - $data[$table] = strippedArray($row, explode("|", API_COUNTRY_FIELDS)); - } - break; - case 'continents': - $sql = "SELECT *, md5(concat(`ContinentID`, `Continent`, max(`ContinentID`) - `ContinentID` + 1)) as `key` FROM `$mode` GROUP BY `ContinentID` ORDER BY `Continent`"; - $result = $GLOBALS['DebauchDB']->queryF($sql); - while($row = $GLOBALS['DebauchDB']->fetchArray($result)) - { - $continent = str_replace(array(" ", "'". "`", "-"), "", ucwords(strtolower($row['Continent']))); - unset($row['ContinentID']); - if ($output!='xml') - $data[$row['key']] = strippedArray($row, explode("|", API_CONTINENT_FIELDS)); - else - $data[$continent] = strippedArray($row, explode("|", API_CONTINENT_FIELDS)); - } - break; - case 'types': - $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `$mode` GROUP BY `CountryID` ORDER BY `Country`"; - $result = $GLOBALS['DebauchDB']->queryF($sql); - while($row = $GLOBALS['DebauchDB']->fetchArray($result)) - { - $table = $row['Table']; - unset($row['Table']); - unset($row['CountryID']); - if ($output!='xml') - $data[$row['key']] = strippedArray($row, explode("|", API_COUNTRY_FIELDS)); - else - $data[$table] = strippedArray($row, explode("|", API_COUNTRY_FIELDS)); - } - break; - case 'place': - $data = findPlace($country, $place, $output, $number); - break; - case 'nearby': - $data = findNearby($latitude, $longitude, $radius, $output); - break; - case 'exactly': - $data = findExactly($latitude, $longitude, $radius, $output); - break; - case 'key': - $data = findKey($key, $radius, $output); - break; - case 'maps': - $data = findKeyMaps($key, $radius, $output); - break; - case 'details': - $data = findKeyDetails($key, $output); - break; - case 'venues': - $data = findKeyVenues($key, $type, $radius, $output); - break; - case 'address': - $data = findAddressVenues($address, $type, $radius, $output); - break; - } + exit; +} - } - if (!empty($data)) - { - APICache::write($keyname, $data, API_CACHE_SECONDS); - if (!$sessions = APICache::read('sessions-'.md5($_SERVER['HTTP_HOST']))) - $sessions = array(); - $sessions[$keyname] = time() + API_CACHE_SECONDS; - APICache::write('sessions-'.md5($_SERVER['HTTP_HOST']), $sessions, API_CACHE_SECONDS * API_CACHE_SECONDS * API_CACHE_SECONDS); - } - } - - switch ($output) { - default: - echo '<h1>' . $country . ' - ' . $place . ' (API data)</h1>'; - echo '<pre style="font-family: \'Courier New\', Courier, Terminal; font-size: 0.77em;">'; - echo print_r($data, true); - echo '</pre>'; +error_reporting(0); +http_response_code(200); +if ($country == 'random' || $place == 'random') + $keyname = md5(whitelistGetIP(true) . '___' . $_SERVER['HTTP_HOST'] . '___' . $_SERVER['REQUEST_URI']); +else + $keyname = md5($_SERVER['REQUEST_URI']); +if (!$data = APICache::read($keyname)) +{ + $retries = 0; + $data = array(); + while (empty($data) || $retries<11) + { + $retries++; + switch ($mode) { + case 'countries': + $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `$mode` GROUP BY `CountryID` ORDER BY `Country`"; + $result = $GLOBALS['DebauchDB']->queryF($sql); + while($row = $GLOBALS['DebauchDB']->fetchArray($result)) + { + $table = $row['Table']; + unset($row['Table']); + unset($row['CountryID']); + if ($output!='xml') + $data[$row['key']] = @strippedArray($row, explode("|", API_COUNTRY_FIELDS)); + else + $data[$table] = @strippedArray($row, explode("|", API_COUNTRY_FIELDS)); + } break; - case 'raw': - echo "<?php\n\nreturn " . var_export($data, true) . ";\n\n?>"; + case 'continents': + $sql = "SELECT *, md5(concat(`ContinentID`, `Continent`, max(`ContinentID`) - `ContinentID` + 1)) as `key` FROM `$mode` GROUP BY `ContinentID` ORDER BY `Continent`"; + $result = $GLOBALS['DebauchDB']->queryF($sql); + while($row = $GLOBALS['DebauchDB']->fetchArray($result)) + { + $continent = str_replace(array(" ", "'". "`", "-"), "", ucwords(strtolower($row['Continent']))); + unset($row['ContinentID']); + if ($output!='xml') + $data[$row['key']] = @strippedArray($row, explode("|", API_CONTINENT_FIELDS)); + else + $data[$continent] = @strippedArray($row, explode("|", API_CONTINENT_FIELDS)); + } break; - case 'json': - header('Content-type: application/json'); - echo json_encode($data); + case 'types': + $sql = "SELECT *, md5(concat(`CountryID`, `Country`, max(`CountryID`) - `CountryID` + 1)) as `key` FROM `$mode` GROUP BY `CountryID` ORDER BY `Country`"; + $result = $GLOBALS['DebauchDB']->queryF($sql); + while($row = $GLOBALS['DebauchDB']->fetchArray($result)) + { + $table = $row['Table']; + unset($row['Table']); + unset($row['CountryID']); + if ($output!='xml') + $data[$row['key']] = @strippedArray($row, explode("|", API_COUNTRY_FIELDS)); + else + $data[$table] = @strippedArray($row, explode("|", API_COUNTRY_FIELDS)); + } break; - case 'serial': - header('Content-type: text/html'); - echo serialize($data); + case 'place': + $data = @findPlace($country, $place, $output, $number); break; - case 'xml': - header('Content-type: application/xml'); - $dom = new XmlDomConstruct('1.0', 'utf-8'); - $dom->fromMixed(array($mode=>$data)); - echo $dom->saveXML(); + case 'nearby': + $data = @findNearby($latitude, $longitude, $radius, $output); break; - } - - if ($sessions = APICache::read('sessions-'.md5($_SERVER['HTTP_HOST']))) - { - foreach($sessions as $key => $seconds) - if ($seconds<time()) - { - APICache::delete($key); - unset ($sessions[$key]); - } - APICache::write('sessions-'.md5($_SERVER['HTTP_HOST']), $sessions, API_CACHE_SECONDS * API_CACHE_SECONDS * API_CACHE_SECONDS); - } -?> \ No newline at end of file + case 'exactly': + $data = @findExactly($latitude, $longitude, $radius, $output); + break; + case 'key': + $data = @findKey($key, $radius, $output); + break; + case 'maps': + $data = @findKeyMaps($key, $radius, $output); + break; + case 'details': + $data = @findKeyDetails($key, $output); + break; + case 'venues': + $data = @findKeyVenues($key, $type, $radius, $output); + break; + case 'address': + $data = @findAddressVenues($address, $type, $radius, $output); + break; + } + + } +} + +error_reporting(0); +if (!empty($data)) +{ + @APICache::write($keyname, $data, API_CACHE_SECONDS); + if (!$sessions = APICache::read('sessions-'.md5($_SERVER['HTTP_HOST']))) + $sessions = array(); + $sessions[$keyname] = time() + API_CACHE_SECONDS; + @APICache::write('sessions-'.md5($_SERVER['HTTP_HOST']), $sessions, API_CACHE_SECONDS * API_CACHE_SECONDS * API_CACHE_SECONDS); +} + +if (function_exists('mb_http_output')) { + mb_http_output('pass'); +} + +error_reporting(0); +switch ($output) { + default: + echo '<h1>' . $country . ' - ' . $place . ' (API data)</h1>'; + echo '<pre style="font-family: \'Courier New\', Courier, Terminal; font-size: 0.77em;">'; + echo print_r($data, true); + echo '</pre>'; + break; + case 'raw': + echo ('<?php'."\n\n".'return ' . var_export($data, true) . ";\n\n?>"); + break; + case 'json': + header('Content-type: application/json'); + echo (json_encode($data)); + break; + case 'serial': + header('Content-type: text/html'); + echo (serialize($data)); + break; + case 'xml': + header('Content-type: application/xml'); + $dom = new XmlDomConstruct('1.0', 'utf-8'); + $dom->fromMixed(array($mode=>$data)); + echo ($dom->saveXML()); + break; +} + + +error_reporting(0); +if ($sessions = @APICache::read('sessions-'.md5($_SERVER['HTTP_HOST']))) +{ + foreach($sessions as $key => $seconds) + if ($seconds<time()) + { + @APICache::delete($key); + unset ($sessions[$key]); + } + @APICache::write('sessions-'.md5($_SERVER['HTTP_HOST']), $sessions, API_CACHE_SECONDS * API_CACHE_SECONDS * API_CACHE_SECONDS); +} |
From: <chr...@us...> - 2018-04-18 22:23:08
|
Revision: 13345 http://sourceforge.net/p/xoops/svn/13345 Author: chronolabscoop Date: 2018-04-18 22:21:32 +0000 (Wed, 18 Apr 2018) Log Message: ----------- GeoSpatial + Locational Places Services API 3.0.11! Modified Paths: -------------- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/common.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/functions.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/version.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/index.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/install/include/config.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/install/include/page.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/install/language/english/install.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/install/page_configsave.php Added Paths: ----------- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/verify.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/install/include/constants.dist.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/install/page_extrasettings.php Removed Paths: ------------- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/common.inc.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/config.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/createconfigform.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/dbconfig.dist.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/install_tpl.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/license.dist.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/mainfile.dist.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/makedata.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/include/page.php *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/verify.php Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md 2018-02-24 13:38:12 UTC (rev 13344) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/README.md 2018-04-18 22:21:32 UTC (rev 13345) @@ -1,10 +1,10 @@ ## Chronolabs Cooperative presents -# GeoSpatial + Locational Places Services API 3.0.9 +# GeoSpatial + Locational Places Services API 3.0.10 -### Author: Simon Antony Roberts <simon@snails.email> +### Author: Simon Antony Roberts <wis...@us...> -#### Demo: http://places.snails.email or http://places.xortify.com +#### Demo: http://places.snails.email This API is a Geospatial service provided by PHP7.0 - it utilises file caches as well as a mysqli database interface to provide and provision both locality keys as well as country and continent keys. Modified: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php 2018-02-24 13:38:12 UTC (rev 13344) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/apiconfig.php 2018-04-18 22:21:32 UTC (rev 13345) @@ -59,7 +59,6 @@ /** * Keys & Identify Strings */ -define('API_GOOGLE_KEY','AIzaSyD0tstaeCtH0gugLJUeYcUSUT_TdXL24Uo'); // Get from: https://developers.google.com/places/web-service/get-api-key = API_GOOGLE_KEY define('API_PLACES_FIELDS', 'Address|Distance|RegionName|mapref_latitude|mapref_longitude|Latitude_Float|Longitude_Float|Altitude_Feet|Altitude_Meters|key'); define('API_COUNTRY_FIELDS', 'Country|ISO2|FIPS104|ISO3|ISON|TLD|Capital|Continent|NationalitySingular|NationalityPlural|Currency|CurrencyCode|Population|Records|Updates|API|Details|key|distance'); define('API_CONTINENT_FIELDS', 'Continent|key|Population|Records|API|Details|Updates'); @@ -69,7 +68,6 @@ /** * Include libraries */ -require_once __DIR__ . DIRECTORY_SEPARATOR . 'functions.php'; require_once __DIR__ . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'file' . DIRECTORY_SEPARATOR . 'apifile.php'; require_once __DIR__ . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'apicache.php'; Deleted: *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php 2018-02-24 13:38:12 UTC (rev 13344) +++ *.xoops.org (Subdomain APIs & Sites)/places.xoops.org/functions.php 2018-04-18 22:21:32 UTC (rev 13345) @@ -1,2113 +0,0 @@ -<?php -/** - * Chronolabs REST Geospatial API Services API - * - * You may not change or alter any portion of this comment or credits - * of supporting developers from this source code or any supporting source code - * which is considered copyrighted (c) material of the original comment or credit authors. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * @copyright Chronolabs Cooperative http://snails.email - * @license GNU GPL 3 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package api - * @since 2.0.1 - * @author Simon Roberts <wis...@us...> - * @subpackage places - * @description Geospatial API Services API - * @see http://internetfounder.wordpress.com - * @see http://sourceoforge.net/projects/chronolabsapis - * @see https://github.com/Chronolabs-Cooperative/API-API-PHP - */ - - -if (!function_exists("whitelistGetIP")) { - - /* function whitelistGetIPAddy() - * - * provides an associative array of whitelisted IP Addresses - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return array - */ - function whitelistGetIPAddy() { - return array_merge(whitelistGetNetBIOSIP(), file(dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'whitelist.txt')); - } -} - -if (!function_exists("whitelistGetNetBIOSIP")) { - - /* function whitelistGetNetBIOSIP() - * - * provides an associative array of whitelisted IP Addresses base on TLD and NetBIOS Addresses - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return array - */ - function whitelistGetNetBIOSIP() { - $ret = array(); - foreach(file(dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'whitelist-domains.txt') as $domain) { - $ip = gethostbyname($domain); - $ret[$ip] = $ip; - } - return $ret; - } -} - -if (!function_exists("whitelistGetIP")) { - - /* function whitelistGetIP() - * - * get the True IPv4/IPv6 address of the client using the API - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $asString boolean Whether to return an address or network long integer - * - * @return mixed - */ - function whitelistGetIP($asString = true){ - // Gets the proxy ip sent by the user - $proxy_ip = ''; - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } else - if (!empty($_SERVER['HTTP_X_FORWARDED'])) { - $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; - } else - if (! empty($_SERVER['HTTP_FORWARDED_FOR'])) { - $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; - } else - if (!empty($_SERVER['HTTP_FORWARDED'])) { - $proxy_ip = $_SERVER['HTTP_FORWARDED']; - } else - if (!empty($_SERVER['HTTP_VIA'])) { - $proxy_ip = $_SERVER['HTTP_VIA']; - } else - if (!empty($_SERVER['HTTP_X_COMING_FROM'])) { - $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; - } else - if (!empty($_SERVER['HTTP_COMING_FROM'])) { - $proxy_ip = $_SERVER['HTTP_COMING_FROM']; - } - if (!empty($proxy_ip) && $is_ip = preg_match('/^([0-9]{1,3}.){3,3}[0-9]{1,3}/', $proxy_ip, $regs) && count($regs) > 0) { - $the_IP = $regs[0]; - } else { - $the_IP = $_SERVER['REMOTE_ADDR']; - } - - $the_IP = ($asString) ? $the_IP : ip2long($the_IP); - return $the_IP; - } -} - -if (!function_exists("randomAPIKey")) { - - /* function randomAPIKey() - * - * Get a random forensic identify key for a place from the database - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return string(32) - */ - function randomAPIKey() - { - $sql = "SELECT * FROM `".$GLOBALS['APIDB']->prefix("countries") . "` WHERE `Records` > 1000 ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - $country = $GLOBALS['APIDB']->fetchArray($result); - $sql = "SELECT concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($country['Table']) . "` ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if (list($key) = $GLOBALS['APIDB']->fetchRow($result)) - return $key; - } - return array(); - } - } -} - -if (!function_exists("randomGeoPlace")) { - - /* function randomAPIKey() - * - * Get a random forensic identify key for a place from the database - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return string(32) - */ - function randomGeoPlace() - { - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `Records` > 1000 ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - $country = $GLOBALS['APIDB']->fetchArray($result); - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix($country['Table']) . "` ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if ($place = $GLOBALS['APIDB']->fetchArray($result)) - return array('country' => $country['Country'], 'iso3' => $country['ISO3'], 'iso2' => $country['ISO2'], 'region' => $place['RegionName']); - } - } - return false; - } -} -if (!function_exists("randomGeoLocation")) { - - /* function randomGeoLocation() - * - * Get a random latitude & longitude for a place from the database - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @return array - */ - function randomGeoLocation() - { - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `Records` > 1000 ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - $country = $GLOBALS['APIDB']->fetchArray($result); - $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix($country['Table']) . "` ORDER BY RAND() LIMIT 1 "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if ($place = $GLOBALS['APIDB']->fetchArray($result)) - return array('latitude'=>$place['Latitude_Float'], 'longitude' => $place['Longitude_Float']); - } - return array('latitude'=> 0, 'longitude' => 0); - } - } -} - -if (!function_exists("findPlace")) { - - /* function findPlace() - * - * Function that finds a location(s) based in the information passed to the URL - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $country string Country Name, ISO2 or ISO3 or keyword 'Random' for a country to search - * @param $place string Name of place or component of name of places to search for or keyword 'Random' - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * @param $return integer Number of Result to Limit the selection and return of the API - * - * @return array - */ - function findPlace($country = '', $place = '', $format = 'json', $radius = 1) - { - if (empty($radius) || $radius < 1) - $radius = API_RADIUS_DEFAULT; - - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - $numberof = 0; - $sql = ''; - $ret = array(); - if (strlen($country)>3&&strtolower($country)!='list'&&strtolower($country)!='random') { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`Country`) LIKE '".strtolower($country)."' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1"; - - } elseif (strlen($country)>3&&strtolower($country)=='random') { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() LIMIT 1"; - - } elseif (strlen($country)>3&&strtolower($country)=='list') { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY `Country` ASC "; - - } elseif (strlen($country)==3) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`ISO3`) LIKE '".strtolower($country)."' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1 "; - } elseif (strlen($country)==2) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`ISO2`) LIKE '".strtolower($country)."' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1 "; - } elseif (strlen($country)!=2 && strlen($country)!=3) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE lower(`Country`) LIKE '%".strtolower($country)."%' GROUP BY `CountryID` ORDER BY RAND() LIMIT 1 "; - } - $numberof=$seconds=$start=$end=0; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $sql = "SELECT count(*) as records FROM `" . $country['Table'] . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - $table = $country['Table']; - if ($format!='xml') - $ret['countries'][$table] = strippedArray($country, explode('|', API_COUNTRY_FIELDS)); - else - $ret['countries'][$table] = strippedArray($country, explode('|', API_COUNTRY_FIELDS)); - - if (strtolower($place)!='random') { - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` WHERE LOWER(`RegionName`) LIKE '" . strtolower($place) . "%' ORDER BY RAND()"; - } elseif (strtolower($place) == 'random' && strtolower($country) == 'random') - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` ORDER BY RAND()"; - elseif (strtolower($place) == 'random' && strtolower($country) != 'random') { - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` ORDER BY RAND()"; - } else { - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` WHERE LOWER(`RegionName`) LIKE '%" . strtolower($place) . "%' ORDER BY RAND()"; - } - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - while ($region = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($seconds==0) - $seconds = 120; - elseif ($end!=0&&$start!=0) - $seconds = $seconds + ($end - $start * 3); - $start = microtime(true); - set_time_limit($seconds); - if (strpos($region['RegionName'], ',')) { - $parts = explode(',',$region['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $region['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($region['RegionName'])); - if ($format!='xml') - $ret['places'][$table][$region['key']] = strippedArray($region, explode('|', API_PLACES_FIELDS)); - else - $ret['places'][$table][$key] = strippedArray($region, explode('|', API_PLACES_FIELDS)); - $numberof++; - - if ($radius != API_RADIUS_DEFAULT) - { - $latitude = $region['Latitude_Float']; - $longitude = $region['Longitude_Float']; - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($latitude) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($latitude) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $longitude . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` HAVING `Distance` <= ".$radius. " ORDER BY `Distance`"; - $ret['search']['countries']++; - unset($resultb); - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) { - while ($nearby = $GLOBALS['APIDB']->fetchArray($resultc)) { - if (strpos($nearby['RegionName'], ',')) { - $parts = explode(',',$nearby['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $nearby['RegionName'] = implode(' ', $parts); - } - $keyb = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($nearby['RegionName'])); - if ($format!='xml') - $ret['places'][$table][$region['key']]['nearby'][$keyb] = strippedArray($nearby, explode('|',API_PLACES_FIELDS)); - else - $ret['places'][$table][$key]['nearby'][$keyb] = strippedArray($nearby, explode('|',API_PLACES_FIELDS)); - } - } - } - $end = microtime(true); - } - } - } - } - return $ret; - } -} - - - -if (!function_exists("findNearby")) { - - /* function findNearby() - * - * Function that finds a location(s) near a latitude & longitude - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $latitude float Latitude to search for places near by - * @param $longitude float Longitude to search for places near by - * @param $radius integer Radius that the search bounded by in kilometers (integer only) - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * - * @return array - */ - function findNearby($latitude = 0, $longitude = 0, $radius = 0, $format = 'json') - { - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - $ret = array(); - $ret['search']['places'] = $ret['search']['countries'] = 0; - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($latitude) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($latitude) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $longitude . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` HAVING `Distance` <= ".$radius. " ORDER BY `Distance`"; - $ret['search']['countries']++; - unset($resultb); - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - while ($place = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['search']['places']++; - } - } - } - } - $ret['search']['type'] = 'nearby'; - return $ret; - } -} - - - - -if (!function_exists("findExactly")) { - - /* function findNearby() - * - * Function that finds a location(s) near a latitude & longitude - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $latitude float Latitude to search for places near by - * @param $longitude float Longitude to search for places near by - * @param $radius integer Radius that the search bounded by in kilometers (integer only) - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * - * @return array - */ - function findExactly($latitude = 0, $longitude = 0, $radius = 0, $format = 'json') - { - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - $ret = array(); - $places = $ret['search']['countries'] = $ret['search']['places'] = 0; - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - $ret['search']['countries']++; - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($latitude) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($latitude) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $longitude . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` WHERE `Latitude_Float` >= ".($latitude - (111.32 * ($radius / 1000)))." AND `Longitude_Float` >= ".($longitude - (111.32 * ($radius / 1000)))." AND `Latitude_Float` <= ".($latitude + (111.32 * ($radius / 1000)))." AND `Longitude_Float` <= ".($longitude + (111.32 * ($radius / 1000))). " ORDER BY `Distance`"; - unset($resultb); - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - while ($place = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['search']['places']++; - } - } - } - } - $ret['search']['type'] = 'exactly'; - return $ret; - } -} - -if (!function_exists("findKey")) { - - /* function findKey() - * - * Function that reverse lookups a forensic identifier MD6 of country or region and return one or more locations - * @author Simon Roberts (Chronolabs) simon@snails.email - * - * @param $key string the MD5 32 Character Checksum for the place or country to lookup - * @param $radius integer Radius that the search bounded by in kilometers (integer only) - * @param $format string API Output mode (JSON, XML, SERIAL, HTML, RAW) - * - * @return array - */ - function findKey($key = '', $radius = 0, $format = 'json') - { - - session_start(); - if (!in_array(whitelistGetIP(true), whitelistGetIPAddy())) { - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - } - - error_reporting(E_ERROR); - session_start(); - if (isset($_SESSION['places']['queries']['time'])) { - if ($_SESSION['places']['queries']['time']>time()) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - } elseif (!isset($_SESSION['places']['queries']['time'])) { - $_SESSION['places']['queries']['number'] = 0; - $_SESSION['places']['queries']['time'] = time()+3600; - } - if ($_SESSION['places']['queries']['number']>MAXIMUM_QUERIES) { - header("HTTP/1.0 404 Not Found"); - exit; - } - $_SESSION['places']['queries']['number']++; - - $sql = ''; - $ret = array(); - $found = false; - $ret['results']['count'] = 0; - - if ( strpos($key, ":") > 0 ) - { - $countryid = substr($key, 0, strpos($key, ":") ); - $key = substr($key, strpos($key, ":") + 1); - } else - $countryid = false; - - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE '" . places_oldhash($key, 'countries') . "' LIKE concat('%', md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)), '%') GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - } - } - if (!isset($table) && !empty($countryid) && $countryid != false) - { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '".$countryid."' GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - if($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - } - } - } - - if (empty($countryid) && $countryid == false && $found==false) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $cntry['Country'] . "'))) as `key`, concat(`RegionName`, '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE '" . places_oldhash($key, $cntry['Table']) . "' LIKE concat('%',md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "')),'%') ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $place = $GLOBALS['APIDB']->fetchArray($resultb); - $table = $cntry['Table']; - $found = true; - if (!isset($country)) - $country = $cntry; - } - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $place['Longitude_Float']; - $ret['latitude'] = $place['Latitude_Float']; - $ret['address'] = $places['Address']; - } - } - } elseif ($found==false && !empty($countryid)) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '$countryid' ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat(`RegionName`, '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $cntry['Country'] . "'))) as `key`, concat(`RegionName`, '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE '" . places_oldhash($key, $cntry['Table']) . "' LIKE concat('%',md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "')),'%') ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $place = $GLOBALS['APIDB']->fetchArray($resultb); - $table = $cntry['Table']; - $found=true; - if (!isset($country)) - $country = $cntry; - } - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $place['Longitude_Float']; - $ret['latitude'] = $place['Latitude_Float']; - $ret['address'] = $places['Address']; - } - } - } - - if (empty($countryid) && $countryid == false && $found==false) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat('" . !empty($country['CountryID'])?$country['CountryID'].":":"" . "', md5(concat(`Name`, `Vicinity`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE '" . places_oldhash($key, $cntry['Table']) . "' LIKE concat('%', md5(concat(`Name`, `Vicinity`)), '%') ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $venue = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $cntry['Country'] . "'))) as `key`, concat(`RegionName`, '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $venue['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $ctry['Table']; - $found = true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $venue['Longitude']; - $ret['latitude'] = $venue['Latitude']; - $ret['address'] = $venue['Vicinity']; - } - } - } - } elseif ($found==false && !empty($countryid)) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '$countryid' ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat('" . !empty($cntry['CountryID'])?$cntry['CountryID'].":":"" . "', md5(concat(`Name`, `Vicinity`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE '" . places_oldhash($key, $cntry['Table']) . "' LIKE concat('%', md5(concat(`Name`, `Vicinity`)), '%') ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $venue = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $cntry['Country'] . "'))) as `key`, concat(`RegionName`, '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $venue['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $cntry['Table']; - $found=true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $venue['Longitude']; - $ret['latitude'] = $venue['Latitude']; - $ret['address'] = $venue['Vicinity']; - } - } - } - } - - if (empty($countryid) && $countryid == false && $found==false) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` GROUP BY `CountryID` ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat('" . !empty($cntry['CountryID'])?$cntry['CountryID'].":":"" . "', md5(concat(`Name`, `Vicinity`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE '" . places_oldhash($key, $cntry['Table']) . "' LIKE concat('%', md5(concat(`Name`, `Vicinity`)), '%') ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $address = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, '" . $cntry['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $cntry['Country'] . "'))) as `key`, concat(`RegionName`, '".$cntry['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $address['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $cntry['Table']; - $found = true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $address['Longitude']; - $ret['latitude'] = $address['Latitude']; - $ret['address'] = $address['Formatted']; - } - } - } - } elseif ($found==false && !empty($countryid)) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `CountryID` = '$countryid' ORDER BY RAND() "; - if ($result = $GLOBALS['APIDB']->queryF($sql)) { - while(($cntry = $GLOBALS['APIDB']->fetchArray($result)) && $found == false) { - $sql = "SELECT *, concat('" . !empty($cntry['CountryID'])?$cntry['CountryID'].":":"" . "', md5(concat(`Name`, `Vicinity`))) as `key` FROM `" . $cntry['Table'] . "_venues` WHERE '" . places_oldhash($key, $cntry['Table']) . "' LIKE concat('%', md5(concat(`Name`, `Vicinity`)), '%') ORDER BY RAND() LIMIT 1"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $address = $GLOBALS['APIDB']->fetchArray($resultb); - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $cntry['Country'] . "'))) as `key`, concat(`RegionName`, '".$country['Country']."') as `Address` FROM `" . $cntry['Table'] . "` WHERE `CordID` = '" . $address['CordID']. "'"; - if ($resultc = $GLOBALS['APIDB']->queryF($sql)) - $place = $GLOBALS['APIDB']->fetchArray($resultc); - $table = $cntry['Table']; - $found=true; - if (!isset($country)) - $country = $cntry; - $sql = "SELECT count(*) as records FROM `" . $GLOBALS['APIDB']->prefix($table) . "`"; - if ($resultb = $GLOBALS['APIDB']->queryF($sql)) { - $records = $GLOBALS['APIDB']->fetchArray($resultb); - $country['records'] = $records['records']; - } else - $country['records'] = 0 ; - if ($format!='xml') - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby'] = array(); - $ret['results']['type'] = 'place'; - $ret['results']['count'] = 1; - $ret['results']['nearby'] = 0; - $ret['longitude'] = $address['Longitude']; - $ret['latitude'] = $address['Latitude']; - $ret['address'] = $address['Formatted']; - } - } - } - } - - if ($radius <= 0 || $radius == API_RADIUS_DEFAULT) - return $ret; - - if ($found == true && $radius > 0) { - if (isset($ret['results']['places'])) - $places = $ret['results']['places']; - elseif (isset($ret['results']['place'])) - $places = $ret['results']['place']; - foreach($places as $table => $values) { - foreach($values as $key => $place) { - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `Table` LIKE '$table' GROUP BY `CountryID` ORDER BY RAND() "; - $result = $GLOBALS['APIDB']->queryF($sql); - while($country = $GLOBALS['APIDB']->fetchArray($result)) { - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($place['Latitude_Float']) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($place['Latitude_Float']) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $place['Longitude_Float'] . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance`, concat(`RegionName`, '".$country['Country']."') as `Address` FROM `" . $GLOBALS['APIDB']->prefix($table) . "` HAVING `Distance` <= ".$radius. " ORDER BY `Distance`"; - $resultb = $GLOBALS['APIDB']->queryF($sql); - while ($place = $GLOBALS['APIDB']->fetchArray($resultb)) { - if ($format!='xml') - $ret['results']['nearby']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - else - $ret['results']['nearby']['countries'][$table] = strippedArray($country, explode('|',API_COUNTRY_FIELDS)); - if (strpos($place['RegionName'], ',')) { - $parts = explode(',',$place['RegionName']); - array_reverse($parts); - foreach($parts as $key => $value) - $parts[$key] = trim($value); - $place['RegionName'] = implode(' ', $parts); - } - $key = str_replace(array(" ", "'", "-", "_", "\"", "`" , ",", "(", ")"), "", strtolower($place['RegionName'])); - if ($format!='xml') - $ret['results']['nearby']['places'][$table][$place['key']] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - else - $ret['results']['nearby']['places'][$table][$key] = strippedArray($place, explode('|',API_PLACES_FIELDS)); - $ret['results']['nearby']++; - } - } - } - } - if ($ret['results']['nearby']>0) - $ret['results']['type'] = 'keyed'; - } - return $ret; - } -} - -if (!function_exists("getAddressGeoMapping")) -{ - /** - * gets Geo Longitude + Latitude for an known address - * - * @param string $address - * @return number[]|unknown[]|mixed[] - */ - function getAddressGeoMapping($address = '') - { - $geo = json_decode(getURIData('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false'), true); - $latitude = $longitude = 0.0001; - if ($geo['status'] == 'OK') { - $address = array(); - foreach($geo['results'][0]['address_components'] as $values) - { - if (in_array('administrative_area_level_1', $values['types']) && in_array('political', $values['types'])) - $address['State'] = $values['long_name']; - elseif (in_array('administrative_area_level_2', $values['types']) && in_array('political', $values['types'])) - $address['Council'] = $values['short_name']; - elseif (in_array('postal_code', $values['types'])) - $address['Postcode'] = $values['long_name']; - elseif (in_array('subpremise', $values['types'])) - $address['Unit'] = $values['long_name']; - elseif (in_array('street_number', $values['types'])) - $address['Building'] = $values['long_name']; - elseif (in_array('route', $values['types'])) - $address['Street'] = $values['long_name']; - elseif (in_array('locality', $values['types'])) - $address['Suburb'] = $values['long_name']; - elseif (in_array('country', $values['types'])) { - $address['Country'] = $values['long_name']; - $address['Country_ISO2'] = $values['short_name']; - } - } - if (!isset($address['State']) && isset($address['Council'])) - { - $address['State'] = $address['Council']; - unset($address['Council']); - } - $address['Formatted'] = $geo['results'][0]['formatted_address']; - $address['GoogleID'] = $geo['results'][0]['place_id']; - $address['Longitude'] = $geo['results'][0]['geometry']['location']['lng']; - $address['Latitude'] = $geo['results'][0]['geometry']['location']['lat']; - $address['View_NE_Longitude'] = $geo['results'][0]['geometry']['viewport']['northeast']['lng']; - $address['View_NE_Latitude'] = $geo['results'][0]['geometry']['viewport']['northeast']['lat']; - $address['View_SW_Longitude'] = $geo['results'][0]['geometry']['viewport']['southwest']['lng']; - $address['View_SW_Latitude'] = $geo['results'][0]['geometry']['viewport']['southwest']['lat']; - - $sql = "SELECT *, md5(concat(`Country`, `Capital`, `Continent`, `CurrencyCode`)) as `key` FROM `" . $GLOBALS['APIDB']->prefix('countries') . "` WHERE `Country` LIKE '%".$address['Country']."%' GROUP BY `CountryID` ORDER BY RAND() "; - $result = $GLOBALS['APIDB']->queryF($sql); - if ($country = $GLOBALS['APIDB']->fetchArray($result)) { - $table = $country['Table']; - $sql = "SELECT *, concat(`RegionName`, '" . $country['Country'] . "') as `Address`, concat(`CountryID`, ':', md5(concat(`Longitude_Float`, `Latitude_Float`, `RegionName`, '" . $country['Country'] . "'))) as `key`, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . abs($geo['results'][0]['geometry']['location']['lat']) . " - abs(`Latitude_Float`)) * pi() / 180 / 2), 2) + COS(" . abs($geo['results'][0]['geometry']['location']['lat']) . " * pi() / 180 ) * COS(abs(`Latitude_Float`) * pi() / 180) * POWER(SIN((" . $geo['results'][0]['geometry']['location']['lng'] . " - `Longitude_Float`) * pi() / 180 / 2), 2) )) as `Distance`, concat(`RegionName`, '".$country['Country']."') as `Address` FROM `" . $country['Table'] . "` WHERE `RegionName` LIKE '%$suburb%' ORDER BY `Distance`"; - $resultb = $GLOBALS['APIDB']->queryF($sql); - $place = $GLOBALS['APIDB']->fetchArray($resultb); - $address['CordID'] = $place['CordID']; - $address['CountryID'] = $country['CountryID']; - - $types = array(); - foreach($geo['results'][0]['types'] as $tno => $type) - { - $sql = "SELECT count(*) as `count` from `" . $GLOBALS['APIDB']->prefix($table . "_address_types") . "` WHERE `Type` LIKE '$type'"; - list($count) = $GLOBALS['APIDB']->fetchRow( $GLOBALS['APIDB']->queryF($sql)); - $sql = "SELECT * from `" . $GLOBALS['APIDB']->prefix($table . "_address_types") ."` WHERE `Type`... [truncated message content] |