diff options
-rw-r--r-- | system/core/Utf8.php | 8 | ||||
-rw-r--r-- | system/helpers/file_helper.php | 1 | ||||
-rw-r--r-- | system/helpers/url_helper.php | 35 | ||||
-rw-r--r-- | system/libraries/Ftp.php | 75 | ||||
-rw-r--r-- | system/libraries/Pagination.php | 38 | ||||
-rw-r--r-- | tests/codeigniter/core/Utf8_test.php | 4 | ||||
-rw-r--r-- | tests/codeigniter/helpers/array_helper_test.php | 16 | ||||
-rw-r--r-- | tests/codeigniter/helpers/captcha_helper_test.php | 2 | ||||
-rw-r--r-- | tests/codeigniter/helpers/directory_helper_test.php | 2 | ||||
-rw-r--r-- | tests/codeigniter/helpers/email_helper_test.php | 5 | ||||
-rw-r--r-- | tests/codeigniter/helpers/file_helper_test.php | 74 | ||||
-rw-r--r-- | tests/codeigniter/helpers/inflector_helper_test.php | 44 | ||||
-rw-r--r-- | tests/mocks/core/utf8.php | 5 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 |
14 files changed, 152 insertions, 158 deletions
diff --git a/system/core/Utf8.php b/system/core/Utf8.php index 6ca1a02ca..c789a7ba4 100644 --- a/system/core/Utf8.php +++ b/system/core/Utf8.php @@ -51,7 +51,7 @@ class CI_Utf8 { if ( defined('PREG_BAD_UTF8_ERROR') // PCRE must support UTF-8 && (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) // iconv or mbstring must be installed - && strnatcasecmp(config_item('charset'), 'UTF-8') === 0 // Application charset must be UTF-8 + && strtoupper(config_item('charset')) === 'UTF-8' // Application charset must be UTF-8 ) { define('UTF8_ENABLED', TRUE); @@ -73,14 +73,12 @@ class CI_Utf8 { * * Ensures strings contain only valid UTF-8 characters. * - * @uses CI_Utf8::_is_ascii() Decide whether a conversion is needed - * * @param string $str String to clean * @return string */ public function clean_string($str) { - if ($this->_is_ascii($str) === FALSE) + if ($this->is_ascii($str) === FALSE) { if (ICONV_ENABLED) { @@ -147,7 +145,7 @@ class CI_Utf8 { * @param string $str String to check * @return bool */ - protected function _is_ascii($str) + public function is_ascii($str) { return (preg_match('/[^\x00-\x7F]/S', $str) === 0); } diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 575b87479..b8b70534f 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -267,7 +267,6 @@ if ( ! function_exists('get_file_info')) */ function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) { - if ( ! file_exists($file)) { return FALSE; diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index a9790e5c4..5f11a42ca 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -342,23 +342,24 @@ if ( ! function_exists('safe_mailto')) $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; $x = array_reverse($x); - ob_start(); - - ?><script type="text/javascript"> - //<![CDATA[ - var l=new Array(); - <?php - for ($i = 0, $c = count($x); $i < $c; $i++) { ?>l[<?php echo $i; ?>]='<?php echo $x[$i]; ?>';<?php } ?> - - for (var i = l.length-1; i >= 0; i=i-1){ - if (l[i].substring(0, 1) === '|') document.write("&#"+unescape(l[i].substring(1))+";"); - else document.write(unescape(l[i]));} - //]]> - </script><?php - - $buffer = ob_get_contents(); - ob_end_clean(); - return $buffer; + + $output = "<script type=\"text/javascript\">\n" + ."\t//<![CDATA[\n" + ."\tvar l=new Array();\n"; + + for ($i = 0, $c = count($x); $i < $c; $i++) + { + $output .= "\tl[".$i."] = '".$x[$i]."';\n"; + } + + $output .= "\n\tfor (var i = l.length-1; i >= 0; i=i-1) {\n" + ."\t\tif (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");\n" + ."\t\telse document.write(unescape(l[i]));\n" + ."\t}\n" + ."\t//]]>\n" + .'</script>'; + + return $output; } } diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index ef3b7d70d..991769a6a 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -463,28 +463,26 @@ class CI_FTP { $filepath = preg_replace('/(.+?)\/*$/', '\\1/', $filepath); $list = $this->list_files($filepath); - - if ($list !== FALSE && count($list) > 0) + if ( ! empty($list)) { - foreach ($list as $item) + for ($i = 0, $c = count($list); $i < $c; $i++) { - // If we can't delete the item it's probaly a folder so - // we'll recursively call delete_dir() - if ( ! @ftp_delete($this->conn_id, $item)) + // If we can't delete the item it's probaly a directory, + // so we'll recursively call delete_dir() + if ( ! @ftp_delete($this->conn_id, $list[$i])) { - $this->delete_dir($item); + $this->delete_dir($list[$i]); } } } - $result = @ftp_rmdir($this->conn_id, $filepath); - - if ($result === FALSE) + if (@ftp_rmdir($this->conn_id, $filepath) === FALSE) { if ($this->debug === TRUE) { $this->_error('ftp_unable_to_delete'); } + return FALSE; } @@ -507,14 +505,13 @@ class CI_FTP { return FALSE; } - $result = @ftp_chmod($this->conn_id, $perm, $path); - - if ($result === FALSE) + if (@ftp_chmod($this->conn_id, $perm, $path) === FALSE) { if ($this->debug === TRUE) { $this->_error('ftp_unable_to_chmod'); } + return FALSE; } @@ -531,12 +528,9 @@ class CI_FTP { */ public function list_files($path = '.') { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - return ftp_nlist($this->conn_id, $path); + return $this->_is_conn() + ? ftp_nlist($this->conn_id, $path) + : FALSE; } // ------------------------------------------------------------------------ @@ -585,6 +579,7 @@ class CI_FTP { $this->upload($locpath.$file, $rempath.$file, $mode); } } + return TRUE; } @@ -601,13 +596,12 @@ class CI_FTP { */ protected function _getext($filename) { - if (FALSE === strpos($filename, '.')) + if (($dot = strrpos($filename, '.')) === FALSE) { return 'txt'; } - $x = explode('.', $filename); - return end($x); + return substr($filename, $dot + 1); } // -------------------------------------------------------------------- @@ -621,20 +615,20 @@ class CI_FTP { protected function _settype($ext) { $text_types = array( - 'txt', - 'text', - 'php', - 'phps', - 'php4', - 'js', - 'css', - 'htm', - 'html', - 'phtml', - 'shtml', - 'log', - 'xml' - ); + 'txt', + 'text', + 'php', + 'phps', + 'php4', + 'js', + 'css', + 'htm', + 'html', + 'phtml', + 'shtml', + 'log', + 'xml' + ); return in_array($ext, $text_types) ? 'ascii' : 'binary'; } @@ -648,12 +642,9 @@ class CI_FTP { */ public function close() { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - return @ftp_close($this->conn_id); + return $this->_is_conn() + ? @ftp_close($this->conn_id) + : FALSE; } // ------------------------------------------------------------------------ diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index f2d38a852..da2fe7400 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -294,6 +294,13 @@ class CI_Pagination { */ protected $data_page_attr = 'data-ci-pagination-page'; + /** + * CI Singleton + * + * @var object + */ + protected $CI; + // -------------------------------------------------------------------- /** @@ -304,11 +311,11 @@ class CI_Pagination { */ public function __construct($params = array()) { - $CI =& get_instance(); - $CI->load->language('pagination'); + $this->CI =& get_instance(); + $this->CI->load->language('pagination'); foreach (array('first_link', 'next_link', 'prev_link', 'last_link') as $key) { - if (($val = $CI->lang->line('pagination_'.$key)) !== FALSE) + if (($val = $this->CI->lang->line('pagination_'.$key)) !== FALSE) { $this->$key = $val; } @@ -344,12 +351,17 @@ class CI_Pagination { foreach ($params as $key => $val) { - if (property_exists($this, $this->$key)) + if (property_exists($this, $key)) { $this->$key = $val; } } + if ($this->CI->config->item('enable_query_strings') === TRUE) + { + $this->page_query_string = TRUE; + } + return $this; } @@ -386,13 +398,11 @@ class CI_Pagination { show_error('Your number of links must be a positive number.'); } - $CI =& get_instance(); - // Keep any existing query string items. // Note: Has nothing to do with any other query string option. if ($this->reuse_query_string === TRUE) { - $get = $CI->input->get(); + $get = $this->CI->input->get(); // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); @@ -411,7 +421,7 @@ class CI_Pagination { $query_string_sep = (strpos($base_url, '?') === FALSE) ? '?' : '&'; // Are we using query strings? - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) + if ($this->page_query_string === TRUE) { // If a custom first_url hasn't been specified, we'll create one from // the base_url, but without the page item. @@ -459,19 +469,19 @@ class CI_Pagination { $base_page = ($this->use_page_numbers) ? 1 : 0; // Are we using query strings? - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) + if ($this->page_query_string === TRUE) { - $this->cur_page = $CI->input->get($this->query_string_segment); + $this->cur_page = $this->CI->input->get($this->query_string_segment); } else { // Default to the last segment number if one hasn't been defined. if ($this->uri_segment === 0) { - $this->uri_segment = count($CI->uri->segment_array()); + $this->uri_segment = count($this->CI->uri->segment_array()); } - $this->cur_page = $CI->uri->segment($this->uri_segment); + $this->cur_page = $this->CI->uri->segment($this->uri_segment); // Remove any specified prefix/suffix from the segment. if ($this->prefix !== '' OR $this->suffix !== '') @@ -629,8 +639,8 @@ class CI_Pagination { { isset($attributes['rel']) OR $attributes['rel'] = TRUE; $this->_link_types = ($attributes['rel']) - ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next') - : array(); + ? array('start' => 'start', 'prev' => 'prev', 'next' => 'next') + : array(); unset($attributes['rel']); $this->_attributes = ''; diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php index 71299134e..2cf404841 100644 --- a/tests/codeigniter/core/Utf8_test.php +++ b/tests/codeigniter/core/Utf8_test.php @@ -18,8 +18,8 @@ class Utf8_test extends CI_TestCase { public function test_is_ascii() { - $this->assertTrue($this->utf8->is_ascii_test('foo bar')); - $this->assertFalse($this->utf8->is_ascii_test('тест')); + $this->assertTrue($this->utf8->is_ascii('foo bar')); + $this->assertFalse($this->utf8->is_ascii('тест')); } }
\ No newline at end of file diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index ba46e86f9..5a9958971 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -2,16 +2,16 @@ class Array_helper_test extends CI_TestCase { + public $my_array = array( + 'foo' => 'bar', + 'sally' => 'jim', + 'maggie' => 'bessie', + 'herb' => 'cook' + ); + public function set_up() { $this->helper('array'); - - $this->my_array = array( - 'foo' => 'bar', - 'sally' => 'jim', - 'maggie' => 'bessie', - 'herb' => 'cook' - ); } // ------------------------------------------------------------------------ @@ -19,9 +19,7 @@ class Array_helper_test extends CI_TestCase { public function test_element_with_existing_item() { $this->assertEquals(FALSE, element('testing', $this->my_array)); - $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); - $this->assertEquals('bar', element('foo', $this->my_array)); } diff --git a/tests/codeigniter/helpers/captcha_helper_test.php b/tests/codeigniter/helpers/captcha_helper_test.php index fc86305e3..bb8760a15 100644 --- a/tests/codeigniter/helpers/captcha_helper_test.php +++ b/tests/codeigniter/helpers/captcha_helper_test.php @@ -4,7 +4,7 @@ class Captcha_helper_test extends CI_TestCase { public function test_create_captcha() { - $this->markTestSkipped('Cant easily test'); + $this->markTestSkipped("Can't test"); } }
\ No newline at end of file diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index de72dee78..ac71dfaf8 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -31,7 +31,7 @@ class Directory_helper_test extends CI_TestCase { // is_dir(), opendir(), etc. seem to fail on Windows + vfsStream when there are trailing backslashes in directory names if ( ! is_dir(vfsStream::url('testDir').DIRECTORY_SEPARATOR)) { - $this->markTestSkipped(); + $this->markTestSkipped("Can't test this under Windows"); return; } diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php index fea452f5f..53a206825 100644 --- a/tests/codeigniter/helpers/email_helper_test.php +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -15,4 +15,9 @@ class Email_helper_test extends CI_TestCase { $this->assertEquals(TRUE, valid_email('my.test@test.com')); } + public function test_send_mail() + { + $this->markTestSkipped("Can't test"); + } + }
\ No newline at end of file diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index 3a6c73a5c..c31817595 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -31,9 +31,10 @@ class File_helper_Test extends CI_TestCase { { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); + $file = vfsStream::newFile('my_file.txt', 0777) + ->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); $this->assertEquals('777', octal_permissions($file->getPermissions())); } @@ -47,9 +48,10 @@ class File_helper_Test extends CI_TestCase { { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); + $file = vfsStream::newFile('my_file.txt', 0777) + ->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); } @@ -60,9 +62,10 @@ class File_helper_Test extends CI_TestCase { { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); + $file = vfsStream::newFile('my_file.txt', 0777) + ->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt'))); @@ -103,19 +106,20 @@ class File_helper_Test extends CI_TestCase { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; $last_modified = time() - 86400; - $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified($last_modified) - ->at($this->_test_dir); + $file = vfsStream::newFile('my_file.txt', 0777) + ->withContent($content) + ->lastModified($last_modified) + ->at($this->_test_dir); $ret_values = array( - 'name' => 'my_file.txt', - 'server_path' => 'vfs://my_file.txt', - 'size' => 57, - 'date' => $last_modified, - 'readable' => TRUE, - 'writable' => TRUE, - 'executable' => TRUE, - 'fileperms' => 33279 + 'name' => 'my_file.txt', + 'server_path' => 'vfs://my_file.txt', + 'size' => 57, + 'date' => $last_modified, + 'readable' => TRUE, + 'writable' => TRUE, + 'executable' => TRUE, + 'fileperms' => 33279 ); $info = get_file_info(vfsStream::url('my_file.txt'), $vals); @@ -128,24 +132,16 @@ class File_helper_Test extends CI_TestCase { // -------------------------------------------------------------------- - // Skipping for now, as it's not implemented in vfsStreamWrapper - // flock(): vfsStreamWrapper::stream_lock is not implemented! - - // public function test_write_file() - // { - // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')) - // { - // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); - // } - // - // $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - // - // $file = vfsStream::newFile('write.txt', 0777)->withContent('') - // ->lastModified(time() - 86400) - // ->at($this->_test_dir); - // - // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); - // - // } + public function test_write_file() + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('write.txt', 0777) + ->withContent('') + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); + } }
\ No newline at end of file diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index f3b0ebbe8..81ce5e394 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -10,11 +10,11 @@ class Inflector_helper_test extends CI_TestCase { public function test_singular() { $strs = array( - 'tellies' => 'telly', - 'smellies' => 'smelly', - 'abjectnesses' => 'abjectness', - 'smells' => 'smell', - 'equipment' => 'equipment' + 'tellies' => 'telly', + 'smellies' => 'smelly', + 'abjectnesses' => 'abjectness', + 'smells' => 'smell', + 'equipment' => 'equipment' ); foreach ($strs as $str => $expect) @@ -28,12 +28,12 @@ class Inflector_helper_test extends CI_TestCase { public function test_plural() { $strs = array( - 'telly' => 'tellies', - 'smelly' => 'smellies', - 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses - 'smell' => 'smells', - 'witch' => 'witches', - 'equipment' => 'equipment' + 'telly' => 'tellies', + 'smelly' => 'smellies', + 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses + 'smell' => 'smells', + 'witch' => 'witches', + 'equipment' => 'equipment' ); foreach ($strs as $str => $expect) @@ -48,9 +48,9 @@ class Inflector_helper_test extends CI_TestCase { { $strs = array( 'this is the string' => 'thisIsTheString', - 'this is another one' => 'thisIsAnotherOne', - 'i-am-playing-a-trick' => 'i-am-playing-a-trick', - 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', + 'this is another one' => 'thisIsAnotherOne', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', ); foreach ($strs as $str => $expect) @@ -64,10 +64,10 @@ class Inflector_helper_test extends CI_TestCase { public function test_underscore() { $strs = array( - 'this is the string' => 'this_is_the_string', - 'this is another one' => 'this_is_another_one', - 'i-am-playing-a-trick' => 'i-am-playing-a-trick', - 'what_do_you_think-yo?' => 'what_do_you_think-yo?', + 'this is the string' => 'this_is_the_string', + 'this is another one' => 'this_is_another_one', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'what_do_you_think-yo?', ); foreach ($strs as $str => $expect) @@ -81,10 +81,10 @@ class Inflector_helper_test extends CI_TestCase { public function test_humanize() { $strs = array( - 'this_is_the_string' => 'This Is The String', - 'this_is_another_one' => 'This Is Another One', - 'i-am-playing-a-trick' => 'I-am-playing-a-trick', - 'what_do_you_think-yo?' => 'What Do You Think-yo?', + 'this_is_the_string' => 'This Is The String', + 'this_is_another_one' => 'This Is Another One', + 'i-am-playing-a-trick' => 'I-am-playing-a-trick', + 'what_do_you_think-yo?' => 'What Do You Think-yo?', ); foreach ($strs as $str => $expect) diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php index 30b78adfe..c8214a62a 100644 --- a/tests/mocks/core/utf8.php +++ b/tests/mocks/core/utf8.php @@ -13,9 +13,4 @@ class Mock_Core_Utf8 extends CI_Utf8 { defined('UTF8_ENABLED') OR define('UTF8_ENABLED', TRUE); } - public function is_ascii_test($str) - { - return $this->_is_ascii($str); - } - }
\ No newline at end of file diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index ca31669e8..bda4cbab4 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -505,6 +505,7 @@ Release Date: Not Released - ``UTF8_ENABLED`` now requires only one of `Multibyte String <http://php.net/mbstring>`_ or `iconv <http://php.net/iconv>`_ to be available instead of both. - Changed method ``clean_string()`` to utilize ``mb_convert_encoding()`` if it is available but ``iconv()`` is not. + - Renamed method ``_is_ascii()`` to ``is_ascii()`` and made it public. - Added `compatibility layers <general/compatibility_functions>` for PHP's `mbstring <http://php.net/mbstring>`_ (limited support) and `password <http://php.net/password>`_ extensions. - Removed ``CI_CORE`` boolean constant from *CodeIgniter.php* (no longer Reactor and Core versions). |