summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/core/Output.php74
-rw-r--r--system/database/DB_query_builder.php5
-rw-r--r--tests/codeigniter/core/Output_test.php37
-rw-r--r--tests/codeigniter/libraries/Session_test.php50
-rw-r--r--user_guide_src/source/changelog.rst3
-rw-r--r--user_guide_src/source/database/query_builder.rst37
-rw-r--r--user_guide_src/source/general/caching.rst12
-rw-r--r--user_guide_src/source/libraries/output.rst30
8 files changed, 219 insertions, 29 deletions
diff --git a/system/core/Output.php b/system/core/Output.php
index 6312ccd86..98deff55c 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -256,7 +256,7 @@ class CI_Output {
{
for ($i = 0, $c = count($this->headers); $i < $c; $i++)
{
- if (sscanf($this->headers[$i][0], 'Content-Type: %s', $content_type) === 1)
+ if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1)
{
return $content_type;
}
@@ -268,6 +268,39 @@ class CI_Output {
// --------------------------------------------------------------------
/**
+ * Get Header
+ *
+ * @param string $header_name
+ * @return string
+ */
+ public function get_header($header)
+ {
+ // Combine headers already sent with our batched headers
+ $headers = array_merge(
+ // We only need [x][0] from our multi-dimensional array
+ array_map('array_shift', $this->headers),
+ headers_list()
+ );
+
+ if (empty($headers) OR empty($header))
+ {
+ return NULL;
+ }
+
+ for ($i = 0, $c = count($headers); $i < $c; $i++)
+ {
+ if (strncasecmp($header, $headers[$i], $l = strlen($header)) === 0)
+ {
+ return trim(substr($headers[$i], $l+1));
+ }
+ }
+
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Set HTTP Status Header
*
* As of version 1.7.2, this is an alias for common function
@@ -594,6 +627,45 @@ class CI_Output {
// --------------------------------------------------------------------
/**
+ * Delete cache
+ *
+ * @param string $uri URI string
+ * @return bool
+ */
+ public function delete_cache($uri = '')
+ {
+ $CI =& get_instance();
+ $cache_path = $CI->config->item('cache_path');
+ if ($cache_path === '')
+ {
+ $cache_path = APPPATH.'cache/';
+ }
+
+ if ( ! is_dir($cache_path))
+ {
+ log_message('error', 'Unable to find cache path: '.$cache_path);
+ return FALSE;
+ }
+
+ if (empty($uri))
+ {
+ $uri = $CI->uri->uri_string();
+ }
+
+ $cache_path .= md5($CI->config->item('base_url').$CI->config->item('index_page').$uri);
+
+ if ( ! @unlink($cache_path))
+ {
+ log_message('error', 'Unable to delete cache file for '.$uri);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Set Cache Header
*
* Set the HTTP headers to match the server-side file cache settings
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 9bd535b0e..e77fba63d 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -903,11 +903,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
is_bool($escape) OR $escape = $this->_protect_identifiers;
- $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0)
- ? $this->_group_get_type('') : $this->_group_get_type($type);
foreach ($field as $k => $v)
{
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0)
+ ? $this->_group_get_type('') : $this->_group_get_type($type);
+
$v = $this->escape_like_str($v);
if ($side === 'none')
diff --git a/tests/codeigniter/core/Output_test.php b/tests/codeigniter/core/Output_test.php
new file mode 100644
index 000000000..d8252403d
--- /dev/null
+++ b/tests/codeigniter/core/Output_test.php
@@ -0,0 +1,37 @@
+<?php
+
+class Output_test extends CI_TestCase {
+
+ public $output;
+
+ public function set_up()
+ {
+ $this->ci_set_config('charset', 'UTF-8');
+ $output = $this->ci_core_class('output');
+ $this->output = new $output();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_content_type()
+ {
+ $this->assertEquals('text/html', $this->output->get_content_type());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_header()
+ {
+ $this->assertNull($this->output->get_header('Non-Existent-Header'));
+
+ // TODO: Find a way to test header() values as well. Currently,
+ // PHPUnit prevents this by not using output buffering.
+
+ $this->output->set_content_type('text/plain', 'WINDOWS-1251');
+ $this->assertEquals(
+ 'text/plain; charset=windows-1251', // Character set is converted to lowercase
+ $this->output->get_header('content-type') // Case-insensitive comparison
+ );
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php
index e675b4ed7..7ef3a3667 100644
--- a/tests/codeigniter/libraries/Session_test.php
+++ b/tests/codeigniter/libraries/Session_test.php
@@ -252,6 +252,56 @@ class Session_test extends CI_TestCase {
$this->assertNull($this->session->native->flashdata($key));
}
+ public function test_keep_flashdata_with_array()
+ {
+ // Set flashdata array for each driver
+ $cdata = array(
+ 'one' => 'first',
+ 'two' => 'second',
+ 'three' => 'third',
+ 'foo' => 'bar',
+ 'bar' => 'baz'
+ );
+ $ndata = array(
+ 'one' => 'gold',
+ 'two' => 'silver',
+ 'three' => 'bronze',
+ 'foo' => 'baz',
+ 'bar' => 'foo'
+ );
+ $kdata = array(
+ 'one',
+ 'two',
+ 'three',
+ 'foo',
+ 'bar'
+ );
+ $this->session->cookie->set_flashdata($cdata);
+ $this->session->native->set_flashdata($ndata);
+
+ // Simulate page reload and verify independent messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cdata, $this->session->cookie->all_flashdata());
+ $this->assertEquals($ndata, $this->session->native->all_flashdata());
+
+ // Keep messages
+ $this->session->cookie->keep_flashdata($kdata);
+ $this->session->native->keep_flashdata($kdata);
+
+ // Simulate next page reload and verify message persistence
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cdata, $this->session->cookie->all_flashdata());
+ $this->assertEquals($ndata, $this->session->native->all_flashdata());
+
+ // Simulate next page reload and verify absence of messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEmpty($this->session->cookie->all_flashdata());
+ $this->assertEmpty($this->session->native->all_flashdata());
+ }
+
/**
* Test the all_flashdata() function
*/
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index ab1d99dab..6570eb790 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -294,8 +294,9 @@ Release Date: Not Released
- 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 <general/hooks>`.
- :doc:`Output Library <libraries/output>` changes include:
- - Added method ``get_content_type()``.
- Added a second argument to method ``set_content_type()`` that allows setting the document charset as well.
+ - Added methods ``get_content_type()`` and ``get_header()``.
+ - Added method ``delete_cache()``.
- ``$config['time_reference']`` now supports all timezone strings supported by PHP.
- :doc:`Config Library <libraries/config>` changes include:
- Changed ``site_url()`` method to accept an array as well.
diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst
index 8fb906052..65609c1cb 100644
--- a/user_guide_src/source/database/query_builder.rst
+++ b/user_guide_src/source/database/query_builder.rst
@@ -345,23 +345,24 @@ if appropriate
$this->db->like()
=================
-This function enables you to generate **LIKE** clauses, useful for doing
+This method enables you to generate **LIKE** clauses, useful for doing
searches.
-.. note:: All values passed to this function are escaped automatically.
+.. note:: All values passed to this method are escaped automatically.
#. **Simple key/value method:**
::
- $this->db->like('title', 'match'); // Produces: WHERE title LIKE '%match%'
+ $this->db->like('title', 'match');
+ // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'
- If you use multiple function calls they will be chained together with
+ If you use multiple method calls they will be chained together with
AND between them::
$this->db->like('title', 'match');
$this->db->like('body', 'match');
- // WHERE title LIKE '%match%' AND body LIKE '%match%
+ // WHERE `title` LIKE '%match%' ESCAPE '!' AND `body` LIKE '%match% ESCAPE '!'
If you want to control where the wildcard (%) is placed, you can use
an optional third argument. Your options are 'before', 'after' and
@@ -369,9 +370,9 @@ searches.
::
- $this->db->like('title', 'match', 'before'); // Produces: WHERE title LIKE '%match'
- $this->db->like('title', 'match', 'after'); // Produces: WHERE title LIKE 'match%'
- $this->db->like('title', 'match', 'both'); // Produces: WHERE title LIKE '%match%'
+ $this->db->like('title', 'match', 'before'); // Produces: WHERE `title` LIKE '%match' ESCAPE '!'
+ $this->db->like('title', 'match', 'after'); // Produces: WHERE `title` LIKE 'match%' ESCAPE '!'
+ $this->db->like('title', 'match', 'both'); // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'
#. **Associative array method:**
@@ -379,37 +380,37 @@ searches.
$array = array('title' => $match, 'page1' => $match, 'page2' => $match);
$this->db->like($array);
- // WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%'
+ // WHERE `title` LIKE '%match%' ESCAPE '!' AND `page1` LIKE '%match%' ESCAPE '!' AND `page2` LIKE '%match%' ESCAPE '!'
$this->db->or_like()
====================
-This function is identical to the one above, except that multiple
+This method is identical to the one above, except that multiple
instances are joined by OR::
$this->db->like('title', 'match'); $this->db->or_like('body', $match);
- // WHERE title LIKE '%match%' OR body LIKE '%match%'
+ // WHERE `title` LIKE '%match%' ESCAPE '!' OR `body` LIKE '%match%' ESCAPE '!'
-.. note:: or_like() was formerly known as orlike(), which has been removed.
+.. note:: ``or_like()`` was formerly known as ``orlike()``, which has been removed.
$this->db->not_like()
=====================
-This function is identical to **like()**, except that it generates NOT
-LIKE statements::
+This method is identical to ``like()``, except that it generates
+NOT LIKE statements::
- $this->db->not_like('title', 'match'); // WHERE title NOT LIKE '%match%
+ $this->db->not_like('title', 'match'); // WHERE `title` NOT LIKE '%match% ESCAPE '!'
$this->db->or_not_like()
========================
-This function is identical to **not_like()**, except that multiple
+This method is identical to ``not_like()``, except that multiple
instances are joined by OR::
$this->db->like('title', 'match');
$this->db->or_not_like('body', 'match');
- // WHERE title LIKE '%match% OR body NOT LIKE '%match%'
+ // WHERE `title` LIKE '%match% OR `body` NOT LIKE '%match%' ESCAPE '!'
$this->db->group_by()
=====================
@@ -1054,4 +1055,4 @@ run the query::
$data = $this->db->get()->result_array();
// Would execute and return an array of results of the following query:
- // SELECT field1, field1 from mytable where field3 = 5;
+ // SELECT field1, field1 from mytable where field3 = 5; \ No newline at end of file
diff --git a/user_guide_src/source/general/caching.rst b/user_guide_src/source/general/caching.rst
index c40f652ac..48385d6c9 100644
--- a/user_guide_src/source/general/caching.rst
+++ b/user_guide_src/source/general/caching.rst
@@ -56,5 +56,13 @@ If you no longer wish to cache a file you can remove the caching tag and
it will no longer be refreshed when it expires.
.. note:: Removing the tag will not delete the cache immediately. It will
- have to expire normally. If you need to remove it earlier you
- will need to manually delete it from your cache directory. \ No newline at end of file
+ have to expire normally.
+
+If you need to manually delete the cache, you can use the ``delete_cache()``
+method::
+
+ // Deletes cache for the currently requested URI
+ $this->output->delete_cache();
+
+ // Deletes cache for /foo/bar
+ $this->output->delete_cache('/foo/bar'); \ No newline at end of file
diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst
index 82b1a56a5..a3d67b847 100644
--- a/user_guide_src/source/libraries/output.rst
+++ b/user_guide_src/source/libraries/output.rst
@@ -53,17 +53,37 @@ You can also set the character set of the document, by passing a second argument
$this->output->set_content_type('css', 'utf-8');
-$this->output->get_content_type();
-==========================================
+$this->output->get_content_type()
+=================================
-Returns the Content-Type HTTP header that's currently in use.
+Returns the Content-Type HTTP header that's currently in use,
+excluding the character set value.
$mime = $this->output->get_content_type();
.. note:: If not set, the default return value is 'text/html'.
-$this->output->get_output();
-=============================
+$this->output->get_header()
+===========================
+
+Gets the requested HTTP header value, if set.
+
+If the header is not set, NULL will be returned.
+If an empty value is passed to the method, it will return FALSE.
+
+Example::
+
+ $this->output->set_content_type('text/plain', 'UTF-8');
+ echo $this->output->get_header('content-type');
+ // Outputs: text/plain; charset=utf-8
+
+.. note:: The header name is compared in a case-insensitive manner.
+
+.. note:: Raw headers sent via PHP's native ``header()`` function are
+ also detected.
+
+$this->output->get_output()
+===========================
Permits you to manually retrieve any output that has been sent for
storage in the output class. Usage example::