diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-09-04 14:56:06 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-09-04 14:56:06 +0200 |
commit | 54d5d869ad2c525dd276f28a8409658a106d9e3f (patch) | |
tree | de619bb4824b61d41b0452a94fc850cc28b27e35 | |
parent | 720808fc3884a415dc483b50796697a095d1b5b8 (diff) |
Generalize request_type() to static_storage()
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/file.php | 6 | ||||
-rw-r--r-- | application/controllers/user.php | 2 | ||||
-rw-r--r-- | application/core/MY_Controller.php | 6 | ||||
-rwxr-xr-x | application/errors/error_general.php | 2 | ||||
-rw-r--r-- | application/helpers/filebin_helper.php | 14 |
5 files changed, 17 insertions, 13 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php index 6e660b306..6a97c645f 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -286,7 +286,7 @@ class File extends MY_Controller { } } - if (request_type() == "json") { + if (static_storage("response_type") == "json") { return send_json_reply($this->data["urls"]); } @@ -466,7 +466,7 @@ class File extends MY_Controller { ORDER BY date $order ", array($user))->result_array(); - if (request_type() == "json") { + if (static_storage("response_type") == "json") { return send_json_reply($query); } @@ -539,7 +539,7 @@ class File extends MY_Controller { } } - if (request_type() == "json") { + if (static_storage("response_type") == "json") { return send_json_reply(array( "errors" => $errors, "deleted" => $deleted, diff --git a/application/controllers/user.php b/application/controllers/user.php index 56f571d6a..34d6c492d 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -131,7 +131,7 @@ class User extends MY_Controller { WHERE `user` = ? order by created desc ", array($userid))->result_array(); - if (request_type() == "json") { + if (static_storage("response_type") == "json") { return send_json_reply($query); } diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 312b0f763..e1c6cc96e 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -35,16 +35,16 @@ class MY_Controller extends CI_Controller { // TODO: proper accept header handling or is this enough? if (isset($_SERVER["HTTP_ACCEPT"])) { if ($_SERVER["HTTP_ACCEPT"] == "application/json") { - request_type("json"); + static_storage("response_type", "json"); } } // Allow for easier testing in browser if ($this->input->get("json") !== false) { - request_type("json"); + static_storage("response_type", "json"); } - if (request_type() == "json" && ! in_array($this->uri->rsegment(2), $this->json_enabled_functions)) { + if (static_storage("response_type") == "json" && ! in_array($this->uri->rsegment(2), $this->json_enabled_functions)) { show_error("Function not JSON enabled"); } diff --git a/application/errors/error_general.php b/application/errors/error_general.php index fc3d3f607..6c67fa33f 100755 --- a/application/errors/error_general.php +++ b/application/errors/error_general.php @@ -9,7 +9,7 @@ if (class_exists("CI_Controller") && !isset($GLOBALS["is_error_page"])) { $CI->load->helper("filebin"); $CI->load->helper("url"); - if (request_type() == "json") { + if (static_storage("response_type") == "json") { $array = array( "status" => "error", "message" => strip_tags($message), diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 9b124506f..7ba68b839 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -341,15 +341,19 @@ function send_json_reply($array, $status = "success") $CI->output->set_output(json_encode($reply)); } -function request_type($set_type = null) +function static_storage($key, $value = null) { - static $type = null; + static $storage = array(); - if ($set_type !== null) { - $type = $set_type; + if ($value !== null) { + $storage[$key] = $value; } - return $type; + if (!isset($storage[$key])) { + $storage[$key] = null; + } + + return $storage[$key]; } # vim: set noet: |