diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/core/Common.php | 8 | ||||
-rw-r--r-- | system/core/Output.php | 2 | ||||
-rw-r--r-- | system/core/Router.php | 2 | ||||
-rw-r--r-- | system/database/DB_driver.php | 2 | ||||
-rw-r--r-- | system/database/DB_query_builder.php | 7 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_driver.php | 2 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php | 24 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php | 30 | ||||
-rw-r--r-- | system/database/drivers/sqlite3/sqlite3_driver.php | 30 | ||||
-rw-r--r-- | system/helpers/array_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/inflector_helper.php | 1 | ||||
-rw-r--r-- | system/helpers/url_helper.php | 2 | ||||
-rw-r--r-- | system/libraries/Cache/Cache.php | 22 | ||||
-rw-r--r-- | system/libraries/Cache/drivers/Cache_redis.php | 14 | ||||
-rw-r--r-- | system/libraries/Form_validation.php | 28 | ||||
-rw-r--r-- | system/libraries/Ftp.php | 2 | ||||
-rw-r--r-- | system/libraries/Image_lib.php | 18 | ||||
-rw-r--r-- | system/libraries/Session/drivers/Session_memcached_driver.php | 2 | ||||
-rw-r--r-- | system/libraries/Session/drivers/Session_redis_driver.php | 2 |
19 files changed, 120 insertions, 82 deletions
diff --git a/system/core/Common.php b/system/core/Common.php index f28272b5b..b850fd39a 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -181,7 +181,7 @@ if ( ! function_exists('load_class')) // Did we find the class? if ($name === FALSE) { - // Note: We use exit() rather then show_error() in order to avoid a + // Note: We use exit() rather than show_error() in order to avoid a // self-referencing loop with the Exceptions class set_status_header(503); echo 'Unable to locate the specified class: '.$class.'.php'; @@ -506,6 +506,9 @@ if ( ! function_exists('set_status_header')) { is_int($code) OR $code = (int) $code; $stati = array( + 100 => 'Continue', + 101 => 'Switching Protocols', + 200 => 'OK', 201 => 'Created', 202 => 'Accepted', @@ -524,6 +527,7 @@ if ( ! function_exists('set_status_header')) 400 => 'Bad Request', 401 => 'Unauthorized', + 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', @@ -745,7 +749,7 @@ if ( ! function_exists('html_escape')) { return $var; } - + if (is_array($var)) { return array_map('html_escape', $var, array_fill(0, count($var), $double_encode)); diff --git a/system/core/Output.php b/system/core/Output.php index 02f66936c..e7d559a1d 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -674,7 +674,7 @@ class CI_Output { $cache_info = unserialize($match[1]); $expire = $cache_info['expire']; - $last_modified = filemtime($cache_path); + $last_modified = filemtime($filepath); // Has the file expired? if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path)) diff --git a/system/core/Router.php b/system/core/Router.php index eb3da2285..f91d3f6ec 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -493,7 +493,7 @@ class CI_Router { * Set directory name * * @param string $dir Directory name - * @param bool $appent Whether we're appending rather then setting the full value + * @param bool $appent Whether we're appending rather than setting the full value * @return void */ public function set_directory($dir, $append = FALSE) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 3d35c2d70..64ee880c8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1218,7 +1218,7 @@ abstract class CI_DB_driver { /** * Fetch Field Names * - * @param string the table name + * @param string $table Table name * @return array */ public function list_fields($table) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index a77ed57d0..8251f4558 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -918,6 +918,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } is_bool($escape) OR $escape = $this->_protect_identifiers; + // lowercase $side in case somebody writes e.g. 'BEFORE' instead of 'before' (doh) + $side = strtolower($side); foreach ($field as $k => $v) { @@ -925,9 +927,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { ? $this->_group_get_type('') : $this->_group_get_type($type); $v = $this->escape_like_str($v); - - // lowercase $side for in case of UPPERCASE string - $side = strtolower($side); if ($side === 'none') { @@ -2256,7 +2255,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { else { // Cycle through the "select" portion of the query and prep each column name. - // The reason we protect identifiers here rather then in the select() function + // The reason we protect identifiers here rather than in the select() function // is because until the user calls the from() function we don't know if there are aliases foreach ($this->qb_select as $key => $val) { diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 4010995a1..b5cf26536 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -573,7 +573,7 @@ class CI_DB_oci8_driver extends CI_DB { { $default = ''; } - $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + $retval[$i]->default = $default; } return $retval; diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index 67dc5f5ec..206d83595 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -157,6 +157,30 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($database))) + { + $this->database = $database; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php index f07f49f84..d5ca741fd 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php @@ -121,17 +121,31 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- /** - * Show column query + * Fetch Field Names * - * Generates a platform-specific query string so that the column names can be fetched - * - * @param string $table - * @return string + * @param string $table Table name + * @return array */ - protected function _list_columns($table = '') + public function list_fields($table) { - // Not supported - return FALSE; + // Is there a cached result? + if (isset($this->data_cache['field_names'][$table])) + { + return $this->data_cache['field_names'][$table]; + } + + if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $this->data_cache['field_names'][$table] = array(); + foreach ($result as $row) + { + $this->data_cache['field_names'][$table][] = $row['name']; + } + + return $this->data_cache['field_names'][$table]; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index fdbe94939..a7c6420bb 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -247,17 +247,31 @@ class CI_DB_sqlite3_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show column query + * Fetch Field Names * - * Generates a platform-specific query string so that the column names can be fetched - * - * @param string $table - * @return string + * @param string $table Table name + * @return array */ - protected function _list_columns($table = '') + public function list_fields($table) { - // Not supported - return FALSE; + // Is there a cached result? + if (isset($this->data_cache['field_names'][$table])) + { + return $this->data_cache['field_names'][$table]; + } + + if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $this->data_cache['field_names'][$table] = array(); + foreach ($result as $row) + { + $this->data_cache['field_names'][$table][] = $row['name']; + } + + return $this->data_cache['field_names'][$table]; } // -------------------------------------------------------------------- diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index e07b52bb5..2ce55b9c4 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -62,7 +62,7 @@ if ( ! function_exists('element')) * @param mixed * @return mixed depends on what the array contains */ - function element($item, $array, $default = NULL) + function element($item, array $array, $default = NULL) { return array_key_exists($item, $array) ? $array[$item] : $default; } @@ -99,7 +99,7 @@ if ( ! function_exists('elements')) * @param mixed * @return mixed depends on what the array contains */ - function elements($items, $array, $default = NULL) + function elements($items, array $array, $default = NULL) { $return = array(); diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index d8ed45df9..f2890059f 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -133,6 +133,7 @@ if ( ! function_exists('plural')) } $plural_rules = array( + '/(quiz)$/' => '\1zes', // quizzes '/^(ox)$/' => '\1\2en', // ox '/([m|l])ouse$/' => '\1ice', // mouse, louse '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index bf623b000..5f8c6ce67 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -161,7 +161,7 @@ if ( ! function_exists('anchor')) $site_url = is_array($uri) ? site_url($uri) - : preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri); + : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri)); if ($title === '') { diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 40ac70103..215a7c528 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -100,28 +100,10 @@ class CI_Cache extends CI_Driver_Library { */ public function __construct($config = array()) { - $default_config = array( - 'adapter', - 'memcached' - ); - - foreach ($default_config as $key) - { - if (isset($config[$key])) - { - $param = '_'.$key; - - $this->{$param} = $config[$key]; - } - } - + isset($config['adapter']) && $this->_adapter = $config['adapter']; + isset($config['backup']) && $this->_backup_driver = $config['backup']; isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; - if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers)) - { - $this->_backup_driver = $config['backup']; - } - // If the specified adapter isn't available, check the backup. if ( ! $this->is_supported($this->_adapter)) { diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index a35fbf6d2..66966ba16 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -125,9 +125,7 @@ class CI_Cache_redis extends CI_Driver $this->_redis->sRemove('_ci_redis_serialized', $id); } - return ($ttl) - ? $this->_redis->setex($id, $ttl, $data) - : $this->_redis->set($id, $data); + return $this->_redis->set($id, $data, $ttl); } // ------------------------------------------------------------------------ @@ -223,7 +221,7 @@ class CI_Cache_redis extends CI_Driver { $value = $this->get($key); - if ($value) + if ($value !== FALSE) { return array( 'expire' => time() + $this->_redis->ttl($key), @@ -270,7 +268,7 @@ class CI_Cache_redis extends CI_Driver if ($CI->config->load('redis', TRUE, TRUE)) { - $config += $CI->config->item('redis'); + $config = $CI->config->item('redis'); } $config = array_merge(self::$_default_config, $config); @@ -302,7 +300,11 @@ class CI_Cache_redis extends CI_Driver if (isset($config['password'])) { - $this->_redis->auth($config['password']); + if ( ! $this->_redis->auth($config['password'])) + { + log_message('debug', 'Cache: Redis authentication failed.'); + return FALSE; + } } // Initialize the index of serialized values. diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 05de59628..7599602c0 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -198,22 +198,20 @@ class CI_Form_validation { return $this; } - // No fields? Nothing to do... - if ( ! is_string($field) OR $field === '') + // No fields or no rules? Nothing to do... + if ( ! is_string($field) OR $field === '' OR empty($rules)) { return $this; } elseif ( ! is_array($rules)) { // BC: Convert pipe-separated rules string to an array - if (is_string($rules)) - { - $rules = explode('|', $rules); - } - else + if ( ! is_string($rules)) { return $this; } + + $rules = explode('|', $rules); } // If the field label wasn't passed we use the field name @@ -463,7 +461,7 @@ class CI_Form_validation { { $this->_field_data[$field]['postdata'] = $this->_reduce_array($validation_array, $row['keys']); } - elseif (isset($validation_array[$field]) && $validation_array[$field] !== '') + elseif (isset($validation_array[$field])) { $this->_field_data[$field]['postdata'] = $validation_array[$field]; } @@ -872,17 +870,11 @@ class CI_Form_validation { */ protected function _translate_fieldname($fieldname) { - // Do we need to translate the field name? - // We look for the prefix lang: to determine this - if (sscanf($fieldname, 'lang:%s', $line) === 1) + // Do we need to translate the field name? We look for the prefix 'lang:' to determine this + // If we find one, but there's no translation for the string - just return it + if (sscanf($fieldname, 'lang:%s', $line) === 1 && FALSE === ($fieldname = $this->CI->lang->line($line, FALSE))) { - // Were we able to translate the field name? If not we use $line - if (FALSE === ($fieldname = $this->CI->lang->line('form_validation_'.$line)) - // DEPRECATED support for non-prefixed keys - && FALSE === ($fieldname = $this->CI->lang->line($line, FALSE))) - { - return $line; - } + return $line; } return $fieldname; diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index af45bb55f..b53207577 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -490,7 +490,7 @@ class CI_FTP { // so we'll recursively call delete_dir() if ( ! preg_match('#/\.\.?$#', $list[$i]) && ! @ftp_delete($this->conn_id, $list[$i])) { - $this->delete_dir($list[$i]); + $this->delete_dir($filepath.$list[$i]); } } } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index e056654bb..ce6c42b02 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1055,8 +1055,11 @@ class CI_Image_lib { if ($this->rotation_angle === 'hor') { - for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1) + for ($i = 0; $i < $height; $i++) { + $left = 0; + $right = $width - 1; + while ($left < $right) { $cl = imagecolorat($src_img, $left, $i); @@ -1072,18 +1075,21 @@ class CI_Image_lib { } else { - for ($i = 0; $i < $width; $i++, $top = 0, $bot = $height-1) + for ($i = 0; $i < $width; $i++) { - while ($top < $bot) + $top = 0; + $bottom = $height - 1; + + while ($top < $bottom) { $ct = imagecolorat($src_img, $i, $top); - $cb = imagecolorat($src_img, $i, $bot); + $cb = imagecolorat($src_img, $i, $bottom); imagesetpixel($src_img, $i, $top, $cb); - imagesetpixel($src_img, $i, $bot, $ct); + imagesetpixel($src_img, $i, $bottom, $ct); $top++; - $bot--; + $bottom--; } } } diff --git a/system/libraries/Session/drivers/Session_memcached_driver.php b/system/libraries/Session/drivers/Session_memcached_driver.php index c7185ee44..97b860588 100644 --- a/system/libraries/Session/drivers/Session_memcached_driver.php +++ b/system/libraries/Session/drivers/Session_memcached_driver.php @@ -322,7 +322,7 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa $this->_lock_key = $lock_key; break; } - while ($attempt++ < 30); + while (++$attempt < 30); if ($attempt === 30) { diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 1ce101daf..b098cc441 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -336,7 +336,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle $this->_lock_key = $lock_key; break; } - while ($attempt++ < 30); + while (++$attempt < 30); if ($attempt === 30) { |