Skip to content

Commit

Permalink
Fixed pretty_print bug that was disabling users from turning pretty p…
Browse files Browse the repository at this point in the history
…rint off if the api.php page used API::set_pretty_print(true) and changed headers from outputting text/javascript to application/json
  • Loading branch information
brannondorsey committed Sep 18, 2013
1 parent e3b0500 commit 867cdc3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This example table, named `users`, holds information about imaginary users that
require_once("api_builder_includes/class.API.inc.php");

//set page to output JSON
header("Content-Type: text/javascript; charset=utf-8");
header("Content-Type: application/json; charset=utf-8");

//If API parameters were included in the http request via $_GET...
if(isset($_GET) && !empty($_GET)){
Expand Down
11 changes: 5 additions & 6 deletions api_builder_includes/class.API.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ public function set_no_results_message($message){
public function get_json_from_assoc(&$get_array){

$json_obj = new StdClass();
$pretty_print = false;
$pretty_print = $this->pretty_print;

if(!$this->find_config_errors()){

if(isset($get_array['pretty_print']) &&
strtolower($get_array['pretty_print']) == "true"){
$pretty_print = true;
if(isset($get_array['pretty_print'])){
if(strtolower($get_array['pretty_print']) == "true") $pretty_print = true;
if(strtolower($get_array['pretty_print']) == "false") $pretty_print = false;
}

//if API is public or if API is private and a correct private key was provided
Expand Down Expand Up @@ -337,8 +337,7 @@ public function get_json_from_assoc(&$get_array){
$pretty_print = true; //always output errors in pretty print for readability
$json_obj->config_error = $this->config_errors;
}
return ($pretty_print || $this->pretty_print &&
version_compare(PHP_VERSION, '5.4.0') >= 0) ? json_encode($json_obj, JSON_PRETTY_PRINT) : json_encode($json_obj);
return ($pretty_print && version_compare(PHP_VERSION, '5.4.0') >= 0) ? json_encode($json_obj, JSON_PRETTY_PRINT) : json_encode($json_obj);
}

//need to put call_limit_reached inside of update_API_hits or something.
Expand Down
2 changes: 1 addition & 1 deletion api_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require_once("api_builder_includes/class.API.inc.php");

//set page to output JSON
header("Content-Type: text/javascript; charset=utf-8");
header("Content-Type: application/json; charset=utf-8");

//If API parameters were included in the http request via $_GET...
if(isset($_GET) && !empty($_GET)){
Expand Down

0 comments on commit 867cdc3

Please sign in to comment.