From 05ae6f99e63641b6d4ecf5e1c30cee0ea41fc1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Sat, 17 Sep 2011 13:02:59 +0000 Subject: [PATCH] Add support for JSONP at country API endpoint git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2906 44740490-163a-0410-bde0-09ae8108e29a --- modules/discojuice/www/country.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/discojuice/www/country.php b/modules/discojuice/www/country.php index 1e09dc61a..0aac0046a 100644 --- a/modules/discojuice/www/country.php +++ b/modules/discojuice/www/country.php @@ -1,6 +1,5 @@ <?php -header('Content-type: application/json; utf-8'); try { @@ -29,8 +28,16 @@ try { $result['geo'] = array('lat' => (float) $matches[1], 'lon' => (float)$matches[2]); } - echo json_encode($result); exit; - throw new Exception('Could not lookup, invalid format: ' . $region); + + + if(preg_match('/^[0-9A-Za-z_\-]+$/', $_REQUEST['callback'], $matches)) { + header('Content-type: application/javascript; utf-8'); + echo $_REQUEST['callback'] . '(' . json_encode($result) . ');'; + } else { + header('Content-type: application/json; utf-8'); + echo json_encode($result); + } + } catch(Exception $e) { -- GitLab