From 52fe7bb68f9961cdd765dd38e54779ae3b66e586 Mon Sep 17 00:00:00 2001 From: Songpol Sripaoeiam Date: Sun, 1 Apr 2012 11:43:20 +0700 Subject: add function get_current_content_type to output class and user manual library --- system/core/Output.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 9bf818e88..673ceb0ee 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -220,6 +220,24 @@ class CI_Output { $this->headers[] = array($header, TRUE); return $this; } + + // -------------------------------------------------------------------- + + /** + * Get Current Content Type Header + * Return text/html if Content-Type is not set + * + * @return string + */ + public function get_current_content_type() + { + foreach($this->headers as $header){ + if(preg_match('/^Content-Type/', $header[0])){ + return str_replace('Content-Type: ', '', $header[0]); + } + } + return 'text/html'; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b966701fad01c094199a89f7e4df72d981e5cf48 Mon Sep 17 00:00:00 2001 From: Songpol Sripaoeiam Date: Sun, 1 Apr 2012 17:13:44 +0700 Subject: bracket on a new line Also add space after foreach bracket on a new line... Also add a space after if Follow up from https://github.com/EllisLab/CodeIgniter/pull/1234/files#r630522 --- system/core/Output.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 673ceb0ee..c0de24bb9 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -231,12 +231,13 @@ class CI_Output { */ public function get_current_content_type() { - foreach($this->headers as $header){ - if(preg_match('/^Content-Type/', $header[0])){ - return str_replace('Content-Type: ', '', $header[0]); - } + foreach ($this->headers as $header){ + if (preg_match('/^Content-Type/', $header[0])) + { + return str_replace('Content-Type: ', '', $header[0]); } - return 'text/html'; + } + return 'text/html'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 38c0a72169ffbf002c7f3c7fd3b4fd41f0d75f09 Mon Sep 17 00:00:00 2001 From: Songpol Sripao-eiam Date: Sun, 1 Apr 2012 20:10:35 +0700 Subject: Fix style coding --- system/core/Output.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index c0de24bb9..ea39b0223 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -231,7 +231,8 @@ class CI_Output { */ public function get_current_content_type() { - foreach ($this->headers as $header){ + foreach ($this->headers as $header) + { if (preg_match('/^Content-Type/', $header[0])) { return str_replace('Content-Type: ', '', $header[0]); -- cgit v1.2.3-24-g4f1b From 614db07c77e341bfe4bf92d7576f01a6cabd43ff Mon Sep 17 00:00:00 2001 From: Songpol Sripaoeiam Date: Tue, 3 Apr 2012 01:29:28 +0700 Subject: The current name is too wide change to get_content_type()consistent with set_content_type() --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index ea39b0223..09d74f0c0 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -229,7 +229,7 @@ class CI_Output { * * @return string */ - public function get_current_content_type() + public function get_content_type() { foreach ($this->headers as $header) { -- cgit v1.2.3-24-g4f1b From 00adf1d480f94692a625ec2165e0fcc9171c6e2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 12:30:50 +0300 Subject: Some improvements to the additions from pull #1234 --- system/core/Output.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 09d74f0c0..01fd1d867 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -220,24 +220,24 @@ class CI_Output { $this->headers[] = array($header, TRUE); return $this; } - + // -------------------------------------------------------------------- - + /** * Get Current Content Type Header - * Return text/html if Content-Type is not set * - * @return string + * @return string 'text/html', if not already set */ public function get_content_type() { - foreach ($this->headers as $header) + for ($i = 0, $c = count($this->headers); $i < $c; $i++) { - if (preg_match('/^Content-Type/', $header[0])) + if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches)) { - return str_replace('Content-Type: ', '', $header[0]); + return $matches[1]; } } + return 'text/html'; } -- cgit v1.2.3-24-g4f1b