more generalized javascript_renderData

- handles json/jsonp transparently (avoiding code duplication in templates)
- use php's internal json_encode functions (with JSON_UNESCAPED_UNICODE
  for backward compatibility)
- be more liberal with what is allowed as a callback identifier
- return a 400 for illegal callbacks
- return application/javascript type when jsonp is requested

fixes #16, fixes #17
This commit is contained in:
Sarah Hoffmann
2012-07-01 13:19:59 +02:00
parent 8ff0aabaf3
commit 1cb55c6e31
5 changed files with 22 additions and 85 deletions

View File

@@ -1,7 +1,4 @@
<?php
header ("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Origin: *");
$aFilteredPlaces = array();
if (!sizeof($aPlace))
@@ -27,13 +24,5 @@
if ($bShowAddressDetails) $aFilteredPlaces['address'] = $aAddress;
}
if (isset($_GET['json_callback']) && preg_match('/^[-A-Za-z0-9:_.]+$/',$_GET['json_callback']))
{
echo $_GET['json_callback'].'('.javascript_renderData($aFilteredPlaces).')';
}
else
{
echo javascript_renderData($aFilteredPlaces);
}
javascript_renderData($aFilteredPlaces);