-
-
Save bnchdrff/1795328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// see http://drupal.org/node/606332 | |
$jsonp_prefix = $options['jsonp_prefix']; | |
if ($view->override_path) { | |
// We're inside a live preview where the JSON is pretty-printed. | |
$json = _views_json_encode_formatted($rows); | |
if ($jsonp_prefix) | |
$json = "\$_GET['$jsonp_prefix']($json)"; | |
print "<code>$json</code>"; | |
} else { | |
$json = json_encode($rows); | |
if ($jsonp_prefix && !preg_match('/\W/', $_GET[$jsonp_prefix])) { | |
$json = $_GET[$jsonp_prefix] ."($json)"; | |
} | |
if ($options['using_views_api_mode']) { | |
// We're in Views API mode. | |
print $json; | |
} else { | |
// We want to send the JSON as a server response so switch the content | |
// type and stop further processing of the page. | |
$content_type = ($options['content_type'] == 'default') ? 'application/json' : $options['content_type']; | |
// Drupal 7: change to | |
//drupal_add_http_header("Content-Type", "$content_type; charset=utf-8"); | |
drupal_set_header("Content-Type: $content_type; charset=utf-8"); | |
print $json; | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment