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 ++++++++++++++++++ user_guide_src/source/libraries/output.rst | 7 +++++++ 2 files changed, 25 insertions(+) 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'; + } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index 2cf7c0854..8cd5ff895 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -49,6 +49,13 @@ data, JPEG's, XML, etc easily. .. important:: Make sure any non-mime string you pass to this method exists in config/mimes.php or it will have no effect. +$this->output->get_current_content_type(); +==================================== + +Get the current mime-type of your page and return 'text/html' by default. + + $this->output->get_current_content_type(); + $this->output->get_output(); ============================= -- 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 ++++++----- user_guide_src/source/libraries/output.rst | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) 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'; } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index 8cd5ff895..ba1ef19e6 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -50,7 +50,7 @@ data, JPEG's, XML, etc easily. exists in config/mimes.php or it will have no effect. $this->output->get_current_content_type(); -==================================== +========================================== Get the current mime-type of your page and return 'text/html' by default. -- 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(-) 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 +- user_guide_src/source/libraries/output.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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) { diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index ba1ef19e6..7fd2a1c72 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -49,12 +49,12 @@ data, JPEG's, XML, etc easily. .. important:: Make sure any non-mime string you pass to this method exists in config/mimes.php or it will have no effect. -$this->output->get_current_content_type(); +$this->output->get_content_type(); ========================================== Get the current mime-type of your page and return 'text/html' by default. - $this->output->get_current_content_type(); + $this->output->get_content_type(); $this->output->get_output(); ============================= -- cgit v1.2.3-24-g4f1b From 937f104c39353ecc513863545b47769143c1c9a1 Mon Sep 17 00:00:00 2001 From: Songpol Sripao-eiam Date: Tue, 3 Apr 2012 11:04:33 +0700 Subject: Update changelog --- user_guide_src/source/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 4fdbda054..272ca348c 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -190,6 +190,9 @@ Release Date: Not Released - Libraries - Further improved MIME type detection in the :doc:`File Uploading Library `. +- Core + - Added get_content_type for get current mime-types :doc:`Core Output Library `. + - Helpers - url_title() performance and output improved. You can now use any string as the word delimiter, but 'dash' and 'underscore' are still supported. -- cgit v1.2.3-24-g4f1b From cc0e4152502c368c0f4aa9be0af6b921ef106b81 Mon Sep 17 00:00:00 2001 From: Songpol Sripao-eiam Date: Tue, 3 Apr 2012 15:37:02 +0700 Subject: Move changelog line from verion 2.1.1 to version 3.0 --- user_guide_src/source/changelog.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 272ca348c..491f93782 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -124,6 +124,7 @@ Release Date: Not Released - Modified valid_ip() to use PHP's filter_var() in the :doc:`Input Library `. - Added support for HTTP-Only cookies with new config option ``cookie_httponly`` (default FALSE). - Renamed method _call_hook() to call_hook() in the :doc:`Hooks Library `. + - Added get_content_type for get current mime-types :doc:`Core Output Library `. Bug fixes for 3.0 ------------------ @@ -190,9 +191,6 @@ Release Date: Not Released - Libraries - Further improved MIME type detection in the :doc:`File Uploading Library `. -- Core - - Added get_content_type for get current mime-types :doc:`Core Output Library `. - - Helpers - url_title() performance and output improved. You can now use any string as the word delimiter, but 'dash' and 'underscore' are still supported. -- cgit v1.2.3-24-g4f1b