From 16516db98bbeaf670972b44a3e39b6852ff83cdf Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sun, 21 Aug 2016 20:42:34 -0600 Subject: [PATCH] JSON UTF crap --- database.mwb | Bin 11777 -> 11776 bytes places.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/database.mwb b/database.mwb index 8cbd6afd1d8eb1ad04c8e1841ba0222eea7592a0..c794fbe41e9ec819b9e1b18420b817c36fe88335 100644 GIT binary patch delta 323 zcmV-J0lfZ!T!37VGYKOS2ubP-1&ze9Jklh8{Qo1Q{;XK#q~v~VA;mgD_K{-ztQq1` zwk&XNzH1yu)1{tk-knF0ca%P`quE7aAy3?n^2aIzapy2~0z70MbBF1_+o;$VyjHOH zZ)C`BS(@e^_0`^OvpjXSH zDpqYpRaB&^8qy6-&%Pl(t6s;9zx`2HvrR-UWBHG%>z0a5O;r@z=08Ff;+HfFo9642 zP^l-~OxNW0@u<5DVt4SM6K6SF2IdFIxj)Qhc;;2Iwfy4!VJeEj7DcfI8FZ~q^&93~_O2_q5+N$Lv) Vjl`2lEmHv-lbtOd0RfY|Ek$08pN#+j delta 324 zcmV-K0lWTyT!CDWGYOQg2T5A)mDt6xJklh8C&)Tdm7fi@oRr*;Eu>f{$UahxpEW~V z%9aJr&3BFCXu8yM&Aam`@{ZC6b~L*vEaZvXQT|wEAnqKdPJoBZW9~5hcN-P^g4YW6 z{*4UTElbnfqrTd^ZI-9bwp?miwq?zGV_EXrCR}D{B=OJ>KSgOeoq6i|%48a0Lp2S5 zMa8PEsEUeIRYSU=>Df2LXVvSN@wY$fYPN~UWi07v{8vNAs_-MJ~zq2ry`S+zM^s_U_ zuV=CbM1K=ZZerG?B+uL$lzOrC5nSUCLwCE5i;us2;I5aP{_Xz*vl}KP2MLs}2T5A) WmDt6TNG($V9Fv?a9svTAyDde%-l{eL diff --git a/places.php b/places.php index e7dc2c4..c0dd8b9 100644 --- a/places.php +++ b/places.php @@ -7,6 +7,8 @@ */ require 'required.php'; +//ini_set('memory_limit','32M'); + $placebase; try { $placebase = new medoo([ @@ -50,14 +52,16 @@ if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) { $userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']); $searchbounds = $userlocation->boundingCoordinates($radius, 'miles'); - +if ($VARS['debug']) { + echo "got to the place data query "; +} if (is_empty($VARS['names'])) { $places = $placebase->select('places', '*', ['AND' => [ 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(), 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()], - "LIMIT" => 100 + "LIMIT" => 200 ]); } else { $places = $placebase->select('places', '*', ['AND' => [ @@ -66,7 +70,7 @@ if (is_empty($VARS['names'])) { 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(), 'name[!]' => ''], - "LIMIT" => 100 + "LIMIT" => 200 ]); } @@ -78,6 +82,9 @@ header('Content-Type: application/json'); $geo['name'] = "Places"; $geo['type'] = 'FeatureCollection'; $geo['features'] = []; +if ($VARS['debug']) { + echo "got to the game data loop "; +} foreach ($places as $place) { if (!$database->has('locations', ['osmid' => $place['osmid']])) { $database->insert('locations', ['osmid' => $place['osmid'], 'teamid' => 0]); @@ -107,4 +114,48 @@ foreach ($places as $place) { ] ); } -echo json_encode($geo); \ No newline at end of file +if ($VARS['debug']) { + echo "got all the way to the encode "; +} + +function utf8ize($d) { + if (is_array($d)) { + foreach ($d as $k => $v) { + $d[$k] = utf8ize($v); + } + } else if (is_object($d)) { + foreach ($d as $k => $v) { + $d->$k = utf8ize($v); + } + } else { + return utf8_encode($d); + } + return $d; +} + +echo json_encode(utf8ize($geo)); +if ($VARS['debug']) { + switch (json_last_error()) { + case JSON_ERROR_NONE: + echo ' - No errors'; + break; + case JSON_ERROR_DEPTH: + echo ' - Maximum stack depth exceeded'; + break; + case JSON_ERROR_STATE_MISMATCH: + echo ' - Underflow or the modes mismatch'; + break; + case JSON_ERROR_CTRL_CHAR: + echo ' - Unexpected control character found'; + break; + case JSON_ERROR_SYNTAX: + echo ' - Syntax error, malformed JSON'; + break; + case JSON_ERROR_UTF8: + echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; + break; + default: + echo ' - Unknown error'; + break; + } +} \ No newline at end of file