Skip to content

Commit

Permalink
Merge branch 'hotfix-jsonp_sref'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Sep 21, 2023
2 parents cdd128b + 374aa68 commit 369ada1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 52 deletions.
4 changes: 2 additions & 2 deletions application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
*
* @var string
*/
$config['version'] = '8.23.0';
$config['version'] = '8.23.1';

/**
* Version release date.
*
* @var string
*/
$config['release_date'] = '2023-09-20';
$config['release_date'] = '2023-09-21';

/**
* Link to the code repository downloads page.
Expand Down
108 changes: 58 additions & 50 deletions modules/indicia_svc_spatial/controllers/services/spatial.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

class Spatial_Controller extends Service_Base_Controller {

/**
* Convert a spatial reference to WKT format.
*
* Handle a service request to convert a spatial reference into WKT
* representing the reference using the internal SRID (normally spherical
* mercator since it is compatible with Google Maps). Optionally returns an
Expand All @@ -13,33 +16,33 @@ class Spatial_Controller extends Service_Base_Controller {
* mapsystem: (optional) Sref system code for additional WKT in response.
* callback: For returning JSONP.
*/
public function sref_to_wkt()
{
try
{
public function sref_to_wkt() {
try {
// Test/escape parameters that are passed in to queries to prevent
// SQL injection.
// sref is not passed to query
// system is validated in sref_to_internal_wkt()
// mapsystem is validated in internal_wkt_to_wkt()
$r = array('wkt'=>spatial_ref::sref_to_internal_wkt($_GET['sref'], $_GET['system']));
if (array_key_exists('mapsystem', $_GET)){
$r = ['wkt' => spatial_ref::sref_to_internal_wkt($_GET['sref'], $_GET['system'])];
if (array_key_exists('mapsystem', $_GET)) {
$r['mapwkt'] = spatial_ref::internal_wkt_to_wkt($r['wkt'], $_GET['mapsystem']);
}
$r = json_encode($r);
// enable a JSONP request
if (array_key_exists('callback', $_GET)){
$r = $_GET['callback']."(".$r.")";
// Enable a JSONP request.
if (array_key_exists('callback', $_GET)) {
$r = "$_GET[callback]($r)";
header('Content-Type: application/javascript; charset=utf-8');
}
echo $r;
}
catch (Exception $e)
{
catch (Exception $e) {
$this->handle_error($e);
}
}

/**
* Convert WKT format text to a spatial reference notation.
*
* Handle a service request to convert a WKT representing the reference
* using the internal SRID (normally spherical mercator since it is compatible with Google Maps)
* into a spatial reference, though this can optionally be overriden by providing a wktsystem.
Expand All @@ -59,22 +62,26 @@ public function sref_to_wkt()
* degrees and minutes, or decimal degrees (default).
* callback: For returning JSONP.
*/
public function wkt_to_sref()
{
try
{
if (array_key_exists('precision',$_GET))
public function wkt_to_sref() {
try {
if (array_key_exists('precision', $_GET)) {
$precision = $_GET['precision'];
else
$precision = null;
if (array_key_exists('metresAccuracy',$_GET))
}
else {
$precision = NULL;
}
if (array_key_exists('metresAccuracy', $_GET)) {
$metresAccuracy = $_GET['metresAccuracy'];
else
$metresAccuracy = null;
if (array_key_exists('output',$_GET))
}
else {
$metresAccuracy = NULL;
}
if (array_key_exists('output', $_GET)) {
$output = $_GET['output'];
else
$output = null;
}
else {
$output = NULL;
}

// Test/escape parameters that are passed in to queries to prevent
// SQL injection.
Expand All @@ -97,22 +104,22 @@ public function wkt_to_sref()
$sref = spatial_ref::internal_wkt_to_sref($wkt, $_GET['system'], $precision, $output, $metresAccuracy);
// Note we also need to return the wkt of the actual sref, which may be a square now.
$wkt = spatial_ref::sref_to_internal_wkt($sref, $_GET['system']);
$r = array('sref' => $sref,'wkt' => $wkt);
$r = ['sref' => $sref,'wkt' => $wkt];

if (array_key_exists('mapsystem', $_GET)){
if (array_key_exists('mapsystem', $_GET)) {
// Optionally output WKT of sref in mapsystem as well.
$r['mapwkt'] = spatial_ref::internal_wkt_to_wkt($r['wkt'], $_GET['mapsystem']);
}

$r = json_encode($r);
// enable a JSONP request
if (array_key_exists('callback', $_GET)){
$r = $_GET['callback']."(".$r.")";
// Enable a JSONP request.
if (array_key_exists('callback', $_GET)) {
$r = "$_GET[callback]($r)";
header('Content-Type: application/javascript; charset=utf-8');
}
echo $r;
}
catch (Exception $e)
{
catch (Exception $e) {
$this->handle_error($e);
}
}
Expand All @@ -128,29 +135,30 @@ public function wkt_to_sref()
* expected to be accurate by. E.g.may be set according to the current zoom
* scale of the map. Provided as an alternative to precision.
*/
public function convert_sref()
{
try
{
public function convert_sref() {
try {
// Test/escape parameters that are passed in to queries to prevent
// SQL injection.
// from_sref is not passed to query
// from_system is validated in sref_to_internal_wkt()
// to_systen us validated in internal_wkt_to_sref()
// precision and metresAccuracy are not used in queries.
$wkt = spatial_ref::sref_to_internal_wkt($_GET['from_sref'], $_GET['from_system']);
if (array_key_exists('precision',$_GET))
if (array_key_exists('precision', $_GET)) {
$precision = $_GET['precision'];
else
$precision = null;
if (array_key_exists('metresAccuracy',$_GET))
}
else {
$precision = NULL;
}
if (array_key_exists('metresAccuracy', $_GET)) {
$metresAccuracy = $_GET['metresAccuracy'];
else
$metresAccuracy = null;
echo spatial_ref::internal_wkt_to_sref($wkt, $_GET['to_system'], $precision, null, $metresAccuracy);
}
else {
$metresAccuracy = NULL;
}
echo spatial_ref::internal_wkt_to_sref($wkt, $_GET['to_system'], $precision, NULL, $metresAccuracy);
}
catch (Exception $e)
{
catch (Exception $e) {
$this->handle_error($e);
}
}
Expand Down Expand Up @@ -183,7 +191,7 @@ public function buffer() {
$r = $params['wkt'];
}
else {
$db = new Database;
$db = new Database();
// Test/escape parameters that are passed in to queries to prevent
// SQL injection.
$wkt = pg_escape_literal($db->getLink(), $params['wkt']);
Expand Down Expand Up @@ -224,11 +232,11 @@ public function buffer() {
} else {
$r = 'No wkt or buffer to process';
}
if (array_key_exists('callback', $_REQUEST))
{
$json=json_encode(array('response'=>$r));
$r = $_REQUEST['callback']."(".$json.")";
$this->content_type = 'Content-Type: application/javascript';
// Enable a JSONP request.
if (array_key_exists('callback', $_REQUEST)) {
$json = json_encode(['response' => $r]);
$r = "$_REQUEST[callback]($json)";
header('Content-Type: application/javascript; charset=utf-8');
}
echo $r;
}
Expand Down

0 comments on commit 369ada1

Please sign in to comment.